Created
September 27, 2011 03:58
-
-
Save bengl/1244307 to your computer and use it in GitHub Desktop.
A DSL for making music with CoffeeScript might look like this...
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
bpm 120 | |
# BootsNCatsNBootsNCatsNBootsNCatsNBootsNCatsNBootsNCatsNBootsNCatsN | |
# http://i.imgur.com/sqmHC.jpg | |
drums = new DrumMachine() | |
n = (s) -> | |
drums 'hihat', s | |
boots = (s) -> | |
drums 'bassdrum', n s # the hihat is on every 1/2 beat | |
cats = (s) -> | |
drums 'snare', n s # ditto | |
# 'xbeaty' means "for all beats z such that z % x == y" | |
on '2beat0', (s) -> | |
boots s | |
on '2beat0.5', (s) -> | |
n s | |
on '2beat1', (s) -> | |
cats s | |
on '2beat1.5', (s) -> | |
n s | |
# get some notes handy | |
fs5 = 739.989 | |
a5 = 880.0 | |
b5 = 987.767 | |
cs6 = 1108.731 | |
e6 = 1318.51 | |
fs6 = 1479.978 | |
gs6 = 1661.219 | |
# for melodys, we have an array like [freq,dur,freq,dur,...] | |
melody = [ # "Kids" by MGMT | |
# first 4 bars | |
a5, 0.25 | |
b5, 0.25 | |
cs6, 0.25 | |
e6, 0.25 | |
fs6, 0.25 | |
gs6, 0.125 | |
fs6, 0.25 | |
e6, 0.25 | |
cs6, 1.125 | |
b5, 1 | |
# second 4 bars | |
a5, 0.25 | |
b5, 0.25 | |
cs6, 0.25 | |
b5, 0.25 | |
a5, 0.25 | |
b5, 0.125 | |
a5, 0.25 | |
fs5, 0.25 | |
a5, 1 | |
] | |
osc = Oscillator 'sine' | |
on '32beat0', (s) -> | |
playMelody melody, osc, s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is just an idea.