Created
February 6, 2013 14:02
-
-
Save gigasquid/4722675 to your computer and use it in GitHub Desktop.
Mary had a little lamb in overtone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns overtone-tutorial.mary) | |
(use 'overtone.core) | |
(boot-external-server) | |
(definst saw-wave [freq 440 attack 0.01 sustain 0.4 release 0.1 vol 0.4] | |
(* (env-gen (lin-env attack sustain release) 1 1 0 1 FREE) | |
(saw freq) | |
vol)) | |
;; Define a function for convenience | |
(defn note->hz [music-note] | |
(midi->hz (note music-note))) | |
;; Let's make it even easier | |
(defn saw2 [music-note] | |
(saw-wave (midi->hz (note music-note)))) | |
(defonce metro (metronome 120)) | |
(metro) | |
(def mary-notes [:E3 :D3 :C3 :D3 :E3 :E3 :E3 nil :D3 :D3 :D3 | |
nil :E3 :G3 :G3 nil :E3 :D3 :C3 :D3 :E3 :E3 | |
:E3 :E3 :D3 :D3 :E3 :D3 :C3]) | |
(defn song-player [m beat-num notes] | |
(map-indexed (fn [idx note] | |
(when note | |
(at (m (+ idx beat-num)) (saw2 note)))) | |
notes)) | |
(song-player metro (metro) mary-notes) |
We used the external server because I thought it was the only option if you installed the SuperCollider in the Mac Applications directory.
Cool to know about temporal recursion! I will have to check it out. Overtone is very fun. The intersection of technology and art is a very interesting place to explore.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool!
Is there any reason you used an external server rather than the internal one?
Also, your
song-player
relies on the REPL forcing the evaluation of the lazy sequence returned bymap-indexed
and uses themetro
as a glorified lookup table - scheduling all events to happen ahead of time. This is a similar approach to that used by Chris Ford in his compositions. An alternative is to use what's known as temporal recursion which involves schedule a fn to call itself slightly before the event should happen. There's some examples of this in action in theexamples
directory found within Overtone's source.Keep it up :-)