summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gistanalysis/addons.make2
-rw-r--r--gistanalysis/src/main.cpp46
-rw-r--r--gistanalysis/src/ofApp.cpp80
-rw-r--r--gistanalysis/src/ofApp.h47
4 files changed, 146 insertions, 29 deletions
diff --git a/gistanalysis/addons.make b/gistanalysis/addons.make
index 3ba8ea8..1b485c8 100644
--- a/gistanalysis/addons.make
+++ b/gistanalysis/addons.make
@@ -2,3 +2,5 @@ ofxGist
ofxOpenALSoundPlayer
ofxHistoryPlot
ofxHelios
+ofxMidi
+ofxGui
diff --git a/gistanalysis/src/main.cpp b/gistanalysis/src/main.cpp
index e57370b..1abb772 100644
--- a/gistanalysis/src/main.cpp
+++ b/gistanalysis/src/main.cpp
@@ -2,12 +2,46 @@
#include "ofApp.h"
//========================================================================
-int main( ){
- ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context
+int main(int argc, char *argv[]){
- // this kicks off the running of my app
- // can be OF_WINDOW or OF_FULLSCREEN
- // pass in width and height too:
- ofRunApp(new ofApp());
+
+ ofGLFWWindowSettings settings;
+
+ settings.decorated = true;
+
+ settings.width = 1024;
+ settings.height = 768 ;
+ settings.setPosition(ofVec2f(1700,0));
+ settings.resizable = false;
+
+ shared_ptr<ofAppBaseWindow> mainWindow = ofCreateWindow(settings);
+ mainWindow->setVerticalSync(false);
+
+ settings.width = 600;
+ settings.height = 900;
+ settings.setPosition(ofVec2f(0,0));
+ settings.resizable = true;
+
+ // share OpenGL resources with other windows
+ settings.shareContextWith = mainWindow;
+
+ //settings.decorated = false; //doesn't suppress FS title bar
+ shared_ptr<ofAppBaseWindow> guiWindow = ofCreateWindow(settings);
+ guiWindow->setVerticalSync(false);
+
+ shared_ptr<ofApp> mainApp(new ofApp);
+ //mainApp->setupGui();
+
+ ofAddListener(mainWindow->events().update,mainApp.get(),&ofApp::updateOutput);
+ ofAddListener(mainWindow->events().draw,mainApp.get(),&ofApp::drawOutput);
+ ofAddListener(mainWindow->events().windowResized,mainApp.get(),&ofApp::outputWindowResized);
+ ofAddListener(mainWindow->events().keyPressed,mainApp.get(),&ofApp::outputKeyPressed);
+ ofAddListener(mainWindow->events().keyReleased,mainApp.get(),&ofApp::outputKeyReleased);
+ ofAddListener(mainWindow->events().mouseDragged,mainApp.get(),&ofApp::outputMouseDragged);
+ ofAddListener(mainWindow->events().mousePressed,mainApp.get(),&ofApp::outputMousePressed);
+ ofAddListener(mainWindow->events().mouseReleased,mainApp.get(),&ofApp::outputMouseReleased);
+
+ ofRunApp(guiWindow, mainApp);
+ ofRunMainLoop();
}
diff --git a/gistanalysis/src/ofApp.cpp b/gistanalysis/src/ofApp.cpp
index 50a4be6..76e53a9 100644
--- a/gistanalysis/src/ofApp.cpp
+++ b/gistanalysis/src/ofApp.cpp
@@ -45,9 +45,11 @@ void ofApp::setup(){
}
-
-
-
+ gui.setup("panel"); // most of the time you don't need a name but don't forget to call setup
+ gui.add(numPlots.set("num plots", 1, 1, 128));
+ gui.add(scalePlot.set( "scale plot", 0.1f, 0.0f, 1.0f ));
+ gui.add(decayPlot.set( "decay", 0.9f, 0.0f, 1.0f ));
+ gui.add(xform.set("xform",ofVec2f(0,0),ofVec2f(-10,-10),ofVec2f(10,10)));
/*
@@ -73,10 +75,11 @@ void ofApp::setup(){
soundStream.setup(this,0, 1, sampleRate, bufferSize, 1);
- loadSong("passades/1 The Ninth Set-sector1:sector2pt.1.aiff");
+ loadSong("12 Ferric Appetite.aiff");
+ //loadSong("passades/1 The Ninth Set-sector1:sector2pt.1.aiff");
//loadSong("assets/sounds/Coltrane_acc_VUIMM.wav");
- plotter=Audioplotter(8);
+ plotter=Audioplotter(4,true);
}
@@ -94,6 +97,9 @@ void ofApp::onNoteOff(GistEvent &e){
//--------------------------------------------------------------
void ofApp::update(){
+}
+//--------------------------------------------------------------
+void ofApp::updateOutput(ofEventArgs& e){
@@ -106,7 +112,7 @@ void ofApp::update(){
processAudio(&output[0], bufferSize, 2);
fftSmoothed = player.getFFT();
- plotter.addpoints(centre,256);
+ plotter.addpoints(centre,numPlots);
}
}
@@ -163,12 +169,16 @@ void ofApp::update(){
noteOnRadius--;
}
}
-
//--------------------------------------------------------------
void ofApp::draw(){
ofBackground(0);
+ gui.draw();
+}
+//--------------------------------------------------------------
+void ofApp::drawOutput(ofEventArgs & args){
+ ofBackground(0);
-
+ /*
ofFill();
@@ -207,6 +217,7 @@ void ofApp::draw(){
for (int i = 0; i < right.size(); i++){
//ofLine(i,500+right[i]*waveHeight,i,500+right[i]*waveHeight+1);
}
+ */
/*
int num;
@@ -230,14 +241,14 @@ void ofApp::draw(){
}
}
- */
+
ofFill();
ofSetColor(255,0,0,200);
ofCircle(ofGetWidth()/2,ofGetHeight()/2,noteOnRadius);
- /*
+
if(!showMFCC){
@@ -261,10 +272,10 @@ void ofApp::draw(){
}
*/
- ofMatrix4x4 xform;
- xform.makeTranslationMatrix(1,5,0);
+ ofMatrix4x4 _xform;
+ _xform.makeTranslationMatrix(xform->x,xform->y,0);
- auto lines=plotter.output(xform);
+ auto lines=plotter.output(_xform,scalePlot,decayPlot);
laser.draw(lines,50);
ofTranslate(0,ofGetHeight()/2);
@@ -273,8 +284,13 @@ void ofApp::draw(){
line->draw();
}
+ ofSetWindowTitle(ofToString(ofGetFrameRate())+" fps, "+ofToString(plotter.numpoints())+" pts");
+
}
+//--------------------------------------------------------------
+void ofApp::exit() {
+}
ofxHistoryPlot* ofApp::addGraph(string varName,float max,ofColor color){
@@ -374,7 +390,13 @@ void ofApp::audioIn(float * input, int bufferSize, int nChannels){
+//--------------------------------------------------------------
+void ofApp::outputKeyPressed(ofKeyEventArgs &args){
+ keyPressed(args.key);
+
+
+}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
if(key =='f'){
@@ -408,7 +430,12 @@ void ofApp::keyPressed(int key){
showMFCC = !showMFCC;
}
}
+//--------------------------------------------------------------
+void ofApp::outputKeyReleased(ofKeyEventArgs &args){
+
+ keyReleased(args.key);
+}
//--------------------------------------------------------------
void ofApp::keyReleased(int key){
@@ -418,7 +445,12 @@ void ofApp::keyReleased(int key){
void ofApp::mouseMoved(int x, int y ){
}
-
+//--------------------------------------------------------------
+void ofApp::outputMouseDragged(ofMouseEventArgs & args){
+ //if (select_warpframe>-1){
+ // warpframe[select_warpframe]=glm::vec2(args.x,args.y);
+ //}
+}
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
if(!useMic){
@@ -428,18 +460,32 @@ void ofApp::mouseDragged(int x, int y, int button){
float t = x/(float)ofGetWidth();
gist.setThreshold(GIST_SPECTRAL_DIFFERENCE,t);
}
-
+//--------------------------------------------------------------
+void ofApp::outputMousePressed(ofMouseEventArgs & args){
+ // for (int i=0;i<4;i++){
+ // if (ofPoint(args.x,args.y).distance(warpframe[i])<25){
+ // select_warpframe=i;
+ // }
+ // }
+}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
}
-
+//--------------------------------------------------------------
+void ofApp::outputMouseReleased(ofMouseEventArgs & args){
+ //select_warpframe=-1;
+}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
+void ofApp::outputWindowResized(ofResizeEventArgs &resizeargs){
+
+}
+//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){
}
@@ -456,3 +502,5 @@ void ofApp::dragEvent(ofDragInfo dragInfo){
loadSong(paths[1]);
}
+void ofApp::newMidiMessage(ofxMidiMessage& msg) {
+}
diff --git a/gistanalysis/src/ofApp.h b/gistanalysis/src/ofApp.h
index e3ad339..44c4aa6 100644
--- a/gistanalysis/src/ofApp.h
+++ b/gistanalysis/src/ofApp.h
@@ -9,7 +9,8 @@
//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
@@ -26,6 +27,7 @@ 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;
@@ -36,9 +38,11 @@ public:
const 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)){
+ 0.0f,0.0f,0.0f,1.0f),
+ float scale=1.0f,
+ float decay=-1.0f){
//destructive or non?
- float fadefactor=1.0f-(1.0f/history_size);
+ float fadefactor=decay<0.0f?1.0f-(1.0f/history_size):decay;
for (int i=0;i<data.size();i++){
data[i]=lineTransformer::polyLineTransform(xform,data[i],fadefactor);
@@ -49,10 +53,12 @@ public:
void addpoints(vector <float> &audio,int number){
colourPolyline newdata;
int num=min(number,(int)audio.size());
- int step=audio.size()/num;
- int start=audio.size()/(num+1);
+ int step=audio.size()/(num+1);
for (int i=0;i<num;i++){
- newdata.addVertex((start+(i*step)*ofGetWidth())/audio.size(),audio[start+(i*step)]*ofGetHeight());
+ newdata.addVertex(((step*(i+1))*ofGetWidth())/audio.size(),audio[step*(i+1)]*ofGetHeight(),colour);
+ if (!joined){
+ newdata.addVertex((((step*(i+1))*ofGetWidth())/audio.size())+1,(audio[step*(i+1)])*ofGetHeight(),0,0,0);
+ }
}
data.insert(data.begin(),newdata);
while (data.size()>history_size) {
@@ -60,19 +66,28 @@ public:
}
}
+ int numpoints(){
+ int num=0;
+ for (auto d=data.begin();d!=data.end();d++){
+ num+=d->size();
+ }
+ return num;
+ }
private:
vector <colourPolyline> data;
bool joined;
int history_size;
+ ofColor colour;
};
-class ofApp : public ofBaseApp{
+class ofApp : public ofBaseApp, public ofxMidiListener{
public:
void setup();
void update();
void draw();
+ void exit();
void keyPressed(int key);
void keyReleased(int key);
@@ -83,6 +98,17 @@ class ofApp : public ofBaseApp{
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;
@@ -128,5 +154,12 @@ class ofApp : public ofBaseApp{
ofxHelios laser;
Audioplotter plotter;
+
+
+ ofxPanel gui;
+ ofParameter<int> numPlots;
+ ofParameter<float> scalePlot;
+ ofParameter<float> decayPlot;
+ ofParameter<ofVec2f> xform;
};