forked from einfachfelixverdammt/Maschine-Jam-for-Bitwig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Button.js
61 lines (50 loc) · 1.52 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
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
57
58
59
60
61
function EmptyButton() {
this.sendValue = function(value, queue) {
};
}
/**
* Button
*
* **/
function Button(midivalue, channel) {
this.midivalue = midivalue;
this.channel = channel === undefined ? 0 : channel;
this.messageCallback = undefined;
this.midistatus = MIDI.CC << 4 | this.channel;
this.lastValue = -1;
this.filterValue = function() {
return this.midivalue;
};
this.sendValue = function(value, queue) {
if(this.lastValue != value) {
if(queue) {
queueMidi(this.midistatus, this.midivalue, value);
} else {
host.getMidiOutPort(0).sendMidi(this.midistatus, this.midivalue, value);
}
this.lastValue = value;
}
};
this.reset = function() {
host.getMidiOutPort(0).sendMidi(this.midistatus, this.midivalue, 0);
};
this.resendLast = function() {
if(this.lastValue >= 0) {
queueMidi(this.midistatus, this.midivalue, this.lastValue);
}
};
this.turnOn = function() {
this.sendValue(127);
};
this.turnOff = function() {
this.sendValue(0);
};
this.doCallback = function(value) {
if(this.messageCallback !== undefined && typeof this.messageCallback === 'function') {
this.messageCallback(value, this.midivalue);
}
};
this.setCallback = function(callback) {
this.messageCallback = callback;
};
};