MIDI file parsing homework
Assignment
- Find a MIDI file on the web. Tip: include filetype:midior filetype:mid when searching for MIDI files in Google searches.
- Save the MIDI file to your desktop and open it (usually double-clicking to open with the default MIDI playing program on your computer). Here are instructions for installing an older version of Quicktime in OS X which plays MIDI files.
- If it plays correctly, drag and drop the MIDI file from your desktop into the box below:
- Parse the resulting display of the MIDI file's hexadecimal bytes by hand. Make note of the number of tracks in the file; whether it is type-0 or type-1 (or type-2), and how many ticks per quarter note are used for basic timing in the file.
- Parse at least 20 delta-time/message pairs in one of the tracks of the MIDI File. Note that type-1 files only store meta messages such as tempo changes in the first track. If your file is a type-1 file, try parsing a few of these meta messages, and then switch to another track with notes.
- Give the basic meaning of MIDI messages (such as this is a note-on messages for pitch A4, or this is a tempo meta message).
- Does the MIDI file use "running status"? Running status would result in the first byte of a MIDI message in any (delta-time/message) pair to be a data byte rather than a command-byte (and the last command-byte in the track would be the inferred command byte).
- Decoding VLVs for delta timings is optional.
- Extra Credit: If decoding the VLV values, does the MIDI file look like it was performed live, or does it represent quantized/proportional time? In other words, if the ratio of time values looks like integers, such as 2:1 for quarter-note:eighth note, then it could not possibly be performed so accurately.
- Extra Credit: Write your own Standard MIDI File parser which will do this homework for you.
- Email MIDI file and your parsing to you know whos.
Example
Here is the simple example done in class using File:Twinkle.mid:
4d 54 68 64 00 00 00 06 00 00 00 01 00 80 4d 54 72 6b 00 00 00 8c 00 ff 58 04 04 02 30 08 00 ff 59 02 00 00 00 90 3c 28 81 00 90 3c 00 00 90 3c 1e 81 00 90 3c 00 00 90 43 2d 81 00 90 43 00 00 90 43 32 81 00 90 43 00 00 90 45 2d 81 00 90 45 00 00 90 45 32 81 00 90 45 00 00 90 43 23 82 00 90 43 00 00 90 41 32 81 00 90 41 00 00 90 41 2d 81 00 90 41 00 00 90 40 32 40 90 40 00 40 90 40 28 40 90 40 00 40 90 3e 2d 40 90 3e 00 40 90 3e 32 40 90 3e 00 40 90 3c 1e 82 00 90 3c 00 00 ff 2f 00
Basic parsing:
4d 54 68 64 ; ASCII characters "MThd" 00 00 00 06 ; Number of bytes in header to follow: 6 00 00 ; MIDI file type: 0 00 01 ; Number of tracks: 1 00 80 ; Ticks per quarter note: 128 4d 54 72 6b ; ASCII characters "MTrk" 00 00 00 8c ; Number of bytes in track to follow: 140 00 ; 0 ticks ff 58 04 04 02 30 08 ; time signature meta event 00 ; 0 ticks ff 59 02 00 00 ; key signature meta event 00 ; 0 ticks 90 3c 28 ; note-on C4 81 00 ; 128 ticks 90 3c 00 ; note off C4 00 ; 0 ticks 90 3c 1e ; note-on C4 81 00 ; 128 ticks 90 3c 00 ; note off C4 00 ; 0 ticks 90 43 2d ; note-on 81 00 ; 128 ticks 90 43 00 ; note-off 00 ; 0 ticks 90 43 32 ; note-on 81 00 ; 128 ticks 90 43 00 ; note-off 00 ; 0 ticks 90 45 2d ; note-on 81 00 ; 128 ticks 90 45 00 ; note-off 00 ; 0 ticks 90 45 32 ; note-on 81 00 ; 128 ticks 90 45 00 ; note-off 00 ; 0 ticks 90 43 23 ; note-on 82 00 ; 256 ticks 90 43 00 ; note-off 00 ; 0 ticks 90 41 32 ; note-on 81 00 ; 128 ticks 90 41 00 ; note-off 00 ; 0 ticks 90 41 2d ; note-on 81 00 ; 128 ticks 90 41 00 ; note-off 00 ; 0 ticks 90 40 32 ; note-on 40 ; 64 ticks 90 40 00 ; note-off 40 ; 64 ticks 90 40 28 ; note-on 40 ; 64 ticks 90 40 00 ; note-off 40 ; 64 ticks 90 3e 2d ; note-on 40 ; 64 ticks 90 3e 00 ; note-off 40 ; 64 ticks 90 3e 32 ; note-on 40 ; 64 ticks 90 3e 00 ; note-off 40 ; 64 ticks 90 3c 1e ; note-on 82 00 ; 256 ticks 90 3c 00 ; note-off 00 ; 0 ticks ff 2f 00
Example of more detailed parsing:
4d 54 68 64 MIDI header chunk marker ("MThd") 00 00 00 06 Bytes to follow in header chunk (6) 00 00 file format: Type-0 (0 == single track format) 00 01 number of tracks (1) 00 80 ticks per quarter note (128) First (and only track): 4d 54 72 6b MIDI track chunk marker ("MTrk") 00 00 00 8c Bytes to follow in track chunk (140 bytes) Delta time / MIDI message ============================================ 0 ff 58 '4 4 2 30 8 Meta-message for time signature 4/; 48 ticks per metronome click; 8 32nds per beat 0 ff 59 '2 0 0 Meta-message for key signature: C major 0 90 '60 '40 Note on, C4 128 90 '60 0 Note off, C4 0 90 '60 '30 etc. 128 90 '60 0 0 90 '67 '45 128 90 '67 0 0 90 '67 '50 128 90 '67 0 0 90 '69 '45 128 90 '69 0 0 90 '69 '50 128 90 '69 0 0 90 '67 '35 256 90 '67 0 0 90 '65 '50 128 90 '65 0 0 90 '65 '45 128 90 '65 0 0 90 '64 '50 64 90 '64 0 64 90 '64 '40 64 90 '64 0 64 90 '62 '45 64 90 '62 0 64 90 '62 '50 64 90 '62 0 64 90 '60 '30 256 90 '60 0 0 ff 2f 0 Meta-message for end-of-track
Notice that this MIDI file was clearly not performed live. The delta-time durations are: 0, 64, 128, and 265 which are all multiples of two from each other (representing eighth notes, quarter notes and half notes).