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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_Clip.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//==============================================================================
22
23//==============================================================================
28{
30 LiveClipLevel() noexcept = default;
31
33 LiveClipLevel (std::shared_ptr<ClipLevel> l) noexcept
34 : levels (std::move (l)) {}
35
37 float getGain() const noexcept { return levels ? dbToGain (levels->dbGain.get()) : 1.0f; }
38
40 float getPan() const noexcept { return levels ? static_cast<float> (levels->pan.get()) : 0.0f; }
41
43 bool isMute() const noexcept { return levels && levels->mute.get(); }
44
46 float getGainIncludingMute() const noexcept { return isMute() ? 0.0f : getGain(); }
47
49 void getLeftAndRightGains (float& left, float& right) const noexcept
50 {
51 const float g = getGainIncludingMute();
52 const float pv = getPan() * g;
53 left = g - pv;
54 right = g + pv;
55 }
56
57private:
59};
60
61
62//==============================================================================
67class Clip : public TrackItem,
68 public Exportable,
70{
71public:
72 //==============================================================================
78
80 ~Clip() override;
81
83 virtual void initialise();
84
87
88 //==============================================================================
90 static bool isClipState (const juce::ValueTree&);
92 static bool isClipState (const juce::Identifier&);
93
97 static Ptr createClipForState (const juce::ValueTree&, ClipOwner& targetParent);
98
100 virtual void flushStateToValueTree();
101
106 virtual void sourceMediaChanged();
107
111 virtual void pitchTempoTrackChanged() {}
112
113 //==============================================================================
115 virtual juce::String getName() const override { return clipName; }
117 void setName (const juce::String& newName);
118
120 [[ nodiscard ]] virtual bool isMidi() const = 0;
121
123 [[ nodiscard ]] virtual bool canBeAddedTo (ClipOwner&) = 0;
124
125 //==============================================================================
127 virtual bool usesSourceFile() const { return false; }
128
130 SourceFileReference& getSourceFileReference() { return sourceFileReference; }
131
135 juce::File getCurrentSourceFile() const { return currentSourceFile; }
136
137 //==============================================================================
140
142 void reassignReferencedItem (const ReferencedItem&, ProjectItemID /*newID*/, double /*newStartTime*/) override;
143
144 //==============================================================================
149
154 virtual void setUsesGlobalLaunchQuatisation (bool) {}
155
160 virtual bool usesGlobalLaunchQuatisation() { return true; }
161
168
172 virtual FollowActions* getFollowActions() { return {}; }
173
176 {
177 beats,
178 loops
179 };
180
183
186
189
190 //==============================================================================
192 ClipPosition getPosition() const override;
193
198
200 virtual TimeDuration getMaximumLength() { return toDuration (Edit::getMaximumEditEnd()); }
201
204
209
210 //==============================================================================
212 virtual bool canLoop() const { return false; }
214 virtual bool isLooping() const { return false; }
216 virtual bool beatBasedLooping() const { return false; }
218 virtual void setNumberOfLoops (int) {}
220 virtual void disableLooping() {}
221
223 virtual BeatPosition getLoopStartBeats() const { return BeatPosition(); }
225 virtual TimePosition getLoopStart() const { return TimePosition(); }
227 virtual BeatDuration getLoopLengthBeats() const { return BeatDuration(); }
229 virtual TimeDuration getLoopLength() const { return TimeDuration(); }
230
232 TimeRange getLoopRange() const { return { getLoopStart(), getLoopLength() }; }
234 BeatRange getLoopRangeBeats() const { return { getLoopStartBeats(), getLoopLengthBeats() }; }
235
237 virtual void setLoopRange (TimeRange) {}
239 virtual void setLoopRangeBeats (BeatRange) {}
240
242 virtual bool isMuted() const = 0;
244 virtual void setMuted (bool) {}
245
252
254 virtual void setSyncType (SyncType sync) { syncType = sync; }
256 SyncType getSyncType() const { return syncType; }
257
258 //==============================================================================
260 void setPosition (ClipPosition newPosition);
261
267 void setStart (TimePosition newStart, bool preserveSync, bool keepLength);
268
273 void setLength (TimeDuration newLength, bool preserveSync);
274
279 void setEnd (TimePosition newEnd, bool preserveSync);
280
284 void setOffset (TimeDuration newOffset);
285
287 void trimAwayOverlap (TimeRange editRangeToTrim);
288
290 void removeFromParent();
291
295 bool moveTo (ClipOwner&);
296
297 //==============================================================================
299 double getSpeedRatio() const noexcept { return speedRatio; }
300
302 virtual void setSpeedRatio (double);
303
308 virtual void rescale (TimePosition pivotTimeInEdit, double factor);
309
310 //==============================================================================
312 bool isGrouped() const override { return groupID.get().isValid(); }
314 TrackItem* getGroupParent() const override;
316 void setGroup (EditItemID newGroupID);
318 EditItemID getGroupID() const noexcept { return groupID; }
321
322 //==============================================================================
324 bool isLinked() const { return linkID.get().isNotEmpty(); }
326 void setLinkGroupID (juce::String newLinkID) { linkID = newLinkID; }
328 juce::String getLinkGroupID() const { return linkID; }
329
330 //==============================================================================
332 ClipOwner* getParent() const;
334 ClipTrack* getClipTrack() const;
336 Track* getTrack() const override;
338 ClipSlot* getClipSlot() const;
339
340 //==============================================================================
342 virtual juce::Colour getColour() const;
344 void setColour (juce::Colour col) { colour = col; }
345
346 //==============================================================================
348 virtual void removePlugin (const Plugin::Ptr&) {}
349
353 virtual bool addClipPlugin (const Plugin::Ptr&, SelectionManager&) { return false; }
354
356 virtual Plugin::Array getAllPlugins() { return {}; }
358 virtual void sendMirrorUpdateToAllPlugins (Plugin&) const {}
359
361 virtual PluginList* getPluginList() { return {}; }
362
363 //==============================================================================
365 virtual juce::Colour getDefaultColour() const = 0;
366
367 //==============================================================================
369 virtual void clearTakes() {}
371 virtual bool hasAnyTakes() const { return false; }
373 virtual juce::StringArray getTakeDescriptions() const { return {}; }
375 virtual void setCurrentTake (int /*takeIndex*/) {}
377 virtual int getCurrentTake() const { return 0; }
381 virtual int getNumTakes (bool /*includeComps*/) { return 0; }
383 virtual bool isCurrentTakeComp() { return false; }
384
386 virtual void setShowingTakes (bool shouldShow) { showingTakes = shouldShow; }
388 virtual bool isShowingTakes() const { return showingTakes; }
389
394 virtual Clip::Array unpackTakes (bool /*toNewTracks*/) { return {}; }
395
396 //==============================================================================
398 virtual void cloneFrom (Clip*);
399
403 void updateLinkedClips();
404
405 //==============================================================================
409 virtual PatternGenerator* getPatternGenerator() { return {}; }
410
411 //==============================================================================
413 struct Listener
414 {
415 /* Destructor */
416 virtual ~Listener() = default;
417
421 virtual void midiMessageGenerated (Clip&, const juce::MidiMessage&) = 0;
422 };
423
425 void addListener (Listener*);
426
428 void removeListener (Listener*);
429
432
433 //==============================================================================
435 void changed() override;
436
439
450 virtual void setParent (ClipOwner*);
451
452protected:
453 friend class Track;
454 friend class ClipTrack;
455 friend class CollectionClip;
456
457 bool isInitialised = false;
458 bool cloneInProgress = false;
460 ClipOwner* parent = nullptr;
462 juce::CachedValue<TimeDuration> length, offset;
463 juce::CachedValue<double> speedRatio;
464 SourceFileReference sourceFileReference;
467 juce::File currentSourceFile;
469 juce::CachedValue<bool> showingTakes;
470 std::unique_ptr<PatternGenerator> patternGenerator;
471 AsyncCaller updateLinkedClipsCaller;
472
474
476 void setCurrentSourceFile (const juce::File&);
477
480
482 void valueTreePropertyChanged (juce::ValueTree&, const juce::Identifier&) override;
484 void valueTreeParentChanged (juce::ValueTree&) override;
485
486private:
487 void updateParent();
488
490};
491
492
493//==============================================================================
495namespace ClipConstants
496{
497 const double speedRatioMin = 0.01;
498 const double speedRatioMax = 20.0;
499}
500
501namespace details
502{
503 Clip::FollowActionDurationType followActionDurationTypeFromString (juce::String);
505}
506
507}} // namespace tracktion { inline namespace engine
508
509namespace juce
510{
511 template<>
512 struct VariantConverter<tracktion::engine::Clip::SyncType>
513 {
514 static tracktion::engine::Clip::SyncType fromVar (const var& v) { return (tracktion::engine::Clip::SyncType) static_cast<int> (v); }
515 static var toVar (tracktion::engine::Clip::SyncType v) { return static_cast<int> (v); }
516 };
517
518 template<>
519 struct VariantConverter<tracktion::engine::Clip::FollowActionDurationType>
520 {
522 {
523 return tracktion::engine::details::followActionDurationTypeFromString (v);
524 }
525
527 {
528 return tracktion::engine::details::toString (v);
529 }
530 };
531}
Type get() const noexcept
Base class for items that can contain clips.
Represents a slot on a track that a Clip can live in to be played as a launched clip.
A clip in an edit.
virtual void disableLooping()
Disables all looping.
virtual juce::Array< TimePosition > getRescaledMarkPoints() const
Returns the mark points relative to the start of the clip, rescaled to the current speed.
virtual TimePosition getLoopStart() const
Returns the start time of the loop start point.
virtual Plugin::Array getAllPlugins()
Returns all the plugins on the clip.
juce::Array< ReferencedItem > getReferencedItems() override
Returns an array of any ReferencedItem[s] e.g.
EditItemID getGroupID() const noexcept
Returns the ID of the group.
virtual bool beatBasedLooping() const
Returns true if this clip's looping is based on beats or false if absolute time.
juce::CachedValue< BeatDuration > followActionBeats
Determines the time for which a launched clip will play before a follow action is taken.
ClipSlot * getClipSlot() const
Returns the parent ClipSlot this clip is on (if any).
virtual void sendMirrorUpdateToAllPlugins(Plugin &) const
Sends an update to all plugins mirroing the one passed in.
static bool isClipState(const juce::ValueTree &)
Checks whether a ValueTree is some kind of clip state.
ClipTrack * getClipTrack() const
Returns the parent ClipTrack this clip is on (if any).
TimePosition getTimeOfContentBeat(BeatPosition) const
Returns time of a beat number.
virtual juce::String getName() const override
Returns the name of the clip.
virtual bool canBeAddedTo(ClipOwner &)=0
Tests whether this clip can go on the given parent.
void changed() override
This should be called to send a change notification to any SelectableListeners that are registered wi...
CollectionClip * getGroupClip() const
Returns this as a CollectionClip if it is one.
void setOffset(TimeDuration newOffset)
Sets the offset of the clip, i.e.
TimePosition getSpottingPoint() const
Returns the first marked time in the source file which can be used for syncronising newly added clips...
virtual bool hasAnyTakes() const
Returns true if this clip has any takes.
virtual void setUsesGlobalLaunchQuatisation(bool)
Some clip types can be launched, if that's possible, this sets whether the clip's quantisation or the...
void trimAwayOverlap(TimeRange editRangeToTrim)
Trims away any part of the clip that overlaps this region.
virtual bool isLooping() const
Returns true if this clip is currently looping.
virtual void pitchTempoTrackChanged()
Called when there are pitch or tempo changes made which might require clips to adjust timing informat...
juce::ValueTree state
The ValueTree of the Clip state.
virtual void flushStateToValueTree()
Can be overridden to ensure any state (e.g.
virtual TimeDuration getMaximumLength()
Returns the maximum length this clip can have.
virtual void removePlugin(const Plugin::Ptr &)
Removes the given plugin from the clip if the clip supports plugins.
virtual void rescale(TimePosition pivotTimeInEdit, double factor)
stretches and scales this clip relative to a fixed point in the edit.
void setStart(TimePosition newStart, bool preserveSync, bool keepLength)
Sets the start time of the clip.
Track * getTrack() const override
Returns the parent Track this clip is on (if any).
juce::String getLinkGroupID() const
Returns the link ID of this clip.
virtual bool isMidi() const =0
Returns true if this is a MidiClip.
void reassignReferencedItem(const ReferencedItem &, ProjectItemID, double) override
Should be implemented to change the underlying source to a new ProjectItemID.
virtual int getNumTakes(bool)
Returns the total number of takes.
virtual void initialise()
Initialises the Clip.
virtual PluginList * getPluginList()
Returns the PluginList for this clip if it has one.
BeatPosition getContentBeatAtTime(TimePosition) const
Returns the beat number (with offset) at the given time.
ClipOwner * getParent() const
Returns the parent ClipOwner this clip is on.
virtual void setLoopRange(TimeRange)
Sets the loop range the clip should use in seconds.
void setColour(juce::Colour col)
Sets the colour property of this clip.
virtual std::shared_ptr< LaunchHandle > getLaunchHandle()
Some clip types can be launched, if that's possible, this returns a handle to trigger starting/stoppi...
virtual bool canLoop() const
Returns true if this clip is capable of looping.
virtual PatternGenerator * getPatternGenerator()
Returns the PatternGenerator for this clip if it has one.
virtual bool usesSourceFile() const
True if it references a source file - i.e.
virtual void sourceMediaChanged()
Called when the source media file reference (attribute "source") has changed - i.e.
virtual void cloneFrom(Clip *)
Clones the given clip to this clip.
void removeFromParent()
Removes this clip from the parent track or container clip.
void setLength(TimeDuration newLength, bool preserveSync)
Sets the length of the clip.
virtual juce::Colour getColour() const
Returns the colour property of this clip.
bool moveTo(ClipOwner &)
Moves the clip to a new parent (if possible).
SyncType getSyncType() const
Returns the sync type clip is using.
bool isGrouped() const override
Returns true if the clip is part of a group.
~Clip() override
Destructor.
virtual void setShowingTakes(bool shouldShow)
Sets whether the clip should be showing takes.
void updateLinkedClips()
Triggers a call to cloneFrom for all clips with the same linkID.
virtual BeatPosition getLoopStartBeats() const
Returns the beat position of the loop start point.
double getSpeedRatio() const noexcept
Returns the speed ratio i.e.
virtual void setNumberOfLoops(int)
Sets the clip looping a number of times.
virtual TimeDuration getLoopLength() const
Returns the length of loop in seconds.
juce::CachedValue< bool > disabled
Whether the Clip is disabled or not.
virtual void setCurrentTake(int)
Sets a given take index to be the current take.
void addListener(Listener *)
Adds a Listener.
juce::CachedValue< FollowActionDurationType > followActionDurationType
The type of duration to use for when to trigger the follow action.
void setName(const juce::String &newName)
Sets a new name for a clip.
virtual Clip::Array unpackTakes(bool)
Attempts to unpack the takes to new clips.
juce::CachedValue< double > followActionNumLoops
Determines the number of loops for which a launched clip will play before a follow action is taken.
virtual juce::Array< TimePosition > getInterestingTimes()
Returns times for snapping to, relative to the Edit.
virtual void setLoopRangeBeats(BeatRange)
Sets the loop range the clip should use in beats.
virtual bool usesGlobalLaunchQuatisation()
Some clip types can be launched, if that's possible, this returns whether the clip's quantisation or ...
virtual bool isMuted() const =0
Returns true if the clip is muted.
virtual void setSpeedRatio(double)
Sets a speed ratio i.e.
TimeRange getLoopRange() const
Returns the loop range in seconds.
BeatRange getLoopRangeBeats() const
Returns the loop range in beats.
virtual bool isShowingTakes() const
Returns true if the clip is showing takes.
juce::File getCurrentSourceFile() const
Returns the current source file, this is different to the SourceFileReference as it could be a tempor...
juce::CachedValue< juce::Colour > colour
The colour property.
virtual FollowActions * getFollowActions()
Some clip types can be launched, if that's possible, this can be used to determine the action to perf...
virtual juce::Colour getDefaultColour() const =0
Returns the default colour for this clip.
virtual LaunchQuantisation * getLaunchQuantisation()
Some clip types can be launched, if that's possible, this returns a quantisation that can be used for...
virtual juce::StringArray getTakeDescriptions() const
Returns the descriptions of any takes.
void setLinkGroupID(juce::String newLinkID)
Sets the link ID to link this clip with others.
juce::ListenerList< Listener > & getListeners()
Returns the listener list so Nodes can manually call them.
juce::UndoManager * getUndoManager() const
Returns the UndoManager.
bool isLinked() const
Returns true if this clip is linked with any others.
ClipPosition getPosition() const override
Returns the ClipPosition on the parent Track.
virtual bool addClipPlugin(const Plugin::Ptr &, SelectionManager &)
Adds a plugin to the clip.
void setEnd(TimePosition newEnd, bool preserveSync)
Sets the end of the clip.
FollowActionDurationType
Defines the types of duration follow actions can use.
static Ptr createClipForState(const juce::ValueTree &, ClipOwner &targetParent)
Creates a clip for a given ValueTree representation.
virtual int getCurrentTake() const
Returns the current take index.
void setGroup(EditItemID newGroupID)
Sets the clip to be part of a group.
virtual void setMuted(bool)
Mutes or unmutes the clip.
void setCurrentSourceFile(const juce::File &)
Sets a new source file for this clip.
SourceFileReference & getSourceFileReference()
Returns the SourceFileReference of the Clip.
SyncType
Determines the clip sync type.
@ syncBarsBeats
Sync to beats.
@ syncAbsolute
Sync to abslute time.
virtual BeatDuration getLoopLengthBeats() const
Returns the length of loop in beats.
void removeListener(Listener *)
Removes a Listener.
void setPosition(ClipPosition newPosition)
Sets the position of the clip.
virtual void setSyncType(SyncType sync)
Sets the sync type for the clip.
virtual void clearTakes()
Clears any takes this clip has.
virtual bool isCurrentTakeComp()
Returns true if the current take is a comp.
TrackItem * getGroupParent() const override
Returns the parent TrackItem if part of a group.
An interface for objects within an edit that can be exported.
Holds a sequence of plugins.
An ID representing one of the items in a Project.
Manages a list of items that are currently selected.
This class wraps a string that is generally held in a 'source' property, and which is a reference to ...
Base class for EditItems that live in a Track, e.g.
Type
Defines the types of item that can live on Track[s].
Base class for tracks which contain clips and plugins and can be added to Edit[s].
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
const double speedRatioMax
Maximum speed ratio.
const double speedRatioMin
Minimum speed ratio.
Holds a clip's level state.
Represents a duration in beats.
Represents a position in beats.
Represents a duration in real-life time.
Represents a position in real-life time.
Represents the position of a clip on a timeline.
Listener interface to be notified of recorded MIDI being sent to the plugins.
virtual void midiMessageGenerated(Clip &, const juce::MidiMessage &)=0
Called when a recorded MidiMessage has been generated and sent.
ID for objects of type EditElement - e.g.
Provides a thread-safe way to share a clip's levels with an audio engine without worrying about the C...
float getGain() const noexcept
Returns the clip's absolute gain.
float getPan() const noexcept
Returns the clip's pan from -1.0 to 1.0.
float getGainIncludingMute() const noexcept
Returns the clip's gain if the clip is not muted.
bool isMute() const noexcept
Returns true if the clip is muted.
void getLeftAndRightGains(float &left, float &right) const noexcept
Reutrns the left and right gains taking in to account mute and pan values.
LiveClipLevel() noexcept=default
Creates an empty LiveClipLevel.
sync