// MidiVizEqWatcher
// Lew Hill II
// a simple watcher for midi viz audio levels

#ifndef _MIDI_VIZ_EQ_WATCHER_
#define _MIDI_VIZ_EQ_WATCHER_

#include <GL/gl.h>
#include "RainbowLookup.h"
#include "WaterfallLookup.h"
#include "MidiVizParticle.h"
#include <vrj/Draw/OGL/GlContextData.h>
#include "MidiVizEQWatcherContextData.h"
#include <math.h>

#define NUM_BANDS 16
#define HISTORY_LENGTH 300
#define NUM_PARTICLES 100

#define MV_PI 3.1428571
#define MV_PI_RAD  MV_PI/180.0

using namespace vrj;

class MidiVizEQWatcher{

 public:

  MidiVizEQWatcher(float* bands, int* rands);
  void init();
  void contextInit();

  void storeSample();
  void drawWatcher();
  void drawBackground();
  void drawLollipop();
  void drawHistory();
  void drawDiscRoom();
  void drawDisc();
  void animateDiscs();

  void drawWaterfall();
  void drawWaterFountain();

  void drawInverse();

  void frame();
  
  void setPosition(float x, float y, float z ){
    position[0] = x;
    position[1] = y;
    position[2] = z;
  }
  
  void setRotation(float x, float y, float z){
    rotation[0] = x;
    rotation[1] = y;
    rotation[2] = z;
  }
  
  void setScale(float x, float y, float z){
    scale[0] = x;
    scale[1] = y;
    scale[2] = z;
  }
  
  void setBandsReference(float* bands, int* rands);
  
 private:
  float* eq_bands;
  float eq_bands_avg[NUM_BANDS];
  float eq_bands_slow_avg[NUM_BANDS];
  float eq_bands_diff[NUM_BANDS];

  float eq_bands_history[16][HISTORY_LENGTH];
  
  int history_index;
  
  int numbands;
  
  float position[3];
  float rotation[3];
  float scale[3];
  
  // temp variables


  RainbowLookup rainbowLookup;
  WaterfallLookup waterfallLookup;
  GlContextData<MidiVizEQWatcherContextData> contextData;

  float discAngles[NUM_BANDS];
  float discColor[NUM_BANDS];
  float discAccel[NUM_BANDS];
  int discflip[NUM_BANDS];

  float orbitCoordinates[360][2];

  // up to 100 particles per band can be active
  MidiVizParticle waterParticles[NUM_BANDS][NUM_PARTICLES];

  // this is the integer index of the next new particle to be issued
  int nextParticle[NUM_BANDS];
  int* mRandomNumbers;
};


#endif

