Skip to content

Instantly share code, notes, and snippets.

@tobetchi
Created September 28, 2016 08:19
Show Gist options
  • Save tobetchi/fa0638c287c6c0ebee688ede356b9959 to your computer and use it in GitHub Desktop.
Save tobetchi/fa0638c287c6c0ebee688ede356b9959 to your computer and use it in GitHub Desktop.
openFrameworks OSC recieve sample Raw
#include "ofMain.h"
#include "ofApp.h"
int main() {
ofSetupOpenGL(1024, 768, OF_WINDOW);
ofRunApp(new ofApp());
}
#include "ofApp.h"
void ofApp::setup() {
// OSC Setup
receiver.setup(PORT);
}
void ofApp::update() {
// OSC Message Recieve
while (receiver.hasWaitingMessages()) {
ofxOscMessage m;
receiver.getNextMessage(m);
string address = m.getAddress();
string arg = "";
for (int i = 0; i < m.getNumArgs(); i++) {
// 引数の型名を取得
arg += m.getArgTypeName(i);
arg += ":";
// 引数の値を取得 (IntとFloatとStringのみ)
if (m.getArgType(i) == OFXOSC_TYPE_INT32) {
arg += ofToString(m.getArgAsInt32(i));
} else if (m.getArgType(i) == OFXOSC_TYPE_FLOAT) {
arg += ofToString(m.getArgAsFloat(i));
} else if (m.getArgType(i) == OFXOSC_TYPE_STRING) {
arg += m.getArgAsString(i);
} else {
arg += "unknown";
}
}
std::cout << address << " " << arg << std::endl;
}
}
#pragma once
#include "ofMain.h"
#include "ofxOsc.h"
#define PORT 7001
class ofApp : public ofBaseApp {
public:
void setup();
void update();
private:
ofxOscReceiver receiver;
ofxOscMessage m;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment