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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_MidiExpression.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
15{
17 static bool noteHasExpression (const juce::ValueTree& noteState) noexcept
18 {
19 jassert (noteState.hasType (IDs::NOTE));
20 return noteState.getNumChildren() > 0;
21 }
22
24 static bool noteHasExpression (const juce::ValueTree& noteState, const juce::Identifier& type) noexcept
25 {
26 jassert (noteState.hasType (IDs::NOTE));
27
28 return noteState.getChildWithName (type).isValid();
29 }
30
32 static bool listHasExpression (const MidiList& midiList) noexcept;
33
34 static bool isExpression (const juce::Identifier& type) noexcept
35 {
36 return type == IDs::PITCHBEND || type == IDs::PRESSURE || type == IDs::TIMBRE;
37 }
38
39 static juce::ValueTree createAndAddExpressionToNote (juce::ValueTree& noteState, const juce::Identifier& expressionType,
40 BeatPosition beat, float value, juce::UndoManager* um)
41 {
42 jassert (noteState.hasType (IDs::NOTE));
43 jassert (isExpression (expressionType));
44
45 juce::ValueTree expression (expressionType);
46 MidiExpression exp (expression);
47 exp.setBeatPosition (beat, um);
48 exp.setValue (value, um);
49 noteState.addChild (expression, -1, nullptr);
50
51 return expression;
52 }
53
54 //==============================================================================
59 : state (v)
60 {
61 jassert (! v[IDs::b].isString());
62 jassert (! v[IDs::v].isString());
63 jassert (isExpression (v.getType()));
64 }
65
67 BeatPosition getBeatPosition() const noexcept { return BeatPosition::fromBeats (static_cast<double> (state[IDs::b])); }
68
71 {
72 state.setProperty (IDs::b, newBeat.inBeats(), um);
73 }
74
78 float getValue() const noexcept { return state[IDs::v]; }
79
81 void setValue (float newValue, juce::UndoManager* um)
82 {
83 if (state.hasType (IDs::PRESSURE) || state.hasType (IDs::TIMBRE))
85
86 state.setProperty (IDs::v, newValue, um);
87 }
88
89 juce::ValueTree state;
90};
91
92}} // namespace tracktion { inline namespace engine
bool hasType(const Identifier &typeName) const noexcept
ValueTree & setProperty(const Identifier &name, const var &newValue, UndoManager *undoManager)
void addChild(const ValueTree &child, int index, UndoManager *undoManager)
exp
#define jassert(expression)
bool isPositiveAndNotGreaterThan(Type1 valueToTest, Type2 upperLimit) noexcept
Represents a position in beats.
constexpr double inBeats() const
Returns the position as a number of beats.
static bool noteHasExpression(const juce::ValueTree &noteState) noexcept
Returns true if this MidiNote is an expressive note.
BeatPosition getBeatPosition() const noexcept
Returns the beat position relative to the note's start.
static bool noteHasExpression(const juce::ValueTree &noteState, const juce::Identifier &type) noexcept
Returns true if this MidiNote is an expressive note of type.
static bool listHasExpression(const MidiList &midiList) noexcept
Returns true if this MidiList is an expressive note.
MidiExpression(const juce::ValueTree &v)
Creates a MidiExpression interface to an existing MIDI note state.
void setBeatPosition(BeatPosition newBeat, juce::UndoManager *um)
Sets the beat position.
void setValue(float newValue, juce::UndoManager *um)
Sets the value with some range validation.
float getValue() const noexcept
Returns the value of the expression.