 
 (defonce context (js/window.AudioContext.))
 (defn beep [freq]
+  (let [start (.-currentTime context)
+        stop (inc start)]
     (doto (.createOscillator context)
       (.connect (.-destination context))
       (-> .-frequency .-value (set! freq))
       (-> .-type (set! "square"))
-      (.start 0)))
-
-(defn kill [oscillator]
-  (.stop oscillator 0))
+      (.start start)
+      (.stop stop))))
 
 (defn handle [expr-str]
   (swap! state assoc-in [:text] expr-str)
   (when-let [value (evaluate expr-str)]
     (swap! state assoc-in [:music] value)))
 
-(defn toggle []
-  (if (:playing @state)
-    (let [oscillator (:playing @state)]
-      (kill oscillator)
-      (swap! state assoc-in [:playing] nil))
-    (let [oscillator (beep (:music @state))]
-      (swap! state assoc-in [:playing] oscillator))))
+(defn play []
+  (beep (:music @state)))
 
 ;; -------------------------
 ;; Views

;; Model
(defonce state
  (atom {:music nil
         :text ""
         :playing nil}))

;; -------------------------
;; Behaviour

   [:div [:input {:type "text"
                  :value (:text @state)
                  :on-change #(-> % .-target .-value handle)}]
    [:button {:on-click play} "Start/stop"]]
   [:div
    (:music @state)]])

