MidiFile Write Issue



Hi everyone,

I seem to be having an issue with writing MidiFiles from big Sysex packets (I’m talking at least 32kb). I’m trying to write one Midi sysex message into a MidiFile… when I output it as a .midi file, SysEx Librarian shows only one valid message. However, when outputting to .sysex file, the sysex message gets split up. Basically, the one written Midi track gets split up into several (up to 74-75 messages/tracks).

I tried to do a small unit test of sending the MidiMessage to an output MIDI device and I also see the sysex packet getting split up like crazy.

tl;dr: Having an issue with sysex messages getting split up into irrelevant midi packets/messages. Not sure what I’m doing wrong with my code because I’ve been able to create valid CC message and smaller sysex messages (small as in size 128).

My code:

void createMidiFile(uint8_t *sysex_data, int sysex_data_size, String filepath) {
    // Create MidiMessage (sysex_data_size can be up to 128kb):
    MidiMessage m = MidiMessage::createSysExMessage(&sysex_data[0], sysex_data_size); 
    MidiMessageSequence midiSequence;
    // Create File
    File outputFile = File::createFileWithoutCheckingPath(filepath);  
    FileOutputStream stream (outputFile);
    MidiFile midiFile;
    //(3) Write to MIDI File
    midiFile.writeTo(stream, 0);