     om/IRender
     (render [_]
       (dom/div nil
-               (dom/button #js {:className "toggle-recording"
-                                :onClick (fn [e]
-                                           (if is-recording
-                                             (do
-                                               (save-recording! data audio-recorder audio-context analyser-node)
-                                               (om/transact! data :is-recording not))
-                                             (do
-                                               (.record audio-recorder)
-                                               (om/transact! data :is-recording not))))}
-                           (if is-recording "Stop" "Record"))))))
+        (dom/button #js {:className "toggle-recording"
+                         :onClick (fn [e]
+                                    (if is-recording
+                                      (do
+                                        (save-recording! data audio-recorder audio-context analyser-node)
+                                        (om/transact! data :is-recording not))
+                                      (do
+                                        (.record audio-recorder)
+                                        (om/transact! data :is-recording not))))}
+                    (if is-recording "Stop" "Record"))))))
+
+(defn clamped-rel-mouse-pos [e min-x max-x {:keys [x-offset mouse-down-pos mouse-down]}]
+  (if mouse-down
+    (let [x (.-clientX e)
+          [old-x old-y] mouse-down-pos
+          new-x (+ x-offset (- x old-x))]
+      [(.clamp goog.math new-x min-x max-x) old-x old-y])
+    nil))
 
 (defn wave-selector-view [data owner]
   (reify

                          :recorded-buffers []
                          :audio-context audio-context}))

(defn listen [el type]
  (let [out (chan)]
    (events/listen el type
      (fn [e] (put! out e)))
    out))

(defn lin-interp [x0 x1 y0 y1]
  (fn [x]

            canvas-context (.getContext canvas "2d")
            mouse-move-chan (listen js/document (.-MOUSEMOVE EventType))
            mouse-up-chan (listen js/document (.-MOUSEUP EventType))]
        (go
          (while true
            (alt!
              mouse-move-chan
              ([v] (when-let [[clamp-x _ old-y] (clamped-rel-mouse-pos v 0 (- 400 canvas-width) (om/get-state owner))]
                     (om/update-state! owner #(assoc % :x-offset clamp-x :mouse-down-pos [(.-clientX v) old-y]))))
              mouse-up-chan
              ([_] (om/set-state! owner :mouse-down false)))))
        (om/update-state! owner #(assoc % :canvas-context canvas-context :canvas canvas))))

    om/IDidUpdate
