Audacity 3.2.0
Typedefs | Functions
MixAndRender.h File Reference
#include "Mix.h"
#include "SampleFormat.h"
#include "Track.h"
#include <memory>
Include dependency graph for MixAndRender.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

using ChannelNames = const ChannelName *
 

Functions

EFFECTS_API Track::Holder MixAndRender (const TrackIterRange< const WaveTrack > &trackRange, const Mixer::WarpOptions &warpOptions, const wxString &newTrackName, WaveTrackFactory *factory, double rate, sampleFormat format, double startTime, double endTime)
 Mixes together all input tracks, applying any envelopes, amplitude gain, panning, and real-time effects in the process. More...
 
EFFECTS_API std::vector< MixerOptions::StageSpecificationGetEffectStages (const WaveTrack &track)
 

Typedef Documentation

◆ ChannelNames

using ChannelNames = const ChannelName *

Definition at line 51 of file MixAndRender.h.

Function Documentation

◆ GetEffectStages()

EFFECTS_API std::vector< MixerOptions::StageSpecification > GetEffectStages ( const WaveTrack track)

Definition at line 171 of file MixAndRender.cpp.

172{
173 auto &effects = RealtimeEffectList::Get(track);
174 if (!effects.IsActive())
175 return {};
176 std::vector<MixerOptions::StageSpecification> result;
177 for (size_t i = 0, count = effects.GetStatesCount(); i < count; ++i) {
178 const auto pState = effects.GetStateAt(i);
179 if (!pState->IsEnabled())
180 continue;
181 const auto pEffect = pState->GetEffect();
182 if (!pEffect)
183 continue;
184 const auto &settings = pState->GetSettings();
185 if (!settings.has_value())
186 continue;
187 auto &stage = result.emplace_back(MixerOptions::StageSpecification{
188 [pEffect]{ return pEffect->MakeInstance(); },
189 settings });
190 }
191 return result;
192}
static Settings & settings()
Definition: TrackInfo.cpp:69
static RealtimeEffectList & Get(AudacityProject &project)

References RealtimeEffectList::Get(), and settings().

Referenced by ExportPluginHelpers::CreateMixer(), MixAndRender(), and EffectStereoToMono::ProcessOne().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MixAndRender()

EFFECTS_API Track::Holder MixAndRender ( const TrackIterRange< const WaveTrack > &  trackRange,
const Mixer::WarpOptions warpOptions,
const wxString &  newTrackName,
WaveTrackFactory factory,
double  rate,
sampleFormat  format,
double  startTime,
double  endTime 
)

Mixes together all input tracks, applying any envelopes, amplitude gain, panning, and real-time effects in the process.

Takes one or more tracks as input; of all the WaveTrack s, it mixes them together, applying any envelopes, amplitude gain, panning, and real-time effects in the process. The resulting pair of tracks (stereo) are "rendered" and have no effects, gain, panning, or envelopes. Other sorts of tracks are ignored. If the start and end times passed are the same this is taken as meaning no explicit time range to process, and the whole occupied length of the input tracks is processed.

Channel group properties of the result are copied from the first input track, except that newTrackName is applied when more than one track is mixed.

Parameters
newTrackNameused only when there is more than one input track (one mono channel or a stereo pair); else the unique track's name is copied

Definition at line 22 of file MixAndRender.cpp.

