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

118 lines
3.8 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
2011-06-12 00:14:19 +00:00
public partial class SoundConfig : Form
{
private bool _programmaticallyChangingValue;
2011-06-12 00:14:19 +00:00
public SoundConfig()
{
InitializeComponent();
}
2011-06-12 00:14:19 +00:00
private void SoundConfig_Load(object sender, EventArgs e)
{
_programmaticallyChangingValue = true;
2011-06-12 00:14:19 +00:00
SoundOnCheckBox.Checked = Global.Config.SoundEnabled;
MuteFrameAdvance.Checked = Global.Config.MuteFrameAdvance;
rbOutputMethodDirectSound.Checked = Global.Config.SoundOutputMethod == Config.ESoundOutputMethod.DirectSound;
rbOutputMethodXAudio2.Checked = Global.Config.SoundOutputMethod == Config.ESoundOutputMethod.XAudio2;
BufferSizeNumeric.Value = Global.Config.SoundBufferSizeMs;
2011-06-12 00:14:19 +00:00
SoundVolBar.Value = Global.Config.SoundVolume;
SoundVolNumeric.Value = Global.Config.SoundVolume;
UpdateSoundDialog();
_programmaticallyChangingValue = false;
2011-06-12 00:14:19 +00:00
}
2011-06-12 00:14:19 +00:00
private void OK_Click(object sender, EventArgs e)
{
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;
}
var oldOutputMethod = Global.Config.SoundOutputMethod;
2011-06-12 00:14:19 +00:00
Global.Config.SoundEnabled = SoundOnCheckBox.Checked;
Global.Config.MuteFrameAdvance = MuteFrameAdvance.Checked;
if (rbOutputMethodDirectSound.Checked) Global.Config.SoundOutputMethod = Config.ESoundOutputMethod.DirectSound;
if (rbOutputMethodXAudio2.Checked) Global.Config.SoundOutputMethod = Config.ESoundOutputMethod.XAudio2;
Global.Config.SoundBufferSizeMs = (int)BufferSizeNumeric.Value;
2011-06-12 00:14:19 +00:00
Global.Config.SoundVolume = SoundVolBar.Value;
Global.Config.SoundDevice = (string)listBoxSoundDevices.SelectedItem ?? "<default>";
GlobalWin.Sound.StopSound();
if (Global.Config.SoundOutputMethod != oldOutputMethod)
{
GlobalWin.Sound.Dispose();
GlobalWin.Sound = new Sound(GlobalWin.MainForm.Handle);
}
GlobalWin.Sound.StartSound();
GlobalWin.OSD.AddMessage("Sound settings saved");
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)
{
GlobalWin.OSD.AddMessage("Sound config aborted");
Close();
2011-06-12 00:14:19 +00:00
}
private void PopulateDeviceList()
{
IEnumerable<string> deviceNames = Enumerable.Empty<string>();
#if WINDOWS
if (rbOutputMethodDirectSound.Checked) deviceNames = DirectSoundSoundOutput.GetDeviceNames();
if (rbOutputMethodXAudio2.Checked) deviceNames = XAudio2SoundOutput.GetDeviceNames();
#endif
listBoxSoundDevices.Items.Clear();
listBoxSoundDevices.Items.Add("<default>");
listBoxSoundDevices.SelectedIndex = 0;
foreach (var name in deviceNames)
{
listBoxSoundDevices.Items.Add(name);
if (name == Global.Config.SoundDevice)
{
listBoxSoundDevices.SelectedItem = name;
}
}
}
private void OutputMethodRadioButtons_CheckedChanged(object sender, EventArgs e)
{
if (!((RadioButton)sender).Checked) return;
PopulateDeviceList();
}
2011-06-12 00:14:19 +00:00
private void trackBar1_Scroll(object sender, EventArgs e)
{
SoundVolNumeric.Value = SoundVolBar.Value;
}
2011-06-12 00:14:19 +00:00
private void SoundVolNumeric_ValueChanged(object sender, EventArgs e)
{
SoundVolBar.Value = (int)SoundVolNumeric.Value;
// If the user is changing the volume, automatically turn on/off sound accordingly
if (!_programmaticallyChangingValue)
SoundOnCheckBox.Checked = SoundVolBar.Value != 0;
2011-06-12 00:14:19 +00:00
}
2011-06-12 00:14:19 +00:00
private void SoundOnCheckBox_CheckedChanged(object sender, EventArgs e)
{
UpdateSoundDialog();
}
2011-06-12 00:14:19 +00:00
private void UpdateSoundDialog()
{
MuteFrameAdvance.Enabled = SoundOnCheckBox.Checked;
2011-06-12 00:14:19 +00:00
}
}
}