           (schedule-pattern beat-t beat-sep-t sound beat-info)
           (at beat-t (when beat-info (apply sound (flatten1 beat-info)))))))))
 
+(def live-sequencer-states {})
+(def *live-sequencer-states (atom live-sequencer-states))
+
 (defn live-sequencer
+  [curr-t pat-dur live-patterns uid]
+  (let [running (@*live-sequencer-states uid)]
+    (when running
+      (doseq [[sound pattern] @live-patterns]
+        (schedule-pattern curr-t pat-dur sound pattern))
+      (let [new-t (+ curr-t pat-dur)]
+        (apply-by new-t #'live-sequencer [new-t pat-dur live-patterns uid]))
+      )))
+
+(defn start-live-sequencer
   [curr-t pat-dur live-patterns]
-  (doseq [[sound pattern] @live-patterns]
-    (schedule-pattern curr-t pat-dur sound pattern))
-  (let [new-t (+ curr-t pat-dur)]
-    (apply-by new-t #'live-sequencer [new-t pat-dur live-patterns])))
+  (let [uid (trig-id)]
+    (swap! *live-sequencer-states assoc uid true)
+    (live-sequencer curr-t pat-dur live-patterns uid)
+    uid
+    ))
 
 (def a {:rate 2 :amp 0.1 :time-scale-max 5})
+(def a {:rate 10 :amp 0.1 :time-scale-max 10})
 (def a {:rate 100 :amp 0.4 :time-scale-max 5})
 (def b {:pan -1 :freq 1000})
 (def c {:freq 25000 :amp 0.2})

  (odoc apply-by)
  (odoc apply-at)
  (odoc at-at)
  )

    ;;(live-sequencer (now) ms-per-pattern *beats)
    ;; (live-sequencer (metro (inc (metro))) ms-per-pattern *beats))
    (live-sequencer (metro (next-beat (metro) 0 beat-per-pattern)) (* 16 ms-per-pattern) *beats16))
  (let [ms-per-pattern (* 1000 dur-per-pattern)]
    ;;(live-sequencer (now) ms-per-pattern *beats)
    ;; (live-sequencer (metro (inc (metro))) ms-per-pattern *beats))
    (start-live-sequencer (metro (next-beat (metro) 0 beat-per-pattern)) (* 16 ms-per-pattern) *beats16))
  (print @*live-sequencer-states)
  (swap! *live-sequencer-states assoc 3 false)
  (reset! *beats16 beats16))


