What’s the best way to use MidiOutput::getAvailableDevices() to observe when a MIDI device has been plugged in/out of the computer?
Should I just use a timer and poll that method from a dedicated thread every few seconds, or is there a better way to figure out when a MIDI device becomes available / unavailable?
Does calling MidiOutput::getAvailableDevices() have the danger of freezing the application for a tiny fraction of a second if called from a different thread than where the main application is running and using MIDI devices?
I tried the above idea of polling in a dedicated juce::Thread and I got an assertion failure in juce_CoreMidi_mac.mm findDevice() method:
// It seems that OSX can be a bit picky about the thread that's first used to
// search for devices. It's safest to use the message thread for calling this.
JUCE_ASSERT_MESSAGE_THREAD
It’s easy to do and I think it would be cool if JUCE included it.
In this way, when a device disconnects (e.g. loose usb plug, usb port going to sleep, etc), you can detect the error the next time that you send a message to it and you can make it reconnect automatically.