Here's the whole code: It may be a bit difficult, and I probably didn't do everything the most efficient way because I'm still pretty new to processing and programmin, so I'm just trying to figure it all out. Let me know if you can see my issue...the place I have issues is when I run the program in full screen and press "@" and let it run for a minute.
Thanks for your help!
// !do not delete the line above, required for linking your tweak if you re-upload
// Created by Anton Pugh
// Learning Processing
// Programmer:Ian McReynolds (IM)
// Date: 05/14/2013
// Status Emotion Visualizer
// ----------------------------------------------------- (IM)
// Psudocode:
// 1. Add music player
// 2. Add songs to be played
// 3. Allow song to be changed with Arrow Keys
// 4. Get music output vulues
// 5. Draw multiple audio visualizers
// 6. Make each visualizer based on the music
// 7. Allow visualizers to be interchanged with keys
// 8. Add camera to allow viewing from different perspectives
// 9. Make camera move based on keys
// 10. Allow for resizing of screen and fullscreen
// ----------------------------------------------------- (IM)
// Description: Here is the opportunity to listen to your favorite Jam
// and watch the beat and volume of the song in many different ways. Change
// the song, change the visualizer, and even change where you watch from.
// This is an interactive audio visualizer you've never seen before. Just press
// the "UP" key to get started.
// ----------------------------------------------------
import ddf.minim.analysis.*;
import ddf.minim.*;
///// SET GLOBAL VARIABLES ///// (IM)
int track=0; // Track Number (IM)
int centerX = -5; //
int centerY = 30; //
int centerZ =-30; // Camera (IM)
int eyeX = 0; // Variables
int eyeY = 20; //
float eyeZ = 12000; //
int vis =1; // Visualizer Variable (IM)
float visName;
float vis1, vis2, vis3, vis3Alt, vis4, vis5, vis6;
color waveColor = color(0); // Wave Color (IM)
color black = color(0); // Color Variables (IM)
color white = color(255);
float color1;//
float strokeWeight1;
float diameter;
float band; //
float iMax=200; //
int xS = 60; // Object/Array (IM)
int bW =10; // Variables
int dF = 10; //
int Spacing = 1; //
int rotX; //
int rotY; // Rotation Variables (IM)
int rotZ = 900; //
float rzc = 0;
float rzc1 = 0;
float ryc= 0;
///// Set-Up Minim Player /////
// Declare a new Minim object which will allow us to play and
// analyze music. If you want to use the computer sound card
// output, leave code as is, otherwise comment out the AudioInput
// line and uncomment the AudioPlayer line.
Minim minim;
AudioPlayer player, song1, song2, song3, song4, song5, song6; // (IM)
FFT fft;
void setup() {
size(1200, 800, P3D); // Set window size (IM)
if (frame != null) {
frame.setResizable(true); // Allow screen to be resized (IM)
}
frameRate(60); // Set FrameRate (IM)
///// Start Minim Player /////
minim = new Minim(this);
// Insert Audio Files (IM)
// Wave files work best, some iTunes mp3's cause error
song1 = minim.loadFile("Sunlight.wav", 512);
song2 = minim.loadFile("Alive.wav", 512);
song3 = minim.loadFile("annArborPart2.mp3", 512);
song4 = minim.loadFile("Explosions.wav", 512);
song5 = minim.loadFile("Demons.wav", 512);
song6 = minim.loadFile("Stellamara.wav", 512);
fft = new FFT(song1.bufferSize(), song1.sampleRate());
fft.window(FFT.HAMMING);
}
void keyPressed() {
///// Change Song w/ Arrow Keys /////
// Re-loop songs to start them from the beginning when you change
// to a new track
if (keyCode==UP) {
track += 1; //
song1.loop(); //
song2.loop(); //
song3.loop(); // Go to next song
song4.loop(); //
song5.loop(); //
song6.loop(); //
}
if (keyCode==DOWN) {
track-=1;
song1.loop(); //
song2.loop(); //
song3.loop(); // Go to previous song
song4.loop(); //
song5.loop(); //
song6.loop(); //
}
///// MOVE CAMERA CENTER POINTS WITH KEYS 0, 2, 4, 5, 6, and 8 ///// (IM)
if (key=='2') { //
centerY +=150; //
} // Center - Y
if (key=='8') { //
centerY -=150; //
}
if (key=='4') { //
centerX -= 150; //
} // Center - X
if (key=='6') { //
centerX+=150; //
}
if (key=='5') { //
centerZ -= 150; //
} // Center - Z
if (key=='0') { //
centerZ+=150; //
}
///// MOVE CAMERA EYE WITH KEYS Q, W, A, S, Z, and X ///// (IM)
if (key=='s') { //
eyeX -= 150; //
} // Eye - X
if (key=='a') { //
eyeX+=150; //
}
if (key=='w') { //
eyeY += 150; //
} // Eye - Y
if (key=='x') { //
eyeY-=150; //
}
if (key=='q') { //
eyeZ -= 150; //
} // Eye - Z
if (key=='z') { //
eyeZ+=150; //
}
///// INCREASE "rotX" BY PRESSING THE "+" KEY ///// (IM)
// Only works on visualizer 1
if (key=='+') {
rotZ+=1;
}
///// RESET ARRAY ROTATION BY PRESSING "SHIFT" & "r" or "R" (IM)
if (key=='R') {
rotX=0;
rotY=0;
rotZ=900;
}
///// CHANGE VISUALIZER WITH KEYS !, @, #, $, %, ^, and & (1-7 across the top + "SHIFT") ///// (IM)
if (key=='!') {
vis=1; //
visName =1; //
centerX = -5; //
centerY = 30; //
centerZ =-30; // Visualizer 1 (Starry Skies)
eyeX = 0; // Keys = "!" ("SHIFT" + "1" at the top)
eyeY = 20; //
eyeZ = 12000; //
rotZ = 900; //
color1 = 255; //
}
if (key=='@') {
vis=2; //
visName=2; //
eyeX=width/2; //
eyeY=height/2; // Visualizer 2
eyeZ=1000; // Keys = "@" ("SHIFT" + "2" at the top)
centerX=width/2; //
centerY=height/2; //
centerZ=0; //
}
if (key =='#') {
vis =3; //
visName = 3; //
eyeX=width/2; //
eyeY=height/2+300; // Visualizer 3
eyeZ= -300; // Keys = "#" ("SHIFT" + "3" at the top)
centerX=width/2; //
centerY=-300; //
centerZ=0; //
}
if (key =='$') {
vis =3;
visName = 3.1; //
eyeX= 1050; //
eyeY= 470; // Visualizer 3 - Alternate View
eyeZ= 950; // Keys = "$" ("SHIFT" + "4" at the top)
centerX=145; //
centerY=30; //
centerZ=-29150; //
}
if (key =='%') {
vis =4; //
visName = 4; //
eyeX=1050; //
eyeY=470; // Visualizer 4
eyeZ= 950; // Keys = "%" ("SHIFT" + "5" at the top)
centerX=145; //
centerY=30; //
centerZ=-29150; //
}
if (key =='^') {
vis=5;
visName = 5; //
eyeX=width/2; //
eyeY=height/2; // Visualizer 5
eyeZ= -400; // Keys = "^" ("SHIFT" + "6" at the top)
centerX=width/2; //
centerY=height/2; //
centerZ=0; //
}
if (key =='&') {
translate(width/2, height/2, 0);
vis= 6; //
visName = 6; //
eyeX=+width/6; //
eyeY=0; // Visualizer 6
eyeZ= 200; // Keys = "&" ("SHIFT" + "7" at the top)
centerX=0+width/6; //
centerY=0; //
centerZ=0; //
translate(-(width/2), -(height/2));
}
}
///// ALLOW rotX AND rotY TO BE CHANGED BY DRAGGING THE MOUSE ///// (IM)
// Only works for visualizer 1
void mouseDragged() {
rotX=mouseX;
rotY=mouseY;
}
///// Begin Draw Routine /////
void draw() {
smooth();
background(128); // Set Background to black (IM)
if (vis == 1) {
rzc1-= PI/128;
rotateZ(rzc1);
}
if (visName == 3) {
ryc+= PI/256;
}
// Next line can be un-commented to help locate camera centers
// point(centerX, centerY, centerZ);
if (band<.01) {
rzc-= (PI/252);
}
else {
rzc += band*band*band*(PI/8)*5;
}
///// PLAY SONGS BASED ON CURRENT TRACK//// (IM)
// Each if pauses all songs except the one which is supposed to play
// It then plays the song which is set for the current track
// Also displays all visualizers
if (track < 1 || track > 6 ) { //
song1.pause(); //
song2.pause(); //
song3.pause(); // Pause all songs if track is
song4.pause(); // less than 1 or greater than 6
song5.pause(); //
song6.pause(); //
}
if (track==1) { //
song1.play(); //
song2.pause(); //
song3.pause(); // Pause 2,3,4,5,6
song4.pause(); // Play Song1
song5.pause(); //
song6.pause(); //
fft.forward(song1.mix); //
}
if (track==2) { //
song1.pause(); //
song2.play(); //
song3.pause(); // Pause 1,3,4,5,6
song4.pause(); // Play Song2
song5.pause(); //
song6.pause(); //
fft.forward(song2.mix); //
}
if (track==3) { //
song1.pause(); //
song2.pause(); //
song3.play(); // Pause 1,2,4,5,6
song4.pause(); // Play Song3
song5.pause(); //
song6.pause(); //
fft.forward(song3.mix); //
}
if (track==4) { //
song1.pause(); //
song2.pause(); //
song3.pause(); // Pause 1,2,3,5,6
song4.play(); // Play Song4
song5.pause(); //
song6.pause(); //
fft.forward(song4.mix); //
}
if (track==5) { //
song1.pause(); //
song2.pause(); //
song3.pause(); // Pause 1,2,3,4,6
song4.pause(); // Play Song5
song5.play(); //
song6.pause(); //
fft.forward(song5.mix); //
}
if (track==6) { //
song1.pause(); //
song2.pause(); //
song3.pause(); // Pause 1,2,3,4,5
song4.pause(); // Play Song6
song5.pause(); //
song6.play(); //
fft.forward(song6.mix); //
}
///// SET UP VISUALIZER ARRAY /////
// GET MAGNITUDE OF FFT AT BAND i
// I added and changed the variables here
for (int i = 0; i < iMax; i++) {
band = fft.getBand(i/dF);
///// DRAW VISUALIZERS ///// (IM)
// Visualizer 1 (IM)
if (vis == 1) {
bW = 10;
xS = 60;
dF =10;
Spacing = 1;
diameter = constrain((bW*band), 0, 2500);
fill(black, 50);
//fill(255, 150);
if (band>5) {
strokeWeight1 = 2;
}
else {
strokeWeight1 = 0;
}
strokeWeight(constrain(strokeWeight1, 0, 3));
stroke(black);
rotateZ(rotZ);
pushMatrix();
pushMatrix();
rotateY(rotY);
ellipse(xS*i, width/2, diameter, diameter);
popMatrix();
popMatrix();
}
// Visualizer 2 (IM)
if (vis == 2) {
rotateZ(0);
iMax = 12;
xS = 60;
bW = 10;
dF = 1;
stroke(255, 120, 0);
if (band>5) {
strokeWeight(constrain(band, 0, 1));
}
else {
noStroke();
}
noFill();
pushMatrix();
// Draw Array and Rotate
translate(width/2, height/2, 0);
rotateZ(rzc);
pushMatrix();
ellipse(xS*i+20, 0, bW*band, bW*band);
rotateZ(PI/2);
ellipse(xS*i+20, 0, bW*band+10, bW*band+10);
rotateZ(PI/2);
ellipse(xS*i+20, 0, bW*band, bW*band);
rotateZ(PI/2);
ellipse(xS*i+20, 0, bW*band+10, bW*band+10);
rotateZ(PI/2);
ellipse(xS*i+20, 0, bW*band, bW*band);
translate(0, 0, 100);
noFill();
rotateZ((3*PI)/4);
pushMatrix();
translate(0, 0, 5);
stroke(black);
if (band>5) {
strokeWeight(constrain(band, 0, 3));
}
else {
noStroke();
}
ellipse(xS*i+20, 0, bW*band, bW*band);
rotateZ(PI/2);
ellipse(xS*i+20, 0, bW*band, bW*band);
rotateZ(PI/2);
ellipse(xS*i+20, 0, bW*band, bW*band);
rotateZ(PI/2);
ellipse(xS*i+20, 0, bW*band, bW*band);
popMatrix();
translate(-width/2, -height/2, -100);
popMatrix();
popMatrix();
}
// Visualizer 3 (IM)
if (vis == 3) {
// stroke(0, 0, 255);
rotateZ (0);
xS = 10;
dF = 1;
bW= 30;
iMax=200;
band =constrain(band, 0, 20);
stroke(black);
if (visName == 3.1) {
fill(black, 50);
}
else if (visName==3) {
noFill();
strokeWeight(1);
xS=22;
}
///// DRAW 3D RECTANGLE BASED ON BAND VALUE //// (IM)
// Front
pushMatrix();
if (visName==3) {
translate(200, height/2, 0);
rotateY(ryc);
translate(-(200), -height/2, 0);
}
else if (visName==3.1) {
rotateY(0);
}
constrain(bW*band, 0, 20);
pushMatrix();
beginShape();
vertex(xS*i-10, height/2 - bW*band, -width/10);
vertex(xS*i+10, height/2 - bW*band, -width/10);
vertex(xS*i+10, height/2, -width/10);
vertex(xS*i-10, height/2, -width/10);
vertex(xS*i+10, height/2 - bW*band, -width/10);
endShape();
// Back
beginShape();
vertex(xS*i+10, height/2 - bW*band, -width/10-10);
vertex(xS*i+10, height/2, -width/10-10);
vertex(xS*i-10, height/2, -width/10-10);
vertex(xS*i-10, height/2 - bW*band, -width/10-10);
vertex(xS*i+10, height/2 - bW*band, -width/10-10);
endShape();
// Right
beginShape();
vertex(xS*i+10, height/2 - bW*band, -width/10);
vertex(xS*i+10, height/2 - bW*band, -width/10-10);
vertex(xS*i+10, height/2, -width/10-10);
vertex(xS*i+10, height/2, -width/10);
vertex(xS*i+10, height/2 - bW*band, -width/10);
endShape();
beginShape();
vertex(xS*i-10, height/2 - bW*band, -width/10);
vertex(xS*i-10, height/2 - bW*band, -width/10-10);
vertex(xS*i-10, height/2, -width/10-10);
vertex(xS*i-10, height/2, -width/10);
vertex(xS*i-10, height/2 - bW*band, -width/10);
endShape();
// Bottom
beginShape();
vertex(xS*i-10, height/2, -width/10);
vertex(xS*i-10, height/2, -width/10-10);
vertex(xS*i+10, height/2, -width/10-10);
vertex(xS*i+10, height/2, -width/10);
vertex(xS*i-10, height/2, -width/10);
endShape();
popMatrix();
popMatrix();
}
// Visualizer 4 (IM)
else if (vis == 4) {
noFill();
// stroke(0, 0, 255);
rotateZ (0);
xS = 10;
dF = 1;
bW= 30;
Spacing = 3;
iMax=200;
stroke(black, random(255)); // Top
beginShape();
vertex(xS*i-10, 23*height/26-bW*band, -width/10);
vertex(xS*i-10, 23*height/26-bW*band, -width/10-10);
vertex(xS*i+10, 23*height/26-bW*band, -width/10-10);
vertex(xS*i+10, 23*height/26-bW*band, -width/10);
vertex(xS*i-10, 23*height/26-bW*band, -width/10);
endShape();
}
// Visualizer 5 (IM)
else if (vis==5) {
stroke(0, 175);
band = constrain(band, 0, 30);
xS = 10;
dF = 1;
bW= 30;
Spacing = 3;
iMax=200;
strokeWeight(band*2); // Change strokeWeight based on band (IM)
noFill();
ellipse(width/2, height/2, band*15, band*15); // Ellipse with size based on band (IM)
//println(band);
stroke(0);
//strokeWeight(band*2);
band=constrain(band, 0, 200);
translate(0, 0, band*4);
//ellipse(width/2, height/2, band*20, band*20);
}
strokeWeight(1);//(IM)
}
// Visualizer 6 (IM)
if (vis==6) {
for (int p = 0; p < song1.bufferSize() - 1; p++)
{
noFill();
// strokeWeight(band*band);
bW = 10;
xS = 60;
dF =10;
Spacing = 1;
iMax=500;
band = constrain(band, 0, 50);
strokeWeight(constrain(band*band, .1, 3));
// Draw the wave depending on what track is playing (IM)
if (track==1) {
stroke(waveColor);
line(p, song1.left.get(p)*band*10, p+1, song1.left.get(p+1)*band*10);
}
else if (track==2) {
stroke(waveColor);
line(p, 50 + song2.left.get(p)*band*10, p+1, 50 + song2.left.get(p+1)*band*10);
}
if (track==3) {
stroke(waveColor);
line(p, 50 + song3.left.get(p)*band*10, p+1, 50 + song3.left.get(p+1)*band*10);
}
else if (track==4) {
stroke(waveColor);
line(p, 50 + song4.left.get(p)*band*10, p+1, 50 + song4.left.get(p+1)*band*10);
}
if (track==5) {
stroke(waveColor);
line(p, 50 + song5.left.get(p)*band*10, p+1, 50 + song5.left.get(p+1)*band*10);
}
else if (track==6) {
stroke(waveColor);
line(p, 50 + song6.left.get(p)*band*10, p+1, 50 + song6.left.get(p+1)*band*10);
}
}
}
// Hide the object when band is below 1.5 (IM)
if (band <1.5) {
noStroke();
fill(0);
}
else {
stroke(random(255), random(255), random(255));
}
// Translate for camer location (IM)
//(0, 0, -100);
strokeWeight(1);
// Add camera view (IM)
camera(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, 0, 1, 0);
// println to locate various locations/values (IM)
println("Track= "+track+" eX= "+eyeX+ " eY= "+eyeY+ " eZ= "+eyeZ+ " cX= "+centerX+ " cY= "+centerY+ " cZ= "+centerZ+" rotZ = " + rotZ+ " band = " + band +" visName = "+visName +" mouseX = "+mouseX+" mouseY = "+mouseY);
}
///// STOP MINIM /////
void stop() {
minim.stop();
super.stop();
}