Making Music
In this lesson, we are going to start programming in Scratch in ernest. Most
of the blocks will be from the Sound palette, as we will be making music.
To begin, start a new project and delete the default sprite that is
automatically added to every new project. You can do this by either selecting
the Scissors tool (in the toolbar), or right-clicking on its image in the Sprite Container
(the panel in the bottom right-hand corner) and selecting delete from the
pop-up menu.
Now, either import or draw the following picture:

This octopus has a number of drumsticks, and this gives me an idea. What if
we made a project full of drums, and clicking each drum would make a
different sound. Sounds fun?
Changing Sprite Names
I would encourage you to keep your project clean and readable, and having a
sprite named Sprite1 doesn't help. You will notice that a sprite's name is
in the Sprite Information area (the
panel in the center below the menu buttons). If you click on the name, it
becomes highlighted in blue. At this point, type in the sprite's new name,
Octopus.

Playing a Drum
Now that the house-keeping is done, let's make some noise. The octopus is
holding a triangle, and that would make a good first instrument. With the
Sound block group selected, drag out the play drum block. 
Plays a particular drum instrument for a given number of beats. The drums are listed by their number, but clicking the arrow reveals their names. Beats can be in parts of a beat by using decimals, e.g. 0.5 for ½


Begins a block stack whenever the sprite is clicked on the stage. You can have multiple instances of this block, and when a sprite is clicked, all attached block stacks are executed.
It has two values, the first is the type of drum to play, and the second is how
long to play it (in beats). Select (81) Open Triangle by clicking on the black
down-arrow icon. Note: Depending on the size of the Scratch window, you may
have to select the more.. item at the end of the list before you will see
the Open Triangle. Clicking more at the end of the list will start the drum
list again.
Once the drum instrument is selected, its number appears in the play drum
block, not the instrument's name. While it saves on screen space, this aspect
can be annoying.
The play drum block
defaults to playing for a fifth of a beat (0.2). Let's have the sound last a
little longer, so change that to ½ beat by clicking and typing, 0.5 in
the second field. Double click on the play drum block in order to hear a
triangle sound.
Note: Changing the beat actually doesn't affect the sound of the drum. It
still plays the full drum sound whether the value for beats is 0 or 100.
We specify a particular value when we play a series of drums and want to play
them with a particular tempo. I'll explain that in detail later in the lesson.
Clicking a Sprite
We want the triangle to chime when the octopus is clicked, and this means that
we will trigger our play drum script using a Hat Block. Under the Control
block group, you will notice a block labeled, when Octopus clicked. Drag
that over and connect it above our play drum block.

Instead of double-clicking on our block stack, click on the octopus on the
stage, and you'll hear the triangle chime. Yes, I'll answer a couple of questions.
Can you have more than one when sprite clicked hat blocks for one sprite?
Yes, you can. What happens when you click on the sprite is that all of the
attached block stacks get executed at the same time.
Well, not exactly at the same time, but essentially at the same time. Let's have
an experiment. Duplicate the stack block and change the drum instrument and try
it out. You'll notice that both drums are played almost at the same time, but
if you pay close attention, you'll notice that one will start slightly ahead of
the other. Oh, and it is arbitrary which will start first. I'll tell you why
at the end of this lesson.

Let me anticipate your other question. Yes, changing the name of the sprite
automatically changes the name of the when sprite clicked block. But you
can see when I begin, why I set the name of a sprite to something meaningful.
You may notice that you can't click the octopus image too quickly, for a
double-click doesn't trigger our block stack twice, but simply selects the
sprite. If you want to wail on that triangle, enter Presentation Mode by clicking
on the Enter Presentation Mode icon.
In this mode, you are only running your project, not developing it, so you can
click on the octopus as fast as you want. Your project is also displayed at
twice the resolution, so it appears much bigger (with the expected resolution
loss). Click the Return Arrow in the top-left corner to go back to developing
your project.
Rotating a Sprite
All we need to do to finish this project is import some drum instruments, however
let me show you some tricks to make that part easier.
First, import a drum. You will notice that Scratch comes with two drum images
in the Things directory folder. After importing it, you can drag it on the
stage to position it correctly. However, it may not have the correct angle. You
can rotate a sprite in the Sprite Information area:

