Skip to content

Commit

Permalink
Switch from using time to event handling.
Browse files Browse the repository at this point in the history
Use :node-destroyed event to trigger recording stop.
  • Loading branch information
mwunsch committed Nov 30, 2015
1 parent df0a396 commit 2123850
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/sonic_sketches/core.clj
Expand Up @@ -5,15 +5,18 @@
(definst mousedrums []
(example membrane-circle :mouse))

(defn play-then-quit
(defn play
"Demo synth for n millis, then exit"
[t ugen-fn]
[ugen-fn callback]
(recording-start "./sounds/test.wav")
(ugen-fn)
(after-delay t (fn [] ((do (recording-stop)
(System/exit 0))))))
(let [synth (ugen-fn)
node-id (:id synth)]
(on-event [:overtone :node-destroyed node-id] (fn [ev] (do
(recording-stop)
(callback))) ::synth-destroyed-handler)))

(defn -main
"I like to play the drums by clicking my mouse on the screen."
[& args]
(play-then-quit *demo-time* #(demo (example dbrown :rand-walk))))
(play #(demo (example dbrown :rand-walk))
#(println "Stopped!")))

0 comments on commit 2123850

Please sign in to comment.