Learning Goals 3 min
By the end of this lesson you will be able to:
- Plan an 8-bar phrase in 4/4 time (8 bars × 4 beats = 32 beats) using the C-major scale.
- Layer play note () melody with a play drum () kick-snare pattern on a second sprite, both running from one flag click.
- Refactor a long melody stack into a custom play melody My Block, and call it twice for repeats.
Warm-Up — count a song in your head 7 min
Most songs are built from bars. A bar is a fixed-size container for beats. In 4/4 time — the most common shape in pop, K-pop, and Malaysian standards — each bar holds 4 beats. So an 8-bar phrase is 8 × 4 = 32 beats.
Predict — at 120 BPM (a brisk pop tempo), how long does an 8-bar phrase last in real seconds?
Reveal the maths
120 BPM means 120 beats per minute, so 2 beats per second. 32 beats ÷ 2 beats-per-second = 16 seconds. That's the length of a typical pop song intro — your theme song will be exactly one of those.
Reveal: why 8 bars?
Eight bars is the size most listeners hear as "one chunk of music". Four bars feels short. Sixteen bars feels long. Eight bars is the natural unit songwriters use for verses, choruses, and intros across pop, hip-hop, traditional asli, and game theme songs alike. It's why we picked 8 for this lesson.
Today is the payoff for everything you learned in lessons 12, 13, and 14. You'll combine the Music extension, drum-and-note blocks, tempo, and rests to compose your own 8-bar theme — and then learn the cleanest trick in Scratch for reusing long stacks: a My Block.
New Concept — composing in bars, refactoring with My Blocks 15 min
So far your music scripts have grown linearly — one note, one note, one note, fifty notes deep. That works for short things. For a theme song, two ideas help: thinking in bars as you plan, and using My Blocks as you build.
The C-major scale, one octave
You already know these from L04-13. Here's the cheat sheet to keep open while composing:
play note (60) for (0.5) beats
play note (62) for (0.5) beats
play note (64) for (0.5) beats
play note (65) for (0.5) beats
play note (67) for (0.5) beats
play note (69) for (0.5) beats
play note (71) for (0.5) beats
play note (72) for (0.5) beats
Planning in bars
Before touching Scratch, sketch on paper. Draw 8 boxes in a row. Each box is one bar. Inside each box, draw 4 small ticks — one per beat. Then write notes above the ticks. Here's a planning sketch for the first 4 bars of a simple theme:
- Bar 1: C (1 beat) · E (1 beat) · G (2 beats)
- Bar 2: G (1 beat) · E (1 beat) · C (2 beats)
- Bar 3: D (1 beat) · F (1 beat) · A (2 beats)
- Bar 4: G (4 beats — hold!)
That's 16 beats so far — half of an 8-bar phrase. The fourth bar is one long held note, which is a classic "the line is ending" signal.
Two sprites — melody and drums
To play melody and drums at the same time, put each on its own sprite and start both with the same flag-click. Scratch runs every sprite's hat in parallel.
when flag clicked
set tempo to (120)
play note (60) for (1) beats
play note (64) for (1) beats
play note (67) for (2) beats
when flag clicked
repeat (4)
play drum (2 v) for (0.5) beats
play drum (1 v) for (0.5) beats
end
Click the flag — both scripts start together. The melody plays its notes; the drum sprite lays down the beat underneath. As long as both stacks add up to the same number of beats, they'll stay in sync.
My Blocks — give your stack a name
An 8-bar melody is roughly 16–24 note blocks. If you want to play it twice (intro + outro), you'd double that to 40 blocks. Painful. The fix is a My Block — a custom block you define, then call by name.
This is exactly the same idea as a list from Level 3: instead of storing data values in a named container, you store actions in a named block. Same "name a thing so you can reuse it" principle, different kind of container.
To define one:
- Click the magenta-pink My Blocks palette.
- Click Make a Block. Type the name:
play melody. - Click OK. Scratch drops a hat block define play melody in your script area.
- Move every note block of your melody under that hat.
Now your event script becomes tiny:
when flag clicked
set tempo to (120)
play melody
rest for (1) beats
play melody
Worked Example — the kuih-stall theme song 12 min
We'll compose a simple, catchy 8-bar theme for a busy kuih stall at a Ramadan bazaar — cheerful, in C major, and layered with a kick-snare percussion track. Eight steps.
Step 1 — Start fresh with two sprites
New project. Default cat is Sprite 1 — rename it "Melody". Click Choose a Sprite → pick any (a drum or a tambourine if you can find one). Rename it "Drums". Add the Music extension.
Step 2 — On Melody, set tempo
From Events: when ⚑ clicked. From Music: set tempo to (120). (Only one sprite needs to do this; tempo is project-wide.)
Step 3 — Make a My Block on Melody
My Blocks → Make a Block → name it play melody. Click OK. The define play melody hat appears.
Step 4 — Build the 8 bars under the define hat
Plan bars 1-4 as the warm-up sketch (C-E-G-hold, G-E-C-hold, D-F-A-hold, G-held-4). Bars 5-8 echo bars 1-4 but climb one note higher to give a sense of rising. Each bar must total exactly 4 beats. Small rests between notes for clarity.
Step 5 — Call play melody from the flag script
Back on the green flag stack (under the set tempo to (120)), drag the play melody call block from My Blocks. The whole melody now lives in one named block.
Step 6 — On Drums, build the kick-snare loop
From Events on the Drums sprite: when ⚑ clicked. From Control: repeat (16). (16 reps × 2 beats per rep = 32 beats = 8 bars — matches the melody.) Inside the repeat: kick + snare, each 1 beat long.
Step 7 — Click the flag
The melody plays on the Melody sprite; the drums lay down kick-snare under it on the Drums sprite. Both finish together at the 16-second mark.
Step 8 — Repeat it
Add a second play melody call (and bump the drum repeat to 32) so the whole theme plays through twice — like a kuih stall jingle that loops for the whole Ramadan bazaar evening.
The full assembled stacks
Melody sprite — event stack:
when flag clicked
set tempo to (120)
play melody
rest for (1) beats
play melody
Melody sprite — define stack (the actual tune):
define play melody
play note (60) for (1) beats
play note (64) for (1) beats
play note (67) for (2) beats
play note (67) for (1) beats
play note (64) for (1) beats
play note (60) for (2) beats
play note (62) for (1) beats
play note (65) for (1) beats
play note (69) for (2) beats
play note (67) for (4) beats
play note (62) for (1) beats
play note (65) for (1) beats
play note (69) for (2) beats
play note (69) for (1) beats
play note (65) for (1) beats
play note (62) for (2) beats
play note (64) for (1) beats
play note (67) for (1) beats
play note (71) for (2) beats
play note (72) for (4) beats
Drums sprite — event stack:
when flag clicked
repeat (32)
play drum (2 v) for (0.5) beats
play drum (1 v) for (0.5) beats
end
What you just built: a real two-track theme song with a reusable melody. The same composition skill — plan in bars, layer sprites, name your stacks — scales from this 8-bar theme to a full 32-bar game soundtrack. The blocks don't change, the count does.
Try It Yourself — three composition drills 15 min
Goal: Compose a 4-bar phrase of your own. Use any notes from the C-major scale (60–72). Each bar must add up to exactly 4 beats. Wrap it in a My Block called my phrase and call it once from the flag.
when flag clicked
set tempo to (110)
my phrase
Think: The point of the My Block isn't the saving on this short tune — it's the habit. From now on, every named melody you make is a reusable musical Lego brick.
Goal: Add a second sprite called "Beat" with a simple drum loop that matches your my phrase. If your phrase is 16 beats total, make the drum sprite do repeat (8) of a 2-beat kick-snare pattern.
when flag clicked
repeat (8)
play drum (2 v) for (1) beats
play drum (1 v) for (1) beats
end
Think: The melody sprite and drum sprite share nothing except the flag-click and the tempo. They are two scripts running in parallel — and that's the whole reason Scratch lets multiple sprites exist.
Goal: Build a verse + chorus structure. Define two My Blocks — verse (4 bars) and chorus (4 bars). The flag script plays verse-chorus-verse-chorus. Add tempo control: verse at 100 BPM, chorus at 120 BPM for energy.
when flag clicked
set tempo to (100)
verse
set tempo to (120)
chorus
set tempo to (100)
verse
set tempo to (120)
chorus
Think: Two named blocks, called four times, with tempo swaps in between. That's the structure of a real pop song expressed in 9 Scratch blocks. The actual notes can be as simple or as complex as you like.
Mini-Challenge — Aishah's drifting drums 5 min
"Why don't the drums match the melody anymore?"
Aishah built a 4-bar (16-beat) melody and a drum loop. First play-through is perfect. After that, the drums drift — they end before the melody. She writes:
when flag clicked
set tempo to (120)
play melody
play melody
play melody
when flag clicked
repeat (8)
play drum (2 v) for (1) beats
play drum (1 v) for (1) beats
end
Click the flag mentally. Why do the drums die after the first melody repeat?
Reveal one valid fix
Count the beats. The drum loop is 8 reps × 2 beats = 16 beats total. The melody is 16 beats × 3 plays = 48 beats total. The drums finish at the end of the first melody play and then sit silent for the next 32 beats. Aishah needs the drum repeat to cover the whole melody.
when flag clicked
repeat (24)
play drum (2 v) for (1) beats
play drum (1 v) for (1) beats
end
24 reps × 2 beats = 48 beats — matches the melody's three plays exactly. When two scripts run in parallel, you keep them in sync by matching total beats, not block counts. The number of blocks can be wildly different on each sprite. The total beats must agree.
Recap 3 min
You composed an original 8-bar theme song using everything from the Music cluster. You planned in bars (4 beats each, 8 bars = 32 beats), used the C-major scale numbers (60-72), layered a melody sprite with a separate drum sprite that runs in parallel from the same flag click, and you wrapped a long melody stack into a reusable play melody My Block. Two scripts on two sprites stay synced as long as their total beats match — block counts can differ wildly, beat counts can't.
- Bar (measure)
- A fixed-size container for beats. In 4/4 time each bar holds exactly 4 beats. An 8-bar phrase is 8 × 4 = 32 beats total.
- Composition
- The process of choosing which notes to play, how long to hold them, and how to arrange them into bars and phrases. Today you composed in C major with the white-key scale.
- My Block
- A custom block you define yourself. The define () hat holds the implementation; the matching call block in My Blocks runs it. Lets a 24-block melody be called by name with 1 block.
- Refactoring
- Rewriting working code into a cleaner shape without changing what it does. Moving a long melody stack into define play melody is refactoring — same music, fewer blocks in the caller.
- Parallel sprites
- Two or more sprites running their own scripts at the same time, both started by the same hat (usually when ⚑ clicked). The basis of layered music in Scratch.
- Beat-count sync
- The rule for keeping parallel scripts together: each script's total beats must match. 32 beats of melody pairs with 32 beats of drums — regardless of how many blocks each one uses.
Homework 2 min
Your Theme Song. Compose an original 8-bar theme for something you care about — your favourite game, your school, your kucing at home, your future YouTube channel.
- Start a new Scratch project. Add the Music extension.
- Plan on paper: 8 boxes, 4 ticks each. Decide your note for every beat. Use only C-major notes (60, 62, 64, 65, 67, 69, 71, 72) for now.
- Build the melody under a define play melody hat. Check that every bar adds up to exactly 4 beats.
- Add a second sprite for drums. Build a kick-snare loop whose total beats match the melody's total beats.
- Pick a tempo that fits the mood — slow for thoughtful, 120+ for energetic, 140+ for chase scenes.
- Bonus: add a third sprite called "Bass" that plays low notes (use 48, 50, 52 — one octave below middle C) on beat 1 of every bar.
Save as HW-L4-15-My-Theme.sb3.
Bring back next class:
- The
.sb3file. - Your paper plan, with the 8 bars and the notes inside each.
- Your answer to: "What is your theme song for, and what tempo did you pick to match that feeling?"
Heads up for next class: SCR-L04-16 is the Music Maker's grand finale — the cat animates to the beat via broadcasts, and you polish and ship the whole project. Get your theme ready to perform!