-
Notifications
You must be signed in to change notification settings - Fork 2
/
SteinbergCC121.device.js
executable file
·127 lines (117 loc) · 4.08 KB
/
SteinbergCC121.device.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
// Current collection of devices in a channel
var deviceBank;
// Current collection of parameters in a device
var parameterBank;
// Factor to speed up scrolling by with job button
var JOGFACTOR_PARAMETER = 4;
// Device buttons "LOW", "LOW MID", "HIGH MID" and "HIGH"
var LOW_LOCKED = 0;
var LOWMID_LOCKED = 0;
var HIGHMID_LOCKED = 0;
var HIGH_LOCKED = 0;
function initDevice() {
// Creating views
arrangerCursorDevice = host.createEditorCursorDevice();
arrangerCursorDevice.isEnabled().addValueObserver(function (deviceEnabled) {
if (deviceEnabled) {
sendMidi(144, NOTE.ALLBYPASS, LIGHT_ON);
} else {
sendMidi(144, NOTE.ALLBYPASS, LIGHT_OFF);
}
});
arrangerCursorDevice.exists().markInterested();
deviceBank = arrangerCursorDevice.deviceChain().createDeviceBank(1);
parameterBank = arrangerCursorDevice.createCursorRemoteControlsPage(8);
return onMidiDevice;
}
function onMidiDevice(status, data1, data2) {
// Check if message is MIDI CC from AI knob
if (isChannelController(status)) {
var changeValue = midiCcValueToInteger(data2)
if (isJogActive)
changeValue = JOGFACTOR_PARAMETER * changeValue;
var parameterNumber;
switch (data1) {
case CC.EQQ1:
parameterBank.selectedPageIndex().set(0);
parameterNumber = 0;
break;
case CC.EQQ2:
parameterBank.selectedPageIndex().set(0);
parameterNumber = 1;
break;
case CC.EQQ3:
parameterBank.selectedPageIndex().set(0);
parameterNumber = 2;
break;
case CC.EQQ4:
parameterBank.selectedPageIndex().set(0);
parameterNumber = 3;
break;
case CC.EQFREQUENCY1:
parameterBank.selectedPageIndex().set(0);
parameterNumber = 4;
break;
case CC.EQFREQUENCY2:
parameterBank.selectedPageIndex().set(0);
parameterNumber = 5;
break;
case CC.EQFREQUENCY3:
parameterBank.selectedPageIndex().set(0);
parameterNumber = 6;
break;
case CC.EQFREQUENCY4:
parameterBank.selectedPageIndex().set(0);
parameterNumber = 7;
break;
case CC.EQGAIN1:
parameterBank.selectedPageIndex().set(1);
parameterNumber = 0;
break;
case CC.EQGAIN2:
parameterBank.selectedPageIndex().set(1);
parameterNumber = 1;
break;
case CC.EQGAIN3:
parameterBank.selectedPageIndex().set(1);
parameterNumber = 2;
break;
case CC.EQGAIN4:
parameterBank.selectedPageIndex().set(1);
parameterNumber = 3;
break;
default:
return;
}
parameterBank.getParameter(parameterNumber).inc(changeValue, ENCODER_RESOLUTION);
} else if (isNoteOn(status) && data2 > 0) {
switch (data1) {
case NOTE.REWIND:
arrangerCursorDevice.selectPrevious();
break;
case NOTE.FORWARD:
arrangerCursorDevice.selectNext();
break;
case NOTE.ALLBYPASS:
arrangerCursorDevice.isEnabled().toggle();
break;
case NOTE.EQTYPE:
if (!arrangerCursorDevice.exists().get()) {
deviceBank.browseToInsertDevice(0);
} else if (arrangerCursorDevice.isEnabled().get()) {
arrangerCursorDevice.browseToInsertAfterDevice();
} else {
arrangerCursorDevice.browseToReplaceDevice();
}
break;
}
}
}
function toggleMidiCCValue(value) {
// Flipping 0 <-> 127
if (value <= 63) {
return 127;
} else {
return 0;
}
}