Today I programmed a song with Strudel, a JavaScript DSL for making music. Here’s my first program, attempting to play the introduction to “Zero” by The Smashing Pumpkins.

const ratchet = register('ratchet', (pat) => pat.sometimes(ply(2)))

setcpm(60 / 4);

const lead = "59 58 58 51 51 51 51 59@2 58 58 51 51 51 51 51";

$: note(lead).sound("sawtooth").gain(0.5);

$: note(lead).transpose(-12).sound('sawtooth').gain(0.5);

$: note("~ ~ ~ 82 79 75 ~ ~ ~ ~ ~ 82 79 75 ~ ~")
  .transpose(12)
  .sound('sawtooth')
  .gain(0.5);

$: s("[bd bd] ~ [bd bd] ~, ~ sd ~ sd, oh*4").fast(2).gain(0.6);

$: s("<cr ~>").fast(2).gain(0.6);

A couple of things I learned while writing this:

  • Transpose with transpose
  • ~ are rests
  • Double and single quotes behave differently in this DSL
  • A sawtooth wave sounds like a distorted guitar

Here’s the result! Thanks to Eugene for pointing out the embed feature.

Listen on Strudel