From 14cc918d7fadfe4037df192c06a84b93637f498b Mon Sep 17 00:00:00 2001 From: mchinen Date: Sun, 9 Jan 2011 13:12:51 +0000 Subject: [PATCH] bug 11 followup fix input hotswapping while monitoring; enable/disable when recording/playing --- src/toolbars/DeviceToolBar.cpp | 46 ++++++++++++++++++++++++++++++++-- src/toolbars/DeviceToolBar.h | 2 +- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/toolbars/DeviceToolBar.cpp b/src/toolbars/DeviceToolBar.cpp index 9ed12e62b..8572fabfe 100644 --- a/src/toolbars/DeviceToolBar.cpp +++ b/src/toolbars/DeviceToolBar.cpp @@ -265,7 +265,7 @@ void DeviceToolBar::Populate() mInput->Enable(false); - wxStaticText *channelsLabel = new wxStaticText(this, wxID_ANY, wxT("# Channels:"), + wxStaticText *channelsLabel = new wxStaticText(this, wxID_ANY, _("Rec Channels:"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT); Add(channelsLabel, 0, wxALIGN_CENTER); @@ -304,6 +304,14 @@ void DeviceToolBar::Populate() wxFocusEventHandler(DeviceToolBar::OnFocus), NULL, this); + mInputChannels->Connect(wxEVT_SET_FOCUS, + wxFocusEventHandler(DeviceToolBar::OnFocus), + NULL, + this); + mInputChannels->Connect(wxEVT_KILL_FOCUS, + wxFocusEventHandler(DeviceToolBar::OnFocus), + NULL, + this); FillHostDevices(); FillInputChannels(); @@ -406,12 +414,26 @@ void DeviceToolBar::UpdatePrefs() ToolBar::UpdatePrefs(); } + +void DeviceToolBar::EnableDisableButtons() +{ + if (gAudioIO) { + // we allow changes when monitoring, but not when recording + bool audioStreamActive = gAudioIO->IsStreamActive() && !gAudioIO->IsMonitoring(); + mHost->Enable(!audioStreamActive); + mInput->Enable(!audioStreamActive); + mOutput->Enable(!audioStreamActive); + mInputChannels->Enable(!audioStreamActive); + } +} + void DeviceToolBar::RegenerateTooltips() { #if wxUSE_TOOLTIPS mOutput->SetToolTip(_("Output Device")); mInput->SetToolTip(_("Input Device")); mHost->SetToolTip(_("Audio Host")); + mInputChannels->SetToolTip(_("Input Channels")); #endif } @@ -612,8 +634,28 @@ void DeviceToolBar::OnChoice(wxCommandEvent &event) SetDevices(&mInputDeviceSourceMaps[newInIndex], &mOutputDeviceSourceMaps[newOutIndex]); } - if (gAudioIO) + if (gAudioIO) { + // We cannot have gotten here if gAudioIO->IsAudioTokenActive(), + // per the setting of AudioIONotBusyFlag and AudioIOBusyFlag in + // AudacityProject::GetUpdateFlags(). + // However, we can have an invalid audio token (so IsAudioTokenActive() + // is false), but be monitoring. + // If monitoring, have to stop the stream, so HandleDeviceChange() can work. + // We could disable the Preferences command while monitoring, i.e., + // set AudioIONotBusyFlag/AudioIOBusyFlag according to monitoring, as well. + // Instead allow it because unlike recording, for example, monitoring + // is not clearly something that should prohibit changing device. + // TO-DO: We *could* be smarter in this method and call HandleDeviceChange() + // only when the device choices actually changed. True of lots of prefs! + // As is, we always stop monitoring before handling the device change. + if (gAudioIO->IsMonitoring()) + { + gAudioIO->StopStream(); + while (gAudioIO->IsBusy()) + wxMilliSleep(100); + } gAudioIO->HandleDeviceChange(); + } GetActiveProject()->UpdatePrefs(); } diff --git a/src/toolbars/DeviceToolBar.h b/src/toolbars/DeviceToolBar.h index dbf6a6fcf..a949daa26 100644 --- a/src/toolbars/DeviceToolBar.h +++ b/src/toolbars/DeviceToolBar.h @@ -44,7 +44,7 @@ class DeviceToolBar:public ToolBar { virtual void Populate(); virtual void Repaint(wxDC *dc) {}; - virtual void EnableDisableButtons() {}; + virtual void EnableDisableButtons(); void OnFocus(wxFocusEvent &event); void OnCaptureKey(wxCommandEvent &event);