topclock-election   scheme


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

Implementation

;; call a general election!
;; this is a broadcast call
;; if there is an existing master
;; that master will continue in the rolw
;; if there is NO master then the peer
;; with the highest *topclock-election-val* will
;; become the new master.
(define topclock-election
  (lambda ()
    ;; assume we won :)
    (set! *topclock-election-winner* #t)
    (print-with-colors 'yellow 'default #f
                       (print "Nominating myself in topclock election...\n"))
    ;; send message to the world!
    (io:osc:send (now) *topclock-broadcast* "/clock/election/q" *topclock-election-val*)
    ;; wait 4 seconds to find out if we really won!
    ;; if we didn't someone will have forced our
    ;; *topclock-election-winner* to #f
    (sys:sleep (* *au:samplerate* 4.0))
    (if *topclock-election-winner*
        (begin
          (set! *topclock-master* #t)
          (print-with-colors 'green 'default #t
                             (print "which I won!\n"))
          (topclock-streamer (*metro* 'get-beat 1) 1/4))
        (print-with-colors 'red 'default #t
                           (print "which I lost!\n")))
    (set! *topclock-election-winner* #f)
    *topclock-election-winner*))


Back to Index