topclock-sync   scheme


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/libs/core/topclock.xtm

Implementation

;; a regular sync to the current master clock
;; this loop is run by all clients
;; (including the master!)
;;
;; also *topclock-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 topclock-sync
  (lambda (cnt)
    ;; (if (= 0 (modulo cnt 25)) (println '[topclock] 'master: *topclock-master*))
    (if (not *topclock-master*)
        (osc_send_one_double *topclock-master-ip* *topclock-port*
                             "/clock/sync/q"
                             (1970->1900 (clock:clock))))
    ;; if not master and last streamed message
    ;; was more than 3 seconds ago
    ;; then call a general election!
    (if (and (not *topclock-master*)
             (> (- (clock:clock) *topclock-lastmsg*) 3.0))
        (topclock-election))
    (callback (+ (now) 10000) 'topclock-sync (+ cnt 1))))


Back to Index