You will notice the reduced version of the sprite's current costume with a
horizontal blue line. This line is a handle that shows the sprite's rotation
value and can be used to change that value. Change it by clicking and dragging
it around. You will notice that the sprite on the stage will rotate around its
center.

Duplicating Scripts to Another Sprite
The script that the octopus and the drum use are very similar, so let's copy
the octopus' script to the drum.
To do this, click on our Octopus sprite in the Sprite Container panel and
view its script. Now click on the Stamp Tool (or Duplicate Tool) in the toolbar
and drag the script down to the drum sprite in the Sprite Container panel. Don't
let go of the mouse button until the drum sprite is outlined (see below):

After making a copy of the script for the drum sprite, the tool reverts back
automatically to the Select Tool (the Arrow), which allows you to click on
the drum sprite in the Sprite Container to see the results.
Note that the when Octopus clicked block has automatically changed to
when Snare clicked (or whatever you named your drum sprite). However, the
drum instrument is still the same. Change this to a snare drum or another drum
instrument.
Feel free to take a minute to make your own drum set. I've provided some
additional drum instruments on my web site to help you get started. Hrm, I
really should make a vibraslap††Because a cuica looks just like a drum from the outside.
Rhythm Involves Resting
After making and playing with your new drum set, you may realize something:
you have no rhythm. Actually, you may have rhythm, but it is hard to keep a
good beat going with a mouse, so let's have Scratch keep the beat and allow
us to riff on top.
With this, let's associate the rhythm with the stage. That's right, the stage
can have scripts as well as sprites. Click on the stage and make sure its
Scripts tab is selected.
Remember what I said earlier about the amount of a beat for a drum? Now is the
time to put that into practice. We can use the play drum and the rest for blocks 
This block does nothing for a given number of beats. The amount of time this actually takes depends on the tempo set for this sprite. Only useful with the play drum and play note blocks.
in order to make a drum lick. Try this standard:

Repeating a Stack
The first thing we need to fix is make our rhythm repeat, for it does no good to
have a lick play once. Let's use the forever crocodile block (we call it that
because the block looks like a reptilian orifice– er, crocodile's mouth). 
Repeatedly runs whatever blocks are inside until the Stop sign is clicked or the stop all scripts block is executed.
Note that when you drag the forever block from the Control group panel
and position it near the start of our stack, the mouth enlarges to encompass
the rest of the stack, for that shows you just what will get inserted into its
gaping maw.
Your stack should look something like this:

Double click our stack and the beats goes on and on and on. Click the
stop sign icon at the top right to give yourself a rest, for that icon stops
all scripts running in all sprites (and the stage too).
Setting the Tempo
I used a ½ beat (0.5) because it is easy to add all the beats to make a measure. However, it
sure is slow. Doesn't sound at all like it does when I get on a drum set.
We can set the tempo using the set tempo to block, 
Specifies the speed, or number of beats per minute, the drums and the notes will be played. 60 bpm means each beat lasts 1 second.
Makes a drum sequence or melody speed up with a positive number or slow down with a negative number.

Starts running the stack attached to it when the green Start Flag icon, or when the project is initially started on the web site. You can have many instances of this block, and all stack blocks would be executed.
and attach it to the beginning of our drum lick stack.

You can play around with various values, but I find that 180 bpm (beats per minute)
sounds right.
Starting Scripts Automatically
Double-clicking a stack is fine when your developing your project, but we
should start our background rhythm automatically. We use the green
Start flag icon (top right corner) for officially starting our project. In the
Control group, drag the first block to the top of our stack:

Clicking on the Start Flag icon begins our rhythm allowing us to click the
other sprites in our drum set.
Multiple Instruments
I think our drum lick should be riding the hi-hat– I mean, we should have
a high-hat hit at the start of each beat. However, we are already hitting a
drum at that same time.
To get around this problem, we will have two drum stacks: one for the snare
and bass drum and another for the hi-hat. Each will get kicked off with the
Start Flag icon:

