summaryrefslogtreecommitdiffstats
path: root/libraries/oscP5/examples/oscP5plug
diff options
context:
space:
mode:
authorDavid Runge <dave@sleepmap.de>2015-12-31 03:34:08 +0100
committerDavid Runge <dave@sleepmap.de>2015-12-31 03:34:08 +0100
commit589e6c881bd2cf11e8615e9c1bf8cb4012293bad (patch)
tree407d617ed861a61d64e64f7d581052f90b10e981 /libraries/oscP5/examples/oscP5plug
parent6a713ba6966eee4cf7bb9fb9e1513918fc94b528 (diff)
downloadprocessing-sketchbook-589e6c881bd2cf11e8615e9c1bf8cb4012293bad.tar.gz
processing-sketchbook-589e6c881bd2cf11e8615e9c1bf8cb4012293bad.tar.bz2
processing-sketchbook-589e6c881bd2cf11e8615e9c1bf8cb4012293bad.tar.xz
processing-sketchbook-589e6c881bd2cf11e8615e9c1bf8cb4012293bad.zip
libraries/oscP5: Adding oscP5 library for OSC capabilities.
Diffstat (limited to 'libraries/oscP5/examples/oscP5plug')
-rw-r--r--libraries/oscP5/examples/oscP5plug/oscP5plug.pde82
1 files changed, 82 insertions, 0 deletions
diff --git a/libraries/oscP5/examples/oscP5plug/oscP5plug.pde b/libraries/oscP5/examples/oscP5plug/oscP5plug.pde
new file mode 100644
index 0000000..5b72973
--- /dev/null
+++ b/libraries/oscP5/examples/oscP5plug/oscP5plug.pde
@@ -0,0 +1,82 @@
+/**
+ * oscP5plug by andreas schlegel
+ * example shows how to use the plug service with oscP5.
+ * the concept of the plug service is, that you can
+ * register methods in your sketch to which incoming
+ * osc messages will be forwareded automatically without
+ * having to parse them in the oscEvent method.
+ * that a look at the example below to get an understanding
+ * of how plug works.
+ * oscP5 website at http://www.sojamo.de/oscP5
+ */
+
+import oscP5.*;
+import netP5.*;
+
+OscP5 oscP5;
+NetAddress myRemoteLocation;
+
+void setup() {
+ size(400,400);
+ frameRate(25);
+ /* start oscP5, listening for incoming messages at port 12000 */
+ oscP5 = new OscP5(this,12000);
+
+ /* myRemoteLocation is a NetAddress. a NetAddress takes 2 parameters,
+ * an ip address and a port number. myRemoteLocation is used as parameter in
+ * oscP5.send() when sending osc packets to another computer, device,
+ * application. usage see below. for testing purposes the listening port
+ * and the port of the remote location address are the same, hence you will
+ * send messages back to this sketch.
+ */
+ myRemoteLocation = new NetAddress("127.0.0.1",12000);
+
+ /* osc plug service
+ * osc messages with a specific address pattern can be automatically
+ * forwarded to a specific method of an object. in this example
+ * a message with address pattern /test will be forwarded to a method
+ * test(). below the method test takes 2 arguments - 2 ints. therefore each
+ * message with address pattern /test and typetag ii will be forwarded to
+ * the method test(int theA, int theB)
+ */
+ oscP5.plug(this,"test","/test");
+}
+
+
+public void test(int theA, int theB) {
+ println("### plug event method. received a message /test.");
+ println(" 2 ints received: "+theA+", "+theB);
+}
+
+
+void draw() {
+ background(0);
+}
+
+
+void mousePressed() {
+ /* createan osc message with address pattern /test */
+ OscMessage myMessage = new OscMessage("/test");
+
+ myMessage.add(123); /* add an int to the osc message */
+ myMessage.add(456); /* add a second int to the osc message */
+
+ /* send the message */
+ oscP5.send(myMessage, myRemoteLocation);
+}
+
+
+/* incoming osc message are forwarded to the oscEvent method. */
+void oscEvent(OscMessage theOscMessage) {
+ /* with theOscMessage.isPlugged() you check if the osc message has already been
+ * forwarded to a plugged method. if theOscMessage.isPlugged()==true, it has already
+ * been forwared to another method in your sketch. theOscMessage.isPlugged() can
+ * be used for double posting but is not required.
+ */
+ if(theOscMessage.isPlugged()==false) {
+ /* print the address pattern and the typetag of the received OscMessage */
+ println("### received an osc message.");
+ println("### addrpattern\t"+theOscMessage.addrPattern());
+ println("### typetag\t"+theOscMessage.typetag());
+ }
+}