tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_Renderer.h
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7
8 Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9*/
10
11namespace tracktion { inline namespace graph
12{
13 class Node;
14 class PlayHead;
15 class PlayHeadState;
16}}
17
18namespace tracktion { inline namespace engine
19{
20
21class NodeRenderContext;
22struct ProcessState;
23
24//==============================================================================
28{
29public:
31 {
32 Parameters() = delete;
33 Parameters (Engine& e) : engine (&e) {}
34 Parameters (Edit& ed) : engine (&ed.engine), edit (&ed) {}
35
36 Parameters (const Parameters&) = default;
37 Parameters (Parameters&&) = default;
38 Parameters& operator= (const Parameters&) = default;
39 Parameters& operator= (Parameters&&) = default;
40
41 Engine* engine = nullptr;
42 Edit* edit = nullptr;
43 juce::BigInteger tracksToDo;
44 juce::Array<Clip*> allowedClips;
45
46 juce::File destFile;
47 juce::AudioFormat* audioFormat = nullptr;
48
49 int bitDepth = 16;
50 int blockSizeForAudio = 44100;
51 double sampleRateForAudio = 44100.0;
52
53 TimeRange time;
54 TimeDuration endAllowance;
55
56 bool createMidiFile = false;
57 bool trimSilenceAtEnds = false;
58
59 bool shouldNormalise = false;
60 bool shouldNormaliseByRMS = false;
61 float normaliseToLevelDb = 0;
62 bool canRenderInMono = true;
63 bool mustRenderInMono = false;
64 bool usePlugins = true;
65 bool useMasterPlugins = false;
66 bool realTimeRender = false;
67 bool ditheringEnabled = false;
68 bool separateTracks = false;
69 bool addAntiDenormalisationNoise = false;
70 bool checkNodesForAudio = true;
71 bool addAcidMetadata = false;
72
73 int quality = 0;
74 juce::StringPairArray metadata;
75 ProjectItem::Category category = ProjectItem::Category::none;
76
77 float resultMagnitude = 0;
78 float resultRMS = 0;
79 float resultAudioDuration = 0;
80 };
81
82 //==============================================================================
87 {
88 public:
89 RenderTask (const juce::String& taskDescription,
91 std::atomic<float>* progressToUpdate,
93
94 RenderTask (const juce::String& taskDescription,
100 std::atomic<float>* progressToUpdate,
102
103 ~RenderTask() override;
104
105 JobStatus runJob() override;
106 float getCurrentTaskProgress() override { return progress; }
107
109 juce::String errorMessage;
110
111 //==============================================================================
112 static void flushAllPlugins (const Plugin::Array&, double sampleRate, int samplesPerBlock);
113 static void setAllPluginsRealtime (const Plugin::Array&, bool realtime);
114 static bool addMidiMetaDataAndWriteToFile (juce::File, juce::MidiMessageSequence, const TempoSequence&);
115 bool performNormalisingAndTrimming (const Renderer::Parameters& target,
116 const Renderer::Parameters& intermediate);
117
118 private:
119 //==============================================================================
124 std::unique_ptr<NodeRenderContext> nodeRenderContext;
125
126 std::atomic<float> progressInternal { 0.0f };
127 std::atomic<float>& progress;
129
130 //==============================================================================
131 bool renderAudio (Renderer::Parameters&);
132 bool renderMidi (Renderer::Parameters&);
133
135 };
136
137 //==============================================================================
141 static bool checkTargetFile (Engine&, const juce::File&);
142
144 static void turnOffAllPlugins (Edit&);
145
146 //==============================================================================
148 static ProjectItem::Ptr renderToProjectItem (const juce::String& taskDescription, const Parameters& params);
149
151 static juce::File renderToFile (const juce::String& taskDescription, const Parameters& params);
152
154 static bool renderToFile (const juce::String& taskDescription,
155 const juce::File& outputFile,
156 Edit& edit,
157 TimeRange range,
158 const juce::BigInteger& tracksToDo,
159 bool usePlugins = true,
160 bool useACID = true,
161 juce::Array<Clip*> clips = {},
162 bool useThread = true);
163
165 static bool renderToFile (Edit&, const juce::File&, bool useThread = true);
166
167 //==============================================================================
171 {
172 float peak = 0;
173 float average = 0;
174 float audioDuration = 0;
175 };
176
178 static Statistics measureStatistics (const juce::String& taskDescription,
179 Edit& edit, TimeRange range,
180 const juce::BigInteger& tracksToDo,
181 int blockSizeForAudio, double sampleRateForAudio = 44100.0);
182
183 //==============================================================================
185 {
186 RenderResult() : result (juce::Result::fail ({})) {}
187
188 RenderResult (const juce::Result& r, ProjectItem::Ptr mo) : result (r)
189 {
190 if (mo != nullptr)
191 items.add (mo);
192 }
193
194 RenderResult (const RenderResult& other)
195 : result (other.result), items (other.items) {}
196
197 RenderResult& operator= (const RenderResult& other)
198 {
199 result = other.result;
200 items = other.items;
201 return *this;
202 }
203
204 juce::Result result;
206 };
207
208 //==============================================================================
211 {
213 : edit (e), tracks (ta)
214 {
215 for (auto t : tracks)
216 {
217 if (auto at = dynamic_cast<AudioTrack*> (t))
218 {
219 playSlotClips.push_back (at->playSlotClips.get());
220 at->playSlotClips = false;
221 }
222 }
223 }
224
226 {
227 for (size_t i = 0; auto t : tracks)
228 if (auto at = dynamic_cast<AudioTrack*> (t))
229 at->playSlotClips = playSlotClips[i++];
230 }
231
232 Edit& edit;
233 Track::Array tracks;
234 std::vector<bool> playSlotClips;
236 };
237};
238
239namespace render_utils
240{
242 std::atomic<float>* progressToUpdate,
244}
245
246}} // namespace tracktion { inline namespace engine
static Result fail(const String &errorMessage) noexcept
The Tracktion Edit class!
Engine & engine
A reference to the Engine.
The Engine is the central class for all tracktion sessions.
Task that actually performs the render operation in blocks.
static void turnOffAllPlugins(Edit &)
Deinitialises all the plugins for the Edit.
static ProjectItem::Ptr renderToProjectItem(const juce::String &taskDescription, const Parameters &params)
Renders an Edit to a file and creates a new ProjectItem for it.
static Statistics measureStatistics(const juce::String &taskDescription, Edit &edit, TimeRange range, const juce::BigInteger &tracksToDo, int blockSizeForAudio, double sampleRateForAudio=44100.0)
Renders a section of an edit to measure various details about its audio content.
static bool checkTargetFile(Engine &, const juce::File &)
Cheks a file for write access etc.
static juce::File renderToFile(const juce::String &taskDescription, const Parameters &params)
Renders an Edit to a file given by the Parameters.
Holds a list of TempoSetting objects, to form a sequence of tempo changes.
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
T push_back(T... args)
Represents a duration in real-life time.
bool checkNodesForAudio
If true, attempting to render an Edit that doesn't produce audio will fail.