forked from AdamCollins/IgNite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
igNite.pde
147 lines (110 loc) · 3.41 KB
/
igNite.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
boolean fileLoaded = false;
color blue = #335755;
color white = #EDDDBB;
color grey = #3D3B38;
color black = #0C0A0B;
PFont Arial;
PImage bckgrd;
float songProgress;
float volume = 0.5;
float volumeSliderX;
int playButtonAlpha = 150;
int loadFileAlpha = 150;
int progressBarAlpha = 150; // bar
int soundVisionAlpha = 50; // visual;
String state = "PLAY";
String title = "";
import ddf.minim.*;
import ddf.minim.analysis.*;
AudioMetaData meta;
Minim minim;
AudioPlayer player;
FFT fft;
PImage fai_iconi;
PGraphics fai_icong;
String fai_filename;
void setup() {
size(500, 200);
Arial = loadFont("data/Arial.vlw");
bckgrd = loadImage("background.png");
volumeSliderX = width-30;
minim = new Minim(this);
}
void draw() {
background(white);
smooth(28);
for (int i = 0; i<900; i+=200) {
image(bckgrd, i, 0); //Stamps background Image.
}
if (fileLoaded) {
soundVision(); //Calls visualizer function
player.setGain(volume);
fill(0, 0, 0, 255);
textSize(21); //Prints title out
textAlign(CENTER);
text(title, width/2, 30);
}
buttons(); //controls other smaller functions.
}
void mouseReleased() {
if (fileLoaded && player.position()>=player.length()) {
state = "PLAY"; //Resets song when it finishes.
}
if (mouseX>0 && mouseX<80 && mouseY < 40) {
if (state == "PLAY" && fileLoaded) {
state = "PAUSE"; //Plays song.
player.play();
player.setVolume(volume); //~~~~~~~~~~~~~~~~~~Volume?------------------\\
} else if (state == "PAUSE") {
state = "PLAY"; //Pauses song.
player.pause();
}
}
if (mouseX>width-110 && mouseX<width && mouseY < 40) {
selectInput("Select a file to process:", "fileSelected"); //Calls selectInput if button pressed.
}
}
void fileSelected(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
} else {
String filepath = selection.getAbsolutePath();
println("User selected " + filepath);
// load file here
player = minim.loadFile(filepath);
fft = new FFT( player.bufferSize(), player.sampleRate());
meta = player.getMetaData();
fileLoaded = true;
title = meta.title();
}
}
void soundVision() {
fft.forward( player.mix );
fill(#45ADA8, soundVisionAlpha);
stroke(grey);
strokeWeight(1);
if (progressBarAlpha<200 && soundVisionAlpha<255) {
soundVisionAlpha+=3;
} else if (soundVisionAlpha>50) {
soundVisionAlpha-=5;
}
for (int i = 0; i < fft.specSize (); i+=5) {
// draw the line for frequency band i, scaling it up a bit so we can see it
colorMode(HSB);
//stroke(i, 255, 255);
//line( i, height, i, height - fft.getBand(i)*8 );
rect(i+width/2, height - fft.getBand(i)*8, 10, height);
//ellipse(i+width/2,height + 10 - fft.getBand(i)*5, 10,10);
}
for (int i = 0; i < fft.specSize (); i+=5) {
// draw the line for frequency band i, scaling it up a bit so we can see it
colorMode(HSB);
//stroke(i, 255, 255);
// strokeWeight(10);
// stroke(#45ADA8,50);
//fill(#45ADA8,20);
//line( i+width/2, height, i+width/2, height - fft.getBand(i)*8 );
rect(i, height - fft.getBand(i)*8, 10, height);
//ellipse(i,height + 10 - fft.getBand(i)*5, 10,10);
}
}