Let’s celebrate Zelda’s 30th anniversary by generating a MIDI file of the game’s main theme.
To generate MIDI files, we are going to use the MidiWriterJS.
Here is how to get started with the library:
A MIDI file is a collection of tracks which are collections of notes.
pitch represents the notes you want to add.
Examples would be:
The letter is the note, you can alter it with
# and the letter corresponds to the octave (I would say that 4 corresponds to your treble clef pitch)
duration represents the duration of each note
|duration||American Name||English Name|
|d2||dotted half||dotted minim|
|d4||dotted quarter||dotted crotchet|
|d8||dotted eighth||dotted quaver|
velocity represents the volume at which that note will play.
The argument must be an Array of tracks. It is of course possible to add several tracks if you want to have several instruments playing at the same time.
I have chosen to go the base64 string route. Here is the code:
Click here if you want to read more on how to strip off the base64 string header.
You can check the git repo here to see the full sequence of notes.
PS: I have submitted my code to the creator of the official library and he has now merged it and added it to the examples :D