Skip to content

Instantly share code, notes, and snippets.

@bengl
Created September 27, 2011 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bengl/1244307 to your computer and use it in GitHub Desktop.
Save bengl/1244307 to your computer and use it in GitHub Desktop.
A DSL for making music with CoffeeScript might look like this...
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
@bengl
Copy link
Author

bengl commented Sep 27, 2011

This is just an idea.

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