-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBeatWrite.pde
70 lines (62 loc) · 1.76 KB
/
BeatWrite.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
import processing.serial.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import cc.arduino.*;
Minim minim;
AudioPlayer song;
BeatDetect beat;
BeatListener bl;
Arduino arduino;
int ledPin = 12;
int ledPin2 = 8;
int ledPin3 = 2;
float kickSize, snareSize, hatSize;
void setup() {
size(512, 200, P3D);
minim = new Minim(this);
arduino = new Arduino(this, Arduino.list()[1], 57600);
song = minim.loadFile("song.mp3", 2048);
song.play();
beat = new BeatDetect(song.bufferSize(), song.sampleRate());
beat.setSensitivity(100);
kickSize = snareSize = hatSize = 16;
bl = new BeatListener(beat, song);
textFont(createFont("Helvetica", 16));
textAlign(CENTER);
arduino.pinMode(ledPin, Arduino.OUTPUT);
arduino.pinMode(ledPin2, Arduino.OUTPUT);
arduino.pinMode(ledPin3, Arduino.OUTPUT);
}
void draw() {
background(0);
fill(255);
if(beat.isKick()) {
arduino.digitalWrite(ledPin, Arduino.HIGH);
kickSize = 32;
}
if(beat.isSnare()) {
arduino.digitalWrite(ledPin2, Arduino.HIGH);
snareSize = 32;
}
if(beat.isHat()) {
arduino.digitalWrite(ledPin3, Arduino.HIGH);
hatSize = 32;
}
arduino.digitalWrite(ledPin, Arduino.LOW);
arduino.digitalWrite(ledPin2, Arduino.LOW);
arduino.digitalWrite(ledPin3, Arduino.LOW);
textSize(kickSize);
text("KICK", width/4, height/2);
textSize(snareSize);
text("SNARE", width/2, height/2);
textSize(hatSize);
text("HAT", 3*width/4, height/2);
kickSize = constrain(kickSize * 0.95, 16, 32);
snareSize = constrain(snareSize * 0.95, 16, 32);
hatSize = constrain(hatSize * 0.95, 16, 32);
}
void stop() {
song.close();
minim.stop();
super.stop();
}