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 // MB: the stop time should not be warped, this was a bug.
36 return std::make_unique<Mixer>(
37 move(inputs), GetMasterEffectStages(project),
38 // Throw, to stop exporting, if read fails:
39 true, Mixer::WarpOptions { tracks.GetOwner() }, startTime, stopTime,
40 numOutChannels, outBufferSize, outInterleaved, outRate, outFormat, true,
41 mixerSpec,
43}
44
45namespace
46{
47 double EvalExportProgress(Mixer &mixer, double t0, double t1)
48 {
49 const auto duration = t1 - t0;
50 if(duration > 0)
51 return std::clamp(mixer.MixGetCurrentTime() - t0, .0, duration) / duration;
52 return .0;
53 }
54}
55
57{
58 delegate.OnProgress(EvalExportProgress(mixer, t0, t1));
59 if(delegate.IsStopped())
61 if(delegate.IsCancelled())
64}
65
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:29
std::vector< Input > Inputs
Definition: Mix.h:47
double MixGetCurrentTime()
Current time in seconds (unwarped, i.e. always between startTime and stopTime)
Definition: Mix.cpp:352
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