Audacity 3.2.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy Class Referencefinal
Inheritance diagram for anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy:
[legend]
Collaboration diagram for anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy:
[legend]

Public Member Functions

 CutPreviewPlaybackPolicy (double gapLeft, double gapLength)
 
 ~CutPreviewPlaybackPolicy () override
 
void Initialize (PlaybackSchedule &schedule, double rate) override
 Called before starting an audio stream. More...
 
bool Done (PlaybackSchedule &schedule, unsigned long) override
 Returns true if schedule.GetSequenceTime() has reached the end of playback. More...
 
double OffsetSequenceTime (PlaybackSchedule &schedule, double offset) override
 Called when the play head needs to jump a certain distance. More...
 
PlaybackSlice GetPlaybackSlice (PlaybackSchedule &schedule, size_t available) override
 Choose length of one fetch of samples from tracks in a call to AudioIO::FillPlayBuffers. More...
 
std::pair< double, double > AdvancedTrackTime (PlaybackSchedule &schedule, double trackTime, size_t nSamples) override
 Compute a new point in a track's timeline from an old point and a real duration. More...
 
bool RepositionPlayback (PlaybackSchedule &schedule, const Mixers &playbackMixers, size_t frames, size_t available) override
 AudioIO::FillPlayBuffers calls this to update its cursors into tracks for changes of position or speed. More...
 
- Public Member Functions inherited from PlaybackPolicy
virtual ~PlaybackPolicy ()=0
 
virtual void Initialize (PlaybackSchedule &schedule, double rate)
 Called before starting an audio stream. More...
 
virtual void Finalize (PlaybackSchedule &schedule)
 Called after stopping of an audio stream or an unsuccessful start. More...
 
virtual Mixer::WarpOptions MixerWarpOptions (PlaybackSchedule &schedule)
 Options to use when constructing mixers for each playback track. More...
 
virtual BufferTimes SuggestedBufferTimes (PlaybackSchedule &schedule)
 Provide hints for construction of playback RingBuffer objects. More...
 
virtual bool AllowSeek (PlaybackSchedule &schedule)
 Whether repositioning commands are allowed during playback. More...
 
virtual bool Done (PlaybackSchedule &schedule, unsigned long outputFrames)
 Returns true if schedule.GetSequenceTime() has reached the end of playback. More...
 
virtual double OffsetSequenceTime (PlaybackSchedule &schedule, double offset)
 Called when the play head needs to jump a certain distance. More...
 
virtual std::chrono::milliseconds SleepInterval (PlaybackSchedule &schedule)
 How long to wait between calls to AudioIO::SequenceBufferExchange. More...
 
virtual PlaybackSlice GetPlaybackSlice (PlaybackSchedule &schedule, size_t available)
 Choose length of one fetch of samples from tracks in a call to AudioIO::FillPlayBuffers. More...
 
virtual std::pair< double, double > AdvancedTrackTime (PlaybackSchedule &schedule, double trackTime, size_t nSamples)
 Compute a new point in a track's timeline from an old point and a real duration. More...
 
virtual bool RepositionPlayback (PlaybackSchedule &schedule, const Mixers &playbackMixers, size_t frames, size_t available)
 AudioIO::FillPlayBuffers calls this to update its cursors into tracks for changes of position or speed. More...
 
virtual bool Looping (const PlaybackSchedule &schedule) const
 

Private Member Functions

double GapStart () const
 
double GapEnd () const
 
bool AtOrBefore (double trackTime1, double trackTime2) const
 

Private Attributes

const double mGapLeft
 Fixed at construction time; these are a track time and duration. More...
 
const double mGapLength
 
double mStart = 0
 Starting and ending track times set in Initialize() More...
 
double mEnd = 0
 
double mDuration1 = 0
 
double mDuration2 = 0
 
double mInitDuration1 = 0
 
double mInitDuration2 = 0
 
bool mDiscontinuity { false }
 
bool mReversed { false }
 

Additional Inherited Members

- Public Types inherited from PlaybackPolicy
using Duration = std::chrono::duration< double >
 
using Mixers = std::vector< std::unique_ptr< Mixer > >
 
- Protected Attributes inherited from PlaybackPolicy
double mRate = 0
 

Detailed Description

Definition at line 107 of file ProjectAudioManager.cpp.

Constructor & Destructor Documentation

◆ CutPreviewPlaybackPolicy()

anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::CutPreviewPlaybackPolicy ( double  gapLeft,
double  gapLength 
)
Parameters
gapLeftLower bound track time of of elision
gapLengthNon-negative track duration

Definition at line 153 of file ProjectAudioManager.cpp.

155: mGapLeft{ gapLeft }, mGapLength{ gapLength }
156{
157 wxASSERT(gapLength >= 0.0);
158}
const double mGapLeft
Fixed at construction time; these are a track time and duration.

◆ ~CutPreviewPlaybackPolicy()

anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::~CutPreviewPlaybackPolicy ( )
overridedefault

Member Function Documentation

◆ AdvancedTrackTime()

