[Fluxus] handy osc function (maybe)

evan.raskob [lists] lists at lowfrequency.org
Mon Sep 28 07:13:40 PDT 2009


kind of a question, kind of an answer.

playing around with sending / receiving osc messages during  
performances.  what I'd like to do is attach certain functions to  
certain osc messages, with varying numbers of arguments.  so I did.   
how does this look? is there a better way of doing this?

2 files included here, run 2 instances of fluxus and try sending osc  
msgs back and forth to make the "mouse cursor" move on one while you  
move the mouse on the other.

cheers
evan



;----- begin osc-send-test.scm
;----- send some mouse data


(osc-destination "osc.udp://localhost:3333")

(define (send-mouse)
     (osc-send "/mouse" "ii" (list (mouse-x) (mouse-y)))
     )

(every-frame (send-mouse))





;----- begin osc-receive-test.scm
;----- attach a function to an osc message and a list of expected values

(osc-source "3333")

;--- this is just a utility function for printing out the 1st osc  
message
(define (print-osc-msgs path val)
     (cond [(not (osc-msg path))
             val]
         [else
             (let [(result (osc 0))]
                 (printf "~s: ~s" path result)
                 (print-osc-msgs path result)
                 )
             ]
         )
     )


;--- run a function on an osc message with a list of arguments (osc  
values indices)
;--- ex: to get both values of the osc message "/mouse 10 20" you'll  
need to match the
;--- path "/mouse" and then two arguments, index 0 (10) and index 1 (20)

(define (osc-func path func args val)
     (cond [(not (osc-msg path))
             #f]
         [else
             (let [(osc-args (list))]
                 (for [(n args)]
                     ;(printf "~s: ~s ~s" path msg0 msg1)(newline)
                     (set! osc-args (append osc-args (list (osc n))))
                     )
                 (func osc-args)
                 (osc-func path func args #t)
                 )

             ]
         )
     )


;--- scale a mouse x value to world coordinates

(define (mouse-pos-x x)
     (* 20 (- (/ x (vector-ref (get-screen-size) 0)) 0.5)))

;--- scale a mouse y value to world coordinates

(define (mouse-pos-y y)
     (* 15 (- (- 1 (/ y (vector-ref (get-screen-size) 1))) 0.5)))

;--- make something visual
(define p (build-plane))


(define (render)
     ;(printf "~a~n" (osc-peek))

     (osc-func "/mouse"
         (lambda (args)
             (cond [args
                     (with-primitive p
                         (let [(x (list-ref args 0)) (y (list-ref args  
1))]
                             (identity)
                             (translate (vector (mouse-pos-x x) (mouse- 
pos-y y) 0))
                             ))
                     ])
             )
         (list 0 1)
         #t)

     (print-osc-msgs "/volume" 0)
     (print-osc-msgs "/pitch" 0)
     (print-osc-msgs "/key_note" 0)
     )

(every-frame (render))




More information about the Fluxus mailing list