Restart Sound in MainForm instead of SoundConfig

This commit is contained in:
YoshiRulz 2020-11-22 12:27:58 +10:00
parent edda120b07
commit bad08162e2
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
3 changed files with 23 additions and 14 deletions

View File

@ -908,17 +908,26 @@ namespace BizHawk.Client.EmuHawk
ESoundOutputMethod.OpenAL => OpenALSoundOutput.GetDeviceNames(), ESoundOutputMethod.OpenAL => OpenALSoundOutput.GetDeviceNames(),
_ => Enumerable.Empty<string>() _ => Enumerable.Empty<string>()
}; };
using var form = new SoundConfig(Config, GetDeviceNamesCallback) { Owner = this }; using var form = new SoundConfig(Config, GetDeviceNamesCallback);
if (form.ShowDialog().IsOk()) if (!form.ShowDialog().IsOk())
{ {
AddOnScreenMessage("Sound config aborted");
return;
}
AddOnScreenMessage("Sound settings saved");
if (form.ApplyNewSoundDevice)
{
Sound.Dispose();
Sound = new Sound(Handle);
Sound.StartSound(); Sound.StartSound();
AddOnScreenMessage("Sound settings saved");
RewireSound();
} }
else else
{ {
AddOnScreenMessage("Sound config aborted"); Sound.StopSound();
Sound.StartSound();
} }
RewireSound();
} }
private void AutofireMenuItem_Click(object sender, EventArgs e) private void AutofireMenuItem_Click(object sender, EventArgs e)

View File

@ -851,7 +851,12 @@ namespace BizHawk.Client.EmuHawk
private GameInfo Game => GlobalWin.Game; private GameInfo Game => GlobalWin.Game;
private Sound Sound => GlobalWin.Sound; private Sound Sound
{
get => GlobalWin.Sound;
set => GlobalWin.Sound = value;
}
public CheatCollection CheatList { get; } public CheatCollection CheatList { get; }
public (HttpCommunication HTTP, MemoryMappedFiles MMF, SocketServer Sockets) NetworkingHelpers { get; } public (HttpCommunication HTTP, MemoryMappedFiles MMF, SocketServer Sockets) NetworkingHelpers { get; }

View File

@ -15,6 +15,8 @@ namespace BizHawk.Client.EmuHawk
private bool _programmaticallyChangingValue; private bool _programmaticallyChangingValue;
public bool ApplyNewSoundDevice { get; private set; }
public SoundConfig(Config config, Func<ESoundOutputMethod, IEnumerable<string>> getDeviceNamesCallback) public SoundConfig(Config config, Func<ESoundOutputMethod, IEnumerable<string>> getDeviceNamesCallback)
{ {
_config = config; _config = config;
@ -80,14 +82,7 @@ namespace BizHawk.Client.EmuHawk
_config.SoundVolume = tbNormal.Value; _config.SoundVolume = tbNormal.Value;
_config.SoundVolumeRWFF = tbRWFF.Value; _config.SoundVolumeRWFF = tbRWFF.Value;
_config.SoundDevice = (string)listBoxSoundDevices.SelectedItem ?? "<default>"; _config.SoundDevice = (string)listBoxSoundDevices.SelectedItem ?? "<default>";
GlobalWin.Sound.StopSound(); ApplyNewSoundDevice = _config.SoundOutputMethod != oldOutputMethod || _config.SoundDevice != oldDevice; // read in MainForm at ShowDialog() callsite
if (_config.SoundOutputMethod != oldOutputMethod
|| _config.SoundDevice != oldDevice)
{
GlobalWin.Sound.Dispose();
GlobalWin.Sound = new Sound(Owner.Handle);
}
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
} }