Member-only story
Music with code: Making a basic drum beat in Sonic Pi

I’m going to walk you through the creation of a basic drum beat using Sonic Pi.
Sonic Pi is a program that lets you make music using code. It’s designed to be simple enough that it doesn’t take long to figure it out. At the same time, it’s powerful enough to make professional music.
I’ve written another tutorial that introduces the basics, but you can still follow along even if you don’t read it. Install Sonic Pi from the link I’ve put above so you can follow along.
After this tutorial, you’ll end up with something that sounds like this.
Kicking things off
We’ll start this drum beat with a bass drum sound. Open up an empty buffer in Sonic Pi and type the following. The buffers are all the pages you can access using the numbered tabs at the bottom of the program.
sample :bd_boom
Hit Run to hear what it sounds like.
The sample
command lets you play a pre-recorded sound, and Sonic Pi comes with about 130 of those. If you bring up the help section by using Alt-i
on Windows or Cmd-i
on Mac, you can click on the “Samples” tab to check them all out.

Now having a bass drum playing once is pretty boring, so let’s put it on repeat.
loop do
sample :bd_boom
sleep 1
end
Once you click Run, that bass drum will loop endlessly until you stop it. You can do that by clicking the stop button in the top left corner. You can also use the keyboard shortcut, on Windows it’s Alt-s
and on Mac it’s…