-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton.js
31 lines (31 loc) · 1.07 KB
/
button.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
(function($){
var Button = $.Button = function(channel, note, midiAdapter){
$.Observable.call(this);
this.channel = channel;
this.note = note;
this.midiAdapter = midiAdapter;
this.id = this.note;
if (!this.isControl()) {
this.x = this.note % 16;
this.y = Math.floor(this.note / 16);
} else {
this.id -= 104;
}
};
Button.prototype = Object.create($.Observable.prototype);
Button.prototype.constructor = Button;
Button.prototype.turn = function(color){
this.paint($.defaults.paintNames[color]);
};
Button.prototype.paint = function(colors){
colors = $.extend(colors, { 'red': 0, 'green': 0 });
var velocity = (colors.green % 4) * 16 + (colors.red % 4);
this.send(velocity);
};
Button.prototype.send = function(velocity){
this.midiAdapter.send(this.channel, this.note, velocity);
};
Button.prototype.isControl = function(){
return this.channel === 176;
};
})(window.launchpad = window.launchpad || {});