Recording, writing, and reading large MIDI files


#1

I am writing an application in which a user can record their MIDI commands while DJing a set. I am wondering how to deal with a recording that could be several hours long, uninterrupted.

First of all, the MidiFile class seems to only let you write a MidiFile all at once, meaning that several hours’ worth of MIDI commands would have to be stored in memory until the very end (when the user stops recording). For obvious reasons, I’d much rather write to the MIDI file as the MIDI commands are received, similar to how a long audio file might be recorded. Is there no way to do this?

Second, I noticed in the MidiFile::readFrom function that there is a line which reads:
const int maxSensibleMidiFileSize = 2 * 1024 * 1024;
Any reason for this? It might prevent my users from loading large files.

Just to clarify, I have already succeeded in writing/reading small MIDI files, so my question is just about very large files. Thanks for any insights.


#2

Hi MusicMan3001,

Unfortunately JUCE doesn’t support realtime writing of MIDI data to a file and instead all the MIDI data is written to the file in one call to the MidiFile::writeTo() method. One possible way of avoiding having to store all your MIDI data in memory until the end is to write short chunks of MIDI data to separate files as the performance is happening and then combine all the files at the end.

As for your second issue, I’ve pushed a change to the develop branch that increases the maximum sensible MIDI file size to 200mb instead of the previous 2mb - this should be large enough for most MIDI files.

Hope this helps!

Ed


#3

Yes, thanks very much for your reply.


#4

MusicMan3001 any chance you could jump in on this thread and help me figure out why the midi files I’m saving aren’t showing up at the proper length: MidiMessageSequence -> MidiFile question