From 3c7d86a57895c82ae5708b553e0ded041d2387f4 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Wed, 17 Jun 2020 22:13:07 +0200 Subject: [PATCH] Made navigation sounds unload and reload properly on theme changes. Also improved the navigation sound handling for SystemView. --- es-app/src/views/SystemView.cpp | 8 +++----- es-app/src/views/SystemView.h | 3 +++ es-app/src/views/ViewController.cpp | 1 + es-core/src/Sound.cpp | 10 +++++++++- es-core/src/Sound.h | 1 + 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/es-app/src/views/SystemView.cpp b/es-app/src/views/SystemView.cpp index 41d214fcf..c2a9c7009 100644 --- a/es-app/src/views/SystemView.cpp +++ b/es-app/src/views/SystemView.cpp @@ -12,9 +12,9 @@ #include "views/ViewController.h" #include "Log.h" #include "Settings.h" +#include "Sound.h" #include "SystemData.h" #include "Window.h" -#include "Sound.h" // Buffer values for scrolling velocity (left, stopped, right). const int logoBuffersLeft[] = { -5, -2, -1 }; @@ -163,12 +163,10 @@ bool SystemView::input(InputConfig* config, Input input) case VERTICAL: case VERTICAL_WHEEL: if (config->isMappedLike("up", input)) { - NavigationSounds::getInstance()->playThemeNavigationSound(SYSTEMBROWSESOUND); listInput(-1); return true; } if (config->isMappedLike("down", input)) { - NavigationSounds::getInstance()->playThemeNavigationSound(SYSTEMBROWSESOUND); listInput(1); return true; } @@ -177,12 +175,10 @@ bool SystemView::input(InputConfig* config, Input input) case HORIZONTAL_WHEEL: default: if (config->isMappedLike("left", input)) { - NavigationSounds::getInstance()->playThemeNavigationSound(SYSTEMBROWSESOUND); listInput(-1); return true; } if (config->isMappedLike("right", input)) { - NavigationSounds::getInstance()->playThemeNavigationSound(SYSTEMBROWSESOUND); listInput(1); return true; } @@ -237,6 +233,8 @@ void SystemView::onCursorChanged(const CursorState& /*state*/) // Update help style. updateHelpPrompts(); +// NavigationSounds::getInstance()->playThemeNavigationSound(SYSTEMBROWSESOUND); + float startPos = mCamOffset; float posMax = (float)mEntries.size(); diff --git a/es-app/src/views/SystemView.h b/es-app/src/views/SystemView.h index 491a352bd..b037a0975 100644 --- a/es-app/src/views/SystemView.h +++ b/es-app/src/views/SystemView.h @@ -12,6 +12,7 @@ #include "components/TextComponent.h" #include "resources/Font.h" #include "GuiComponent.h" +#include "Sound.h" #include class AnimatedImageComponent; @@ -67,6 +68,8 @@ public: protected: void onCursorChanged(const CursorState& state) override; + virtual void onScroll() { + NavigationSounds::getInstance()->playThemeNavigationSound(SYSTEMBROWSESOUND); } private: void populate(); diff --git a/es-app/src/views/ViewController.cpp b/es-app/src/views/ViewController.cpp index 304a1544d..a75e8e53e 100644 --- a/es-app/src/views/ViewController.cpp +++ b/es-app/src/views/ViewController.cpp @@ -548,6 +548,7 @@ void ViewController::reloadAll() } // Load navigation sounds. + NavigationSounds::getInstance()->deinit(); NavigationSounds::getInstance()->loadThemeNavigationSounds( SystemData::sSystemVector.front()->getTheme()); diff --git a/es-core/src/Sound.cpp b/es-core/src/Sound.cpp index 988d554b7..9776d7533 100644 --- a/es-core/src/Sound.cpp +++ b/es-core/src/Sound.cpp @@ -38,12 +38,20 @@ std::shared_ptr Sound::getFromTheme(const std::shared_ptr& the NavigationSounds* NavigationSounds::getInstance() { - if (sInstance == NULL) + if (sInstance == nullptr) sInstance = new NavigationSounds(); return sInstance; } +void NavigationSounds::deinit() +{ + if (sInstance) + delete sInstance; + + sInstance = nullptr; +} + void NavigationSounds::loadThemeNavigationSounds(const std::shared_ptr& theme) { navigationSounds.push_back(Sound::getFromTheme(theme, "all", "systembrowseSound")); diff --git a/es-core/src/Sound.h b/es-core/src/Sound.h index 034dc6c26..7827689bd 100644 --- a/es-core/src/Sound.h +++ b/es-core/src/Sound.h @@ -60,6 +60,7 @@ class NavigationSounds public: static NavigationSounds* getInstance(); + void deinit(); void loadThemeNavigationSounds(const std::shared_ptr& theme); void playThemeNavigationSound(NavigationSoundsID soundID); bool isPlayingThemeNavigationSound(NavigationSoundsID soundID);