Tips & Tricks: OSC With Processing

OSC (Open Sound Control) is a content format for messaging between devices and software over a network connection.

Anatomy of OSC Messages

OSC messages are sent over a network so you must define where you want to send your message. You must define the following things:

  • IP Address – The IP address of the device where you send your message. If you want to send data from one software to another on your computer, you can use the localhost IP address 127.0.0.1
  • Port – The port number where you are sending your message. This could basically any number, but a lot of ports are reserved for other purposes. Use a 4- or 5-digit number to stay out of the range of most common ports.
    • Example: 7777
  • Address Pattern – This usually looks like an URL. It is used to differentiate between different messages you are sending on one port.
    • Example: /sensor/flex
  • The actual message is the data that you are sending. You have to also define what the data type is (string, int, float etc.) The Processing library we use does the data type definition for us.
Examples of OSC messages:
  • /sensor/accelerometer/x 0.765
  • /sensor/accelerometer/y 0.482
  • /text/matti hello

OSC in Processing

Once again, you will need to install an external library to use OSC in Proccessing:

Download OSCP5 library.

Unzip and put the extracted oscP5 folder into the libraries folder of your Processing sketches. Reference and examples are included in the oscP5 folder. You can access the examples from Examples browser. They will be in the Contributed Libraries section.

When to use OSC

For example, you might want to read some sensors from the Arduino and create graphics based on that data, but you would also like to connect that awesome synthesizer you built in PD to the same data. You can only open the serial port of the Arduino in one program at a time, but OSC is an easy and fast way to send that sensor data from Processing to PD.

There are also lots of computer vision applications that do some form of motion or gesture tracking that then send the data via OSC. Some examples:

FaceOSC

Download: https://github.com/downloads/kylemcdonald/ofxFaceTracker/FaceOSC.zip

Synapse for Kinect

Download: http://synapsekinect.tumblr.com/post/6307790318/synapse-for-kinect

OSCeleton (A tracker for Kinect)

Download: https://github.com/Sensebloom/OSCeleton

TUIO

TUIO is a specific way of formatting OSC messages that is used by many computer vision applications.

http://tuio.org/?software

You could use the OSCP5 library, but there is also a specific library for TUIO messages that makes it easier to parse the TUIO messages.