-
Notifications
You must be signed in to change notification settings - Fork 0
/
Watcher.js
88 lines (88 loc) · 2.49 KB
/
Watcher.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
let Watcher = {
sendCommand: (cmd, quiet) => {
let obj = {
watcher: Array.isArray(cmd) ? cmd : [ cmd ],
};
if(!quiet)
console.log("Sending", obj);
Bela.control.send(obj);
},
requestList: () => {
Watcher.sendCommand({cmd: "list"});
},
backwCompatibility: true,
backwTypes: [],
watchers: [],
processList: (watchers) => {
this.backwTypes = watchers.map((v) => {
return v.type;
});
this.watchers = watchers.map((v) => {
return v.name;
});
},
parseInputData: (buffers, list, useList) => {
if(!buffers)
return;
let retBufs = Array();
for(let k = 0; k < buffers.length; ++k)
{
if(useList) {
// Bela.data.buffers have been populated only by the audio watched variables
// everything else we have to set here
retBufs.push({
timestamp: list.timestamp,
buf: [ list[k].valueInput ],
watcher: this.watchers[k],
});
}
if(!buffers[k])
continue;
let timestampBuf;
let type = buffers[k].type;
if(!type) {
// when running with old version of the core GUI, type has to be set elsewhere
backwCompatibility = true;
type = this.backwTypes[k];
}
switch(type)
{
case 'c':
// absurb reverse mapping of an absurd fwd mapping
let intArr = buffers[k].slice(0, 8).map((e) => {
return e.charCodeAt(0);
});
timestampBuf = new Uint8Array(intArr);
buf = buffers[k].slice(8);
break;
case 'j': // unsigned int
timestampBuf = new Uint32Array(buffers[k].slice(0, 2))
buf = buffers[k].slice(2);
break;
case 'i': // int
timestampBuf = new Int32Array(buffers[k].slice(0, 2))
buf = buffers[k].slice(2);
break;
case 'f': // float
timestampBuf = new Float32Array(buffers[k].slice(0, 2));
buf = buffers[k].slice(2);
break;
case 'd':
timestampBuf = new Float64Array(buffers[k].slice(0, 1));
buf = buffers[k].slice(1);
break;
default:
console.log("Unknown buffer type ", type);
continue;
}
let timestampUint32 = new Uint32Array(timestampBuf.buffer);
let timestamp = timestampUint32[0] * (1 << 32) + timestampUint32[1];
retBufs.push({
timestamp: timestamp,
buf: buf,
watcher: this.watchers[k],
});
}
return retBufs;
},
};