The Mudcat Café TM
Thread #77761   Message #1390990
Posted By: pavane
28-Jan-05 - 03:17 AM
Thread Name: Tech: how do I 'fix' a midi file?
Subject: RE: Tech: how do I 'fix' a midi file?
I am not sure you should 'fix' it in that way. A MIDI file requires a small set-up time at the start, in order to distribute setup parameters and maybe sampling dumps to the instruments.

A good MIDI sequencer will usually leave the equivalent of (at least) one bar length at the start to allow for this. Therefore I would be inclined to INCREASE the size of the rest.

(Fixing the MIDI file itself could be done - I have written programs to do similar changes, but the file format is complex, and you cannot edit it by hand.)

The program importing the MIDI has no easy way of telling where the actual music starts, because MIDI does not encode bar lines. If it assumes the start of the file, then it will be out by the setup time. If it assumes the first Note-on, then all the bars may be out of alignment because the first bar may be shorter than the others.

The bar lines can be calculated from the elapsed time (in MIDI ticks) and the time signature, but only if the person (or program) who sequences the file includes time signature changes for any nonstandard bars, e.g. a few bars of 4/4 in a 3/4 tune. Time and key signatures are optional in MIDI files, so not everyone bothers.