-
Notifications
You must be signed in to change notification settings - Fork 1
/
rotateSlider.ts
48 lines (38 loc) · 1.02 KB
/
rotateSlider.ts
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
inlets = 2;
outlets = 2;
let values: number[] = [];
let view: number[] = [];
let viewLength = 12;
let steps = 0;
function msg_int(v: number) {
const l = viewLength;
steps = (-v + l) % l;
bang();
}
function arrays_equal(a: any[], b: any[]) { return !!a && !!b && !(a < b || b < a); }
function list() {
switch (inlet) {
case 0:
const input = arrayfromargs(arguments);
values = input.slice(-steps, viewLength).concat(input.slice(0, -steps));
outlet(1, values);
// outlet(0, "setlist " + view.join(' '));
break;
case 1:
const updatedValues = arrayfromargs(arguments);
if (arrays_equal(values, updatedValues)) {
return;
}
else {
values = updatedValues;
bang();
}
break;
}
}
function bang() {
view = values.slice(steps, values.length).concat(values.slice(0, steps));
outlet(0, view);
}
let module = {};
export = {};