From d6a8d1d93c6b5abd8b69985f182667c2994f13fd Mon Sep 17 00:00:00 2001 From: Comment Date: Wed, 29 May 2013 00:28:36 +0100 Subject: nearly ready --- src/viewport.h | 120 +++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 99 insertions(+), 21 deletions(-) (limited to 'src/viewport.h') diff --git a/src/viewport.h b/src/viewport.h index 7ab1477..b786fe9 100755 --- a/src/viewport.h +++ b/src/viewport.h @@ -4,51 +4,129 @@ #include "ofMain.h" #include "ofxXmlSettings.h" -class vpcontrol { +static int bufferSize = 1024; +static int bufferscale = 4; + +class palette { public: - vpcontrol(){ - fillgrey=false; - fillgreyfreq=1.0f; - xshift=0; - yshift=0; - fscale=1.0f; - } - void loadpalette(string &filename){ + bool load(string &filename){ ofxXmlSettings XML; if( !XML.loadFile(filename) ){ printf("unable to load palette file\n"); }else{ - palette.clear(); - palettename=XML.getAttribute("palette","name","",0); + colours.clear(); + name=XML.getAttribute("palette","name","",0); if(XML.pushTag("palette")) { int numCols=XML.getNumTags("colour"); - 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; + thickness=1.0f; + + 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 fillgrey; - float fillgreyfreq; + bool fill; + float freq; int xshift,yshift; float fscale,scale; - vector palette; - string palettename; + bool wave; + float thickness; + + 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); + viewport(int _w,int _h,int _ox,int _oy,int _num); virtual ~viewport(); - void setup(int _w,int _h,int _ox,int _oy); + void setup(int _w,int _h,int _ox,int _oy,int _num); void drawport(vpcontrol &control); - void draw(uint8_t brightness); + void draw(uint8_t brightness,float scale=1.0f); ofFbo rb1,rb2; + palette Palette; protected: private: - int x,y,w,h,ox,oy; + int x,y,w,h,ox,oy,num; float seed; }; -- cgit v1.2.3