-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
59 lines (52 loc) · 1.66 KB
/
test.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
const focusrite = require('./main');
// focusrite.createFakeServer([
// `<client-details id="XXXXXXXXX"/>`,
// `<device-arrival>...</device-arrival>`,
// ], (data) => {
// console.log(data);
// });
focusrite.findServerPort((port) => {
const config = {
airmode: null,
instmode: null,
};
focusrite.createFakeClient(port, 'xxxxxxxx-0000-xxxx-xxxx-xxxxxxxxxxxx', (onData, clientWrite) => {
onData((data) => {
let airmode = data.toString().match(/id="23" value\=\"([truefals]*)\"/);
let instmode = data.toString().match(/id="28" value\=\"([LineInst]*)\"/);
if (airmode && config.airmode !== airmode[1]) {
config.airmode = airmode[1];
console.log(`Airmode was set to : ${config.airmode}`);
}
if (instmode && config.instmode !== instmode[1]) {
config.instmode = instmode[1];
if (config.instmode === 'Inst') {
clientWrite(focusrite.requests.MODE_NORMAL);
clientWrite(focusrite.requests.MODE_COLOR);
changeColor();
}else clientWrite(focusrite.requests.MODE_NORMAL);
}
});
let i = 0;
let reverse = false;
function changeColor() {
if (config.instmode !== 'Inst') return;
if (reverse) i--;
else i++;
let rq = focusrite.colors.fromIndex(i);
if (!rq) {
// reverse = !reverse;
// if (reverse) i -= 2;
// else i += 2;
i = 0;
rq = focusrite.colors.fromIndex(i);
}
clientWrite(rq);
if (config.instmode === 'Inst') setTimeout(changeColor, 70);
}
Object.prototype.fromIndex = function(i) {
const keys = Object.keys(this);
return this[keys[i]];
}
});
});