-
Notifications
You must be signed in to change notification settings - Fork 2
/
SteinbergCC121.channel.js
executable file
·124 lines (114 loc) · 4.13 KB
/
SteinbergCC121.channel.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
// Factor to speed up panning by with job button
var JOGFACTOR_PANNING = 4;
function initChannel() {
// Creating views
trackBank = host.createTrackBank(1, 0, 0, true);
cursorTrack = host.createCursorTrack("CC121_TRACK", "Cursor Track", 1, 1, true);
trackBank.followCursorTrack(cursorTrack);
transport = host.createTransport();
application = host.createApplication();
// Publishing observers
trackBank.getChannel(0).mute().addValueObserver(function (isMuted) {
if (isMuted) {
sendMidi(144, NOTE.MUTE, LIGHT_ON);
} else {
sendMidi(144, NOTE.MUTE, LIGHT_OFF);
}
});
trackBank.getChannel(0).solo().addValueObserver(function (isSolo) {
if (isSolo) {
sendMidi(144, NOTE.SOLO, LIGHT_ON);
} else {
sendMidi(144, NOTE.SOLO, LIGHT_OFF);
}
});
transport.isArrangerAutomationWriteEnabled().addValueObserver(function (isAutomationWrite) {
if (isAutomationWrite) {
sendMidi(144, NOTE.AUTOMATIONWRITE, LIGHT_ON);
} else {
sendMidi(144, NOTE.AUTOMATIONWRITE, LIGHT_OFF);
}
});
trackBank.getTrack(0).arm().addValueObserver(function (isArmed) {
if (isArmed) {
sendMidi(144, NOTE.RECORDARM, LIGHT_ON);
} else {
sendMidi(144, NOTE.RECORDARM, LIGHT_OFF);
}
});
trackBank.getTrack(0).monitorMode().addValueObserver(function (value) {
if (value.toUpperCase() === MONITORMODE.AUTO || value.toUpperCase() === MONITORMODE.ON) {
sendMidi(144, NOTE.INPUTMONITOR, LIGHT_ON);
} else {
sendMidi(144, NOTE.INPUTMONITOR, LIGHT_OFF);
}
});
trackBank.getChannel(0).volume().value().addValueObserver(function (volumeValue) {
var LSB = parseInt((volumeValue * 16383) % 128);
var MSB = parseInt((volumeValue * 16383) / 128);
sendMidi(224, LSB, MSB);
});
return onMidiChannel;
}
function onMidiChannel(status, data1, data2) {
// Check if message is MIDI CC
if (isChannelController(status)) {
var changeValue = midiCcValueToInteger(data2);
if (isJogActive)
changeValue = JOGFACTOR_PANNING * changeValue;
switch (data1) {
case CC.PAN:
trackBank.getChannel(0).pan().value().inc(changeValue, ENCODER_RESOLUTION);
break;
}
} else if (isNoteOn(status) && data2 > 0) {
switch (data1) {
case NOTE.CHANNELSELECTRIGHT:
cursorTrack.selectNext();
break;
case NOTE.CHANNELSELECTLEFT:
cursorTrack.selectPrevious();
break;
case NOTE.MUTE:
trackBank.getChannel(0).mute().toggle();
break;
case NOTE.SOLO:
trackBank.getChannel(0).solo().toggle();
break;
case NOTE.AUTOMATIONWRITE:
transport.isArrangerAutomationWriteEnabled().toggle();
break;
case NOTE.AUTOMATIONREAD:
transport.resetAutomationOverrides();
break;
case NOTE.RECORDARM:
trackBank.getTrack(0).arm().toggle();
break;
case NOTE.INPUTMONITOR:
toggleMonitorMode();
break;
case NOTE.EBUTTON:
application.toggleInspector();
break;
case NOTE.OPENVSTI:
application.toggleDevices();
break;
}
} else if (status == 224) {
trackBank.getChannel(0).volume().value().set(data2 * 128 + data1, 16383);
}
}
function toggleMonitorMode() {
var currentValue = trackBank.getTrack(0).monitorMode().get();
switch (currentValue.toUpperCase()) {
case MONITORMODE.AUTO:
trackBank.getTrack(0).monitorMode().set(MONITORMODE.ON);
break;
case MONITORMODE.ON:
trackBank.getTrack(0).monitorMode().set(MONITORMODE.OFF);
break;
case MONITORMODE.OFF:
trackBank.getTrack(0).monitorMode().set(MONITORMODE.AUTO);
break;
}
}