Skip to content

Instantly share code, notes, and snippets.

@neatonk
Created May 7, 2012 21:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neatonk/2630543 to your computer and use it in GitHub Desktop.
Save neatonk/2630543 to your computer and use it in GitHub Desktop.
All new sampled piano in Overtone.
;; A simple musical example illustrating the use of gating to control the note length
;; of the updated sampled-piano available in overtone 0.7-dev.
(use 'overtone.live)
;; wait ...
;; if you already downloaded the piano samples, do this first.
;; you'll only to do this once. Adjust the path if needed.
(register-assets! :overtone.inst.sampled-piano/MISStereoPiano
"~/.overtone/assets/www.ericmhobbs.com-Blackhole-music-backup-MISStereoPiano.zip--1263714981/Piano/")
(use 'overtone.inst.sampled-piano)
;; downloading....
;; start a metronome
(def metro (metronome (* 2 120)))
;; define some 'notes'
(defn p1 [b]
[{:beat (+ 0 b) :note :E4 :note-value 2}
{:beat (+ 2 b) :note :D4 :note-value 2}
{:beat (+ 4 b) :note :C4 :note-value 3.5}])
;; def some more notes
(defn p2 [b]
(concat
(for [b (range b (+ b 4))]
{:beat b :note :C4 :note-value 1})
(for [b (range (+ b 4) (+ b 8))]
{:beat b :note :D4 :note-value 1})))
;; put it all together
(def hcb (concat (p1 1) (p1 9) (p2 17) (p1 25)))
;; take a note spec and play it for :note-value beats.
;; sampled-piano is an inst now, you can send it ctl messages by name.
(defn play-note
[inst beat metro note-spec]
;(println note-spec)
(let [n (note (:note note-spec))
v (or (:note-value note-spec) 1)]
(at (metro beat)
(inst n))
(at (-> (metro (+ beat v))
(- 1))
(ctl inst :gate 0))))
;; play a series of 'notes'
(defn play-notes
[inst beat metro notes]
(let [[n1 n2 & more] notes]
(play-note inst beat metro n1)
(when n2
(let [beat (+ beat (- (:beat n2)
(:beat n1)))]
(apply-at (metro beat)
#'play-notes [inst beat metro (rest notes)])))))
(comment
;; eval and laugh...
(play-notes sampled-piano (metro) metro hcb)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment