Last active
December 7, 2017 02:46
-
-
Save kylev/313de67d5dd43503524a44f1beaffcba to your computer and use it in GitHub Desktop.
"Mary Had a Little Lamb" in Clojure
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 tutorial.maryhad | |
"Implementation of \"Mary Had a Little Lamb\" | |
Found here: | |
http://www.pianolessons4children.com/sheetmusic/Mary_Had_a_Little_Lamb_C_Major.pdf" | |
(:require [leipzig.live :as live] | |
[leipzig.melody :refer :all] | |
[leipzig.scale :as scale] | |
[overtone.inst.piano :refer [piano]] | |
[overtone.live :refer :all])) | |
(definst verboop [freq 440 delay 0.01 dur 0.6] | |
(-> freq | |
saw | |
(rlpf (mul-add (sin-osc 3) 300 (* freq 4))) | |
(* (env-gen (perc 0.01 dur) :action FREE)))) | |
;; (verboop) | |
;; (defmethod live/play-note :melody [{midi :pitch}] (piano midi)) | |
(defmethod live/play-note :melody [{midi :pitch}] (verboop (midi->hz midi))) | |
(def phrase1 | |
"... little lamb." | |
(->> (phrase [3/2 1/2 1 1 1 1 2] | |
[ 2 1 0 1 2 2 2]) | |
(then (phrase [1 1 2 1 1 2] | |
[1 1 1 2 4 4])))) | |
(def phrase2 | |
"... white as snow." | |
(->> (phrase [3/2 1/2 1 1 1 1 1 1] | |
[ 2 1 0 1 2 2 2 2]) | |
(then (phrase [1 1 1 1 4] | |
[1 1 2 1 0])))) | |
(def melody | |
(->> | |
phrase1 | |
(then phrase2) | |
(all :part :melody))) | |
(def track | |
(->> | |
melody | |
(tempo (bpm 110)) | |
(where :pitch (comp scale/G scale/major)) | |
;; (live/play) | |
)) | |
(comment | |
(live/play track) | |
(live/jam (var track)) | |
(live/stop) | |
(piano 90) | |
(stop) | |
(kill 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment