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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_CompManager.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 engine
12{
13
14//==============================================================================
19{
20public:
23
25 ~CompManager() override;
26
28
29 virtual void initialise();
30
31 //==============================================================================
32 virtual HashCode getBaseTakeHash (int takeIndex) const = 0;
33 virtual double getTakeLength (int takeIndex) const = 0;
34 virtual double getOffset() const = 0;
35 virtual double getLoopLength() const = 0;
36 virtual bool getAutoTempo() = 0;
37 virtual double getSourceTempo() = 0;
38 virtual juce::String getWarning() { return {}; }
39 virtual float getRenderProgress() const { return 1.0f; }
40 virtual void discardCachedData() {}
41
43 virtual void triggerCompRender() = 0;
44
46 virtual void flattenTake (int takeIndex, bool deleteSourceFiles) = 0;
47
49 virtual juce::ValueTree pasteComp (const juce::ValueTree& /*compTree*/) { return {}; }
50
51 //==============================================================================
52 Clip& getClip() const noexcept { return clip; }
53
56
58 bool shouldDisplayWarning() const noexcept { return displayWarning; }
59
60 //==============================================================================
62 juce::ValueTree getSection (int takeIndex, int sectionIndex) const;
63
68
73 int findSectionWithEndTime (juce::Range<double> range, int takeIndex, bool& timeFoundAtStartOfSection) const;
74
79
80 //==============================================================================
81 juce::ValueTree getTakesTree() { return takesTree; }
82
84 void setActiveTakeIndex (int index);
85
87 int getActiveTakeIndex() const { return clip.getCurrentTake(); }
88
91
93 int getNumTakes() const;
94
96 int getNumComps() const { return takesTree.getNumChildren() - getNumTakes(); }
97
99 int getTotalNumTakes() const { return takesTree.getNumChildren(); }
100
102 bool isTakeComp (int takeIndex) const { return isTakeComp (takesTree.getChild (takeIndex)); }
103
105 bool isTakeComp (const juce::ValueTree& takeTree) const { return bool (takeTree.getProperty (IDs::isComp, false)); }
106
109
111 juce::String getTakeName (int index) const;
112
113 //==============================================================================
118
120 double getMaxCompLength() const { return maxCompLength; }
121
124
128 double getSpeedRatio() const;
129
131 double getSourceTimeMultiplier() const { return effectiveTimeMultiplier; }
132
136 HashCode getTakeHash (int takeIndex) const;
137
138 //==============================================================================
142 void changeSectionIndexAtTime (double time, int takeIndex);
143
145 void removeSectionIndexAtTime (double time, int takeIndex);
146
151 void moveSectionEndTime (juce::ValueTree& section, double newTime);
152
159 void moveSection (juce::ValueTree& section, double timeDelta);
160
167 void moveSectionToEndAt (juce::ValueTree& section, double newEndTime);
168
170 juce::ValueTree addSection (int takeIndex, double endTime);
171
173 void removeSection (const juce::ValueTree& sectionToRemove);
174
177
181 void removeSectionsWithinRange (juce::Range<double> timeRange, const juce::ValueTree& sectionToKeep);
182
183protected:
184 juce::ValueTree takesTree;
185 int lastRenderedTake = -1;
186 HashCode lastHash = 0;
187 double maxCompLength, effectiveTimeMultiplier;
188 double lastOffset = 1.0, lastTimeRatio = 1.0;
189
190 juce::UndoManager* getUndoManager() const;
191 void keepSectionsSortedAndInRange();
192 juce::ValueTree getNewCompTree() const;
193
194private:
195 //==============================================================================
196 Clip& clip;
197 bool displayWarning = false;
198
199 //==============================================================================
200 void reCacheInfo();
201 void refreshCachedTakeLengths();
202 void updateOffsetAndRatioFromSource();
203 void addOrRemoveListenerIfNeeded();
204
205 void valueTreePropertyChanged (juce::ValueTree&, const juce::Identifier&) override;
206 void valueTreeChildAdded (juce::ValueTree& p, juce::ValueTree&) override { if (p == takesTree) reCacheInfo(); }
207 void valueTreeChildRemoved (juce::ValueTree& p, juce::ValueTree&, int) override { if (p == takesTree) reCacheInfo(); }
208 void valueTreeChildOrderChanged (juce::ValueTree&, int, int) override {}
209 void valueTreeParentChanged (juce::ValueTree&) override {}
210 void valueTreeRedirected (juce::ValueTree&) override { jassertfalse; }
211
212 //==============================================================================
213 struct RenderTrigger;
214 std::unique_ptr<RenderTrigger> renderTrigger;
215
217};
218
219//==============================================================================
223{
224public:
225 CompFactory() = default;
226 ~CompFactory() { jassert (comps.isEmpty()); }
227
228 CompManager::Ptr getCompManager (Clip&);
229
230private:
231 friend class CompManager;
233 juce::CriticalSection compLock;
234
235 void addComp (CompManager&);
236 void removeComp (CompManager&);
237
239};
240
241//==============================================================================
245 private juce::Timer
246{
247public:
249
251 ~WaveCompManager() override;
252
255
258
259 //==============================================================================
260 HashCode getBaseTakeHash (int takeIndex) const override { return getProjectItemIDForTake (takeIndex).getItemID(); }
261 double getTakeLength (int takeIndex) const override;
262 double getOffset() const override;
263 double getLoopLength() const override;
264 bool getAutoTempo() override;
265 double getSourceTempo() override;
266 juce::String getWarning() override;
267 float getRenderProgress() const override;
268
269 void triggerCompRender() override;
270 void flattenTake (int takeIndex, bool deleteSourceFiles) override;
271 juce::ValueTree pasteComp (const juce::ValueTree& compTree) override;
272 void setStripToUpdate (juce::Component* strip) override;
273
274 juce::ValueTree addNewComp() override;
275
276 //==============================================================================
277 struct CompRenderContext;
278
281
288
289private:
290 enum { compGeneratorDelay = 500 };
291
292 WaveAudioClip& clip;
293 AudioFile lastCompFile;
294 juce::String warning;
295
296 //==============================================================================
297 struct FlattenRetrier;
298 std::unique_ptr<FlattenRetrier> flattenRetrier;
299
300 struct CompUpdater;
302
303 void setProjectItemIDForTake (int takeIndex, ProjectItemID) const;
304 ProjectItemID getProjectItemIDForTake (int takeIndex) const;
305 AudioFile getSourceFileForTake (int takeIndex) const;
306 juce::File getDefaultTakeFile (int index) const;
307 ProjectItem::Ptr getOrCreateProjectItemForTake (juce::ValueTree& takeTree);
308
309 void timerCallback() override;
310
312};
313
314//==============================================================================
317{
318public:
320
322 ~MidiCompManager() override;
323
324 void initialise() override;
325 MidiList* getSequenceLooped (int index);
326
327 //==============================================================================
328 HashCode getBaseTakeHash (int takeIndex) const override;
329 double getTakeLength (int takeIndex) const override;
330 double getOffset() const override { return 0.0; }
331 double getLoopLength() const override { return getTakeLength (0); }
332 bool getAutoTempo() override { return false; }
333 double getSourceTempo() override { return 1.0; }
334 juce::String getWarning() override { return {}; }
335 float getRenderProgress() const override { return 1.0f; }
336 void discardCachedData() override;
337
338 void triggerCompRender() override;
339 void flattenTake (int takeIndex, bool deleteSourceFiles) override;
340 juce::ValueTree addNewComp() override;
341
342private:
343 MidiClip& clip;
344 juce::ValueTree midiTakes;
345 juce::OwnedArray<MidiList> cachedLoopSequences;
346
347 void createComp (const juce::ValueTree& takeTree);
348
350};
351
352}} // namespace tracktion { inline namespace engine
ValueTree getChild(int index) const
int getNumChildren() const noexcept
const var & getProperty(const Identifier &name) const noexcept
Smart wrapper for writing to an audio file.
A clip in an edit.
virtual int getCurrentTake() const
Returns the current take index.
int getTotalNumTakes() const
Returns the total number of takes including comp takes.
int findSectionWithEndTime(juce::Range< double > range, int takeIndex, bool &timeFoundAtStartOfSection) const
Returns the index of the section whose end lies within the given time range.
void moveSectionToEndAt(juce::ValueTree &section, double newEndTime)
Moves a section to an absolute end time also moving the previous section's end time by the same ammou...
virtual void triggerCompRender()=0
Triggers the render of the comp.
bool shouldDisplayWarning() const noexcept
Returns true if the source should display a warning about using multi-tempo changes.
juce::ValueTree getActiveTakeTree() const
Returns the active take tree.
void setActiveTakeIndex(int index)
Sets the active take index.
juce::String getTakeName(int index) const
Returns the name of a take.
double getSpeedRatio() const
Returns the effective speed ratio used for displaying waveforms.
HashCode getTakeHash(int takeIndex) const
Returns a hash code representing a take.
int getActiveTakeIndex() const
Returns the active take index.
juce::ValueTree splitSectionAtTime(double time)
Find the current section at the given time and splits it in two ready for a new comp section.
void changeSectionIndexAtTime(double time, int takeIndex)
Changes the index of the active comp's section at a given time.
void removeSectionsWithinRange(juce::Range< double > timeRange, const juce::ValueTree &sectionToKeep)
Removes all sections which lie within the given time range.
virtual juce::ValueTree addNewComp()=0
Adds a new comp to the end of the takes list optionally making it active.
virtual void setStripToUpdate(juce::Component *)
Sets a component to be updated during render processes.
double getSourceTimeMultiplier() const
Returns the current time multiplier in use by the source, either the speed ratio or auto tempo ratio.
virtual juce::ValueTree pasteComp(const juce::ValueTree &)
Pastes an existing comp to this manager and returns the newly added tree.
juce::Range< double > getCompRange() const
Returns the time range available for comping i.e.
double getMaxCompLength() const
Returns the maximum length that a comp can be.
int getNumComps() const
Returns the number of comps that are comps.
virtual void flattenTake(int takeIndex, bool deleteSourceFiles)=0
Should flatten the comp and remove all other takes.
void removeSectionIndexAtTime(double time, int takeIndex)
Removes a section from the comp at the given time if the section is at the given take index.
bool isCurrentTakeComp() const
Returns true if the current take is a comp.
bool isTakeComp(const juce::ValueTree &takeTree) const
Returns true if the given take is a comp.
juce::ValueTree addSection(int takeIndex, double endTime)
Adds a new section at a given time and returns the index of it.
void moveSection(juce::ValueTree &section, double timeDelta)
Moves a section by the specified time delta also moving the previous section's end time by the same a...
juce::Range< double > getSectionTimes(const juce::ValueTree &) const
Returns the time range a given section occupies for a given take.
juce::ValueTree getSection(int takeIndex, int sectionIndex) const
Returns the section at the given index of a given take.
void moveSectionEndTime(juce::ValueTree &section, double newTime)
Moves a section's end time to the new time specified.
int getNumTakes() const
Returns the number of takes that are not comps.
juce::ValueTree findSectionAtTime(double time)
Returns either the section for the current comp at a given time or if a whole take is being used the ...
void removeSection(const juce::ValueTree &sectionToRemove)
Removes a section from the active comp if it is within range.
bool isTakeComp(int takeIndex) const
Returns true if the given take at an index is a comp.
juce::ValueTree addNewComp() override
Adds a new comp to the end of the takes list optionally making it active.
void flattenTake(int takeIndex, bool deleteSourceFiles) override
Should flatten the comp and remove all other takes.
void triggerCompRender() override
Triggers the render of the comp.
An ID representing one of the items in a Project.
int getItemID() const
Returns the ID of the item within the project.
An audio clip that uses an audio file as its source.
juce::ValueTree pasteComp(const juce::ValueTree &compTree) override
Pastes an existing comp to this manager and returns the newly added tree.
CompRenderContext * createRenderContext() const
Returns a context to render the current taste of this comp.
void flattenTake(int takeIndex, bool deleteSourceFiles) override
Should flatten the comp and remove all other takes.
void triggerCompRender() override
Triggers the render of the comp.
void setStripToUpdate(juce::Component *strip) override
Sets a component to be updated during render processes.
juce::ValueTree addNewComp() override
Adds a new comp to the end of the takes list optionally making it active.
static bool renderTake(CompRenderContext &, AudioFileWriter &, juce::ThreadPoolJob &, std::atomic< float > &progress)
Renders the comp using the given writer and ThreadPoolJob.
void updateThumbnails(juce::Component &, juce::OwnedArray< SmartThumbnail > &thumbnails) const
Updates an array of thumbnails so they represent the takes and are in the correct order etc.
juce::File getCurrentCompFile() const
Returns the current comp file.
#define jassert(expression)
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
#define jassertfalse
Updates a strip during a comp render and notifies the Clip when it finishes.
Re-calls flatten take to allow the comp time to finish rendering if needed.