openMSX
GlobalSettings.cc
Go to the documentation of this file.
1 #include "GlobalSettings.hh"
2 #include "SettingsConfig.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 
11 namespace openmsx {
12 
14  : commandController(commandController_)
15  , speedSetting(commandController, "speed",
16  "controls the emulation speed: higher is faster, 100 is normal",
17  100, 1, 1000000)
18  , pauseSetting(commandController, "pause",
19  "pauses the emulation", false, Setting::DONT_SAVE)
20  , powerSetting(commandController, "power",
21  "turn power on/off", false, Setting::DONT_SAVE)
22  , autoSaveSetting(commandController, "save_settings_on_exit",
23  "automatically save settings when openMSX exits", true)
24  , pauseOnLostFocusSetting(commandController, "pause_on_lost_focus",
25  "pause emulation when the openMSX window loses focus", false)
26  , umrCallBackSetting(commandController, "umr_callback",
27  "Tcl proc to call when an UMR is detected", {})
28  , invalidPsgDirectionsSetting(commandController,
29  "invalid_psg_directions_callback",
30  "Tcl proc called when the MSX program has set invalid PSG port directions",
31  {})
32  , resampleSetting(commandController, "resampler", "Resample algorithm",
33 #if PLATFORM_DINGUX
34  // For Dingux, LQ is good compromise between quality and performance
36 #elif PLATFORM_ANDROID
37  // For Android, BLIP is good compromise between quality and performance
39 #else
40  // For other platforms, default setting may be changed in future
41  ResampledSoundDevice::RESAMPLE_BLIP,
42 #endif
45  {"fast", ResampledSoundDevice::RESAMPLE_LQ},
46  {"blip", ResampledSoundDevice::RESAMPLE_BLIP}})
47  , throttleManager(commandController)
48 {
49  deadzoneSettings = to_vector(
50  view::transform(xrange(SDL_NumJoysticks()), [&](auto i) {
51  return std::make_unique<IntegerSetting>(
52  commandController,
53  strCat("joystick", i + 1, "_deadzone"),
54  "size (as a percentage) of the dead center zone",
55  25, 0, 100);
56  }));
57  getPowerSetting().attach(*this);
58 }
59 
61 {
62  getPowerSetting().detach(*this);
63  commandController.getSettingsConfig().setSaveSettings(
64  autoSaveSetting.getBoolean());
65 }
66 
67 // Observer<Setting>
68 void GlobalSettings::update(const Setting& setting)
69 {
70  if (&setting == &getPowerSetting()) { // either on or off
71  // automatically unpause after a power off/on cycle
72  // this solved a bug, but apart from that this behaviour also
73  // makes more sense
74  getPauseSetting().setBoolean(false);
75  }
76 }
77 
78 } // namespace openmsx
auto transform(Range &&range, UnaryOp op)
Definition: view.hh:312
auto xrange(T e)
Definition: xrange.hh:170
BooleanSetting & getPauseSetting()
BooleanSetting & getPowerSetting()
void setSaveSettings(bool save)
void attach(Observer< T > &observer)
Definition: Subject.hh:45
GlobalSettings(GlobalCommandController &commandController)
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void detach(Observer< T > &observer)
Definition: Subject.hh:51
std::string strCat(Ts &&...ts)
Definition: strCat.hh:577
auto to_vector(Range &&range) -> std::vector< detail::ToVectorType< T, decltype(std::begin(range))>>
Definition: stl.hh:325