Deactivated the audio device settings and added a new setting for custom scripts.

Also changed some other setting names.
This commit is contained in:
Leon Styhre 2020-07-09 19:24:20 +02:00
parent d1f8c3e385
commit 9ba4f01a29
10 changed files with 92 additions and 48 deletions

View file

@ -8,12 +8,24 @@
#include "math/Misc.h" #include "math/Misc.h"
#include "Log.h" #include "Log.h"
#ifdef _RPI_
#include "Settings.h" #include "Settings.h"
#endif
#ifdef _WIN64 #ifdef _WIN64
#include <mmdeviceapi.h> #include <mmdeviceapi.h>
#endif #endif
// 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
// make much sense to be able to select ALSA devices directly. Normally (always?)
// the selection doesn't make any difference at all. But maybe some PulseAudio
// settings could be added later on, if needed.
// The code is still active for Raspberry Pi though as I'm not sure if this is
// useful for that device.
// Keeping mixerName and mixerCard at their default values should make sure that
// the rest of the volume control code in here compiles and works fine.
#if defined(__linux__) #if defined(__linux__)
#if defined(_RPI_) || defined(_VERO4K_) #if defined(_RPI_) || defined(_VERO4K_)
const char * VolumeControl::mixerName = "PCM"; const char * VolumeControl::mixerName = "PCM";
@ -102,8 +114,10 @@ void VolumeControl::init()
// Try to open mixer device. // Try to open mixer device.
if (mixerHandle == nullptr) { if (mixerHandle == nullptr) {
// Allow user to override the AudioCard and AudioDevice in es_settings.cfg. // Allow user to override the AudioCard and AudioDevice in es_settings.cfg.
#ifdef _RPI_
mixerCard = Settings::getInstance()->getString("AudioCard").c_str(); mixerCard = Settings::getInstance()->getString("AudioCard").c_str();
mixerName = Settings::getInstance()->getString("AudioDevice").c_str(); mixerName = Settings::getInstance()->getString("AudioDevice").c_str();
#endif
snd_mixer_selem_id_alloca(&mixerSelemId); snd_mixer_selem_id_alloca(&mixerSelemId);
// Sets simple-mixer index and name. // Sets simple-mixer index and name.
@ -312,8 +326,7 @@ int VolumeControl::getVolume() const
float floatVolume = 0.0f; // 0-1 float floatVolume = 0.0f; // 0-1
if (endpointVolume->GetMasterVolumeLevelScalar(&floatVolume) == S_OK) { if (endpointVolume->GetMasterVolumeLevelScalar(&floatVolume) == S_OK) {
volume = (int)Math::round(floatVolume * 100.0f); volume = (int)Math::round(floatVolume * 100.0f);
LOG(LogInfo) << "System audio volume is " << volume << LOG(LogInfo) << "System audio volume is " << volume;
" (floating point value " << floatVolume << ")";
} }
else { else {
LOG(LogError) << "VolumeControl::getVolume() - Failed to get master volume!"; LOG(LogError) << "VolumeControl::getVolume() - Failed to get master volume!";

View file

@ -87,7 +87,15 @@ void GuiMenu::openSoundSettings()
setVolume((int)Math::round(volume->getValue())); }); setVolume((int)Math::round(volume->getValue())); });
if (UIModeController::getInstance()->isUIModeFull()) { if (UIModeController::getInstance()->isUIModeFull()) {
#if defined(__linux__) // 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
// make much sense to be able to select ALSA devices directly. Normally (always?)
// the selection doesn't make any difference at all. But maybe some PulseAudio
// settings could be added later on, if needed.
// The code is still active for Raspberry Pi though as I'm not sure if this is
// useful for that device.
// #if defined(__linux__)
#ifdef _RPI_
// audio card // audio card
auto audio_card = std::make_shared<OptionListComponent<std::string>> auto audio_card = std::make_shared<OptionListComponent<std::string>>
(mWindow, getHelpStyle(), "AUDIO CARD", false); (mWindow, getHelpStyle(), "AUDIO CARD", false);
@ -173,24 +181,24 @@ void GuiMenu::openSoundSettings()
// Video audio. // Video audio.
auto video_audio = std::make_shared<SwitchComponent>(mWindow); auto video_audio = std::make_shared<SwitchComponent>(mWindow);
video_audio->setState(Settings::getInstance()->getBool("VideoAudio")); video_audio->setState(Settings::getInstance()->getBool("VideoAudio"));
s->addWithLabel("ENABLE AUDIO FOR VIDEO FILES", video_audio); s->addWithLabel("AUDIO FOR VIDEO FILES", video_audio);
s->addSaveFunc([video_audio] { Settings::getInstance()->setBool("VideoAudio", s->addSaveFunc([video_audio] { Settings::getInstance()->setBool("VideoAudio",
video_audio->getState()); }); video_audio->getState()); });
// Navigation sounds. // Navigation sounds.
auto navigationsounds_enabled = std::make_shared<SwitchComponent>(mWindow); auto navigation_sounds = std::make_shared<SwitchComponent>(mWindow);
navigationsounds_enabled->setState(Settings::getInstance()-> navigation_sounds->setState(Settings::getInstance()->
getBool("EnableNavigationSounds")); getBool("NavigationSounds"));
s->addWithLabel("ENABLE NAVIGATION SOUNDS", navigationsounds_enabled); s->addWithLabel("NAVIGATION SOUNDS", navigation_sounds);
s->addSaveFunc([navigationsounds_enabled] { s->addSaveFunc([navigation_sounds] {
if (navigationsounds_enabled->getState() && if (navigation_sounds->getState() &&
!Settings::getInstance()->getBool("EnableNavigationSounds") && !Settings::getInstance()->getBool("NavigationSounds") &&
PowerSaver::getMode() == PowerSaver::INSTANT) { PowerSaver::getMode() == PowerSaver::INSTANT) {
Settings::getInstance()->setString("PowerSaverMode", "default"); Settings::getInstance()->setString("PowerSaverMode", "default");
PowerSaver::init(); PowerSaver::init();
} }
Settings::getInstance()->setBool("EnableNavigationSounds", Settings::getInstance()->setBool("NavigationSounds",
navigationsounds_enabled->getState()); navigation_sounds->getState());
}); });
} }
@ -353,7 +361,7 @@ void GuiMenu::openUISettings()
// Enable filters (ForceDisableFilters). // Enable filters (ForceDisableFilters).
auto enable_filter = std::make_shared<SwitchComponent>(mWindow); auto enable_filter = std::make_shared<SwitchComponent>(mWindow);
enable_filter->setState(!Settings::getInstance()->getBool("ForceDisableFilters")); enable_filter->setState(!Settings::getInstance()->getBool("ForceDisableFilters"));
s->addWithLabel("ENABLE GAMELIST FILTERS", enable_filter); s->addWithLabel("GAMELIST FILTERS", enable_filter);
s->addSaveFunc([enable_filter] { s->addSaveFunc([enable_filter] {
bool filter_is_enabled = !Settings::getInstance()->getBool("ForceDisableFilters"); bool filter_is_enabled = !Settings::getInstance()->getBool("ForceDisableFilters");
Settings::getInstance()->setBool("ForceDisableFilters", !enable_filter->getState()); Settings::getInstance()->setBool("ForceDisableFilters", !enable_filter->getState());
@ -382,13 +390,6 @@ void GuiMenu::openUISettings()
Settings::getInstance()->setBool("MoveCarousel", move_carousel->getState()); Settings::getInstance()->setBool("MoveCarousel", move_carousel->getState());
}); });
// Hide start menu in Kid Mode.
auto disable_start = std::make_shared<SwitchComponent>(mWindow);
disable_start->setState(Settings::getInstance()->getBool("DisableKidStartMenu"));
s->addWithLabel("DISABLE START MENU IN KID MODE", disable_start);
s->addSaveFunc([disable_start] { Settings::getInstance()->setBool("DisableKidStartMenu",
disable_start->getState()); });
// Show help. // Show help.
auto show_help = std::make_shared<SwitchComponent>(mWindow); auto show_help = std::make_shared<SwitchComponent>(mWindow);
show_help->setState(Settings::getInstance()->getBool("ShowHelpPrompts")); show_help->setState(Settings::getInstance()->getBool("ShowHelpPrompts"));
@ -396,6 +397,13 @@ void GuiMenu::openUISettings()
s->addSaveFunc([show_help] { Settings::getInstance()->setBool("ShowHelpPrompts", s->addSaveFunc([show_help] { Settings::getInstance()->setBool("ShowHelpPrompts",
show_help->getState()); }); show_help->getState()); });
// Whether to show start menu in Kid Mode.
auto show_kidstartmenu = std::make_shared<SwitchComponent>(mWindow);
show_kidstartmenu->setState(Settings::getInstance()->getBool("ShowKidStartMenu"));
s->addWithLabel("SHOW START MENU IN KID MODE", show_kidstartmenu);
s->addSaveFunc([show_kidstartmenu] { Settings::getInstance()->setBool("ShowKidStartMenu",
show_kidstartmenu->getState()); });
// Screensaver. // Screensaver.
ComponentListRow screensaver_row; ComponentListRow screensaver_row;
screensaver_row.elements.clear(); screensaver_row.elements.clear();
@ -453,7 +461,7 @@ void GuiMenu::openOtherSettings()
"instant" && power_saver->getSelected() == "instant") { "instant" && power_saver->getSelected() == "instant") {
Settings::getInstance()->setString("TransitionStyle", "instant"); Settings::getInstance()->setString("TransitionStyle", "instant");
Settings::getInstance()->setBool("MoveCarousel", false); Settings::getInstance()->setBool("MoveCarousel", false);
Settings::getInstance()->setBool("EnableNavigationSounds", false); Settings::getInstance()->setBool("NavigationSounds", false);
} }
Settings::getInstance()->setString("PowerSaverMode", power_saver->getSelected()); Settings::getInstance()->setString("PowerSaverMode", power_saver->getSelected());
PowerSaver::init(); PowerSaver::init();
@ -499,10 +507,17 @@ void GuiMenu::openOtherSettings()
// to disable this is intended primarily for testing purposes). // to disable this is intended primarily for testing purposes).
auto launchcommand_override = std::make_shared<SwitchComponent>(mWindow); auto launchcommand_override = std::make_shared<SwitchComponent>(mWindow);
launchcommand_override->setState(Settings::getInstance()->getBool("LaunchCommandOverride")); launchcommand_override->setState(Settings::getInstance()->getBool("LaunchCommandOverride"));
s->addWithLabel("ENABLE PER GAME LAUNCH COMMAND OVERRIDE", launchcommand_override); s->addWithLabel("PER GAME LAUNCH COMMAND OVERRIDE", launchcommand_override);
s->addSaveFunc([launchcommand_override] { Settings::getInstance()-> s->addSaveFunc([launchcommand_override] { Settings::getInstance()->
setBool("LaunchCommandOverride", launchcommand_override->getState()); }); setBool("LaunchCommandOverride", launchcommand_override->getState()); });
// Custom event scripts, fired using Scripting::fireEvent().
auto custom_eventscripts = std::make_shared<SwitchComponent>(mWindow);
custom_eventscripts->setState(Settings::getInstance()->getBool("CustomEventScripts"));
s->addWithLabel("CUSTOM EVENT SCRIPTS", custom_eventscripts);
s->addSaveFunc([custom_eventscripts] { Settings::getInstance()->
setBool("CustomEventScripts", custom_eventscripts->getState()); });
auto parse_gamelists = std::make_shared<SwitchComponent>(mWindow); auto parse_gamelists = std::make_shared<SwitchComponent>(mWindow);
parse_gamelists->setState(Settings::getInstance()->getBool("ParseGamelistOnly")); parse_gamelists->setState(Settings::getInstance()->getBool("ParseGamelistOnly"));
s->addWithLabel("ONLY SHOW ROMS FROM GAMELIST.XML FILES", parse_gamelists); s->addWithLabel("ONLY SHOW ROMS FROM GAMELIST.XML FILES", parse_gamelists);

