I am just looking into the MidiMessage class, because I want to program an arpeggiator with JUCE.
I realized, that MidiMessage is using malloc internally. As far as I know, malloc is not lock free.
So you are not allowed to create or copy a MidiMessage on the audio thread.
Am I correct here?
How do you guys deal with that? Do you create a separate Midi thread, which is separated from the audio thread? What do you think is the best way?
I would be very surprised this is correct. As far as I understand all incoming midi messages are fwd into the processor hence in the audio thread. Those may include sysex. How and where (on which thread) are those created then? (Then again, by all means surprise me!)
In the question it was asked to create an arpeggiator, which means creating simple midi messages inside the processBlock. And I would agree this is safe to do with simple noteOn, or controller messages.
However you are correct, as far as I can see in the code, if the midi device were to send a chunk of sysex data, this would in the JUCE wrapper trigger a MidiMessage::createSysex(), which involves a HeapBlock.
leads to:
which is:
This is a use case that might be worth looking into. Maybe there could be a flag to skip SysEx, if it is sent to an AudioProcessor for realtime consumption, but I am not expert enough in midi and all the use cases to make a call on that.