EXTRA: Extending NOTE with MIDI note numbers

This time we'll modify the NOTE language instead of the MUS language. Suppose we modified the NOTE language to store MIDI note numbers for pitches. Now a chord in NOTE looks like:

The chord would previously have had c4, e4, and g4 as the pitches but now has 60, 64, and 67. Here is a chart of MIDI note numbers and pitches.

Extend your compile function to output NOTE songs with MIDI note numbers.

You should just need to add one function call in compileT to a new function convertPitch. The convertPitch function takes pitches (like c4) and returns a number (like 60).

To write convertPitch, you need to break apart the pitch letter and the octave. The MIDI number is 12 + 12 * octave + letterPitch. The letterPitch is 0 for C, 2 for D, up to 11 for B.

Prev Next