Skip to content

Commit

Permalink
Play Jingle Bells with a tb303
Browse files Browse the repository at this point in the history
  • Loading branch information
mwunsch committed Dec 23, 2015
1 parent 28da39f commit 62763e3
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions src/sonic_sketches/core.clj
Expand Up @@ -46,36 +46,44 @@
[{:pitch (note :E4) :duration 1/4}
{:pitch (note :E4) :duration 1/4}
{:pitch (note :E4) :duration 1/2}

{:pitch (note :E4) :duration 1/4}
{:pitch (note :E4) :duration 1/4}
{:pitch (note :E4) :duration 1/2}

{:pitch (note :E4) :duration 1/4}
{:pitch (note :G4) :duration 1/4}
{:pitch (note :C4) :duration 1/4}
{:pitch (note :D4) :duration 1/4}
{:pitch (note :E4) :duration 1}])

(defn play-monotron
"Accepts a monotron synth, a metronome, and a sequence of maps with :pitch and :duration"
[tron nome notes]
(let [beat (nome)
{pitch :pitch duration :duration :as note} (first notes)]
(if (some? note)
(at (nome beat) (ctl tron :note pitch))
(apply-by (nome (inc beat)) #(kill tron)))
(apply-by (+ (nome (inc beat)) (* (metro-tick nome) duration))
#'play-monotron [tron nome (rest notes)])))
{:pitch (note :E4) :duration 1}

{:pitch (note :F4) :duration 1/4}
{:pitch (note :F4) :duration 1/4}
{:pitch (note :F4) :duration 1/4}
{:pitch (note :F4) :duration 1/4}

{:pitch (note :F4) :duration 1/4}
{:pitch (note :E4) :duration 1/4}
{:pitch (note :E4) :duration 1/2}

{:pitch (note :E4) :duration 1/4}
{:pitch (note :D4) :duration 1/4}
{:pitch (note :D4) :duration 1/4}
{:pitch (note :E4) :duration 1/4}

{:pitch (note :D4) :duration 1/2}
{:pitch (note :G4) :duration 1/2}
])

(defn play
"Record a fn that starts a synth-node and call a callback when that node is destroyed."
[ugen-fn callback]
(recording-start "./sounds/test.wav")
(after-delay 1500 ; We delay b/c recording-start has a 1.5s pause
#(let [synth (ugen-fn)
node-id (:id synth)]
(on-event [:overtone :node-destroyed node-id] (fn [ev] (do
(recording-stop)
(callback))) ::synth-destroyed-handler))))
"Accepts a monotron synth, a metronome, and a sequence of maps with :pitch and :duration"
[nome notes]
(let [beat (nome)
{pitch :pitch duration :duration :as note} (first notes)
decay (* (metro-tick nome) duration)]
(at (nome beat) (overtone.inst.synth/tb303 :note pitch :cutoff 1050 :decay (/ decay 1000)))
(apply-by (+ (nome (inc beat)) decay) #'play [nome (rest notes)])))

(defn -main
[& args]
Expand Down

0 comments on commit 62763e3

Please sign in to comment.