Skip to content

Instantly share code, notes, and snippets.

@ctford
Created September 28, 2014 19:22
Show Gist options
  • Save ctford/ecf4285826efa4949ba5 to your computer and use it in GitHub Desktop.
Save ctford/ecf4285826efa4949ba5 to your computer and use it in GitHub Desktop.
Tuesday - written with Overtone and Leipzig.
(ns tuesday.song
(:require [overtone.live :refer :all]
[leipzig.melody :refer :all]
[leipzig.scale :as scale]
[leipzig.live :as live]
[leipzig.chord :as chord]
[leipzig.temperament :as temperament]))
; Instruments
(definst bass [freq 110 volume 1.0]
(-> (sin-osc freq (sin-osc 1))
(+ (sin-osc (* freq 1/2)))
(clip2 0.8)
(* (env-gen (perc 0.01 0.3) :action FREE))
(* volume)))
(definst waver [freq 440 dur 1 volume 1.0]
(-> (sin-osc freq (sin-osc 3))
(+ (sin-osc (* 1/2 freq) (sin-osc 2)))
(* (env-gen (adsr 0.2 0.6 0.3) (line:kr 1 0 dur) :action FREE))
(* 1/3 volume)))
(definst metallia [freq 440 dur 1 volume 1.0]
(-> (sin-osc freq (sin-osc 1))
(+ (sin-osc (* 1/2 freq) (sin-osc 1/3)))
(clip2 (mul-add (saw 1/4) 0.2 0.7))
(* (env-gen (adsr 0.03 0.6 0.3) (line:kr 1 0 dur) :action FREE))
(* 1/4 volume)))
(definst drum [freq 220]
(-> (line:kr freq (* freq 1/2) 0.5)
sin-osc
(+ (sin-osc freq))
(* (env-gen (perc 0.01 0.1) :action FREE))))
; Arrangement
(defmethod live/play-note :bass [{hertz :pitch}] (bass hertz))
(defmethod live/play-note :beat [{hertz :pitch}] (drum hertz))
(defmethod live/play-note :accompaniment [{hertz :pitch seconds :duration}] (metallia hertz seconds))
(defmethod live/play-note :melody [{hertz :pitch seconds :duration}] (metallia hertz seconds 1.5))
(defmethod live/play-note :harmony [{hertz :pitch seconds :duration}] (waver hertz seconds))
; Composition
(defn minor [chord] (update-in chord [:iii] (scale/from -1/2)))
(def progression [chord/triad
(-> chord/triad (update-in [:i] dec))
(-> chord/triad (update-in [:i] (comp dec dec)))
(-> chord/triad (chord/root -4) minor)])
(def bassline
(->> (mapthen
(fn [{:keys [i iii v]}]
(phrase [1 2/3 1/3 2/3 1/3 1 1 ] [i v i v i v i iii]))
(take 3 progression))
(then (phrase [1 1 1 2/3 1/3 1] [-4 -2.5 0 4.5 4 3]))
(where :pitch (comp scale/lower scale/lower))
(where :part (is :bass))))
(def accompaniment
(->>
(phrase (repeat 5) progression)
(where :part (is :accompaniment))))
(def melody
(->>
(phrase [2/3 13/3 5/3 9/3 1/3 2/3 13/3 2/3 13/3]
[ 1 2 1 0 0 1 2 3 0])
(where :pitch scale/raise)
(where :part (is :melody))))
(def harmony
(->>
(phrase [5 5 5 1 2 1 1] [0 -1 4 3 4 4.5 3])
(where :part (is :harmony))))
(def jiggle
(->>
(phrase [5 6] [4 7])
(then (phrase [2/3 1/3 2/3 1/3 2/3 1/3 2/3 1/3 5]
[4 5 4 5 4 3.5 3 2 0]))
(where :part (is :melody))))
(def beat
(->>
(phrase (cycle [2/3 1/3]) (cycle [-7 -7 -4 0 -4]))
(where :pitch scale/lower)
(take 10)
(times 4)
(where :part (is :beat))))
(def plain
(->> (mapthen
(fn [{:keys [i iii v]}]
(phrase (repeat 1) [i v v v iii]))
(take 3 progression))
(then (phrase [6/3 2/3 1/3 6/3] [3 2 1 0]))
(where :part (is :melody))))
; Track
(def track
(->>
(times 2 (with bassline plain))
(then (times 2 (with bassline beat plain)))
(then (times 2 (with bassline beat melody accompaniment)))
(then (times 2 (with bassline beat melody accompaniment harmony)))
(then bassline)
(then (with bassline beat))
(then (times 2 (with bassline beat jiggle accompaniment)))
(then (times 2 (with bassline beat melody jiggle accompaniment)))
(then (times 2 (with bassline beat melody accompaniment harmony)))
(with bassline plain)
(then (times 2 (with bassline plain beat melody accompaniment harmony)))
(then (drop-last beat))
(where :pitch (comp temperament/equal scale/A scale/mixolydian))
(where :time (bpm 110))
(where :duration (bpm 110))))
(comment
(recording-start "tuesday.wav")
(live/play track)
(recording-stop)
(live/jam (var track))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment