1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
#ifndef VIEWPORT_H
#define VIEWPORT_H
#include "ofMain.h"
#include "ofxXmlSettings.h"
static int bufferSize = 1024;
static int oversample = 4;
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;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;
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 <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,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
|