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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
#pragma once
#include "ofMain.h"
#include "ofxHelios.h"
#include "ofxAChaoslib.h"
#include "lineTransformer.h"
//This is included only as a way of getting buffer out of loaded sound.
//There are many other ways you can do that.
//This player includes a version of kissFFT. You can remove the one included in Gist.
//https://github.com/borg/ofxOpenALSoundPlayer
#include "ofxOpenALSoundPlayer.h"
#include "ofxMidi.h"
#include "ofxGui.h"
//Slightly modified to add a dynamic getVariable method to be able to plot based on
//gist feature list
//https://github.com/local-projects/ofxHistoryPlot
#include "ofxHistoryPlot.h"
#include "ofxGist.h"
//audioplot draws from 0 to ofGetWidth
//change to -ofGetWidth/2 to ofGetWidth/2
class Audioplotter{
//store and draw a numbr of audio samples
//how best to handle transforms - maybe pass in a transform to be added to 2nd and subsequent
//how best to handle length of history data - fixed number that can be set, or line budget?
public:
Audioplotter(int _size=1,bool _joined=true,bool _bars=false,int _width=2){
setup(_size,_joined,_bars,_width);
}
void setup(int _size=1,bool _joined=true,bool _bars=false,int _width=2){
set_size(_size);
set_joined(_joined);
set_bars(_bars);
set_width(_width);
startColour=ofColor(255,255,255);
endColour=ofColor(0,0,0);
attractor.setup();
}
void set_size(int _size){
history_size=_size;
}
void set_joined(bool _joined){
joined=_joined;
}
void set_bars(bool _bars){
bars=_bars;
}
void set_width(int _width){
width=_width;
}
void set_colours(const ofColor _start,const ofColor _end){
startColour=_start;
endColour=_end;
}
colourPolyline compute_chaos(colourPolyline& poly,float colourFade=1.0f){
colourPolyline tempPoly;
for (int i=0;i<poly.size();i++){
REAL iv[6]={poly[i].x,poly[i].y,chaos_a,chaos_b,chaos_k,chaos_p};
//ofLog() << i<<": calculating chaos with: "<<poly[i].x<<" "<<poly[i].y<<" "<<attractor.a<<" "<<attractor.b<<" "<<attractor.k<<" "<<attractor.p;
attractor.set(iv);
attractor.calc();
//ofLog() << i<<": got points: "<<attractor.nx<<" "<<attractor.ny;
tempPoly.addVertex(ofPoint(attractor.nx,attractor.ny),poly.getColourAt(i)*colourFade);
}
return tempPoly;
}
vector <colourPolyline> output(const ofMatrix4x4 xform=ofMatrix4x4(1.0f,0.0f,0.0f,0.0f,
0.0f,1.0f,0.0f,0.0f,
0.0f,0.0f,1.0f,0.0f,
0.0f,0.0f,0.0f,1.0f),
float scale=1.0f,
float decay=-1.0f){
//destructive or non?
float fadefactor=decay<0.0f?1.0f-(1.0f/history_size):decay;
vector <colourPolyline> outdata;
for (int i=0;i<data.size();i++){
vector <colourPolyline> newdata;
for (int j=0;j<data[i].size();j++){
colourPolyline line=lineTransformer::polyLineTransform(xform,data[i][j]); //,fadefactor);
line.setColour((line.getColourAt(0)*fadefactor)+(((ofColor)endColour)*(1.0f-fadefactor)));
if (usechaos) {
colourPolyline chaosline=compute_chaos(line); //,fadefactor);
line.mix(chaosline,chaosamount);
}
//ofLog() << "set colour to "<<col;
newdata.push_back(line);
outdata.push_back(line);
}
data[i]=newdata;
}
return outdata;
}
void addpoints(vector <float> &audio){
int num=min((int)num_points,(int)audio.size());
int step=audio.size()/(num+1);
vector <colourPolyline> newdata;
if (joined){
colourPolyline line;
if (bars){
for (int i=0;i<num-1;i++){
line.addVertex(((step*(i+1))*ofGetWidth())/audio.size(),audio[step*(i+1)]*ofGetHeight(),startColour);
line.addVertex(((step*(i+2))*ofGetWidth())/audio.size(),audio[step*(i+1)]*ofGetHeight(),startColour);
line.addVertex(((step*(i+2))*ofGetWidth())/audio.size(),audio[step*(i+2)]*ofGetHeight(),startColour);
}
}
else {
for (int i=0;i<num;i++){
line.addVertex(((step*(i+1))*ofGetWidth())/audio.size(),audio[step*(i+1)]*ofGetHeight(),startColour);
}
}
newdata.push_back(line);
}
else{
for (int i=0;i<num;i++){
colourPolyline line;
line.addVertex(((step*(i+1))*ofGetWidth())/audio.size(),audio[step*(i+1)]*ofGetHeight(),startColour);
line.addVertex(((step*(i+1))*ofGetWidth())/audio.size()+width,audio[step*(i+1)]*ofGetHeight(),startColour);
newdata.push_back(line);
}
}
data.insert(data.begin(),newdata);
while (data.size()>history_size) {
data.pop_back();
}
}
int numpoints(){
int num=0;
for (auto d=data.begin();d!=data.end();d++){
num+=d->size();
}
return num;
}
ofParameter<bool> joined;
ofParameter<bool> bars;
ofParameter<int> width;
ofParameter<int> history_size;
ofParameter<int> num_points;
ofParameter<ofColor> startColour;
ofParameter<ofColor> endColour;
ofParameter<bool> usechaos;
ofParameter<float> chaosamount;
ofParameter<float> chaos_a;
ofParameter<float> chaos_b;
ofParameter<float> chaos_k;
ofParameter<float> chaos_p;
private:
vector < vector<colourPolyline>> data;
AChaosIkeda attractor;
};
class ofApp : public ofBaseApp, public ofxMidiListener{
public:
void setup();
void update();
void draw();
void exit();
void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
void newMidiMessage(ofxMidiMessage& eventArgs);
void updateOutput(ofEventArgs & args);
void drawOutput(ofEventArgs & args);
void outputKeyPressed(ofKeyEventArgs & args);
void outputKeyReleased(ofKeyEventArgs & args);
void outputMouseDragged(ofMouseEventArgs & args);
void outputMousePressed(ofMouseEventArgs & args);
void outputMouseReleased(ofMouseEventArgs & args);
void outputWindowResized(ofResizeEventArgs &resizeargs);
ofSoundStream soundStream;
ofxOpenALSoundPlayer player;
void processAudio(float * input, int bufferSize, int nChannels);
void audioIn(float * input, int bufferSize, int nChannels);
vector<float>fftSmoothed;
vector <float> left;
vector <float> right;
vector <float> centre;
vector <float> volHistory;
vector<float>mfccSmoothed;
float mfccMax;
int bufferSize;
int sampleRate;
bool useMic;
bool isPaused;
void clear();
void loadSong(string str);
vector<ofxHistoryPlot *>plots;
map<string,ofxHistoryPlot *>plotMap;
ofxHistoryPlot* addGraph(string varName,float max,ofColor color);
ofxGist gist;
void onNoteOn(GistEvent &e);
void onNoteOff(GistEvent &e);
int noteOnRadius;
bool showMFCC;
vector<ofxHistoryPlot *>mfccPlots;
ofxHelios laser;
Audioplotter plotter;
ofxPanel gui;
ofParameter<bool> fft;
ofParameter<float> scalePlot;
ofParameter<float> decayPlot;
ofParameter<ofVec2f> xform;
ofParameter<float> rotate;
ofParameter<ofVec2f> scale;
ofxPanel chaosgui;
ofxPanel lasergui;
ofParameter<int> intensity;
ofParameter<int> subdivide;
ofParameter<int> blank_num;
ofParameter<float> max_angle;
//======================================= //positioning interface
ofParameter<bool> drawWarpFrame;
glm::vec2 warpframe[4];
int select_warpframe;
float outputScale;
};
|