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

Music that repeats

Week 14 · Unit 6: Be a musician · 3 lessons
1

Follow the repeating tune

Computing 4: Unit 6, pp. 74–89
GoalFollow an algorithm that repeats and predict what a music program will play.
New words
forever loop · a loop that repeats its steps until someone clicks the stop buttonrepeat loop · a loop that repeats its steps a set number of timesvolume · how loud a sound is, from 0 (silent) to 100 (loudest)note number · the number that tells Scratch which note to play, such as 60 for C
Explanation

An algorithm for music lists the sounds in order. A forever loop repeats its steps again and again until someone clicks stop. A repeat loop repeats them a set number of times. To predict the music, follow the steps one at a time, as the computer does. Take care with “repeat steps 2 to 4 two more times”. The steps have already played once, so you hear them three times in all. Volume is a number from 0 to 100, and Scratch never goes above 100 or below 0. At the usual tempo, one beat lasts one second.

StepInstruction
1Start program when the b key is pressed
2Play note 72 (high C) for 0.5 beats
3Play note 67 (G) for 0.5 beats
4Rest for 1 beat
5Repeat steps 2 to 4 two more times
6Play the crash cymbal for 1 beat
7Stop program
Worked examples
whenbkey pressedplay note72for0.5beatsplay note67for0.5beatsrest for1beatsrepeat3play drum(4) Crash Cymbalfor1beats
Here is the school-bell algorithm as a Scratch program. The repeat block runs its blocks 3 times in all: the first time and two more times. So you hear 6 notes and then the cymbal. One round lasts 0.5 + 0.5 + 1 = 2 beats, so the whole tune lasts 3 × 2 + 1 = 7 seconds.
when this sprite clickedplay note67for0.5beatsrest for0.5beatsforever
A forever loop never stops by itself. This program plays G for half a beat, then rests half a beat, over and over. One round takes 1 second, so in 10 seconds it plays 10 notes. It only stops when someone clicks the stop button.
The algorithm saysSteps are played
repeat once more2 times in all
repeat two more times3 times in all
repeat three more times4 times in all
repeat (5) block5 times in all
Be careful with the words “more times”. The steps have already been played once.
Class activity

Body music (with family): make an algorithm for a rhythm. 1 Start. 2 Clap. 3 Clap. 4 Stamp your foot. 5 Repeat steps 2 to 4 two more times. 6 Stop. Perform it while somebody reads the steps. How many claps do you make in all? How many stamps? Now change step 5 to “repeat forever” and let your partner say “Stop!” after 15 seconds. How is this different?

Practice
1
Follow the drum algorithm. How many times is the snare drum played? How long does the whole program take?
StepInstruction
1Start program when the green flag is clicked
2Play the bass drum for 1 beat
3Play the snare drum for 0.5 beats
4Play the snare drum for 0.5 beats
5Repeat steps 2 to 4 three more times
6Stop program
2
In the drum algorithm of question 1, step 5 is changed to “Repeat steps 2 to 4 forever”. How many times is the bass drum played in the first 20 seconds? How does the music stop now?
3
Which script stops by itself, and when?
Script Awhenclickedplay note60for0.5beatsforeverScript Bwhenclickedplay note60for0.5beatsrepeat6
4
Predict the music. Does it get louder or quieter? At what volume is the last note played, and what is the volume at the end?
whenspacekey pressedset volume to100%play note60for1beatschange volume by-25repeat4