From fdf0759301b9d4ac7a1d91ffc532591c8cb4853b Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sun, 12 Jul 2015 08:47:56 -0400 Subject: [PATCH] Bug1075, and define and use new event type for TrackPanel timer ticks... ... Thus allowing TrackPanel.cpp to work without including Lyrics headers. Also eliminates some of its direct notification of MixerBoard. --- src/AudioIO.cpp | 2 ++ src/LyricsWindow.cpp | 30 +++++++++++++++++++++++++- src/LyricsWindow.h | 1 + src/MixerBoard.cpp | 38 +++++++++++++++++++++++++++++++-- src/MixerBoard.h | 1 + src/TrackPanel.cpp | 50 +++++--------------------------------------- src/TrackPanel.h | 2 ++ 7 files changed, 76 insertions(+), 48 deletions(-) diff --git a/src/AudioIO.cpp b/src/AudioIO.cpp index 223ff1d64..cfcaaac07 100644 --- a/src/AudioIO.cpp +++ b/src/AudioIO.cpp @@ -4520,6 +4520,8 @@ int audacityAudioCallback(const void *inputBuffer, void *outputBuffer, // The problem there occurs if Software Playthrough is on. // Could conditionally do the update here if Software Playthrough is off, // and in TrackPanel::OnTimer() if Software Playthrough is on, but not now. + // PRL 12 Jul 2015: and what was in TrackPanel::OnTimer is now handled by means of event + // type EVT_TRACK_PANEL_TIMER //AudacityProject* pProj = GetActiveProject(); //MixerBoard* pMixerBoard = pProj->GetMixerBoard(); //if (pMixerBoard) diff --git a/src/LyricsWindow.cpp b/src/LyricsWindow.cpp index 672491538..4d30ae534 100644 --- a/src/LyricsWindow.cpp +++ b/src/LyricsWindow.cpp @@ -13,7 +13,9 @@ #include "LyricsWindow.h" #include "Lyrics.h" +#include "AudioIO.h" #include "Project.h" +#include "TrackPanel.h" // for EVT_TRACK_PANEL_TIMER #include #include @@ -123,10 +125,21 @@ LyricsWindow::LyricsWindow(AudacityProject *parent): // default: // pRadioButton_Highlight->SetValue(true); break; //} + + // Events from the project don't propagate directly to this other frame, so... + mProject->Connect(EVT_TRACK_PANEL_TIMER, + wxCommandEventHandler(LyricsWindow::OnTimer), + NULL, + this); } LyricsWindow::~LyricsWindow() -{} +{ + mProject->Disconnect(EVT_TRACK_PANEL_TIMER, + wxCommandEventHandler(LyricsWindow::OnTimer), + NULL, + this); +} void LyricsWindow::OnCloseWindow(wxCloseEvent & WXUNUSED(event)) { @@ -143,3 +156,18 @@ void LyricsWindow::OnStyle_Highlight(wxCommandEvent & WXUNUSED(event)) mLyricsPanel->SetLyricsStyle(Lyrics::kHighlightLyrics); } +void LyricsWindow::OnTimer(wxCommandEvent &event) +{ + if (mProject->IsAudioActive()) + { + GetLyricsPanel()->Update(gAudioIO->GetStreamTime()); + } + else + { + // Reset lyrics display. + GetLyricsPanel()->Update(mProject->GetSel0()); + } + + // Let other listeners get the notification + event.Skip(); +} diff --git a/src/LyricsWindow.h b/src/LyricsWindow.h index d0afd19d7..1334ae33f 100644 --- a/src/LyricsWindow.h +++ b/src/LyricsWindow.h @@ -32,6 +32,7 @@ class LyricsWindow : public wxFrame { void OnStyle_BouncingBall(wxCommandEvent &evt); void OnStyle_Highlight(wxCommandEvent &evt); + void OnTimer(wxCommandEvent &event); AudacityProject *mProject; Lyrics *mLyricsPanel; diff --git a/src/MixerBoard.cpp b/src/MixerBoard.cpp index 6f350ef28..b04720cb6 100644 --- a/src/MixerBoard.cpp +++ b/src/MixerBoard.cpp @@ -26,6 +26,7 @@ #include "NoteTrack.h" #endif #include "Project.h" +#include "TrackPanel.h" // for EVT_TRACK_PANEL_TIMER #include "WaveTrack.h" #include "widgets/Meter.h" @@ -1017,6 +1018,12 @@ MixerBoard::MixerBoard(AudacityProject* pProject, mPrevT1 = 0.0; mTracks = mProject->GetTracks(); + + // Events from the project don't propagate directly to this other frame, so... + mProject->Connect(EVT_TRACK_PANEL_TIMER, + wxCommandEventHandler(MixerBoard::OnTimer), + NULL, + this); } MixerBoard::~MixerBoard() @@ -1034,6 +1041,11 @@ MixerBoard::~MixerBoard() // private data members mMusicalInstruments.Clear(); + + mProject->Disconnect(EVT_TRACK_PANEL_TIMER, + wxCommandEventHandler(MixerBoard::OnTimer), + NULL, + this); } // Reassign mixer input strips (MixerTrackClusters) to Track Clusters @@ -1693,6 +1705,30 @@ void MixerBoard::OnSize(wxSizeEvent &evt) this->RefreshTrackClusters(true); } +void MixerBoard::OnTimer(wxCommandEvent &event) +{ + // PRL 12 Jul 2015: Moved the below (with comments) out of TrackPanel::OnTimer. + + // Vaughan, 2011-01-28: No longer doing this on timer. + // Now it's in AudioIO::SetMeters() and AudioIO::StopStream(), as with Meter Toolbar meters. + //if (pMixerBoard) + // pMixerBoard->ResetMeters(false); + + //v Vaughan, 2011-02-25: Moved this update back here from audacityAudioCallback. + // See note there. + // Vaughan, 2010-01-30: + // Since all we're doing here is updating the meters, I moved it to + // audacityAudioCallback where it calls gAudioIO->mOutputMeter->UpdateDisplay(). + if (mProject->IsAudioActive()) + { + UpdateMeters(gAudioIO->GetStreamTime(), + (mProject->mLastPlayMode == loopedPlay)); + } + + // Let other listeners get the notification + event.Skip(); +} + // class MixerBoardFrame @@ -1761,5 +1797,3 @@ void MixerBoardFrame::OnSize(wxSizeEvent & WXUNUSED(event)) { mMixerBoard->SetSize(this->GetClientSize()); } - - diff --git a/src/MixerBoard.h b/src/MixerBoard.h index 15e9522dd..0d3ead754 100644 --- a/src/MixerBoard.h +++ b/src/MixerBoard.h @@ -265,6 +265,7 @@ private: // event handlers void OnSize(wxSizeEvent &evt); + void OnTimer(wxCommandEvent &event); public: diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index 8825e834f..3eb0ef70b 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -196,8 +196,6 @@ is time to refresh some aspect of the screen. #include "float_cast.h" #include "Internat.h" #include "LabelTrack.h" -#include "Lyrics.h" -#include "LyricsWindow.h" #include "MixerBoard.h" #include "NoteTrack.h" @@ -236,6 +234,8 @@ is time to refresh some aspect of the screen. #include "../images/Cursors.h" #include +DEFINE_EVENT_TYPE(EVT_TRACK_PANEL_TIMER) + enum { kLeftInset = 4, kTopInset = 4, @@ -1053,27 +1053,9 @@ void TrackPanel::OnTimer() wxCommandEvent dummyEvent; AudacityProject *p = GetProject(); - if (IsAudioActive()) { - // Update lyrics display. - LyricsWindow* pLyricsWindow = p->GetLyricsWindow(); - if (pLyricsWindow) - { - Lyrics* pLyricsPanel = pLyricsWindow->GetLyricsPanel(); - pLyricsPanel->Update(gAudioIO->GetStreamTime()); - } - } - - //v Vaughan, 2011-02-25: Moved this update back here from audacityAudioCallback. - // See note there. - // Vaughan, 2010-01-30: - // Since all we're doing here is updating the meters, I moved it to - // audacityAudioCallback where it calls gAudioIO->mOutputMeter->UpdateDisplay(). - MixerBoard* pMixerBoard = this->GetMixerBoard(); - if (pMixerBoard && IsAudioActive()) - { - pMixerBoard->UpdateMeters(gAudioIO->GetStreamTime(), - (p->mLastPlayMode == loopedPlay)); + wxCommandEvent e(EVT_TRACK_PANEL_TIMER); + p->ProcessEvent(e); } #ifdef EXPERIMENTAL_SCRUBBING_BASIC @@ -1119,19 +1101,6 @@ void TrackPanel::OnTimer() //the stream may have been started up after this one finished (by some other project) //in that case reset the buttons don't stop the stream p->GetControlToolBar()->StopPlaying(!gAudioIO->IsStreamActive()); - - // Reset lyrics display. - LyricsWindow* pLyricsWindow = p->GetLyricsWindow(); - if (pLyricsWindow) - { - Lyrics* pLyricsPanel = pLyricsWindow->GetLyricsPanel(); - pLyricsPanel->Update(p->GetSel0()); - } - - // Vaughan, 2011-01-28: No longer doing this on timer. - // Now it's in AudioIO::SetMeters() and AudioIO::StopStream(), as with Meter Toolbar meters. - //if (pMixerBoard) - // pMixerBoard->ResetMeters(false); } // Next, check to see if we were playing or recording @@ -2176,7 +2145,7 @@ void TrackPanel::HandleSelect(wxMouseEvent & event) // AS: Ok, did the user just click the mouse, release the mouse, // or drag? if (event.LeftDown() || - (event.LeftDClick() && event.CmdDown())) { + (event.LeftDClick() && event.CmdDown())) { // AS: Now, did they click in a track somewhere? If so, we want // to extend the current selection or start a new selection, // depending on the shift key. If not, cancel all selections. @@ -2258,15 +2227,6 @@ void TrackPanel::HandleSelect(wxMouseEvent & event) #endif done: SelectionHandleDrag(event, t); - - // Update lyrics display for new selection. - AudacityProject* pProj = GetActiveProject(); - LyricsWindow* pLyricsWindow = pProj->GetLyricsWindow(); - if (pLyricsWindow && pLyricsWindow->IsShown()) - { - Lyrics* pLyricsPanel = pLyricsWindow->GetLyricsPanel(); - pLyricsPanel->Update(pProj->GetSel0()); - } } diff --git a/src/TrackPanel.h b/src/TrackPanel.h index d10cd9ef0..5cc2950b0 100644 --- a/src/TrackPanel.h +++ b/src/TrackPanel.h @@ -68,6 +68,8 @@ class TrackPanelListener; #pragma warning( disable: 4251 ) #endif +DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_TRACK_PANEL_TIMER, -1); + class AUDACITY_DLL_API TrackInfo { public: