Skip to content

Instantly share code, notes, and snippets.

@harold
Created October 15, 2012 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save harold/3890789 to your computer and use it in GitHub Desktop.
Save harold/3890789 to your computer and use it in GitHub Desktop.
16th note sequencer
(def snare (sample (freesound-path 26903)))
(def kick (sample (freesound-path 2086)))
(def ch (sample (freesound-path 802)))
(def oh (sample (freesound-path 26657)))
(def insts {:kick kick
:snare snare
:oh oh
:ch ch})
(def pat {:kick [1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0]
:snare [0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0]
:oh [1 0 0 0 0 0 1 0 0 0 0 0 1 0 1 0]
:ch [0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0]})
(def metro (metronome 135))
(defn play-pat [beat i]
(let [t (mod beat 4)
p (vec (take 4 (drop (* 4 t) (pat i))))]
(if (= 1 (p 0)) (at (metro (+ 0.00 beat)) ((insts i))))
(if (= 1 (p 1)) (at (metro (+ 0.25 beat)) ((insts i))))
(if (= 1 (p 2)) (at (metro (+ 0.50 beat)) ((insts i))))
(if (= 1 (p 3)) (at (metro (+ 0.75 beat)) ((insts i))))))
(defn player [beat]
(doseq [i (keys insts)] (play-pat beat i))
(apply-at (metro (inc beat)) #'player (inc beat) []))
(player (metro))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment