1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-23 15:50:05 +02:00

Start scrub polling before the PortAudio stream...

... A part, but only a part, of the fix for "bounce" at start of scrub
This commit is contained in:
Paul Licameli 2018-08-27 12:36:27 -04:00
parent 27ede251d5
commit 303ac9367a
2 changed files with 44 additions and 24 deletions

View File

@ -336,8 +336,7 @@ 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();
@ -403,6 +402,15 @@ bool Scrubber::MaybeStartScrubbing(wxCoord xx)
);
#endif
mScrubSpeedDisplayCountdown = 0;
// Must start the thread and poller first or else PlayPlayRegion
// will insert some silence
StartPolling();
auto cleanup = finally([this]{
if (mScrubToken < 0)
StopPolling();
});
mScrubToken =
ctb->PlayPlayRegion(SelectedRegion(time0, time1), options,
PlayMode::normalPlay, appearance, backwards);
@ -421,17 +429,7 @@ 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.
@ -491,6 +489,14 @@ bool Scrubber::StartSpeedPlay(double speed, double time0, double time1)
);
#endif
// Must start the thread and poller first or else PlayPlayRegion
// will insert some silence
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;
@ -500,18 +506,9 @@ 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;
}
@ -630,8 +627,24 @@ void Scrubber::ContinueScrubbingUI()
}
}
void Scrubber::StopScrubbing()
void Scrubber::StartPolling()
{
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();
@ -640,6 +653,11 @@ void Scrubber::StopScrubbing()
#endif
mPoller->Stop();
}
void Scrubber::StopScrubbing()
{
StopPolling();
if (HasMark() && !mCancelled) {
const wxMouseState state(::wxGetMouseState());

View File

@ -154,6 +154,8 @@ public:
void CheckMenuItems();
private:
void StartPolling();
void StopPolling();
void DoScrub(bool seek);
void OnActivateOrDeactivateApp(wxActivateEvent & event);