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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_MidiLearn.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
14MidiLearnState::MidiLearnState (Engine& e) : engine (e) {}
15MidiLearnState::~MidiLearnState() {}
16
17void MidiLearnState::setActive (bool shouldBeActive)
18{
20
21 learnActive = shouldBeActive;
22 listeners.call (&Listener::midiLearnStatusChanged, learnActive);
23
24 // Update all the content components so they show the learn tab
25 SelectionManager::refreshAllPropertyPanels();
26}
27
28void MidiLearnState::assignmentChanged (ChangeType t)
29{
30 listeners.call (&Listener::midiLearnAssignmentChanged, t);
31}
32
33MidiLearnState::ScopedChangeCaller::ScopedChangeCaller (MidiLearnState& s, ChangeType t) : state (s), type (t) {}
34MidiLearnState::ScopedChangeCaller::~ScopedChangeCaller() { state.assignmentChanged (type); }
35
36MidiLearnState::Listener::Listener (MidiLearnState& s) : ownerState (s)
37{
38 ownerState.addListener (this);
39}
40
41MidiLearnState::Listener::~Listener()
42{
44 ownerState.removeListener (this);
45}
46
47
48//==============================================================================
49MidiAssignable::MidiAssignable (Engine& e) : engine (e) {}
50
51void MidiAssignable::addAssignent (const Assignment newAssignment)
52{
53 for (auto ass : assignemnts)
54 if (ass.id == newAssignment.id)
55 return;
56
57 assignemnts.add (newAssignment);
58}
59
60void MidiAssignable::buildMenu (juce::PopupMenu& m)
61{
63
64 for (auto ass : assignemnts)
65 {
66 switch (ass.id)
67 {
68 case CustomControlSurface::paramTrackId:
69 case CustomControlSurface::selectClipInTrackId:
70 case CustomControlSurface::selectPluginInTrackId:
71 {
72 if (auto ec = engine.getExternalControllerManager().getActiveCustomController())
73 {
74 juce::PopupMenu paramsMenu;
75 auto numParams = ec->getNumParameterControls();
76
77 auto baseName = ass.id == CustomControlSurface::paramTrackId ? TRANS("Parameter")
78 : TRANS("Track");
79
80 for (int i = 0; i < numParams; ++i)
81 paramsMenu.addItem (CustomControlSurface::paramTrackId + i,
82 baseName + " #" + juce::String (i + 1));
83
84 m.addSubMenu (ass.name, paramsMenu);
85 }
86
87 break;
88 }
89
90 case CustomControlSurface::playId:
91 case CustomControlSurface::stopId:
92 case CustomControlSurface::recordId:
93 case CustomControlSurface::homeId:
94 case CustomControlSurface::endId:
95 case CustomControlSurface::rewindId:
96 case CustomControlSurface::fastForwardId:
97 case CustomControlSurface::markInId:
98 case CustomControlSurface::markOutId:
99 case CustomControlSurface::automationReadId:
100 case CustomControlSurface::automationRecordId:
101 case CustomControlSurface::addMarkerId:
102 case CustomControlSurface::nextMarkerId:
103 case CustomControlSurface::previousMarkerId:
104 case CustomControlSurface::nudgeLeftId:
105 case CustomControlSurface::nudgeRightId:
106 case CustomControlSurface::abortId:
107 case CustomControlSurface::abortRestartId:
108 case CustomControlSurface::jogId:
109 case CustomControlSurface::jumpToMarkInId:
110 case CustomControlSurface::jumpToMarkOutId:
111 case CustomControlSurface::timecodeId:
112 case CustomControlSurface::toggleBeatsSecondsModeId:
113 case CustomControlSurface::toggleLoopId:
114 case CustomControlSurface::togglePunchId:
115 case CustomControlSurface::toggleClickId:
116 case CustomControlSurface::toggleSnapId:
117 case CustomControlSurface::toggleSlaveId:
118 case CustomControlSurface::toggleEtoEId:
119 case CustomControlSurface::toggleScrollId:
120 case CustomControlSurface::toggleAllArmId:
121 case CustomControlSurface::masterVolumeId:
122 case CustomControlSurface::masterVolumeTextId:
123 case CustomControlSurface::masterPanId:
124 case CustomControlSurface::quickParamId:
125 case CustomControlSurface::paramNameTrackId:
126 case CustomControlSurface::paramTextTrackId:
127 case CustomControlSurface::clearAllSoloId:
128 case CustomControlSurface::nameTrackId:
129 case CustomControlSurface::numberTrackId:
130 case CustomControlSurface::volTrackId:
131 case CustomControlSurface::volTextTrackId:
132 case CustomControlSurface::panTrackId:
133 case CustomControlSurface::panTextTrackId:
134 case CustomControlSurface::muteTrackId:
135 case CustomControlSurface::soloTrackId:
136 case CustomControlSurface::armTrackId:
137 case CustomControlSurface::selectTrackId:
138 case CustomControlSurface::auxTrackId:
139 case CustomControlSurface::auxTextTrackId:
140 case CustomControlSurface::zoomInId:
141 case CustomControlSurface::zoomOutId:
142 case CustomControlSurface::scrollTracksUpId:
143 case CustomControlSurface::scrollTracksDownId:
144 case CustomControlSurface::scrollTracksLeftId:
145 case CustomControlSurface::scrollTracksRightId:
146 case CustomControlSurface::zoomTracksInId:
147 case CustomControlSurface::zoomTracksOutId:
148 case CustomControlSurface::toggleSelectionModeId:
149 case CustomControlSurface::selectLeftId:
150 case CustomControlSurface::selectRightId:
151 case CustomControlSurface::selectUpId:
152 case CustomControlSurface::selectDownId:
153 case CustomControlSurface::selectedPluginNameId:
154 case CustomControlSurface::faderBankLeftId:
155 case CustomControlSurface::faderBankLeft1Id:
156 case CustomControlSurface::faderBankLeft4Id:
157 case CustomControlSurface::faderBankLeft8Id:
158 case CustomControlSurface::faderBankLeft16Id:
159 case CustomControlSurface::faderBankRightId:
160 case CustomControlSurface::faderBankRight1Id:
161 case CustomControlSurface::faderBankRight4Id:
162 case CustomControlSurface::faderBankRight8Id:
163 case CustomControlSurface::faderBankRight16Id:
164 case CustomControlSurface::paramBankLeftId:
165 case CustomControlSurface::paramBankLeft1Id:
166 case CustomControlSurface::paramBankLeft4Id:
167 case CustomControlSurface::paramBankLeft8Id:
168 case CustomControlSurface::paramBankLeft16Id:
169 case CustomControlSurface::paramBankLeft24Id:
170 case CustomControlSurface::paramBankRightId:
171 case CustomControlSurface::paramBankRight1Id:
172 case CustomControlSurface::paramBankRight4Id:
173 case CustomControlSurface::paramBankRight8Id:
174 case CustomControlSurface::paramBankRight16Id:
175 case CustomControlSurface::paramBankRight24Id:
176 case CustomControlSurface::userAction1Id:
177 case CustomControlSurface::userAction2Id:
178 case CustomControlSurface::userAction3Id:
179 case CustomControlSurface::userAction4Id:
180 case CustomControlSurface::userAction5Id:
181 case CustomControlSurface::userAction6Id:
182 case CustomControlSurface::userAction7Id:
183 case CustomControlSurface::userAction8Id:
184 case CustomControlSurface::userAction9Id:
185 case CustomControlSurface::userAction10Id:
186 case CustomControlSurface::userAction11Id:
187 case CustomControlSurface::userAction12Id:
188 case CustomControlSurface::userAction13Id:
189 case CustomControlSurface::userAction14Id:
190 case CustomControlSurface::userAction15Id:
191 case CustomControlSurface::userAction16Id:
192 case CustomControlSurface::userAction17Id:
193 case CustomControlSurface::userAction18Id:
194 case CustomControlSurface::userAction19Id:
195 case CustomControlSurface::userAction20Id:
196 case CustomControlSurface::emptyTextId:
197 case CustomControlSurface::clip1TrackId:
198 case CustomControlSurface::clip2TrackId:
199 case CustomControlSurface::clip3TrackId:
200 case CustomControlSurface::clip4TrackId:
201 case CustomControlSurface::clip5TrackId:
202 case CustomControlSurface::clip6TrackId:
203 case CustomControlSurface::clip7TrackId:
204 case CustomControlSurface::clip8TrackId:
205 case CustomControlSurface::stopClipsTrackId:
206 case CustomControlSurface::sceneId:
207 case CustomControlSurface::clipBankUp1Id:
208 case CustomControlSurface::clipBankUp4Id:
209 case CustomControlSurface::clipBankUp8Id:
210 case CustomControlSurface::clipBankDown1Id:
211 case CustomControlSurface::clipBankDown4Id:
212 case CustomControlSurface::clipBankDown8Id:
213 case CustomControlSurface::marker1Id:
214 case CustomControlSurface::marker2Id:
215 case CustomControlSurface::marker3Id:
216 case CustomControlSurface::marker4Id:
217 case CustomControlSurface::marker5Id:
218 case CustomControlSurface::marker6Id:
219 case CustomControlSurface::marker7Id:
220 case CustomControlSurface::marker8Id:
221 case CustomControlSurface::none:
222 default:
223 {
224 int faderIndex = 0;
225
226 if (getControlledTrack() != nullptr)
227 faderIndex = getFaderIndex();
228
229 m.addItem (ass.id + faderIndex, ass.name);
230 break;
231 }
232 }
233 }
234}
235
236void MidiAssignable::handleMenuResult (int menuResult)
237{
239
240 if (! engine.getMidiLearnState().isActive())
241 return;
242
243 if (auto edit = engine.getUIBehaviour().getCurrentlyFocusedEdit())
244 if (menuResult > 0)
245 edit->getParameterChangeHandler().actionFunctionTriggered (menuResult);
246}
247
248int MidiAssignable::getFaderIndex()
249{
251
252 if (auto t = getControlledTrack())
253 {
254 auto& ecm = engine.getExternalControllerManager();
255
256 if (auto ec = ecm.getActiveCustomController())
257 return ec->getFaderIndexInActiveRegion (ecm.mapTrackNumToChannelNum (t->getIndexInEditTrackList()));
258 }
259
260 return -1;
261}
262
263}} // namespace tracktion { inline namespace engine
void addItem(Item newItem)
#define TRANS(stringLiteral)
#define CRASH_TRACER
This macro adds the current location to a stack which gets logged if a crash happens.