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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_PitchSetting.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
14PitchSetting::PitchSetting (Edit& ed, const juce::ValueTree& v)
15 : TrackItem (ed, {}, Type::pitch), state (v)
16{
17 auto um = &ed.getUndoManager();
18
19 startBeat.referTo (state, IDs::startBeat, um);
20 pitch.referTo (state, IDs::pitch, um, 60);
21 accidentalsSharp.referTo (state, IDs::accidentalsSharp, um, true);
22 scale.referTo (state, IDs::scale, um, Scale::major);
23
24 state.addListener (this);
25}
26
27PitchSetting::~PitchSetting()
28{
29 state.removeListener (this);
30
31 notifyListenersOfDeletion();
32}
33
34juce::String PitchSetting::getName() const
35{
36 return juce::MidiMessage::getMidiNoteName (pitch, accidentalsSharp, false,
37 edit.engine.getEngineBehaviour().getMiddleCOctave());
38}
39
40juce::String PitchSetting::getSelectableDescription()
41{
42 return TRANS("Key");
43}
44
45Track* PitchSetting::getTrack() const
46{
47 return edit.getTempoTrack();
48}
49
50ClipPosition PitchSetting::getPosition() const
51{
52 auto& ps = edit.pitchSequence;
53 auto s = edit.tempoSequence.toTime (startBeat);
54
55 if (auto i = ps.indexOfPitch (this); i >= 0)
56 if (auto nextPitch = ps.getPitch (i + 1))
57 return { { s, nextPitch->getPosition().getStart() }, TimeDuration() };
58
59 return { { s, s + TimeDuration::fromSeconds (1.0) }, TimeDuration() };
60}
61
62void PitchSetting::setStartBeat (BeatPosition beat)
63{
64 startBeat = beat;
65 edit.pitchSequence.sortEvents();
66 changed();
67}
68
69void PitchSetting::setPitch (int p)
70{
71 pitch = juce::jlimit (0, 127, p);
72}
73
74void PitchSetting::setScaleID (Scale::ScaleType st)
75{
76 scale = st;
77}
78
79void PitchSetting::removeFromEdit()
80{
81 auto p = state.getParent();
82
83 if (p.getNumChildren() > 1)
84 p.removeChild (state, &edit.getUndoManager());
85}
86
87}} // namespace tracktion { inline namespace engine
static String getMidiNoteName(int noteNumber, bool useSharps, bool includeOctaveNumber, int octaveNumForMiddleC)
Base class for tracks which contain clips and plugins and can be added to Edit[s].
#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 the position of a clip on a timeline.
TimePosition getStart() const
Returns the start time.