Skip to content

Instantly share code, notes, and snippets.

@matschaffer
Created May 31, 2013 19:01
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 matschaffer/5687159 to your computer and use it in GitHub Desktop.
Save matschaffer/5687159 to your computer and use it in GitHub Desktop.
(ns soundscape.core
(:require [leipzig.live :refer :all]
[leipzig.melody :refer :all]
[leipzig.scale :refer :all]
[leipzig.canon :refer :all]
[overtone.live :as overtone]
[overtone.synth.stringed :as strings]
[overtone.at-at :as atat]))
(def wind-pool (atat/mk-pool))
(def wind-samples (ref 0))
(def wind-cap 20)
(def wind (overtone/sample (overtone/freesound-path 158685)))
(defn monitored-wind []
(wind)
(dosync (alter wind-samples inc))
(atat/after 1500 #(dosync (alter wind-samples dec)) wind-pool))
(def chirp (overtone/sample (overtone/freesound-path 164485)))
(defn httpstatus [code]
(cond
(and (>= code 200) (< code 300)) (if (< @wind-samples wind-cap) (monitored-wind))
(and (>= code 500) (< code 600)) (chirp)
:else (println "No sound for " code)))
; (httpstatus 200)
; (httpstatus 500)
(strings/gen-stringed-synth ektara 1 true)
(defn pick [distort amp {midi :pitch, start :time, length :duration}]
(let [synth-id (overtone/at start
(ektara midi :distort distort :amp amp :gate 1))]
(overtone/at (+ start length) (overtone/ctl synth-id :gate 0))))
(def pitch-mode major)
(defn bad []
(def pitch-mode minor))
(defn good []
(def pitch-mode major))
; (bad)
; (good)
(defmethod play-note :leader [note]
(pick 0.7 1.0 (update-in note [:pitch] (comp C pitch-mode))))
(defmethod play-note :follower [note]
(pick 0.3 1.0 note))
(defmethod play-note :bass [note]
(pick 0.9 0.2 (update-in note [:pitch] #(- % 12))))
(def melody
; Row, row, row your boat,
(->> (phrase [3/3 3/3 2/3 1/3 3/3]
[ 0 0 0 1 2])
(then
; Gently down the stream,
(phrase [2/3 1/3 2/3 1/3 6/3]
[ 2 1 2 3 4]))
(then
; Merrily, merrily, merrily, merrily,
(phrase (repeat 12 1/3)
(mapcat (partial repeat 3) [7 4 2 0])))
(then
; Life is but a dream!
(phrase [2/3 1/3 2/3 1/3 6/3]
[ 4 3 2 1 0]))
(where :part (is :leader))))
(def bass
(->> (phrase [1 1 2]
[0 -3 0])
(where :part (is :bass))
(times 4)))
(defn row-row [speed key]
(->> melody
(with bass)
(times 2)
(canon (comp (simple 4)
(partial where :part (is :follower))))
(where :time speed)
(where :duration speed)
play))
(def speed (bpm 120))
(def rrb (->> melody
(where :time speed)
(where :duration speed)))
(defn appstate [status]
(case status
"good" (good)
"bad" (bad)))
; (appstate "bad")
; (jam rrb)
; (def rrb nil)
; (row-row (bpm 120) (comp C sharp major))
; (row-row (bpm 90) (comp low B flat minor))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment