Skip to content

Instantly share code, notes, and snippets.

@koji
Last active January 20, 2019 07:27
Show Gist options
  • Save koji/44efed869f98c4edb73ee0b580e7ee80 to your computer and use it in GitHub Desktop.
Save koji/44efed869f98c4edb73ee0b580e7ee80 to your computer and use it in GitHub Desktop.
runway osc test

runway(v0.1.4) settings
input camera
output osc

ofApp.h

#pragma once

#include "ofMain.h"
#include "ofxOsc.h"
#include "ofxJSON.h"
#define PORT 57101

class ofApp : public ofBaseApp{

	public:
		void setup();
		void update();
		void draw();

    void dumpOSC(ofxOscMessage m); 
    
    ofxOscReceiver receiver;
    ofxJSONElement results;
    string caption;
};

ofApp.cpp

#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
    ofSetFrameRate(60);
    receiver.setup(PORT);

}

//--------------------------------------------------------------
void ofApp::update(){

    while (receiver.hasWaitingMessages()) {
        ofxOscMessage m;
        receiver.getNextMessage(m);
        if (m.getAddress() == "/data") {
            string data = m.getArgAsString(0);
            results.parse(data);
            caption = results["results"][0]["caption"].asString();
            cout << caption << endl;
        }
        dumpOSC(m);
    }
}

void ofApp::dumpOSC(ofxOscMessage m) {
    string msg_string;
    msg_string = m.getAddress();
    for (int i=0; i<m.getNumArgs(); i++ ) {
        msg_string += " ";
        if(m.getArgType(i) == OFXOSC_TYPE_INT32)
            msg_string += ofToString( m.getArgAsInt32(i));
        else if(m.getArgType(i) == OFXOSC_TYPE_FLOAT)
            msg_string += ofToString( m.getArgAsFloat(i));
        else if(m.getArgType(i) == OFXOSC_TYPE_STRING)
            msg_string += m.getArgAsString(i);
    }
    cout << msg_string << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment