I have been trying without any success to write a simple MidiMessageSequence to a MidiFile. I followed all the advice in the blog and the documentation, and in the examples.
The MIDI data is gathered from the handleIncomingMidiMessage callback.
When I try to open the file in Logic or any other MIDI enabled DAW, it does not load.
I checked with MidiKit and it is possible to “fix” the file using the “fix” function.
The error indicated in MidiKit is “the extension/type should be fixed”.
You probably have a few other problems, but note that FileOutputStream appends to a file. You should at least delete the file first or you’ll just be adding more junk on the end each time.
I can certainly make sure the file doesn’t exist first, however in my case I am always writing to a new directory, so there is no chance the file might already exist.
Strangely enough the file, once “fixed” by MidiKit, looks, internally, exactly the same as the faulty one.
Here are the two identical files, on of them is the faulty file created by my code. I still have timing issues with the “fixed” file though, and I’ll need to figure that one out. I saw some discussions concerning that. I hope they’re not related.
I was wondering if someone could take a few minutes to try to generate a MIDI file, and see if they can make it work, and perhaps show me how ? I am on Mac Osx 10.13.3 Beta. (I am an Apple Beta tester).
Hmm, for a start you seem to call both setSmpteTimeFormat and setTicksPerQuarterNote, referring to your first post. These sets the used time format and are mutually exclusive, you must decide on using either, have a read of the comments in juce_MidiFile.h for getTimeFormat(), setTicksPerQuarterNote() and setSmpteTimeFormat().
In other words you have to decide in what time format you want to save your midi file and thereafter calculate the time stamp for each midi event according to that format. And tempo meta events are not used for smtpe formats.
Besides, there’s no need to call updateMatchedPairs() just to save a sequence, it will only update some internal pointers that’s not going to be saved anyway. But if you do (e.g after manually editing a midi sequence) you mustn’t call sort() afterwards while it might screw up the order of the newly updated pair-pointers. But in this case (recording some live midi events as it looks like), both calls will probably do nothing (the sequence is already sorted).