Audacity 3.2.0
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Attributes | List of all members
EffectOutputTracks Class Reference

Use this object to copy the input tracks to tentative outputTracks. More...

#include <EffectOutputTracks.h>

Collaboration diagram for EffectOutputTracks:
[legend]

Public Types

using TimeInterval = std::pair< double, double >
 

Public Member Functions

 EffectOutputTracks (TrackList &tracks, EffectType effectType, std::optional< TimeInterval > effectTimeInterval, bool allSyncLockSelected=false, bool stretchSyncLocked=false)
 
 EffectOutputTracks (const EffectOutputTracks &)=delete
 
 ~EffectOutputTracks ()
 
TrackAddToOutputTracks (const std::shared_ptr< Track > &t)
 Use this to add an output track, not corresponding to an input. More...
 
const TrackGetMatchingInput (const Track &outTrack) const
 Gets the matching input track for the given output track if it finds its match, else nullptr. More...
 
void Commit ()
 Replace input tracks with temporaries only on commit. More...
 
TrackListGet ()
 Expose the output track list for iterations or even erasures. More...
 

Static Public Member Functions

static void IncEffectCounter ()
 

Static Public Attributes

static int nEffectsDone = 0
 

Private Attributes

TrackListmTracks
 
const EffectType mEffectType
 
std::vector< Track * > mIMap
 
std::vector< Track * > mOMap
 
std::shared_ptr< TrackListmOutputTracks
 

Detailed Description

Use this object to copy the input tracks to tentative outputTracks.

Definition at line 28 of file EffectOutputTracks.h.

Member Typedef Documentation

◆ TimeInterval

using EffectOutputTracks::TimeInterval = std::pair<double, double>

Definition at line 35 of file EffectOutputTracks.h.

Constructor & Destructor Documentation

◆ EffectOutputTracks() [1/2]

EffectOutputTracks::EffectOutputTracks ( TrackList tracks,
EffectType  effectType,
std::optional< TimeInterval effectTimeInterval,
bool  allSyncLockSelected = false,
bool  stretchSyncLocked = false 
)
Parameters
effectTimeIntervalif given, and any copied tracks have clips with non-unit stretch intersecting that interval, then in the copies those clips are split, and new clips bounded by the interval, with the stretches applied, are inserted.
allSyncLockSelectedif true, unselected tracks that are sync-locked with a selected track are copied too
stretchSyncLockedif false, do not apply the stretch interval to any unselected WaveTrack that is copied
Precondition
!effectTimeInterval.has_value() || effectTimeInterval->first <= effectTimeInterval->second

Definition at line 20 of file EffectOutputTracks.cpp.

