-
Notifications
You must be signed in to change notification settings - Fork 3
/
RANDOMCHANNEL.js
47 lines (43 loc) · 1.5 KB
/
RANDOMCHANNEL.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
//--------------------------------------------------------------------------------------------------------------------------------------
// RANDOMCHANNEL
//--------------------------------------------------------------------------------------------------------------------------------------
/*
* Just randomizes the MIDI Channel that the notes are send to.
* Basic idea is to share a melody between multiple instruments.
*/
//--------------------------------------------------------------------------------------------------------------------------------------
var activeNotes = [];
function HandleMIDI(event) {
if (event instanceof NoteOn) {
var numChannel = GetParameter("Max Channels");
var randomChannel = Math.floor(Math.random() * numChannel) + 1;
var record = {
pitch: event.pitch,
channel: randomChannel
};
event.channel = randomChannel;
activeNotes.push(record);
event.send();
} else if (event instanceof NoteOff) {
for (var i in activeNotes) {
if (activeNotes[i].pitch == event.pitch) {
event.channel = activeNotes[i].channel;
activeNotes.splice(i, 1);
event.send();
break;
}
}
}
Trace(event);
}
var PluginParameters = [{
name: "RANDOMCHANNEL",
type: "text"
}, {
name: "Max Channels",
type: "linear",
defaultValue: 2,
minValue: 2,
maxValue: 16,
numberOfSteps: 14
}];