Skip to content

2bbb/ofxPubSubOsc

Repository files navigation

ofxPubSubOsc

easy utility for publish/subscribe OSC message.

Dependencies

  • ofxOsc

Notice

  • this addon is tested with oF0.9.0~
  • if you use oF0.9.0~, then you can use std::function<void(ofxOscMessage &)>! detail: API Reference
  • if you use oF~0.8.4, then you can use branch:v0_1_x_oF084
  • if you have challange spirit, please use dev/main branch.
  • if you want to join development ofxPubSubOsc, open the issue and post the PR for dev/main.

TOC

class ofApp : public ofBaseApp {
	int foo;
	ofColor c;
	ofPoint p;
public:
	void setup() {
		ofxSubscribeOsc(9005, "/foo", foo);
		ofxSubscribeOsc(9005, "/color", c);
		ofxSubscribeOsc(9005, "/p", p);
		
		ofxPublishOsc("localhost", 9006, "/fps", &ofGetFrameRate);
		
		ofxSubscribeOsc(9005, "/lambda", [](const std::string &str){
			ofLogNotice() << "receive " << str;
		});
		ofxSubscribeOsc(9005, "/trigger_event", [](){
			ofLogNotice() << "receive trigger_event";
		});
	}
	
	void update() {
		// do NOTHING about OSC on update!!!
	}
	
	void draw() {
		ofSetColor(c);
		ofDrawCircle(p, 5);
	}
};

If you want to use advanced features, see Advanced

  • void ofxSubscribeOsc(int port, const string &address, SupportedType &value);

bind a value to the argument(s) of OSC messages with an address pattern address incoming to port.

  • ofxUnsubscribeOsc(int port, const string &address);

unbind from OSC messages with an address pattern address incoming to port.

  • ofxUnsubscribeOsc(int port);

unbind from OSC messages with any address patterns incoming to port.

  • void ofxPublishOsc(const string &ip, int port, const string &address, SupportedType &value, bool whenValueIsChanged = true);

publish value as an OSC message with an address pattern address to ip:port every time the value has changed. If whenValueIsChanged is set to false, then the binded value is sent every frame after App::update.

  • void ofxUnpublishOsc(const string &ip, int port, const string &address);

unbind a publisher sending OSC message with an address pattern address to ip:port.

  • void ofxUnpublishOsc(const string &ip, int port);

unbind all the publishers sending to ip:port.

  • void ofxRegisterPublishingOsc(const string &ip, int port, const string &address, SupportedType &value)
  • void ofxPublishRegisteredOsc(const string &ip, int port, const string &address)

register value as an OSC message with an address pattern address to ip:port. and publish when call ofxPublishRegisteredOsc(ip, port, address).

  • void ofxUnregisterPublishingOsc(const string &ip, int port, const string &address)

unregister OSC message with an address pattern address to ip:port.

  • void ofxUnregisterPublishingOsc(const string &ip, int port)

unregister all the messages sending to ip:port.

NOTE: registable type is same to ofxPublishOsc. see more ofxPublishOsc.

  • Arithmetic is any type of Int32, Int64 or Float
  • bool (published as Int32)
  • unsigned char, char (published as Int32)
  • unsigned short, short (published as Int32)
  • unsigned int, int (published as Int32 or Int64 (if sizeof(int) == 8 then Int64))
  • unsigned long, long (published as Int64 or Int64 (if sizeof(int) == 8 then Int64))
  • unsigned long long, long long (published as Int64)
  • float (published as Float)
  • double (published as Float)

NOTE: long double is not guaranteed

  • string

Arithmetic[2]

  • ofVec2f (published as Float * 2)

Arithmetic[3]

  • ofVec3f (= ofPoint) (published as Float * 3)

Arithmetic[4]

  • ofVec4f (published as Float * 4)
  • ofColor (published as Int32 * 4)
  • ofShortColor (published as Int32 * 4)
  • ofFloatColor (published as Float * 4)
  • ofQuaternion (published as Float * 4)
  • ofRectangle (published as Float * 4)

Arithmetic[9]

  • ofMatrix3x3 (published as Float * 9)

Arithmetic[16]

  • ofMatrix4x4 (publish as Float * 16)

Blob

  • ofBuffer
  • ofParameter<SupportedType>

NOTE: we only support subscribing ofParameterGroup. See How to subscribe ofParameterGroup

  • SupportedType[size]
  • vector<SupportedType>

if you use vector<SomeType> vec;, when vec will be resized every receiving OSC messages.

NOTE: do NOT use vector<vector<SupportedType>>, vector<SupportedType>[size]

  • T (\*callback)(ofxOscMessage &);
  • pair of U &that, T (U::\*callback)(ofxOscMessage &);
  • pair of U \*that, T (U::\*callback)(ofxOscMessage &);
  • std::function<void(ofxOscMessage &)>

2016/01/25 ver 0.2.2 release

  • bugfix: about ofQuaternion's operator>>, operator<< (issued by musiko. thanks!!!)

2016/01/04 ver 0.2.1 release

  • critical bugfix, hehe
  • enable subscribe lambda has argument is not ofxOscMessage.
  • enable subscribe method has no argument
  • update exmaples (xcodeproj) for oF0.9.0
  • some cleaning source and doxygen

2016/01/02 ver 0.2.0 release (this version is broken)

  • after this release, we will only test on oF0.9.0~
  • new feature: multi-subscribe, multi-publish
    • ofxSubscribeOsc returns ofxSubscriberIdentifier
    • ofxPublishOsc returns ofxPublisherIdentifier
    • TODO: API Reference
  • add iterators to ofxOscSubscriberManager
  • add iterators to ofxOscPublisherManager
  • add all port operation to ofxUnsubscribeOsc, ofxNotifyToSubscribedOsc, ofxRemoveLeakedOscPicker
  • add ofxSetLeakedOscPickerAll
  • add ofxSubscribeOsc with std::initializer_list<int> port and std::initializer_list<std::string> addresses
  • add iterators to ofxOscPublisherManager
  • add all port operation to ofxUnpublishOsc, ofxUnregisterPublishingOsc
  • add feature publishing r-value. (i.e., you can do ofxPublishOsc(host, port, "/bar", "value!!"))
  • add const to lambda callback (proposed by satoruhiga. thanks!!)
  • add useful macro SubscribeOsc(port, name) is same as ofxSubscribeOsc(port, "/name", name) (porposed by hanasaan. thanks!!)
  • add std:: prefix
  • cleaning up conditional macro about oF0.8.x
  • some bugfix around lambda
  • TODO: update some API Documentations

2016/01/25 ver 0.1.3 release

  • bugfix: about ofQuaternion's operator>>, operator<< (issued by musiko. thanks!!!)

2016/01/02 ver 0.1.2 release

  • this is final update added new feature, with oF0.8.4 support
  • after this release, "ver 0.1.x will only bugfie about supporting oF0.8.4
  • add new feature ofxNotifyToSubscribedOsc (proposed by satcy. thanks!!)
  • some bugfix

about Versioning

ofxPubSubOsc uses Mood Versioning. maybe, 1.0.0. will not come.

MIT License.

  • ISHII 2bit [bufferRenaiss co., ltd.]
  • ishii[at]buffer-renaiss.com

Please create a new issue if there is a problem. And please throw a pull request if you have a cool idea!!