24 : mTracks { tracks }
25 , mEffectType { effectType }
26{
27 assert(
28 !effectTimeInterval.has_value() ||
29 effectTimeInterval->first <= effectTimeInterval->second);
30 // Reset map
31 mIMap.clear();
32 mOMap.clear();
34
35 auto trackRange = mTracks.Any() +
36 [&] (const Track *pTrack) {
37 return allSyncLockSelected
39 : dynamic_cast<const WaveTrack*>(pTrack) && pTrack->GetSelected();
40 };
41
42 for (auto aTrack : trackRange) {
43 auto pTrack = aTrack->Duplicate();
44 mIMap.push_back(aTrack);
45 mOMap.push_back(pTrack.get());
46 mOutputTracks->Add(pTrack);
47 }
48
49 if (
50 effectTimeInterval.has_value() &&
51 effectTimeInterval->second > effectTimeInterval->first)
52 {
54 [&](const ProgressReporter& parent)
55 {
56 const auto tracksToUnstretch =
57 (stretchSyncLocked ? mOutputTracks->Any<WaveTrack>() :
58 mOutputTracks->Selected<WaveTrack>()) +
59 [&](const WaveTrack* pTrack)
60 {
62 *pTrack, effectTimeInterval->first,
63 effectTimeInterval->second);
64 };
66 tracksToUnstretch.begin(), tracksToUnstretch.end(),
67 [&](WaveTrack* aTrack, const ProgressReporter& child) {
68 aTrack->ApplyPitchAndSpeed(effectTimeInterval, child);
69 },
70 parent);
71 });
72 }
73
74 // Invariant is established
75 assert(mIMap.size() == mOutputTracks->Size());
76 assert(mIMap.size() == mOMap.size());
77}
const auto tracks
std::function< void(double)> ProgressReporter
Definition: Track.h:48
const EffectType mEffectType
std::vector< Track * > mOMap
std::vector< Track * > mIMap
std::shared_ptr< TrackList > mOutputTracks
static bool IsSelectedOrSyncLockSelected(const Track &track)
Definition: SyncLock.cpp:104
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
virtual Holder Duplicate(DuplicateOptions={}) const
public nonvirtual duplication function that invokes Clone()
Definition: Track.cpp:109
static TrackListHolder Create(AudacityProject *pOwner)
Definition: Track.cpp:330
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:950
AudacityProject * GetOwner()
Definition: Track.h:887
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
void SplitProgress(ItType first, ItType last, FnType action, ProgressReporter parent)
Helper for the update of a task's progress bar when this task is made of a range's subtasks.
Definition: BasicUI.h:339
WAVE_TRACK_API void WithClipRenderingProgress(std::function< void(const ProgressReporter &)> action, TranslatableString title=defaultStretchRenderingTitle)
WAVE_TRACK_API bool HasPitchOrSpeed(const WaveTrack &track, double t0, double t1)

References TrackList::Any(), TrackList::Create(), TrackList::GetOwner(), Track::GetSelected(), TimeStretching::HasPitchOrSpeed(), SyncLock::IsSelectedOrSyncLockSelected(), mIMap, mOMap, mOutputTracks, mTracks, BasicUI::SplitProgress(), and TimeStretching::WithClipRenderingProgress().

Here is the call graph for this function:

◆ EffectOutputTracks() [2/2]

EffectOutputTracks::EffectOutputTracks ( const EffectOutputTracks )
delete

◆ ~EffectOutputTracks()

EffectOutputTracks::~EffectOutputTracks ( )
default

Member Function Documentation

◆ AddToOutputTracks()

Track * EffectOutputTracks::AddToOutputTracks ( const std::shared_ptr< Track > &  t)

Use this to add an output track, not corresponding to an input.

Returns
a pointer to the given track

Definition at line 81 of file EffectOutputTracks.cpp.

82{
83 mIMap.push_back(nullptr);
84 mOMap.push_back(t.get());
85 auto result = mOutputTracks->Add(t);
86 // Invariant is maintained
87 assert(mIMap.size() == mOutputTracks->Size());
88 assert(mIMap.size() == mOMap.size());
89 return result;
90}

References mIMap, mOMap, and mOutputTracks.

Referenced by NyquistBase::ProcessOne().

Here is the caller graph for this function:

◆ Commit()

void EffectOutputTracks::Commit ( )

Replace input tracks with temporaries only on commit.

Definition at line 103 of file EffectOutputTracks.cpp.

