using NAudio.Midi; using NAudio.Wave; using QuikDawEditor.MiscClasses; using QuikDawEditor.Properties; using System; using System.Collections.ObjectModel; using System.Diagnostics; using System.IO; using System.Windows; using System.Windows.Controls; using static QuikDawEditor.EDITING.StaticProperties; namespace QuikDawEditor; public partial class SetupInfoWindow : Window { public SetupInfoWindow() { InitializeComponent(); GetAudioDevices(); GetMidiDevices(); } public ObservableCollection asioInputs { get; set; } = new ObservableCollection(); public ObservableCollection asioOutputs { get; set; } = new ObservableCollection(); public ObservableCollection waveInputs { get; set; } = new ObservableCollection(); public ObservableCollection waveOutputs { get; set; } = new ObservableCollection(); public ObservableCollection midiDevices { get; set; } = new ObservableCollection(); internal void GetAudioDevices() { for (int wo = 0; wo < WaveOut.DeviceCount; wo++) waveOutputs.Add(WaveOut.GetCapabilities(wo).ProductName); for (int wo = 0; wo < WaveIn.DeviceCount; wo++) waveInputs.Add(WaveIn.GetCapabilities(wo).ProductName); foreach (string dname in AsioOut.GetDriverNames()) asioInputs.Add(dname); foreach (string dname in AsioOut.GetDriverNames()) asioOutputs.Add(dname); } internal void GetMidiDevices() { for (int mi = 0; mi < MidiIn.NumberOfDevices; mi++) midiDevices.Add(new MidiDevice() { DeviceName = MidiIn.DeviceInfo(mi).ProductName, Manufacturer = MidiIn.DeviceInfo(mi).Manufacturer.ToString() }); //MessageBox.Show("# of midi devices: " + midiDevices.Count.ToString()); } private void Window_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e) { if (e.Key == System.Windows.Input.Key.Escape) CloseBut.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } private void CloseBut_Click(object sender, RoutedEventArgs e) { Settings.Default.Save(); this.Hide(); //if (AudioWasReset) // MessageBox.Show("Audio device was reset, Please restart QuikDaw"); } private void OpenSoundMixerBut_Click(object sender, RoutedEventArgs e) { Process.Start(new ProcessStartInfo("sndvol.exe") { UseShellExecute = true }); } private void DataDirChangeBut_Click(object sender, RoutedEventArgs e) { System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog(); fbd.SelectedPath = Settings.Default.DataDirectory; if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string seldatapath = fbd.SelectedPath; if (!seldatapath.EndsWith("\\QuikDawData")) { seldatapath += "\\QuikDawData"; if (!Directory.Exists(seldatapath)) Directory.CreateDirectory(seldatapath); } Settings.Default.DataDirectory = seldatapath; Settings.Default.Save(); } } private void WaveRadioButton_Click(object sender, RoutedEventArgs e) { AudioInputsCB.ItemsSource = setupWin.waveInputs; AudioOutputsCB.ItemsSource = setupWin.waveOutputs; Settings.Default.AsioInRadioButtonChecked = false; Settings.Default.Save(); AsioDriverSettingsBut.Visibility = Visibility.Hidden; } private void AsioRadioButton_Click(object sender, RoutedEventArgs e) { AudioInputsCB.ItemsSource = setupWin.asioInputs; AudioOutputsCB.ItemsSource = setupWin.asioOutputs; Settings.Default.AsioInRadioButtonChecked = true; Settings.Default.Save(); AsioDriverSettingsBut.Visibility = Visibility.Visible; } private void setupWin_Loaded(object sender, RoutedEventArgs e) { //AsioRadioButton.IsChecked = Settings.Default.AsioInRadioButtonChecked; //TEMP AsioRadioButton.IsChecked = true; Settings.Default.AsioInRadioButtonChecked = true; Settings.Default.Save(); //TEMP switch ((bool)AsioRadioButton.IsChecked) { case true: AudioInputsCB.ItemsSource = setupWin.asioInputs; AudioOutputsCB.ItemsSource = setupWin.asioOutputs; AudioInputsCB.SelectedIndex = setupWin.asioInputs.IndexOf(Settings.Default.SoundInputDeviceName); AudioOutputsCB.SelectedIndex = setupWin.asioOutputs.IndexOf(Settings.Default.SoundOutputDeviceName); break; case false: AudioInputsCB.ItemsSource = setupWin.waveInputs; AudioOutputsCB.ItemsSource = setupWin.waveOutputs; AudioInputsCB.SelectedIndex = setupWin.waveInputs.IndexOf(Settings.Default.SoundInputDeviceName); AudioOutputsCB.SelectedIndex = setupWin.waveOutputs.IndexOf(Settings.Default.SoundOutputDeviceName); break; } if (projPlayer != null) AsioDriverSettingsBut.IsEnabled = (playAsioOut != null); MidiInDevicesLB.ItemsSource = setupWin.midiDevices; AudioWasReset = false; } private void AudioInputsCB_DropDownClosed(object sender, EventArgs e) { if (AudioInputsCB.SelectedValue == null) return; if (AudioInputsCB.SelectedIndex == -1) return; if (Settings.Default.SoundInputDeviceName != AudioInputsCB.SelectedValue.ToString()) { SelectedAudioInIndex = AudioInputsCB.SelectedIndex; Settings.Default.SoundInputDeviceName = AudioInputsCB.SelectedValue.ToString(); Settings.Default.Save(); AudioWasReset = true; } } public bool AudioWasReset = false; private void AudioOutputsCB_DropDownClosed(object sender, EventArgs e) { if (AudioOutputsCB.SelectedValue == null) return; if (Settings.Default.SoundOutputDeviceName != AudioOutputsCB.SelectedValue.ToString()) { SelectedAudioOutIndex = AudioOutputsCB.SelectedIndex; Settings.Default.SoundOutputDeviceName = AudioOutputsCB.SelectedValue.ToString(); Settings.Default.Save(); AudioWasReset = true; } } private void AsioDriverSettingsBut_Click(object sender, RoutedEventArgs e) { try { if (projPlayer != null) { if (playAsioOut != null) { this.Topmost = false; playAsioOut.ShowControlPanel(); } } else { try { AsioOut checkAsioOut = new AsioOut(AudioOutputsCB.SelectedIndex); this.Topmost = false; checkAsioOut.ShowControlPanel(); checkAsioOut.Dispose(); } catch { MessageBox.Show("Unable to open checking asio device"); } } } catch { MessageBox.Show("Unable to open asio device"); } } }