;; a regular sync to the current master clock
;; this loop is run by all clients
;; (including the master!)
;;
;; also *toplap-lastsync* should never be
;; more than 1/2 second old..
;; if we get to more than 2 seconds old call
;; a general election! because the master
;; must have died!
(define toplap-clock-sync
(lambda ()
(let ((t (split-clock-time (clock:clock))))
(io:osc:send (now) (cons *masterip* *toplap-sync-port*) "/clock/sync/q"
(car t) (cdr t)))
;; if not master and last streamed message
;; was more than 3 seconds ago
;; then call a general election!
(if (and (not *master*)
(> (- (clock:clock) *toplap-lastmsg*) 3.0))
(toplap-clock-election))
(callback (+ (now) 10000) 'toplap-clock-sync)))