Skip to Main Content
University of York Library
Library Subject Guides

Coding: a Practical Guide

Sonic Pi

Sonic Pi

Want to learn how to live code music?

Sonic Pi is a coding language and code-based tool for music creation and performance that is also a useful way to learn coding concepts whilst making sounds.

What is Sonic Pi?

Sonic Pi is a coding tool and language that allows you to create music. You do this by writing your music as code and then setting it to play either a certain number of times or in a loop.

Not only can you create music quickly and "live code" your music to change when performing, but you can also use Sonic Pi as a way to learn coding in a more creative way rather than focusing on abstract concepts or working with data.

Sonic Pi is based on the coding language Ruby and any code files you save will be saved as Ruby files. However, you can learn Sonic Pi entirely separately from other coding languages and do not need any coding experience to have a go with it.

The Sonic Pi interface has a space for code that will often have live_loop written and then actions like sample or play or sleep. Buttons like run and stop allow you to control the run of the code.
A Sonic Pi screen showing some sample code.

How to get started with Sonic Pi

The first thing you need to do to use Sonic Pi is to download and install it on your device. You can do this from the Sonic Pi website. Sonic Pi is not available on University computers.

If you want to start learning Sonic Pi and the coding language it uses, there's a tutorial on the Sonic Pi website that gets you started with the basics and then goes into more depth. You might also want to read the Sonic Pi guide we created for a previous session on Sonic Pi:

The Sonic Pi website also has a range of example code that varies from simple to more complex. If you're looking to see something at the more complicated end of the scale once you've got used to the basics of Sonic Pi, here's some sample code from a teaching session that recreates a well-known song which you could try pasting into Sonic Pi.


Here are some possible things to try doing in Sonic Pi as you start learning using the tutorial linked on this page:

  • Try combining some notes and sleeps to create a melody.
  • Use a live_loop to repeat some notes and sleeps and then change it as it plays.
  • Use samples and play around with their rate to see what you can make.
  • Try and recreate a simple song you can find the notation for online (e.g. Twinkle Twinkle Little Star, the Nokia theme).