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;
|
|
|
|
|
|
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
|
|
|
|
|
{
|
2015-01-04 16:48:11 +00:00
|
|
|
|
private bool _programmaticallyChangingValue;
|
|
|
|
|
|
2011-06-12 00:14:19 +00:00
|
|
|
|
public SoundConfig()
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
2011-06-12 00:14:19 +00:00
|
|
|
|
SoundOnCheckBox.Checked = Global.Config.SoundEnabled;
|
|
|
|
|
MuteFrameAdvance.Checked = Global.Config.MuteFrameAdvance;
|
2015-01-31 06:40:14 +00:00
|
|
|
|
rbOutputMethodDirectSound.Checked = Global.Config.SoundOutputMethod == Config.ESoundOutputMethod.DirectSound;
|
|
|
|
|
rbOutputMethodXAudio2.Checked = Global.Config.SoundOutputMethod == Config.ESoundOutputMethod.XAudio2;
|
2015-01-25 03:33:45 +00:00
|
|
|
|
BufferSizeNumeric.Value = Global.Config.SoundBufferSizeMs;
|
2011-06-12 00:14:19 +00:00
|
|
|
|
SoundVolBar.Value = Global.Config.SoundVolume;
|
|
|
|
|
SoundVolNumeric.Value = Global.Config.SoundVolume;
|
|
|
|
|
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
|
|
|
|
|
2011-06-12 00:14:19 +00:00
|
|
|
|
private void OK_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
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;
|
|
|
|
|
}
|
|
|
|
|
var oldOutputMethod = Global.Config.SoundOutputMethod;
|
2011-06-12 00:14:19 +00:00
|
|
|
|
Global.Config.SoundEnabled = SoundOnCheckBox.Checked;
|
|
|
|
|
Global.Config.MuteFrameAdvance = MuteFrameAdvance.Checked;
|
2015-01-31 06:40:14 +00:00
|
|
|
|
if (rbOutputMethodDirectSound.Checked) Global.Config.SoundOutputMethod = Config.ESoundOutputMethod.DirectSound;
|
|
|
|
|
if (rbOutputMethodXAudio2.Checked) Global.Config.SoundOutputMethod = Config.ESoundOutputMethod.XAudio2;
|
2015-01-25 03:33:45 +00:00
|
|
|
|
Global.Config.SoundBufferSizeMs = (int)BufferSizeNumeric.Value;
|
2011-06-12 00:14:19 +00:00
|
|
|
|
Global.Config.SoundVolume = SoundVolBar.Value;
|
2013-06-02 00:49:40 +00:00
|
|
|
|
Global.Config.SoundDevice = (string)listBoxSoundDevices.SelectedItem ?? "<default>";
|
2015-01-25 03:33:45 +00:00
|
|
|
|
GlobalWin.Sound.StopSound();
|
2015-01-31 06:40:14 +00:00
|
|
|
|
if (Global.Config.SoundOutputMethod != oldOutputMethod)
|
|
|
|
|
{
|
|
|
|
|
GlobalWin.Sound.Dispose();
|
|
|
|
|
GlobalWin.Sound = new Sound(GlobalWin.MainForm.Handle);
|
|
|
|
|
}
|
2013-11-03 16:07:58 +00:00
|
|
|
|
GlobalWin.Sound.StartSound();
|
|
|
|
|
GlobalWin.OSD.AddMessage("Sound settings saved");
|
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-03 16:07:58 +00:00
|
|
|
|
GlobalWin.OSD.AddMessage("Sound config aborted");
|
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>();
|
2015-02-19 02:30:55 +00:00
|
|
|
|
#if WINDOWS
|
2015-01-31 06:40:14 +00:00
|
|
|
|
if (rbOutputMethodDirectSound.Checked) deviceNames = DirectSoundSoundOutput.GetDeviceNames();
|
|
|
|
|
if (rbOutputMethodXAudio2.Checked) deviceNames = XAudio2SoundOutput.GetDeviceNames();
|
2015-02-19 02:30:55 +00:00
|
|
|
|
#endif
|
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);
|
|
|
|
|
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-05-23 21:31:29 +00:00
|
|
|
|
|
2011-06-12 00:14:19 +00:00
|
|
|
|
private void SoundVolNumeric_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
SoundVolBar.Value = (int)SoundVolNumeric.Value;
|
2015-01-04 16:48:11 +00:00
|
|
|
|
|
|
|
|
|
// 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-05-25 01:33:54 +00:00
|
|
|
|
|
2011-06-12 00:14:19 +00:00
|
|
|
|
private void SoundOnCheckBox_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
UpdateSoundDialog();
|
|
|
|
|
}
|
2015-01-23 04:16:25 +00:00
|
|
|
|
|
2011-06-12 00:14:19 +00:00
|
|
|
|
private void UpdateSoundDialog()
|
|
|
|
|
{
|
2015-01-23 04:16:25 +00:00
|
|
|
|
MuteFrameAdvance.Enabled = SoundOnCheckBox.Checked;
|
2011-06-12 00:14:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-15 19:05:21 +00:00
|
|
|
|
}
|