(define clock-client-receive
(lambda (timestamp address srcip srcport . args)
(cond ((string=? address "/clock/bpm/update")
;; bpm/update is same as bpm/set but is a broadcast
;; call from the master
;; (i.e. we don't care so much if this UDP packet gets lost
(let ((time (join-clock-time (car args) (cadr args)))
(beat-n (caddr args))
(beat-d (cadddr args))
(bpm (car (cddddr args))))
(if (and (not *master*) (<> bpm *clock-oldbpm*))
(begin
(set! *clock-oldbpm* bpm)
(*metro* 'set-tempo bpm (clock->samples time) (/ beat-n beat-d))))))
((string=? address "/clock/cycle/update")
;; bpm/update is same as bpm/set but is a broadcast
;; call from the master
;; (i.e. we don't care so much if this UDP packet gets lost
(let ((beat-n (car args))
(beat-d (cadr args))
(cycle (caddr args)))
(if (and (not *master*) (<> cycle *clock-oldcycle*))
(begin
(set! *clock-oldcycle* cycle)
(*metro* 'set-cycle cycle (/ beat-n beat-d))))))
((string=? address "/clock/offset/r")
;; retrieve clock offset
(let ((offset (join-clock-time (car args) (cadr args))))
(clock:adjust-offset offset)))
((string=? address "/clock/state/r")
(let ((bpmtime (join-clock-time (car args) (cadr args)))
(bpmbeat (/ (caddr args) (cadddr args)))
(bpm (car (cddddr args)))
(cyclebeat (/ (cadr (cddddr args)) (caddr (cddddr args))))
(cycle (cadddr (cddddr args))))
(println 'bpmtime: bpmtime 'bpmbeat: bpmbeat 'bpm: bpm
'cyclebeat: cyclebeat 'cycle: cycle)))
(else (println 'bad 'osc 'message: address))))))