From 589e6c881bd2cf11e8615e9c1bf8cb4012293bad Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 31 Dec 2015 03:34:08 +0100 Subject: libraries/oscP5: Adding oscP5 library for OSC capabilities. --- .../oscP5broadcastClient/oscP5broadcastClient.pde | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 libraries/oscP5/examples/oscP5broadcastClient/oscP5broadcastClient.pde (limited to 'libraries/oscP5/examples/oscP5broadcastClient/oscP5broadcastClient.pde') diff --git a/libraries/oscP5/examples/oscP5broadcastClient/oscP5broadcastClient.pde b/libraries/oscP5/examples/oscP5broadcastClient/oscP5broadcastClient.pde new file mode 100644 index 0000000..56fb843 --- /dev/null +++ b/libraries/oscP5/examples/oscP5broadcastClient/oscP5broadcastClient.pde @@ -0,0 +1,73 @@ +/** + * oscP5broadcastClient by andreas schlegel + * an osc broadcast client. + * an example for broadcast server is located in the oscP5broadcaster exmaple. + * oscP5 website at http://www.sojamo.de/oscP5 + */ + +import oscP5.*; +import netP5.*; + + +OscP5 oscP5; + +/* a NetAddress contains the ip address and port number of a remote location in the network. */ +NetAddress myBroadcastLocation; + +void setup() { + size(400,400); + frameRate(25); + + /* create a new instance of oscP5. + * 12000 is the port number you are listening for incoming osc messages. + */ + oscP5 = new OscP5(this,12000); + + /* create a new NetAddress. a NetAddress is used when sending osc messages + * with the oscP5.send method. + */ + + /* the address of the osc broadcast server */ + myBroadcastLocation = new NetAddress("127.0.0.1",32000); +} + + +void draw() { + background(0); +} + + +void mousePressed() { + /* create a new OscMessage with an address pattern, in this case /test. */ + OscMessage myOscMessage = new OscMessage("/test"); + /* add a value (an integer) to the OscMessage */ + myOscMessage.add(100); + /* send the OscMessage to a remote location specified in myNetAddress */ + oscP5.send(myOscMessage, myBroadcastLocation); +} + + +void keyPressed() { + OscMessage m; + switch(key) { + case('c'): + /* connect to the broadcaster */ + m = new OscMessage("/server/connect",new Object[0]); + oscP5.flush(m,myBroadcastLocation); + break; + case('d'): + /* disconnect from the broadcaster */ + m = new OscMessage("/server/disconnect",new Object[0]); + oscP5.flush(m,myBroadcastLocation); + break; + + } +} + + +/* incoming osc message are forwarded to the oscEvent method. */ +void oscEvent(OscMessage theOscMessage) { + /* get and print the address pattern and the typetag of the received OscMessage */ + println("### received an osc message with addrpattern "+theOscMessage.addrPattern()+" and typetag "+theOscMessage.typetag()); + theOscMessage.print(); +} -- cgit v1.2.3-54-g00ecf