Skip to content

Instantly share code, notes, and snippets.

@unohee
Created May 3, 2016 03:05
Show Gist options
  • Save unohee/bc2bcb566ba1bb129ca6782d064a708c to your computer and use it in GitHub Desktop.
Save unohee/bc2bcb566ba1bb129ca6782d064a708c to your computer and use it in GitHub Desktop.
//NETWORK
#include "ofMain.h"
#include "ofxOsc.h"
#ifndef Network_h
#define Network_h
struct Note{
void setTypeTag(string _typeTag){typeTag = _typeTag;};
void setNote(int &note, int &velocity, float &duration, bool &on){
msg = new ofxOscMessage();
if(on) {
msg->addIntArg(note);
msg->addIntArg(velocity);
msg->addFloatArg(duration);
}else{
msg->addIntArg(note);
msg->addIntArg(0);
msg->addFloatArg(0);
}
msg->addBoolArg(on);
msg->setAddress(typeTag);
}
ofxOscMessage *msg;
string typeTag;
};
class Network{
public:
void setup(string hostname, int port, string oscTypeTag);
void sendNote(int pitch, int velocity, float duration, bool trigger);
void sendMIDI();
void setup(string hostname, int port, string oscTypeTag){
sender.setup(hostname, port);
typeTag = oscTypeTag;
oscID = typeTag;
HOST = hostname;
PORT = to_string(port);
//Remove slashs.
oscID.erase(std::remove(oscID.begin(),oscID.end(),'/'),oscID.end());
}
void sendNote(int pitch, int velocity, float duration, bool trigger){
note.setTypeTag(typeTag);
note.setNote(pitch, velocity, duration, trigger);
sender.sendMessage(*note.msg);
}
string HOST, PORT;
string typeTag;
string oscID;
protected:
Note note;
vector<Note*>messages;
ofxOscSender sender;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment