So I have gotten myself in to a small pickle. In removing a SYSEX event from a MIDI file, I need to combine the pre- and post-SYSEX delta times in to a new single delta time and write that/those byte(s) in place of the original delta times. I know how to read a delta time going forward in a file. If the byte is greater than 127, keep reading until the byte is less than 127, combine values appropriately. However, if I do this going backwards, the"first" byte will always be less than 127, so how would I know how far back to go before stopping? Is this even possible? I think maybe not. For example, two SYSEX commands one after another. F0 ... F7 12 F0 ... F7 12 ... would give me two delta times of 12, adding to 24, but if I tried to read backwards I'd have F7 12, which is obviously no good.
I thought of a workaround while typing this, in that I could store the pre- and post-SYSEX delta times in their own variables as I am reading the file in, but I feel like there might be a better solution. Or am I doomed because MIDI is a linear "forward" format?