OSCNode Examples

The OSCNode is a Ygdrasil node that provides basic network communication over OSC. You can use it with any program or language that can receive OSC messages.

The host and port parameters are used to set the host address and port of the sound server computer. OSCNode will send all OSC messages to this address and port. This is not terribly robust, since running the scene in different installation setups requires actually changing this part of the YG scene file. On the other hand, this does allow one YG scene to control multiple sound servers simultaneously.

Example: playing basic tones



OSCNode osc (host("localhost"),port(9000))

wandTrigger (
	when(button1,osc.oscmessage("/sinewave",220.0)),
	when(button2,osc.oscmessage("/sinewave",440.0)),
	when(button3,osc.oscmessage("/sinewave",880.0))
)

Sending the wand position over OSC


#include "user0.scene"

wandPosition(when(inside,osc.sendMessage("/wand" $xpos $ypos $zpos)))
OSCNode osc (host("localhost"),port(10000))

This example sends a different frequency value for a sinewave with each button press. It sends it to a sound server running on the same computer as YG (localhost), listening on port 9000. To use this example, you would have to also program a sound server to interpret the messages. In Max/MSP or Pure Data, the OSC object looks for the "/sinewave" address, and knows to pass parameters onto a ~sine object. The "f" typetags string means that there is one parameter, and it is a float. To make the parameter mean "frequency", route the output from the OSC object into the ~sine object's frequency inlet.

Getting OSC Messages in PureData

dumpOSC receives osc messages; give it the port number you want to listen to. Must be the same as what you enter in YG.
route routes different OSC messages such as "/wand", "/bang", "/note", whatever send from YG.
unpack f f f splits up a message into 3 floating-point numbers.

OSCNode Documentation

MessageParametersDefaultDescription
hoststring"localhost"the hostname or IP address of the sound server computer.
portint0the port to send OSC messages to on the sound server
oscMessagestring osc address, parameter1, parameter2, ... sends a message over OSC. the meaning of the OSC Address parameter depends on the exact sound server application, but generally refers to a patch, synth, or function running on the sound server.
an OSC Message can contain any number of floating-point values

(c) Ben Chang