summaryrefslogtreecommitdiff
path: root/src/viewport.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/viewport.h')
-rwxr-xr-xsrc/viewport.h120
1 files changed, 99 insertions, 21 deletions
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;i<numCols;i++) {
- palette.push_back(ofColor.fromHex(ofFromHex(XML.getAttribute("colour","hex",0x00,0))));
+ if (numCols){
+ for (int i=0;i<numCols;i++) {
+ ofColor c;
+ c.setHex(ofHexToInt(XML.getAttribute("colour","hex","000000",i)));
+ colours.push_back(c);
+ }
+ return true;
}
}
+
+ }
+ return false;
+ }
+ void randomise(){
+ colours.clear();
+ for (int i=0;i<ofRandom(10);i++){
+ colours.push_back(ofColor(ofRandom(255),ofRandom(255),ofRandom(255)));
+ }
+ }
+ int size(){
+ return colours.size();
+ }
+ bool isLoaded(){
+ return colours.size()>0;
+ }
+ 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: "<<size()<<" colours"<<endl;
+ for (auto c:colours) cerr<<((int)c.r)<<" "<<((int)c.g)<<" "<<((int)c.b)<<endl;
+ }
+ vector<ofColor> 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<ofColor> palette;
- string palettename;
+ bool wave;
+ float thickness;
+
+ vector <float> left;
+ vector <float> right;
+ vector <float> 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;
};