diff --git a/src/tracks/ui/Scrubbing.cpp b/src/tracks/ui/Scrubbing.cpp index ee6ccb071..e116ea405 100644 --- a/src/tracks/ui/Scrubbing.cpp +++ b/src/tracks/ui/Scrubbing.cpp @@ -38,6 +38,8 @@ enum { #ifdef EXPERIMENTAL_SCRUBBING_SCROLL_WHEEL ScrubSpeedStepsPerOctave = 4, #endif + + ScrubPollInterval_ms = 50, }; namespace { @@ -112,6 +114,26 @@ namespace { } } +class Scrubber::ScrubPoller : public wxTimer +{ +public: + ScrubPoller(Scrubber &scrubber) : mScrubber{ scrubber } {} + +private: + void Notify() override; + + Scrubber &mScrubber; +}; + +void Scrubber::ScrubPoller::Notify() +{ + // Call ContinueScrubbing() here in a timer handler + // rather than in SelectionHandleDrag() + // so that even without drag events, we can instruct the play head to + // keep approaching the mouse cursor, when its maximum speed is limited. + mScrubber.ContinueScrubbing(); +} + Scrubber::Scrubber(AudacityProject *project) : mScrubToken(-1) , mScrubStartClockTimeMillis(-1) @@ -126,6 +148,7 @@ Scrubber::Scrubber(AudacityProject *project) #endif , mProject(project) + , mPoller { std::make_unique(*this) } { if (wxTheApp) wxTheApp->Connect @@ -311,6 +334,8 @@ bool Scrubber::MaybeStartScrubbing(wxCoord xx) mProject->GetPlaybackScroller().Activate(mSmoothScrollingScrub); mScrubHasFocus = true; mLastScrubPosition = xx; + + mPoller->Start(ScrubPollInterval_ms); } // Return true whether we started scrub, or are still waiting to decide. @@ -393,6 +418,8 @@ void Scrubber::ContinueScrubbing() void Scrubber::StopScrubbing() { + mPoller->Stop(); + UncheckAllMenuItems(); mScrubStartPosition = -1; @@ -597,12 +624,6 @@ void ScrubbingOverlay::OnTimer(wxCommandEvent &event) ruler->ShowQuickPlayIndicator(); } - // Call ContinueScrubbing() here in the timer handler - // rather than in SelectionHandleDrag() - // so that even without drag events, we can instruct the play head to - // keep approaching the mouse cursor, when its maximum speed is limited. - scrubber.ContinueScrubbing(); - if (!scrubber.ShouldDrawScrubSpeed()) { mNextScrubRect = wxRect(); } diff --git a/src/tracks/ui/Scrubbing.h b/src/tracks/ui/Scrubbing.h index 92e631929..2c46bc796 100644 --- a/src/tracks/ui/Scrubbing.h +++ b/src/tracks/ui/Scrubbing.h @@ -11,6 +11,7 @@ Paul Licameli split from TrackPanel.cpp #ifndef __AUDACITY_SCRUBBING__ #define __AUDACITY_SCRUBBING__ +#include "../../MemoryX.h" #include #include #include @@ -125,6 +126,9 @@ private: AudacityProject *mProject; DECLARE_EVENT_TABLE() + + class ScrubPoller; + std::unique_ptr mPoller; }; // Specialist in drawing the scrub speed, and listening for certain events