This repository has been archived by the owner on May 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TrackHandler.js
98 lines (73 loc) · 2.67 KB
/
TrackHandler.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
load("Midi.js");
load("Utils.js");
const KNOBS_REMOTE = [102, 103, 104, 105, 110, 111, 112, 113];
const KNOBS_SEND = [106, 107, 108, 109];
const KNOB_VOLUME = 117;
const KNOB_PAN = 116;
const OCTAVE_DOWN = 20;
const OCTAVE_UP = 21;
function TrackHandler(host, hardware) {
this.host = host;
this.hardware = hardware;
this.cursorTrack = this.host.createCursorTrack(4, 0);
this.cursorDevice = this.cursorTrack.createCursorDevice();
this.remoteControls = this.cursorDevice.createCursorRemoteControlsPage(8);
this.sendBank = this.cursorDevice.channel().sendBank();
for (var i = 0; i < 8; i++) {
var p = this.remoteControls.getParameter(i).getAmount();
p.setIndication(true);
p.setLabel("P" + (i + 1));
}
}
TrackHandler.prototype.handleMidi = function(status, data1, data2) {
if(Midi.isCC(status)) {
var increment = (data2 - 64) * 0.1;
if(KNOBS_REMOTE.includes(data1)) {
var paramIndex = KNOBS_REMOTE.indexOf(data1);
this.remoteControls.getParameter(paramIndex).inc(increment, 128);
return true;
}
else if(KNOBS_SEND.includes(data1)) {
var knobIndex = KNOBS_SEND.indexOf(data1);
this.sendBank.getItemAt(knobIndex).value().inc(increment, 128)
}
else if(data1 == KNOB_VOLUME) {
this.cursorTrack.volume().value().inc(increment, 128);
}
else if(data1 == KNOB_PAN) {
this.cursorTrack.pan().value().inc(increment, 128);
}
else if(data1 == OCTAVE_DOWN) {
if(data2 != 127) {
this.hardware.isOctaveDownPressed = false;
return true;
}
this.hardware.isOctaveDownPressed = true;
if(this.hardware.isOctaveUpPressed) {
// Reset
this.remoteControls.selectedPageIndex().set(0);
}
else {
// Previous Page
this.remoteControls.selectPreviousPage(false);
}
return true;
}
else if(data1 == OCTAVE_UP) {
if(data2 != 127) {
this.hardware.isOctaveUpPressed = false;
return true;
}
this.hardware.isOctaveUpPressed = true;
if(this.hardware.isOctaveDownPressed) {
// Reset
this.remoteControls.selectedPageIndex().set(0);
}
else {
// Next Page
this.remoteControls.selectNextPage(false);
}
return true;
}
}
}