28{
29 if (trackRange.empty())
30 return {};
31
32 // This function was formerly known as "Quick Mix".
33 bool mono = false; /* flag if output can be mono without losing anything*/
34 bool oneinput = false; /* flag set to true if there is only one input track
35 (mono or stereo) */
36
37 auto first = *trackRange.begin();
38 assert(first); // because the range is known to be nonempty
39
40 // this only iterates tracks which are relevant to this function, i.e.
41 // selected WaveTracks. The tracklist is (confusingly) the list of all
42 // tracks in the project
43
44 size_t numWaves = 0; /* number of wave tracks in the selection */
45 size_t numMono = 0; /* number of mono, centre-panned wave tracks in selection*/
46 for (auto wt : trackRange) {
47 numWaves += wt->NChannels();
48 if (IsMono(*wt) && wt->GetPan() == 0)
49 numMono++;
50 }
51
52 if (numMono == numWaves)
53 mono = true;
54
55 /* the next loop will do two things at once:
56 * 1. build an array of all the wave tracks were are trying to process
57 * 2. determine when the set of WaveTracks starts and ends, in case we
58 * need to work out for ourselves when to start and stop rendering.
59 */
60
61 double mixStartTime = 0.0; /* start time of first track to start */
62 bool gotstart = false; // flag indicates we have found a start time
63 double mixEndTime = 0.0; /* end time of last track to end */
64 double tstart, tend; // start and end times for one track.
65
66 Mixer::Inputs waveArray;
67
68 for (auto wt : trackRange) {
69 const auto stretchingSequence =
70 StretchingSequence::Create(*wt, wt->GetClipInterfaces());
71 waveArray.emplace_back(stretchingSequence, GetEffectStages(*wt));
72 tstart = wt->GetStartTime();
73 tend = wt->GetEndTime();
74 if (tend > mixEndTime)
75 mixEndTime = tend;
76 // try and get the start time. If the track is empty we will get 0,
77 // which is ambiguous because it could just mean the track starts at
78 // the beginning of the project, as well as empty track. The give-away
79 // is that an empty track also ends at zero.
80
81 if (tstart != tend) {
82 // we don't get empty tracks here
83 if (!gotstart) {
84 // no previous start, use this one unconditionally
85 mixStartTime = tstart;
86 gotstart = true;
87 } else if (tstart < mixStartTime)
88 mixStartTime = tstart; // have a start, only make it smaller
89 } // end if start and end are different
90 }
91
92 /* create the destination track (NEW track) */
93 if (numWaves == first->NChannels())
94 oneinput = true;
95 // only one input track (either 1 mono or one linked stereo pair)
96
97 auto mix = trackFactory->Create(mono ? 1 : 2, *first);
98 mix->SetPan(0);
99 mix->SetGain(1.0f);
100 mix->SetRate(rate);
101 mix->ConvertToSampleFormat(format);
102 if(!oneinput)
103 mix->SetName(newTrackName);
104 mix->MoveTo(mixStartTime);
105
106 auto maxBlockLen = mix->GetIdealBlockSize();
107
108 // If the caller didn't specify a time range, use the whole range in which
109 // any input track had clips in it.
110 if (startTime == endTime) {
111 startTime = mixStartTime;
112 endTime = mixEndTime;
113 }
114
115 Mixer mixer(move(waveArray),
116 // Throw to abort mix-and-render if read fails:
117 true, warpOptions,
118 startTime, endTime, mono ? 1 : 2, maxBlockLen, false,
119 rate, format);
120
121 using namespace BasicUI;
122 auto updateResult = ProgressResult::Success;
123 {
124 auto effectiveFormat = mixer.EffectiveFormat();
125 auto pProgress = MakeProgress(XO("Mix and Render"),
126 XO("Mixing and rendering tracks"));
127
128 while (updateResult == ProgressResult::Success) {
129 auto blockLen = mixer.Process();
130
131 if (blockLen == 0)
132 break;
133
134 for(auto channel : mix->Channels())
135 {
136 auto buffer = mixer.GetBuffer(channel->GetChannelIndex());
137 channel->AppendBuffer(buffer, format, blockLen, 1, effectiveFormat);
138 }
139
140 updateResult = pProgress->Poll(
141 mixer.MixGetCurrentTime() - startTime, endTime - startTime);
142 }
143 }
144 mix->Flush();
145 if (updateResult == ProgressResult::Cancelled ||
146 updateResult == ProgressResult::Failed)
147 return {};
148 else {
149#if 0
150 int elapsedMS = wxGetElapsedTime();
151 double elapsedTime = elapsedMS * 0.001;
152 double maxTracks = totalTime / (elapsedTime / numWaves);
153
154 // Note: these shouldn't be translated - they're for debugging
155 // and profiling only.
156 wxPrintf(" Tracks: %d\n", numWaves);
157 wxPrintf(" Mix length: %f sec\n", totalTime);
158 wxPrintf("Elapsed time: %f sec\n", elapsedTime);
159 wxPrintf("Max number of tracks to mix in real time: %f\n", maxTracks);
160#endif
162 }
163
164 return mix;
165}
XO("Cut/Copy/Paste")
std::vector< MixerOptions::StageSpecification > GetEffectStages(const WaveTrack &track)
Functions for doing the mixdown of the tracks.
Definition: Mix.h:27
std::vector< Input > Inputs
Definition: Mix.h:45
void Clear()
Use only in the main thread. Sends Remove messages.
static std::shared_ptr< StretchingSequence > Create(const PlayableSequence &, const ClipConstHolders &clips)
bool IsMono(const Channel &channel)
Whether the channel is mono.
std::unique_ptr< ProgressDialog > MakeProgress(const TranslatableString &title, const TranslatableString &message, unsigned flags=(ProgressShowStop|ProgressShowCancel), const TranslatableString &remainingLabelText={})
Create and display a progress dialog.
Definition: BasicUI.h:294
bool empty() const
Definition: IteratorX.h:58
Iterator begin() const
Definition: IteratorX.h:52

References IteratorRange< Iterator >::begin(), BasicUI::Cancelled, RealtimeEffectList::Clear(), WaveTrackFactory::Create(), StretchingSequence::Create(), Mixer::EffectiveFormat(), IteratorRange< Iterator >::empty(), BasicUI::Failed, anonymous_namespace{ExportPCM.cpp}::format, RealtimeEffectList::Get(), Mixer::GetBuffer(), GetEffectStages(), AudioGraph::IsMono(), BasicUI::MakeProgress(), Mixer::MixGetCurrentTime(), Mixer::Process(), BasicUI::Success, and XO().

Referenced by anonymous_namespace{TrackMenus.cpp}::DoMixAndRender(), EffectPreview(), and WaveTrackMenuTable::OnMergeStereo().

Here is the call graph for this function:
Here is the caller graph for this function: