OXYGENHUB
◆ main openmsx / src / GlobalSettings.cc
2.1 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#include "GlobalSettings.hh"
2
3
#include "GlobalCommandController.hh"
4
#include "SettingsConfig.hh"
5
6
namespace openmsx {
7
8
GlobalSettings::GlobalSettings(GlobalCommandController& commandController_)
9
	: commandController(commandController_)
10
	, pauseSetting(commandController, "pause",
11
	       "pauses the emulation", false, Setting::Save::NO)
12
	, powerSetting(commandController, "power",
13
	        "turn power on/off", false, Setting::Save::NO)
14
	, autoSaveSetting(commandController, "save_settings_on_exit",
15
	        "automatically save settings when openMSX exits", true)
16
	, umrCallBackSetting(commandController, "umr_callback",
17
		"Tcl proc to call when an UMR is detected", {})
18
	, invalidPsgDirectionsSetting(commandController,
19
		"invalid_psg_directions_callback",
20
		"Tcl proc called when the MSX program has set invalid PSG port directions",
21
		"default_invalid_psg_directions_callback")
22
	, invalidPpiModeSetting(commandController,
23
		"invalid_ppi_mode_callback",
24
		"Tcl proc called when the MSX program has set an invalid PPI mode",
25
		"default_invalid_ppi_mode_callback")
26
	, resampleSetting(commandController, "resampler", "Resample algorithm",
27
		ResampledSoundDevice::ResampleType::HQ,
28
		EnumSetting<ResampledSoundDevice::ResampleType>::Map{
29
			{"hq",   ResampledSoundDevice::ResampleType::HQ},
30
			{"blip", ResampledSoundDevice::ResampleType::BLIP}})
31
	, speedManager(commandController)
32
	, throttleManager(commandController)
33
{
34
	getPowerSetting().attach(*this);
35
}
36
37
GlobalSettings::~GlobalSettings()
38
{
39
	getPowerSetting().detach(*this);
40
	commandController.getSettingsConfig().setSaveSettings(
41
		autoSaveSetting.getBoolean());
42
}
43
44
// Observer<Setting>
45
void GlobalSettings::update(const Setting& setting) noexcept
46
{
47
	if (&setting == &getPowerSetting()) { // either on or off
48
		// automatically unpause after a power off/on cycle
49
		// this solved a bug, but apart from that this behaviour also
50
		// makes more sense
51
		try {
52
			getPauseSetting().setBoolean(false);
53
		} catch(...) {
54
			// Ignore. E.g. can trigger when a Tcl trace on the
55
			// pause setting triggers errors in the Tcl script.
56
		}
57
	}
58
}
59
60
} // namespace openmsx