If you play our project long enough, you'll notice something disconcerting:
the hi-hat can get out of sync with the drums. Why? Well, I'll discuss this
in the Software Engineering Concepts near the end of the
lesson.
Make Some Music
Let's leave the drums and work on making a melody. Save and start a new project,
and once again, delete the default sprite as we will be doing all our work on
the stage.
For this project, we are going to make a tune, and then use the melody we make
to create a musical round where the same tune is repeated by a second voice
slightly later. So let's use everybody's favorite round, Row, Row, Row your Boat.
Begin by dragging out the play note block: 
Plays a note for a given beat duration. The instrument used can be set beforehand with the set instrument block.
By default, it plays 'middle C' (#60), and for Row, row, the first note is an 'E'.
Click on the black down-arrow to reveal a keyboard that allows you to pick the
correct note:

Once you select the correct note, the block displays the note number (in this
case, it is 65). Until you get used to what notes match with numbers, debugging
a tune is a little difficult, so play the tune regularly.

Setting the Musical Instrument
Now that we have the basic melody, let's play around with it the way we did at
camp when we were kids: we turn it into a round. First, let's repeat our melody
three times, up the tempo to 320 bpm and start the music with the Start Flag
icon. Oh, and let's change the instrument we use to play the melody using the
set instrument to block. 
Sets the instrument used for the play note block. There is one musical instrument setting per sprite, so if you want to have more than one instrument playing, they need to come from different sprites.
Clicking the black down-arrow on the set instrument to block shows a list
of musical instruments we can use to play our melody:

Each sprite (and the stage as well) can have a single musical instrument
setting, so we typically set this once before the tune plays.
The top part of your stack should now include all the preliminary setup code
and look like:

In the interest of saving space, I'm only showing you the top and the bottom
of the code, as all the notes are the same as above.
Building the Round
A musical round requires multiple voices, but each voice comes in slightly
later– in our case, 12 beats later. So use the Stamp/Duplicate Tool and
make a copy of our current stack, but replace things like the tempo and
instument with a rest of 12 beats.
If you really want to annoy yourself, duplicate that stack, but change the rest
to 24 beats. And you wonder why we only did this round once at camp before
the councilors would send us to bed.

Setting the Volume
Most applications, like most rock bands, play as loud as they can, and let the
user adjust the volume on their speaker system. However, let's be kind to the
people next to us and set the volume a bit softer with the set volume to
block. 
Sets the volume of the drums and musical notes this sprite is producing. A value of 0 or less will make the sprite silent.

Alters the current volume from its current setting. Negative values make the volume softer and positive number make the volume louder. If the new volume ends up less than 0, the music will be silent. Values over 100 become 100.
An interesting idea may be to change the volume softer with each
round. In fact, we can make the music softer and faster as the song progresses–
which may just save our sanity. Just remember to include a set volume to
block at the beginning, otherwise the next time you play your music, you may
not hear anything at all.

You can finish by drawing a nice picture of a rowboat going off a water fall or
even moving the round sections to different sprites with different musical
instruments.
| (1) | Acoustic Grand Piano |
(44) | Contrabass |
(87) | Lead 7 (fifths) |
| (2) | Bright Acoustic Piano |
(45) | Tremolo Strings |
(88) | Lead 8 (bass+lead) |
| (3) | Electric Grand Piano |
(46) | Pizzicato Strings |
(89) | Pad 1 (new age) |
| (4) | Honky-Tonk Piano |
(47) | Orchestral Strings |
(90) | Pad 2 (warm) |
| (5) | Electric Piano 1 |
(48) | Timpani |
(91) | Pad 3 (polysynth) |
| (6) | Electric Piano 2 |
(49) | String Ensemble 1 |
(92) | Pad 4 (choir) |
| (7) | Harpsichord |
(50) | String Ensemble 2 |
(93) | Pad 5 (bowed) |
| (8) | Clavinet |
(51) | Synthesized Strings 1 |
(94) | Pad 6 (metallic) |
| (9) | Celesta |
(52) | Synthesized Strings 2 |
(95) | Pad 7 (halo) |
| (10) | Glockenspiel |
(53) | Choir Aahs |
(96) | Pad 8 (sweep) |
| (11) | Music Box |
(54) | Voice Oohs |
(97) | FX 1 (rain) |
| (12) | Vibraphone |
(55) | Synthesized Voice |
(98) | FX 2 (soundtrack) |
| (13) | Marimba |
(56) | Orchestra Hit |
(99) | FX 3 (crystal) |
| (14) | Xylophone |
(57) | Trumpet |
(100) | FX 4 (atmosphere) |
| (15) | Tubular Bells |
(58) | Trombone |
(101) | FX 5 (brightness) |
| (16) | Culcimer |
(59) | Tuba |
(102) | FX 6 (goblins) |
| (17) | Drawbar Organ |
(60) | Muted Trumpet |
(103) | FX 7 (echoes) |
| (18) | Percussive Organ |
(61) | French Horn |
(104) | FX 8 (sci-fi) |
| (19) | Rock Organ |
(62) | Brass Section |
(105) | Sitar |
| (20) | Church Organ |
(63) | Synthesized Brass 1 |
(106) | Banjo |
| (21) | Reed Organ |
(64) | Synthesized Brass 2 |
(107) | Shamisen |
| (22) | Accordion |
(65) | Soprano Sax |
(108) | Koto |
| (23) | Harmonica |
(66) | Alto Sax |
(109) | Kalimba |
| (24) | Tango Accordion |
(67) | Tenor Sax |
(110) | Bagpipe |
| (25) | Nylon String Guitar |
(68) | Baritone Sax |
(111) | Fiddle |
| (26) | Steel String Guitar |
(69) | Oboe |
(112) | Shanai |
| (27) | Electric Jazz Guitar |
(70) | English Horn |
(113) | Tinkle Bell |
| (28) | Electric Clean Guitar |
(71) | Bassoon |
(114) | Agogo |
| (29) | Electric Muted Guitar |
(72) | Clarinet |
(115) | Steel Drums |
| (30) | Overdriven Guitar |
(73) | Piccolo |
(116) | Woodblock |
| (31) | Distortion Guitar |
(74) | Flute |
(117) | Taiko Drum |
| (32) | Guitar Harmonics |
(75) | Recorder |
(118) | Melodic Drum |
| (33) | Acoustic Bass |
(76) | Pan Flute |
(119) | Synth Drum |
| (34) | Electric Bass (finger) |
(77) | Blown Bottle |
(120) | Reverse Cymbal |
| (35) | Electric Bass (pick) |
(78) | Shakuhachi |
(121) | Guitar Fret Noise |
| (36) | Fretless Bass |
(79) | Whistle |
(122) | Breath Noise |
| (37) | Slap Bass 1 |
(80) | Ocarina |
(123) | Seashore |
| (38) | Slap Bass 2 |
(81) | Lead 1 (square) |
(124) | Bird Tweet |
| (39) | Synth Bass 1 |
(82) | Lead 2 (sawtooth) |
(125) | Telephone Ring |
| (40) | Synth Bass 2 |
(83) | Lead 3 (calliope) |
(126) | Helicopter |
| (41) | Violin |
(84) | Lead 4 (chiff) |
(127) | Applause |
| (42) | Viola |
(85) | Lead 5 (charang) |
(128) | Gunshot |
| (43) | Cello |
(86) | Lead 6 (voice) |
|---|
Summary
In this lesson, we covered the basics of making music in Scratch, and showed
that simple melodies are best and that harmonies are beyond Scratch's ability.
However, this is sufficient for most students, who only think about the melody
anyway.
We used drum beats to also discuss repeating blocks and starting and stopping
block stacks: the basics of computer programming.
In the next lesson, we will learn various techniques for getting a sprite to
move around on stage and the basics of computer animation.
Tell others about this article: