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.GetTrackTime() has reached the end of playback. More...
 
double OffsetTrackTime (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.GetTrackTime() has reached the end of playback. More...
 
virtual double OffsetTrackTime (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::TrackBufferExchange. 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 103 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 149 of file ProjectAudioManager.cpp.

151: mGapLeft{ gapLeft }, mGapLength{ gapLength }
152{
153 wxASSERT(gapLength >= 0.0);
154}
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 250 of file ProjectAudioManager.cpp.

252{
253 auto realDuration = nSamples / mRate;
254 if (mDuration1 > 0) {
255 mDuration1 = std::max(0.0, mDuration1 - realDuration);
256 if (sampleCount(mDuration1 * mRate) == 0) {
257 mDuration1 = 0;
258 mDiscontinuity = true;
259 return { GapStart(), GapEnd() };
260 }
261 }
262 else
263 mDuration2 = std::max(0.0, mDuration2 - realDuration);
264 if (mReversed)
265 realDuration *= -1;
266 const double time = schedule.SolveWarpedLength(trackTime, realDuration);
267
268 if ( mReversed ? time <= mEnd : time >= mEnd )
269 return {mEnd, std::numeric_limits<double>::infinity()};
270 else
271 return {time, time};
272}
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 132 of file ProjectAudioManager.cpp.

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

◆ Done()

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

Returns true if schedule.GetTrackTime() 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 183 of file ProjectAudioManager.cpp.

184{
186 auto diff = schedule.GetTrackTime() - mEnd;
187 if (mReversed)
188 diff *= -1;
189 return sampleCount(diff * mRate) >= 0;
190}
double GetTrackTime() const
Get current track time value, unadjusted.

References PlaybackSchedule::GetTrackTime(), 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 130 of file ProjectAudioManager.cpp.

131 { 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 128 of file ProjectAudioManager.cpp.

129 { 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 229 of file ProjectAudioManager.cpp.

231{
232 size_t frames = available;
233 size_t toProduce = frames;
234 sampleCount samples1(mDuration1 * mRate + 0.5);
235 if (samples1 > 0 && samples1 < frames)
236 // Shorter slice than requested, up to the discontinuity
237 toProduce = frames = samples1.as_size_t();
238 else if (samples1 == 0) {
239 sampleCount samples2(mDuration2 * mRate + 0.5);
240 if (samples2 < frames) {
241 toProduce = samples2.as_size_t();
242 // Produce some extra silence so that the time queue consumer can
243 // satisfy its end condition
244 frames = std::min(available, toProduce + TimeQueueGrainSize + 1);
245 }
246 }
247 return { available, frames, toProduce };
248}
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 158 of file ProjectAudioManager.cpp.

160{
161 PlaybackPolicy::Initialize(schedule, rate);
162
163 // Examine mT0 and mT1 in the schedule only now; ignore changes during play
164 double left = mStart = schedule.mT0;
165 double right = mEnd = schedule.mT1;
166 mReversed = left > right;
167 if (mReversed)
168 std::swap(left, right);
169
170 if (left < mGapLeft)
171 mDuration1 = schedule.ComputeWarpedLength(left, mGapLeft);
172 const auto gapEnd = mGapLeft + mGapLength;
173 if (gapEnd < right)
174 mDuration2 = schedule.ComputeWarpedLength(gapEnd, right);
175 if (mReversed)
177 if (sampleCount(mDuration2 * rate) == 0)
181}
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:752
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:

◆ OffsetTrackTime()

double anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::OffsetTrackTime ( 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::GetTrackTime()
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 274 of file ProjectAudioManager.cpp.

276{
277 if (mDiscontinuity) {
278 mDiscontinuity = false;
279 auto newTime = GapEnd();
280 for (auto &pMixer : playbackMixers)
281 pMixer->Reposition(newTime, true);
282 // Tell TrackBufferExchange that we aren't done yet
283 return false;
284 }
285 return true;
286}

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 145 of file ProjectAudioManager.cpp.

Referenced by AdvancedTrackTime(), and RepositionPlayback().

◆ mDuration1

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

Definition at line 142 of file ProjectAudioManager.cpp.

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

◆ mDuration2

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

Definition at line 142 of file ProjectAudioManager.cpp.

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

◆ mEnd

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

Definition at line 139 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 136 of file ProjectAudioManager.cpp.

Referenced by Initialize().

◆ mGapLength

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

Definition at line 136 of file ProjectAudioManager.cpp.

Referenced by Initialize().

◆ mInitDuration1

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

Definition at line 143 of file ProjectAudioManager.cpp.

Referenced by Initialize().

◆ mInitDuration2

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

Definition at line 143 of file ProjectAudioManager.cpp.

Referenced by Initialize().

◆ mReversed

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

Definition at line 146 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 139 of file ProjectAudioManager.cpp.

Referenced by Initialize().


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