Skip to content

Commit

Permalink
"Drums please"
Browse files Browse the repository at this point in the history
Make a step sequencer.
  • Loading branch information
mwunsch committed Feb 2, 2016
1 parent d741f1e commit 908817f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/sonic_sketches/core.clj
@@ -1,6 +1,7 @@
(ns sonic-sketches.core
(:use [overtone.live])
(:require [overtone.inst.piano]
[overtone.inst.drum :as drums]
[overtone.inst.synth :refer [tb303]]
[clojure.core.async :as async]
[amazonica.aws.s3 :as s3])
Expand Down Expand Up @@ -45,6 +46,26 @@
{:chord (concat (chord :F3 :major) [(note :F4)]) :duration 3}
])

(defn sequencer
"Accepts a metronome, an instrument, and a vector of 0's or 1's. If
the pulse is 1, the instrument will play. To be used something like:
(let [instruments [drums/kick drums/snare]]
(dotimes [n (count instruments)]
(sequencer (metronome 120) (get instruments n) (repeatedly 8 #(choose [0 1])))))
Or something of that nature."
[nome instrument pulses]
(let [t (now)
beat (nome)
tick (metro-tick nome)]
(if-let [pulse (first pulses)]
(do
(when (pos? pulse)
(at t (instrument)))
(apply-at (+ t tick) #'sequencer [nome instrument (rest pulses)]))
nome)))

(defn play
"Accepts a metronome and a sequence of notes with a :chord
and :duration. Returns a core.async channel that, when read, will
Expand Down

0 comments on commit 908817f

Please sign in to comment.