This repository has been archived by the owner on Nov 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
source.js
102 lines (89 loc) · 2.19 KB
/
source.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
this.inlets = 1;
this.outlets = 2;
function Source(parseCh) {
this.parseCh = parseCh;
this.ch = 0;
this.a = 0;
this.e = 0;
this.d = 0;
this.sendCoordinates = sendCoordinates;
this.remove = remove;
this.updateCh = updateCh;
}
function sendCoordinates(spread) {
if (this.ch > 0) {
outlet(0, ["aed",
this.ch,
this.a + spread,
this.e,
this.d,
1]);
}
}
function remove() {
outlet(1, this.ch);
}
function updateCh(chs) {
newCh = this.parseCh(chs);
if (newCh != this.ch) {
this.remove();
this.ch = newCh;
this.sendCoordinates();
}
}
function parseLeft(chs) {
var re = new RegExp("([0-9]+)/?([0-9]+)?");
return parseInt(re.exec(chs)[1]);
}
function parseRight(chs) {
var re = new RegExp("([0-9]+)/?([0-9]+)?");
ch = re.exec(chs)[2];
if (ch == null)
return 0;
return parseInt(ch);
}
var Sources = {
sLeft: new Source(parseLeft),
sRight: new Source(parseRight),
spread: 0,
track: null,
setProperty: function(property, value) {
if (property == "spread") {
this.spread = value;
} else {
this.sLeft[property] = value;
this.sRight[property] = value;
}
this.sendCoordinates();
},
sendCoordinates: function() {
if (this.sRight.ch != 0) {
this.sLeft.sendCoordinates(-1*this.spread/2.0);
this.sRight.sendCoordinates(this.spread/2.0);
} else {
this.sLeft.sendCoordinates(0);
}
},
updateChs: function(chs) {
this.sLeft.updateCh(chs);
this.sRight.updateCh(chs);
}
};
function setProperty(property, value) {
Sources.setProperty(property, value);
}
function apiCallback(args) {
if (args[0] == "current_output_sub_routing") {
if (Sources.track.get("current_output_routing") == "Ext. Out") {
Sources.updateChs(args[1]);
} else {
Sources.updateChs('0/0')
}
post("left: ", Sources.sLeft.ch, " right: ", Sources.sRight.ch, "\n");
Sources.sendCoordinates();
}
}
function bang() {
Sources.track = new LiveAPI(apiCallback, "this_device canonical_parent");
Sources.track.property = "current_output_sub_routing";
}