 (defn create-touch-input-channel
   [canvas-id]
   (async/merge [(util/listen (dom/getElement canvas-id) :touchstart)
-                (util/listen (dom/getElement canvas-id) :touchend)]))
+                (util/listen (dom/getElement canvas-id) :touchend)
+                (util/listen (dom/getElement canvas-id) :touchmove)]))
+
 (defn step-time
-  [instrument]
-  (let [now (.getTime (js/Date.))]
-    (-> instrument
-        (assoc :playhead (+ (instrument :playhead)
-                            (- now (instrument :previous-time))))
-        (assoc :previous-time now))))
+  [instrument delta]
+  (if (not (instrument :scrolling?))
+    (assoc instrument :playhead (+ (instrument :playhead) delta))
+    instrument))
 
 (let [canvas-id "canvas"
-      c-instrument (chan)
+      c-instrument (chan (sliding-buffer 1))
       c-orientation-change (util/listen js/window :orientation-change)
       c-touch (create-touch-input-channel canvas-id)
-      frame-delay 30]
+      frame-delay 16]
 
   (go
    (let [draw-ctx (util/get-ctx canvas-id)]
      (util/set-canvas-size! canvas-id (util/get-window-size))
-     (loop [instrument (<! c-instrument)]
-       (let [[data c] (alts! [c-instrument (timeout frame-delay)])]
+     (loop [instrument (<! c-instrument)
+            timer (timeout frame-delay)]
+       (let [[data c] (alts! [c-instrument timer])]
          (condp = c
-           c-instrument (recur data)
+           c-instrument (recur data timer)
            (do (draw-instrument draw-ctx instrument)
-               (recur instrument)))))))
+               (recur instrument (timeout frame-delay))))))))
 
   (go
    (loop [instrument (update-size (create-instrument (scales/c-minor)) canvas-id)]

                 (-> instrument :piano-keys keys))
    :sound-ready true))

(defn touch-data->touches [touch-data]
  (let [event (.-event_ touch-data)
        touches (js->clj (.-changedTouches event) :keywordize-keys true)]
    (map (fn [x] {:type (.-type event)
                  :touch-id (:identifier x)
                  :clientX (:clientX x)
                  :time (.-timeStamp event)})
         (for [x (range (:length touches))] ((keyword (str x)) touches)))))

(defn touch->freq
  [instrument touch]
  (touch->note (get touch :clientX)
               instrument))

(def instrument-fns
  {"touchstart" (fn
                  [instrument {touch-id :touch-id time :time :as event}]
                  (let [freq (touch->freq instrument event)
                        piano-key (get-in instrument [:piano-keys freq])]
                    (if-not (:on? piano-key)
                      (do
                        ;; (println "play")
                        (.play (.bang (:synth piano-key)))
                        (-> instrument
                            (assoc :notes (conj (get instrument :notes)
                                                {:freq freq :on time :off nil :touch-id touch-id}))
                            (assoc-in [:piano-keys freq :on?] true))))))
   "touchend" (fn
                [{piano-keys :piano-keys :as instrument}
                 {touch-id :touch-id time :time :as event}]
                (let [freqs-on (atom [])
                      instrument (assoc instrument :notes
                                        (doall
                                         (map (fn [{freq :freq :as note}]
                                                (if (= touch-id (note :touch-id))
                                                  (do
                                                    (swap! freqs-on conj freq)
                                                    ;; (println "release")
                                                    (.release ((get piano-keys freq) :synth))
                                                    (assoc note :off time))
                                                  note))
                                              (-> instrument :notes))))]
                  (reduce (fn [inst freq]
                            (assoc-in inst [:piano-keys freq :on?] false))
                          instrument
                          @freqs-on)))})

(defn fire-event-on-instrument
  [instrument event]
  (let [f-instrument (get instrument-fns (:type event))]
    (or (and f-instrument (f-instrument instrument event))
        instrument)))

(defn maybe-init-synths
  [instrument]

     :notes ()
     :w 0 :h 0 :sound-ready false
     :px-per-ms 0.04
     :cur-touches {}
     :scrolling? false
     :start start
     :playhead start}))

(defn add-synths-to-instrument
