Merge pull request #242 from psyke83/PSFixes

Power Saving enhancements
This commit is contained in:
Jools Wills 2017-10-28 20:18:38 +01:00 committed by GitHub
commit d57dee245c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 14 deletions

View file

@ -268,7 +268,6 @@ void FileData::launchGame(Window* window)
window->init();
VolumeControl::getInstance()->init();
AudioManager::getInstance()->init();
window->normalizeNextUpdate();
//update number of times the game has been launched
@ -343,4 +342,4 @@ FileData::SortType getSortTypeFromString(std::string desc) {
}
// if not found default to name, ascending
return FileSorts::SortTypes.at(0);
}
}

View file

@ -76,13 +76,11 @@ public:
inline void setSelectorOffsetY(float selectorOffsetY) { mSelectorOffsetY = selectorOffsetY; }
inline void setSelectorColor(unsigned int color) { mSelectorColor = color; }
inline void setSelectedColor(unsigned int color) { mSelectedColor = color; }
inline void setScrollSound(const std::shared_ptr<Sound>& sound) { mScrollSound = sound; }
inline void setColor(unsigned int id, unsigned int color) { mColors[id] = color; }
inline void setSound(const std::shared_ptr<Sound>& sound) { mScrollSound = sound; }
inline void setLineSpacing(float lineSpacing) { mLineSpacing = lineSpacing; }
protected:
virtual void onScroll(int amt) { if(mScrollSound) mScrollSound->play(); }
virtual void onScroll(int amt) { if(!mScrollSound.empty()) Sound::get(mScrollSound)->play(); }
virtual void onCursorChanged(const CursorState& state);
private:
@ -105,7 +103,7 @@ private:
float mSelectorOffsetY;
unsigned int mSelectorColor;
unsigned int mSelectedColor;
std::shared_ptr<Sound> mScrollSound;
std::string mScrollSound;
static const unsigned int COLOR_ID_COUNT = 2;
unsigned int mColors[COLOR_ID_COUNT];
@ -354,7 +352,7 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme, c
setSelectorHeight(selectorHeight);
if(properties & SOUND && elem->has("scrollSound"))
setSound(Sound::get(elem->get<std::string>("scrollSound")));
mScrollSound = elem->get<std::string>("scrollSound");
if(properties & ALIGNMENT)
{

View file

@ -120,7 +120,16 @@ void GuiMenu::openSoundSettings()
auto sounds_enabled = std::make_shared<SwitchComponent>(mWindow);
sounds_enabled->setState(Settings::getInstance()->getBool("EnableSounds"));
s->addWithLabel("ENABLE NAVIGATION SOUNDS", sounds_enabled);
s->addSaveFunc([sounds_enabled] { Settings::getInstance()->setBool("EnableSounds", sounds_enabled->getState()); });
s->addSaveFunc([sounds_enabled] {
if (sounds_enabled->getState()
&& !Settings::getInstance()->getBool("EnableSounds")
&& PowerSaver::getMode() == PowerSaver::INSTANT)
{
Settings::getInstance()->setString("PowerSaverMode", "default");
PowerSaver::init();
}
Settings::getInstance()->setBool("EnableSounds", sounds_enabled->getState());
});
auto video_audio = std::make_shared<SwitchComponent>(mWindow);
video_audio->setState(Settings::getInstance()->getBool("VideoAudio"));
@ -316,6 +325,7 @@ void GuiMenu::openOtherSettings()
if (Settings::getInstance()->getString("PowerSaverMode") != "instant" && power_saver->getSelected() == "instant") {
Settings::getInstance()->setString("TransitionStyle", "instant");
Settings::getInstance()->setBool("MoveCarousel", false);
Settings::getInstance()->setBool("EnableSounds", false);
}
Settings::getInstance()->setString("PowerSaverMode", power_saver->getSelected());
PowerSaver::init();

View file

@ -1,4 +1,5 @@
#include "AudioManager.h"
#include "Settings.h"
#include <SDL.h>
#include "Log.h"
@ -62,7 +63,7 @@ AudioManager::~AudioManager()
std::shared_ptr<AudioManager> & AudioManager::getInstance()
{
//check if an AudioManager instance is already created, if not create one
if (sInstance == nullptr) {
if (sInstance == nullptr && Settings::getInstance()->getBool("EnableSounds")) {
sInstance = std::shared_ptr<AudioManager>(new AudioManager);
}
return sInstance;
@ -106,6 +107,7 @@ void AudioManager::deinit()
//completely tear down SDL audio. else SDL hogs audio resources and emulators might fail to start...
SDL_CloseAudio();
SDL_QuitSubSystem(SDL_INIT_AUDIO);
sInstance = NULL;
}
void AudioManager::registerSound(std::shared_ptr<Sound> & sound)

View file

@ -1,4 +1,5 @@
#include "PowerSaver.h"
#include "AudioManager.h"
#include "Settings.h"
#include <string.h>
@ -17,6 +18,9 @@ void PowerSaver::init()
int PowerSaver::getTimeout()
{
if (SDL_GetAudioStatus() == SDL_AUDIO_PAUSED)
AudioManager::getInstance()->deinit();
// Used only for SDL_WaitEventTimeout. Use `getMode()` for modes.
return mRunningScreenSaver ? mWakeupTimeout : mScreenSaverTimeout;
}

View file

@ -114,6 +114,8 @@ void Sound::play()
if(!Settings::getInstance()->getBool("EnableSounds"))
return;
AudioManager::getInstance();
SDL_LockAudio();
if (playing)
{

View file

@ -191,11 +191,6 @@ void VideoPlayerComponent::stopVideo()
int status;
kill(mPlayerPid, SIGKILL);
waitpid(mPlayerPid, &status, WNOHANG);
// Restart AudioManager
if (boost::starts_with(Settings::getInstance()->getString("OMXAudioDev").c_str(), "alsa"))
{
AudioManager::getInstance()->init();
}
mPlayerPid = -1;
}
}