Type the following into the buffer and press run:
That didn’t sound like a melody, did it? Instead of playing a sequence, Sonic Pi played all the notes at once (and that’s how you can actually write chords).
If you want Sonic Pi to play each note in a sequence, you have to tell the software to take a break every now and then. Try typing in
sleep 1 underneath each note, like this:
sleep 1 tells Sonic Pi to wait for one beat. You can try smaller and bigger numbers. The smaller the sleep value, the shorter the duration is between the play commands and vice versa. If you’re familiar with musical notation, this is what different notes look like in Sonic Pi:
As mentioned before, you can write the notes in MIDI, which is basically numbers between 0 and 127 (
22) or in musical notes (
:Bb), it’s up to you. Here’s a chart displaying notes and corresponding MIDI values:
Use notes from the C-major scale (
72, 74, 76, 77, 79, 81, 83 or
:C5 :D5 :E5 :F5 :G5 :A5 :B5) to create a melody. Use
sleep with different values to vary the rhythm. You can use
use_bpm in the beginning to make your tune faster or slower. The acronym BPM stands for Beats Per Minute. Here’s an example:
Now make your own melody!