std::pair< double, double > anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::AdvancedTrackTime ( PlaybackSchedule schedule,
double  trackTime,
size_t  nSamples 
)
overridevirtual

Compute a new point in a track's timeline from an old point and a real duration.

Needed because playback might be at non-unit speed.

Called one or more times between GetPlaybackSlice and RepositionPlayback, until the sum of the nSamples values equals the most recent playback slice (including any trailing silence).

Returns
a pair, which indicates a discontinuous jump when its members are not equal, or specially the end of playback when the second member is infinite

Reimplemented from PlaybackPolicy.

Definition at line 254 of file ProjectAudioManager.cpp.

256{
257 auto realDuration = nSamples / mRate;
258 if (mDuration1 > 0) {
259 mDuration1 = std::max(0.0, mDuration1 - realDuration);
260 if (sampleCount(mDuration1 * mRate) == 0) {
261 mDuration1 = 0;
262 mDiscontinuity = true;
263 return { GapStart(), GapEnd() };
264 }
265 }
266 else
267 mDuration2 = std::max(0.0, mDuration2 - realDuration);
268 if (mReversed)
269 realDuration *= -1;
270 const double time = schedule.SolveWarpedLength(trackTime, realDuration);
271
272 if ( mReversed ? time <= mEnd : time >= mEnd )
273 return {mEnd, std::numeric_limits<double>::infinity()};
274 else
275 return {time, time};
276}
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
double SolveWarpedLength(double t0, double length) const
Compute how much unwarped time must have elapsed if length seconds of warped time has elapsed,...

References GapEnd(), GapStart(), mDiscontinuity, mDuration1, mDuration2, mEnd, PlaybackPolicy::mRate, mReversed, and PlaybackSchedule::SolveWarpedLength().

Here is the call graph for this function:

◆ AtOrBefore()

bool anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::AtOrBefore ( double  trackTime1,
double  trackTime2 
) const
inlineprivate

Definition at line 136 of file ProjectAudioManager.cpp.

137 { return mReversed ? trackTime1 >= trackTime2 : trackTime1 <= trackTime2; }

◆ Done()

bool anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::Done ( PlaybackSchedule schedule,
unsigned long  outputFrames 
)
overridevirtual

Returns true if schedule.GetSequenceTime() has reached the end of playback.

Called in the PortAudio thread

Parameters
outputFrameshow many playback frames were taken from RingBuffers

Reimplemented from PlaybackPolicy.

Definition at line 187 of file ProjectAudioManager.cpp.

188{
190 auto diff = schedule.GetSequenceTime() - mEnd;
191 if (mReversed)
192 diff *= -1;
193 return sampleCount(diff * mRate) >= 0;
194}
double GetSequenceTime() const
Get current track time value, unadjusted.

References PlaybackSchedule::GetSequenceTime(), mEnd, PlaybackPolicy::mRate, and mReversed.

Here is the call graph for this function:

◆ GapEnd()

double anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::GapEnd ( ) const
inlineprivate

Definition at line 134 of file ProjectAudioManager.cpp.

135 { return mReversed ? mGapLeft : mGapLeft + mGapLength; }

Referenced by AdvancedTrackTime(), and RepositionPlayback().

Here is the caller graph for this function:

◆ GapStart()

double anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::GapStart ( ) const
inlineprivate

Definition at line 132 of file ProjectAudioManager.cpp.

133 { return mReversed ? mGapLeft + mGapLength : mGapLeft; }

Referenced by AdvancedTrackTime().

Here is the caller graph for this function:

◆ GetPlaybackSlice()

PlaybackSlice anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::GetPlaybackSlice ( PlaybackSchedule schedule,
size_t  available 
)
overridevirtual

Choose length of one fetch of samples from tracks in a call to AudioIO::FillPlayBuffers.

Parameters
availableupper bound for the length of the fetch

Reimplemented from PlaybackPolicy.

Definition at line 233 of file ProjectAudioManager.cpp.

235{
236 size_t frames = available;
237 size_t toProduce = frames;
238 sampleCount samples1(mDuration1 * mRate + 0.5);
239 if (samples1 > 0 && samples1 < frames)
240 // Shorter slice than requested, up to the discontinuity
241 toProduce = frames = samples1.as_size_t();
242 else if (samples1 == 0) {
243 sampleCount samples2(mDuration2 * mRate + 0.5);
244 if (samples2 < frames) {
245 toProduce = samples2.as_size_t();
246 // Produce some extra silence so that the time queue consumer can
247 // satisfy its end condition
248 frames = std::min(available, toProduce + TimeQueueGrainSize + 1);
249 }
250 }
251 return { available, frames, toProduce };
252}
int min(int a, int b)
constexpr size_t TimeQueueGrainSize

References sampleCount::as_size_t(), mDuration1, mDuration2, min(), PlaybackPolicy::mRate, and TimeQueueGrainSize.

Here is the call graph for this function:

◆ Initialize()

void anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::Initialize ( PlaybackSchedule schedule,
double  rate 
)
overridevirtual

