What a great-sounding bit of code! One of the slickest-sounding things I’ve ever heard in Sonic Pi with no external samples! Thanks so much for sharing this.
A couple more ideas for the code:
First, in addition to what @ethancrawford said above, you can shorten the initial delay with a trick from @robin.newman, explained here: start the metronome loop with a very short delay:
parameter, like delay: 0.01
. It’s imperceptible to humans, but it gives the other loops a chance to get their sync
s ready to catch the first metronome cue. (The follow-up discussion with @Martin clarifies the intuition.)
Second, the rythm
variable encodes the rhythm as a list of 1s and 0s. That works well, but as a lapsed music theorist I can’t help noticing that it has a pattern: it steps by 3s until the end, when it has a couple 2s, for a total of 32 beats. This makes it a kind of “Euclidean” rhythm, which Sonic Pi’s supremely handy spread
function can encapsulate as spread(11, 32)
: given 32 time points, trigger 11 “events” as evenly as possible. I like this slightly more synthetic formulation, as it captures the thinking behind the rhythm.
If you’re curious, there’s even an academic article that discusses Deadmau5’s use of this rhythm: A Platonic Model of Funky Rhythms by Richard Cohn.