View file

@ -246,8 +246,8 @@ MDResolveHandle::MDResolveHandle(const ScraperSearchResult& result,
} }
// Resize it. // Resize it.
if (!resizeImage(filePath, Settings::getInstance()->getInt("ScraperResizeWidth"), if (!resizeImage(filePath, Settings::getInstance()->getInt("ScraperResizeMaxWidth"),
Settings::getInstance()->getInt("ScraperResizeHeight"))) { Settings::getInstance()->getInt("ScraperResizeMaxHeight"))) {
setError("Error saving resized image. Out of memory? Disk full?"); setError("Error saving resized image. Out of memory? Disk full?");
return; return;
} }
@ -292,8 +292,8 @@ std::unique_ptr<ImageDownloadHandle> downloadImageAsync(const std::string& url,
url, url,
saveAs, saveAs,
existingMediaFile, existingMediaFile,
Settings::getInstance()->getInt("ScraperResizeWidth"), Settings::getInstance()->getInt("ScraperResizeMaxWidth"),
Settings::getInstance()->getInt("ScraperResizeHeight"))); Settings::getInstance()->getInt("ScraperResizeMaxHeight")));
} }
ImageDownloadHandle::ImageDownloadHandle( ImageDownloadHandle::ImageDownloadHandle(

View file

@ -203,8 +203,8 @@ private:
std::string getSaveAsPath(const ScraperSearchParams& params, std::string getSaveAsPath(const ScraperSearchParams& params,
const std::string& filetypeSubdirectory, const std::string& url); const std::string& filetypeSubdirectory, const std::string& url);
// Will resize according to Settings::getInt("ScraperResizeWidth") and // Will resize according to Settings::getInt("ScraperResizeMaxWidth") and
// Settings::getInt("ScraperResizeHeight"). // Settings::getInt("ScraperResizeMaxHeight").
std::unique_ptr<ImageDownloadHandle> downloadImageAsync(const std::string& url, std::unique_ptr<ImageDownloadHandle> downloadImageAsync(const std::string& url,
const std::string& saveAs, const std::string& existingMediaPath); const std::string& saveAs, const std::string& existingMediaPath);

View file

@ -13,6 +13,7 @@
#include "resources/Font.h" #include "resources/Font.h"
#include "GuiComponent.h" #include "GuiComponent.h"
#include "Sound.h" #include "Sound.h"
#include <memory> #include <memory>
class AnimatedImageComponent; class AnimatedImageComponent;

View file

@ -388,7 +388,7 @@ bool ViewController::input(InputConfig* config, Input input)
// Open menu. // Open menu.
if (!(UIModeController::getInstance()->isUIModeKid() && if (!(UIModeController::getInstance()->isUIModeKid() &&
Settings::getInstance()->getBool("DisableKidStartMenu")) && !Settings::getInstance()->getBool("ShowKidStartMenu")) &&
config->isMappedTo("start", input) && input.value != 0) { config->isMappedTo("start", input) && input.value != 0) {
// If we don't stop the scrolling here, it will continue to // If we don't stop the scrolling here, it will continue to
// run after closing the menu. // run after closing the menu.
@ -564,7 +564,7 @@ std::vector<HelpPrompt> ViewController::getHelpPrompts()
prompts = mCurrentView->getHelpPrompts(); prompts = mCurrentView->getHelpPrompts();
if (!(UIModeController::getInstance()->isUIModeKid() && if (!(UIModeController::getInstance()->isUIModeKid() &&
Settings::getInstance()->getBool("DisableKidStartMenu"))) !Settings::getInstance()->getBool("ShowKidStartMenu")))
prompts.push_back(HelpPrompt("start", "menu")); prompts.push_back(HelpPrompt("start", "menu"));
return prompts; return prompts;
} }

View file

@ -73,7 +73,7 @@ AudioManager::~AudioManager()
std::shared_ptr<AudioManager> & AudioManager::getInstance() std::shared_ptr<AudioManager> & AudioManager::getInstance()
{ {
// Check if an AudioManager instance is already created, if not create one. // Check if an AudioManager instance is already created, if not create one.
if (sInstance == nullptr && Settings::getInstance()->getBool("EnableNavigationSounds")) { if (sInstance == nullptr && Settings::getInstance()->getBool("NavigationSounds")) {
sInstance = std::shared_ptr<AudioManager>(new AudioManager); sInstance = std::shared_ptr<AudioManager>(new AudioManager);
} }
return sInstance; return sInstance;

View file

@ -11,14 +11,19 @@
// //
#include "Scripting.h" #include "Scripting.h"
#include "utils/FileSystemUtil.h"
#include "Log.h" #include "Log.h"
#include "Platform.h" #include "Platform.h"
#include "utils/FileSystemUtil.h" #include "Settings.h"
namespace Scripting namespace Scripting
{ {
void fireEvent(const std::string& eventName, const std::string& arg1, const std::string& arg2) void fireEvent(const std::string& eventName, const std::string& arg1, const std::string& arg2)
{ {
if (!Settings::getInstance()->getBool("CustomEventScripts"))
return;
LOG(LogDebug) << "fireEvent: " << eventName << " " << arg1 << " " << arg2; LOG(LogDebug) << "fireEvent: " << eventName << " " << arg1 << " " << arg2;
std::list<std::string> scriptDirList; std::list<std::string> scriptDirList;

View file

@ -76,7 +76,7 @@ void Settings::setDefaults()
// UI settings. // UI settings.
mStringMap["StartupSystem"] = ""; mStringMap["StartupSystem"] = "";
mStringMap["GamelistViewStyle"] = "automatic"; mStringMap["GamelistViewStyle"] = "detailed";
mStringMap["TransitionStyle"] = "instant"; mStringMap["TransitionStyle"] = "instant";
mStringMap["ThemeSet"] = ""; mStringMap["ThemeSet"] = "";
mStringMap["UIMode"] = "Full"; mStringMap["UIMode"] = "Full";
@ -84,8 +84,8 @@ void Settings::setDefaults()
mBoolMap["ForceDisableFilters"] = false; mBoolMap["ForceDisableFilters"] = false;
mBoolMap["QuickSystemSelect"] = true; mBoolMap["QuickSystemSelect"] = true;
mBoolMap["MoveCarousel"] = true; mBoolMap["MoveCarousel"] = true;
mBoolMap["DisableKidStartMenu"] = true;
mBoolMap["ShowHelpPrompts"] = true; mBoolMap["ShowHelpPrompts"] = true;
mBoolMap["ShowKidStartMenu"] = false;
// UI settings -> scrensaver settings. // UI settings -> scrensaver settings.
mIntMap["ScreenSaverTime"] = 5*60*1000; // 5 minutes mIntMap["ScreenSaverTime"] = 5*60*1000; // 5 minutes
@ -111,17 +111,26 @@ void Settings::setDefaults()
mStringMap["SlideshowScreenSaverImageFilter"] = ".png,.jpg"; mStringMap["SlideshowScreenSaverImageFilter"] = ".png,.jpg";
// Sound settings. // Sound settings.
// 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
// make much sense to be able to select ALSA devices directly. Normally (always?)
// the selection doesn't make any difference at all. But maybe some PulseAudio
// settings could be added later on, if needed.
// The code is still active for Raspberry Pi though as I'm not sure if this is
// useful for that device.
#ifdef _RPI_
mStringMap["AudioCard"] = "default"; mStringMap["AudioCard"] = "default";
// Audio out device for volume control. // Audio out device for volume control.
#ifdef _RPI_ //#endif
//#ifdef _RPI_
mStringMap["AudioDevice"] = "PCM"; mStringMap["AudioDevice"] = "PCM";
#else
mStringMap["AudioDevice"] = "Master";
#endif
mBoolMap["VideoAudio"] = true;
mBoolMap["EnableNavigationSounds"] = true;
// Audio out device for Video playback using OMX player. // Audio out device for Video playback using OMX player.
mStringMap["OMXAudioDev"] = "both"; mStringMap["OMXAudioDev"] = "both";
//#else
// mStringMap["AudioDevice"] = "Master";
#endif
mBoolMap["VideoAudio"] = true;
mBoolMap["NavigationSounds"] = true;
// Game collection settings. // Game collection settings.
mStringMap["CollectionSystemsAuto"] = ""; mStringMap["CollectionSystemsAuto"] = "";
@ -138,7 +147,7 @@ void Settings::setDefaults()
// mBoolMap["ScraperGenerateThumbnails"] = false; // mBoolMap["ScraperGenerateThumbnails"] = false;
mBoolMap["ScraperInteractive"] = true; mBoolMap["ScraperInteractive"] = true;
mBoolMap["ScraperSemiautomatic"] = true; mBoolMap["ScraperSemiautomatic"] = true;
mBoolMap["ScraperOverwriteData"] = false; mBoolMap["ScraperOverwriteData"] = true;
mBoolMap["ScrapeMetadata"] = true; mBoolMap["ScrapeMetadata"] = true;
mBoolMap["ScrapeGameNames"] = true; mBoolMap["ScrapeGameNames"] = true;
mBoolMap["ScrapeRatings"] = true; mBoolMap["ScrapeRatings"] = true;
@ -171,6 +180,7 @@ void Settings::setDefaults()
#endif #endif
mStringMap["SaveGamelistsMode"] = "always"; mStringMap["SaveGamelistsMode"] = "always";
mBoolMap["LaunchCommandOverride"] = true; mBoolMap["LaunchCommandOverride"] = true;
mBoolMap["CustomEventScripts"] = false;
mBoolMap["ParseGamelistOnly"] = false; mBoolMap["ParseGamelistOnly"] = false;
mBoolMap["LocalArt"] = false; mBoolMap["LocalArt"] = false;
mBoolMap["ShowHiddenFiles"] = false; mBoolMap["ShowHiddenFiles"] = false;
@ -209,8 +219,8 @@ void Settings::setDefaults()
mStringMap["DefaultSortOrder"] = "filename, ascending"; mStringMap["DefaultSortOrder"] = "filename, ascending";
mStringMap["MediaDirectory"] = ""; mStringMap["MediaDirectory"] = "";
mStringMap["ROMDirectory"] = ""; mStringMap["ROMDirectory"] = "";
mIntMap["ScraperResizeWidth"] = 600; mIntMap["ScraperResizeMaxWidth"] = 600;
mIntMap["ScraperResizeHeight"] = 0; mIntMap["ScraperResizeMaxHeight"] = 0;
// //
// Hardcoded or program-internal settings. // Hardcoded or program-internal settings.
@ -275,7 +285,7 @@ void Settings::loadFile()
pugi::xml_document doc; pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_file(path.c_str()); pugi::xml_parse_result result = doc.load_file(path.c_str());
if (!result) { if (!result) {
LOG(LogError) << "Could not parse Settings file!\n " << result.description(); LOG(LogError) << "Error - Could not parse Settings file!\n " << result.description();
return; return;
} }
@ -295,7 +305,7 @@ void Settings::loadFile()
type Settings::getMethodName(const std::string& name) \ type Settings::getMethodName(const std::string& name) \
{ \ { \
if (mapName.find(name) == mapName.cend()) { \ if (mapName.find(name) == mapName.cend()) { \
LOG(LogError) << "Tried to use unset setting " << name << "!"; \ LOG(LogError) << "Error - Tried to use unset setting " << name << "!"; \
} \ } \
return mapName[name]; \ return mapName[name]; \
} \ } \

View file

@ -164,7 +164,7 @@ void Sound::play()
if(mSampleData == nullptr) if(mSampleData == nullptr)
return; return;
if(!Settings::getInstance()->getBool("EnableNavigationSounds")) if(!Settings::getInstance()->getBool("NavigationSounds"))
return; return;
AudioManager::getInstance(); AudioManager::getInstance();