🎼 Musical Notes Introduction | myBetabox

🎼 Musical Notes Introduction

Keyboard Guide

Musical Notes Introduction

Here is a nifty note conversion chart. Experiment with some sounds!

The Code Explained

In this section, we will be learning simple ways to begin creating music. The simplest way to do this is to use what Sonic Pi refers to as “synths.” Generally speaking, synth is short for synthesizer which is a type of electronic instrument used to create music. Sonic Pi has support for many different synths but for now, we will just use the default to get started!

Sonic Pi allows you to start creating music immediately with note. When you hear that note, we refer to them as tones. Let’s give it a shot now!

To hear your sounds, hit run to run the code.

The notes you choose correspond to the notes of an instrument. You can use either a number or the note name.

To play the note numbered 60, type this:

play 60

If you type and run this code, you should then hear a tone played! Now obviously this is just one note. How do we go about changing that? What if we change the number to be higher or lower? What happens? Try replacing your code with something like the following:

play 100

You’ll see that the higher the number, the higher the note. That means the lower the number, the lower the note!

It is generally advised that you stay within the range of 30 – 120. Anything outside of that range may be too high or low to be heard but experiences vary.

You can also use the note name and its octave to play a note. Reference the note conversion chart above to see which octave note correlates with what number. We can see that 60 is the same as C4 (C note in the 4th octave)! To code this with Ruby syntax, make sure to use a colon, like this:

play :C4

Try playing a few notes by writing three lines of code with different notes. Here’s an example:

play 60
play :C4
play 22

I’m sure you probably noticed that all three notes played at the same time. This is because the computer runs so quickly that it executes each line almost simultaneously. This is great if we want to play all of the notes at the same time, like in chords, but what if we don’t? What if we want to create a sequence of notes or a melody.?

The sleep command acts like a rest between notes and allows notes to be heard one after the other.

sleep 1 codes for 1 beat rest
sleep 0.5 codes for a half-beat rest
sleep 2 codes for a 2 beat rest

Using the same notes, the melody can look something like this:

play 60 
sleep 1
play :C4 
sleep 1
play 22

You can even make sharp notes to jazz it up a little! These are notes that are a half-step higher and can be written like this:

play :Fs5 is an F# in the 5th octave