 
        1 (fn [^afterglow.rhythm.Metronome metronome]
            (let [sync-handler (ClockSync. metronome (first result) (ref (ring-buffer max-clock-intervals))
+                                          (ref (ring-buffer max-clock-intervals))
                                           (ref {:master (get-in @clock-sources [(first result) :master])}))]
              (sync-start sync-handler)
              sync-handler))

  "Handles MIDI communication, including syncing a show metronome to MIDI clock pulses."
  (:require [afterglow.rhythm :as rhythm]
            [amalloy.ring-buffer :refer [ring-buffer]]
            [overtone.at-at :refer [now]]
            [overtone.midi :as midi]
            [taoensso.timbre :as timbre])


;; A simple object which holds the values necessary to establish a link between an external
;; source of MIDI clock messages and the metronome driving the timing of a light show.
(defrecord ClockSync [metronome midi-clock-source timestamps means traktor-info] 
    IClockSync
    (sync-start [this]
      (add-synced-metronome midi-clock-source metronome
                            (fn [msg] (sync-handler msg timestamps means metronome traktor-info))))
    (sync-stop [this]
      (remove-synced-metronome midi-clock-source metronome))
    (sync-status [this]
      (dosync
       (ensure timestamps)
       (ensure traktor-info)
       (let [n (count @timestamps)
             lag (when (pos? n) (- (now) (last @timestamps)))
             current (and (= n max-clock-intervals)
                          (< lag 100))
             traktor-current (traktor-beat-phase-current @traktor-info)]
