-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
79 lines (64 loc) · 2.55 KB
/
index.js
File metadata and controls
79 lines (64 loc) · 2.55 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var PixelPusher = require('heroic-pixel-pusher');
var PixelStrip = PixelPusher.PixelStrip;
var NanoTimer = require('nanotimer');
var midi = require('midi');
var patterns = require('./patterns');
var bpminfo = require('./bpminfo');
var pixelpusher = new PixelPusher();
var timer = null;
var input = new midi.input();
try {
// Configure a callback.
input.on('message', function (deltaTime, message) {
bpminfo.handleMessage(deltaTime, message);
});
// Open the first available input port.
input.openPort(0);
// Sysex, timing, and active sensing messages are ignored
// by default. To enable these message types, pass false for
// the appropriate type in the function below.
// Order: (Sysex, Timing, Active Sensing)
// For example if you want to receive only MIDI Clock beats
// you should use
// input.ignoreTypes(true, false, true)
input.ignoreTypes(true, false, true);
} finally {
}
var UPDATE_FREQUENCY_MILLIS = 15; // 15 is just faster than 60 FPS
timer = new NanoTimer();
var intvl = '' + UPDATE_FREQUENCY_MILLIS + 'm';
console.log(intvl);
timer.setInterval(tick, '', intvl);
var lastTick = (new Date).getTime();
var pattern = new patterns.patterns[0](pixelpusher, bpminfo);
function tick() {
pattern.tick((new Date).getTime() - lastTick);
lastTick = (new Date).getTime();
}
pixelpusher.on('discover', function (controller) {
// log connection data on initial discovery
console.log('-----------------------------------');
console.log('Discovered PixelPusher on network: ');
console.log(controller.params.pixelpusher);
console.log('-----------------------------------');
// capture the update message sent back from the pp controller
controller.on('update', function update() {
console.log({
updatePeriod: Math.round(
this.params.pixelpusher.updatePeriod * 100) / 100,
deltaSequence: this.params.pixelpusher.deltaSequence,
powerTotal: this.params.pixelpusher.powerTotal
});
}).on('timeout', function timeout() {
// be sure to handel the situation when the controller dissappears.
// this could be due to power cycle or network conditions
console.log(
'TIMEOUT : PixelPusher at address [' + controller.params.ipAddress +
'] with MAC (' + controller.params.macAddress +
') has timed out. Awaiting re-discovery....');
//if (!!timer) timer.clearInterval();
});
});
pixelpusher.on('error', function (err) {
console.log('PixelPusher Error: ' + err.message);
});