-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_BPM_PerlinNoise.pde
181 lines (127 loc) · 4.4 KB
/
test_BPM_PerlinNoise.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
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
Visual from : Code-Package-Processing-3.x/02_M/M_1_5_02_TOOL/M_1_5_02_TOOL.pde
at https://github.com/generative-design/Code-Package-Processing-3.x/blob/master/02_M/M_1_5_02_TOOL/M_1_5_02_TOOL.pde
* noise values (noise 2d) are used to animate a bunch of agents.
*
* KEYS
* m : toogle menu open/close
* 1-2 : switch noise mode
* space : new noise seed
* backspace : clear screen
* s : save png
* This sketch demonstrates how to use the BeatDetect object song SOUND_ENERGY mode.<br />
*
* For more information about Minim and additional features,
* visit http://code.compartmental.net/minim/
*/
// FIRST TRY
// BPM DETECTION + PERLIN NOISE BASED VIDEO GENERATION
// NO SERIAL CONNECTION
//
//
//import processing.serial.*;
import ddf.minim.*; //BPM detection
import ddf.minim.analysis.*;
import controlP5.*; //fader
import java.util.Calendar;
Minim minim;
AudioPlayer song;
BeatDetect beat;
Bpm bpmo;
int MAX_AGENTS = 2000;
// ------ agents ------
Agent[] agents = new Agent[MAX_AGENTS]; // create more ... to fit max slider agentsCount
int agentsCount = 400;
float noiseScale = 300, noiseOld = 300, noiseStrength = 10;
float overlayAlpha = 10, overlayAlphaOld = 10, agentsAlpha = 90, agentsAlphaOld = 90, strokeWidth = 0.3;
int drawMode = 1;
//float con, res, conv;
ControlP5 controlP5;
boolean showGUI = false;
Slider[] sliders;
float eRadius;
int initTime, counter;
int BPM1=0;
void setup()
{
size(1280,800,P2D);
smooth();
for(int i=0; i<agents.length; i++) { //inizializza gli oggetti grafici
agents[i] = new Agent();
}
setupGUI();
bpmo = new Bpm();
minim = new Minim(this);
song = minim.loadFile("song.mp3", 2048);
song.play();
// a beat detection object song SOUND_ENERGY mode with a sensitivity of 10 milliseconds
beat = new BeatDetect(song.bufferSize(), song.sampleRate());
bpmo.setInitTime(millis());
bpmo.setCounter(0);
frameRate(30);
beat.setSensitivity(400);
// String portName = Serial.list()[0]; //serial communication
// myPort = new Serial(this, portName, 9600);
}
void draw()
{
agentsAlpha = agentsAlphaOld;
noiseScale = noiseOld ;
overlayAlpha = overlayAlphaOld;
// agentsCount = (int)(1.0+(float)agentsCount*con); //modify agents number according to CONDUCTANCE value from the sensor
// println(agentsCount);
// if(agentsCount > MAX_AGENTS) agentsCount = (int)((float)agentsCount / 50 );
beat.detect(song.mix);
BPM1 = bpmo.getBPM( 1500 ); //GET BPM FUNCTION
if ( beat.isRange(1,1,1) ) { //if KICK is detected...
int newNoiseSeed = (int) random(100000); // change objects direction
//println("newNoiseSeed: "+newNoiseSeed);
noiseSeed(newNoiseSeed);
//noiseOld = noiseScale;
//noiseScale = 0;
overlayAlphaOld = overlayAlpha; // fa una copia del valore attuale di OverlayAlpha
overlayAlpha = 255; // Imposta temporaneamente l'opacità al minimo (effetto flash)
agentsAlphaOld = agentsAlpha;
agentsAlpha = 30;
bpmo.incrementCounter();
}
fill(255, overlayAlpha);
noStroke();
rect(0,0,width,height);
strokeWidth = BPM1/40;
//println(" strokeWidth: " +strokeWidth);
stroke(0, agentsAlpha);
//draw agents
if (drawMode == 1) { // default is 1
for(int i=0; i<agentsCount; i++) agents[i].update1();
}
else {
for(int i=0; i<agentsCount; i++) agents[i].update2();
}
drawGUI();
//println("CON: "+ con);
}
void keyReleased(){
if(key=='m' || key=='M') {
showGUI = controlP5.getGroup("menu").isOpen();
showGUI = !showGUI;
}
if (showGUI) controlP5.getGroup("menu").open();
else controlP5.getGroup("menu").close();
if (key == '1') drawMode = 1;
if (key == '2') drawMode = 2;
if (key=='s' || key=='S') saveFrame(timestamp()+".png");
if (key == ' ') {
int newNoiseSeed = (int) random(100000);
println("newNoiseSeed: "+newNoiseSeed);
noiseSeed(newNoiseSeed);
}
if (key == DELETE || key == BACKSPACE) background(255);
}
String timestamp() {
return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", Calendar.getInstance());
}