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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_TimeSigSetting.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
14TimeSigSetting::TimeSigSetting (TempoSequence& ts, const juce::ValueTree& v)
15 : TrackItem (ts.edit, {}, Type::timeSig),
16 state (v), ownerSequence (ts)
17{
18 auto* um = ts.getUndoManager();
19
20 startBeatNumber.referTo (state, IDs::startBeat, um);
21 numerator.referTo (state, IDs::numerator, um, 4);
22 denominator.referTo (state, IDs::denominator, um, 4);
23 triplets.referTo (state, IDs::triplets, um);
24
25 state.addListener (this);
26}
27
28TimeSigSetting::~TimeSigSetting()
29{
30 state.removeListener (this);
31
32 notifyListenersOfDeletion();
33}
34
35juce::String TimeSigSetting::getSelectableDescription()
36{
37 return TRANS("Time Signature");
38}
39
40juce::String TimeSigSetting::getStringTimeSig() const
41{
42 return juce::String (numerator) + "/" + juce::String (denominator);
43}
44
45void TimeSigSetting::setStringTimeSig (const juce::String& s)
46{
47 if (s.containsChar ('/'))
48 {
49 numerator = s.upToFirstOccurrenceOf ("/", false, false).trim().getIntValue();
50 denominator = s.fromLastOccurrenceOf ("/", false, false).trim().getIntValue();
51 }
52}
53
54void TimeSigSetting::removeFromEdit()
55{
56 jassert (Selectable::isSelectableValid (&edit));
57 ownerSequence.removeTimeSig (ownerSequence.indexOfTimeSig (this));
58}
59
60Track* TimeSigSetting::getTrack() const
61{
62 return edit.getTempoTrack();
63}
64
65ClipPosition TimeSigSetting::getPosition() const
66{
67 ownerSequence.updateTempoDataIfNeeded();
68 auto s = startTime;
69
70 if (auto nextTimeSig = ownerSequence.getTimeSig (ownerSequence.indexOfTimeSig (this) + 1))
71 return { { s, nextTimeSig->startTime }, TimeDuration() };
72
73 return { { s, s + TimeDuration::fromSeconds (1.0) }, TimeDuration() };
74}
75
76juce::String TimeSigSetting::getName() const
77{
78 return getStringTimeSig();
79}
80
81}} // namespace tracktion { inline namespace engine
String upToFirstOccurrenceOf(StringRef substringToEndWith, bool includeSubStringInResult, bool ignoreCase) const
String trim() const
bool containsChar(juce_wchar character) const noexcept
String fromLastOccurrenceOf(StringRef substringToFind, bool includeSubStringInResult, bool ignoreCase) const
int getIntValue() const noexcept
Base class for tracks which contain clips and plugins and can be added to Edit[s].
#define TRANS(stringLiteral)
#define jassert(expression)
Represents a duration in real-life time.
Represents the position of a clip on a timeline.