Code Music

March 04, 2018

About five or six years ago, I got on a bus and headed to McMaster University to meet with the creator of the Cybernetic Orchestra. I was setting out to make a short documentary on a collective headed by David Ogborn, a group of people who, to be reductive, were collaboratively creating and producing music with code. I remember getting off the bus, lugging 70lbs. of camera equipment and getting lost in the summer heat as I tried to navigate the McMaster campus. At the time I was working as an undergraduate research assistant filming and editing videos about the social and community impacts of improvised music.

I met with the Orchestra and documented one of their rehearsals and interviewed Dr. Ogborn. Part of the documentary involved going through a live demo of getting my personal laptop setup to be made available as a possible node that could join the Orchestra. We timed it. It took 12 minutes or so before my system was ready to join the others.

I didn’t make any music with the Orchestra that day, though; instead, I filmed their rehearsal and learned about some of the tenets of creating collaborative music with code and non-traditional, DIY, and community-driven tools and instruments.

At the time, I knew what an arduino was. I knew what Max/Msp and Pure Data were, but the topic was intimidating. I had tried to learn to code once or twice. I remember learning about how I could set up my MPD32 to work as a pseudo-launchpad for Ableton Live 8 with python. But I never got much farther than that.

I was inspired when I left that day. Despite that, I had two negative things rattling around in my head:

  • The belief that I could not learn to code.
  • A feeling of disenchantment with how I was making music at the time.

I’ve since “learned to code”. That is, I learned well enough to find work at various startups (while clawing at furthering my understanding in my spare time). I haven’t really made music for fun for over a year.

You can make music with code in a lot of different ways. I thought I’d write up a few notes and survey some of the open source / community tools that are out there to try and get inspired and find some common ground between programming and music making. Let’s take a look at the environment. I’ll be looking at Pure Data, SuperCollider, Overtone, and TidalCycles in this doc.

Pure Data

Pure Data (Pd) is a visual programming language developed by Miller Puckette in the 1990s for creating interactive computer music and multimedia works. While Puckette is the main author of the program, Pd is an open-source project with a large developer base working on new extensions. It is released under a license similar to the BSD license.

Pure Data is a canvas that let’s your visually patch together a series of blocks to create “patches”. It’s massively powerful, and I barely understand it, having only downloaded a few patches to poke around in. Pure Data can generate and affect visuals, as well as sound. It’s also the foundation of a powerful and lovely-looking synth, The Organelle, by Critter and Guitari.

The above video is a complex example of creating generative music with Pure Data.

Not everything about Pure Data has to be complex. I decided to dip my feet in by trying to build a sampler/looper by following this tutorial.

ScreenShot2019 02 07at7 19b017d6 7202 4a4e 9c18 d8cbdd241848 33 26PM 2

Creating a basic sampler with PD.

As I was playing around I thought the least I could do was find a way to augment the patch that I had copied out of the tutorial and make it my own. So, I tried to find a way to add some reverb. I found out that Pure Data comes with plenty of patches, available right in-app in a patch browser, under the Help menu.

After some digging around (and being impressed at the volume of patches and their curious and intriguing names) I found a reverb patch and opened it up.


The original patch is in the top left. Pure Data patches, like code, can contain comments. I followed the instructions to open to see how it works and ended up with the window on the right.

Next, I thought maybe I could do something with pitch shifting. Back to Google. That lead me to a Pure Data forum. The following screenshot is an excerpt of a relevant forum thread. I think it exemplifies a lot of what learning a tool like Pure Data can be like:

screencapture forum pdpatchrepo info topic 3244 pitch shifter object 2019 02 07 19 49 17 01b751c0 b319 4d89 b8a9 3fe3696b498f

I feel very much like the forum poster asking a question in the screenshot above. I want a simple and easy pitch shifter and isn’t there just a Pitch Shift box I can drop in here?

And the answer is, kind of, yes. You can just copy and paste someone else’s work right into your patch. Kind of like code!

There’s an overwhelming amount of potential. If you haven’t done any programming whatsoever, and swimming through forums is new, you might find this kind of community documentation and discussion a little bit intimidating. It takes a certain amount of pushing and determination to get to a point where you just try stuff. (🌀 And sometimes you might even need to write about your process so it forces you to dig deeper 🌀).

I didn’t get it working, yet. I think I would need to watch a few videos (see resources below) on the basics before getting much further.

I feel like Pure Data really excels when you set out with a specific goal/idea of what you want to make, and those things generally might be a bit more “low level”. For example, maybe I’d like to build my own custom looper/sampler that could record and tweak 4 simultaneous loops, as well as launch individual one-shot samplers. Pure Data would probably be a good place to start, even if just to prototype.

Finally, Pure Data has been around for a long time. It was made by the same person who kicked off its commercial sibling Max/Msp. You can interop Pure Data with actual code, some people have integrated it into Open Frameworks recently, you can use it on iOS, and someone even ported it to run in browser.


Super Collider

SuperCollider is an environment and programming language originally released in 1996 by James McCartney for real-time audio synthesis and algorithmic composition.[2][3]

