-
Notifications
You must be signed in to change notification settings - Fork 1
/
shiftSlider.java
68 lines (60 loc) · 1.73 KB
/
shiftSlider.java
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
import com.cycling74.max.*;
public class shiftSlider extends MaxObject {
Atom[] values;
Atom[] view;
int steps = 0;
int viewLength = 10;
shiftSlider() {
declareInlets(new int[] { DataTypes.LIST, DataTypes.INT, DataTypes.LIST });
declareOutlets(new int[] { DataTypes.LIST, DataTypes.LIST });
values = new Atom[viewLength * 3];
for (int i = 0; i < values.length; i++) {
values[i] = Atom.newAtom(0.);
}
view = new Atom[viewLength];
for (int i = 0; i < view.length; i++) {
view[i] = Atom.newAtom(0.);
}
}
private boolean arrayEquals(Atom[] a, Atom[] b) {
if (a == null || b == null || a.length != b.length) {
return false;
}
for (int i = 0; i < a.length; i++) {
if (!a[i].equals(b[i])) {
return false;
}
}
return true;
}
protected void list(Atom[] a) {
int idx = getInlet();
switch (idx) {
case 0:
System.arraycopy(a, 0, values, viewLength + steps, viewLength);
outlet(1, values);
break;
case 2:
if (arrayEquals(a, values)) {
return;
} else {
values = a;
outputView();
}
break;
}
}
protected void inlet(int v) {
int idx = getInlet();
switch (idx) {
case 1:
steps = -v;
outputView();
break;
}
}
protected void outputView() {
System.arraycopy(values, steps + viewLength, view, 0, viewLength);
outlet(0, view);
}
}