Display MIDI note names

Challenge Level: Growing experience

Learning outcomes

Students will be able to:

Requirement:

Write a program that asks the user to type in a number between 0 and 127 (60 is middle C) as the input and displays the corresponding MIDI note name as well as playing the note (the midi value mod 12 will be 0 to 11 for C, C#, D, Eb, E, F, F#, G, G#, A, Bb, B - and these can be looked up in a list).

Testing examples:

Your program should display the outputs shown in this table for the given inputs provided;

Input Output
60 C
34 Bb
85 C#
127 G
0 C

Languages

Scratch

What it should look like

Click on the green flag to see the expected output of your program.

Recommended blocks
when green flag clicked

ask [Type in a number between 0 and 127 (60 is middle C) and I display the corresponding MIDI note name as well as playing the note:] and wait

set [note v] to (answer)

play note (note) for (0.5) beats

say (item (((note) mod (12)) + (1)) of [notes v] :: list) for (3) secs

forever
end
Hints
  • Make a list called “notes” and add the 12 notes; C, C#, D, Eb, E, F, F#, G, G#, A, Bb and B to your list (list of length 12).
  • When you apply the mod 12 function to the midi value you'll get a number ranging from 0 to 11, but in Scratch the first item in the list “notes” (which is C) is stored at index 1. To display the correct corresponding note, you'll need to add 1 to the value of the midi value mod 12.

Show Scratch solution

Python