forked from codingjoe/MusicBeam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Strobe_Effect.pde
126 lines (99 loc) · 5.11 KB
/
Strobe_Effect.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
/*
* Copyright (c) 2012-2014 Johannes Hoppe <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
public class Strobe_Effect extends Effect
{
public String getName()
{
return "Strobe";
}
char triggeredByKey() {
return '1';
}
public Strobe_Effect(MusicBeam controller, int y)
{
super(controller, y);
randomToggle.setState(false);
manualButton = cp5.addButton("manual"+getName()).setSize(195, 195).setPosition(0, 5).setGroup(controlGroup);
manualButton.getCaptionLabel().set("Manual Trigger").align(ControlP5.CENTER, ControlP5.CENTER);
hatToggle = cp5.addToggle("hat"+getName()).setSize(195, 45).setPosition(200, 5).setGroup(controlGroup);
hatToggle.getCaptionLabel().set("Hat").align(ControlP5.CENTER, ControlP5.CENTER);
snareToggle = cp5.addToggle("snare"+getName()).setSize(195, 45).setPosition(200, 55).setGroup(controlGroup);
snareToggle.getCaptionLabel().set("Snare").align(ControlP5.CENTER, ControlP5.CENTER);
kickToggle = cp5.addToggle("kick"+getName()).setSize(195, 45).setPosition(200, 105).setGroup(controlGroup);
kickToggle.getCaptionLabel().set("Kick").align(ControlP5.CENTER, ControlP5.CENTER);
kickToggle.setState(true);
onsetToggle = cp5.addToggle("onset"+getName()).setSize(195, 45).setPosition(200, 155).setGroup(controlGroup);
onsetToggle.getCaptionLabel().set("Peak").align(ControlP5.CENTER, ControlP5.CENTER);
onsetToggle.setState(true);
delaySlider = cp5.addSlider("delay"+getName()).setRange(10, frameRate/2).setValue(frameRate/2-2).setPosition(0, 205).setSize(395, 45).setGroup(controlGroup);
delaySlider.getCaptionLabel().set("Frequency (Hz)").align(ControlP5.RIGHT, ControlP5.CENTER);
hueSlider = cp5.addSlider("hue"+getName()).setRange(0, 360).setSize(295, 45).setPosition(50, 255).setGroup(controlGroup);
hueSlider.getCaptionLabel().set("hue").align(ControlP5.RIGHT, ControlP5.CENTER);
hueSlider.setValue(0);
aHueToggle = cp5.addToggle("ahue"+getName()).setPosition(0, 255).setSize(45, 45).setGroup(controlGroup);
aHueToggle.getCaptionLabel().set("A").align(ControlP5.CENTER, ControlP5.CENTER);
aHueToggle.setState(true);
bwToggle = ctrl.cp5.addToggle("bw"+getName()).setPosition(350, 255).setSize(45, 45).setGroup(controlGroup);
bwToggle.getCaptionLabel().set("BW").align(ControlP5.CENTER, ControlP5.CENTER);
bwToggle.setState(true);
}
boolean state = false;
float timer = 0;
Button manualButton;
Slider delaySlider, hueSlider;
Toggle hatToggle, snareToggle, kickToggle, onsetToggle, aHueToggle, bwToggle;
boolean isTriggered()
{
if (manualButton.isOn() || effect_manual_triggered)
return true;
else if ((!onsetToggle.getState() && hatToggle.getState() && isHat()) || (onsetToggle.getState() && isOnset() && hatToggle.getState() && isHat()))
return true;
else if ((!onsetToggle.getState() && snareToggle.getState() && isSnare()) || (onsetToggle.getState() && isOnset() && snareToggle.getState() && isSnare()))
return true;
else if ((!onsetToggle.getState() && kickToggle.getState() && isKick()) || (onsetToggle.getState() && isOnset() && kickToggle.getState() && isKick()))
return true;
else if (onsetToggle.getState() && isOnset())
return true;
else
return false;
}
void draw() {
if (state && (timer <= 0 || timer < frameRate/2-delaySlider.getValue()-3)) {
state = false;
timer = frameRate/2-delaySlider.getValue();
}
else if (!state && isTriggered() && timer <= 0) {
state = true;
timer = frameRate/2-delaySlider.getValue();
}
if (timer > 0)
timer--;
if (aHueToggle.getState())
hueSlider.setValue((hueSlider.getValue()+1)%360);
stg.fill(hueSlider.getValue(), bwToggle.getState()?0:100, 100);
if (state)
stg.rect(-stg.maxRadius/2, -stg.maxRadius/2, stg.maxRadius, stg.maxRadius);
}
void keyPressed(char key, int keyCode)
{
super.keyPressed(key, keyCode);
if (key == CODED) {
if (keyCode == LEFT)
delaySlider.setValue(delaySlider.getValue()-1);
else if (keyCode == RIGHT)
delaySlider.setValue(delaySlider.getValue()+1);
}
}
}