                              (om/update! bpm :next-beat (+ t interval))))))
                      (when (om/get-state owner :mounted)
                        (.requestAnimationFrame js/window cb))))
-                 (let [click-channel (om/get-state owner :click-channel)]
+                 (let [tempo-channel (om/get-state owner :tempo-channel)]
                    (go (loop []
-                         (let [new-interval-millis (<! click-channel)]
+                         (let [new-interval-millis (<! tempo-channel)]
                            (if (false? new-interval-millis)
                              (stop-interval)
                              (start-interval new-interval-millis))

                 (dot 3)
                 (dot 0))))))

(defn keylistener [app owner]
  (reify
    om/IDidMount
    (did-mount [_]
      (let [f (fn [e] (when (= "Shift" (.-key e)) (om/update! app :should-stop (= "keydown" (.-type e)))))]
        (.addEventListener js/document "keydown" f)
        (.addEventListener js/document "keyup" f)))

    om/IRender
    (render [_] (dom/div nil))))

(om/root
 (fn [app owner]
   (reify
     om/IInitState
     (init-state [_] {:sound-channel (chan)
                      :click-channel (chan)})
     om/IRenderState
     (render-state
      [_ {:keys [sound-channel click-channel]}]
      (dom/div nil
               (dom/h1 nil "metronome")
               (om/build clock (:bpm app) {:init-state {:sound-channel sound-channel :click-channel click-channel}})
               (om/build sound (:meter app) {:init-state {:sound-channel sound-channel}})
               (om/build click app {:init-state {:click-channel click-channel}})
               (om/build dots (:meter app))
               (om/build keylistener app))
      )))
 app-state
 {:target (. js/document (getElementById "app"))})

  (:require-macros [cljs.core.async.macros :refer [go]]))

(defonce app-setup

  (do
    (enable-console-print!)))

(defonce app-state (atom {:bpm {} 
                          :meter {:count 0}}))

(defn clock [bpm owner]
  (letfn [(start-interval [millis] 
            (om/update! bpm :interval millis)
            (om/update! bpm :next-beat nil))
          (stop-interval []
            (om/update! bpm :interval nil))]
    (reify
      om/IInitState
