From bigfug
Jump to: navigation, search

One of the useful features of Open Sound Control is the ability to send and receive messages that contain more than one item of data within them.

For instance, if you had a phone app that sends X and Y coordinates of where the user is touching the screen, it's quicker and more efficient to send one OSC message with both values in rather than two messages (one for X, one for Y).

In Fugio we use some simple Lua scripting to process these kind of messages. In our example, we would create a Lua node and add one input pin called 'Input', and two output pins called 'X' and 'Y' (of type float). We can then use the following code:

fugio = require "fugio"

-- Set up our inputs and outputs

PinInput = fugio.input( "Input" )

PinOutputX = fugio.output( "X" )
PinOutputY = fugio.output( "Y" )

function main()
    -- Called when the input pin is updated

    local Input = PinInput:get()    -- get the input values (as an array)

    PinOutputX:set( Input[ 1 ] )    -- X is the first value
    PinOutputY:set( Input[ 2 ] )    -- Y is the second value

While this might seem like quite some work just to break apart the values in this example, the OSC specification allows for complex data structures to be passed in this manner, including nested arrays. By processing the data in Lua, we can handle any kind of message.