import ddf.minim.*;
import ddf.minim.analysis.*;

Minim minim;
AudioPlayer s;
ddf.minim.analysis.FFT f;
  
processing.sound.SoundFile sample;  
processing.sound.SoundFile sample2;
processing.sound.SoundFile sample3;
processing.sound.SoundFile sample4;
processing.sound.Amplitude rms;
PImage img;
PShape spinner;


float zPosition;
float timePrev;
int stage;
int demoCounter;
float angle;

ArrayList<demoBase> Demos;

void setup() {
  fullScreen(P3D);
  demoCounter = 0;
  minim = new Minim(this);
  //s = minim.loadFile("Hypp_fractal_-_09_-_Vertigo.mp3");
  s = minim.loadFile("Furious Freak.mp3");
  f = new ddf.minim.analysis.FFT(s.bufferSize(), s.sampleRate());
  
  
  PImage iJ = loadImage("Juge.JPG");
  PImage iH = loadImage("Hai.jpg");
  PImage iT = loadImage("Timo.jpg");
  PImage iM = loadImage("Max.jpg");
  
  
  sample = new processing.sound.SoundFile(this, "Furious Freak.mp3");
  sample2 = new processing.sound.SoundFile(this, "Furious Freak.mp3");
  sample3 = new processing.sound.SoundFile(this, "Furious Freak.mp3");
  sample4 = new processing.sound.SoundFile(this, "Furious Freak.mp3");
  
  
  PShape spinnuri = loadShape("helicopter_2.obj");
  PShape spinner = loadShape("fidget_spinner_final123.obj");
  
  rms = new processing.sound.Amplitude(this);
  //img = loadImage("texture.png");
  spinner = loadShape("fidget_spinner_final123.obj");
    
  zPosition = 0;
  stage = 0;
  timePrev = 0;
  
  Demos = new ArrayList<demoBase>();
  Demos.add(new lineDemo(sample3));
  Demos.add(new spinnerDemo(sample, rms, img, spinner));
  Demos.add(new TravercingBall(s, f));
  Demos.add(new copterDemo(sample4, spinnuri, spinner));
  Demos.add(new Presentation(iJ, iH, iT, iM, sample2));
  
}
void draw() {
  
  float time = millis()/1000.0;
  
  switch(stage){
    case 0:   
      drawStuff();
      if(time - timePrev > 2) {
        stage = 1;
        timePrev = time;
      }
      break;
    case 1:  
      drawStuff();
      zPosition += 10;
      if(zPosition > 700) {
        stage = 2;
        timePrev = time;
      }
      break;
    case 2:
       if(Demos.size() <= demoCounter) {
         stage = 5;
       }
       else {
         demoBase demo = Demos.get(demoCounter);
         demo.playDemo();
         if(demo.isOver()) {
          stage = 3;
          timePrev = time;
          demoCounter++;
        }
      }
      break;
   case 3:  
      drawStuff();
      zPosition -= 10;
       if(zPosition < 300) {
        stage = 4;
        timePrev = time;
        angle = 0;
      }
      break;
    case 4:  
    drawStuff();
    angle += 3;
     if(angle > 89) {
      angle = 90;
      stage = 1;
      timePrev = time;
    }
    break;
    case 5: 
      exit();
    break;
  }
}

void drawStuff() {
  pushMatrix();
  background(0);
  translate(width/2, height/2, zPosition); 
  rotateY(radians(angle));
  noFill();
  stroke(255);
  box(250);
  popMatrix();
}