SuperCollider (SC) is a pretty remarkable piece of software:

  • it’s been around since 1996
  • it’s still maintained (wikipedia says the last release was January 2019),
  • SC can be used independently to make music and sound
  • it’s used not just on its own, but often as the foundation (or “server”) for other sound/music making tools. Overtone, SonicPi and Tidal Cycles, all discussed below, use SC as the platform for generating

SC is quite complex. It is actually made up of several moving parts. Consider the following, which I borrowed, from their client vs server documentation. (along with the below figure)

The name “SuperCollider” is in fact used to indicate five different things (Figure 1):

  1. an audio server
  2. an audio programming language
  3. an interpreter for the language, i.e. a program able to interpret it
  4. the interpreter program as a client for the server
  5. the application including the two programs and providing mentioned functionalities

Untitled bc57c317 88de 45d2 8761 95f7498bc035


I cannot lie, I am intimidated by SuperCollider. I must admit it so that I can get on with my investigations and make this sound-machine do its thing. Besides, I had to install SC in order to try out TidalCycles

It’s true that SC is 23 years old, yes it was written in C++, yes the documentation looks a little bit more dated than I am used to. But! I have to get past that in order to learn how this tool works — a tool that is, to be fair, accessible enough that tools like Overtone and SonicPi are built on it.

Screen Shot 2019 04 07 at 3 f33ac8eb c0f4 4477 917d 983b4198fb1d 03 17 PM

SC has a documentation browser built into it’s IDE. I found reading it in-app much easier than on their website, where the text spans the whole width of the browser.

SC has its own syntax that is likened to C in its syntax and Ruby or SmallTalk in its execution (ie, everything is an object and uses message passing). In the above example, you can execute a hello world statement by mousing over the code and keying in shift + enter. Lovely!

Reading through the first few tutorials of the getting started guide in SC provides an overview of objected oriented programming (oop). I must also say, it’s a nice change of pace to see OOP demonstrated and explained through sound generation:

{ [, 0, 0.4),, 0, 0.2)] }.play;

Where .ar is the means to make an instance of the SinOsc class.

I guess that means that {} creates an anonymous function which has the ability to pass the .play message to…another object. I think. I don’t know. It’s been a while since I’ve had to write OOP code.

Screen Shot 2019 04 07 at 3 3f47670f 7313 4f63 bc35 205f42148af1 22 39 PM

You don’t have to just .play sounds. You can .plot them too!

This machine is large. SC uses [Ugens](UGens represent calculations with signals. They are the basic building blocks of synth definitions on the server, and are used to generate or process both audio and control signals. The many subclasses of UGen are the client-side representations of unit generators, and are used to specify their parameters when constructing synth definitions (see SynthDef).) as the basic building blocks of…everything? There are lots of third-party contributions to the ecosystem as well. I think it’s fair to say that SC is a bit intimidating — enough so that people are building API’s for it with more familiar languages. Which brings us to three tools that all use SuperCollider: Overtone, SonicPi and TidalCycles.


The next two tools (Overtone and Sonic Pi) have been largely written by Sam Aaron. He’s quite the prolific programmer (and no doubt Open Source Maintainer). It seems that Overtone came first, starting in 2009, while Sonic Pi started around 2013 (at least, as far as I can discern from Github’s contributor insights).

Overtone is built with Clojure, and is dubbed as an “A Clojure API to the SuperCollider synthesis engine”. The original introduction video is available below:

Clojure is a lisp, which if you are unfamiliar, is a family of languages that has a long and interesting history. Across the corners of the web (or at least, a few choice slack groups, and the occasional hacker news post) you will find lisp advocates who will rally their cry for the REPL (the read-eval-print-loop). Lisps have the ability to hot load (I guess?) and evaluate code (I think?), because, well, the code that makes up a lisp is a data structure. So, like, code is data and data is code. In a year of writing Clojure, I never even wrote a macro, so… it’s still a little ambiguous and strange to me.

But! I have eval’d some code in a REPL before! It’s actually pretty awesome, even when you’re developing web apps with a tool like Clojurescript.

Also, if you are not intimidated by esoteric text editors, then you might find yourself also writing Clojure code in emacs, where you can eval code directly from a visual selection with a few choice, yo-sick-pal-how-did-you-do-that, series of keystrokes

But, in my short time programming, I’ve seen lots of people recoil at lisps. And I’ve also seen a small group of curious and (generally) friendly programmers using it. I don’t think it’s the most touted and popular tool, and with that can come a bit of a learning curve, compared to some of the more popular languages out there.

Sonic Pi

Sonic Pi describes itself as a code-based music creation and performance tool. But on top of that, Sonic Pi is largely education oriented; the site states that:

Sonic Pi was specifically designed for and built in collaboration with teachers for use in the classroom.

As the name indicates, Sonic Pi happily runs along on a Raspberry Pi, part of what makes it so accessible (and education-oriented). The whole platform feels particularly accessible and seems to have quite a bit of momentum and steam built up around it.

Sonic Pi’s syntax is a DSL built with Ruby. You’ll see lots of do blocks and not a lot of parens; quite the opposite of Overtone! For a full overview of the background of Sonic Pi, I’d recommend this video interview with the creator, Sam Aaron. I enjoyed listening to Mr. Aaron talk about introducing ideas of concurrency in programming (to six year olds!) through Sonic Pi. Rad. That’s about 6 minutes into the video.

