0% found this document useful (0 votes)
145 views7 pages

Making Music With Code

Sonic Pi is a free application that allows users to create music using code. It can be used on Mac, Windows, or Linux computers. The application has a simple interface with controls to play, stop, and record music. It also includes an editor to write the code that generates the music. The code is based on the Ruby programming language. The document provides examples of simple code that can generate drum beats and arpeggios. It also demonstrates how code can be used to randomize samples for more complex, unique sounds. Sonic Pi is designed for both musicians new to coding or coders new to music to experiment and create music projects.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
145 views7 pages

Making Music With Code

Sonic Pi is a free application that allows users to create music using code. It can be used on Mac, Windows, or Linux computers. The application has a simple interface with controls to play, stop, and record music. It also includes an editor to write the code that generates the music. The code is based on the Ruby programming language. The document provides examples of simple code that can generate drum beats and arpeggios. It also demonstrates how code can be used to randomize samples for more complex, unique sounds. Sonic Pi is designed for both musicians new to coding or coders new to music to experiment and create music projects.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Making Music with Code!

An Introduction to
Sonic Pi

Welcome to the world of musical code!


Sonic Pi is a FREE application one can download using Mac, Windows, or Linux.
With it, the user has the ability to create music with code! The nicest thing about
the program is that it is a welcoming starting point to everyone. If you code but
don’t play music, this is a great place to learn, and vice versa!

***This isn’t a tutorial per-say, but to more-so show you how the app works, to get
you excited, and to give examples on the possibilities. The app itself has a strong
and in depth tutorial at length you should follow if you wish to!***

Sonic Pi can also be played with and updated live, allowing one to potentially
change their recordings on the fly by changing their code, or even play a live event
with other musicians as a drum machine or synthesizer.

Getting Started
Navigating the program is simple, and laid out for the user with a great tutorial
guide. While the program can end up being as complicated as you would like it to
be, it really is a typical example of easy to use and hard to master.
Here you can see the lay out of your music creator. Let’s break it down fo ra
second.

A) These are your play controls. They do exactly what they sound like they should!
Play your code, stop it, record it… It is your fundamental control of your music
output.

B) These control your editor. These less so control how you edit, and more-so your
editing experience. Let you change the size of your code editor, show wavelength
feedback, etc.

C) Info and help is exactly what it sounds like. These sections are robust and great
for beginners, of which I found myself constantly referring to.

D) The code editor is where you write your code to create your music. It’s
essentially your instrument! This we will get into more depth on later.

E) The prefs panel sets your preferences, such as if you want your output to be
mono or stereo, and how you want to deal with your volume controls.

F) The log viewer is interesting. It is a live update of all the loops and code being
played, showing you in real time how the music is passing.
G) The help system is what comes up when you ask for it with the help button
(section C). It is extremely… well… helpful and I suggest you use it often!

H) Scope viewer is where you see the visual feedback, such as the wavelengths, in
real time as they are generated.

Lets take a look at some music code


To start, I began using the tutorial that is built into the program and runs as you
start it up. The tutorial is easily laid out and great for beginners as I was. I know a
bit of ruby code and am a musician myself, but knowing neither or being a
beginner at either would not hold me back from learning how to use this tool after
doing the painless tutorial.

Checking out a first simple live loop, lets take a look at the code below:

Writing this into the code editor (D above), it seems to look like ruby code with its
own syntax. Interesting! Here we have a simple live loop where we can have
the sample (in this case a sample synth, called bd_haus) at a rate of 1 (this is
tempo or rhythmic speed of the music) called, followed by a sleep of 1. The sleep
here is the time in-between notes being played. This is a very simple starting point
and no where nears shows the power of Sonic Pi, but it does show a starting point
in how to interact with the program. Below is an example of how the code sounds
once its played:

Here we have a simple repeating beat at the same frequency. We made our first
beat! Cool? Not really. Conceptually, yes, but lets make something more
interesting.

HELPFUL TIP — As I got further into using Sonic Pi, I realized there are more
similarities to its syntax within Ruby than I initially thought! Using a # to comment
out lines works within the program as well, which not only allows you to add
comments within your lines of music, but also allows one to single out a line by
commenting out others and hearing it in isolation!

Lets try and play a chord here:


