Difference between revisions of "MIDI file parsing homework"
Jump to navigation
Jump to search
Line 23: | Line 23: | ||
90 3c 1e 82 00 90 3c 00 00 ff 2f 00 | 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") | 4d 54 68 64 MIDI header chunk marker ("MThd") | ||
00 00 00 06 Bytes to follow in header chunk (6) | 00 00 00 06 Bytes to follow in header chunk (6) | ||
Line 39: | Line 112: | ||
VLV MIDI message | VLV MIDI message | ||
============================================ | ============================================ | ||
− | 0 ff 58 '4 4 2 30 8 Meta-message for | + | 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 | + | 0 ff 59 '2 0 0 Meta-message for key signature: C major |
0 90 '60 '40 Note on, C4 | 0 90 '60 '40 Note on, C4 | ||
128 90 '60 0 Note off, C4 | 128 90 '60 0 Note off, C4 |
Revision as of 00:21, 26 January 2016
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).
- If it plays correctly, drag and drop the MIDI file from your desktop onto the binasc online webpage.
- 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 (or SMPTE frames/subframes) are used for basic timing in the file.
- Parse at least 25 time/message pairs in one of the tracks of the MIDI File. Note that type-1 files only stores 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).
- Decoding VLVs for delta timings is optional.
- 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. Converting bytes into a list of hexadecimal numbers with binasc online:
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) VLV 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