-
-
Save venantius/b77946218e4b96ab71a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment