mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-24 16:20:05 +02:00
Further simplified argument passing
This commit is contained in:
parent
e4fadf4aaf
commit
a9a404c7cf
@ -372,7 +372,7 @@ So a small, fixed queue size should be adequate.
|
||||
struct AudioIO::ScrubQueue
|
||||
{
|
||||
ScrubQueue(double t0, double t1, wxLongLong startClockMillis,
|
||||
double rate, double maxSpeed, long maxDebt,
|
||||
double rate, long maxDebt,
|
||||
const ScrubbingOptions &options)
|
||||
: mTrailingIdx(0)
|
||||
, mMiddleIdx(1)
|
||||
@ -389,7 +389,7 @@ struct AudioIO::ScrubQueue
|
||||
Duration dd { *this };
|
||||
long actualDuration = std::max(1L, dd.duration);
|
||||
auto success = mEntries[mMiddleIdx].Init(nullptr,
|
||||
s0, s1, actualDuration, maxSpeed, options);
|
||||
s0, s1, actualDuration, options);
|
||||
if (success)
|
||||
++mLeadingIdx;
|
||||
else {
|
||||
@ -423,7 +423,7 @@ struct AudioIO::ScrubQueue
|
||||
mAvailable.Signal();
|
||||
}
|
||||
|
||||
bool Producer(double end, double maxSpeed, const ScrubbingOptions &options)
|
||||
bool Producer(double end, const ScrubbingOptions &options)
|
||||
{
|
||||
// Main thread indicates a scrubbing interval
|
||||
|
||||
@ -449,7 +449,7 @@ struct AudioIO::ScrubQueue
|
||||
? s0 + lrint(origDuration * end) // end is a speed
|
||||
: lrint(end * mRate); // end is a time
|
||||
auto success =
|
||||
current->Init(previous, s0, s1, actualDuration, maxSpeed, options);
|
||||
current->Init(previous, s0, s1, actualDuration, options);
|
||||
if (success)
|
||||
mLeadingIdx = next;
|
||||
else {
|
||||
@ -615,7 +615,7 @@ private:
|
||||
|
||||
bool Init(Entry *previous, long s0, long s1,
|
||||
long &duration /* in/out */,
|
||||
double maxSpeed, const ScrubbingOptions &options)
|
||||
const ScrubbingOptions &options)
|
||||
{
|
||||
const bool &adjustStart = options.adjustStart;
|
||||
|
||||
@ -624,10 +624,10 @@ private:
|
||||
bool adjustedSpeed = false;
|
||||
|
||||
// May change the requested speed and duration
|
||||
if (!adjustStart && speed > maxSpeed)
|
||||
if (!adjustStart && speed > options.maxSpeed)
|
||||
{
|
||||
// Reduce speed to the maximum selected in the user interface.
|
||||
speed = maxSpeed;
|
||||
speed = options.maxSpeed;
|
||||
mGoal = s1;
|
||||
adjustedSpeed = true;
|
||||
}
|
||||
@ -642,8 +642,8 @@ private:
|
||||
// the final catch-up can make a slow scrub interval
|
||||
// that drops the pitch and sounds wrong.)
|
||||
// Trim the duration.
|
||||
duration = std::max(0L, lrint(speed * duration / maxSpeed));
|
||||
speed = maxSpeed;
|
||||
duration = std::max(0L, lrint(speed * duration / options.maxSpeed));
|
||||
speed = options.maxSpeed;
|
||||
mGoal = s1;
|
||||
adjustedSpeed = true;
|
||||
}
|
||||
@ -701,7 +701,7 @@ private:
|
||||
if (adjustStart && !silent)
|
||||
{
|
||||
// Limit diff because this is seeking.
|
||||
const long diff = lrint(std::min(maxSpeed, speed) * duration);
|
||||
const long diff = lrint(std::min(options.maxSpeed, speed) * duration);
|
||||
if (s0 < s1)
|
||||
s0 = s1 - diff;
|
||||
else
|
||||
@ -1949,8 +1949,8 @@ int AudioIO::StartStream(const WaveTrackArray &playbackTracks,
|
||||
const auto &scrubOptions = *options.pScrubbingOptions;
|
||||
mScrubQueue =
|
||||
new ScrubQueue(mT0, mT1, scrubOptions.startClockTimeMillis,
|
||||
sampleRate, scrubOptions.maxSpeed, 2 * scrubOptions.minStutter,
|
||||
*options.pScrubbingOptions);
|
||||
sampleRate, 2 * scrubOptions.minStutter,
|
||||
scrubOptions);
|
||||
mScrubDuration = 0;
|
||||
mSilentScrub = false;
|
||||
}
|
||||
@ -2548,10 +2548,10 @@ bool AudioIO::IsPaused()
|
||||
|
||||
#ifdef EXPERIMENTAL_SCRUBBING_SUPPORT
|
||||
bool AudioIO::EnqueueScrub
|
||||
(double endTimeOrSpeed, double maxSpeed, const ScrubbingOptions &options)
|
||||
(double endTimeOrSpeed, const ScrubbingOptions &options)
|
||||
{
|
||||
if (mScrubQueue)
|
||||
return mScrubQueue->Producer(endTimeOrSpeed, maxSpeed, options);
|
||||
return mScrubQueue->Producer(endTimeOrSpeed, options);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ class AUDACITY_DLL_API AudioIO final {
|
||||
* Return true if some sound was really enqueued.
|
||||
* But if the "stutter" is too short for the minimum, enqueue nothing and return false.
|
||||
*/
|
||||
bool EnqueueScrub(double endTimeOrSpeed, double maxSpeed, const ScrubbingOptions &options);
|
||||
bool EnqueueScrub(double endTimeOrSpeed, const ScrubbingOptions &options);
|
||||
|
||||
/** \brief return the ending time of the last enqueued scrub interval.
|
||||
*/
|
||||
|
@ -345,13 +345,13 @@ bool Scrubber::MaybeStartScrubbing(wxCoord xx)
|
||||
if (!mAlwaysSeeking) {
|
||||
// Take the starting speed limit from the transcription toolbar,
|
||||
// but it may be varied during the scrub.
|
||||
mOptions.maxSpeed =
|
||||
mMaxSpeed = mOptions.maxSpeed =
|
||||
mProject->GetTranscriptionToolBar()->GetPlaySpeed();
|
||||
}
|
||||
#else
|
||||
// That idea seems unpopular... just make it one for move-scrub,
|
||||
// but big for drag-scrub
|
||||
mOptions.maxSpeed = mDragging ? MaxDragSpeed : 1.0;
|
||||
mMaxSpeed = mOptions.maxSpeed = mDragging ? MaxDragSpeed : 1.0;
|
||||
#endif
|
||||
mOptions.minSample = 0;
|
||||
mOptions.maxSample =
|
||||
@ -367,7 +367,7 @@ bool Scrubber::MaybeStartScrubbing(wxCoord xx)
|
||||
static const double maxScrubSpeedBase =
|
||||
pow(2.0, 1.0 / ScrubSpeedStepsPerOctave);
|
||||
mLogMaxScrubSpeed = floor(0.5 +
|
||||
log(mOptions.maxSpeed) / log(maxScrubSpeedBase)
|
||||
log(mMaxSpeed) / log(maxScrubSpeedBase)
|
||||
);
|
||||
#endif
|
||||
mScrubSpeedDisplayCountdown = 0;
|
||||
@ -414,9 +414,10 @@ void Scrubber::ContinueScrubbingPoll()
|
||||
bool result = false;
|
||||
if (mPaused) {
|
||||
// When paused, enqueue silent scrubs.
|
||||
mOptions.maxSpeed = mMaxSpeed;
|
||||
mOptions.adjustStart = false;
|
||||
mOptions.enqueueBySpeed = true;
|
||||
result = gAudioIO->EnqueueScrub(0, mOptions.maxSpeed, mOptions);
|
||||
result = gAudioIO->EnqueueScrub(0, mOptions);
|
||||
}
|
||||
else {
|
||||
const wxMouseState state(::wxGetMouseState());
|
||||
@ -427,24 +428,25 @@ void Scrubber::ContinueScrubbingPoll()
|
||||
const auto lastTime = gAudioIO->GetLastTimeInScrubQueue();
|
||||
const auto delta = mLastScrubPosition - position.x;
|
||||
const double time = viewInfo.OffsetTimeByPixels(lastTime, delta);
|
||||
mOptions.maxSpeed = mMaxSpeed;
|
||||
mOptions.adjustStart = true;
|
||||
mOptions.enqueueBySpeed = false;
|
||||
result = gAudioIO->EnqueueScrub(time, mOptions.maxSpeed, mOptions);
|
||||
result = gAudioIO->EnqueueScrub(time, mOptions);
|
||||
mLastScrubPosition = position.x;
|
||||
}
|
||||
else {
|
||||
const double time = viewInfo.PositionToTime(position.x, trackPanel->GetLeftOffset());
|
||||
mOptions.adjustStart = seek;
|
||||
auto maxSpeed = (mDragging || !seek) ? mOptions.maxSpeed : 1.0;
|
||||
mOptions.maxSpeed = (mDragging || !seek) ? mMaxSpeed : 1.0;
|
||||
|
||||
if (mSmoothScrollingScrub) {
|
||||
const double speed = FindScrubSpeed(seek, time);
|
||||
mOptions.enqueueBySpeed = true;
|
||||
result = gAudioIO->EnqueueScrub(speed, maxSpeed, mOptions);
|
||||
result = gAudioIO->EnqueueScrub(speed, mOptions);
|
||||
}
|
||||
else {
|
||||
mOptions.enqueueBySpeed = false;
|
||||
result = gAudioIO->EnqueueScrub(time, maxSpeed, mOptions);
|
||||
result = gAudioIO->EnqueueScrub(time, mOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -550,7 +552,7 @@ double Scrubber::FindScrubSpeed(bool seeking, double time) const
|
||||
ViewInfo &viewInfo = mProject->GetViewInfo();
|
||||
const double screen = mProject->GetScreenEndTime() - viewInfo.h;
|
||||
return (seeking ? FindSeekSpeed : FindScrubbingSpeed)
|
||||
(viewInfo, mOptions.maxSpeed, screen, time);
|
||||
(viewInfo, mMaxSpeed, screen, time);
|
||||
}
|
||||
|
||||
void Scrubber::HandleScrollWheel(int steps)
|
||||
@ -569,7 +571,7 @@ void Scrubber::HandleScrollWheel(int steps)
|
||||
if (newSpeed >= ScrubbingOptions::MinAllowedScrubSpeed() &&
|
||||
newSpeed <= ScrubbingOptions::MaxAllowedScrubSpeed()) {
|
||||
mLogMaxScrubSpeed = newLogMaxScrubSpeed;
|
||||
mOptions.maxSpeed = newSpeed;
|
||||
mMaxSpeed = newSpeed;
|
||||
if (!mSmoothScrollingScrub)
|
||||
// Show the speed for one second
|
||||
mScrubSpeedDisplayCountdown = kOneSecondCountdown + 1;
|
||||
|
@ -178,6 +178,7 @@ private:
|
||||
std::unique_ptr<ScrubPoller> mPoller;
|
||||
|
||||
ScrubbingOptions mOptions;
|
||||
double mMaxSpeed { 1.0 };
|
||||
};
|
||||
|
||||
// Specialist in drawing the scrub speed, and listening for certain events
|
||||
|
Loading…
x
Reference in New Issue
Block a user