1. --!movie
  2. --!encoding=utf-8
  3.  
  4. global $
  5.  
  6. ----------------------------------------
  7. -- SEND VARIOUS OSC MESSAGES TO LOCALHOST:5500
  8. ----------------------------------------
  9.  
  10. -- UPDATED API, REQUIRES VERSION 1.4!
  11. --
  12. -- new message format:
  13. --   msg    = ["/address", [arg1, arg2...]]
  14. --   msg    = ["/address", [#type1:args1, #type2:args2, ...]]
  15. --
  16. -- new bundle format:
  17. --   bundle = [timecode, [msg1, msg2, bundle1, ...]] -- notice: bundles can now be nested within bundles
  18.  
  19. on startMovie
  20.  
  21.   -- libs
  22.   import("lib/console").show()
  23.   import("lib/osc")
  24.   -- or: buffer size increased to 5 kb
  25.   --import("lib/osc", 1024*5)
  26.   import("lib/date")
  27.  
  28.   -- set destination host and port
  29.   $.osc.setDestination("localhost", 5500)
  30.  
  31.   -- send message without arguments
  32.   put $.osc.send(["/test1"])
  33.  
  34.   -- send message with int32 and float32 argument
  35.   put $.osc.send(["/test2", ["int32":23, #float32:66.5]])
  36.  
  37.   -- send message with string and blob argument
  38.   put $.osc.send(["/test3", [#string:"Hello", #blob:bytearray("World!")]])
  39.  
  40.   -- send message with arguments as linear list (core types only)
  41.   put $.osc.send(["/test4", [23, 66.5, "Hello", bytearray("World!"), VOID]])
  42.  
  43.   -- send message with various arguments
  44.   put $.osc.send(["/test5", [#bool:1, #double:23.0, #int64:23.0, #char:65, #nil:void, #infinitum:void]])
  45.  
  46.   -- send message with a rgba color argument
  47.   put $.osc.send(["/test6", [#rgba:$.osc.rgba(255,127,127)]])
  48.  
  49.   -- send message with a time tag
  50.   now = $.date.dateToTimestamp() * 4294967296.0
  51.   put $.osc.send(["/test7", [#time: now]])
  52.  
  53.   -- send 2 arrays
  54.   put $.osc.send(["/test8", [#array: [1,2,4,5,6,7], #array:["hello","world"]]])
  55.  
  56.   -- send array with explicit types (propList)
  57.   put $.osc.send(["/test9", [#array: [#int64:111, #int64:222]]])
  58.  
  59.   -- send bundle with 3 messages
  60.   bundle = [1, []] -- timecode 1 = immediately
  61.   bundle[2].add(["/bundlemsg1"])
  62.   bundle[2].add(["/bundlemsg2", ["Hello World!"]])
  63.   bundle[2].add(["/bundlemsg3", [#int32:23, #float32:66.5]])
  64.   put $.osc.send(bundle)
  65.  
  66.   -- send nested bundle (bundle inside another bundle)
  67.   bundle = [float($.date.dateToTimestamp()) * 256*256*256*256, []] -- timecode 1 = immediately
  68.   bundle[2].add(["/bundlemsg1"])
  69.   bundle[2].add(["/bundlemsg2", [#time:($.date.dateToTimestamp())]]) --  * 256*256*256*256
  70.   bundle[2].add(["/bundlemsg3", [#int32:23, #float32:66.5]])
  71.   innerBundle = [1, []] -- timecode 1 = immediately
  72.   innerBundle[2].add(["/innerbundlemsg1"])
  73.   innerBundle[2].add(["/innerbundlemsg2", [#int32:23, #float32:66.5]])
  74.   bundle[2].add(innerBundle)
  75.   put $.osc.send(bundle)
  76.  
  77.   -- test overflow
  78.   -- send returns false if data specified is bigger than allocated buffer
  79.   -- default bufferSize is 1024 bytes, in can be changed by passing an integer value
  80.   -- as argument to the new() constructor when creating the xtra instance
  81.   put $.osc.send(["/test", [#blob:bytearray(2048)]])
  82.  
  83.   --_movie.quit()
  84.  
  85. end
  86.  
[raw code]