Skip to content

Instantly share code, notes, and snippets.

@ctford
Created October 3, 2014 17:56
Show Gist options
  • Save ctford/9821f647ebc933b56b2b to your computer and use it in GitHub Desktop.
Save ctford/9821f647ebc933b56b2b to your computer and use it in GitHub Desktop.
Little triangles
(ns triangles.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]
(-> (square freq)
(+ (sin-osc (/ freq 2)))
(* (env-gen (perc 0.3 0.2) :action FREE))
(rlpf (line:kr 1000 0 0.5))
(* volume)))
(definst wheeze [freq 440 dur 1 clip 0.2 volume 1.0]
(-> (saw freq)
(* (env-gen (adsr 0.02 0.8 0.5) (line:kr 1 0 dur) :action FREE))
(clip2 0.2)
(* volume)))
(definst wall [freq 440 dur 1 volume 1.0]
(-> (sin-osc freq (sin-osc 2))
(+ (sin-osc (* 2 freq (sin-osc 0.01))))
(+ (sin-osc (* 3 freq (sin-osc 0.2))))
(* (env-gen (adsr 0.02 0.8 0.5) (line:kr 1 0 dur) :action FREE))
(clip2 0.2)
(* volume)))
(definst drum [freq 220]
(-> (line:kr freq (* freq 1/2) 0.5)
sin-osc
(+ (sin-osc freq))
(+ (sin-osc (/ freq 2) (sin-osc 1)))
(* (env-gen (perc 0.01 0.1) :action FREE))))
; Arrangement
(defmethod live/play-note :bass [{hertz :pitch}] (bass hertz))
(defmethod live/play-note :wall [{hertz :pitch seconds :duration}] (wall hertz seconds))
(defmethod live/play-note :beat [{hertz :pitch}] (drum hertz))
(defmethod live/play-note :melody [{hertz :pitch seconds :duration}] (wheeze hertz seconds))
(defmethod live/play-note :chunk [{hertz :pitch seconds :duration}] (wheeze hertz (/ seconds 4) 0.9))
; Composition
(def bassline
(->> (phrase [3/2 3/2 3/2 3/2 2/2] [0 4 3.5 3 2])
(where :pitch (comp scale/lower scale/lower))
(where :part (is :bass))
(times 4)))
(def half-bass
(->>
(take 10 bassline)
(with (phrase [7] [0]))
(where :part (is :melody))
(times 2)))
(def chords
(->>
(phrase (repeat 1/2) (cycle [0 2 4]))
(take (* 2 21))
(then (phrase [2] [0]))
(where :part (is :melody))))
(def positive (-> chord/triad (update-in [:iii] (partial + 1/2))))
(def balance (-> chord/triad (chord/root 2) (chord/inversion 2)))
(def lunge
(->>
(phrase [1 5 1 1 5 1 1 5 1 5 1]
[nil nil positive
positive nil balance
positive nil balance
positive nil balance])
(filter :pitch)
(where :part (is :chunk))))
(def melody
(->>
(phrase (repeat 1) [nil [0 -3] [0 -3] [2 -3] [2 -3] [-1 -3] [-1 -3]])
(filter :pitch)
(times 4)
(where :pitch scale/raise)
(where :part (is :melody))))
(def high
(->>
melody
(take-last 24)
(where :pitch scale/raise)))
(def beat
(->>
(phrase (cycle [1 1 2/3 1/3 1/3 1/3 1/3]) (cycle (range -7 -14 -1)))
(take-while #(-> % :time (< 7)))
(times 3)
(then (phrase (repeat 1) (repeat 7 [-7 -14])))
(where :part (is :beat))))
(def whelp
(->>
(phrase [(* 7 4)] [chord/seventh])
(where :part (is :wall))))
; Track
(def track
(->>
bassline
(then (with bassline beat))
(then (times 2 (with bassline beat melody)))
(then (times 2 (with bassline beat chords)))
(then half-bass)
(then (times 2 (with bassline lunge beat)))
(then (times 2 (with bassline beat chords)))
(then (times 2 half-bass))
(then (with bassline beat melody))
(then (with whelp bassline))
(then (times 2 (with bassline beat melody high)))
(where :pitch (comp temperament/equal scale/E scale/flat scale/minor))
(where :time (bpm 180))
(where :duration (bpm 180))))
(defn -main []
(live/play track))
(comment
; Loop the track, allowing live editing.
(recording-start "little-triangles.wav")
(live/jam (var track))
(recording-stop)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment