summaryrefslogtreecommitdiffstats
path: root/libraries/oscP5/examples/oscP5parsing
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/oscP5parsing
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/oscP5parsing')
-rw-r--r--libraries/oscP5/examples/oscP5parsing/oscP5parsing.pde65
1 files changed, 65 insertions, 0 deletions
diff --git a/libraries/oscP5/examples/oscP5parsing/oscP5parsing.pde b/libraries/oscP5/examples/oscP5parsing/oscP5parsing.pde
new file mode 100644
index 0000000..abb035d
--- /dev/null
+++ b/libraries/oscP5/examples/oscP5parsing/oscP5parsing.pde
@@ -0,0 +1,65 @@
+/**
+ * oscP5parsing by andreas schlegel
+ * example shows how to parse incoming osc messages "by hand".
+ * it is recommended to take a look at oscP5plug for an
+ * alternative and more convenient way to parse messages.
+ * 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);
+}
+
+void draw() {
+ background(0);
+}
+
+
+void mousePressed() {
+ /* create a new osc message object */
+ OscMessage myMessage = new OscMessage("/test");
+
+ myMessage.add(123); /* add an int to the osc message */
+ myMessage.add(12.34); /* add a float to the osc message */
+ myMessage.add("some text"); /* add a string to the osc message */
+
+ /* send the message */
+ oscP5.send(myMessage, myRemoteLocation);
+}
+
+
+void oscEvent(OscMessage theOscMessage) {
+ /* check if theOscMessage has the address pattern we are looking for. */
+
+ if(theOscMessage.checkAddrPattern("/test")==true) {
+ /* check if the typetag is the right one. */
+ if(theOscMessage.checkTypetag("ifs")) {
+ /* parse theOscMessage and extract the values from the osc message arguments. */
+ int firstValue = theOscMessage.get(0).intValue();
+ float secondValue = theOscMessage.get(1).floatValue();
+ String thirdValue = theOscMessage.get(2).stringValue();
+ print("### received an osc message /test with typetag ifs.");
+ println(" values: "+firstValue+", "+secondValue+", "+thirdValue);
+ return;
+ }
+ }
+ println("### received an osc message. with address pattern "+theOscMessage.addrPattern());
+}