Next: , Previous: UtilFunctions, Up: Functions



12.12 OSC

OSC stands for Open Sound Control, and is a widely used protocol for passing data between multimedia applications. Fluxus can send or receive messages.

Example
      An example of using osc to communicate between pd and fluxus.
      A fluxus script to move a cube based on incoming osc messages.
      -- osc.scm
     
      (define value 0)
     
      (define (test)
          (push)
          (if (osc-msg "/zzz")
              (set! value (osc 0)))
          (translate (vector 1 0 value))
          (draw-cube)
          (pop))
     
      (osc-source "6543")
      (every-frame (test))
     
      --- EOF
      A PD patch to send control messages to fluxus:
      --- zzz.pd
      #N canvas 618 417 286 266 10;
      #X obj 58 161 sendOSC;
      #X msg 73 135 connect localhost 6543;
      #X msg 58 82 send /zzz \$1;
      #X floatatom 58 29 5 0 0 0 - - -;
      #X obj 58 54 / 100;
      #X obj 73 110 loadbang;
      #X connect 1 0 0 0;
      #X connect 2 0 0 0;
      #X connect 3 0 4 0;
      #X connect 4 0 2 0;
      #X connect 5 0 1 0;
     

12.12.1 (osc-source port-string)

Returns

void

Description

Starts up the osc server, or changes port. Known bug: seems to fail if you set it back to a port used previously.

Example
      (osc-source "4444")	 ; listen to port 4444 for osc messages
     

12.12.2 (osc-msg name-string)

Returns

msgreceived-boolean

Description

Returns true if the message has been received since the last frame, and sets it as the current message for subsequent calls to (osc) for reading the arguments.

Example
      (cond
          ((osc-msg "/hello")              ; if a the /hello message is recieved
              (display (osc 1))(newline)))	; print out the first argument
     

12.12.3 (osc argument-number)

Returns

oscargument

Description

Returns the argument from the current osc message.

Example
      (cond
          ((osc-msg "/hello")              ; if a the /hello message is recieved
              (display (osc 1))(newline)))	; print out the first argument
     

12.12.4 (osc-destination port-string)

Returns

void

Description

Specifies the destination for outgoing osc messages. The port name needs to specify the whole url and should look something like this "osc.udp://localhost:4444"

Example
      (osc-destination "osc.udp:localhost:4444")
      (osc-send "/hello" "s" (list "boo!"))  ; send a message to this destination
     

12.12.5 (osc-peek)

Returns

msg-string

Description

This util function returns the name, and format string and number/string arguments of the last sent message as a string - for debugging your osc network.

Example
      (display (osc-peek))(newline)
     

12.12.6 (osc-send name-string format-string argument-list)

Returns

void

Description

Sends an osc message with the argument list as the osc data. Only supports floats, ints and strings as data. The format-string should be composed of "i", "f" and "s", and must match the types given in the list. This could probably be removed by using the types directly, but doing it this way allows you to explicitly set the typing for the osc message.

Example
      (osc-destination "osc.udp:localhost:4444")
      (osc-send "/hello" "sif" (list "boo!" 3 42.3))  ; send a message to this destination