Installing Sonic Pi is easy. Follow the instructions on the site. I love that on my Mac I’ve got a .app file that I can just open and get started.

[time elapses]

Oh, where did the time go? I got a little distracted. Sonic Pi is really cool. It’s fast, immediate, and super responsive. I think the download size is a bit large because Super Collider seems to be bundled in with it. You can read more about the Sonic Pi internal engines on the Github Wiki.

I also love that this comes bundled with its own editor that gives you everything you need to get started. You can write code, listen to your music, read documentation, load up examples, and even record output straight from the app. On top of all that, the app is built in QT, and not electron 🏎.

Screen Shot 2019 04 22 at 4 e062ebf0 de3e 4f75 907f 8ce186bd6b43 50 08 PM

Sonic Pi seems to have a pretty vibrant community and is also being actively developed. Great place to get your feet wet, I think.

Tidal Cycles

TidalCycles has popped up more recently on my radar. It’s likely that I became aware of it from a subreddit, but I don’t really remember. Tidal Cycles seems to be geared toward live coding, but can also be used for composition; it seems particularly oriented for rhythmic-oriented creations.

TidalCycles’ syntax is built with Haskell and uses SuperCollider (and the plugin SuperDirt). I won’t go over the installation details specifically, other than that to proceed with TidalCycles you’ll need:

  • Haskell and subsequently the Tidal cabal package.
  • SuperCollider and SuperDirt
  • Atom (and an atom plugin). Other editors are supported, though.

Screen Shot 2019 04 05 at 12 d96e3cc4 da7a 4dfc 8ca8 8b61e864378b 43 03 PM

cabal install tidal will take a bit of time.

My first half-hour with TidalCycles left me impressed, excited, and a little overwhelmed (the possibilities for glitched out and humanly-unplayable percussion!). I wasn’t necessarily able to make anything that I would consider useable for a composition, but I was quickly inspired by the power and responsiveness of the system. TidalCycles uses lines of code that are evaluated much like you would in an interactive REPL (such as emacs + CIDER). When your cursor sits over a line of code, pressing shift + enter evaluates the code and generate sound. TidalCycles documentation seems to have undergone some shifts, but generally speaking, the getting started guide is more than enough to inspire some possibilities.

Let’s analyze an evaluate-able chunk of code in TidalCycles:

d1 $ sound "bd bd bd bd"   -- run a four-on-the-floor bass drum pattern
d1 $ sound "bd bd bd bd:3" -- same as above, but play a different sample on the last bass drum.

Now let’s take a look at a more complicated TidalCycle pattern, broken down by section:

Artboard e7ccf70a f997 4059 a5c9 49ed55f98b91

The examples discussed have only mentioned triggering samples; you can run Tidal patterns that send along midi, either triggering internal synth (via the SuperCollider sc3-plugins), or a hardware synthesizer (I think).

d1 $ n "12 7 9 5 4 5 7 4" # s "supersaw" |> pan 0.75 |> gain "0.8"
d2 $ n "0 4 4 5 4 5 7 4" # s "supersquare"
d3 $ every 6 (|+ speed "2") $ n "5 5 5 5 4 5 7 4" # s "supersaw" |> pan 0.25

Above, the lines of code look a bit different before. Gone is the sound keyword; we are no longer working in patterns. Instead, we have n or notes, indicating that we are sending midi notes. The string of numbers that follows is “note numbers” where 0 is middle c.

One of my favourite features that I didn’t demonstrate in the video above is to have “sub-patterns” within a pattern. This fits notes in-between other notes, in a sense, by using [ and ] to indicate patterns within patterns. Here the use of the comma also allows for playing other sounds simultaneously on the same track.

d4 $ sound "[bd:3 [sn hh bd hh hh bd sn] bd, sn:2 bd sn:3 [bd bd hh hh:3]]" # speed "1.7 1.2 2 4" # gain "1.5"

I couldn’t tell you what each of those notes is rhythmically (some are definitely 1/32 and 1/64th notes; but I definitely find that part of the fun. You’ll have to install TidalCycles to figure out what the line of code above sounds like.

Unfortunately, I didn’t come across any docs on how to get the audio generated by TidalCycles recorded. For the video above, I believe I used Piezo, but Soundflower would probably work.


Tone.js doesn’t exactly fall into the same category as some of these other tools, however, I wanted to draw attention to the capabilities of the web-audio api (and web midi). Tools like Tone.js takes the already powerful web-audio api and provides a framework to help abstract some of the more difficult and time-consuming tasks (like building scheduling or full-on instruments and effects).

One of my favourite projects that I’ve stumbled on is BlokDust, a project that uses Tone.js and canvas to enable people to build interactive audio pieces (that are shareable too). Highly recommended.

Screen Shot 2019 04 05 at 11 9a25f854 9ee0 410e b13a 8322d1f07e86 52 37 PM

Wrapping up

There are still more tools I haven’t covered! I haven’t made any music with any of these yet! I should go do that.