-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexample.js
44 lines (33 loc) · 904 Bytes
/
example.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
var MidiStream = require('./index')
var duplex = MidiStream('Launchpad', 0)
// clear lights
duplex.write([176, 0, 0])
// echo back the message to launchpad
duplex.pipe(duplex)
// write buttons pressed to console
duplex.on('data', function(data){
console.log(data)
})
// paint a face after 10 seconds :)
var faceCoords = [
[1,1], [2,1], [5,1], [6,1],
[1,2], [2,2], [5,2], [6,2],
[2,4], [5,4],
[2,5], [3,5], [4,5], [5,5]
]
setTimeout(function(){
faceCoords.forEach(function(xy){
var id = xy[1] * 16 + xy[0] // convert coords to midi note
duplex.write([144, id, 60])
})
}, 10000)
// wait 20 seconds then close the port
setTimeout(function(){
duplex.end()
}, 20000)
///// bonus round, second launchpad! ////
var bonus = MidiStream('Launchpad', 1)
faceCoords.forEach(function(xy){
var id = xy[1] * 16 + xy[0] // convert coords to midi note
bonus.write([144, id, 60])
})