From 133c0ec61d672b557bed71a310d3ea4d7d76c4ea Mon Sep 17 00:00:00 2001 From: Leland Lucius Date: Wed, 26 Aug 2015 00:13:14 -0500 Subject: [PATCH] Fix for bug #1159 --- src/AudioIO.cpp | 18 ++++++++++++++---- src/toolbars/ControlToolBar.cpp | 6 ++++++ src/toolbars/ControlToolBar.h | 3 +++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/AudioIO.cpp b/src/AudioIO.cpp index 61f63ac21..b0de6b4e0 100644 --- a/src/AudioIO.cpp +++ b/src/AudioIO.cpp @@ -4023,19 +4023,29 @@ int audacityAudioCallback(const void *inputBuffer, void *outputBuffer, } // end recording VU meter update // Stop recording if 'silence' is detected + // + // LL: We'd gotten a little "dangerous" with the control toolbar calls + // here because we are not running in the main GUI thread. Eventually + // the toolbar attempts to update the active project's status bar. + // But, since we're not in the main thread, we can get all manner of + // really weird failures. Or none at all which is even worse, since + // we don't know a problem exists. + // + // By using CallAfter(), we can schedule the call to the toolbar + // to run in the main GUI thread after the next event loop iteration. if(gAudioIO->mPauseRec && inputBuffer && gAudioIO->mInputMeter) { if(gAudioIO->mInputMeter->GetMaxPeak() < gAudioIO->mSilenceLevel ) { if(!gAudioIO->IsPaused()) { AudacityProject *p = GetActiveProject(); - wxCommandEvent dummyEvt; - p->GetControlToolBar()->OnPause(dummyEvt); + ControlToolBar *bar = p->GetControlToolBar(); + bar->CallAfter(&ControlToolBar::Pause); } } else { if(gAudioIO->IsPaused()) { AudacityProject *p = GetActiveProject(); - wxCommandEvent dummyEvt; - p->GetControlToolBar()->OnPause(dummyEvt); + ControlToolBar *bar = p->GetControlToolBar(); + bar->CallAfter(&ControlToolBar::Pause); } } } diff --git a/src/toolbars/ControlToolBar.cpp b/src/toolbars/ControlToolBar.cpp index 48fb4f208..4d179d861 100644 --- a/src/toolbars/ControlToolBar.cpp +++ b/src/toolbars/ControlToolBar.cpp @@ -776,6 +776,12 @@ void ControlToolBar::StopPlaying(bool stopStream /* = true*/) } } +void ControlToolBar::Pause() +{ + wxCommandEvent dummy; + OnPause(dummy); +} + void ControlToolBar::OnRecord(wxCommandEvent &evt) { if (gAudioIO->IsBusy()) { diff --git a/src/toolbars/ControlToolBar.h b/src/toolbars/ControlToolBar.h index c9a27c650..92fd097f5 100644 --- a/src/toolbars/ControlToolBar.h +++ b/src/toolbars/ControlToolBar.h @@ -79,6 +79,9 @@ class ControlToolBar:public ToolBar { // Stop playing void StopPlaying(bool stopStream = true); + // Pause - used by AudioIO to pause sound activate recording + void Pause(); + void Populate(); virtual void Repaint(wxDC *dc); virtual void EnableDisableButtons();