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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_ChordClip.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
14ChordClip::ChordClip (const juce::ValueTree& v, EditItemID id, ClipOwner& targetParent)
15 : Clip (v, targetParent, id, Type::chord)
16{
17 if (clipName.get().isEmpty())
18 clipName = TRANS("Chord");
19
20 auto pgen = state.getChildWithName (IDs::PATTERNGENERATOR);
21
22 if (pgen.isValid())
23 {
24 patternGenerator = std::make_unique<PatternGenerator> (*this, pgen);
25
26 if (patternGenerator->getChordProgression().isEmpty())
27 patternGenerator->setChordProgressionFromChordNames ({ "i" });
28 }
29
30 state.addListener (this);
31}
32
33ChordClip::~ChordClip()
34{
35 notifyListenersOfDeletion();
36
37 state.removeListener (this);
38}
39
40void ChordClip::initialise()
41{
42 Clip::initialise();
43
44 speedRatio = 1.0; // not used
45}
46
47juce::String ChordClip::getSelectableDescription()
48{
49 return TRANS("Chord Clip");
50}
51
52juce::Colour ChordClip::getDefaultColour() const
53{
54 return juce::Colours::red.withHue (1.0f / 9.0f);
55}
56
57//==============================================================================
58bool ChordClip::canBeAddedTo (ClipOwner& co)
59{
60 return isChordTrack (co);
61}
62
63void ChordClip::valueTreeChildAdded (juce::ValueTree&, juce::ValueTree& c)
64{
65 if (c.hasType (IDs::PATTERNGENERATOR))
66 {
67 patternGenerator = std::make_unique<PatternGenerator> (*this, c);
68
69 if (patternGenerator->getChordProgression().isEmpty())
70 patternGenerator->setChordProgressionFromChordNames ({ "i" });
71 }
72
73 changed();
74 triggerAsyncUpdate();
75}
76
77void ChordClip::valueTreeChildRemoved (juce::ValueTree& p, juce::ValueTree& c, int)
78{
79 if (p == state && c.hasType (IDs::PATTERNGENERATOR))
80 {
81 patternGenerator = nullptr;
82 }
83 changed();
84 triggerAsyncUpdate();
85}
86
87void ChordClip::valueTreePropertyChanged (juce::ValueTree& v, const juce::Identifier& i)
88{
89 changed();
90 triggerAsyncUpdate();
91
92 Clip::valueTreePropertyChanged (v, i);
93}
94
95void ChordClip::valueTreeParentChanged (juce::ValueTree& v)
96{
97 if (! v.getParent().isValid())
98 edit.sendTempoOrPitchSequenceChangedUpdates();
99
100 Clip::valueTreeParentChanged (v);
101}
102
103PatternGenerator* ChordClip::getPatternGenerator()
104{
105 if (! state.getChildWithName (IDs::PATTERNGENERATOR).isValid())
106 state.addChild (juce::ValueTree (IDs::PATTERNGENERATOR), -1, &edit.getUndoManager());
107
108 jassert (patternGenerator != nullptr);
109 return patternGenerator.get();
110}
111
112void ChordClip::pitchTempoTrackChanged()
113{
114 if (patternGenerator != nullptr)
115 patternGenerator->refreshPatternIfNeeded();
116
117 changed();
118}
119
120juce::Colour ChordClip::getColour() const
121{
122 return Clip::getColour();
123}
124
125void ChordClip::handleAsyncUpdate()
126{
127 edit.sendTempoOrPitchSequenceChangedUpdates();
128}
129
130}} // namespace tracktion { inline namespace engine
Colour withHue(float newHue) const noexcept
bool isValid() const noexcept
Base class for items that can contain clips.
T is_pointer_v
#define TRANS(stringLiteral)
#define jassert(expression)
bool isChordTrack(const Track &t)
Returns true if this is a ChordTrack.