                  (-> instrument :piano-keys keys))
     :sound-ready true))
 
+(defn play-piano-key
+  [instrument freq]
+  (println "play")
+  (.play (.bang (get-in instrument [:piano-keys freq :synth])))
+  (assoc-in instrument [:piano-keys freq :on?] true))
+
+(defn stop-piano-key
+  [instrument freq]
+  (if (get-in instrument [:piano-keys freq :on?])
+    (do
+      (println "stop" (get-in instrument [:piano-keys freq :synth]))
+      (.release (get-in instrument [:piano-keys freq :synth]))
+      (assoc-in instrument [:piano-keys freq :on?] false))
+    instrument))
+
 (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)
+                  :position {:x (:clientX x) :y (:clientY x)}
                   :time (.-timeStamp event)})
          (for [x (range (:length touches))] ((keyword (str x)) touches)))))
 
 (defn touch->freq
   [instrument touch]
-  (touch->note (get touch :clientX)
+  (touch->note (get-in touch [:position :x])
                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]

       (condp = c
         c-orientation-change (recur (update-size instrument canvas-id))
         c-touch (recur (fire-touch-data-on-instrument instrument data))
         (recur (step-time instrument))))))
  )

(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) :touchmove)]))

(defn step-time
  [instrument delta]
  (if (not (instrument :scrolling?))
    (assoc instrument :playhead (+ (instrument :playhead) delta))
    instrument))

(let [canvas-id "canvas"
      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 16]

  (go
   (let [draw-ctx (util/get-ctx canvas-id)]
     (util/set-canvas-size! canvas-id (util/get-window-size))
     (loop [instrument (<! c-instrument)
            timer (timeout frame-delay)]
       (let [[data c] (alts! [c-instrument timer])]
         (condp = c
           c-instrument (recur data timer)
           (do (draw-instrument draw-ctx instrument)
               (recur instrument (timeout frame-delay))))))))

  (go
   (loop [instrument (update-size (create-instrument (scales/c-minor)) canvas-id)]
