From eeb5f1ec20ca4023711a91c638a318baa6bdabfe Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sat, 25 Aug 2018 19:42:12 -0400 Subject: [PATCH] Revert "Fix the hiccup at the start of scrub or play at speed..." (It didn't really achieve what that commit comment said) This reverts commit 26f72b110ceb07bc837eec5450084c6f5421ebb7. --- src/AudioIO.cpp | 7 +--- src/tracks/ui/Scrubbing.cpp | 66 ++++++++++++++----------------------- src/tracks/ui/Scrubbing.h | 2 -- 3 files changed, 25 insertions(+), 50 deletions(-) diff --git a/src/AudioIO.cpp b/src/AudioIO.cpp index 219aa5b6d..a041e8ce3 100644 --- a/src/AudioIO.cpp +++ b/src/AudioIO.cpp @@ -2282,12 +2282,7 @@ int AudioIO::StartStream(const TransportTracks &tracks, while( mAudioThreadShouldCallFillBuffersOnce ) { if (mScrubQueue) - // If not using a scrub thread, then we need to let the mouse polling - // in the main thread deliver its messages to ScrubQueue, so that - // FillBuffers() can progress in priming the RingBuffer. Else we would - // deadlock here. If not using the scrub thread, this should be - // harmless. - wxEventLoopBase::GetActive()->YieldFor( wxEVT_CATEGORY_TIMER ); + mScrubQueue->Nudge(); wxMilliSleep( 50 ); } diff --git a/src/tracks/ui/Scrubbing.cpp b/src/tracks/ui/Scrubbing.cpp index 1670a9c10..187103a11 100644 --- a/src/tracks/ui/Scrubbing.cpp +++ b/src/tracks/ui/Scrubbing.cpp @@ -336,7 +336,8 @@ bool Scrubber::MaybeStartScrubbing(wxCoord xx) double time1 = std::min(maxTime, viewInfo.PositionToTime(position, leftOffset) ); - if (time1 != time0) { + if (time1 != time0) + { if (busy) { auto position = mScrubStartPosition; ctb->StopPlaying(); @@ -402,15 +403,6 @@ bool Scrubber::MaybeStartScrubbing(wxCoord xx) ); #endif mScrubSpeedDisplayCountdown = 0; - - // Must start the thread and poller first or else PlayPlayRegion - // will deadlock - StartPolling(); - auto cleanup = finally([this]{ - if (mScrubToken < 0) - StopPolling(); - }); - mScrubToken = ctb->PlayPlayRegion(SelectedRegion(time0, time1), options, PlayMode::normalPlay, appearance, backwards); @@ -429,7 +421,17 @@ bool Scrubber::MaybeStartScrubbing(wxCoord xx) mOptions.startClockTimeMillis = ::wxGetLocalTimeMillis(); if (IsScrubbing()) { + mPaused = false; mLastScrubPosition = xx; + +#ifdef USE_SCRUB_THREAD + // Detached thread is self-deleting, after it receives the Delete() message + mpThread = safenew ScrubPollerThread{ *this }; + mpThread->Create(4096); + mpThread->Run(); +#endif + + mPoller->Start(ScrubPollInterval_ms); } // Return true whether we started scrub, or are still waiting to decide. @@ -489,14 +491,6 @@ bool Scrubber::StartSpeedPlay(double speed, double time0, double time1) ); #endif - // Must start the thread and poller first or else PlayPlayRegion - // will deadlock - StartPolling(); - auto cleanup = finally([this]{ - if (mScrubToken < 0) - StopPolling(); - }); - mScrubSpeedDisplayCountdown = 0; // Aim to stop within 20 samples of correct position. double stopTolerance = 20.0 / options.rate; @@ -506,9 +500,18 @@ bool Scrubber::StartSpeedPlay(double speed, double time0, double time1) PlayMode::normalPlay, appearance, backwards); if (mScrubToken >= 0) { + mPaused = false; mLastScrubPosition = 0; - } +#ifdef USE_SCRUB_THREAD + // Detached thread is self-deleting, after it receives the Delete() message + mpThread = safenew ScrubPollerThread{ *this }; + mpThread->Create(4096); + mpThread->Run(); +#endif + + mPoller->Start(ScrubPollInterval_ms); + } return true; } @@ -627,37 +630,16 @@ void Scrubber::ContinueScrubbingUI() } } -void Scrubber::StartPolling() +void Scrubber::StopScrubbing() { - mPaused = false; - -#ifdef USE_SCRUB_THREAD - // Detached thread is self-deleting, after it receives the Delete() message - mpThread = safenew ScrubPollerThread{ *this }; - mpThread->Create(4096); - mpThread->Run(); -#endif - - mPoller->Start(ScrubPollInterval_ms); -} - -void Scrubber::StopPolling() -{ - mPaused = true; - #ifdef USE_SCRUB_THREAD if (mpThread) { mpThread->Delete(); mpThread = nullptr; } #endif - - mPoller->Stop(); -} -void Scrubber::StopScrubbing() -{ - StopPolling(); + mPoller->Stop(); if (HasMark() && !mCancelled) { const wxMouseState state(::wxGetMouseState()); diff --git a/src/tracks/ui/Scrubbing.h b/src/tracks/ui/Scrubbing.h index 4d1fdaeed..139494097 100644 --- a/src/tracks/ui/Scrubbing.h +++ b/src/tracks/ui/Scrubbing.h @@ -154,8 +154,6 @@ public: void CheckMenuItems(); private: - void StartPolling(); - void StopPolling(); void DoScrub(bool seek); void OnActivateOrDeactivateApp(wxActivateEvent & event);