#ifndef VIEWPORT_H #define VIEWPORT_H #include "ofMain.h" #include "ofxXmlSettings.h" static int bufferSize = 2048; static int oversample = 8; static int windowsize = 32; static int previewscale = 5; //make sure that windowsize*oversample*8 <= buffersize class palette { public: bool load(string &filename){ ofxXmlSettings XML; if( !XML.loadFile(filename) ){ printf("unable to load palette file\n"); }else{ colours.clear(); name=XML.getAttribute("palette","name","",0); if(XML.pushTag("palette")) { int numCols=XML.getNumTags("colour"); if (numCols){ for (int i=0;i0; } ofColor getBlend(float phase){ if (colours.size()){ float scaled=fmod(phase,1.0f)*colours.size(); int first=(int)scaled; int second=(first+1)%colours.size(); float frac=scaled-first; return colours[first].getLerped(colours[second],frac); } else return ofColor(0,0,0); } void print(){ cerr<<"printing palette: "< colours; string name; }; class vpcontrol { public: vpcontrol(){ fill=false; freq=1.0f; xshift=0; yshift=0; fscale=1.0f; wave=false; fillwave=false; thickness=1.0f; waveheight=1.0f; fade=0; left.assign(bufferSize, 0.0); right.assign(bufferSize, 0.0); volHistory.assign(400, 0.0); bufferCounter = 0; drawCounter = 0; smoothedVol = 0.0; scaledVol = 0.0; } void update(){ //lets scale the vol up to a 0-1 range scaledVol = ofMap(smoothedVol, 0.0, 0.17, 0.0, 1.0, true); //lets record the volume into an array volHistory.push_back( scaledVol ); //if we are bigger the the size we want to record - lets drop the oldest value if( volHistory.size() >= 400 ){ volHistory.erase(volHistory.begin(), volHistory.begin()+1); } } bool fill; float freq; int xshift,yshift; float fscale,scale; bool wave,fillwave; float thickness,waveheight; uint8_t fade; vector left; vector right; vector volHistory; int bufferCounter; int drawCounter; float smoothedVol; float scaledVol; }; class viewport { public: viewport(); viewport(int _w,int _h,int _ox,int _oy,int _num); virtual ~viewport(); void setup(int _w,int _h,int _ox,int _oy,int _num); void drawport(vpcontrol &control); void draw(uint8_t brightness,float scale=1.0f); ofFbo rb1,rb2; palette Palette; int w,h; protected: private: int x,y,bw,bh,ox,oy,num; float seed; }; #endif // VIEWPORT_H