Called before starting an audio stream.

Reimplemented from PlaybackPolicy.

Definition at line 162 of file ProjectAudioManager.cpp.

164{
165 PlaybackPolicy::Initialize(schedule, rate);
166
167 // Examine mT0 and mT1 in the schedule only now; ignore changes during play
168 double left = mStart = schedule.mT0;
169 double right = mEnd = schedule.mT1;
170 mReversed = left > right;
171 if (mReversed)
172 std::swap(left, right);
173
174 if (left < mGapLeft)
175 mDuration1 = schedule.ComputeWarpedLength(left, mGapLeft);
176 const auto gapEnd = mGapLeft + mGapLength;
177 if (gapEnd < right)
178 mDuration2 = schedule.ComputeWarpedLength(gapEnd, right);
179 if (mReversed)
181 if (sampleCount(mDuration2 * rate) == 0)
185}
virtual void Initialize(PlaybackSchedule &schedule, double rate)
Called before starting an audio stream.
double mStart
Starting and ending track times set in Initialize()
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:634
double mT0
Playback starts at offset of mT0, which is measured in seconds.
double mT1
Playback ends at offset of mT1, which is measured in seconds. Note that mT1 may be less than mT0 duri...
double ComputeWarpedLength(double t0, double t1) const
Compute signed duration (in seconds at playback) of the specified region of the track.

References PlaybackSchedule::ComputeWarpedLength(), PlaybackPolicy::Initialize(), mDuration1, mDuration2, mEnd, mGapLeft, mGapLength, mInitDuration1, mInitDuration2, mReversed, mStart, PlaybackSchedule::mT0, PlaybackSchedule::mT1, and anonymous_namespace{NoteTrack.cpp}::swap().

Here is the call graph for this function:

◆ OffsetSequenceTime()

double anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::OffsetSequenceTime ( PlaybackSchedule schedule,
double  offset 
)
overridevirtual

Called when the play head needs to jump a certain distance.

Parameters
offsetsigned amount requested to be added to schedule::GetSequenceTime()
Returns
the new value that will be set as the schedule's track time

Reimplemented from PlaybackPolicy.

◆ RepositionPlayback()

bool anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::RepositionPlayback ( PlaybackSchedule schedule,
const Mixers playbackMixers,
size_t  frames,
size_t  available 
)
overridevirtual

AudioIO::FillPlayBuffers calls this to update its cursors into tracks for changes of position or speed.

Returns
if true, AudioIO::FillPlayBuffers stops producing samples even if space remains
Parameters
frameshow many samples were just now buffered for play
availablehow many more samples may be buffered

Reimplemented from PlaybackPolicy.

Definition at line 278 of file ProjectAudioManager.cpp.

280{
281 if (mDiscontinuity) {
282 mDiscontinuity = false;
283 auto newTime = GapEnd();
284 for (auto &pMixer : playbackMixers)
285 pMixer->Reposition(newTime, true);
286 // Tell SequenceBufferExchange that we aren't done yet
287 return false;
288 }
289 return true;
290}

References GapEnd(), and mDiscontinuity.

Here is the call graph for this function:

Member Data Documentation

◆ mDiscontinuity

bool anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::mDiscontinuity { false }
private

Definition at line 149 of file ProjectAudioManager.cpp.

Referenced by AdvancedTrackTime(), and RepositionPlayback().

◆ mDuration1

double anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::mDuration1 = 0
private

Definition at line 146 of file ProjectAudioManager.cpp.

Referenced by AdvancedTrackTime(), GetPlaybackSlice(), and Initialize().

◆ mDuration2

double anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::mDuration2 = 0
private

Definition at line 146 of file ProjectAudioManager.cpp.

Referenced by AdvancedTrackTime(), GetPlaybackSlice(), and Initialize().

◆ mEnd

double anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::mEnd = 0
private

Definition at line 143 of file ProjectAudioManager.cpp.

Referenced by AdvancedTrackTime(), Done(), and Initialize().

◆ mGapLeft

const double anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::mGapLeft
private

Fixed at construction time; these are a track time and duration.

Definition at line 140 of file ProjectAudioManager.cpp.

Referenced by Initialize().

◆ mGapLength

const double anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::mGapLength
private

Definition at line 140 of file ProjectAudioManager.cpp.

Referenced by Initialize().

◆ mInitDuration1

double anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::mInitDuration1 = 0
private

Definition at line 147 of file ProjectAudioManager.cpp.

Referenced by Initialize().

◆ mInitDuration2

double anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::mInitDuration2 = 0
private

Definition at line 147 of file ProjectAudioManager.cpp.

Referenced by Initialize().

◆ mReversed

bool anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::mReversed { false }
private

Definition at line 150 of file ProjectAudioManager.cpp.

Referenced by AdvancedTrackTime(), Done(), and Initialize().

◆ mStart

double anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::mStart = 0
private

Starting and ending track times set in Initialize()

Definition at line 143 of file ProjectAudioManager.cpp.

Referenced by Initialize().


The documentation for this class was generated from the following file: