AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Build and judge programs

Week 15 · Unit 6: Sub-routines in programming · 3 lessons
1

Verse and chorus

Computing 6: Unit 6, pp. 78–91
GoalBuild a program from several sub-routines and trace how long it plays.
New words
beat · a steady pulse in music; note lengths are counted in beatstempo · how many beats are played in one minutechorus · the part of a song that comes back again and againverse · a part of a song with new words or notes each time it appears
Explanation

A song is made of parts, and some of the parts come back again and again. Each part can be a sub-routine with a clear name, such as verse and chorus. The main script then calls the parts in the order of the song. If you want another chorus at the end, you add one more call. If you improve the chorus, you change it once, and every chorus in the song changes. In Scratch the Music extension has blocks such as play note for some beats. A note number chooses the pitch, and the number of beats gives the length. The tempo block sets the speed. A tempo of 120 means 120 beats in a minute, so one beat lasts half a second.

versedefineverseplay note60for0.5beatsplay note62for0.5beatsplay note64for1beatschorusdefinechorusplay note67for0.5beatsplay note65for0.5beatsplay note64for0.5beatsplay note62for0.5beatsplay note60for1beatsMain scriptwhenclickedset tempo to120versechorusversechorus
Worked examples
PartNotesBeatsTimes calledNotes playedBeats played
verse30.5 + 0.5 + 1 = 2264
chorus50.5 + 0.5 + 0.5 + 0.5 + 1 = 32106
whole song1610
Count the notes and the beats in each part. The main script plays the verse twice and the chorus twice, so it plays 16 notes and 10 beats. At tempo 120 there are 2 beats every second, so the music lasts 10 ÷ 2 = 5 seconds.
ChangeResult
one more chorus at the end10 + 3 = 13 beats
tempo 120 changed to 24010 beats last 2.5 seconds
order changed to chorus, verse, chorus, versestill 10 beats, but a different tune
The song can be changed without touching the notes. Add one more chorus call at the end and the song has 13 beats. Change the tempo from 120 to 240 and every beat is twice as quick, so the music lasts half as long.
Good names help. ‘verse’ and ‘chorus’ tell the reader what each block does. Names like ‘part1’ and ‘part2’ would make the program hard to read.
Class activity

Rhythm sub-routines (no computer): invent two rhythms and name them. Part A is clap, clap, stamp. Part B is stamp, stamp, clap, clap. Write each part on a card. Now write the order of a song: A, B, A, B, B. Perform the song. Then change part B by adding a finger click at the end and perform the same song again. Did every B change? If you have a computer or tablet, add the Music extension in Scratch and build a verse and a chorus with play note blocks.

Practice
1
The main script calls intro, tune, tune, intro. How many notes are played, how many beats are played and how many seconds does the music last?
introdefineintroplay note64for1beatsplay note67for1beatstunedefinetuneplay note60for0.5beatsplay note62for0.5beatsplay note64for0.5beatsplay note65for0.5beatsMain scriptwhenclickedset tempo to120introtunetuneintro
2
Mia wants the song verse, chorus, verse, verse, chorus. A verse has 4 notes and a chorus has 6 notes. Write the calls and find the number of notes played.
3
A song has 12 beats. How long does it last at tempo 60, at tempo 120 and at tempo 240?
Tempo (beats a minute)Beats each secondTime for 12 beats
60??
120??
240??
4
Why is it better to put the chorus in a sub-routine than to copy its notes into the main script every time it plays?