BizHawk/BizHawk.Client.EmuHawk/config/SoundConfig.cs

153 lines
4.7 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Common;
namespace BizHawk.Client.EmuHawk
{
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;
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-06-12 00:14:19 +00:00
private void SoundConfig_Load(object sender, EventArgs e)
{
_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;
if (OSTailoredCode.IsUnixHost)
{
// 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();
_programmaticallyChangingValue = false;
2011-06-12 00:14:19 +00:00
}
private void Ok_Click(object sender, EventArgs e)
2011-06-12 00:14:19 +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>";
GlobalWin.Sound.StopSound();
2019-12-17 01:54:40 +00:00
if (_config.SoundOutputMethod != oldOutputMethod
|| _config.SoundDevice != oldDevice)
{
GlobalWin.Sound.Dispose();
2019-12-31 23:14:04 +00:00
GlobalWin.Sound = new Sound(Owner.Handle);
}
DialogResult = DialogResult.OK;
2011-06-12 00:14:19 +00:00
}
2011-06-12 00:14:19 +00:00
private void Cancel_Click(object sender, EventArgs e)
{
Close();
2011-06-12 00:14:19 +00:00
}
private void PopulateDeviceList()
{
IEnumerable<string> deviceNames = Enumerable.Empty<string>();
if (!OSTailoredCode.IsUnixHost)
{
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();
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)
{
listBoxSoundDevices.SelectedItem = name;
}
}
}
private void OutputMethodRadioButtons_CheckedChanged(object sender, EventArgs e)
{
if (!((RadioButton)sender).Checked)
{
return;
}
PopulateDeviceList();
}
private void TrackBar1_Scroll(object sender, EventArgs e)
2011-06-12 00:14:19 +00:00
{
nudNormal.Value = tbNormal.Value;
}
private void TbRwff_Scroll(object sender, EventArgs e)
{
nudRWFF.Value = tbRWFF.Value;
2011-06-12 00:14:19 +00:00
}
2011-06-12 00:14:19 +00:00
private void SoundVolNumeric_ValueChanged(object sender, EventArgs e)
{
tbNormal.Value = (int)nudNormal.Value;
// If the user is changing the volume, automatically turn on/off sound accordingly
if (!_programmaticallyChangingValue)
{
cbEnableNormal.Checked = tbNormal.Value != 0;
}
2011-06-12 00:14:19 +00:00
}
private void UpdateSoundDialog()
2011-06-12 00:14:19 +00:00
{
cbEnableRWFF.Enabled = cbEnableNormal.Checked;
grpSoundVol.Enabled = cbEnableMaster.Checked;
2011-06-12 00:14:19 +00:00
}
private void UpdateSoundDialog(object sender, EventArgs e)
2011-06-12 00:14:19 +00:00
{
UpdateSoundDialog();
2011-06-12 00:14:19 +00:00
}
}
}