-
Notifications
You must be signed in to change notification settings - Fork 4
/
drum_pad.js
58 lines (49 loc) · 887 Bytes
/
drum_pad.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
outlets = 2;
var _start = 36;
var _end = 51;
var _oldNote;
var _notePressed;
var _colors = { "off":0, "yellow":13, "blue":40, "green":75 };
function init()
{
_oldNote = _start;
_notePressed = 0;
}
function focus()
{
for(i=_start; i<= _end; i++)
setColor(i,"yellow");
setColor(_oldNote, "blue");
outlet(1, "note_change", _oldNote);
}
function list()
{
var a = arrayfromargs(arguments);
drumPress( a[0], a[1]);
}
function drumPress(note, velocity)
{
if(velocity == 0){
_notePressed --;
if(_notePressed == 0){
setColor(_oldNote, "yellow");
setColor(note, "blue");
_oldNote = note;
outlet(1, "note_change", note);
}
else{
setColor(note,"yellow");
}
}
else
{
setColor(note, "green");
_notePressed ++;
}
}
function setColor(note, color)
{
outlet(0, note, _colors["off"]);
if(color != "off")
outlet(0, note, _colors[color]);
}