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

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



(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 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 play []
  (beep (:music @state)))

;; -------------------------
;; Views
