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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_EditUtilities.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//==============================================================================
15// Projects and Files
16//==============================================================================
17
19Project::Ptr getProjectForEdit (const Edit&);
20
22ProjectItem::Ptr getProjectItemForEdit (const Edit&);
23
26
28bool referencesProjectItem (Edit&, ProjectItemID);
29
30
31//==============================================================================
32// Edit
33//==============================================================================
34
36void insertSpaceIntoEdit (Edit&, TimeRange timeRangeToInsert);
37
39void insertSpaceIntoEditFromBeatRange (Edit&, BeatRange);
40
41//==============================================================================
42// Tracks
43//==============================================================================
44
47
50
52template<typename TrackType>
53juce::Array<TrackType*> getTracksOfType (const Edit&, bool recursive);
54
57
60
62int getTotalNumTracks (const Edit&);
63
65Track* findTrackForID (const Edit&, EditItemID);
66
68AudioTrack* findAudioTrackForID (const Edit&, EditItemID);
69
72
74Track* findTrackForState (const Edit&, const juce::ValueTree&);
75
77AudioTrack* getFirstAudioTrack (const Edit&);
78
81
83ClipTrack* findFirstClipTrackFromSelection (const SelectableList&);
84
86bool containsTrack (const Edit&, const Track&);
87
89TrackOutput* getTrackOutput (Track&);
90
95
100
101template<typename TrackItemType>
102[[ nodiscard ]] juce::Array<TrackItemType*> getTrackItemsOfType (const Track&);
103
105ClipOwner* findClipOwnerForID (const Edit&, EditItemID);
106
107
108//==============================================================================
109// ClipSlots
110//==============================================================================
112ClipSlot* findClipSlotForID (const Edit&, EditItemID);
113
115int findClipSlotIndex (ClipSlot&);
116
117
118//==============================================================================
119// Clips
120//==============================================================================
121
123Clip* findClipForID (const Edit&, EditItemID);
124
126Clip* findClipForState (const Edit&, const juce::ValueTree&);
127
129bool containsClip (const Edit&, Clip*);
130
132Clip::Ptr duplicateClip (const Clip&);
133
135void visitAllTrackItems (const Edit&, std::function<bool (TrackItem&)>);
136
138TimeRange getTimeRangeForSelectedItems (const SelectableList&);
139
141enum class CloseGap
142{
143 no,
144 yes
145};
146
148void deleteRegionOfTracks (Edit&, TimeRange rangeToDelete, bool onlySelectedTracks, CloseGap, SelectionManager*);
149
151void deleteRegionOfClip (Clip&, TimeRange rangeToDelete);
152
154void deleteRegionOfSelectedClips (SelectionManager&, TimeRange rangeToDelete,
155 CloseGap, bool moveAllSubsequentClipsOnTrack);
156
158SelectableList splitClips (const SelectableList& clips, TimePosition time);
159
162{
163 moveToEndOfLast,
164 moveToStartOfNext,
165 moveStartToCursor,
166 moveEndToCursor
167};
168
170void moveSelectedClips (const SelectableList&, Edit&, MoveClipAction mode, bool alsoMoveAutomation);
171
173SelectableList getClipSelectionWithCollectionClipContents (const SelectableList&);
174
177
178//==============================================================================
179// MIDI
180//==============================================================================
181
183MidiNote* findNoteForState (const Edit&, const juce::ValueTree&);
184
186juce::Result mergeMidiClips (juce::Array<MidiClip*>, SelectionManager* sm = nullptr);
187
189juce::OwnedArray<MidiList> readFileToMidiList (juce::File midiFile, bool importAsNoteExpression);
190
195MidiClip::Ptr createClipFromFile (juce::File midiFile, ClipOwner&, bool importAsNoteExpression);
196
197
198//==============================================================================
199// Plugins
200//==============================================================================
201
203Plugin::Array getAllPlugins (const Edit&, bool includeMasterVolume);
204
206Plugin::Ptr findPluginForState (const Edit&, const juce::ValueTree&);
207
209Plugin::Ptr findPluginForID (const Edit&, EditItemID);
210
212Track* getTrackContainingPlugin (const Edit&, const Plugin*);
213
215bool areAnyPluginsMissing (const Edit&);
216
219
221void muteOrUnmuteAllPlugins (const Edit&);
222
224void injectMIDIToAllPlugins (const Edit&, const std::span<juce::MidiMessage>& messagesToSend);
225
229void midiPanic (Edit&, bool resetPlugins);
230
231
233template<typename PluginType>
235
236//==============================================================================
237// Automation and parameters
238//==============================================================================
239
242
244void deleteAutomation (const SelectableList& selectedClips);
245
246//==============================================================================
247// Modifiers
248//==============================================================================
249
252
255
257template<typename ModifierType>
258typename ModifierType::Ptr findModifierTypeForID (const Edit&, EditItemID);
259
261Modifier::Ptr findModifierForID (const Edit&, EditItemID);
262
264Modifier::Ptr findModifierForID (const RackType&, EditItemID);
265
267Track* getTrackContainingModifier (const Edit&, const Modifier::Ptr&);
268
269
270//==============================================================================
271// Macros
272//==============================================================================
273
276
279
280
281//==============================================================================
282// Inputs/recording
283//==============================================================================
289InputDeviceInstance::RecordingParameters getDefaultRecordingParameters (const EditPlaybackContext&,
290 TimePosition playStart,
291 TimePosition punchIn);
292
296juce::Result prepareAndPunchRecord (InputDeviceInstance&, EditItemID);
297
301tl::expected<Clip::Array, juce::String> punchOutRecording (InputDeviceInstance&);
302
304bool isRecording (EditPlaybackContext&);
305
306
307//==============================================================================
309template<typename PluginType>
311{
312 if (auto p = track.edit.getPluginCache().createNewPlugin (PluginType::create()))
313 {
314 if (auto pluginAsType = dynamic_cast<PluginType*> (p.get()))
315 {
316 track.pluginList.insertPlugin (*p, index, {});
317 return pluginAsType;
318 }
319 }
320
321 return {};
322}
323
325template<typename TrackType>
326inline juce::Array<TrackType*> getTracksOfType (const Edit& edit, bool recursive)
327{
329 result.ensureStorageAllocated (32);
330
331 edit.visitAllTracks ([&] (Track& t)
332 {
333 if (auto type = dynamic_cast<TrackType*> (&t))
334 result.add (type);
335
336 return true;
337 }, recursive);
338
339 return result;
340}
341
343template<typename TrackItemType>
344inline juce::Array<TrackItemType*> getTrackItemsOfType (const Track& track)
345{
347 const int numItems = track.getNumTrackItems();
348
349 for (int i = 0; i < numItems; ++i)
350 if (auto ti = dynamic_cast<TrackItemType*> (track.getTrackItem (i)))
351 items.add (ti);
352
353 return items;
354}
355
357template<typename ModifierType>
358inline typename ModifierType::Ptr findModifierTypeForID (const Edit& edit, EditItemID id)
359{
360 for (auto modifier : getAllModifiers (edit))
361 if (modifier->itemID == id)
362 if (auto asType = dynamic_cast<ModifierType*> (modifier))
363 return typename ModifierType::Ptr (asType);
364
365 return {};
366}
367
368}} // namespace tracktion { inline namespace engine
void ensureStorageAllocated(int minNumElements)
void add(const ElementType &newElement)
The Tracktion Edit class!
void visitAllTracks(std::function< bool(Track &)>, bool recursive) const
Visits all tracks in the Edit with the given function.
Base class for tracks which contain clips and plugins and can be added to Edit[s].
juce::File getEditFileFromProjectManager(Edit &edit)
Uses the ProjectManager to look up the file for an Edit.
juce::Array< MacroParameterElement * > getAllMacroParameterElements(const Edit &edit)
Returns all the MacroParameterElement in an Edit.
bool referencesProjectItem(Edit &edit, ProjectItemID itemID)
Returns true if the ProjectItemID is being used for any of the Edit's elements.
AudioTrack * getFirstAudioTrack(const Edit &edit)
Returns the first audio track in an Edit.
void insertSpaceIntoEdit(Edit &edit, TimeRange timeRange)
Inserts blank space in to an Edit, splitting clips if necessary.
TrackOutput * getTrackOutput(Track &track)
Returns the TrackOutput if the given track has one.
SelectableList splitClips(const SelectableList &clips, TimePosition time)
Splits the clips at a given time.
juce::Array< TrackType * > getTracksOfType(const Edit &, bool recursive)
Returns the tracks of a given type in an Edit.
SelectableList getClipSelectionWithCollectionClipContents(const SelectableList &in)
Returns a list of clips.
Track * findTrackForState(const Edit &edit, const juce::ValueTree &v)
Returns the Track with a given state if contained in the Edit.
void deleteAutomation(const SelectableList &selectedClips)
Deletes the automation covered by the selected clips.
Clip * findClipForState(ClipOwner &co, const juce::ValueTree &v)
Returns a clip with the given state if the ClipOwner contains it.
juce::Array< Track * > toTrackArray(Edit &edit, const juce::BigInteger &tracksToAdd)
Returns an Array of Track[s] corresponding to the set bits of all tracks in an Edit.
juce::Array< Track * > getTopLevelTracks(const Edit &edit)
Returns all of the non-foldered tracks in an Edit.
void insertSpaceIntoEditFromBeatRange(Edit &edit, BeatRange beatRange)
Inserts a number of blank beats in to the Edit.
juce::Result mergeMidiClips(juce::Array< MidiClip * > clips, SelectionManager *sm)
Merges a set of MIDI clips in to one new one.
TimeRange getTimeRangeForSelectedItems(const SelectableList &selected)
Returns the time range covered by the given items.
Clip::Ptr duplicateClip(const Clip &c)
Creates a unique copy of this clip with a new EditItemID.
Clip * findClipForID(ClipOwner &co, EditItemID id)
Returns a clip with the given ID if the ClipOwner contains it.
CloseGap
An enum to specify if gaps deleted should be closed or not.
ClipTrack * findFirstClipTrackFromSelection(const SelectableList &items)
Returns the first ClipTrack from the selected tracks or clips.
bool areAnyPluginsMissing(const Edit &edit)
Returns true if any plugins couldn't be loaded beacuse their files are missing.
juce::Array< MacroParameterList * > getAllMacroParameterLists(const Edit &edit)
Returns all the MacroParameterLists in an Edit.
juce::Array< Track * > getAllTracks(const Edit &edit)
Returns all the tracks in an Edit.
int findClipSlotIndex(ClipSlot &slot)
Returns the index of the ClipSlot in the list it is owned by.
ClipOwner * findClipOwnerForID(const Edit &edit, EditItemID id)
Returns the ClipOwner with a given ID if it can be found in the Edit.
bool containsTrack(const Edit &edit, const Track &track)
Returns true if the Edit contains this Track.
juce::Array< Track * > findTracksForIDs(const Edit &edit, const juce::Array< EditItemID > &ids)
Returns the Tracks for the given IDs in the Edit.
tl::expected< Clip::Array, juce::String > punchOutRecording(InputDeviceInstance &instance)
If the instance is currently recording, this will stop it and return any created clips or an error me...
juce::Array< AudioTrack * > getAudioTracks(const Edit &edit)
Returns all the AudioTracks in an Edit.
ModifierType::Ptr findModifierTypeForID(const Edit &, EditItemID)
Returns the Modifier with a given type and ID.
void visitAllTrackItems(const Edit &edit, std::function< bool(TrackItem &)> f)
Calls a function for all TrackItems in an Edit.
Track * getTrackContainingPlugin(const Edit &edit, const Plugin *p)
Returns the track for the track which the plugin is located on.
juce::BigInteger toBitSet(const juce::Array< Track * > &tracks)
Returns the set of tracks as a BigInteger with each bit corresponding to the array of all tracks in a...
juce::Array< AutomatableParameter::ModifierSource * > getAllModifierSources(const Edit &edit)
Returns all the ModifierSources in an Edit.
MidiNote * findNoteForState(const Edit &edit, const juce::ValueTree &v)
Returns the MidiNote with a given state.
Plugin::Ptr findPluginForState(const Edit &edit, const juce::ValueTree &v)
Returns the plugin with given state.
ClipSlot * findClipSlotForID(const Edit &edit, EditItemID id)
Returns the ClipSlot for the given ID.
void deleteRegionOfClip(Clip &c, TimeRange timeRangeToDelete)
Deletes a time range of a Clip.
ProjectItem::Ptr getProjectItemForEdit(const Edit &e)
Tries to find the project item that refers to this edit (but may return nullptr!)
juce::Array< ClipTrack * > getClipTracks(const Edit &edit)
Returns all the ClipTracks in an Edit.
juce::ReferenceCountedArray< Modifier > getAllModifiers(const Edit &edit)
Returns all the Modifiers in an Edit.
Plugin::Ptr findPluginForID(const Edit &edit, EditItemID id)
Returns the plugin with given EditItemID.
void deleteRegionOfTracks(Edit &edit, TimeRange rangeToDelete, bool onlySelected, CloseGap closeGap, SelectionManager *selectionManager)
Deletes a time range of an Edit, optionally closing the gap.
juce::Array< RackInstance * > getRackInstancesInEditForType(const RackType &rt)
Returns all of the instances of a specific RackType in an Edit.
Modifier::Ptr findModifierForID(ModifierList &ml, EditItemID modifierID)
Returns a Modifier if it can be found in the list.
int getTotalNumTracks(const Edit &edit)
Returns the total number of Tracks in an Edit.
juce::Array< AutomatableEditItem * > getAllAutomatableEditItems(const Edit &edit)
Returns all AutomatableEditItems in an Edit.
void deleteRegionOfSelectedClips(SelectionManager &selectionManager, TimeRange rangeToDelete, CloseGap closeGap, bool moveAllSubsequentClipsOnTrack)
Deletes a time range of a Clip selection, optionally closing the gap.
juce::Result prepareAndPunchRecord(InputDeviceInstance &instance, EditItemID targetID)
Starts an InputDeviceInstance recording to the given target without any count-in etc.
Track * getTrackContainingModifier(const Edit &edit, const Modifier::Ptr &m)
Returns the Track containing a Modifier.
juce::OwnedArray< MidiList > readFileToMidiList(juce::File midiFile, bool importAsNoteExpression)
Helper function to read a file to a number of MidiLists.
void injectMIDIToAllPlugins(const Edit &edit, const std::span< juce::MidiMessage > &messages)
Sends a list of MIDI messages to all the plugins in this edit.
Track * findTrackForID(const Edit &edit, EditItemID id)
Returns the Track with a given ID if contained in the Edit.
void muteOrUnmuteAllPlugins(const Edit &edit)
Toggles the enabled state of all plugins in an Edit.
Project::Ptr getProjectForEdit(const Edit &e)
Tries to find the project that contains this edit (but may return nullptr!)
juce::ReferenceCountedObjectPtr< PluginType > insertNewPlugin(Track &, int index=0)
Adds a new instance of the given plugin to the track's plugin list at the specified index.
void moveSelectedClips(const SelectableList &selectedObjectsIn, Edit &edit, MoveClipAction mode, bool automationLocked)
Moves the selected clips within their track.
juce::Array< Track * > findAllTracksContainingSelectedItems(const SelectableList &items)
Returns all the tracks containing the selected tracks or TrackItems.
bool isRecording(EditPlaybackContext &epc)
Returns true if any inputs are currently recording.
void midiPanic(Edit &edit, bool resetPlugins)
Performs a "MIDI panic" on the edit, by resetting playback, and sending some all-note-off messages to...
InputDeviceInstance::RecordingParameters getDefaultRecordingParameters(const EditPlaybackContext &context, TimePosition playStart, TimePosition punchIn)
Returns the default set of recording parameters.
AudioTrack * findAudioTrackForID(const Edit &edit, EditItemID id)
Returns the AudioTrack with a given ID if contained in the Edit.
MoveClipAction
Enum to dictate move clip behaviour.
MidiClip::Ptr createClipFromFile(juce::File midiFile, ClipOwner &owner, bool importAsNoteExpression)
Helper function to read a MIDI file and create a MidiClip from it.
bool containsClip(const Edit &edit, Clip *clip)
Returns true if an Edit contains a given clip.
Plugin::Array getAllPlugins(const Edit &edit, bool includeMasterVolume)
Returns all the plugins in a given Edit.
juce::Array< ClipEffect * > getAllClipEffects(Edit &edit)
Returns all clip effects.
RangeType< TimePosition > TimeRange
A RangeType based on real time (i.e.
ID for objects of type EditElement - e.g.