-
Notifications
You must be signed in to change notification settings - Fork 2
/
controlP5.pde
400 lines (327 loc) · 11.9 KB
/
controlP5.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
void controlP5Setup() {
cp5 = new ControlP5(this);
PFont pfont = createFont("Helvetica", 32, true); // use true/false for smooth/no-smooth
ControlFont font = new ControlFont(pfont, 14);
cp5.setFont(font);
//Controllers are organized from the top and down and left to right
cp5.addSlider("base")
.setPosition(stageMargin+35 + 50*baseMin, 40)
.setWidth(rectSize*(baseMax-baseMin))
.setHeight(20)
.setRange(baseMin, baseMax)
.setValue(0)
.setNumberOfTickMarks(baseMax-baseMin + 1)
.setSliderMode(Slider.FLEXIBLE)
.setColorActive(baseColor)
.setColorForeground(baseColor)
.setColorLabel(baseColor)
;
cp5.addSlider("snare")
.setPosition(stageMargin+35+50*snareMin, 70)
.setWidth(rectSize*(snareMax-snareMin))
.setHeight(20)
.setRange(snareMin, snareMax)
.setValue(5)
.setNumberOfTickMarks(snareMax-snareMin + 1)
.setSliderMode(Slider.FLEXIBLE)
.setColorActive(snareColor)
.setColorForeground(snareColor)
.setColorLabel(snareColor)
;
cp5.addSlider("baseThreshold").setPosition(65, 100).setSize(20, 100).setColorForeground(baseColor).setColorActive(baseColor).setRange(100, 0).setValue(50).setColorLabel(baseColor);
cp5.getController("baseThreshold").getValueLabel();
cp5.getController("baseThreshold").getCaptionLabel().align(ControlP5.CENTER, ControlP5.BOTTOM_OUTSIDE).setPaddingY(10);
cp5.addSlider("snareThreshold").setPosition(width-110, 100).setSize(20, 100).setColorForeground(snareColor).setColorActive(snareColor).setRange(100, 0).setValue(50).setColorLabel(snareColor);
cp5.getController("snareThreshold").getValueLabel();
cp5.getController("snareThreshold").getCaptionLabel().align(ControlP5.CENTER, ControlP5.BOTTOM_OUTSIDE).setPaddingY(10);
cp5.addKnob("baseTimerThreshold").setPosition(width/2-75, 275).setRadius(25).setColorForeground(baseColor).setColorActive(baseColor).setRange(1, 1000).setValue(50).setColorLabel(baseColor);
cp5.getController("baseTimerThreshold").getValueLabel().align(ControlP5.RIGHT, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
cp5.getController("baseTimerThreshold").getCaptionLabel().align(ControlP5.CENTER, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
cp5.addKnob("snareTimerThreshold").setPosition(width - stageMargin- 50, 275).setRadius(25).setColorForeground(snareColor).setColorActive(snareColor).setRange(1, 1000).setValue(50).setColorLabel(snareColor);
cp5.getController("snareTimerThreshold").getValueLabel().align(ControlP5.RIGHT, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
cp5.getController("snareTimerThreshold").getCaptionLabel().align(ControlP5.CENTER, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
Group BASEOSC = cp5.addGroup("BASEOSC")
.setPosition(stageMargin-25, 400)
.setBarHeight(18)
.setSize(350, 200)
.activateEvent(true)
.setColorBackground(0)
.setColorLabel(snareColor)
//.setColorForeground(snareColor)
.setBackgroundColor(color(255, 80))
//.setBackgroundHeight(100)
.setLabel("BASE OSC Controls")
;
baseClipsColumnsEffect = cp5.addRadioButton("baseClipsColumnsEffect")
.setPosition(10, 10)
.setSize(20, 15)
.setColorForeground(color(120))
.setColorActive(color(255))
.setColorLabel(color(255))
.addItem("Clips", 0)
.addItem("Columns", 1)
.addItem("Effect", 2)
.addItem("Pianop", 3)
.setNoneSelectedAllowed(false)
.activate(0)
.setGroup(BASEOSC)
;
baseLayers = cp5.addCheckBox("baseLayers")
.setPosition(250, 10)
.setSize(20, 15)
.setColorForeground(color(120))
.setColorActive(color(255))
.setColorLabel(color(255))
.addItem("Layer3", 3)
.addItem("Layer2", 2)
.addItem("Layer1", 1)
.setNoneSelectedAllowed(false)
.activate(2)
.setGroup(BASEOSC)
;
baseOscRange = cp5.addRange("baseRange")
// disable broadcasting since setRange and setRangeValues will trigger an event
.setBroadcast(false)
.setPosition(10, 85)
.setSize(215, 10)
.setHandleSize(20)
.setRange(1, 6)
.setDecimalPrecision(0)
// after the initialization we turn broadcast back on again
.setBroadcast(true)
.setLowValue(1)
.setHighValue(6)
.setGroup(BASEOSC)
;
baseSequentialOrRandom = cp5.addRadioButton("baseSequentialOrRandom")
.setPosition(125, 10)
.setSize(20, 15)
.setColorForeground(color(120))
.setColorActive(color(255))
.setColorLabel(color(255))
.addItem("_Sequential", 0)
.addItem("_Random", 1)
.setNoneSelectedAllowed(false)
.activate(1)
.setGroup(BASEOSC)
;
cp5.addTextfield("BaseOscAdress")
.setPosition(10, 110)
.setSize(215, 30)
.setFocus(false)
.setLabel("OSC Effect Adress")
.setGroup(BASEOSC)
;
cp5.addToggle("basePeakToggle")
.setPosition(235, 110)
.setSize(30, 20)
.setGroup(BASEOSC)
.setLabel("Peak")
;
cp5.addToggle("baseOscToggle")
.setPosition(280, 110)
.setSize(30, 20)
.setGroup(BASEOSC)
.setLabel("On/Off")
;
cp5.addSlider("basePianoClip")
.setPosition(10, 170)
.setSize(212, 10)
.setRange(1, 6) // values can range from big to small as well
.setValue(1)
.setNumberOfTickMarks(6)
.setSliderMode(Slider.FLEXIBLE)
.setGroup(BASEOSC)
;
Group SNAREOSC = cp5.addGroup("SNAREOSC")
.setPosition(width/2+25, 400)
.setBarHeight(18)
.setSize(350, 200)
.activateEvent(true)
.setColorBackground(0)
.setColorLabel(snareColor)
//.setColorForeground(snareColor)
.setBackgroundColor(color(255, 80))
//.setBackgroundHeight(100)
.setLabel("SNARE OSC Controls")
;
snareClipsColumnsEffect = cp5.addRadioButton("snareClipsColumnsEffect")
.setPosition(10, 10)
.setSize(20, 15)
.setColorForeground(color(120))
.setColorActive(color(255))
.setColorLabel(color(255))
.addItem("CLIPS", 0)
.addItem("COLUMNS", 1)
.addItem("EFFECT", 2)
.addItem("PIANO", 3)
.setNoneSelectedAllowed(false)
.activate(0)
.setGroup(SNAREOSC)
;
sequentialOrRandom = cp5.addRadioButton("sequentialOrRandom")
.setPosition(125, 10)
.setSize(20, 15)
.setColorForeground(color(120))
.setColorActive(color(255))
.setColorLabel(color(255))
.addItem("Sequential", 0)
.addItem("Random", 1)
.setNoneSelectedAllowed(false)
.activate(1)
.setGroup(SNAREOSC)
;
snareLayers = cp5.addCheckBox("snareLayers")
.setPosition(250, 10)
.setSize(20, 15)
.setColorForeground(color(120))
.setColorActive(color(255))
.setColorLabel(color(255))
.addItem("Layer 3", 3)
.addItem("Layer 2", 2)
.addItem("Layer 1", 1)
.setNoneSelectedAllowed(false)
.activate(2)
.setGroup(SNAREOSC)
;
snareOscRange = cp5.addRange("snareRange")
// disable broadcasting since setRange and setRangeValues will trigger an event
.setBroadcast(false)
.setPosition(10, 85)
.setSize(215, 10)
.setHandleSize(20)
.setRange(1, 6)
.setDecimalPrecision(0)
// after the initialization we turn broadcast back on again
.setBroadcast(true)
.setLowValue(1)
.setHighValue(6)
//.snapToTickMarks(true)
//.setColorForeground(snareColor)
//.setColorBackground(0)
.setGroup(SNAREOSC)
;
cp5.addTextfield("SnareOscAdress")
.setPosition(10, 110)
.setSize(215, 30)
//.setFont()
.setFocus(false)
//.setColor(color(255,0,0))
//.setFont(createFont("arial",14))
.setLabel("OSC Effect Adress")
.setGroup(SNAREOSC)
;
cp5.addToggle("snarePeakToggle")
.setPosition(245, 110)
.setSize(30, 20)
.setGroup(SNAREOSC)
.setLabel("Peak")
;
cp5.addToggle("snareOscToggle")
.setPosition(295, 110)
.setSize(30, 20)
.setGroup(SNAREOSC)
.setLabel("On/Off")
;
cp5.addSlider("snarePianoClip")
.setPosition(10, 170)
.setSize(212, 10)
.setRange(1, 6) // values can range from big to small as well
.setValue(1)
.setNumberOfTickMarks(6)
.setSliderMode(Slider.FLEXIBLE)
.setGroup(SNAREOSC)
;
Group FFT = cp5.addGroup("FFT")
.setPosition(stageMargin-25, 625)
.setBarHeight(18)
.setWidth(350)
.activateEvent(true)
.setBackgroundColor(color(255, 80))
.setBackgroundHeight(100)
.setLabel("FFT Variables")
;
int fftOffsetX = 150;
cp5.addSlider("myAudioAmp").setPosition(fftOffsetX, 10).setSize(175, 10).setRange(0, 15000).setValue(6500).setGroup(FFT);
cp5.getController("myAudioAmp").getValueLabel().align(ControlP5.RIGHT, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
cp5.getController("myAudioAmp").getCaptionLabel().align(ControlP5.LEFT, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
cp5.addSlider("myAudioIndex").setPosition(fftOffsetX, 40).setSize(175, 10).setRange(0.0, 1.0).setValue(0.2).setGroup(FFT);
cp5.getController("myAudioIndex").getValueLabel().align(ControlP5.RIGHT, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
cp5.getController("myAudioIndex").getCaptionLabel().align(ControlP5.LEFT, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
cp5.addSlider("myAudioIndexStep").setPosition(fftOffsetX, 70).setSize(175, 10).setRange(0.0, 1.0).setValue(0.5).setGroup(FFT);
cp5.getController("myAudioIndexStep").getValueLabel().align(ControlP5.RIGHT, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
cp5.getController("myAudioIndexStep").getCaptionLabel().align(ControlP5.LEFT, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
fftWindow = cp5.addRadioButton("fftWindow")
.setPosition(10, 10)
.setSize(20, 15)
.setColorForeground(color(120))
.setColorActive(color(255))
.setColorLabel(color(255))
.addItem("NONE", 0)
.addItem("BARTLETT", 1)
.addItem("BARTLETTHANN", 2)
.addItem("BLACKMAN", 3)
.addItem("GAUSS", 4)
.setNoneSelectedAllowed(false)
.setCaptionLabel("FFT Window Type")
.activate(0)
.setGroup(FFT)
;
cp5.addBang("bang").setPosition(width-75, height-75).setSize(40, 40).setLabel("reset");
cp5.getController("bang").getCaptionLabel().align(ControlP5.CENTER, ControlP5.BOTTOM_OUTSIDE);
}
public void bang() {
//This is not updated right now...
cp5.get("myAudioAmp").setValue(65);
cp5.get("snareThreshold").setValue(50);
cp5.get("snareTimerThreshold").setValue(50);
cp5.get("myAudioIndex").setValue(0.2);
cp5.get("myAudioIndexStep").setValue(0.5);
cp5.get("fftWindow").setValue(4);
snare = 5;
fftWindow.activate(4);
}
void controlEvent(ControlEvent theEvent) {
if (theEvent.isFrom(snareLayers)) {
print("got an event from "+snareLayers.getName()+"\t\n");
// checkbox uses arrayValue to store the state of
// individual checkbox-items. usage:
println(snareLayers.getArrayValue());
int col = 0;
for (int i=0; i<snareLayers.getArrayValue().length; i++) {
int n = (int)snareLayers.getArrayValue()[i];
print(n);
if (n==1) {
// myColorBackground += checkbox.getItem(i).internalValue();
}
}
println();
}
if (theEvent.isFrom(baseLayers)) {
print("got an event from "+baseLayers.getName()+"\t\n");
// checkbox uses arrayValue to store the state of
// individual checkbox-items. usage:
println(baseLayers.getArrayValue());
int col = 0;
for (int i=0; i<baseLayers.getArrayValue().length; i++) {
int n = (int)baseLayers.getArrayValue()[i];
print(n);
if (n==1) {
// myColorBackground += checkbox.getItem(i).internalValue();
}
}
println();
}
if (theEvent.isFrom("snareRange")) {
// min and max values are stored in an array.
// access this array with controller().arrayValue(). min is at index 0, max is at index 1.
snareMinRange = int(theEvent.getController().getArrayValue(0));
snareMaxRange = int(theEvent.getController().getArrayValue(1));
}
if (theEvent.isFrom("baseRange")) {
// min and max values are stored in an array.
// access this array with controller().arrayValue(). min is at index 0, max is at index 1.
baseMinRange = int(theEvent.getController().getArrayValue(0));
baseMaxRange = int(theEvent.getController().getArrayValue(1));
}
}