GoalTrace a Scratch music program with a repeat block, a volume change and a repeat until block.
New words
repeat · a block that runs the blocks inside it a fixed number of timesrepeat until · a block that checks a condition at the start of every round and stops when it is truevolume · how loud a sound is, from 0 to 100beat · the unit of time in music: at tempo 60 one beat lasts one second
Explanation
A loop saves blocks. The repeat block runs its blocks a number of times. The repeat until block checks its condition at the start of each round. If the condition is false, it does one more round. If it is true, it stops. So a round that has begun always finishes. Volume goes from 0 to 100. The block set volume sets it, and change volume by adds to it. The volume can never go above 100. When we trace music, we write each note and its volume in a table. At tempo 60, one beat is one second.
Worked examples
Round
Volume of the note
Volume after the change
1
50
75
2
75
100
3
100
100 (125 is too high)
The frog pond tune. The volume is set first. Each round plays one note and then raises the volume by 25. Volume cannot go over 100.
A tune that stops when a key is pressed. The player presses and holds the q key 3 seconds after the start. Each round takes 2 seconds. Round 1 is from 0 s to 2 s. Round 2 starts at 2 s, and the check at 4 s sees the key and stops. The note is played in 2 rounds.
A repeat block can replace many copies. These two scripts play the same music, but the second needs fewer blocks.
Class activity
Body music (with family): a person claps once for each beat while another says the volume of the clap as a number, starting at 40 and adding 20 each time. Stop at 100: the loudest clap can only stay at 100. Then play a game of repeat until: keep clapping a 2-beat pattern, clap and rest, until someone taps the table. The pattern in progress must always be finished first. How many patterns did you clap?
Practice
1
A script uses set volume to 20 and then repeat 4: play a note, change volume by 30. Write the volume of each note.
20, 50, 80 and 100. The fourth note would be 110, but the volume cannot be above 100.
2
How many beats does this script play, and how many seconds does it last at tempo 60?
3 × (1 + 1) = 6 beats, which is 6 seconds.
3
A repeat until block waits for the key m. The key is pressed in the middle of round 3 and held down. How many rounds are played?
3 rounds. The round that has begun is finished, and the check at the start of round 4 finds that the key was pressed.
4
Change the script in question 1 so that it plays 6 notes with the same volume change. What must change? What are the volumes now?
Change the repeat number from 4 to 6. The volumes are 20, 50, 80, 100, 100 and 100: the volume reaches 100 at the fourth note and stays there.