Audacity 3.2.0
ExportPluginHelpers.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 ExportPluginHelpers.cpp
6
7 Dominic Mazzoni
8
9 Vitaly Sverchinsky split from ExportPlugin.h
10
11**********************************************************************/
12
13#include "ExportPluginHelpers.h"
14#include "Track.h"
15#include "Mix.h"
16#include "WaveTrack.h"
17#include "MixAndRender.h"
18#include "ExportUtils.h"
19#include "ExportPlugin.h"
20#include "StretchingSequence.h"
21
22//Create a mixer by computing the time warp factor
23std::unique_ptr<Mixer> ExportPluginHelpers::CreateMixer(
24 const AudacityProject& project, bool selectionOnly, double startTime,
25 double stopTime, unsigned numOutChannels, size_t outBufferSize,
26 bool outInterleaved, double outRate, sampleFormat outFormat,
27 MixerOptions::Downmix* mixerSpec)
28{
29 Mixer::Inputs inputs;
30 const auto& tracks = TrackList::Get(project);
31 for (auto pTrack: ExportUtils::FindExportWaveTracks(tracks, selectionOnly))
32 inputs.emplace_back(
33 StretchingSequence::Create(*pTrack, pTrack->GetClipInterfaces()),
34 GetEffectStages(*pTrack));
35 auto masterEffectStages = GetMasterEffectStages(project);
36 //custom channel mapping isn't support with master effects on
37 assert(masterEffectStages.empty() || (numOutChannels <= 2 && mixerSpec == nullptr));
38 // MB: the stop time should not be warped, this was a bug.
39 return std::make_unique<Mixer>(
40 std::move(inputs), std::move(masterEffectStages),
41 // Throw, to stop exporting, if read fails:
42 true, Mixer::WarpOptions { tracks.GetOwner() }, startTime, stopTime,
43 numOutChannels, outBufferSize, outInterleaved, outRate, outFormat, true,
44 mixerSpec,
46}
47
48namespace
49{
50 double EvalExportProgress(Mixer &mixer, double t0, double t1)
51 {
52 const auto duration = t1 - t0;
53 if(duration > 0)
54 return std::clamp(mixer.MixGetCurrentTime() - t0, .0, duration) / duration;
55 return .0;
56 }
57}
58
60{
61 delegate.OnProgress(EvalExportProgress(mixer, t0, t1));
62 if(delegate.IsStopped())
64 if(delegate.IsCancelled())
67}
68
ExportResult
Definition: ExportTypes.h:24
std::vector< MixerOptions::StageSpecification > GetMasterEffectStages(const AudacityProject &project)
std::vector< MixerOptions::StageSpecification > GetEffectStages(const WaveTrack &track)
sampleFormat
The ordering of these values with operator < agrees with the order of increasing bit width.
Definition: SampleFormat.h:30
const auto tracks
const auto project
declares abstract base class Track, TrackList, and iterators over TrackList
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
static ExportResult UpdateProgress(ExportProcessorDelegate &delegate, Mixer &mixer, double t0, double t1)
Sends progress update to delegate and retrieves state update from it. Typically used inside each expo...
static std::unique_ptr< Mixer > CreateMixer(const AudacityProject &project, bool selectionOnly, double startTime, double stopTime, unsigned numOutChannels, size_t outBufferSize, bool outInterleaved, double outRate, sampleFormat outFormat, MixerOptions::Downmix *mixerSpec)
virtual bool IsCancelled() const =0
virtual void OnProgress(double progress)=0
virtual bool IsStopped() const =0
static TrackIterRange< const WaveTrack > FindExportWaveTracks(const TrackList &tracks, bool selectedOnly)
Definition: ExportUtils.cpp:23
Functions for doing the mixdown of the tracks.
Definition: Mix.h:31
std::vector< Input > Inputs
Definition: Mix.h:49
double MixGetCurrentTime()
Current time in seconds (unwarped, i.e. always between startTime and stopTime)
Definition: Mix.cpp:359
A matrix of booleans, one row per input channel, column per output.
Definition: MixerOptions.h:32
static std::shared_ptr< StretchingSequence > Create(const PlayableSequence &, const ClipConstHolders &clips)
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
double EvalExportProgress(Mixer &mixer, double t0, double t1)
Immutable structure is an argument to Mixer's constructor.
Definition: MixerOptions.h:56