      :notes ()
      :w 0 :h 0 :sound-ready false
      :px-per-ms 0.04
+     :cur-touches {}
+     :scrolling? false
      :start start
-     :previous-time start
      :playhead start}))
 
 (defn add-synths-to-instrument

                 (-> 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]

(defn piano-key-width
  [{piano-keys :piano-keys w :w}]
  (.round js/Math (/ w (count piano-keys))))

(defn t->px
  [{start :start px-per-ms :px-per-ms} t]
