-
Notifications
You must be signed in to change notification settings - Fork 1
/
launchkey 61.control.js
344 lines (303 loc) · 9.4 KB
/
launchkey 61.control.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
334
335
336
337
338
339
340
341
342
// Controller Script for Launchkey series in Biwig Studio
// Copyright (C) 2015 SAILLANT
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
loadAPI(1);
host.defineController("Novation", "Launchkey 61", "1.0", "45108550-9E02-11E2-9E96-D0AA527BA73B");
host.defineMidiPorts(2, 2);
host.addDeviceNameBasedDiscoveryPair(["Launchkey 61", "MIDIIN2 (Launchkey 61)"], ["Launchkey 61", "MIDIOUT2 (Launchkey 61)"]);
host.addDeviceNameBasedDiscoveryPair(["Launchkey 61 MIDI 1", "Launchkey 61 MIDI 2"], ["Launchkey 61 MIDI 1", "Launchkey 61 MIDI 2"]);
load("launchkey_common.js");
function init()
{
host.getMidiInPort(0).createNoteInput("Launchkey 49", "80????", "90????", "B001??", "D0????", "E0????");
host.getMidiInPort(0).createNoteInput("Launchkey Pads", "89????", "99????");
host.getMidiInPort(0).setMidiCallback(onMidi0);
host.getMidiInPort(1).setMidiCallback(onMidi1);
transport = host.createTransportSection();
cursorTrack = host.createCursorTrackSection(0, 8);
masterTrack = host.createMasterTrackSection(0);
primaryDevice = cursorTrack.getPrimaryDevice();
primaryDevice.addSelectedPageObserver(-1, function(value)
{
selectedPage = value;
});
primaryDevice.addPageNamesObserver(function()
{
numParameterPages = arguments.length;
});
trackBank = host.createTrackBank(8, 8, 1);
trackBank.addCanScrollScenesUpObserver( canScrollScenesUpOb );
trackBank.addCanScrollScenesDownObserver( canScrollScenesDownOb );
for( var t = 0; t < 8; t++ )
{
var track = trackBank.getTrack( t );
var clipLauncher = track.getClipLauncherSlots();
clipLauncher.addHasContentObserver (getClipObserverFunc( t, 1 ) );
clipLauncher.addIsPlayingObserver( getClipObserverFunc( t, 2 ) );
clipLauncher.addIsRecordingObserver( getClipObserverFunc( t, 3 ) );
clipLauncher.addIsPlaybackQueuedObserver( getClipObserverFunc( t, 4 ) );
clipLauncher.setIndication( true );
}
//trackBank.addCanScrollTracksUpObserver( function A(x){return getCanScrollChannelsUp(x)});
//trackBank.addCanScrollTracksDownObserver(function B(x){return getCanScrollChannelsDown(x)});
for(var p=0; p<8; p++)
{
var modSource = primaryDevice.getModulationSource(p);
modSource.addIsMappingObserver(modSourceStates.setter(p));
}
userControls = host.createUserControlsSection(8);
for(var p=0; p<8; p++)
{
userControls.getControl(p).setLabel("User " + (p + 1));
}
sendMidi(0x90, 0x0C, 0x7F);
host.getMidiOutPort(1).sendMidi(0x90, 0x0C, 0x7F);
updateIndications();
host.scheduleTask(blinkTimer, null, 100);
}
var fastblink = false;
var blink = false;
function blinkTimer()
{
fastblink = !fastblink;
if (fastblink)
{
blink = !blink;
}
host.scheduleTask(blinkTimer, null, 100);
}
function updateIndications()
{
for(var i=0; i<8; i++)
{
primaryDevice.getParameter(i).setIndication(incontrol_knobs);
userControls.getControl(i).setIndication(!incontrol_knobs);
primaryDevice.getMacro(i).getAmount().setIndication(incontrol_mix);
trackBank.getTrack(i).getVolume().setIndication(!incontrol_mix);
}
}
function exit()
{
sendMidi(0x90, 0x0C, 0x00);
}
function flush()
{
updateOutputState();
flushOutputState();
}
function onMidi0(status, data1, data2)
{
//printMidi(status, data1, data2);
if (isChannelController(status))
{
if (data1 >= 21 && data1 <= 28)
{
var knobIndex = data1 - 21;
userControls.getControl(knobIndex).set(data2, 128);
}
else if (data1 >= 41 && data1 <= 48)
{
var sliderIndex = data1 - 41;
trackBank.getTrack(sliderIndex).getVolume().set(data2, 128);
}
else if (data1 == 7)
{
masterTrack.getVolume().set(data2, 128);
}
else if (data1 >= 51 && data1 <= 58)
{
var buttonIndex = data1 - 51;
if (data2 == 127)
{
trackBank.getTrack(buttonIndex).select();
}
}
if(data2==127 && data1==59)
{
control_launcher = !control_launcher;
host.getMidiOutPort(1).sendMidi(0xB0, 59, 127*control_launcher);
}
}
}
var incontrol_mix = true;
var incontrol_knobs = true;
var incontrol_pads = true;
var control_launcher = false;
function onMidi1(status, data1, data2)
{
//printMidi(status, data1, data2);
if (isChannelController(status))
{
if (data1 >= 21 && data1 <= 28)
{
var knobIndex = data1 - 21;
primaryDevice.getParameter(knobIndex).set(data2, 128);
}
else if (data1 >= 41 && data1 <= 48)
{
var sliderIndex = data1 - 41;
primaryDevice.getMacro(sliderIndex).getAmount().set(data2, 128);
}
else if (data1 == 7)
{
cursorTrack.getVolume().set(data2, 128);
}
else if (data1 >= 51 && data1 <= 59)
{
var buttonIndex = data1 - 51;
if (data2 == 127 && buttonIndex<=7)
{
primaryDevice.getMacro(buttonIndex).getModulationSource().toggleIsMapping();
}
else if(data2==127 && buttonIndex==8)
{
control_launcher = !control_launcher;
host.getMidiOutPort(1).sendMidi(0xB0, 59, 127*control_launcher);
}
}
if (data2 == 127)
{
// button presses
if (data1 == 102)
{
if (!incontrol_knobs && !control_launcher)
{
trackBank.scrollTracksPageUp();
}
else
{
cursorTrack.selectPrevious();
}
}
else if (data1 == 103)
{
if (!incontrol_knobs && !control_launcher)
{
trackBank.scrollTracksPageDown();
}
else
{
cursorTrack.selectNext();
}
}
else if (data1 == 112 && !control_launcher)
{
transport.rewind();
}
else if (data1 == 112 && control_launcher)
{
trackBank.scrollScenesUp();
if(canScrollUp){cursorScene--;}
}
else if (data1 == 113 && !control_launcher)
{
transport.fastForward();
}
else if (data1 == 113 && control_launcher)
{
trackBank.scrollScenesDown();
if(canScrollDown){cursorScene++;}
}
else if (data1 == 114)
{
transport.stop();
}
else if (data1 == 115)
{
transport.play();
}
else if (data1 == 116)
{
transport.toggleLoop();
}
else if (data1 == 117)
{
transport.record();
}
}
}
if (MIDIChannel(status) == 0 && isNoteOn(status))
{
if (data1 >= 96 && data1 < 104 && !control_launcher)
{
var i = data1 - 96;
primaryDevice.setParameterPage(i);
}
else if (data1 >= 112 && data1 < 120 && !control_launcher)
{
var i = data1 - 112;
primaryDevice.getModulationSource(i).toggleIsMapping();
}
else if (data1 == 104 && !control_launcher)
{
primaryDevice.switchToPreviousPreset();
}
else if (data1 == 120 && !control_launcher)
{
primaryDevice.switchToNextPreset();
}
else if (data1 >= 96 && data1 < 104 && control_launcher)
{
slot=data1-96;
track=trackBank.getTrack(slot);
Clips=track.getClipLauncherSlots();
if(clipIsPlaiyng[slot])
{
Clips.stop()
}
else if(clipHasContent[slot])
{
Clips.launch(0);
}
else
{
track.getClipLauncher().record(0);
}
}
else if (data1 >= 112 && data1 < 120 && control_launcher)
{
selected_scene=data1-112;
trackBank.scrollToScene(selected_scene);
cursorScene=selected_scene;
}
else if (data1 == 104 && control_launcher)
{
trackBank.launchScene(0)
}
else if (data1 == 120 && control_launcher)
{
trackBank.getClipLauncherScenes().stop()
}
if (data1 == 13)
{
incontrol_knobs = data2 == 127;
host.showPopupNotification(incontrol_knobs ? "Knobs: Parameters" : "Knobs: User Mappings");
updateIndications();
}
else if (data1 == 14)
{
incontrol_mix = data2 == 127;
host.showPopupNotification(incontrol_mix ? "Sliders: Macros" : "Sliders: Mixer");
updateIndications();
}
else if (data1 == 15)
{
incontrol_pads = data2 == 127;
if (!control_launcher){host.showPopupNotification(incontrol_pads ? "Parameter Page & Modulation" : "Drum Pads");}
else {host.showPopupNotification(incontrol_pads ? "Launcher" : "Drum Pads");}
updateIndications();
}
}
}