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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_TempoSetting.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
16 ownerSequence (ts), state (v)
17{
18 auto* um = ts.getUndoManager();
19
20 startBeatNumber.referTo (state, IDs::startBeat, um);
21 bpm.referTo (state, IDs::bpm, um, 120.0);
22 curve.referTo (state, IDs::curve, um);
23}
24
28
29juce::ValueTree TempoSetting::create (BeatPosition beat, double newBPM, float curveVal)
30{
31 return createValueTree (IDs::TEMPO,
32 IDs::startBeat, beat.inBeats(),
33 IDs::bpm, newBPM,
34 IDs::curve, curveVal);
35}
36
38{
39 return ownerSequence.edit;
40}
41
42//==============================================================================
47
48//==============================================================================
50{
51 ownerSequence.updateTempoDataIfNeeded();
52 return startTime;
53}
54
55void TempoSetting::set (BeatPosition newStartBeat, double newBPM, float newCurve, bool remapEditPositions)
56{
57 startBeatNumber.forceUpdateOfCachedValue();
60
61 newBPM = juce::jlimit (minBPM, maxBPM, newBPM);
62 newCurve = juce::jlimit (-1.0f, 1.0f, newCurve);
63
64 if (newBPM != bpm || startBeatNumber != newStartBeat || curve != newCurve)
65 {
67
68 if (remapEditPositions)
69 snap.savePreChangeState (getEdit());
70
71 bpm = newBPM;
72 curve = newCurve;
73 startBeatNumber = newStartBeat;
74
75 changed();
76
77 if (remapEditPositions)
78 snap.remapEdit (getEdit());
79 }
80}
81
82void TempoSetting::setStartBeat (BeatPosition b)
83{
84 set (b, bpm, curve, false);
85}
86
87void TempoSetting::setBpm (double newBpm)
88{
89 set (startBeatNumber, newBpm, curve, true);
90}
91
92void TempoSetting::setCurve (float newCurve)
93{
94 set (startBeatNumber, bpm, newCurve, true);
95}
96
98{
99 return TimeDuration::fromSeconds (240.0 / (bpm * getMatchingTimeSig().denominator));
100}
101
103{
105 ownerSequence.removeTempo (ownerSequence.indexOfTempo (this), true);
106}
107
109{
110 return ownerSequence.getTempo (ownerSequence.indexOfTempo (this) - 1);
111}
112
114{
115 return ownerSequence.getTimeSigAt (startBeatNumber);
116}
117
118HashCode TempoSetting::getHash() const noexcept
119{
120 return static_cast<HashCode> (startBeatNumber.get().inBeats() * 128.0)
121 ^ (static_cast<HashCode> (bpm * 1217.0)
122 + static_cast<HashCode> (curve * 1023.0));
123}
124
125}} // namespace tracktion { inline namespace engine
void forceUpdateOfCachedValue()
void referTo(ValueTree &tree, const Identifier &property, UndoManager *um)
The Tracktion Edit class!
virtual void changed()
This should be called to send a change notification to any SelectableListeners that are registered wi...
Holds a list of TempoSetting objects, to form a sequence of tempo changes.
TimeSigSetting & getTimeSigAt(TimePosition) const
Returns the TimeSigSetting at a given position.
int indexOfTempo(const TempoSetting *) const
Returns the index of the given TempoSetting.
void removeTempo(int index, bool remapEdit)
Removes the TempoSetting at a given index.
TempoSetting * getTempo(int index) const
Returns the TempoSetting at the given index.
Edit & edit
The Edit this sequence belongs to.
A tempo value, as used in a TempoSequence.
void set(BeatPosition, double newBpm, float newCurve, bool remapEditPositions)
Sets the properties of this tempo setting.
void setBpm(double newBpm)
Sets the BPM of this tempo setting.
static constexpr double minBPM
Minimum BPM a setting can have.
juce::String getSelectableDescription() override
Returns the description of this Selectable.
TimeSigSetting & getMatchingTimeSig() const
Returns the time signature at this tempo's time in the sequence.
TimePosition getStartTime() const
Returns the start time in seconds of the tempo setting.
TempoSetting * getPreviousTempo() const
Returns the previous tempo setting in the sequence.
void setCurve(float curve)
Sets the curve of this tempo setting.
TimeDuration getApproxBeatLength() const
Returns the approximate length of one beat based on the bpm and matching time sig denonimator.
TempoSetting(TempoSequence &, const juce::ValueTree &)
Constructs a TempoSetting belonging to a given TempoSequence.
static constexpr double maxBPM
Maximum BPM a setting can have.
static juce::ValueTree create(BeatPosition startBeat, double bpm, float curve)
Creates a tree to prepresent a TempoSetting.
void removeFromEdit()
Removes the TempoSetting from the sequence.
Edit & getEdit() const
Returns the Edit this setting belongs to.
#define TRANS(stringLiteral)
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Represents a position in beats.
Represents a duration in real-life time.
Represents a position in real-life time.
Takes a copy of all the beat related things in an edit in terms of bars/beats and then remaps these a...
#define CRASH_TRACER
This macro adds the current location to a stack which gets logged if a crash happens.