With straightforward code elements involved, almost anyone can create their own music without touching an instrument.

First, grab the completed code from theRaspberry Pi GitHubrepository.

Next, let’s install Sonic Pi.

conductor guiding orchestra

Open your downloads folder or wherever you saved the DEB file.

Right-punch the file and chooseSoftware Installer.

From there, you should be prompted to install Sonic Pi.

sonic pi installer

Some basic music knowledge will come in handy.

Yet, if you’re not too familiar with music theory that’s okay too.

For example, “On the first day of Christmas, my true love sent to me.”

creating music using sonic pi

This introduction repeats using the same notes.

We’re not worried about song lyrics here.

We’re only concerned with the melody.

creating a music loop with sonic pi

There are a few other song sections that repeat.

Same idea goes for the section “(And) a partridge in a pear tree.”

In music, there are 8 octaves.

Sonic looks for a note letter and an octave number.

This will tell Sonic the note and tone to play.

With respect to duration, this will define how long the tone will play (or ring) for.

The functions on the third row of the code tells Sonic what to do with the notes and durations.

You’ll add a bpm function which is known as beats per minute.

How many times are you snapping your finger in a minute?

That’s the same thing as what bpm is.

For this melody, that’s why you’ll notice that bpm is set to 120.

From there, all the definitions can be put into each respective section.

To move through this Christmas tune, you’ll want to loop through the 12 days.

That’s the nuts and bolts of creating music programmatically.

With a good foundation under your belt, why notbuild some musical instruments using your Raspberry Pi?

May we suggest naming your band “The Four Cores?”

Maybe you’ll soon be hired as the next Raspberry Pi DJ?

All the best, Maestro!

May your keyboard and creative mind become one as you set out to program your next one hit wonder!