I have a situation where I try to send MIDI notes to a track via a VirtualMidiInput. The notes never arrives at the synth living in the track (I can verify that by logging in the synth).
track->injectLiveMidiMessage(midiMessage, 0); // This works
virtualMidiInput->handleIncomingMidiMessage(midiMessage); // This doesn't
I can verify that the track is indeed a target track for virtualMidiInput by listing the target tracks:
Debugging reveals that the if statement on line 138 of MidiInputDeviceNode::processSection is triggered and thereby discarding the note:
// if it's been a long time since the last block, clear the buffer because
// it means we were muted or glitching
if (timeNow > lastReadTime + maxExpectedMsPerBuffer)
{
//jassertfalse
numMessages = 0;
}
We experience the problem in a test where we first run TransportControl::ensureContextAllocated and soon after virtualMidiInput->handleIncomingMidiMessage(midiMessage).
If we add juce::Thread::sleep(100) before the handleIncomingMidiMessage it works as expected, so there seems to be a race condition!?
Is ensureContextAllocated synchronous or asynchronous?
If asynchronous, is there way to know when things are set up and handleIncomingMidiMessage can be sent?
@svenemtellensureContextAllocated is synchronous.
If lastReadTime is initialised to juce::Time::getApproximateMillisecondCounter() rather than = 0, does your test case work? That’s probably what it should be.