How to code this song on sonic PI

wheelsOntheBus

How to code this piece of music in sonic pi.
Especially “wheels on the” part?

play :F4
sleep 0.25
play :F4
sleep 0.25
play :F4
sleep 0.25
play :F4
sleep 0.25

Is the above code correct?

It isn’t. You do have the pitch of the notes correct for the “wheels on the bus” - however, the lengths of the notes are not quite correct.

If you have a look at the notation in the screenshot, the symbols change slightly. The first note is just by itself, not connected to others, and has a ‘flag’ hanging off its ‘stem’. The next few are connected together by horizontal ‘beams’, some even connected by double beams.
These are all just ways of indicating the length of the notes, as well as their timing within a bar.
The notation in the screenshot for the “wheels on the bus” notes (the four F notes) shows that they have different lengths:

  • The notes for “wheels” and “bus” both have the same representation - a solid note ‘head’, a single beam connecting them to something - so they have the same length as each other.
  • The double ‘beams’ for “on the” mean that those two notes are each half as long as the notes for “wheels” and “bus”.

This gives us a clue that the Sonic Pi representations of those notes are likely to have different lengths too - or in the case of your example, different sleeps between notes, which is almost the same thing. For your code snippet, the first and last notes need to be twice as long as they currently are (ie, the first and last sleeps need to be twice as long).

From there, to translate rhythm from a musical score to Sonic Pi in general, it’s a matter of understanding what each kind of note written in musical notation means when it comes to the note’s length and timing. There are many resources for this - if you’re interested in learning more about Western music theory, there’s certainly no shortage of material! There has been a little discussion elsewhere in this forum about it:

(One particularly interesting resource mentioned in that thread is a series of musical theory ‘lessons’ laid out in PDF form, which you can download for free. It’s even available in several languages):
https://tobyrush.com/theorypages/

1 Like

is the change you are suggesting right.

That is certainly the right rhythm for the “wheels on the bus” notes :+1: It depends on how fast overall you want the melody to play - if you want it slower or faster, you can either leave the sleeps as-is and adjust the tempo with use_bpm/with_bpm, or leave the tempo as-is and multiply all of the sleeps by a certain value :slightly_smiling_face: (For example, if I were doing it, I’d be multiplying all the sleeps by 2 - there’s technically no ‘right’ or ‘wrong’ way though - if it sounds fine, that’s all that really matters).

Hi @vinodv

Personnaly, i prefer set this values
image

4 >> whole (en français ronde)
2 >> Half (en français blanche)
1 >> quarter (en français noire)
0.5 >> eight (en français croche)
0.25 >> sixteenth (en français double-croche)

wheelsOntheBus

play :c
sleep 0.5

play :F
sleep 0.5
play :F
sleep 0.25
play :F
sleep 0.25
play :F
sleep 0.5

play :a
sleep 0.5

Note that you can omit the 4 after the note name.

Cheers

2 Likes

You can also adjust the sustain to match the sleep length, or make it otherwise related to it.

The sustain option controls how long the note plays. You can find out more about the specifics in the envelope section of the tutorial.

For example:

play :c, sustain: 0.5
sleep 0.5
1 Like

Hi Vindod

I have coded songs like this before for my Grandchildren when they were younger, so I thought I would post some code for the complete song which you can look at. There are many ways it can be done, but I hope you can follow how this works, and I have added quite a lot of comments to help. Do also look up any of the commands in the built in tutorial and language help files which are very useful.
I hope this will also be beneficial to others who may be in the early stages of using Sonic Pi, particularly in coding tunes.

Here is the complete music for tune I used and found on line.

Others in this thread have explained how the length of the notes need to be adjusted. I basically used a list for the note names, and a second list for the durations of the notes where 1 represented a crotchet, with other notes being shorter or longer. It would play very slowly with these values if they were times in seconds, so you use the command use_bpm to adjust how fast you want it to play. I used 180 crotchets (length 1) per minute.

