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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_ClipSlot.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
11
12namespace tracktion { inline namespace engine
13{
14
16 : EditItem (EditItemID::fromID (v), t.edit),
17 state (v), track (t)
18{
19 assert (state.hasType (IDs::CLIPSLOT));
20 assert (itemID.isValid());
22 edit.clipSlotCache.addItem (*this);
23}
24
26{
27 notifyListenersOfDeletion();
28 edit.clipSlotCache.removeItem (*this);
29}
30
31//==============================================================================
33{
34 if (c == nullptr)
35 return;
36
37 if (auto existingClip = getClip())
38 existingClip->removeFromParent();
39
40 jassert (findClipForID (edit, c->itemID) == nullptr);
41
42 auto um = c->getUndoManager();
43 c->state.getParent().removeChild (c->state, um);
44 state.addChild (c->state, -1, um);
45}
46
48{
49 return getClips()[0];
50}
51
53{
54 if (auto at = dynamic_cast<AudioTrack*> (&track))
55 return at->getClipSlotList().getClipSlots().indexOf (this);
56
58 return -1;
59}
60
61InputDeviceInstance::Destination* ClipSlot::getInputDestination()
62{
63 for (auto in : track.edit.getAllInputDevices())
64 for (auto dest : in->destinations)
65 if (dest->targetID == state[IDs::id])
66 return dest;
67
68 return nullptr;
69}
70
71//==============================================================================
72juce::String ClipSlot::getName() const
73{
74 return TRANS("Clip Slot");
75}
76
78{
79 return TRANS("Clip Slot");
80}
81
86
91
96
98{
99 return track.edit;
100}
101
102//==============================================================================
103void ClipSlot::clipCreated (Clip&)
104{
105}
106
107void ClipSlot::clipAddedOrRemoved()
108{
109 jassert (getClips().size() <= 1);
110}
111
112void ClipSlot::clipOrderChanged()
113{
114}
115
116void ClipSlot::clipPositionChanged()
117{
118}
119
120
121//==============================================================================
122//==============================================================================
125 state (v),
126 track (t)
127{
128 assert (v.hasType (IDs::CLIPSLOTS));
129
130 for (auto child : state)
131 if (child.hasType (IDs::CLIPSLOT))
132 EditItemID::readOrCreateNewID (track.edit, child);
133
134 rebuildObjects();
135}
136
138{
139 freeObjects();
140}
141
143{
144 return objects;
145}
146
148{
149 for (int i = size(); i < numSlots; ++i)
150 {
151 auto newSlotState = juce::ValueTree (IDs::CLIPSLOT);
152 EditItemID::readOrCreateNewID (track.edit, newSlotState);
153 parent.appendChild (newSlotState, &track.edit.getUndoManager());
154 }
155
156 assert (objects.size() >= numSlots);
157}
158
160{
161 if (numSlots > size())
162 {
163 ensureNumberOfSlots (numSlots);
164 }
165 else if (size() > numSlots)
166 {
167 while (size() > numSlots)
168 deleteSlot (*getClipSlots().getLast());
169 }
170}
171
173{
174 auto newSlotState = juce::ValueTree (IDs::CLIPSLOT);
175 EditItemID::readOrCreateNewID (track.edit, newSlotState);
176 parent.addChild (newSlotState, index, &track.edit.getUndoManager());
177 return getClipSlots()[index];
178}
179
180void ClipSlotList::deleteSlot (ClipSlot& cs)
181{
182 assert (&cs.track == &track);
183 parent.removeChild (cs.state, &track.edit.getUndoManager());
184}
185
186//==============================================================================
187bool ClipSlotList::isSuitableType (const juce::ValueTree& v) const
188{
189 return v.hasType (IDs::CLIPSLOT);
190}
191
192ClipSlot* ClipSlotList::createNewObject (const juce::ValueTree& v)
193{
194 return new ClipSlot (v, track);
195}
196
197void ClipSlotList::deleteObject (ClipSlot* clipSlot)
198{
199 delete clipSlot;
200}
201
202void ClipSlotList::newObjectAdded (ClipSlot*)
203{
204}
205
206void ClipSlotList::objectRemoved (ClipSlot*)
207{
208}
209
210void ClipSlotList::objectOrderChanged()
211{
212}
213
214
215}} // namespace tracktion { inline namespace engine
assert
int indexOf(ParameterType elementToLookFor) const
bool hasType(const Identifier &typeName) const noexcept
void addChild(const ValueTree &child, int index, UndoManager *undoManager)
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.
ClipSlot * insertSlot(int index)
Inserts a new slot with the given index.
juce::Array< ClipSlot * > getClipSlots() const
Returns the ClipSlot* on this Track.
ClipSlotList(const juce::ValueTree &, Track &)
Creates a ClipSlotList for a Track.
Track & track
The Track this ClipSlotList belongs to.
juce::ValueTree state
The state of this ClipSlotList.
void setNumberOfSlots(int numSlots)
Adds or removes Slots to ensure the exact number of slots exist.
void ensureNumberOfSlots(int numSlots)
Adds Slots to ensure at least numSlots exist.
Represents a slot on a track that a Clip can live in to be played as a launched clip.
juce::ValueTree & getClipOwnerState() override
Must return the state of this ClipOwner.
juce::String getSelectableDescription() override
Subclasses must return a description of what they are.
Edit & getClipOwnerEdit() override
Must return the Edit this ClipOwner belongs to.
EditItemID getClipOwnerID() override
Must return the ID of this ClipOwner.
ClipSlot(const juce::ValueTree &, Track &)
Creates a ClipSlot for a given Track.
Clip * getClip()
Returns the currently set clip.
Track & track
The Track this ClipSlot belongs to.
int getIndex()
Returns slot index on track.
void setClip(Clip *)
Sets the Clip to be used within this slot.
~ClipSlot() override
Destructor.
Selectable * getClipOwnerSelectable() override
Must return the selectable if this ClipOwner is one.
juce::ValueTree state
The state of this ClipSlot.
A clip in an edit.
Base class for objects that live inside an edit - e.g.
const EditItemID itemID
Every EditItem has an ID which is unique within the edit.
The Tracktion Edit class!
juce::UndoManager & getUndoManager() noexcept
Returns the juce::UndoManager used for this Edit.
EditItemCache< ClipSlot > clipSlotCache
Quick way to find and iterate all ClipSlot[s] in the Edit.
Base class for things that can be selected, and whose properties can appear in the properties panel.
Base class for tracks which contain clips and plugins and can be added to Edit[s].
#define TRANS(stringLiteral)
#define jassert(expression)
#define jassertfalse
Clip * findClipForID(ClipOwner &co, EditItemID id)
Returns a clip with the given ID if the ClipOwner contains it.
ID for objects of type EditElement - e.g.