Skip to content

Commit

Permalink
Add OSCManager
Browse files Browse the repository at this point in the history
  • Loading branch information
murawakimitsuhiro committed Aug 19, 2017
1 parent a57ea17 commit 615692c
Show file tree
Hide file tree
Showing 9 changed files with 290 additions and 23 deletions.
206 changes: 200 additions & 6 deletions Brain-Fu_k.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>Brain-Fu_k Debug.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>Brain-Fu_k Release.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>E4B69B5A0A3A1756003C02F2</key>
Expand Down
1 change: 1 addition & 0 deletions addons.make
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ofxAssimpModelLoader
ofxOsc
Binary file modified bin/Brain-Fu_kDebug.app/Contents/MacOS/Brain-Fu_kDebug
Binary file not shown.
38 changes: 38 additions & 0 deletions src/OSCManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// OSCManager.cpp
// Brain-Fu_k
//
// Created by Murawaki on 2017/08/20.
//
//

#include "OSCManager.hpp"

void OSCManager::setup() {
receiver.setup(fromPort);
}

void OSCManager::update() {
//receive message
while( receiver.hasWaitingMessages()){
ofxOscMessage m;
receiver.getNextMessage(m);

dumpOSC(m);
}
}

void OSCManager::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;
}
46 changes: 46 additions & 0 deletions src/OSCManager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// OSCManager.hpp
// Brain-Fu_k
//
// Created by Murawaki on 2017/08/20.
//
//

#ifndef OSCManager_hpp
#define OSCManager_hpp

#include <stdio.h>
#include <map>

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

class OSCManager {
private:
OSCManager() = default;
~OSCManager() = default;

static const int fromPort = 8000;
static const int toPort = 8001;

ofxOscReceiver receiver;

map<string, int> messageMap;

public:
OSCManager(const OSCManager&) = delete;
OSCManager& operator=(const OSCManager&) = delete;
OSCManager(OSCManager&&) = delete;
OSCManager& operator=(OSCManager&&) = delete;

static OSCManager& get_instance() {
static OSCManager inst;
return inst;
}

void setup();
void update();
void dumpOSC(ofxOscMessage m);
};

#endif /* OSCManager_hpp */
8 changes: 4 additions & 4 deletions src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,24 @@ void ofApp::setup() {
secondLight.setDiffuseColor(initDifColor);
secondLight.setSpecularColor(initSpeColor);

OSCManager::get_instance().setup();
brain.setup();
}

void ofApp::update() {
OSCManager::get_instance().update();
brain.update();
}

void ofApp::draw(){
ofEnableDepthTest();
cam.begin();

cam.begin();
ofPushStyle();

brain.draw();

ofPopStyle();

cam.end();

ofDisableDepthTest();
Expand All @@ -62,7 +63,6 @@ void ofApp::keyPressed(int key){

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

}

//--------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/ofApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "ofxAssimpModelLoader.h"

#include "BrainController.hpp"
#include "OSCManager.hpp"

class ofApp : public ofBaseApp{

Expand Down

0 comments on commit 615692c

Please sign in to comment.