From 0aafc1314aa57499b8580fb80e7c7b6e93c5a155 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Fri, 15 May 2020 18:08:26 +0200 Subject: [PATCH] Added navigation sound support (configurable per theme) and implemented proper sound handling at most places in ES --- es-app/src/components/TextListComponent.h | 8 ++++---- es-app/src/views/SystemView.cpp | 14 ++++++++++++++ es-app/src/views/SystemView.h | 4 +++- es-app/src/views/gamelist/BasicGameListView.cpp | 4 ---- es-app/src/views/gamelist/GridGameListView.cpp | 5 +++++ es-app/src/views/gamelist/IGameListView.cpp | 1 - es-app/src/views/gamelist/ISimpleGameListView.cpp | 12 ++++++++++-- es-core/src/Sound.cpp | 10 +++++++--- es-core/src/ThemeData.cpp | 10 +++++++++- es-core/src/components/IList.h | 4 ++-- 10 files changed, 54 insertions(+), 18 deletions(-) diff --git a/es-app/src/components/TextListComponent.h b/es-app/src/components/TextListComponent.h index b0124f22b..a703e378e 100644 --- a/es-app/src/components/TextListComponent.h +++ b/es-app/src/components/TextListComponent.h @@ -80,8 +80,9 @@ public: inline void setLineSpacing(float lineSpacing) { mLineSpacing = lineSpacing; } protected: - virtual void onScroll(int /*amt*/) { if(!mScrollSound.empty()) Sound::get(mScrollSound)->play(); } + virtual void onScroll() { soundfile->play(); } virtual void onCursorChanged(const CursorState& state); + std::shared_ptr soundfile; private: int mMarqueeOffset; @@ -390,9 +391,8 @@ void TextListComponent::applyTheme(const std::shared_ptr& theme, c const float selectorHeight = Math::max(mFont->getHeight(1.0), (float)mFont->getSize()) * mLineSpacing; setSelectorHeight(selectorHeight); - if(properties & SOUND && elem->has("scrollSound")) - mScrollSound = elem->get("scrollSound"); - + soundfile = Sound::getFromTheme(theme, "navigationsounds", "scrollSound"); + if(properties & ALIGNMENT) { if(elem->has("alignment")) diff --git a/es-app/src/views/SystemView.cpp b/es-app/src/views/SystemView.cpp index 44e299c49..00de042df 100644 --- a/es-app/src/views/SystemView.cpp +++ b/es-app/src/views/SystemView.cpp @@ -8,6 +8,7 @@ #include "Settings.h" #include "SystemData.h" #include "Window.h" +#include "Sound.h" // buffer values for scrolling velocity (left, stopped, right) const int logoBuffersLeft[] = { -5, -2, -1 }; @@ -28,6 +29,8 @@ SystemView::SystemView(Window* window) : IList(wind void SystemView::populate() { mEntries.clear(); + mSelectSound = ""; +// mScrollSound = ""; for(auto it = SystemData::sSystemVector.cbegin(); it != SystemData::sSystemVector.cend(); it++) { @@ -124,6 +127,8 @@ void SystemView::populate() mWindow->pushGui(new GuiMsgBox(mWindow, "The selected UI mode has nothing to show,\n returning to UI mode: FULL", "OK", nullptr)); } } + + } void SystemView::goToSystem(SystemData* system, bool animate) @@ -136,6 +141,9 @@ void SystemView::goToSystem(SystemData* system, bool animate) bool SystemView::input(InputConfig* config, Input input) { + auto it = SystemData::sSystemVector.cbegin(); + const std::shared_ptr& theme = (*it)->getTheme(); + if(input.value != 0) { if(config->getDeviceId() == DEVICE_KEYBOARD && input.value && input.id == SDLK_r && SDL_GetModState() & KMOD_LCTRL && Settings::getInstance()->getBool("Debug")) @@ -151,11 +159,13 @@ bool SystemView::input(InputConfig* config, Input input) case VERTICAL_WHEEL: if (config->isMappedLike("up", input)) { + Sound::getFromTheme(theme, "navigationsounds", "systembrowseSound")->play(); listInput(-1); return true; } if (config->isMappedLike("down", input)) { + Sound::getFromTheme(theme, "navigationsounds", "systembrowseSound")->play(); listInput(1); return true; } @@ -165,11 +175,13 @@ bool SystemView::input(InputConfig* config, Input input) default: if (config->isMappedLike("left", input)) { + Sound::getFromTheme(theme, "navigationsounds", "systembrowseSound")->play(); listInput(-1); return true; } if (config->isMappedLike("right", input)) { + Sound::getFromTheme(theme, "navigationsounds", "systembrowseSound")->play(); listInput(1); return true; } @@ -178,6 +190,7 @@ bool SystemView::input(InputConfig* config, Input input) if(config->isMappedTo("a", input)) { + Sound::getFromTheme(theme, "navigationsounds", "selectSound")->play(); stopScrolling(); ViewController::get()->goToGameList(getSelected()); return true; @@ -186,6 +199,7 @@ bool SystemView::input(InputConfig* config, Input input) { // get random system // go to system + Sound::getFromTheme(theme, "navigationsounds", "systembrowseSound")->play(); setCursor(SystemData::getRandomSystem()); return true; } diff --git a/es-app/src/views/SystemView.h b/es-app/src/views/SystemView.h index 85b0aca44..8e77e744d 100644 --- a/es-app/src/views/SystemView.h +++ b/es-app/src/views/SystemView.h @@ -62,6 +62,9 @@ public: std::vector getHelpPrompts() override; virtual HelpStyle getHelpStyle() override; + std::string mSelectSound; +// std::string mScrollSound; + protected: void onCursorChanged(const CursorState& state) override; @@ -76,7 +79,6 @@ private: void renderInfoBar(const Transform4x4f& trans); void renderFade(const Transform4x4f& trans); - SystemViewCarousel mCarousel; TextComponent mSystemInfo; diff --git a/es-app/src/views/gamelist/BasicGameListView.cpp b/es-app/src/views/gamelist/BasicGameListView.cpp index 3cba7522f..c61253077 100644 --- a/es-app/src/views/gamelist/BasicGameListView.cpp +++ b/es-app/src/views/gamelist/BasicGameListView.cpp @@ -50,10 +50,6 @@ void BasicGameListView::populateList(const std::vector& files) bool favoritesFirst = Settings::getInstance()->getBool("FavoritesFirst"); -// auto fav = Settings::getInstance()->getString(mRoot->getSystem()->getName() + ".FavoritesFirst"); -// if (fav == "1") favoritesFirst = true; -// else if (fav == "0") favoritesFirst = false; - bool showFavoriteIcon = (systemName != "favorites" && systemName != "recent"); if (!showFavoriteIcon) favoritesFirst = false; diff --git a/es-app/src/views/gamelist/GridGameListView.cpp b/es-app/src/views/gamelist/GridGameListView.cpp index a95033d89..b85debc51 100644 --- a/es-app/src/views/gamelist/GridGameListView.cpp +++ b/es-app/src/views/gamelist/GridGameListView.cpp @@ -6,6 +6,7 @@ #include "CollectionSystemManager.h" #include "Settings.h" #include "SystemData.h" +#include "Sound.h" #ifdef _RPI_ #include "components/VideoPlayerComponent.h" #endif @@ -146,6 +147,10 @@ std::string GridGameListView::getQuickSystemSelectLeftButton() bool GridGameListView::input(InputConfig* config, Input input) { + if (input.value == 0 and (config->isMappedLike("left", input) || config->isMappedLike("right", input) + || (config->isMappedLike("up", input)) || (config->isMappedLike("down", input)) )) + Sound::getFromTheme(getTheme(), "navigationsounds", "scrollSound")->play(); + if(config->isMappedLike("left", input) || config->isMappedLike("right", input)) return GuiComponent::input(config, input); diff --git a/es-app/src/views/gamelist/IGameListView.cpp b/es-app/src/views/gamelist/IGameListView.cpp index 4b48bdd37..39ebf52b0 100644 --- a/es-app/src/views/gamelist/IGameListView.cpp +++ b/es-app/src/views/gamelist/IGameListView.cpp @@ -11,7 +11,6 @@ bool IGameListView::input(InputConfig* config, Input input) // select to open GuiGamelistOptions if(!UIModeController::getInstance()->isUIModeKid() && config->isMappedTo("select", input) && input.value) { - Sound::getFromTheme(mTheme, getName(), "menuOpen")->play(); mWindow->pushGui(new GuiGamelistOptions(mWindow, this->mRoot->getSystem())); return true; diff --git a/es-app/src/views/gamelist/ISimpleGameListView.cpp b/es-app/src/views/gamelist/ISimpleGameListView.cpp index 7d361fc94..efb389c4e 100644 --- a/es-app/src/views/gamelist/ISimpleGameListView.cpp +++ b/es-app/src/views/gamelist/ISimpleGameListView.cpp @@ -78,6 +78,8 @@ void ISimpleGameListView::onFileChanged(FileData* /*file*/, FileChangeType /*cha bool ISimpleGameListView::input(InputConfig* config, Input input) { + std::shared_ptr soundfile; + if(input.value != 0) { if(config->isMappedTo("a", input)) @@ -85,7 +87,9 @@ bool ISimpleGameListView::input(InputConfig* config, Input input) FileData* cursor = getCursor(); if(cursor->getType() == GAME) { - Sound::getFromTheme(getTheme(), getName(), "launch")->play(); + soundfile = Sound::getFromTheme(getTheme(), "navigationsounds", "launchSound"); + soundfile->play(); + while(soundfile->isPlaying()); launch(cursor); }else{ // it's a folder @@ -106,8 +110,8 @@ bool ISimpleGameListView::input(InputConfig* config, Input input) populateList(mCursorStack.top()->getParent()->getChildren()); setCursor(mCursorStack.top()); mCursorStack.pop(); - Sound::getFromTheme(getTheme(), getName(), "back")->play(); }else{ + Sound::getFromTheme(getTheme(), "navigationsounds", "backSound")->play(); onFocusLost(); SystemData* systemToView = getCursor()->getSystem(); if (systemToView->isCollection()) @@ -122,6 +126,7 @@ bool ISimpleGameListView::input(InputConfig* config, Input input) { if(Settings::getInstance()->getBool("QuickSystemSelect")) { + Sound::getFromTheme(getTheme(), "navigationsounds", "quicksysselectSound")->play(); onFocusLost(); ViewController::get()->goToNextGameList(); return true; @@ -130,6 +135,7 @@ bool ISimpleGameListView::input(InputConfig* config, Input input) { if(Settings::getInstance()->getBool("QuickSystemSelect")) { + Sound::getFromTheme(getTheme(), "navigationsounds", "quicksysselectSound")->play(); onFocusLost(); ViewController::get()->goToPrevGameList(); return true; @@ -139,6 +145,7 @@ bool ISimpleGameListView::input(InputConfig* config, Input input) if (mRoot->getSystem()->isGameSystem()) { // go to random system game + Sound::getFromTheme(getTheme(), "navigationsounds", "scrollSound")->play(); FileData* randomGame = getCursor()->getSystem()->getRandomGame(); if (randomGame) { @@ -150,6 +157,7 @@ bool ISimpleGameListView::input(InputConfig* config, Input input) { if(mRoot->getSystem()->isGameSystem()) { + Sound::getFromTheme(getTheme(), "navigationsounds", "favoriteSound")->play(); if(CollectionSystemManager::get()->toggleGameInCollection(getCursor())) { return true; diff --git a/es-core/src/Sound.cpp b/es-core/src/Sound.cpp index e3f46e279..fdc38a073 100644 --- a/es-core/src/Sound.cpp +++ b/es-core/src/Sound.cpp @@ -21,15 +21,19 @@ 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) << " req sound [" << view << "." << element << "]"; + if(!Settings::getInstance()->getBool("EnableSounds")) + return get(""); + + LOG(LogInfo) << "Sound::getFromTheme() looking for [" << view << "." << element << "]"; const ThemeData::ThemeElement* elem = theme->getElement(view, element, "sound"); if(!elem || !elem->has("path")) { - LOG(LogInfo) << " (missing)"; + LOG(LogInfo) << "[" << element << "] not found, can't play sound file"; return get(""); } - + + LOG(LogInfo) << "[" << element << "] found, ready to play sound file"; return get(elem->get("path")); } diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 2d1be3d04..df532892b 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -10,10 +10,18 @@ #include #include -std::vector ThemeData::sSupportedViews { { "system" }, { "basic" }, { "detailed" }, { "grid" }, { "video" } }; +std::vector ThemeData::sSupportedViews { { "navigationsounds" }, { "system" }, { "basic" }, { "detailed" }, { "grid" }, { "video" } }; std::vector ThemeData::sSupportedFeatures { { "video" }, { "carousel" }, { "z-index" }, { "visible" } }; std::map> ThemeData::sElementMap { + { "navigationsounds", { + { "systembrowseSound", PATH }, + { "quicksysselectSound", PATH }, + { "selectSound", PATH }, + { "backSound", PATH }, + { "scrollSound", PATH }, + { "favoriteSound", PATH }, + { "launchSound", PATH } } }, { "image", { { "pos", NORMALIZED_PAIR }, { "size", NORMALIZED_PAIR }, diff --git a/es-core/src/components/IList.h b/es-core/src/components/IList.h index 93f61ce9a..b48fb5f98 100644 --- a/es-core/src/components/IList.h +++ b/es-core/src/components/IList.h @@ -299,14 +299,14 @@ protected: } if(cursor != mCursor) - onScroll(absAmt); + onScroll(); mCursor = cursor; onCursorChanged((mScrollTier > 0) ? CURSOR_SCROLLING : CURSOR_STOPPED); } virtual void onCursorChanged(const CursorState& /*state*/) {} - virtual void onScroll(int /*amt*/) {} + virtual void onScroll() {} }; #endif // ES_CORE_COMPONENTS_ILIST_H