#pragma once #include "ofMain.h" #include "ofxHelios.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" 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){ set_size(_size); set_joined(_joined); colour=ofColor(255,255,255); } void set_size(int _size){ history_size=_size; } void set_joined(bool _joined){ joined=_joined; } vector 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 outdata; for (int i=0;i newdata; for (int j=0;j &audio,int number){ int num=min(number,(int)audio.size()); int step=audio.size()/(num+1); vector newdata; if (joined){ colourPolyline line; for (int i=0;ihistory_size) { data.pop_back(); } } int numpoints(){ int num=0; for (auto d=data.begin();d!=data.end();d++){ num+=d->size(); } return num; } private: vector < vector> data; bool joined; int history_size; ofColor colour; }; 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); vectorfftSmoothed; vector left; vector right; vector centre; vector volHistory; vectormfccSmoothed; float mfccMax; int bufferSize; int sampleRate; bool useMic; bool isPaused; void clear(); void loadSong(string str); vectorplots; mapplotMap; ofxHistoryPlot* addGraph(string varName,float max,ofColor color); ofxGist gist; void onNoteOn(GistEvent &e); void onNoteOff(GistEvent &e); int noteOnRadius; bool showMFCC; vectormfccPlots; ofxHelios laser; Audioplotter plotter; ofxPanel gui; ofParameter joined; ofParameter numPlots; ofParameter scalePlot; ofParameter decayPlot; ofParameter xform; };