To make it more fun, you will see that the music I used has two parts. If you were playing it on a piano they would be for the tune (the right had) and the accompaniment (left hand). So in fact I had two lists of notes and two corresponding lists for their durations.

To play them together at the same time, there are several ways it can be done. I used two live_loops which give repeating sequences of commands in each loop, but more importantly play at the same time.

The comments in the first loop explain how this works using the tick and loop commands. To make the notes sound for their correct duration but not run completely together I used the syntax for the play command.
play <note name>,sustain: <time at a constant level>,release: <time to die away>
the is taken from the list eg :c4 The overall duration of the note is taken from the Lengths lists. I multiplied this by 0.9 to get the sustain time (90% of the duration) and calculated the :release time by taking 0.1 times this time or 10%. This allows each note to be clearly heard as the previous one dies away.

I hope this explanation is helpful. Once you have the program running, you can have a lot of fun with it. Try using different synths eg :tri or :pulse, or even something wacky like :zawa

You can add some reverb by inserting a line
with_fx :reverb, room: 0.8,mix: 0.7 do
immediately before the first live_loop :whee1
and adding the line
end
just after the second live loop. That’s the nice thing about Sonic Pi. It is easy to experiment.

#The wheels on the bus go round and round
#played by Sonic Pi
#the program can be streamlined, but as presented it
#makes it easier to follow what is going on.

use_bpm 180 #set the tempo to 180 beats (crotchets)/minute

use_synth :piano #try other sysnts to find the one you like
#wheelTune is a list of the notes in the tune.
#You need the 4 and 3 at the end so SP knows which octave to use
wheelTune=[:c4,:f4,:f4,:f4,:f4,:a4,:c5,:a4,:f4,
           :g4,:g4,:g4,:e4,:d4,:c4,
           :c4,:f4,:f4,:f4,:f4,:a4,:c5,:a4,:f4,
           :g4,:c4,:f4]
#wheelLengths is a list of the note durations in the tune
#1 is a crotchet, 0.5 a quaver, 2 a minim,4 a breve
wheelLengths=[1,1,0.5,0.5,1,1,1,1,2,
              1,1,2,1,1,1,
              1,1,0.5,0.5,1,1,1,1,2,
              2,2,4]
#added an accompaniment. Again two lists, one of notes and one of durations
#note the first note is a rest (symbol :r)
wheelAccomp=[:r,:f3,:a3,:c4,:a3,:f3,:a3,:c4,:a3,
             :c3,:e3,:g3,:e3,:c3,:e3,:g3,
             :e3,:f3,:a3,:c4,:a3,:f3,:a3,:c4,:f3,
             :c4,:g3,:e3,:c3,:f3,:c3,:f2]
wheelAccompLengths=[1,1,1,1,1,1,1,1,1,
                    1,1,1,1,1,1,1,
                    1,1,1,1,1,1,1,1,1,
                    1,1,1,1,1,1,2]


#To play the two parts simultaneously there are several solutions
#here I have chosen to play each lift repeatedly in a live_loop
#these will start together and remain in sync until you press stop


live_loop :wheel1 do
  #tick is a counter which increments on each pass of the loop
  #you can use the command look to find the current value of tick
  #the tick commands in each live loop are independent
  tick
  #wheelTune.look chooses the note from the wheelTune list in position look
  #since look increments each time the loop plays the next note is chosen in sequence
  #when it reaches the end it automatically starts at the beginning of the list again
  #the sustain: value is the time for which the note is held before it decays when released
  #I assigned 90% of the time to sustain: and 10% to release:
  play wheelTune.look,sustain: 0.9*wheelLengths.look, release: 0.1*wheelLengths.look
  #the loop sleeps or waits for the duration of the current note before restarting.
  sleep wheelLengths.look
end

#the second live loop plays in parallel to the first. It behaves the same way,
#just using a different list of notes and times
live_loop :wheel2 do
  tick
  play wheelAccomp.look,sustain: 0.9*wheelAccompLengths.look, release: 0.1*wheelAccompLengths.look
  sleep wheelAccompLengths.look
end
1 Like

Thanks for sharing the code.

1 Like