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...
 
TrackAddToOutputTracks (TrackList &&list)
 
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 list = aTrack->Duplicate();
44 mIMap.push_back(aTrack);
45 mOMap.push_back(*list->begin());
46 mOutputTracks->Append(std::move(*list));
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->ApplyStretchRatio(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:53
const EffectType mEffectType
std::vector< Track * > mOMap
std::vector< Track * > mIMap
std::shared_ptr< TrackList > mOutputTracks
static bool IsSelectedOrSyncLockSelected(const Track *pTrack)
Definition: SyncLock.cpp:112
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:122
virtual TrackListHolder Duplicate() const
public nonvirtual duplication function that invokes Clone()
Definition: Track.cpp:86
static TrackListHolder Create(AudacityProject *pOwner)
Definition: Track.cpp:365
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:1079
AudacityProject * GetOwner()
Definition: Track.h:1014
A Track that contains audio waveform data.
Definition: WaveTrack.h:222
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:329
WAVE_TRACK_API void WithStretchRenderingProgress(std::function< void(const ProgressReporter &)> action, TranslatableString title=defaultStretchRenderingTitle, TranslatableString message=XO("Rendering Time-Stretched Audio"))
WAVE_TRACK_API bool HasStretch(const WaveTrack &track, double t0, double t1)

References TrackList::Any(), TrackList::Create(), TrackList::GetOwner(), Track::GetSelected(), WaveTrackUtilities::HasStretch(), SyncLock::IsSelectedOrSyncLockSelected(), mIMap, mOMap, mOutputTracks, mTracks, BasicUI::SplitProgress(), and WaveTrackUtilities::WithStretchRenderingProgress().

Here is the call graph for this function:

◆ EffectOutputTracks() [2/2]

EffectOutputTracks::EffectOutputTracks ( const EffectOutputTracks )
delete

◆ ~EffectOutputTracks()

EffectOutputTracks::~EffectOutputTracks ( )
default

Member Function Documentation

◆ AddToOutputTracks() [1/2]

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

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

Precondition
t && t->IsLeader() && t->NChannels() == 1
Returns
a pointer to the given track

Definition at line 81 of file EffectOutputTracks.cpp.

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

References mIMap, mOMap, and mOutputTracks.

Referenced by NyquistEffect::ProcessOne().

Here is the caller graph for this function:

◆ AddToOutputTracks() [2/2]

Track * EffectOutputTracks::AddToOutputTracks ( TrackList &&  list)

An overload to add a "wide" output track, now represented as a TrackList, which will be moved-from.

Precondition
list.Size() == 1
Returns
a pointer to the given (leader) track

Definition at line 93 of file EffectOutputTracks.cpp.

94{
95 assert(list.Size() == 1);
96 mIMap.push_back(nullptr);
97 auto result = *list.begin();
98 mOMap.push_back(result);
99 mOutputTracks->Append(std::move(list));
100 // Invariant is maintained
101 assert(mIMap.size() == mOutputTracks->Size());
102 assert(mIMap.size() == mOMap.size());
103 return result;
104}
size_t Size() const
Definition: Track.h:1241
iterator begin()
Definition: Track.h:1032

References mIMap, mOMap, and mOutputTracks.

◆ Commit()

void EffectOutputTracks::Commit ( )

Replace input tracks with temporaries only on commit.

Definition at line 117 of file EffectOutputTracks.cpp.

118{
119 if (!mOutputTracks) {
120 // Already committed, violating precondition. Maybe wrong intent...
121 assert(false);
122 // ... but harmless
123 return;
124 }
125
126 size_t cnt = mOMap.size();
127 size_t i = 0;
128
129 while (!mOutputTracks->empty()) {
130 const auto pOutputTrack = *mOutputTracks->begin();
131
132 // If tracks were removed from mOutputTracks, then there will be
133 // tracks in the map that must be removed from mTracks.
134 while (i < cnt && mOMap[i] != pOutputTrack) {
135 const auto t = mIMap[i];
136 // Class invariant justifies the assertion
137 assert(t && t->IsLeader());
138 ++i;
139 mTracks.Remove(*t);
140 }
141
142 // The output track, still in the list, must also have been placed in
143 // the map
144 assert(i < cnt);
145
146 // Find the input track it corresponds to
147 if (!mIMap[i])
148 // This track was an addition to output tracks; add it to mTracks
149 mTracks.AppendOne(std::move(*mOutputTracks));
150 else if (
152 // Replace mTracks entry with the new track
153 mTracks.ReplaceOne(*mIMap[i], std::move(*mOutputTracks));
154 else
155 // This output track was just a placeholder for pre-processing. Discard
156 // it.
157 mOutputTracks->Remove(*pOutputTrack);
158 ++i;
159 }
160
161 // If tracks were removed from mOutputTracks, then there may be tracks
162 // left at the end of the map that must be removed from mTracks.
163 while (i < cnt) {
164 const auto t = mIMap[i];
165 // Class invariant justifies the assertion
166 assert(t && t->IsLeader());
167 ++i;
168 mTracks.Remove(*t);
169 }
170
171 // Reset map
172 mIMap.clear();
173 mOMap.clear();
174
175 // Make sure we processed everything
176 assert(mOutputTracks->empty());
177
178 // The output list is no longer needed
179 mOutputTracks.reset();
180 ++nEffectsDone;
181}
@ EffectTypeAnalyze
@ EffectTypeNone
void AppendOne(TrackList &&list)
Definition: Track.cpp:1470
void Remove(Track &track)
Remove a channel group, given the leader.
Definition: Track.cpp:745
TrackListHolder ReplaceOne(Track &t, TrackList &&with)
Definition: Track.cpp:637

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 88 of file EffectOutputTracks.h.

88{ return *mOutputTracks; }

Referenced by NyquistEffect::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 106 of file EffectOutputTracks.cpp.

107{
108 const auto it = std::find(mOMap.begin(), mOMap.end(), &outTrack);
109 if (it == mOMap.end())
110 return nullptr;
111 const auto index = it - mOMap.begin();
112 return mIMap[index];
113}

References mIMap, and mOMap.

Referenced by NyquistEffect::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 92 of file EffectOutputTracks.h.

Referenced by Commit().

◆ mIMap

std::vector<Track*> EffectOutputTracks::mIMap
private
Invariant
mIMap.size() == mOutputTracks->Size()
mIMap.size() == mOMap.size()
mIMap points to leaders only, or nulls

Definition at line 98 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 100 of file EffectOutputTracks.h.

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

◆ mTracks

TrackList& EffectOutputTracks::mTracks
private

Definition at line 91 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 NyquistEffect::Process().


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