From c5b1328f77e2adb47930a9eb3d26865e4ce2fe6a Mon Sep 17 00:00:00 2001 From: adelikat Date: Mon, 16 Dec 2019 19:54:40 -0600 Subject: [PATCH] Sound config - pass in Config --- BizHawk.Client.EmuHawk/MainForm.Events.cs | 2 +- BizHawk.Client.EmuHawk/config/RewindConfig.cs | 2 +- BizHawk.Client.EmuHawk/config/SoundConfig.cs | 60 ++++++++++--------- 3 files changed, 33 insertions(+), 31 deletions(-) diff --git a/BizHawk.Client.EmuHawk/MainForm.Events.cs b/BizHawk.Client.EmuHawk/MainForm.Events.cs index 6c35368b31..239f8798e5 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -1001,7 +1001,7 @@ namespace BizHawk.Client.EmuHawk private void SoundMenuItem_Click(object sender, EventArgs e) { - using var form = new SoundConfig(); + using var form = new SoundConfig(Global.Config); if (form.ShowDialog() == DialogResult.OK) { RewireSound(); diff --git a/BizHawk.Client.EmuHawk/config/RewindConfig.cs b/BizHawk.Client.EmuHawk/config/RewindConfig.cs index 66fc4cd80d..078e4d3f84 100644 --- a/BizHawk.Client.EmuHawk/config/RewindConfig.cs +++ b/BizHawk.Client.EmuHawk/config/RewindConfig.cs @@ -380,7 +380,7 @@ namespace BizHawk.Client.EmuHawk private void TrackBarCompression_ValueChanged(object sender, EventArgs e) { - // TODO - make a UserControl which is trackbar and NUD combined + // TODO - make a UserControl which is TrackBar and NUD combined nudCompression.Value = ((TrackBar)sender).Value; } diff --git a/BizHawk.Client.EmuHawk/config/SoundConfig.cs b/BizHawk.Client.EmuHawk/config/SoundConfig.cs index c902d6d2b0..c3f193b131 100644 --- a/BizHawk.Client.EmuHawk/config/SoundConfig.cs +++ b/BizHawk.Client.EmuHawk/config/SoundConfig.cs @@ -10,10 +10,12 @@ namespace BizHawk.Client.EmuHawk { public partial class SoundConfig : Form { + private readonly Config _config; private bool _programmaticallyChangingValue; - public SoundConfig() + public SoundConfig(Config config) { + _config = config; InitializeComponent(); } @@ -21,10 +23,10 @@ namespace BizHawk.Client.EmuHawk { _programmaticallyChangingValue = true; - cbEnableMaster.Checked = Global.Config.SoundEnabled; - cbEnableNormal.Checked = Global.Config.SoundEnabledNormal; - cbEnableRWFF.Checked = Global.Config.SoundEnabledRWFF; - cbMuteFrameAdvance.Checked = Global.Config.MuteFrameAdvance; + cbEnableMaster.Checked = _config.SoundEnabled; + cbEnableNormal.Checked = _config.SoundEnabledNormal; + cbEnableRWFF.Checked = _config.SoundEnabledRWFF; + cbMuteFrameAdvance.Checked = _config.MuteFrameAdvance; if (OSTailoredCode.IsUnixHost) { @@ -33,14 +35,14 @@ namespace BizHawk.Client.EmuHawk rbOutputMethodXAudio2.Enabled = false; } - rbOutputMethodDirectSound.Checked = Global.Config.SoundOutputMethod == Config.ESoundOutputMethod.DirectSound; - rbOutputMethodXAudio2.Checked = Global.Config.SoundOutputMethod == Config.ESoundOutputMethod.XAudio2; - rbOutputMethodOpenAL.Checked = Global.Config.SoundOutputMethod == Config.ESoundOutputMethod.OpenAL; - BufferSizeNumeric.Value = Global.Config.SoundBufferSizeMs; - tbNormal.Value = Global.Config.SoundVolume; - nudNormal.Value = Global.Config.SoundVolume; - tbRWFF.Value = Global.Config.SoundVolumeRWFF; - nudRWFF.Value = Global.Config.SoundVolumeRWFF; + rbOutputMethodDirectSound.Checked = _config.SoundOutputMethod == Config.ESoundOutputMethod.DirectSound; + rbOutputMethodXAudio2.Checked = _config.SoundOutputMethod == Config.ESoundOutputMethod.XAudio2; + rbOutputMethodOpenAL.Checked = _config.SoundOutputMethod == Config.ESoundOutputMethod.OpenAL; + BufferSizeNumeric.Value = _config.SoundBufferSizeMs; + tbNormal.Value = _config.SoundVolume; + nudNormal.Value = _config.SoundVolume; + tbRWFF.Value = _config.SoundVolumeRWFF; + nudRWFF.Value = _config.SoundVolumeRWFF; UpdateSoundDialog(); _programmaticallyChangingValue = false; @@ -53,22 +55,22 @@ namespace BizHawk.Client.EmuHawk MessageBox.Show("Buffer size must be at least 60 milliseconds for DirectSound.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - var oldOutputMethod = Global.Config.SoundOutputMethod; - var oldDevice = Global.Config.SoundDevice; - Global.Config.SoundEnabled = cbEnableMaster.Checked; - Global.Config.SoundEnabledNormal = cbEnableNormal.Checked; - Global.Config.SoundEnabledRWFF = cbEnableRWFF.Checked; - Global.Config.MuteFrameAdvance = cbMuteFrameAdvance.Checked; - if (rbOutputMethodDirectSound.Checked) Global.Config.SoundOutputMethod = Config.ESoundOutputMethod.DirectSound; - if (rbOutputMethodXAudio2.Checked) Global.Config.SoundOutputMethod = Config.ESoundOutputMethod.XAudio2; - if (rbOutputMethodOpenAL.Checked) Global.Config.SoundOutputMethod = Config.ESoundOutputMethod.OpenAL; - Global.Config.SoundBufferSizeMs = (int)BufferSizeNumeric.Value; - Global.Config.SoundVolume = tbNormal.Value; - Global.Config.SoundVolumeRWFF = tbRWFF.Value; - Global.Config.SoundDevice = (string)listBoxSoundDevices.SelectedItem ?? ""; + var oldOutputMethod = _config.SoundOutputMethod; + var oldDevice = _config.SoundDevice; + _config.SoundEnabled = cbEnableMaster.Checked; + _config.SoundEnabledNormal = cbEnableNormal.Checked; + _config.SoundEnabledRWFF = cbEnableRWFF.Checked; + _config.MuteFrameAdvance = cbMuteFrameAdvance.Checked; + if (rbOutputMethodDirectSound.Checked) _config.SoundOutputMethod = Config.ESoundOutputMethod.DirectSound; + if (rbOutputMethodXAudio2.Checked) _config.SoundOutputMethod = Config.ESoundOutputMethod.XAudio2; + if (rbOutputMethodOpenAL.Checked) _config.SoundOutputMethod = Config.ESoundOutputMethod.OpenAL; + _config.SoundBufferSizeMs = (int)BufferSizeNumeric.Value; + _config.SoundVolume = tbNormal.Value; + _config.SoundVolumeRWFF = tbRWFF.Value; + _config.SoundDevice = (string)listBoxSoundDevices.SelectedItem ?? ""; GlobalWin.Sound.StopSound(); - if (Global.Config.SoundOutputMethod != oldOutputMethod - || Global.Config.SoundDevice != oldDevice) + if (_config.SoundOutputMethod != oldOutputMethod + || _config.SoundDevice != oldDevice) { GlobalWin.Sound.Dispose(); GlobalWin.Sound = new Sound(GlobalWin.MainForm.Handle); @@ -101,7 +103,7 @@ namespace BizHawk.Client.EmuHawk foreach (var name in deviceNames) { listBoxSoundDevices.Items.Add(name); - if (name == Global.Config.SoundDevice) + if (name == _config.SoundDevice) { listBoxSoundDevices.SelectedItem = name; }