From 46c178af1dfa2e75977590117e72caab918ed2f1 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 20 Dec 2020 16:41:58 +0100 Subject: [PATCH] Added volume controls for navigation sounds and the video player. --- es-app/src/guis/GuiMenu.cpp | 30 ++++++++++++++++++++ es-app/src/guis/GuiScreensaverOptions.cpp | 2 +- es-core/src/AudioManager.cpp | 12 +++++++- es-core/src/Settings.cpp | 2 ++ es-core/src/components/VideoVlcComponent.cpp | 8 +++++- 5 files changed, 51 insertions(+), 3 deletions(-) diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index bac63c310..c706b7216 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -439,6 +439,36 @@ void GuiMenu::openSoundSettings() }); #endif + // Volume for navigation sounds. + auto sound_volume_navigation = + std::make_shared(mWindow, 0.f, 100.f, 1.f, "%"); + sound_volume_navigation->setValue(static_cast(Settings::getInstance()-> + getInt("SoundVolumeNavigation"))); + s->addWithLabel("NAVIGATION VOLUME", sound_volume_navigation); + s->addSaveFunc([sound_volume_navigation, s] { + if (sound_volume_navigation->getValue() != + static_cast(Settings::getInstance()->getInt("SoundVolumeNavigation"))) { + Settings::getInstance()->setInt("SoundVolumeNavigation", + static_cast(sound_volume_navigation->getValue())); + s->setNeedsSaving(); + } + }); + + // Volume for videos. + auto sound_volume_videos = + std::make_shared(mWindow, 0.f, 100.f, 1.f, "%"); + sound_volume_videos->setValue(static_cast(Settings::getInstance()-> + getInt("SoundVolumeVideos"))); + s->addWithLabel("VIDEO VOLUME", sound_volume_videos); + s->addSaveFunc([sound_volume_videos, s] { + if (sound_volume_videos->getValue() != + static_cast(Settings::getInstance()->getInt("SoundVolumeVideos"))) { + Settings::getInstance()->setInt("SoundVolumeVideos", + static_cast(sound_volume_videos->getValue())); + s->setNeedsSaving(); + } + }); + if (UIModeController::getInstance()->isUIModeFull()) { // The ALSA Audio Card and Audio Device selection code is disabled at the moment. // As PulseAudio controls the sound devices for the desktop environment, it doesn't diff --git a/es-app/src/guis/GuiScreensaverOptions.cpp b/es-app/src/guis/GuiScreensaverOptions.cpp index 74d4d8de4..7181d6e86 100644 --- a/es-app/src/guis/GuiScreensaverOptions.cpp +++ b/es-app/src/guis/GuiScreensaverOptions.cpp @@ -214,7 +214,7 @@ void GuiScreensaverOptions::openVideoScreensaverOptions() screensaver_swap_video_timeout->setValue(static_cast(Settings::getInstance()-> getInt("ScreensaverSwapVideoTimeout") / (1000))); s->addWithLabel("SWAP VIDEOS AFTER (SECONDS)", screensaver_swap_video_timeout); - s->addSaveFunc([screensaver_swap_video_timeout,s ] { + s->addSaveFunc([screensaver_swap_video_timeout, s] { if (screensaver_swap_video_timeout->getValue() != static_cast(Settings::getInstance()-> getInt("ScreensaverSwapVideoTimeout") / (1000))) { diff --git a/es-core/src/AudioManager.cpp b/es-core/src/AudioManager.cpp index 8baff7d6d..59611d98e 100644 --- a/es-core/src/AudioManager.cpp +++ b/es-core/src/AudioManager.cpp @@ -38,7 +38,7 @@ void AudioManager::mixAudio(void* /*unused*/, Uint8* stream, int len) } // Mix sample into stream. SDL_MixAudio(stream, &(sound->getData()[sound->getPosition()]), - restLength, SDL_MIX_MAXVOLUME); + restLength, Settings::getInstance()->getInt("SoundVolumeNavigation") * 1.28); if (sound->getPosition() + restLength < sound->getLength()) { //sample hasn't ended yet stillPlaying = true; @@ -103,6 +103,16 @@ void AudioManager::init() LOG(LogError) << "AudioManager - Unable to open SDL audio: " << SDL_GetError() << std::endl; } + + // Just in case someone changed the es_settings.cfg file manually to invalid values. + if (Settings::getInstance()->getInt("SoundVolumeNavigation") > 100) + Settings::getInstance()->setInt("SoundVolumeNavigation", 100); + if (Settings::getInstance()->getInt("SoundVolumeNavigation") < 0) + Settings::getInstance()->setInt("SoundVolumeNavigation", 0); + if (Settings::getInstance()->getInt("SoundVolumeVideos") > 100) + Settings::getInstance()->setInt("SoundVolumeVideos", 100); + if (Settings::getInstance()->getInt("SoundVolumeVideos") < 0) + Settings::getInstance()->setInt("SoundVolumeVideos", 0); } void AudioManager::deinit() diff --git a/es-core/src/Settings.cpp b/es-core/src/Settings.cpp index 061b02882..7740f4b5f 100644 --- a/es-core/src/Settings.cpp +++ b/es-core/src/Settings.cpp @@ -170,6 +170,8 @@ void Settings::setDefaults() //#else // mStringMap["AudioDevice"] = { "Master", "Master" }; #endif + mIntMap["SoundVolumeNavigation"] = { 80, 80 }; + mIntMap["SoundVolumeVideos"] = { 100, 100 }; mBoolMap["GamelistVideoAudio"] = { true, true }; mBoolMap["NavigationSounds"] = { true, true }; diff --git a/es-core/src/components/VideoVlcComponent.cpp b/es-core/src/components/VideoVlcComponent.cpp index 625595c06..ac60234bb 100644 --- a/es-core/src/components/VideoVlcComponent.cpp +++ b/es-core/src/components/VideoVlcComponent.cpp @@ -360,8 +360,14 @@ void VideoVlcComponent::startVideo() if ((!Settings::getInstance()->getBool("GamelistVideoAudio") && !mScreensaverMode) || (!Settings::getInstance()->getBool("ScreensaverVideoAudio") && - mScreensaverMode)) + mScreensaverMode)) { libvlc_audio_set_mute(mMediaPlayer, 1); + } + else { + libvlc_audio_set_mute(mMediaPlayer, 0); + libvlc_audio_set_volume(mMediaPlayer, + Settings::getInstance()->getInt("SoundVolumeVideos")); + } libvlc_media_player_play(mMediaPlayer); libvlc_video_set_callbacks(mMediaPlayer, lock, unlock, display,