-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathControl.pde
154 lines (133 loc) · 3.7 KB
/
Control.pde
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
void updateModulations() {
viewportMixer.setPan(pan);
float[] panAndScanArrayLeft = panAndScanLeftSlider.getArrayValue();
panAndScanLeft.xMod = panAndScanArrayLeft[0] / 100.0;
panAndScanLeft.yMod = panAndScanArrayLeft[1] / 100.0;
panAndScanLeft.setSizeMod(panAndScanLeftSizeSlider.getValue());
float[] panAndScanArrayRight = panAndScanRightSlider.getArrayValue();
panAndScanRight.xMod = panAndScanArrayRight[0] / 100.0;
panAndScanRight.yMod = panAndScanArrayRight[1] / 100.0;
panAndScanRight.setSizeMod(panAndScanRightSizeSlider.getValue());
}
void initControls() {
// GUI
CColor guiOrange = new CColor(
color(128, 96, 0),
color(128, 64, 0),
color(255, 128, 0),
color(255),
color(255)
);
CColor guiMagenta = new CColor(
color(255, 0, 128),
color(128, 0, 64),
color(255, 64, 255),
color(255),
color(255));
cp5 = new ControlP5(this);
sliderPan = cp5.addSlider("pan")
.setPosition(150,300)
.setRange(0, 1.0)
.setSize(300, 20)
.setColor(guiMagenta);
panAndScanLeftSlider = cp5.addSlider2D("Pan and Scan Left")
.setPosition(0, 320)
.setSize(150, 150)
.setArrayValue(new float[] {0.5, 0.5})
.setColor(guiMagenta);
panAndScanRightSlider = cp5.addSlider2D("Pan and Scan Right")
.setPosition(450, 320)
.setSize(150, 150)
.setArrayValue(new float[] {0.5, 0.5})
.setColor(guiMagenta);
panAndScanLeftSizeSlider = cp5.addSlider("Pan and Scan Size")
.setPosition(0, 490)
.setRange(0, 1.0)
.setSize(150, 20)
.setLabelVisible(false)
.setColor(guiMagenta);
panAndScanRightSizeSlider = cp5.addSlider("Pan and Scan Size2")
.setPosition(450, 490)
.setRange(0, 1.0)
.setSize(150, 20)
.setLabelVisible(false)
.setColor(guiMagenta);
cp5.addButton("newLeft")
.setValue(0)
.setPosition(0, 300)
.setSize(150, 20)
.setColor(guiOrange);
cp5.addButton("newRight")
.setValue(0)
.setPosition(450, 300)
.setSize(150, 20)
.setColor(guiOrange);
}
void resetCrossFade() {
pan = 0.5;
}
void requestChangeRoutine() {
shouldChangeRoutine = true;
}
// Do not call directly, instead set shouldChangeRoutine
void changeRoutine() {
shouldChangeRoutine = false;
// Update the routine faded away, or
// randomly update one of either the left or right.
if (pan < 0.25) {
viewportLeft.setRoutine(pickRoutine());
} else if (pan > 0.75) {
viewportRight.setRoutine(pickRoutine());
} else if (random(2) > 1.0) {
viewportLeft.setRoutine(pickRoutine());
} else {
viewportRight.setRoutine(pickRoutine());
}
}
void keyPressed() {
rotateColors(1);
}
void oscEvent(OscMessage message) {
String pattern = message.addrPattern();
//message.print();
if (!pattern.startsWith("/wii/"))
return;
if (pattern.endsWith("/button/A") && message.get(0).floatValue() == 0) {
requestChangeRoutine();
}
else if (pattern.endsWith("/motion/angles")) {
// Control microviews here
}
else if (pattern.endsWith("/button/Plus")) {
// panOfs = -2 * message.get(0).floatValue();
}
else if (pattern.endsWith("/button/Minus")) {
// panOfs = 2 * message.get(0).floatValue();
}
else if (pattern.endsWith("/button/Home")) {
resetCrossFade();
}
else if (pattern.endsWith("/button/Up")) {
rotateColors(1);
}
else if (pattern.endsWith("/button/Down")) {
rotateColors(-1);
}
}
Routine pickRoutine() {
int idx = int(random(routines.length));
RoutineFactory factory = routines[idx];
Routine instance = factory.create(this);
instance.beginDraw();
instance.setup();
instance.endDraw();
return instance;
}
public void rotateColors(int ofs) {
int len = Config.PALETTE.length;
colorOffset += ofs;
if (colorOffset >= len)
colorOffset -= len;
else if (colorOffset < 0)
colorOffset += len;
}