Exploring the Music Instrument Digital Interface in Scratch

Welcome back to Scratch 101! In addition to uploading sounds, Scratchers can create their own tunes utilizing the Music Instrument Digital Interface (learn more about MIDI).

You will need to load this feature in as an extension in Scratch 3.0. It is built into Scratch 1.4 and 2.0.

Scratch Editor Screenshot highlighting Extension Button

Scratch Extension Page Music Highlighted

Once you load in the music extension, all of the necessary blocks will appear in their own tab. Scratch allows you to set your tune to twenty-one different instruments (ex. block below) or create music with a combination of instruments for temporary notes.

Set Instrument Block
Different instruments for the Scratch MIDI system
Different Instruments for the Scratch MIDI System
Different instruments for the Scratch MIDI system for temporary notes.
You can also include rests and set a tempo. The latter sets how quickly the music flows, a lower number means that the music is slower while a higher number means the music goes faster.

Rest and Tempo Blocks
Blocks for rests and tempo setting.

With these tools you can create music ranging from simple to complex depending on your skill level and how much time you have spent with the MIDI. Here is a simple version of Beethoven's piece Ode to Joy:

Ode to Joy Scratch MIDI
Ode to Joy Scratch MIDI
You probably have two questions when seeing this script:

1.) Why is there Green Flag clicked with an empty forever script?

This essentially helps to ensure that the code runs continuously and that the song does not experience any hiccups when moving from fragment to fragment...

2.) Why are the notes broken up into fragments separated by broadcasting messages?

This is done to minimize the number of errors the MIDI makes when translating the song. It is more difficult for the compiler to play one hundred notes than ten notes. Therefore the logical way to play one hundred notes is to break it up into groups of ten. Of course when this code was created the approximate breakup between the groups was very rough; therefore, each segment has a slightly different number of notes.

Sound Output (watch video):


Of course this is only the surface of creating music with Scratch and those more practiced can produce far more polished pieces.

Here are some examples of more advanced songs (some of them have even been featured on the Scratch homepage!):

Tetris by SAPotter
Hedwig's Theme by SA Potter
Snowdin Town - Undertale by WolfCat67
Flight of the Bumblebee by WolfCat67

Now it is your turn to try and create some music in the Scratch MIDI Editor! Let's see what you come up with! 

Tip: If you are running an especially complex MIDI script, consider switching over the phosphorus player. This javascript compiled version optimizes the Scratch GUI interface and makes it easier to run complex code. Overall when listening to your music (given that it has some complexity) you will hear an enhanced quality and tone. You can also try a newer version called forkphorus specifically for Scratch 3.0...

Phosphorus Interface
Phosphorus Interface Picture.
Conclusion: The goal of this project was to gain familiarity with the Scratch MIDI Interface and inspire creativity through musical exploration.

Completed Project: Share your work with those around you!




No comments:

Post a Comment