Fix Standard MIDI File track chunk byte counts.
MIDI track chunk byte counts are often incorrect in Standard
MIDI Files. This example program shows how to correct byte
counts by reading a MIDI file and then writing it out again,
without doing anything else to automatically fix the track
chunk sizes.
The
MidiFile
class ignores the byte-count value in track chunk headers when
reading a MIDI file, so incorrect byte counts do not affect parsing
of the file. When writing a file out again, the byte count for
each track is calculated and automatically corrected.
Note that the MidiFile class usually expands running-status messages,
so the size of the MIDI file may change from the original size.
Also note that this example overwrites the old file contents. To
ensure that there was not a problem reading the file, the
MidiFile::status
function is checked to
see if the parsing of the input data was successful.