GlobalSettings.cc 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "GlobalSettings.hh"
  2. #include "SettingsConfig.hh"
  3. #include "GlobalCommandController.hh"
  4. #include "strCat.hh"
  5. #include "view.hh"
  6. #include "xrange.hh"
  7. #include "build-info.hh"
  8. #include <memory>
  9. #include <SDL.h>
  10. namespace openmsx {
  11. GlobalSettings::GlobalSettings(GlobalCommandController& commandController_)
  12. : commandController(commandController_)
  13. , pauseSetting(commandController, "pause",
  14. "pauses the emulation", false, Setting::DONT_SAVE)
  15. , powerSetting(commandController, "power",
  16. "turn power on/off", false, Setting::DONT_SAVE)
  17. , autoSaveSetting(commandController, "save_settings_on_exit",
  18. "automatically save settings when openMSX exits", true)
  19. , umrCallBackSetting(commandController, "umr_callback",
  20. "Tcl proc to call when an UMR is detected", {})
  21. , invalidPsgDirectionsSetting(commandController,
  22. "invalid_psg_directions_callback",
  23. "Tcl proc called when the MSX program has set invalid PSG port directions",
  24. {})
  25. , invalidPpiModeSetting(commandController,
  26. "invalid_ppi_mode_callback",
  27. "Tcl proc called when the MSX program has set an invalid PPI mode",
  28. {})
  29. , resampleSetting(commandController, "resampler", "Resample algorithm",
  30. #if PLATFORM_DINGUX
  31. // For Dingux, LQ is good compromise between quality and performance
  32. ResampledSoundDevice::RESAMPLE_LQ,
  33. #elif PLATFORM_ANDROID
  34. // For Android, BLIP is good compromise between quality and performance
  35. ResampledSoundDevice::RESAMPLE_BLIP,
  36. #else
  37. // For other platforms, default setting may be changed in future
  38. ResampledSoundDevice::RESAMPLE_BLIP,
  39. #endif
  40. EnumSetting<ResampledSoundDevice::ResampleType>::Map{
  41. {"hq", ResampledSoundDevice::RESAMPLE_HQ},
  42. {"fast", ResampledSoundDevice::RESAMPLE_LQ},
  43. {"blip", ResampledSoundDevice::RESAMPLE_BLIP}})
  44. , speedManager(commandController)
  45. , throttleManager(commandController)
  46. {
  47. deadzoneSettings = to_vector(
  48. view::transform(xrange(SDL_NumJoysticks()), [&](auto i) {
  49. return std::make_unique<IntegerSetting>(
  50. commandController,
  51. strCat("joystick", i + 1, "_deadzone"),
  52. "size (as a percentage) of the dead center zone",
  53. 25, 0, 100);
  54. }));
  55. getPowerSetting().attach(*this);
  56. }
  57. GlobalSettings::~GlobalSettings()
  58. {
  59. getPowerSetting().detach(*this);
  60. commandController.getSettingsConfig().setSaveSettings(
  61. autoSaveSetting.getBoolean());
  62. }
  63. // Observer<Setting>
  64. void GlobalSettings::update(const Setting& setting)
  65. {
  66. if (&setting == &getPowerSetting()) { // either on or off
  67. // automatically unpause after a power off/on cycle
  68. // this solved a bug, but apart from that this behaviour also
  69. // makes more sense
  70. getPauseSetting().setBoolean(false);
  71. }
  72. }
  73. } // namespace openmsx