-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabletonLink.js
More file actions
36 lines (32 loc) · 898 Bytes
/
abletonLink.js
File metadata and controls
36 lines (32 loc) · 898 Bytes
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
// Ableton Link
module.exports = (io) => {
const abletonlink = require('abletonlink');
const link = new abletonlink();
const updateLink = () => {
let lastBeat = 0.0;
let lastBpm = 0;
link.startUpdate(60, (beat, phase, bpm) => {
//Beats
beat = 0 ^ beat;
if (0 < beat - lastBeat) {
io.emit('beat', {
beat,
bpm
});
lastBeat = beat;
}
//BPM
bpm = Math.round((bpm + Number.EPSILON) * 100) / 100;
if (bpm != lastBpm) {
io.emit('bpm', {
bpm
});
lastBpm = bpm;
serverLocalStorage.setItem('bpm', lastBpm)
//console.log(bpm);
}
});
};
updateLink();
return link;
};