-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSliderModeHandler.js
333 lines (299 loc) · 11.4 KB
/
SliderModeHandler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
/**
* General Handler for Controlling the modes of the Touchstrips
*
* @param {TrackBankContainer} mixerTrackBank
* @param {TrackBankContainer} effectTrackBank
* @param {int} numTracks
* @param {ClipLaunchView} clipview
* @param {Device} cursorDevice
* @param {TrackHandler} trackHandler
*/
function SliderModeHandler(mixerTrackBank, effectTrackBank, numTracks, cursorDevice, trackHandler) {
var levelButton = controls.createButton(ENCODERBUTTON.LEVEL);
var auxButton = controls.createButton(ENCODERBUTTON.AUX);
var deviceButton = controls.createButton(ENCODERBUTTON.CONTROL);
var macrcoButton = controls.createButton(ENCODERBUTTON.MACRO);
var deviceControl = new DeviceSliderControl(cursorDevice, trackHandler);
var mixerControl = new MixerSliderControl("mixer", mixerTrackBank, host.createEffectTrackBank(8, 8));
var efxControl = new MixerSliderControl("effect", effectTrackBank);
var sliderView = new SliderView(numTracks);
transport.setParameterControl(deviceControl);
var masterMode = mixerControl;
var currentMode = mixerControl;
var controlMode = ControlModes.VOLUME;
mixerControl.setDisplay(sliderView);
currentMode.setMode(controlMode);
/**
* Make Select the Touch Strip Slider Mode Butto according to current mode
**/
function radioModes() {
levelButton.sendValue(controlMode === ControlModes.VOLUME || controlMode === ControlModes.PAN ? 127 : 0);
auxButton.sendValue(controlMode === ControlModes.AUX ? 127 : 0);
deviceButton.sendValue(controlMode === ControlModes.DEVICE || controlMode === ControlModes.MIDI_CC ? 127 : 0);
macrcoButton.sendValue(controlMode === ControlModes.MACRO ? 127 : 0);
}
radioModes();
this.updateTrackColor = function (color) {
deviceControl.updateTrackColor(color);
};
this.switchToEffectMode = function () {
if (masterMode === efxControl) {
return;
}
masterMode = efxControl;
if (currentMode.isMixer()) {
currentMode.setDisplay(null);
currentMode = efxControl;
currentMode.setDisplay(sliderView);
if (controlMode === ControlModes.AUX) {
controlMode = ControlModes.VOLUME;
currentMode.setMode(controlMode);
radioModes();
}
refreshMixerMode();
}
};
this.inEffectMode = function () {
return masterMode !== mixerControl;
};
this.switchToTrackMode = function () {
if (masterMode === mixerControl) {
return;
}
masterMode = mixerControl;
if (currentMode.isMixer()) {
currentMode.setDisplay(null);
currentMode = mixerControl;
currentMode.setDisplay(sliderView);
refreshMixerMode();
}
};
function getOffset(slider, value) {
var offset = 0;
if (slider.touched) {
slider.touched = false;
slider.downValue = value;
} else {
var diff = (value - slider.downValue);
// Diff needs to be greater than 1 to adjust value in smaller increments
if (Math.abs(diff) > 1) {
offset = diff > 0 ? 1 : -1;
slider.downValue = value;
}
}
return offset;
}
function changeCCValue(value, slider, index) {
noteInput.sendRawMidiEvent(0xB0, 45 + index, value);
}
function changeDeviceValue(value, slider, index) {
var offset = getOffset(slider, value);
if (modifiers.isShiftDown()) {
if (offset === 0)
return;
} else {
currentMode.setDeviceValue(index, value);
}
}
function changeMacroValue(value, slider, index) {
var offset = getOffset(slider, value);
if (modifiers.isShiftDown()) {
if (offset === 0)
return;
currentMode.setMacroValue(index, currentMode.getMacroValue(index) + offset);
} else {
currentMode.setMacroValue(index, value);
}
}
function changeMacroTouchValue(index, value) {
currentMode.setMacroTouchValue(index, value);
}
function changeSendLevel(value, slider, index) {
var offset = getOffset(slider, value);
if (modifiers.isShiftDown()) {
if (offset === 0)
return;
currentMode.setSendLevel(index, currentMode.getSendValue(index) + offset);
} else {
currentMode.setSendLevel(index, value);
}
}
function handleSliderTouch(index, value) {
if (value === 0) {
var trackValues = currentMode.values();
currentMode.cleanUpView(index, trackValues[index].volume);
}
}
function changeMixerLevels(value, slider, index) {
var offset = getOffset(slider, value);
var trackValues = currentMode.values();
if (modifiers.isShiftDown()) {
if (offset === 0)
return;
currentMode.setVolume(index, trackValues[index].volume + offset);
} else {
currentMode.setVolume(index, value);
}
}
function changePan(value, slider, index) {
var offset = getOffset(slider, value);
var trackValues = currentMode.values();
if (modifiers.isShiftDown()) {
if (offset === 0)
return;
currentMode.setPan(index, trackValues[index].pan + offset);
} else {
currentMode.setPan(index, value);
}
}
sliderView.assignSliderCallback(changeMixerLevels, handleSliderTouch);
masterMode.setSendsToZeroListener(function () {
setToVolumeMode();
});
function setToVolumeMode(showNotification) {
switchToMixerMode(ControlModes.VOLUME);
controlMode = ControlModes.VOLUME;
currentMode.setMode(controlMode);
barmode = BarModes.DUAL;
sliderView.assignSliderCallback(changeMixerLevels, handleSliderTouch);
var trackValues = currentMode.values();
sliderView.setStripValues(BarModes.DUAL, currentMode.getVolume, trackValues);
radioModes();
if (showNotification) {
host.showPopupNotification("Touchstrip controls Volume");
}
}
function setToPanMode(showNotification) {
switchToMixerMode(ControlModes.PAN);
controlMode = ControlModes.PAN;
sliderView.assignSliderCallback(changePan);
sliderView.setStripValues(BarModes.PAN, currentMode.getPan, currentMode.values());
radioModes();
if (showNotification) {
host.showPopupNotification("Touchstrip controls Panning");
}
}
function refreshMixerMode() {
switch (controlMode) {
case ControlModes.VOLUME:
setToVolumeMode(true);
break;
case ControlModes.PAN:
setToPanMode(true);
break;
case ControlModes.AUX:
setToAuxMode(true);
break;
}
}
function setToAuxMode(showNotification) {
switchToMixerMode(ControlModes.AUX);
controlMode = ControlModes.AUX;
sliderView.assignSliderCallback(changeSendLevel);
sliderView.setStripValues(BarModes.DOT, currentMode.getSendValue, currentMode.values());
radioModes();
currentMode.showSendIndex();
}
function switchToMixerMode(newMode) {
if (!currentMode.isMixer()) {
currentMode.setDisplay(null);
currentMode.setMode(newMode);
currentMode = masterMode;
currentMode.setDisplay(sliderView);
}
currentMode.setMode(newMode);
}
function switchToDeviceMode(newMode) {
if (currentMode.isMixer()) {
currentMode.setDisplay(null);
currentMode.setMode(newMode);
currentMode = deviceControl;
currentMode.setDisplay(sliderView);
}
currentMode.setMode(newMode);
}
levelButton.setCallback(function (value) {
if (value === 0) {
return;
}
if (modifiers.isShiftDown()) {
if (controlMode !== ControlModes.PAN) {
setToPanMode();
}
} else {
if (controlMode !== ControlModes.VOLUME) {
setToVolumeMode();
}
}
});
auxButton.setCallback(function (value) {
if (value === 0 || masterMode.numberOfSends() === 0) {
return;
}
if (controlMode !== ControlModes.AUX) {
setToAuxMode();
} else {
currentMode.incrementSendIndex();
}
});
deviceButton.setCallback(function (value) {
transport.notifyModButton(ENCODERBUTTON.CONTROL, value > 0);
if (value === 0) {
return;
}
if (modifiers.isShiftDown()) {
if (controlMode !== ControlModes.MIDI_CC) {
switchToDeviceMode(ControlModes.MIDI_CC);
controlMode = ControlModes.MIDI_CC;
sliderView.assignSliderCallback(changeCCValue);
sliderView.refresh();
currentMode.updateSliders();
radioModes();
host.showPopupNotification("Touchstrip controls Midi CC");
}
return;
} else if (controlMode !== ControlModes.DEVICE) {
if (!deviceControl.hasDevice()) {
return;
}
switchToDeviceMode(ControlModes.DEVICE);
controlMode = ControlModes.DEVICE;
sliderView.assignSliderCallback(changeDeviceValue);
sliderView.refresh();
currentMode.updateSliders();
radioModes();
cursorDevice.selectInEditor();
if (modifiers.isSelectDown()) {
cursorDevice.isWindowOpen().toggle();
}
host.showPopupNotification("Touchstrip controls Device");
} else if (modifiers.isSelectDown()) {
cursorDevice.isWindowOpen().toggle();
} else if (modifiers.isClearDown()){
host.showPopupNotification("TODO clear device ... mit enter ?");
applicationControl.focusDevicePanel();
cursorDevice.selectInEditor();
applicationControl.getApplication().remove();
}
currentMode.showParamAssignments();
});
macrcoButton.setCallback(function (value) {
transport.notifyModButton(ENCODERBUTTON.MACRO, value > 0);
if (value === 0) {
return;
}
if (controlMode !== ControlModes.MACRO) {
switchToDeviceMode(ControlModes.MACRO);
controlMode = ControlModes.MACRO;
sliderView.assignSliderCallback(changeMacroValue, changeMacroTouchValue);
sliderView.refresh();
currentMode.updateSliders();
radioModes();
applicationControl.showDevices();
host.showPopupNotification("Touchstrip controls Macros");
}
});
this.exit = function () {
host.getMidiOutPort(0).sendSysex("f000210915004d5000010500000000000000000000000000000000f7");
};
}