-
Notifications
You must be signed in to change notification settings - Fork 4
/
MPK49.control.js
223 lines (212 loc) · 6.49 KB
/
MPK49.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
//////////////////////////////////////////////////////
//// encoders can send nrpn, but it's broken. on fast movements, an encoder sends less data,
//// which means, much less and delayed change of parameter values in the app.
//// only works like expected when moving encoders very slowly
//// -> check nrpn behaviour on apc40
/////////////////////////////////////////////////////////////////////////////////////////////////////
loadAPI(1);
host.defineController("Akai", "MPK49", "1.0", "B8A86DCE-F608-4A49-8CA1-789A87C2F765");
host.defineSysexIdentityReply("F0 7E 00 06 02 47 6B 00 19 00 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? F7");
host.defineMidiPorts(1, 1);
// //////////////// Bank A/B/C: channel0/1/2 (status 176/177/178)
var CC =
{
REW : 115,
FF : 116,
STOP : 117,
PLAY : 118,
REC : 119,
K1 : 22, // encoders
F1 : 12, // sliders
S1 : 32, // buttons /
S2 : 33,
S3 : 34,
S4 : 35,
S5 : 36,
S6 : 37,
S7 : 38,
S8 : 39
// ////////////
};
var isShift = false;
var isPlay = false;
// //////////////////////////////////////////////////////
function init()
{
host.getMidiInPort(0).createNoteInput("MPK49 Keyboard", "80????", "90????", "B001??", "B040??", "D0????", "E0????");
host.getMidiInPort(0).createNoteInput("MPK49 Pads", "81????", "91????", "D1????");
host.getMidiInPort(0).setMidiCallback(onMidi);
// /////////////////////////////////////////////////// sections
transport = host.createTransportSection();
application = host.createApplicationSection();
trackBank = host.createTrackBankSection(8, 2, 0);
cursorTrack = host.createCursorTrackSection(2, 0);
cursorDevice = host.createCursorDeviceSection(8);
primaryInstrument = cursorTrack.getPrimaryInstrument();
transport.addIsPlayingObserver(function(on)
{
isPlay = on;
});
for ( var p = 0; p < 8; p++)
{
var macro = primaryInstrument.getMacro(p).getAmount();
var parameter = cursorDevice.getParameter(p);
var track = trackBank.getTrack(p);
macro.setIndication(true);
parameter.setIndication(true);
parameter.setLabel("P" + (p + 1));
track.getVolume().setIndication(true);
track.getPan().setIndication(true);
track.getSend(0).setIndication(true);
track.getSend(1).setIndication(true);
}
}
function exit()
{
}
function onMidi(status, data1, data2)
{
var index = data1;
var val = data2;
var buttonPressed = val > 0;
// printMidi(status, index, val);
if (index == CC.S1)
{
isShift = val > 0;
}
if (buttonPressed)
{
if (status == 176) // Control Bank A
{
switch (index)
{
case CC.S2:
isShift ? cursorTrack.selectPrevious() : cursorTrack.selectNext();
break;
case CC.S3:
isShift ? cursorDevice.previousParameterPage() : cursorDevice.nextParameterPage();
break;
case CC.S4:
cursorDevice.switchToPreviousPreset();
break;
case CC.S5:
cursorDevice.switchToNextPreset();
break;
case CC.S6:
isShift ? cursorDevice.switchToPreviousPresetCategory() : cursorDevice.switchToNextPresetCategory();
break;
case CC.S7:
isShift ? cursorDevice.switchToPreviousPresetCreator() : cursorDevice.switchToNextPresetCreator();
break;
case CC.S8:
application.nextPerspective();// planned to switch mode / page
break;
}
}
else if (status == 177) // Control Bank B
{
switch (index)
{
case CC.S2:
isShift ? cursorTrack.selectPrevious() : cursorTrack.selectNext();
break;
case CC.S3:
isShift ? trackBank.scrollTracksPageDown() : trackBank.scrollTracksPageUp();
break;
case CC.S4:
cursorDevice.switchToPreviousPreset();
break;
case CC.S5:
cursorDevice.switchToNextPreset();
break;
case CC.S6:
isShift ? cursorDevice.switchToPreviousPresetCategory() : cursorDevice.switchToNextPresetCategory();
break;
case CC.S7:
isShift ? cursorDevice.switchToPreviousPresetCreator() : cursorDevice.switchToNextPresetCreator();
break;
case CC.S8:
application.nextPerspective();// planned to switch mode / page
break;
}
}
else if (status == 178) // Control Bank C
{
switch (index)
{
case CC.S2:
isShift ? cursorTrack.selectPrevious() : cursorTrack.selectNext();
break;
case CC.S3:
isShift ? trackBank.scrollTracksPageDown() : trackBank.scrollTracksPageUp();
break;
case CC.S4:
cursorDevice.switchToPreviousPreset();
break;
case CC.S5:
cursorDevice.switchToNextPreset();
break;
case CC.S6:
isShift ? cursorDevice.switchToPreviousPresetCategory() : cursorDevice.switchToNextPresetCategory();
break;
case CC.S7:
isShift ? cursorDevice.switchToPreviousPresetCreator() : cursorDevice.switchToNextPresetCreator();
break;
case CC.S8:
application.nextPerspective();// planned to switch mode / page
break;
}
}
switch (index)
{
case CC.PLAY:
isShift ? transport.returnToArrangerment() : isPlay ? transport.restart() : transport.play();
break;
case CC.STOP:
isShift ? transport.resetAutomationOverrides() : transport.stop();
break;
case CC.REC:
isShift ? cursorTrack.getArm().toggle() : transport.record();
break;
case CC.REW:
isShift ? cursorTrack.selectPrevious() : transport.rewind();
break;
case CC.FF:
isShift ? cursorTrack.selectNext() : transport.fastForward();
break;
}
}
if (status == 176) // Control Bank A
{
if (index >= CC.K1 && index < CC.K1 + 8)
{
isShift ? primaryInstrument.getMacro(index - CC.K1).getAmount().reset() : primaryInstrument.getMacro(index - CC.K1).getAmount().set(val, 128);
}
else if (index >= CC.F1 && index < CC.F1 + 8)
{
isShift ? cursorDevice.getParameter(index - CC.F1).reset() : cursorDevice.getParameter(index - CC.F1).set(val, 128);
}
}
else if (status == 177) // Control Bank B
{
if (index >= CC.K1 && index < CC.K1 + 8)
{
isShift ? trackBank.getTrack(index - CC.K1).getPan().reset() : trackBank.getTrack(index - CC.K1).getPan().set(val, 128);
}
else if (index >= CC.F1 && index < CC.F1 + 8)
{
isShift ? trackBank.getTrack(index - CC.F1).getVolume().reset() : trackBank.getTrack(index - CC.F1).getVolume().set(val, 128);
}
}
else if (status == 178) // Control Bank C
{
if (index >= CC.K1 && index < CC.K1 + 8)
{
isShift ? trackBank.getTrack(index - CC.K1).getSend(1).reset() : trackBank.getTrack(index - CC.K1).getSend(1).set(val, 128);
}
else if (index >= CC.F1 && index < CC.F1 + 8)
{
isShift ? trackBank.getTrack(index - CC.F1).getSend(0).reset() : trackBank.getTrack(index - CC.F1).getSend(0).set(val, 128);
}
}
}