MidiMessageSequence::addEvent() and EOT

I think that MidiMessageSequence::addEvent() should check if the newMessage isEndOfTrackMetaEvent() and if it is, delete any other EOT Events which may exist in the sequence to prevent there being more than one EOT Event on the Track.



Why would you want to add an EOT event to a sequence, unless you create it from from scratch? And then you’d probably remember what you’ve done and don’t do it twice…

Admittedly it might make sense to do a check when adding two midimessagesequences, and then only keep the one with the last timestamp, but then I’d rather have a check when saving the sequence to a file.

Come to think about it, I might add a temporary EOT as a placeholder/cue point when adding to sequences or doing a time stretch, and you’re suggestion might probably break that. And hence might break some others code as well…

What’s your use case?

Well it was part of debugging an issue where I was creating a new sequence from an existing sequence… and the new sequence ended up with an EOT 2x the last event.

I fixed the issue by checking for the EOT of the original and not adding it to the new sequence (which was my bug)… but part of the debugging was to add an EOT after I added the last Event and that ended up with the new sequence having two EOT’s (which isn’t allowed)… so JUCE should trap for that in addEvent and in MIDIFile::addTrack() IMO to ensure that the created MIDI sequence and MIDIFile conform to the spec.