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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_EditTime.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
11
12namespace tracktion { inline namespace engine
13{
14
16BeatPosition toBeats (TimePosition, const TempoSequence&);
17
19TimePosition toTime (BeatPosition, const TempoSequence&);
20
21//==============================================================================
23BeatRange toBeats (TimeRange, const TempoSequence&);
24
26TimeRange toTime (BeatRange, const TempoSequence&);
27
28
29//==============================================================================
30//==============================================================================
36{
38 EditTime();
39
42
45
47 bool isBeats() const;
48
49private:
52
54};
55
56//==============================================================================
61
66
67
68//==============================================================================
69//==============================================================================
75{
77 EditTimeRange (TimeRange);
78
81
84
86 EditTimeRange (BeatRange);
87
90
93
95 bool isBeats() const;
96
97private:
98 friend TimeRange toTime (EditTimeRange, const TempoSequence&);
99 friend BeatRange toBeats (EditTimeRange, const TempoSequence&);
100
102};
103
107TimeRange toTime (EditTimeRange, const TempoSequence&);
108
112BeatRange toBeats (EditTimeRange, const TempoSequence&);
113
114
115//==============================================================================
119{
120 TimeRange time;
131 TimePosition getStart() const { return time.getStart(); }
133 TimePosition getEnd() const { return time.getEnd(); }
135 TimeDuration getLength() const { return time.getLength(); }
137 TimeDuration getOffset() const { return offset; }
139 TimePosition getStartOfSource() const { return time.getStart() - offset; }
140
142 bool operator== (const ClipPosition& other) const { return offset == other.offset && time == other.time; }
144 bool operator!= (const ClipPosition& other) const { return ! operator== (other); }
145
147 ClipPosition rescaled (TimePosition anchorTime, double factor) const;
148};
149
151ClipPosition createClipPosition (const TempoSequence&, TimeRange, TimeDuration offset = {});
152
154ClipPosition createClipPosition (const TempoSequence&, BeatRange, BeatDuration offset = {});
155
156
157//==============================================================================
158//==============================================================================
159}} // namespace tracktion { inline namespace engine
160
161namespace juce
162{
163 template<>
164 struct VariantConverter<tracktion::core::TimePosition>
165 {
166 static tracktion::core::TimePosition fromVar (const var& v) { return tracktion::core::TimePosition::fromSeconds (static_cast<double> (v)); }
167 static var toVar (tracktion::core::TimePosition v) { return v.inSeconds(); }
168 };
169
170 template<>
171 struct VariantConverter<tracktion::core::TimeDuration>
172 {
173 static tracktion::core::TimeDuration fromVar (const var& v) { return tracktion::core::TimeDuration::fromSeconds (static_cast<double> (v)); }
174 static var toVar (tracktion::core::TimeDuration v) { return v.inSeconds(); }
175 };
176
177 template<>
178 struct VariantConverter<tracktion::core::BeatPosition>
179 {
180 static tracktion::core::BeatPosition fromVar (const var& v) { return tracktion::core::BeatPosition::fromBeats (static_cast<double> (v)); }
181 static var toVar (tracktion::core::BeatPosition v) { return v.inBeats(); }
182 };
183
184 template<>
185 struct VariantConverter<tracktion::core::BeatDuration>
186 {
187 static tracktion::core::BeatDuration fromVar (const var& v) { return tracktion::core::BeatDuration::fromBeats (static_cast<double> (v)); }
188 static var toVar (tracktion::core::BeatDuration v) { return v.inBeats(); }
189 };
190}
191
192namespace tracktion { inline namespace engine {
193
194//==============================================================================
195// _ _ _ _
196// __| | ___ | |_ __ _ (_)| | ___
197// / _` | / _ \| __| / _` || || |/ __|
198// | (_| || __/| |_ | (_| || || |\__ \ _ _ _
199// \__,_| \___| \__| \__,_||_||_||___/(_)(_)(_)
200//
201// Code beyond this point is implementation detail...
202//
203//==============================================================================
204
207{
208}
209
211 : position (tp)
212{
213}
214
216 : position (bp)
217{
218}
219
220inline bool EditTime::isBeats() const
221{
222 return std::holds_alternative<BeatPosition> (position);
223}
224
225//==============================================================================
227{
228 // N.B. std::get unavailable prior to macOS 10.14
229 if (const auto tp = std::get_if<TimePosition> (&et.position))
230 return *tp;
231
232 return tracktion::engine::toTime (*std::get_if<BeatPosition> (&et.position), ts);
233}
234
236{
237 if (const auto bp = std::get_if<BeatPosition> (&et.position))
238 return *bp;
239
240 return tracktion::engine::toBeats (*std::get_if<TimePosition> (&et.position), ts);
241}
242
243//==============================================================================
245 : range (r)
246{
247}
248
250 : range (r)
251{
252}
253
255 : range (TimeRange (start, end))
256{
257}
258
260 : range (TimeRange (start, length))
261{
262}
263
265 : range (BeatRange (start, end))
266{
267}
268
270 : range (BeatRange (start, length))
271{
272}
273
274inline bool EditTimeRange::isBeats() const
275{
277}
278
279//==============================================================================
280inline TimeRange toTime (EditTimeRange r, const TempoSequence& ts)
281{
282 // N.B. std::get unavailable prior to macOS 10.14
283 if (const auto tr = std::get_if<TimeRange> (&r.range))
284 return *tr;
285
286 return tracktion::engine::toTime (*std::get_if<BeatRange> (&r.range), ts);
287}
288
289inline BeatRange toBeats (EditTimeRange r, const TempoSequence& ts)
290{
291 if (const auto br = std::get_if<BeatRange> (&r.range))
292 return *br;
293
294 return tracktion::engine::toBeats (*std::get_if<TimeRange> (&r.range), ts);
295}
296
297//==============================================================================
298inline ClipPosition ClipPosition::rescaled (TimePosition anchorTime, double factor) const
299{
300 return { time.rescaled (anchorTime, factor), offset * factor };
301}
302
303
304}} // namespace tracktion { inline namespace engine
Holds a list of TempoSetting objects, to form a sequence of tempo changes.
T is_pointer_v
BeatPosition toBeats(TimePosition tp, const TempoSequence &ts)
Converts a TimePosition to a BeatPosition given a TempoSequence.
ClipPosition createClipPosition(const TempoSequence &, TimeRange range, TimeDuration offset)
Creates a ClipPosition from either a time or beat range.
TimePosition toTime(BeatPosition bp, const TempoSequence &ts)
Converts a BeatPosition to a TimePosition given a TempoSequence.
RangeType< BeatPosition > BeatRange
A RangeType based on beats.
RangeType< TimePosition > TimeRange
A RangeType based on real time (i.e.
Represents a duration in beats.
static constexpr BeatDuration fromBeats(T durationInBeats)
Create a BeatPosition from a number of beats.
Represents a position in beats.
static constexpr BeatPosition fromBeats(T positionInBeats)
Create a BeatPosition from a number of beats.
Represents a duration in real-life time.
static constexpr TimeDuration fromSeconds(T positionInSeconds)
Create a TimeDuration from a number of seconds.
Represents a position in real-life time.
static constexpr TimePosition fromSeconds(T positionInSeconds)
Create a TimePosition from a number of seconds.
Represents the position of a clip on a timeline.
TimePosition getEnd() const
Returns the end time.
TimePosition getStartOfSource() const
Returns what would be the the start of the source material in the timeline.
TimeDuration offset
The offset this ClipPosition has.
TimePosition getStart() const
Returns the start time.
TimeRange time
The TimeRange this ClipPosition occupies.
bool operator==(const ClipPosition &other) const
Compares two ClipPositions.
TimeDuration getOffset() const
Returns the offset.
ClipPosition rescaled(TimePosition anchorTime, double factor) const
Returns a ClipPosition scaled around an anchor point.
bool operator!=(const ClipPosition &other) const
Compares two ClipPositions.
TimeDuration getLength() const
Returns the length.
Represents a time range in an Edit stored as either time or beats.
friend TimeRange toTime(EditTimeRange, const TempoSequence &)
Converts an EditTimeRange to a TimeRange.
EditTimeRange(TimeRange)
Creates an EditTimeRange from a TimeRange.
friend BeatRange toBeats(EditTimeRange, const TempoSequence &)
Converts an EditTimeRange to a BeatRange.
bool isBeats() const
Returns true if the time is stored as beats, false if stored as a TimePosition.
Represents a time point in an Edit stored as either time or beats.
friend BeatPosition toBeats(EditTime, const TempoSequence &)
Converts an EditTime to a BeatPosition.
bool isBeats() const
Returns true if the time is stored as beats, false if stored as a TimePosition.
EditTime()
Creates an empty EditTime, starting at 0.
friend TimePosition toTime(EditTime, const TempoSequence &)
Converts an EditTime to a TimePosition.