Wawa wee! Look at that! With this code we were capable of writing three different
notes (each number being a different pitch) at the same time and creating a chord!
It sounds like this:

Real Notes
This is great an all, but what do these arbitrary numbers mean? It may be great as
you begin, or if you don’t have a background in music yourself, but the best way to
really understand how to make notes work together in harmony is to use real note
signifiers. Sonic Pi lets you write out your code simply using “play #” to identify a
pitch, or you can write the actual notes themselves in symbol syntax!

Oooooh! Check it out; we wrote a C, D, E note progression that easily! With a few
sleeps in between (once again, these delay the following note, and the number
signifies the length of delay), we can hear ourselves a nice little three note diddy :)

Making an Arpeggio Interesting


Ok we got three notes, but arpeggios are simple and bland, so we might as well
spice them up with minors, majors, dims, and some timing inbetween. We can do
that simply with the syntax below!

Here we take in two arguments to our play_pattern_timed chord, of which are the
E3 scale at m13, and set at the parameters of 0.25 and 0.5 for timing. This signifies
the scale, whether its minor or major, and the parameters tell you the different
timing in-between the notes. Let’s listen.

Here you can hear the lag between the two with the 0.5 timing, and it having an
“and” beat with the 0.25. After we have made a simple arpeggio and added some
timing to go along with our notes, we can see even with very simple sound
manipulation Sonic Pi has the ability to go far and make very complicated music
that is only limited to your creativity.

Adding Beats
Awww yisssss ELECTRONIC MUSIC working with SYNTHS making BEATS oh
yeahh! What is the first thing on your mind when you hear this? Obviously drum
machines!

This is where Sonic Pi gets really fun and frees up your space to mess with built in
drum machines and beats. As this is just an introduction, we can start simple here
and go into depth in a future article. To start, let’s take a look at a simple drum beat
that Sonic Pi has already available as a sample for you.

Easy syntax. Look familiar ruby users? Its a loop! The loop allows one to do just
that; loop the music to your hearts content. You can choose the looping duration,
but here I simply have a never ending loop, followed by the sample provided in the
program (:loop_amen), and the sample duration being simply that of the length of
the sample.

One can also choose the parameters of the loop, making the loop go a certain
amount of times over again using ruby syntax. To do so, you add “#. times do”
before your loop to signify how many times you would like to to repeat. (i.e.
50.times do).

Lets hear the code played below:

Randomized Beats
Great, we made a drum beat by simply asking Sonic Pi to use one of its samples
(tysm Sonic Pi so nice of you) to get started. But is there a way to make it
a little more our own?
A great way to do this is by randomizing your samples. Take a look at the code
below:

Whoa! This looks a little complicated. Thats ok! This is simply to show you WHAT
Sonic Pi can do, and to be excited about making music with it. Above we can see
that we have our live loop of the beat slicer. This has a slice index of “random
index 8”, where it with slice a certain size of the sample, choose where to start and
finish based on the sample size, and and choose how often to sleep in-between.

This can be a little confusing. Here is a visual representation of the code written
above in wavelength form:

Let’s break down the three wavelengths:

A) The sample drum beat. This is what we used before. This is one iteration of the
drum beat split up into 8 sections.

B) Here we can see the beat split up and assigned values (0–7, as we indicate them
as index numbers, and in ruby, index starts on 0 instead of 1).
C) Now that we have the size and amount of chunks out of the sample that we want
and signified in our code above, we randomize them to different places, durations,
speeds, etc to make our own randomized sample!

This randomizes every the sample restarts, making each loop unique, and gives
the sample an almost jazz like quality to its randomization.

Just the Beginning


This article is meant to get you excited about using Sonic Pi; not a tutorial! The
tutorial is built into the free program and helps a lot for anyone just beginning. But
take a look at the ~possibilities~!! You can find other samples, synths, update your
code live, use a MIDI in and out, mess with live loops, control your output with a
ton of FX, write functions that include threads, conditionals, variables, and so
much more. The tool is extremely powerful and one that would take only the limits
of your creativity to master.

And with a free recording functionality, everything you can make can be saved and
shared with the world!

Sonic Pi is a great example of mixing creativity with code, and makes one excited
to use both sides of their brain. Download the application at https://sonic-
pi.net/ and get started :)

You might also like