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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_TimecodeDisplayFormat.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//==============================================================================
17enum class TimecodeType
18{
19 millisecs,
20 barsBeats,
21 fps24,
22 fps25,
23 fps30
24};
25
26
27//==============================================================================
33{
34 //==============================================================================
35 // default to minutes/secs, snap to 1ms
36 TimecodeSnapType() noexcept = default;
37 TimecodeSnapType (TimecodeType t, int lev) noexcept : type (t), level (lev) {}
38
39 //==============================================================================
40 juce::String getDescription (const TempoSetting&, bool isTripletOverride) const;
41 TimeDuration getApproxIntervalTime (const TempoSetting&) const; // may not be accurate for stuff like ramped tempos
42
44 TimeDuration getApproxIntervalTime (const TempoSetting&, bool isTripletsOverride) const; // may not be accurate for stuff like ramped tempos
45
46 juce::String getTimecodeString (TimePosition time,
47 const TempoSequence&,
48 bool useStartLabelIfZero) const;
49
50 TimePosition roundTimeDown (TimePosition, const TempoSequence&) const;
51 TimePosition roundTimeDown (TimePosition, const TempoSequence&, bool isTripletsOverride) const;
52 TimePosition roundTimeNearest (TimePosition, const TempoSequence&) const;
53 TimePosition roundTimeNearest (TimePosition, const TempoSequence&, bool isTripletsOverride) const;
54 TimePosition roundTimeUp (TimePosition, const TempoSequence&) const;
55 TimePosition roundTimeUp (TimePosition, const TempoSequence&, bool tripletsOverride) const;
56
57 //==============================================================================
58 int getLevel() const noexcept { return level; }
59 int getOneBarLevel() const noexcept;
60
61 // find the maximum snap level for which this time can be considered 'on an interval'
62 TimecodeSnapType getSnapTypeForMaximumSnapLevelOf (TimePosition, const TempoSequence&) const;
63 TimecodeSnapType getSnapTypeForMaximumSnapLevelOf (TimePosition, const TempoSequence&, bool isTripletsOverride) const;
64
65 // get a snap type that rounds things to 1 beat
66 static TimecodeSnapType get1BeatSnapType();
67
68 TimecodeType type = TimecodeType::millisecs;
69 int level = 0;
70
71private:
72 TimeDuration getIntervalNonBarsBeats() const;
73 TimePosition roundTime (TimePosition, const TempoSequence&, double adjustment) const;
74 TimePosition roundTime (TimePosition, const TempoSequence&, double adjustment, bool isTripletsOverride) const;
75};
76
79{
80public:
81 TimecodeDuration() = default;
82 static TimecodeDuration fromSeconds (Edit&, TimePosition start, TimePosition end);
83 static TimecodeDuration fromBeatsOnly (BeatDuration beats, int beatsPerBar);
84 static TimecodeDuration fromSecondsOnly (TimeDuration seconds);
85
86 bool operator== (const TimecodeDuration&) const;
87 bool operator!= (const TimecodeDuration&) const;
88
91
92 int beatsPerBar = 0;
93
94private:
96};
97
98//==============================================================================
103{
104 //==============================================================================
105 TimecodeType type;
106
107 //==============================================================================
108 // (defaults to barsBeats, 24fps
109 TimecodeDisplayFormat() noexcept : type (TimecodeType::barsBeats) {}
110 TimecodeDisplayFormat (TimecodeType t) noexcept : type (t) {}
111
112 bool operator== (const TimecodeDisplayFormat& other) const { return type == other.type; }
113 bool operator!= (const TimecodeDisplayFormat& other) const { return type != other.type; }
114
115 //==============================================================================
116 bool isBarsBeats() const;
117 bool isMilliseconds() const;
118 bool isSMPTE() const;
119 int getFPS() const;
120
121 //==============================================================================
122 // general description of how the rounding will be done - e.g. "Snap to nearest beat"
123 juce::String getRoundingDescription() const;
124
125 juce::String getString (const TempoSequence&, TimePosition, bool isRelative) const;
126 juce::String getStartLabel() const;
127
129 int getNumParts() const;
130 juce::String getSeparator (int part) const;
131 int getMaxCharsInPart (int part, bool canBeNegative) const;
132 int getMaxValueOfPart (const TempoSequence&, TimecodeDuration currentTime, int part, bool isRelative) const;
133 int getMinValueOfPart (int part, bool isRelative) const;
134
135 void getPartStrings (TimecodeDuration duration, const TempoSequence&, bool isRelative, juce::String results[4]) const;
136 TimecodeDuration getNewTimeWithPartValue (TimecodeDuration oldTime, const TempoSequence&,
137 int part, int newValue, bool isRelative) const;
138
139 //==============================================================================
140 TimecodeSnapType getBestSnapType (const TempoSetting&, TimeDuration onScreenTimePerPixel, bool isTripletOverride) const;
141
142 int getNumSnapTypes() const;
143 TimecodeSnapType getSnapType (int index) const;
144
145 int getSubSecondDivisions() const; // ticks, fps or 1000 for minutes/secs
146
154 const int subSecondDivisions = 1000,
155 bool showHours = false);
156};
157
158
159//==============================================================================
164{
166 TimecodeSnapType minSnapTypeToUse,
167 bool isTripletOverride);
168
171
172 juce::String getTimecodeAsString() const;
173
175 int getCurrentResolutionLevel() const noexcept { return currentSnapType.getLevel(); }
176 int getMinimumResolutionLevel() const noexcept { return minSnapType.getLevel(); }
177
178 // true if the current resolution is at least bar level
179 bool isOneBarOrGreater() const noexcept;
180
181private:
182 const TempoSequence& sequence;
183 TimecodeSnapType minSnapType, currentSnapType;
184 TimePosition time;
185 bool isTripletOverride;
186
187 JUCE_DECLARE_NON_COPYABLE (TimecodeDisplayIterator)
188};
189
190
191}} // namespace tracktion { inline namespace engine
192
193//==============================================================================
194
195namespace juce
196{
197
198template<>
199struct VariantConverter<tracktion::engine::TimecodeDisplayFormat>
200{
201 static tracktion::engine::TimecodeDisplayFormat fromVar (const var& v)
202 {
203 if (v == "beats") return tracktion::engine::TimecodeType::barsBeats;
204 if (v == "fps24") return tracktion::engine::TimecodeType::fps24;
205 if (v == "fps25") return tracktion::engine::TimecodeType::fps25;
206 if (v == "fps30") return tracktion::engine::TimecodeType::fps30;
207
208 return tracktion::engine::TimecodeType::millisecs;
209 }
210
212 {
213 if (t.type == tracktion::engine::TimecodeType::barsBeats) return "beats";
214 if (t.type == tracktion::engine::TimecodeType::fps24) return "fps24";
215 if (t.type == tracktion::engine::TimecodeType::fps25) return "fps25";
216 if (t.type == tracktion::engine::TimecodeType::fps30) return "fps30";
217
218 return "seconds";
219 }
220};
221
222}
The Tracktion Edit class!
Holds a list of TempoSetting objects, to form a sequence of tempo changes.
A tempo value, as used in a TempoSequence.
Stores a duration in both beats and seconds.
Represents a duration in beats.
Represents a duration in real-life time.
Represents a position in real-life time.
int getNumParts() const
number of sections in the timecode string
static juce::String toFullTimecode(TimePosition, const int subSecondDivisions=1000, bool showHours=false)
this will format the time as "hh:mm:ss.xxx".
Iterates along a timeline for drawing things like the ticks on the timebar.
int getCurrentResolutionLevel() const noexcept
the resolution level of the timecode that the current interval is at
time