           (recur (inc i) cur-val)
           (recur (inc i) max-val))))))
 
-(defn draw-select-rect! [canvas-width canvas-height canvas-context x]
+(defn draw-select-rect! [canvas-width canvas-height canvas-context x mouse-down?]
   (.clearRect canvas-context 0 0 canvas-width canvas-height)
-  (.fillRect canvas-context x 0 100 100))
+  (.fillRect canvas-context x 0 100 100)
+  (when mouse-down?
+      (aset canvas-context "strokeStyle" "aliceblue")
+      (aset canvas-context "lineWidth" 6)
+      (.strokeRect canvas-context x 2 100 96)))
+
 
 (defn draw-buffer! [width height canvas-context data]
   (let [step (.ceil js/Math (/ (.-length data) width))

(ns ^:figwheel-always web-audio-cljs.core
  (:require [om.core :as om :include-macros true]
            [om.dom :as dom :include-macros true]
            [web-audio-cljs.audio :as audio]
            [web-audio-cljs.utils :refer [l]]
            [cljs.core.async :refer [put! chan timeout <! >!] :as async])
  (:require-macros [cljs.core.async.macros :refer [go go-loop alt!]]))

(enable-console-print!)

                     :canvas-context nil
                     :canvas-width 400
                     :canvas-height 100
                     :mouse-down false
                     :x-offset 0})

    om/IDidMount
    (did-mount [_]
      (let [{:keys [canvas-width canvas-height left-x x-offset]} (om/get-state owner)
            canvas (om/get-node owner "canvas-ref")
            canvas-context (.getContext canvas "2d")
            x-pos (.-left (.getBoundingClientRect canvas))
            mouse-move-chan (listen (googdom/getElement js/document) (.-MOUSEMOVE EventType))]
        (go
          (while true
            (let [e (<! mouse-move-chan)
                  x (.-clientX e)
                  rel-x (- (- x x-pos) (/ 100 2))
                  {:keys [mouse-down]} (om/get-state owner)]
              (when mouse-down
                (.log js/console "!!!clientX" x)
                (.log js/console "OFFSET x: " rel-x)
                (om/update-state! owner #(assoc % :x-offset rel-x))))))
        (om/update-state! owner #(assoc % :canvas-context canvas-context :canvas canvas))))

    om/IDidUpdate
    (did-update [_ _ _]
      (let [{:keys [canvas-width canvas-height canvas-context x-offset mouse-down]} (om/get-state owner)]
        (if canvas-context
          (draw-select-rect! canvas-width canvas-height canvas-context x-offset mouse-down)
          (om/refresh! owner))))

    om/IRenderState
    (render-state [_ {:keys [canvas-width canvas-height mouse-down]}]
      (dom/canvas #js {:width       canvas-width
                       :height      canvas-height
                       :style       #js {:opacity 0.3 :position "relative" :left (- canvas-width)}
                       :ref         "canvas-ref"
                       :onMouseDown #(om/set-state! owner :mouse-down true)
                       :onMouseUp   #(om/set-state! owner :mouse-down false)}
                  "no canvas"))))

(defn buffer-view [data owner]
  (reify
