Skip to content

Instantly share code, notes, and snippets.

@urbanautomaton
Last active August 29, 2015 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save urbanautomaton/11ce2acb775d1bc24898 to your computer and use it in GitHub Desktop.
Save urbanautomaton/11ce2acb775d1bc24898 to your computer and use it in GitHub Desktop.
Overtone code to play the amen break
(ns amen.core
(:require [overtone.live :refer :all]))
(def snare (freesound 26903))
(def crash (freesound 26884))
(def ride (freesound 26889))
(def kick (freesound 26888))
(def amen-tabs
[{:sound crash, :tab "----------------|----------------|----------------|----------x-----"}
{:sound ride, :tab "x-x-x-x-x-x-x-x-|x-x-x-x-x-x-x-x-|x-x-x-x-x-x-x-x-|x-x-x-x-x---x-x-"}
{:sound snare, :tab "----x--x-x--x--x|----x--x-x--x--x|----x--x-x----x-|-x--x--x-x----x-"}
{:sound kick, :tab "x-x-------xx----|x-x-------xx----|x-x-------x-----|--xx------x-----"}])
(def amen-nome (metronome 136))
(def one-twenty (metronome 120))
(defn tab-to-offsets
"Converts <tab> to a sequence of numerical beat offsets. <tab> should be a
string of semiquaver tablature, with '-' denoting a rest, 'x' denoting a hit,
and '|' delimiting bars."
([tab] (tab-to-offsets 0 tab))
([pos tab]
(when (seq tab)
(case (first tab)
\x (cons pos (tab-to-offsets (+ pos 1/4) (rest tab)))
\- (recur (+ pos 1/4) (rest tab))
(recur pos (rest tab))))))
(defn play-tab
"Plays a given <tab> on a beat specified by <nome>, starting at the specified
<beat>."
[nome beat tab]
(let [offsets (tab-to-offsets (:tab tab))]
(map #(at (nome (+ beat %)) ((:sound tab))) offsets)))
(defn play-tabs [nome tabs]
(let [beat (inc (nome))]
(map (partial play-tab nome beat) tabs)))
(play-tabs amen-nome amen-tabs)
@venantius
Copy link

You are my hero for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment