dark mode light mode Search Menu
Search

Strudel a Tune

Michela Simoncini on Flickr

If the idea of making music with code sounds fun, or if you’ve tried Sonic Pi and wished you could do something like it on a school Chromebook, then the new algorithmic music system, Strudel, might be your thing.

Strudel is a close cousin of the live-coding system, TidalCycles, which is my personal favorite of all the algorithmic music systems out there and something I’ve used myself for performances. But what does it mean to use code to make music?

Traditional music production on a computer is done manually, placing the sounds—whether pre-recorded sound clips called samples or on-the-spot-generated-with-code sounds called synths—at different points in time. It’s more like composing music on sheet paper than playing an instrument, a creative act of writing that’s generally too slow to be done in front of an audience.

But what if we could write code that created patterns, and those patterns in turn created loops that triggered the sounds—synths and samples—at different points in time? If the library or language for this was easy to type and sufficiently expressive, you could potentially do this fast enough to interactively create music in front of a live audience. This is what we call “live coding”.

Strudel is built around the idea of a “cycle”, which by default is a little under two seconds, and, when you write a pattern, it will space all the sounds in the pattern equally over a cycle. If you open up Strudel and clear out all the code from one of the built-in examples,—or listen to it for a while and try changing numbers in it—you can then type and either hit ctrl-enter or the play button to hear a bass drum hit of four equally spaced beats across a cycle. If you make that number bigger or smaller, then there will be more beats in a cycle played faster, or fewer beats in a cycle played slower.

There’s actually a bunch of different samples, or rather families of samples you can use here if you just click on the samples tab in the window. If you look at the number that appears after the
sample family name, this indicates how many samples are within the family. You can access these samples with the .n() method like this:

s("sd*2 sd").n("<2 0 1 3>")

Now we’ve actually added a few pieces here. First, you could try watching the highlighting on the screen as you run this and see if you can guess what the syntax does and then come back and read the explanation.

So what this example does is:

  • play two snare drum hits in the first half of the cycle
  • play one snare drum hit in the second half of the cycle
  • loop between the second, zeroth, first, and third snare drum samples across four cycles

That’s actually a lot of density for what only takes a few seconds to type out. This is also just JavaScript code, so if you’re already familiar with JavaScript you can still use functions and variables like you’re used to. Here’s an example that combines a bunch of things together.

let melody = "<-2 1 ~ 0 3>"
           .scale('C minor')
           .echoWith(4,1/8,(e,n) => e.scaleTranspose(2*n))

note(melody).s("piano").cutoff(1000)

You can read this and guess what it does: we create a melody and put it in a variable, where the melody plays four notes for each note in the initial pattern, each 1/8th of a cycle apart and shifted up. We then play the melody with the built-in piano samples and apply a low-pass filter that cuts out the higher pitches of the sound and makes the piano sound more lo-fi.

Now, if you have no music experience and don’t really understand the music parts of all of this, that’s okay. I didn’t really know any music theory either until I started doing live coding a few years ago. It’s how I learned about music.

So with that, I encourage you to try Strudel, read through the really excellent tutorials on the Strudel site, and, if you’re either a musician who wants to do more coding or a programmer who wants to be a musician, you’ll find yourself at home in live-coding

Learn More