toplap-clock-election   scheme


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/libs/core/toplap_clock.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 *election-val* will
;; become the new master.
(define toplap-clock-election
  (lambda ()
    ;; assume we won :)
    (set! *election-winner* #t)
    (ascii-print-color 0 5 9)
    (println 'Nominating 'myself 'in 'toplap 'clock 'election!)
    (ascii-print-color 0 7 9)
    ;; send message to the world!
    (io:osc:send (now) *toplap-sync-broadcast* "/clock/election/q" *election-val*)
    ;; wait 4 seconds to find out if we really won!
    ;; if we didn't someone will have forced our
    ;; *election-winner* to #f
    (sys:sleep (* *au:samplerate* 4.0))
    (if *election-winner*
        (begin
          (set! *master* #t)
          (ascii-print-color 1 5 9)
          (println 'Which 'I 'Won!)
          (ascii-print-color 0 7 9))
        (begin
          (ascii-print-color 1 5 9)
          (println 'Which 'I 'lost!)
          (ascii-print-color 0 7 9)))
    (set! *election-winner* #f)))


Back to Index