104{
105 if (!mOutputTracks) {
106 // Already committed, violating precondition. Maybe wrong intent...
107 assert(false);
108 // ... but harmless
109 return;
110 }
111
112 size_t cnt = mOMap.size();
113 size_t i = 0;
114
115 while (!mOutputTracks->empty()) {
116 const auto pOutputTrack = *mOutputTracks->begin();
117
118 // If tracks were removed from mOutputTracks, then there will be
119 // tracks in the map that must be removed from mTracks.
120 while (i < cnt && mOMap[i] != pOutputTrack) {
121 const auto t = mIMap[i];
122 // Class invariant justifies the assertion
123 assert(t);
124 ++i;
125 mTracks.Remove(*t);
126 }
127
128 // The output track, still in the list, must also have been placed in
129 // the map
130 assert(i < cnt);
131
132 // Find the input track it corresponds to
133 if (!mIMap[i])
134 // This track was an addition to output tracks; add it to mTracks
135 mTracks.AppendOne(std::move(*mOutputTracks));
136 else if (
138 // Replace mTracks entry with the new track
139 mTracks.ReplaceOne(*mIMap[i], std::move(*mOutputTracks));
140 else
141 // This output track was just a placeholder for pre-processing. Discard
142 // it.
143 mOutputTracks->Remove(*pOutputTrack);
144 ++i;
145 }
146
147 // If tracks were removed from mOutputTracks, then there may be tracks
148 // left at the end of the map that must be removed from mTracks.
149 while (i < cnt) {
150 const auto t = mIMap[i];
151 // Class invariant justifies the assertion
152 assert(t);
153 ++i;
154 mTracks.Remove(*t);
155 }
156
157 // Reset map
158 mIMap.clear();
159 mOMap.clear();
160
161 // Make sure we processed everything
162 assert(mOutputTracks->empty());
163
164 // The output list is no longer needed
165 mOutputTracks.reset();
166 ++nEffectsDone;
167}
@ EffectTypeAnalyze
@ EffectTypeNone
void AppendOne(TrackList &&list)
Remove first track (if any) from list and put it at the end of this
Definition: Track.cpp:886
Track::Holder ReplaceOne(Track &t, TrackList &&with)
Definition: Track.cpp:560
Track::Holder Remove(Track &track)
Remove a track and return it.
Definition: Track.cpp:584

References TrackList::AppendOne(), EffectTypeAnalyze, EffectTypeNone, mEffectType, mIMap, mOMap, mOutputTracks, mTracks, nEffectsDone, TrackList::Remove(), and TrackList::ReplaceOne().

Here is the call graph for this function:

◆ Get()

TrackList & EffectOutputTracks::Get ( )
inline

Expose the output track list for iterations or even erasures.

Definition at line 80 of file EffectOutputTracks.h.

80{ return *mOutputTracks; }

Referenced by NyquistBase::ProcessOne().

Here is the caller graph for this function:

◆ GetMatchingInput()

const Track * EffectOutputTracks::GetMatchingInput ( const Track outTrack) const

Gets the matching input track for the given output track if it finds its match, else nullptr.

Definition at line 92 of file EffectOutputTracks.cpp.

93{
94 const auto it = std::find(mOMap.begin(), mOMap.end(), &outTrack);
95 if (it == mOMap.end())
96 return nullptr;
97 const auto index = it - mOMap.begin();
98 return mIMap[index];
99}

References mIMap, and mOMap.

Referenced by NyquistBase::ProcessOne().

Here is the caller graph for this function:

◆ IncEffectCounter()

static void EffectOutputTracks::IncEffectCounter ( )
inlinestatic

Definition at line 33 of file EffectOutputTracks.h.

33{ ++nEffectsDone; }

Referenced by SelectTracksCommand::Apply().

Here is the caller graph for this function:

Member Data Documentation

◆ mEffectType

const EffectType EffectOutputTracks::mEffectType
private

Definition at line 84 of file EffectOutputTracks.h.

Referenced by Commit().

◆ mIMap

std::vector<Track*> EffectOutputTracks::mIMap
private
Invariant
mIMap.size() == mOutputTracks->Size()
mIMap.size() == mOMap.size()

Definition at line 89 of file EffectOutputTracks.h.

Referenced by AddToOutputTracks(), Commit(), EffectOutputTracks(), and GetMatchingInput().

◆ mOMap

std::vector<Track*> EffectOutputTracks::mOMap
private

◆ mOutputTracks

std::shared_ptr<TrackList> EffectOutputTracks::mOutputTracks
private

Definition at line 91 of file EffectOutputTracks.h.

Referenced by AddToOutputTracks(), Commit(), and EffectOutputTracks().

◆ mTracks

TrackList& EffectOutputTracks::mTracks
private

Definition at line 83 of file EffectOutputTracks.h.

Referenced by Commit(), and EffectOutputTracks().

◆ nEffectsDone

int EffectOutputTracks::nEffectsDone = 0
static

Definition at line 32 of file EffectOutputTracks.h.

Referenced by Commit(), and NyquistBase::Process().


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