Last active
August 29, 2015 13:57
-
-
Save danosborne/9631756 to your computer and use it in GitHub Desktop.
First London Clojurians Clojure Dojo and dabble with Overtone - in honor of St Patrick's Day
This file contains 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
; Authors - Greg Hawkins, Patrick Gallagher, Dan Osborne | |
(ns diddly.core | |
(:use [overtone.core] | |
[overtone.inst.piano] | |
[overtone.inst.synth])) | |
(boot-external-server) | |
(definst saw-wave [freq 440 attack 0.01 sustain 0.2 release 0.05 vol 0.4] | |
(* (env-gen (env-lin attack sustain release) 1 1 0 1 FREE) | |
(saw freq) | |
vol)) | |
(defn saw-note [n] | |
(saw-wave (midi->hz (note n)))) | |
(defn play-chord [c] | |
(doseq [note c] (saw-note note))) | |
(def kick (sample (freesound-path 2086))) | |
(def bodhrun (sample (freesound-path 65833))) | |
(def progression [[:D3 :major] | |
[:G3 :major] | |
[:D3 :major] | |
[:A3 :major] | |
[:B3 :minor] | |
[:A3 :major] | |
[:G3 :major] | |
[:D3 :major]]) | |
(defn looper [nome tick bass bod play-note] | |
(let [beat (nome)] | |
(case (mod tick 3) | |
0 (do (at (nome beat) (bass)) (at (nome beat) (play-note))) | |
1 (when (> 0.5 (rand)) (at (nome beat) (play-note))) | |
2 (do (at (nome beat) (bod)) (at (nome beat) (play-note)))) | |
(when (zero? (mod tick 12)) | |
(at (nome beat) (play-chord (apply chord (nth progression (mod (/ tick 12) 4)))))) | |
(apply-at (nome (inc beat)) looper nome (inc tick) bass bod play-note []))) | |
(def D-ISH [:D4 :D4 :D4 :E4 :F#4 :F#4 :G4 :A4 :A4 :A4 :B4 :C#4 :D5]) | |
(defn play-note [] | |
(saw-note (rand-nth D-ISH))) | |
(def irish-tempo (metronome (* 250 3))) | |
(defn play-tune [] | |
(looper irish-tempo 0 | |
(fn [] (kick 1 :amp 5.0)) | |
(fn [] (bodhrun 1 :amp 7.0)) | |
play-note)) | |
(defn -main[& args] | |
(play-tune)) |
This file contains 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
(defproject diddly "0.1.0-SNAPSHOT" | |
:description "FIXME: write description" | |
:url "http://example.com/FIXME" | |
:license {:name "Eclipse Public License" | |
:url "http://www.eclipse.org/legal/epl-v10.html"} | |
:dependencies [[org.clojure/clojure "1.5.1"] | |
[overtone "0.9.1"]] | |
:main diddly.core) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment