From c585bb16fbd585d58b07fd5f0e4e6b51faf4cd4e Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Fri, 20 May 2016 19:32:07 -0400 Subject: [PATCH] Move bounding times and minimum stutter length into ScrubOptions --- src/AudioIO.cpp | 24 ++++++++---------------- src/tracks/ui/Scrubbing.cpp | 10 ++++++++-- src/tracks/ui/Scrubbing.h | 10 ++++++---- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/AudioIO.cpp b/src/AudioIO.cpp index 46b44af3b..217ae90b3 100644 --- a/src/AudioIO.cpp +++ b/src/AudioIO.cpp @@ -372,16 +372,12 @@ So a small, fixed queue size should be adequate. struct AudioIO::ScrubQueue { ScrubQueue(double t0, double t1, wxLongLong startClockMillis, - double minTime, double maxTime, - double rate, double maxSpeed, double minStutter, + double rate, double maxSpeed, const ScrubbingOptions &options) : mTrailingIdx(0) , mMiddleIdx(1) , mLeadingIdx(2) - , mMinSample(minTime * rate) - , mMaxSample(maxTime * rate) , mRate(rate) - , mMinStutter(lrint(std::max(0.0, minStutter) * mRate)) , mLastScrubTimeMillis(startClockMillis) , mUpdating() { @@ -536,8 +532,8 @@ private: {} bool Init(Entry *previous, long s0, long s1, long duration, - double maxSpeed, long minStutter, long minSample, long maxSample, - bool adjustStart, const ScrubbingOptions &options) + double maxSpeed, bool adjustStart, + const ScrubbingOptions &options) { if (duration <= 0) return false; @@ -588,7 +584,7 @@ private: // (Assume s0 is in bounds, because it is the last scrub's s1 which was checked.) if (s1 != s0) { - const long newS1 = std::max(minSample, std::min(maxSample, s1)); + const long newS1 = std::max(options.minSample, std::min(options.maxSample, s1)); if (s1 != newS1) { long newDuration = long(duration * double(newS1 - s0) / (s1 - s0)); @@ -606,7 +602,7 @@ private: { // When playback follows a fast mouse movement by "stuttering" // at maximum playback, don't make stutters too short to be useful. - if (duration < minStutter) + if (duration < options.minStutter) return false; // Limit diff because this is seeking. const long diff = lrint(std::min(1.0, speed) * duration); @@ -628,7 +624,7 @@ private: // Adjust s1 again, and duration, if s1 is out of bounds. (Assume s0 is in bounds.) if (s1 != s0) { - const long newS1 = std::max(minSample, std::min(maxSample, s1)); + const long newS1 = std::max(options.minSample, std::min(options.maxSample, s1)); if (s1 != newS1) { long newDuration = long(duration * double(newS1 - s0) / (s1 - s0)); @@ -684,8 +680,7 @@ private: ? s0 + lrint(duration * end) // end is a speed : lrint(end * mRate); // end is a time const bool success = - entry.Init(previous, s0, s1, duration, maxSpeed, mMinStutter, - mMinSample, mMaxSample, adjustStart, options); + entry.Init(previous, s0, s1, duration, maxSpeed, adjustStart, options); if (success) mLastScrubTimeMillis = clockTime; return success; @@ -696,9 +691,7 @@ private: unsigned mTrailingIdx; unsigned mMiddleIdx; unsigned mLeadingIdx; - const long mMinSample, mMaxSample; const double mRate; - const long mMinStutter; wxLongLong mLastScrubTimeMillis; mutable wxMutex mUpdating; mutable wxCondition mAvailable { mUpdating }; @@ -1870,8 +1863,7 @@ int AudioIO::StartStream(const WaveTrackArray &playbackTracks, const auto &scrubOptions = *options.pScrubbingOptions; mScrubQueue = new ScrubQueue(mT0, mT1, scrubOptions.startClockTimeMillis, - 0.0, scrubOptions.maxTime, - sampleRate, scrubOptions.maxSpeed, scrubOptions.minStutter, + sampleRate, scrubOptions.maxSpeed, *options.pScrubbingOptions); mScrubDuration = 0; mSilentScrub = false; diff --git a/src/tracks/ui/Scrubbing.cpp b/src/tracks/ui/Scrubbing.cpp index 0fe3328cf..2d6d9bd50 100644 --- a/src/tracks/ui/Scrubbing.cpp +++ b/src/tracks/ui/Scrubbing.cpp @@ -48,6 +48,8 @@ enum { ScrubPollInterval_ms = 50, }; +static const double MinStutter = 0.2; + namespace { double FindScrubbingSpeed(const ViewInfo &viewInfo, double maxScrubSpeed, double screen, double timeAtMouse) { @@ -299,7 +301,6 @@ bool Scrubber::MaybeStartScrubbing(wxCoord xx) options.pScrubbingOptions = &mOptions; options.timeTrack = NULL; mOptions.delay = (ScrubPollInterval_ms / 1000.0); - mOptions.minStutter = 0.2; #ifdef USE_TRANSCRIPTION_TOOLBAR if (!mAlwaysSeeking) { // Take the starting speed limit from the transcription toolbar, @@ -313,7 +314,12 @@ bool Scrubber::MaybeStartScrubbing(wxCoord xx) mOptions.maxSpeed = mDragging ? ScrubbingOptions::MaxAllowedScrubSpeed() : 1.0; #endif - mOptions.maxTime = mProject->GetTracks()->GetEndTime(); + mOptions.minSample = 0; + mOptions.maxSample = + lrint(std::max(0.0, mProject->GetTracks()->GetEndTime()) * options.rate); + mOptions.minStutter = + lrint(std::max(0.0, MinStutter) * options.rate); + ControlToolBar::PlayAppearance appearance = ControlToolBar::PlayAppearance::Scrub; const bool cutPreview = false; diff --git a/src/tracks/ui/Scrubbing.h b/src/tracks/ui/Scrubbing.h index 8dcc9ec9c..b1c639a31 100644 --- a/src/tracks/ui/Scrubbing.h +++ b/src/tracks/ui/Scrubbing.h @@ -27,6 +27,10 @@ struct ScrubbingOptions { bool adjustStart {}; + // usually from TrackList::GetEndTime() + long maxSample {}; + long minSample {}; + bool enqueueBySpeed {}; double delay {}; @@ -34,17 +38,15 @@ struct ScrubbingOptions { // A limiting value for the speed of a scrub interval: double maxSpeed { 1.0 }; + // When maximum speed scrubbing skips to follow the mouse, // this is the minimum amount of playback allowed at the maximum speed: - double minStutter {}; + long minStutter {}; // Scrubbing needs the time of start of the mouse movement that began // the scrub: wxLongLong startClockTimeMillis { -1 }; - // usually from TrackList::GetEndTime() - double maxTime {}; - static double MaxAllowedScrubSpeed() { return 32.0; } // Is five octaves enough for your amusement? static double MinAllowedScrubSpeed()