Skip to content

GlovePIE OSC (Open Sound Control)

Ravbug edited this page Jan 15, 2019 · 2 revisions

OSC support seems to be broken in GlovePIE 0.40 and above. Sorry. It might be an issue with Delphi 2009 and unicode.

Open Sound Control is a simple network protocol for controlling just about anything. It doesn’t need to involve sound.

You can use it to communicate with other computers, which might be Macs, or Linux boxes, or whatever. You might also be able to use it with some other hardware.

GlovePIE now supports OSC input and output, but unfortunately in the current implementation all messages received from different sources are pooled together into one, so you can’t tell where they came from. Also it can’t tell the difference between dots and slashes in addresses. And it doesn’t support bundles at all.

There are two ways to send OSC messages in GlovePIE. The first is with the SendOsc and BroadcastOsc functions.

Using the SendOsc and BroadcastOsc functions

The BroadcastOsc function sends an OSC message to all computers on the local network. It looks like this:

BroadcastOsc(port, OscAddress, param1, param2, param3, …)

Port is the port number to send it to. It can be any integer, but it is best if it is between 49,152 and 65,535. The machine receiving the OSC messages needs to be set to the same port.

OscAddress is a path, which begins with a / and has a bunch of nodes separated by slashes. For example: “/resonators/3/frequency

The other parameters can be anything. GlovePIE will send them as single-precision floating-point, or an integer, or true or false, or an array (for vectors), or an array of arrays (for matrices). You need to convert the parameters to the correct type that the machine you are sending to is expecting.

SendOsc will send to a specific address, rather than to every computer. It looks like this:

SendOsc(IpAddress, port, OscAddress, param1, param2, param3, …)

IpAddress is the IP address eg. “192.168.1.4” or the internet address eg. “www.google.com” or “localhost” to send to its own computer, or “broadcast” to send to all computers on the local network

See the p5osc.PIE sample file for an example.

Using the OSC objects

You can have multiple OSC object. Each object can support input, output or both. But in the current version, all the input sources are pooled into one.

Using OSC output in GlovePIE first requires setting the port and either broadcast or IP address on an OSC object like this:

Osc1.port = 54934
Osc1.broadcast = true

Note that the port can be anything, preferably between 49,152 and 65,535. But it needs to match whatever the receiver is expecting.

When broadcast is true, the OSC messages will be sent to all computers on the local network, but not the rest of the internet. When broadcast is false, you need to set the IP address of the computer you want to send to, like this:

Osc1.IP = “192.168.1.4”

After you have set either the IP address, or broadcast to true, then you can set any values you like, like this:

Osc1.hello.foo.glove.x = p5.x

That will tell all the receiving computers that the OSC address /hello/foo/glove/x is being set to a single-precision floating point number, equal to whatever the horizontal position of the P5 glove is.

Basically, each device that listens to OSC messages has a kind of tree structure of values that can be set. Each element on the tree has an address, starting with a / and with slashes separating each folder, or node on the tree. GlovePIE uses dots instead of slashes, to make it more consistent with the way GlovePIE works, and you can just assign to the address like a normal variable.

GlovePIE can send Single-precision floating point numbers (that’s numbers with decimal points), or it can send 32-bit integers (that’s whole numbers), or it can send True or False values, or it can send strings of text. But it can only send one value at a time.

For example, we could make something like this to send glove data via osc:

Osc1.port = 54934
Osc1.broadcast = true
Osc1.glove.finger.index = p5.index
Osc1.glove.finger.middle = p5.middle
Osc1.glove.finger.ring = p5.ring
Osc1.glove.finger.pinky = p5.pinky
Osc1.glove.finger.thumb = p5.thumb
Osc1.glove.pos.x = p5.x
Osc1.glove.pos.y = p5.y
Osc1.glove.pos.z = p5.z
Osc1.glove.button.A = p5.A
Osc1.glove.button.B = p5.B
Osc1.glove.button.C = p5.C
// etc.

Note that the buttons will be either true or false. If the receiving program can’t handle true or false values, use the int( ) function to convert them to integers like this:

Osc1.glove.button.A = int(p5.A)

You would then have to set up the receiving program or device to listen to port 54934 and understand those addresses, which would become like this: /glove/finger/index

Receiving OSC Messages

You can receive OSC messages by setting ListenPort to the port you want to listen to, and setting Listening to true.

Osc2.ListenPort = 54934
Osc2.Listening = true

then you can read any OSC values like this:

var.x = Osc2.glove.pos.x

You don’t have to use separate OSC objects for receiving and sending, but you can if you want.

Beware: OSC has security holes. If you set Listening to true then GlovePIE will accept osc messages from any source. If an internet attacker knows your PIE script is running and what format it uses, they could send OSC messages to you. That isn’t a major problem, and is extremely unlikely, so I wouldn’t worry about it.

Clone this wiki locally