-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaunchpad.js
57 lines (50 loc) · 1.65 KB
/
launchpad.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
"use strict";
var _ = require('underscore');
var lp = require('midi-launchpad');
var cycle = require('./utils').cycle;
var shifted1 = false;
var shifted2 = false;
var Launchpad = function(outPort, inPort, banks){
this.launchpad;
if (inPort){
this.launchpad = new lp.Launchpad(0, false);
// Close and delete the ports, remove callback
this.launchpad.output.closePort();
delete this.launchpad.output;
this.launchpad.input.closePort();
delete this.launchpad.input;
// then repoen them with the differing ports and readd callback
this.launchpad.output = new midi.output();
this.launchpad.output.openPort(outPort);
this.launchpad.input = new midi.input();
this.launchpad.input.openPort(inPort);
this.launchpad.input.on('message', function(deltaTime, message) {
this.launchpad.receiveMessage(deltaTime, message);
});
} else {
this.launchpad = lp.connect(parseInt(result.launchpad));
}
this.banks = banks;
this.bankCycle = cycle(banks);
this.callbacks = {
'both':{},
'shift1': {},
'shift2': {},
'none': {'catchall': {}}
}
this.launchpad.on("press", function(button) {
var shift = 'none'
if (shifted1 && shifted2){
shift = 'both';
} else if (shifted1){
shift = 'shift1'
} else if (shifted2){
shift = 'shift2'
};
if (this.callbacks[shift][button.toString()]){
this.callbacks[shift][button.toString()](button);
} else {
this.callbacks[shift]['catchall'](button);
}
});
}