-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathj_lg_filter.js
50 lines (45 loc) · 1.18 KB
/
j_lg_filter.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
inlets = 2;
outlets = 1;
var filter = {};
function setFilter(noteList) {
filter = {};
for (var i = 0; i < noteList.length; i++) {
filter[noteList[i]] = true;
}
post("Filter set to: " + noteList.join(", ") + "\n");
}
function processMIDIMessage(note, velocity) {
if (filter[note % 12]) {
outlet(0, note, velocity);
if (velocity > 0) {
post("Note-on passed: " + note + " " + velocity + "\n");
} else {
post("Note-off passed: " + note + "\n");
}
} else {
if (velocity > 0) {
post("Note-on dropped: " + note + " " + velocity + "\n");
} else {
post("Note-off dropped: " + note + "\n");
}
}
}
function list() {
var args = arrayfromargs(arguments);
if (inlet === 0) {
setFilter(args);
} else if (inlet === 1) {
if (args.length === 2) {
processMIDIMessage(args[0], args[1]);
} else {
post("Invalid MIDI message. Expected NOTE VELOCITY.\n");
}
}
}
function clear() {
if (inlet === 0) {
filter = {};
} else {
post("'clear' command should be sent to left inlet.\n");
}
}