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(),
_ => Enumerable.Empty<string>()
};
using var form = new SoundConfig(Config, GetDeviceNamesCallback) { Owner = this };
if (form.ShowDialog().IsOk())
using var form = new SoundConfig(Config, GetDeviceNamesCallback);
if (!form.ShowDialog().IsOk())
{
AddOnScreenMessage("Sound config aborted");
return;
}
AddOnScreenMessage("Sound settings saved");
if (form.ApplyNewSoundDevice)
{
Sound.Dispose();
Sound = new Sound(Handle);
Sound.StartSound();
AddOnScreenMessage("Sound settings saved");
RewireSound();
}
else
{
AddOnScreenMessage("Sound config aborted");
Sound.StopSound();
Sound.StartSound();
}
RewireSound();
}
private void AutofireMenuItem_Click(object sender, EventArgs e)

View File

@ -851,7 +851,12 @@ namespace BizHawk.Client.EmuHawk
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 (HttpCommunication HTTP, MemoryMappedFiles MMF, SocketServer Sockets) NetworkingHelpers { get; }

View File

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