 
 (defn create-instrument
   [scale]
-  {:piano-keys (into (sorted-map) (map (fn [freq] [freq {}])
-                                       scale))
+  {:piano-keys (into (sorted-map) (map-indexed (fn [i freq] [freq {:n i}])
+                                               scale))
    :notes [] :w 0 :h 0 :sound-ready false
    :px-per-ms 0.01
    :start (.getTime (js/Date.))

  (let [freqs (-> instrument :piano-keys keys)
        piano-key-w (piano-key-width instrument)]
    (dotimes [n (count freqs)]
      (let [freq (nth freqs n)
            note (latest-note instrument freq)
            piano-key-on (and note (-> note :off nil?))]
        (set! (.-fillStyle draw-ctx)
              ((if piano-key-on :light :dark) (color-set instrument freq)))
        (.fillRect draw-ctx
                   (* n piano-key-w)
                   (t->px instrument playhead)

  [{w :w h :h playhead :playhead :as instrument}]
  {:x 0 :y (t->px instrument playhead) :w w :h h})

(defn draw-note
  [draw-ctx instrument note]
  (let [{x :x y :y w :w h :h} (note-rect note instrument)]
