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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_ContainerClip.cpp
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
15 : AudioClipBase (v, clipID, Type::container, targetParent)
16{
17}
18
20{
21 notifyListenersOfDeletion();
22}
23
24//==============================================================================
26{
27 clipListState = state.getOrCreateChildWithName (IDs::CLIPLIST, getUndoManager());
28 initialiseClipOwner (edit, clipListState);
29
31}
32
34{
35 if (auto other = dynamic_cast<ContainerClip*> (c))
36 {
38 auto list = state.getChildWithName (IDs::CLIPLIST);
39 copyValueTree (list, other->state.getChildWithName (IDs::CLIPLIST), nullptr);
40
42 }
43}
44
45//==============================================================================
47{
48 return TRANS("Container Clip") + " - \"" + getName() + "\"";
49}
50
52{
53 for (auto c : getClips())
54 if (c->isMidi())
55 return true;
56
57 return false;
58}
59
61{
62 auto l = getLoopRange().getLength();
63
64 for (auto c : getClips())
65 l = std::max (l, toDuration (c->getPosition().getEnd()));
66
67 return l;
68}
69
70HashCode ContainerClip::getHash() const
71{
72 size_t hash = 0;
73
74 for (auto c : getClipsOfType<AudioClipBase> (*this))
75 hash_combine (hash, c->getHash());
76
77 return static_cast<HashCode> (hash);
78}
79
81{
82 auto& ts = edit.tempoSequence;
83 auto pos = getPosition();
84
85 if (loopInfo.getNumerator() == 0)
86 loopInfo.setNumerator (ts.getTimeSigAt (pos.getStart()).numerator);
87
88 if (loopInfo.getDenominator() == 0)
89 loopInfo.setDenominator (ts.getTimeSigAt (pos.getStart()).denominator);
90
91 if (loopInfo.getNumBeats() == 0.0)
92 loopInfo.setNumBeats (getSourceLength().inSeconds() * (ts.getTempoAt (pos.getStart()).getBpm() / 60.0));
93}
94
95void ContainerClip::setLoopRangeBeats (BeatRange newRangeBeats)
96{
97 const auto newStartBeat = juce::jmax (0_bp, newRangeBeats.getStart());
98 const auto newLengthBeat = juce::jmax (0_bd, newRangeBeats.getLength());
99
100 if (loopStartBeats != newStartBeat || loopLengthBeats != newLengthBeat)
101 {
103 setAutoTempo (true);
104
105 loopStartBeats = newStartBeat;
106 loopLengthBeats = newLengthBeat;
107 }
108}
109
111{
112 for (auto c : getClips())
113 c->flushStateToValueTree();
114
116}
117
119{
120 for (auto c : getClips())
121 c->pitchTempoTrackChanged();
122
124}
125
126//==============================================================================
128{
129 return clipListState;
130}
131
136
141
146
147//==============================================================================
149{
151 return true;
152
153 for (auto c : getClipsOfType<AudioClipBase> (*this))
154 if (c->isUsingFile (af))
155 return true;
156
157 return false;
158}
159
160void ContainerClip::clipCreated (Clip&)
161{
162}
163
164void ContainerClip::clipAddedOrRemoved()
165{
166}
167
168void ContainerClip::clipOrderChanged()
169{
170}
171
172void ContainerClip::clipPositionChanged()
173{
174}
175
176
177}} // namespace tracktion { inline namespace engine
ValueTree getChildWithName(const Identifier &type) const
ValueTree getOrCreateChildWithName(const Identifier &type, UndoManager *undoManager)
Base class for Clips that produce some kind of audio e.g.
virtual bool isUsingFile(const AudioFile &)
Should return true if the clip is referencing the file in any way.
void pitchTempoTrackChanged() override
Called when there are pitch or tempo changes made which might require clips to adjust timing informat...
void flushStateToValueTree() override
Can be overridden to ensure any state (e.g.
TimeRange getLoopRange() const
Returns the loop range in seconds.
void initialise() override
Initialises the Clip.
void cloneFrom(Clip *) override
Clones the given clip to this clip.
void setAutoTempo(bool shouldUseAutoTempo)
Enables/disables auto-tempo.
Base class for items that can contain clips.
const juce::Array< Clip * > & getClips() const
Returns the clips this owner contains.
void initialiseClipOwner(Edit &, juce::ValueTree clipParentState)
Must be called once from the subclass constructor to init the clip owner.
A clip in an edit.
virtual juce::String getName() const override
Returns the name of the clip.
juce::ValueTree state
The ValueTree of the Clip state.
virtual void setSpeedRatio(double)
Sets a speed ratio i.e.
juce::UndoManager * getUndoManager() const
Returns the UndoManager.
ClipPosition getPosition() const override
Returns the ClipPosition on the parent Track.
A clip that can contain multiple other clips and mix their output together.
bool isMidi() const override
Returns true if this is a MidiClip.
juce::ValueTree & getClipOwnerState() override
Must return the state of this ClipOwner.
juce::String getSelectableDescription() override
Subclasses must return a description of what they are.
Selectable * getClipOwnerSelectable() override
Must return the selectable if this ClipOwner is one.
TimeDuration getSourceLength() const override
Must return the length in seconds of the source material e.g.
void cloneFrom(Clip *) override
Clones the given clip to this clip.
EditItemID getClipOwnerID() override
Must return the ID of this ClipOwner.
void flushStateToValueTree() override
Can be overridden to ensure any state (e.g.
bool isUsingFile(const AudioFile &) override
Should return true if the clip is referencing the file in any way.
void pitchTempoTrackChanged() override
Called when there are pitch or tempo changes made which might require clips to adjust timing informat...
void initialise() override
Initialises the Clip.
ContainerClip(const juce::ValueTree &, EditItemID, ClipOwner &)
Creates a ContainerClip from a given state.
void setLoopRangeBeats(BeatRange) override
Sets the loop range the clip should use in beats.
HashCode getHash() const override
Must return a unique hash for this clip's source.
Edit & getClipOwnerEdit() override
Must return the Edit this ClipOwner belongs to.
void setLoopDefaults() override
Override this to fill in the LoopInfo structure as best fits the source.
const EditItemID itemID
Every EditItem has an ID which is unique within the edit.
The Tracktion Edit class!
void setNumerator(int newNumerator)
Sets the numerator of the object.
void setDenominator(int newDenominator)
Sets the denominator of the object.
int getDenominator() const
Returns the denominator of the object.
double getNumBeats() const
Returns the number of beats.
int getNumerator() const
Returns the numerator of the object.
void setNumBeats(double newNumBeats)
Sets the number of beats.
Base class for things that can be selected, and whose properties can appear in the properties panel.
virtual void changed()
This should be called to send a change notification to any SelectableListeners that are registered wi...
Type
Defines the types of item that can live on Track[s].
#define TRANS(stringLiteral)
T max(T... args)
constexpr Type jmax(Type a, Type b)
Represents a duration in real-life time.
ID for objects of type EditElement - e.g.