-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmixtape_visual.pde
164 lines (150 loc) · 3.38 KB
/
mixtape_visual.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
import ddf.minim.*;
import ddf.minim.analysis.*;
Minim minim;
AudioPlayer player;
AudioMetaData meta;
BeatDetect beat;
FFT spectrum;
String [] song = {"straight from the start.mp3", "pt1.mp3", "pt2.mp3", "crookeddreams.mp3", "yah.mp3", "wasabi.mp3", "interlude.mp3", "crazy.mp3"};
PImage cover;
int txtsz = 30;
boolean pause =false;
int current = 0;
int past = 0;
String a;
boolean rep = false;
boolean shuf = false;
void setup()
{
size(800, 800);
minim = new Minim(this);
player = minim.loadFile(song[0], 2048);
cover = loadImage("mixtape.jpg");
meta = player.getMetaData();
spectrum = new FFT(player.bufferSize(), player.sampleRate());
}
void draw() {
back();
isPlaying();
spectrum.forward(player.mix);
freq();
nextSong();
currentSong();
println("shuf", "c p", "pause");
println(shuf, current, past, pause);
}
void currentSong() {
textSize(30);
fill(255);
ellipse(130, 90+txtsz*current, 10, 10);
for (int i = 0; i < song.length; i++) {
stroke(0);
//text(i+1+") "+ song[i].substring(0, song[i].length() - 4), 150, 100 + txtsz*i);
text(i+1+")"+ "????????", 150, 100 + txtsz*i);
}
}
void back() {
image(cover, 0, 0);
fill(40, 40, 40, 70);
rect(0, 0, width, height);
}
void isPlaying() {
if (pause == true) {
player.pause();
} else {
player.play();
}
}
void nextSong() {
if (((!player.isPlaying() && !pause) && (!shuf))) {
player.pause();
if (!shuf){
current+=1;
}
else{
past = current;
//println("works");
while (past == current){
current = int(random(0.0, float(song.length)));
}
past = current;
}
player = minim.loadFile( song[current], 2048);
player.play();
}
if (current < 0) {
current = song.length-1;
}
}
void freq() {
stroke(255);
strokeWeight(4);
fill(255);
for (int i = 0; i < 100 - 1; i++) {
if (spectrum.getBand(i)*2 > 200) {
line((i*5)+150, 650, (i*5)+150, 450);
} else {
line((i*5)+150, 650, (i*5)+150, 650 - (spectrum.getBand(i)*2));
}
}
}
void keyReleased() {
//songChange();
if ((key==' ') && (pause == false)) {
pause = true;
} else {
pause = false;
}
if ((keyCode == DOWN) || (keyCode == RIGHT)) {
player.pause();
if (!shuf){
current+=1;
}
else{
past = current;
//println("works");
while (past == current){
current = int(random(0.0, float(song.length)));
}
past = current;
}
if (current < 0) {
current = song.length-1;
}
a = song[current];
player = minim.loadFile( a, 2048);
player.play();
}
if (keyCode == UP) {
player.pause();
current-= 1;
if (current < 0) {
current = song.length-1;
}
a = song[current];
player = minim.loadFile( a, 2048);
player.play();
}
if (keyCode == LEFT) {
player.pause();
a = song[current];
player = minim.loadFile( a, 2048);
player.play();
}
//shuffle
if ((key == 's') && (!shuf)){
shuf = true;
}
else if ((key == 's') && (shuf)){
shuf = false;
}
}
void repeat() {
if (((rep) && (current == song.length - 1)) && (!player.isPlaying())) {
current = 0;
player.pause();
a = song[current];
player = minim.loadFile( a, 2048);
player.play();
}
}