danielsdesk
7/2/2016 - 6:18 PM

ofxMultiTrack test osc subscrier

ofxMultiTrack test osc subscrier

#pragma once

#include "ofMain.h"
#include "ofxOsc.h"

class ofApp : public ofBaseApp{

	struct Body {
		map<string, ofVec3f> joints;
	};

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

		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 mouseEntered(int x, int y);
		void mouseExited(int x, int y);
		void windowResized(int w, int h);
		void dragEvent(ofDragInfo dragInfo);
		void gotMessage(ofMessage msg);
	
		ofxOscSender subscriber;
		ofxOscReceiver receiver;

		ofEasyCam camera;

		map<int, Body> bodies;
};
#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
	this->receiver.setup(4444);

	this->subscriber.setup("localhost", 2046);
	{
		ofxOscMessage message;
		message.setAddress("/addClient");
		
		//OPTIONAL : send to address (defaults to port it hears the 'addClient' message come from)
		message.addInt32Arg(4444);

		//OPTIONAL : send to address (defaults to address it hears the 'addClient' message come from)
		//message.addStringArg("127.0.0.1");

		this->subscriber.sendMessage(message);
	}
}

//--------------------------------------------------------------
void ofApp::update(){
	while (this->receiver.hasWaitingMessages()) {
		ofxOscMessage message;
		if (this->receiver.getNextMessage(message)) {

			//print out all incoming messages to console
			{
				cout << message.getAddress() << " : ";
				for (int i = 0; i < message.getNumArgs(); i++) {
					cout << message.getArgTypeName(i) << " ";
				}
				cout << endl;
			}
			
			//handle messages about bodies
			if (message.getAddress() == "/combined/bodies/indices") {
				vector<int> bodyIndices;
				for (int i = 0; i < message.getNumArgs(); i++) {
					bodyIndices.push_back(message.getArgAsInt(i));
				}

			}
		}
	}
}

//--------------------------------------------------------------
void ofApp::draw(){
	this->camera.begin();
	{
		
	}
	this->camera.end();
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){

}

//--------------------------------------------------------------
void ofApp::keyReleased(int key){

}

//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){

}

//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y){

}

//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y){

}

//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){

}

//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){

}

//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){ 

}