diff --git a/src/ProjectWindow.cpp b/src/ProjectWindow.cpp index 179529dd6..8484efb8b 100644 --- a/src/ProjectWindow.cpp +++ b/src/ProjectWindow.cpp @@ -1660,7 +1660,7 @@ void ProjectWindow::TP_HandleResize() ProjectWindow::PlaybackScroller::PlaybackScroller(AudacityProject *project) : mProject(project) { - ViewInfo::Get( *mProject ).Bind(EVT_TRACK_PANEL_TIMER, + mProject->Bind(EVT_TRACK_PANEL_TIMER, &PlaybackScroller::OnTimer, this); } @@ -1670,9 +1670,12 @@ void ProjectWindow::PlaybackScroller::OnTimer(wxCommandEvent &event) // Let other listeners get the notification event.Skip(); + auto gAudioIO = AudioIOBase::Get(); + mRecentStreamTime = gAudioIO->GetStreamTime(); + auto cleanup = finally([&]{ // Propagate the message to other listeners bound to this - this->ProcessEvent( event ); + this->SafelyProcessEvent( event ); }); if(!ProjectAudioIO::Get( *mProject ).IsAudioActive()) @@ -1692,7 +1695,7 @@ void ProjectWindow::PlaybackScroller::OnTimer(wxCommandEvent &event) auto &viewInfo = ViewInfo::Get( *mProject ); auto &trackPanel = GetProjectPanel( *mProject ); - const int posX = viewInfo.TimeToPosition(viewInfo.mRecentStreamTime); + const int posX = viewInfo.TimeToPosition(mRecentStreamTime); auto width = viewInfo.GetTracksUsableWidth(); int deltaX; switch (mMode) diff --git a/src/ProjectWindow.h b/src/ProjectWindow.h index c124c06ff..54b324497 100644 --- a/src/ProjectWindow.h +++ b/src/ProjectWindow.h @@ -75,11 +75,17 @@ public: mMode = mode; } + double GetRecentStreamTime() const { return mRecentStreamTime; } + private: void OnTimer(wxCommandEvent &event); AudacityProject *mProject; Mode mMode { Mode::Off }; + + // During timer update, grab the volatile stream time just once, so that + // various other drawing code can use the exact same value. + double mRecentStreamTime{ -1.0 }; }; PlaybackScroller &GetPlaybackScroller() { return *mPlaybackScroller; } diff --git a/src/ViewInfo.cpp b/src/ViewInfo.cpp index 6ba76e61b..4c39a7157 100644 --- a/src/ViewInfo.cpp +++ b/src/ViewInfo.cpp @@ -14,7 +14,6 @@ Paul Licameli #include -#include "AudioIOBase.h" #include "Prefs.h" #include "Project.h" #include "xml/XMLWriter.h" @@ -150,12 +149,7 @@ void NotifyingSelectedRegion::Notify( bool delayed ) static const AudacityProject::AttachedObjects::RegisteredFactory key{ []( AudacityProject &project ) { - auto result = - std::make_unique(0.0, 1.0, ZoomInfo::GetDefaultZoom()); - project.Bind(EVT_TRACK_PANEL_TIMER, - &ViewInfo::OnTimer, - result.get()); - return std::move( result ); + return std::make_unique(0.0, 1.0, ZoomInfo::GetDefaultZoom()); } }; @@ -180,7 +174,6 @@ ViewInfo::ViewInfo(double start, double screenDuration, double pixelsPerSecond) , scrollStep(16) , bUpdateTrackIndicator(true) , bScrollBeyondZero(false) - , mRecentStreamTime(-1.0) { UpdatePrefs(); } @@ -248,15 +241,6 @@ bool ViewInfo::ReadXMLAttribute(const wxChar *attr, const wxChar *value) return false; } -void ViewInfo::OnTimer(wxCommandEvent &event) -{ - auto gAudioIO = AudioIOBase::Get(); - mRecentStreamTime = gAudioIO->GetStreamTime(); - event.Skip(); - // Propagate the message to other listeners bound to this - this->ProcessEvent( event ); -} - int ViewInfo::UpdateScrollPrefsID() { static int value = wxNewId(); diff --git a/src/ViewInfo.h b/src/ViewInfo.h index 4b4182c0b..46a09769a 100644 --- a/src/ViewInfo.h +++ b/src/ViewInfo.h @@ -224,16 +224,9 @@ public: bool bScrollBeyondZero; bool bAdjustSelectionEdges; - // During timer update, grab the volatile stream time just once, so that - // various other drawing code can use the exact same value. - double mRecentStreamTime; - void WriteXMLAttributes(XMLWriter &xmlFile) const; bool ReadXMLAttribute(const wxChar *attr, const wxChar *value); - // Receive track panel timer notifications - void OnTimer(wxCommandEvent &event); - private: int mHeight{ 0 }; }; diff --git a/src/tracks/ui/PlayIndicatorOverlay.cpp b/src/tracks/ui/PlayIndicatorOverlay.cpp index f808c54ce..6d1fe64f7 100644 --- a/src/tracks/ui/PlayIndicatorOverlay.cpp +++ b/src/tracks/ui/PlayIndicatorOverlay.cpp @@ -174,13 +174,13 @@ void PlayIndicatorOverlay::OnTimer(wxCommandEvent &event) } } else { - // Calculate the horizontal position of the indicator - const double playPos = viewInfo.mRecentStreamTime; - auto &window = ProjectWindow::Get( *mProject ); + auto &scroller = window.GetPlaybackScroller(); + // Calculate the horizontal position of the indicator + const double playPos = scroller.GetRecentStreamTime(); + using Mode = ProjectWindow::PlaybackScroller::Mode; - const Mode mode = - window.GetPlaybackScroller().GetMode(); + const Mode mode = scroller.GetMode(); const bool pinned = ( mode == Mode::Pinned || mode == Mode::Right ); // Use a small tolerance to avoid flicker of play head pinned all the way