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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_TrackUtils.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
19{
26 TrackInsertPoint (Track* parent, Track* preceding);
27
34 TrackInsertPoint (EditItemID parentTrackID, EditItemID precedingTrackID);
35
40 TrackInsertPoint (Track& currentPos, bool insertBefore);
41
44
45 EditItemID parentTrackID, precedingTrackID;
46};
47
48//==============================================================================
53struct TrackList : public ValueTreeObjectList<Track>,
54 private juce::AsyncUpdater
55{
57 TrackList (Edit&, const juce::ValueTree& parent);
58
60 ~TrackList() override;
61
62 //==============================================================================
64 Track* getTrackFor (const juce::ValueTree&) const;
65
70 bool visitAllRecursive (const std::function<bool(Track&)>&) const;
71
76 void visitAllTopLevel (const std::function<bool(Track&)>&) const;
77
83 void visitAllTracks (const std::function<bool(Track&)>&, bool recursive) const;
84
85 //==============================================================================
87 static bool isMovableTrack (const juce::ValueTree&) noexcept;
88
90 static bool isArrangerTrack (const juce::ValueTree&) noexcept;
91
93 static bool isChordTrack (const juce::ValueTree&) noexcept;
94
96 static bool isMarkerTrack (const juce::ValueTree&) noexcept;
97
99 static bool isTempoTrack (const juce::ValueTree&) noexcept;
100
102 static bool isMasterTrack (const juce::ValueTree&) noexcept;
103
107 static bool isFixedTrack (const juce::ValueTree&) noexcept;
108
110 static bool isTrack (const juce::ValueTree&) noexcept;
111
113 static bool isTrack (const juce::Identifier&) noexcept;
114
118 static bool hasAnySubTracks (const juce::ValueTree&);
119
120 //==============================================================================
122 static void sortTracksByType (juce::ValueTree& editState, juce::UndoManager*);
123
124 //==============================================================================
126 bool isSuitableType (const juce::ValueTree&) const override;
128 Track* createNewObject (const juce::ValueTree&) override;
130 void deleteObject (Track* t) override;
132 void newObjectAdded (Track* t) override;
134 void objectRemoved (Track*) override;
136 void objectOrderChanged() override;
137
138 Edit& edit;
139 bool rebuilding = true;
140
141private:
142 void handleAsyncUpdate() override;
143
145};
146
147//==============================================================================
152{
153 Track* track = nullptr;
154 TimeRange range;
161 bool merge (const TrackItem& c)
162 {
163 if (c.getTrack() == track
164 && c.getEditTimeRange().overlaps (range.expanded (TimeDuration::fromSeconds (0.0001))))
165 {
166 range = range.getUnionWith (c.getEditTimeRange());
167 return true;
168 }
169
170 return false;
171 }
172
174 template <typename TrackItemArray>
175 static juce::Array<TrackSection> findSections (const TrackItemArray& trackItems)
176 {
178
179 for (auto&& c : trackItems)
180 {
181 bool segFound = false;
182
183 for (auto& dstSeg : result)
184 {
185 if (dstSeg.merge (*c))
186 {
187 segFound = true;
188 break;
189 }
190 }
191
192 if (! segFound)
193 {
194 TrackSection cs;
195 cs.range = c->getEditTimeRange();
196 cs.track = c->getTrack();
197
198 if (cs.track != nullptr)
199 result.add (cs);
200 }
201 }
202
203 return result;
204 }
205};
206
207//==============================================================================
241
246
247
248//==============================================================================
252template <typename ArrayType>
253int findIndexOfNextItemAt (const ArrayType& items, TimePosition time)
254{
255 for (int i = items.size(); --i >= 0;)
256 {
257 auto pos = items.getUnchecked (i)->getPosition().time;
258
259 if (pos.getStart() < time)
260 {
261 if (pos.getEnd() > time)
262 return i;
263
264 return i + 1;
265 }
266 }
267
268 return 0;
269}
270
274template <typename ArrayType>
275TimeRange findUnionOfEditTimeRanges (const ArrayType& items)
276{
277 TimeRange total;
278 bool first = true;
279
280 for (auto& item : items)
281 {
282 auto time = item->getEditTimeRange();
283
284 if (first)
285 {
286 first = false;
287 total = time;
288 }
289 else
290 {
291 total = total.getUnionWith (time);
292 }
293 }
294
295 return total;
296}
297
298}} // namespace tracktion { inline namespace engine
void add(const ElementType &newElement)
The Tracktion Edit class!
Base class for EditItems that live in a Track, e.g.
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)
int findIndexOfNextItemAt(const ArrayType &items, TimePosition time)
Returns the index of the next item after the given time.
void moveAutomation(const juce::Array< TrackAutomationSection > &origSections, TimeDuration offset, bool copy)
Moves a set of automation optionally applying an offset and copying the automation (rather than movin...
TimeRange findUnionOfEditTimeRanges(const ArrayType &items)
Returns the the time range that covers all the given TrackItems.
Represents a duration in real-life time.
Represents a position in real-life time.
ID for objects of type EditElement - e.g.
Holds a reference to a section of automation for a given Track.
Track::Ptr src
The time range of the automation section.
TrackAutomationSection() noexcept=default
Construts an empty section.
bool containsParameter(AutomatableParameter *) const
Tests whether this section contains a given parameter.
AutomationCurve curve
The curve section of this parameter.
void mergeIn(const TrackAutomationSection &)
The destination Track.
juce::Array< ActiveParameters > activeParameters
A list of parameteres and their curves.
bool overlaps(const TrackAutomationSection &) const
Tests whether another section overlaps with this one.
Defines the place to insert Track[s].
An iterable list of Track[s] that live either in an Edit or as subtracks of a Track.
static bool isMarkerTrack(const juce::ValueTree &) noexcept
Returns true if the state is for a MarkerTrack.
static bool isMasterTrack(const juce::ValueTree &) noexcept
Returns true if the state is for a MasterTrack.
Track * getTrackFor(const juce::ValueTree &) const
Returns a Track for a given state.
static void sortTracksByType(juce::ValueTree &editState, juce::UndoManager *)
Sorts a list of tracks by their type, placing global tracks at the top.
static bool isFixedTrack(const juce::ValueTree &) noexcept
Returns true if the track is fixed.
static bool isChordTrack(const juce::ValueTree &) noexcept
Returns true if the state is for a ChordTrack.
static bool isTempoTrack(const juce::ValueTree &) noexcept
Returns true if the state is for a TempoTrack.
void visitAllTracks(const std::function< bool(Track &)> &, bool recursive) const
Calls the given function on all Track[s], optionally recursively.
void visitAllTopLevel(const std::function< bool(Track &)> &) const
Calls the given function on all top-level Track[s].
static bool isTrack(const juce::ValueTree &) noexcept
Returns true if the given ValeTree is for a known Track type.
static bool isArrangerTrack(const juce::ValueTree &) noexcept
Returns true if the state is for an ArrangerTrack.
static bool hasAnySubTracks(const juce::ValueTree &)
Returns true if the track has any sub tracks.
bool visitAllRecursive(const std::function< bool(Track &)> &) const
Calls the given function on all Track[s].
static bool isMovableTrack(const juce::ValueTree &) noexcept
Returns true if the track is movable.
Defines a time raneg sectin of a Track.
TimeRange range
The time range this section refers to.
bool merge(const TrackItem &c)
Merges an overlapping TrackItem track/time range with this section.
Track * track
The Track this section refers to.
static juce::Array< TrackSection > findSections(const TrackItemArray &trackItems)
Returns a set of TrackSections for the given TrackItems.
time