-
Notifications
You must be signed in to change notification settings - Fork 5
/
MidiMessage.js
51 lines (49 loc) · 1.95 KB
/
MidiMessage.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
//Summary of MIDI Messages from MIDI spec:
// https://www.midi.org/specifications/item/table-1-summary-of-midi-message
let p2sysex = require('./Push2SysexCommands');
class MidiMessage {
constructor(messageArray) {
let midiMessages={
128:"note off",
144:"note on",
160:"polyphonic key pressure",
176:"control change", // see table Channel Mode Messages for reserved controller numbers 120-127
192:"program change",
208:"channel pressure",
224:"pitch bend change",
240:"system common message",
};
this.statusCode = messageArray[0];
let message = midiMessages[messageArray[0]];
if (!message) {
console.warn("status code not understood.",messageArray);
return;
}
this.message = message;
if (this.statusCode==128 || this.statusCode==144 || this.statusCode==160) {
if (messageArray.length != 3) throw "Received unexpected number of parameters";
this.key = messageArray[1];
this.value = messageArray[2];
} else if (this.statusCode==176) { // control change
if (messageArray.length != 3) throw "Received unexpected number of parameters";
this.control = messageArray[1];
this.value = messageArray[2];
} else if (this.statusCode==192 || this.statusCode==208 ) {
this.value = messageArray[1];
} else if (this.statusCode==224) {
this.value = messageArray[2];
} else if (messageArray[0]==240&&messageArray[1]==0&&
messageArray[2]==33&&messageArray[3]==29&&
messageArray[4]==1&&messageArray[5]==1){
// sysex command [ 240, 0, 33, 29, 1, 1, ${commandId}, ${value}, 247 ]
this.commandId = messageArray[6];
let command = p2sysex.commands[this.commandId];
this.command = command.name;
if (Object.keys(command).includes('mode')){
this.mode = command.mode[messageArray[7]];
}
//this.value = messageArray.slice(7,messageArray.length-1);
}
}
}
module.exports = MidiMessage;