2011-02-15 19:05:21 +00:00
|
|
|
|
using System;
|
2015-01-31 06:40:14 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2011-02-15 19:05:21 +00:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2013-10-25 00:57:23 +00:00
|
|
|
|
using BizHawk.Client.Common;
|
2019-05-18 10:17:02 +00:00
|
|
|
|
using BizHawk.Common;
|
2013-10-25 00:57:23 +00:00
|
|
|
|
|
2013-11-03 03:54:37 +00:00
|
|
|
|
namespace BizHawk.Client.EmuHawk
|
2011-02-15 19:05:21 +00:00
|
|
|
|
{
|
2011-06-12 00:14:19 +00:00
|
|
|
|
public partial class SoundConfig : Form
|
|
|
|
|
{
|
2019-12-17 01:54:40 +00:00
|
|
|
|
private readonly Config _config;
|
2015-01-04 16:48:11 +00:00
|
|
|
|
private bool _programmaticallyChangingValue;
|
|
|
|
|
|
2019-12-17 01:54:40 +00:00
|
|
|
|
public SoundConfig(Config config)
|
2011-06-12 00:14:19 +00:00
|
|
|
|
{
|
2019-12-17 01:54:40 +00:00
|
|
|
|
_config = config;
|
2011-06-12 00:14:19 +00:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
2011-02-15 19:05:21 +00:00
|
|
|
|
|
2011-06-12 00:14:19 +00:00
|
|
|
|
private void SoundConfig_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
2015-01-04 16:48:11 +00:00
|
|
|
|
_programmaticallyChangingValue = true;
|
|
|
|
|
|
2019-12-17 01:54:40 +00:00
|
|
|
|
cbEnableMaster.Checked = _config.SoundEnabled;
|
|
|
|
|
cbEnableNormal.Checked = _config.SoundEnabledNormal;
|
|
|
|
|
cbEnableRWFF.Checked = _config.SoundEnabledRWFF;
|
|
|
|
|
cbMuteFrameAdvance.Checked = _config.MuteFrameAdvance;
|
2019-05-18 10:17:02 +00:00
|
|
|
|
|
2019-11-04 04:30:05 +00:00
|
|
|
|
if (OSTailoredCode.IsUnixHost)
|
2019-05-18 10:17:02 +00:00
|
|
|
|
{
|
|
|
|
|
// Disable DirectSound and XAudio2 on Mono
|
|
|
|
|
rbOutputMethodDirectSound.Enabled = false;
|
|
|
|
|
rbOutputMethodXAudio2.Enabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-17 01:54:40 +00:00
|
|
|
|
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;
|
2011-06-12 00:14:19 +00:00
|
|
|
|
UpdateSoundDialog();
|
2012-10-04 02:05:07 +00:00
|
|
|
|
|
2015-01-04 16:48:11 +00:00
|
|
|
|
_programmaticallyChangingValue = false;
|
2011-06-12 00:14:19 +00:00
|
|
|
|
}
|
2011-02-15 19:05:21 +00:00
|
|
|
|
|
2017-05-31 15:28:06 +00:00
|
|
|
|
private void Ok_Click(object sender, EventArgs e)
|
2011-06-12 00:14:19 +00:00
|
|
|
|
{
|
2015-01-31 06:40:14 +00:00
|
|
|
|
if (rbOutputMethodDirectSound.Checked && (int)BufferSizeNumeric.Value < 60)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Buffer size must be at least 60 milliseconds for DirectSound.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-12-17 01:54:40 +00:00
|
|
|
|
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 ?? "<default>";
|
2015-01-25 03:33:45 +00:00
|
|
|
|
GlobalWin.Sound.StopSound();
|
2019-12-17 01:54:40 +00:00
|
|
|
|
if (_config.SoundOutputMethod != oldOutputMethod
|
|
|
|
|
|| _config.SoundDevice != oldDevice)
|
2015-01-31 06:40:14 +00:00
|
|
|
|
{
|
|
|
|
|
GlobalWin.Sound.Dispose();
|
2019-12-31 23:14:04 +00:00
|
|
|
|
GlobalWin.Sound = new Sound(Owner.Handle);
|
2015-01-31 06:40:14 +00:00
|
|
|
|
}
|
2017-05-31 15:28:06 +00:00
|
|
|
|
|
2015-01-31 06:40:14 +00:00
|
|
|
|
DialogResult = DialogResult.OK;
|
2011-06-12 00:14:19 +00:00
|
|
|
|
}
|
2011-02-15 20:18:12 +00:00
|
|
|
|
|
2011-06-12 00:14:19 +00:00
|
|
|
|
private void Cancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2013-11-28 01:33:38 +00:00
|
|
|
|
Close();
|
2011-06-12 00:14:19 +00:00
|
|
|
|
}
|
2011-05-23 21:31:29 +00:00
|
|
|
|
|
2015-01-31 06:40:14 +00:00
|
|
|
|
private void PopulateDeviceList()
|
|
|
|
|
{
|
|
|
|
|
IEnumerable<string> deviceNames = Enumerable.Empty<string>();
|
2019-11-04 04:30:05 +00:00
|
|
|
|
if (!OSTailoredCode.IsUnixHost)
|
2019-05-18 10:17:02 +00:00
|
|
|
|
{
|
|
|
|
|
if (rbOutputMethodDirectSound.Checked) deviceNames = DirectSoundSoundOutput.GetDeviceNames();
|
|
|
|
|
if (rbOutputMethodXAudio2.Checked) deviceNames = XAudio2SoundOutput.GetDeviceNames();
|
|
|
|
|
}
|
2015-02-19 06:00:07 +00:00
|
|
|
|
if (rbOutputMethodOpenAL.Checked) deviceNames = OpenALSoundOutput.GetDeviceNames();
|
2019-05-18 10:17:02 +00:00
|
|
|
|
|
2015-01-31 06:40:14 +00:00
|
|
|
|
listBoxSoundDevices.Items.Clear();
|
|
|
|
|
listBoxSoundDevices.Items.Add("<default>");
|
|
|
|
|
listBoxSoundDevices.SelectedIndex = 0;
|
|
|
|
|
foreach (var name in deviceNames)
|
|
|
|
|
{
|
|
|
|
|
listBoxSoundDevices.Items.Add(name);
|
2019-12-17 01:54:40 +00:00
|
|
|
|
if (name == _config.SoundDevice)
|
2015-01-31 06:40:14 +00:00
|
|
|
|
{
|
|
|
|
|
listBoxSoundDevices.SelectedItem = name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OutputMethodRadioButtons_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-05-31 15:28:06 +00:00
|
|
|
|
if (!((RadioButton)sender).Checked)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-31 06:40:14 +00:00
|
|
|
|
PopulateDeviceList();
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 15:28:06 +00:00
|
|
|
|
private void TrackBar1_Scroll(object sender, EventArgs e)
|
2011-06-12 00:14:19 +00:00
|
|
|
|
{
|
2016-03-29 08:40:37 +00:00
|
|
|
|
nudNormal.Value = tbNormal.Value;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 15:28:06 +00:00
|
|
|
|
private void TbRwff_Scroll(object sender, EventArgs e)
|
2016-03-29 08:40:37 +00:00
|
|
|
|
{
|
|
|
|
|
nudRWFF.Value = tbRWFF.Value;
|
2011-06-12 00:14:19 +00:00
|
|
|
|
}
|
2011-05-23 21:31:29 +00:00
|
|
|
|
|
2011-06-12 00:14:19 +00:00
|
|
|
|
private void SoundVolNumeric_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2016-03-29 08:40:37 +00:00
|
|
|
|
tbNormal.Value = (int)nudNormal.Value;
|
2015-01-04 16:48:11 +00:00
|
|
|
|
|
|
|
|
|
// If the user is changing the volume, automatically turn on/off sound accordingly
|
|
|
|
|
if (!_programmaticallyChangingValue)
|
2017-05-31 15:28:06 +00:00
|
|
|
|
{
|
2016-03-29 08:40:37 +00:00
|
|
|
|
cbEnableNormal.Checked = tbNormal.Value != 0;
|
2017-05-31 15:28:06 +00:00
|
|
|
|
}
|
2011-06-12 00:14:19 +00:00
|
|
|
|
}
|
2011-05-25 01:33:54 +00:00
|
|
|
|
|
2016-03-29 08:40:37 +00:00
|
|
|
|
private void UpdateSoundDialog()
|
2011-06-12 00:14:19 +00:00
|
|
|
|
{
|
2016-03-29 08:40:37 +00:00
|
|
|
|
cbEnableRWFF.Enabled = cbEnableNormal.Checked;
|
|
|
|
|
grpSoundVol.Enabled = cbEnableMaster.Checked;
|
2011-06-12 00:14:19 +00:00
|
|
|
|
}
|
2015-01-23 04:16:25 +00:00
|
|
|
|
|
2016-03-29 08:40:37 +00:00
|
|
|
|
private void UpdateSoundDialog(object sender, EventArgs e)
|
2011-06-12 00:14:19 +00:00
|
|
|
|
{
|
2016-03-29 08:40:37 +00:00
|
|
|
|
UpdateSoundDialog();
|
2011-06-12 00:14:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-15 19:05:21 +00:00
|
|
|
|
}
|