From 6565355831f10ddf98476b334c8bbe4e2261ae23 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 12 Jul 2020 11:40:30 +0200 Subject: [PATCH] Bundled fallback sounds are now loaded if the theme does not provide any navigation sounds. --- THEMES.md | 31 ++++++++++++++----------- es-core/src/Sound.cpp | 28 ++++++++++++---------- themes/rbsimple-DE/navigationsounds.xml | 14 +++++------ 3 files changed, 41 insertions(+), 32 deletions(-) diff --git a/THEMES.md b/THEMES.md index c5a72ac2e..259d67187 100644 --- a/THEMES.md +++ b/THEMES.md @@ -277,16 +277,21 @@ You can now change the order in which elements are rendered by setting `zIndex` #### Navigation sounds -The navigation sounds are configured globally per theme, so it needs to be defined as a feature and with the view set to the special 'all' category. +The navigation sounds are configured globally per theme set, so it needs to be defined as a feature and with the view set to the special 'all' category. It's recommended to put these elements in a separate file and include it from the main theme file (e.g. `./navigationsounds.xml`). There are seven different navigation sounds that can be configured. The names as well as the element structure should be self-explanatory based on the example below. -Starting EmulationStation with the --debug flag will provide feedback on whether the navigation sound elements were read correctly, as well as -providing an error message if any of the .wav sound files could not be loaded. +Starting EmulationStation with the --debug flag will provide feedback on whether any navigation sound elements were read from the theme set. If no navigation sound is provided by the theme, ES will use the bundled navigation sound file as a fallback. This is done per sound, so the theme could provide for example one or two custom sound files while using the bundled ES sounds for the other samples. -Example debug output: \ -`May 12 21:12:37 lvl2: Sound::getFromTheme() looking for [all.selectSound]` \ -`May 12 21:12:37 lvl2: [selectSound] found, ready to play sound file` + +Example debug output: +``` +Jul 12 11:28:58 lvl3: Sound::getFromTheme(): Looking for navigation sound tag . +Jul 12 11:28:58 lvl3: Sound::getFromTheme(): Tag found, ready to load theme sound file. +Jul 12 11:28:58 lvl3: Sound::getFromTheme(): Looking for navigation sound tag . +Jul 12 11:28:58 lvl3: Sound::getFromTheme(): Tag not found, using fallback sound file. + +``` Example `navigationsounds.xml`, to be included from the main theme file: @@ -295,25 +300,25 @@ Example `navigationsounds.xml`, to be included from the main theme file: 6 - + ./core/sounds/systembrowse.wav - + ./core/sounds/quicksysselect.wav - + ./core/sounds/select.wav - + ./core/sounds/back.wav - + ./core/sounds/scroll.wav - + ./core/sounds/favorite.wav - + ./core/sounds/launch.wav diff --git a/es-core/src/Sound.cpp b/es-core/src/Sound.cpp index e2a48040a..a17ab6159 100644 --- a/es-core/src/Sound.cpp +++ b/es-core/src/Sound.cpp @@ -7,6 +7,7 @@ #include "Sound.h" +#include "resources/ResourceManager.h" #include "AudioManager.h" #include "Log.h" #include "Settings.h" @@ -31,15 +32,17 @@ std::shared_ptr Sound::get(const std::string& path) std::shared_ptr Sound::getFromTheme(const std::shared_ptr& theme, const std::string& view, const std::string& element) { - LOG(LogInfo) << "Sound::getFromTheme() looking for [" << view << "." << element << "]"; + LOG(LogDebug) << "Sound::getFromTheme(): Looking for navigation sound tag ."; const ThemeData::ThemeElement* elem = theme->getElement(view, element, "sound"); if(!elem || !elem->has("path")) { - LOG(LogInfo) << "[" << element << "] not found, won't load any sound file"; - return get(""); + LOG(LogDebug) << "Sound::getFromTheme(): " << "Tag not found, using fallback sound file."; + return get(ResourceManager::getInstance()-> + getResourcePath(":/sounds/" + element + ".wav")); } - LOG(LogInfo) << "[" << element << "] found, ready to load sound file"; + LOG(LogDebug) << "Sound::getFromTheme(): Tag found, ready to load theme sound file."; return get(elem->get("path")); } @@ -61,13 +64,13 @@ void NavigationSounds::deinit() void NavigationSounds::loadThemeNavigationSounds(const std::shared_ptr& theme) { - navigationSounds.push_back(Sound::getFromTheme(theme, "all", "systembrowseSound")); - navigationSounds.push_back(Sound::getFromTheme(theme, "all", "quicksysselectSound")); - navigationSounds.push_back(Sound::getFromTheme(theme, "all", "selectSound")); - navigationSounds.push_back(Sound::getFromTheme(theme, "all", "backSound")); - navigationSounds.push_back(Sound::getFromTheme(theme, "all", "scrollSound")); - navigationSounds.push_back(Sound::getFromTheme(theme, "all", "favoriteSound")); - navigationSounds.push_back(Sound::getFromTheme(theme, "all", "launchSound")); + navigationSounds.push_back(Sound::getFromTheme(theme, "all", "systembrowse")); + navigationSounds.push_back(Sound::getFromTheme(theme, "all", "quicksysselect")); + navigationSounds.push_back(Sound::getFromTheme(theme, "all", "select")); + navigationSounds.push_back(Sound::getFromTheme(theme, "all", "back")); + navigationSounds.push_back(Sound::getFromTheme(theme, "all", "scroll")); + navigationSounds.push_back(Sound::getFromTheme(theme, "all", "favorite")); + navigationSounds.push_back(Sound::getFromTheme(theme, "all", "launch")); } void NavigationSounds::playThemeNavigationSound(NavigationSoundsID soundID) @@ -114,7 +117,8 @@ void Sound::init() Uint8 * data = nullptr; Uint32 dlen = 0; if (SDL_LoadWAV(mPath.c_str(), &wave, &data, &dlen) == nullptr) { - LOG(LogError) << "Error loading sound file \"" << mPath << "\"!\n" << " " << SDL_GetError(); + LOG(LogError) << "Error - Failed to load theme navigation sound file:"; + LOG(LogError) << SDL_GetError(); return; } // Build conversion buffer. diff --git a/themes/rbsimple-DE/navigationsounds.xml b/themes/rbsimple-DE/navigationsounds.xml index d3462a797..066b4861a 100644 --- a/themes/rbsimple-DE/navigationsounds.xml +++ b/themes/rbsimple-DE/navigationsounds.xml @@ -3,25 +3,25 @@ - + ./core/sounds/systembrowse.wav - + ./core/sounds/quicksysselect.wav - + ./core/sounds/select.wav - + ./core/sounds/back.wav - + ./core/sounds/scroll.wav - + ./core/sounds/favorite.wav - + ./core/sounds/launch.wav