private void listBoxAsioDevices_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (listBoxAsioDevices.SelectedIndex != m_selectedAsioDeviceIdx) { if (m_asioStatus == AsioStatus.Ready) { asio.Unsetup(); m_asioStatus = AsioStatus.NotReady; } if (0 <= m_selectedAsioDeviceIdx) { asio.DriverUnload(); m_selectedAsioDeviceIdx = -1; } m_selectedAsioDeviceIdx = listBoxAsioDevices.SelectedIndex; bool bRv = asio.DriverLoad(m_selectedAsioDeviceIdx); if (!bRv) { MessageBox.Show(string.Format("エラー: ASIOドライバー{0}のロードに失敗", asio.DriverNameGet(m_selectedAsioDeviceIdx))); return; } int sampleRate = System.Convert.ToInt32(((ListBoxItem)listBoxSampleFreq.SelectedItem).Content); int rv = asio.Setup(sampleRate); if (rv != 0) { MessageBox.Show(string.Format("エラー: サンプルレートの設定に失敗 {0}\n AsioError {1}", sampleRate, rv)); return; } m_asioStatus = AsioStatus.Ready; { int nCh = asio.OutputChannelsNumGet(); if (nCh <= 0) { MessageBox.Show("エラー: 出力チャンネル情報取得に失敗"); return; } listBoxAsioChannels.Items.Clear(); for (int i = 0; i < nCh; ++i) { ListBoxItem item = new ListBoxItem(); item.Content = asio.OutputChannelNameGet(i); listBoxAsioChannels.Items.Add(item); } listBoxAsioChannels.SelectedIndex = 0; } { int nCS = asio.ClockSourceNumGet(); if (nCS <= 0) { MessageBox.Show("エラー: クロックソース情報取得に失敗"); return; } listBoxAsioClockSource.Items.Clear(); for (int i = 0; i < nCS; ++i) { ListBoxItem item = new ListBoxItem(); item.Content = asio.ClockSourceNameGet(i); listBoxAsioClockSource.Items.Add(item); } listBoxAsioClockSource.SelectedIndex = 0; } } }
private void buttonLoadDriver_Click(object sender, EventArgs e) { buttonLoadDriver.Enabled = false; bool bRv = asio.DriverLoad(listBoxDrivers.SelectedIndex); if (!bRv) { return; } int rv = asio.Setup(SAMPLE_RATE); if (0 != rv) { string errStr = string.Empty; switch (rv) { case -5003: errStr = "Device Not Found"; break; case -1000: errStr = "hardware input or output is not present or available"; break; default: break; } if (errStr == string.Empty) { MessageBox.Show(string.Format("ASIO setup({0}) failed {1:X8}", SAMPLE_RATE, rv)); } else { MessageBox.Show(string.Format("ASIO setup({0}) failed {1} ({2:X8})", SAMPLE_RATE, errStr, rv)); } asio.Unsetup(); asio.DriverUnload(); buttonLoadDriver.Enabled = true; return; } for (int i = 0; i < asio.InputChannelsNumGet(); ++i) { listBoxInput.Items.Add(asio.InputChannelNameGet(i)); } if (0 < listBoxInput.Items.Count) { listBoxInput.SelectedIndex = 0; } for (int i = 0; i < asio.OutputChannelsNumGet(); ++i) { listBoxOutput.Items.Add(asio.OutputChannelNameGet(i)); } if (0 < listBoxOutput.Items.Count) { listBoxOutput.SelectedIndex = 0; } for (int i = 0; i < asio.ClockSourceNumGet(); ++i) { listBoxClockSources.Items.Add(asio.ClockSourceNameGet(i)); } if (0 < listBoxOutput.Items.Count) { listBoxClockSources.SelectedIndex = 0; } if (0 == rv && 0 < listBoxInput.Items.Count && 0 < listBoxOutput.Items.Count) { buttonStart.Enabled = true; } listBoxDrivers.Enabled = false; buttonControlPanel.Enabled = true; }