--!movie
--!encoding=utf-8
global $
----------------------------------------
-- SEND VARIOUS OSC MESSAGES TO LOCALHOST:5500
----------------------------------------
-- UPDATED API, REQUIRES VERSION 1.4!
--
-- new message format:
-- msg = ["/address", [arg1, arg2...]]
-- msg = ["/address", [#type1:args1, #type2:args2, ...]]
--
-- new bundle format:
-- bundle = [timecode, [msg1, msg2, bundle1, ...]] -- notice: bundles can now be nested within bundles
on startMovie
-- libs
import("lib/console").show()
import("lib/osc")
-- or: buffer size increased to 5 kb
--import("lib/osc", 1024*5)
import("lib/date")
-- set destination host and port
$.osc.setDestination("localhost", 5500)
-- send message without arguments
put $.osc.send(["/test1"])
-- send message with int32 and float32 argument
put $.osc.send(["/test2", ["int32":23, #float32:66.5]])
-- send message with string and blob argument
put $.osc.send(["/test3", [#string:"Hello", #blob:bytearray("World!")]])
-- send message with arguments as linear list (core types only)
put $.osc.send(["/test4", [23, 66.5, "Hello", bytearray("World!"), VOID]])
-- send message with various arguments
put $.osc.send(["/test5", [#bool:1, #double:23.0, #int64:23.0, #char:65, #nil:void, #infinitum:void]])
-- send message with a rgba color argument
put $.osc.send(["/test6", [#rgba:$.osc.rgba(255,127,127)]])
-- send message with a time tag
now = $.date.dateToTimestamp() * 4294967296.0
put $.osc.send(["/test7", [#time: now]])
-- send 2 arrays
put $.osc.send(["/test8", [#array: [1,2,4,5,6,7], #array:["hello","world"]]])
-- send array with explicit types (propList)
put $.osc.send(["/test9", [#array: [#int64:111, #int64:222]]])
-- send bundle with 3 messages
bundle = [1, []] -- timecode 1 = immediately
bundle[2].add(["/bundlemsg1"])
bundle[2].add(["/bundlemsg2", ["Hello World!"]])
bundle[2].add(["/bundlemsg3", [#int32:23, #float32:66.5]])
put $.osc.send(bundle)
-- send nested bundle (bundle inside another bundle)
bundle = [float($.date.dateToTimestamp()) * 256*256*256*256, []] -- timecode 1 = immediately
bundle[2].add(["/bundlemsg1"])
bundle[2].add(["/bundlemsg2", [#time:($.date.dateToTimestamp())]]) -- * 256*256*256*256
bundle[2].add(["/bundlemsg3", [#int32:23, #float32:66.5]])
innerBundle = [1, []] -- timecode 1 = immediately
innerBundle[2].add(["/innerbundlemsg1"])
innerBundle[2].add(["/innerbundlemsg2", [#int32:23, #float32:66.5]])
bundle[2].add(innerBundle)
put $.osc.send(bundle)
-- test overflow
-- send returns false if data specified is bigger than allocated buffer
-- default bufferSize is 1024 bytes, in can be changed by passing an integer value
-- as argument to the new() constructor when creating the xtra instance
put $.osc.send(["/test", [#blob:bytearray(2048)]])
--_movie.quit()
end