Load what we can from broken/truncated MIDI files.

We're still a very long way from tolerant of weird SMF files (libsmf takes a
"crash if input is not exactly perfect" philosophy, if we're going to be polite
and elevate such a thing to "philosophy"), but at least we'll get what's there
from files truncated by old broken versions of Ardour or other situations.
This commit is contained in:
David Robillard 2014-12-30 23:07:19 -05:00
parent 4facff3b8e
commit 168d187994
4 changed files with 74 additions and 44 deletions

View file

@ -286,7 +286,11 @@ SMF::read_event(uint32_t* delta_t, uint32_t* size, uint8_t** buf, event_id_t* no
memcpy(*buf, event->midi_buffer, size_t(event_size));
*size = event_size;
assert(midi_event_is_valid(*buf, *size));
if (!midi_event_is_valid(*buf, *size)) {
cerr << "WARNING: SMF ignoring illegal MIDI event" << endl;
*size = 0;
return -1;
}
/* printf("SMF::read_event @ %u: ", *delta_t);
for (size_t i = 0; i < *size; ++i) {