Skip to content

Instantly share code, notes, and snippets.

@tobetchi

tobetchi/main.cpp

Created Sep 28, 2016
Embed
What would you like to do?
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