Check Online/Offline status of USB-MIDI application

I am creating a GUI for USB-MIDI audio processor. The device used to connect to computer through USB cable.
MIDI is the communication protocol. When a GUI is launched, I am creating a MIDIOutput object and calling the open() and sendMessageNow() method to send the MIDI messages.

My question is how can I know if device is attached or not or is it powered off after connecting and I can display some message to the user and stop sending the MIDI message. It’s like someone unplg the MIDI device.

Basically, I am trying to implement the Online/Offline state of the MIDI device.

Any suggestion is welcome!!!

As far as I know, the only way to learn that a USB MIDI driver has disconnected or connected is to enumerate all devices anew:

MidiOutput::getDevices() MidiInput::getDevices()
and then comparing your own internal device list with the results.

Under MacOS X, there is a cool notification callback that is called by the OS when a MIDI driver is connected disconnected, but unfortunately Juce does not make use of it. Probably because this does not work under Windows.

Therefore you must resort to polling in some way, i.e. enumerate the devices every 30 seconds or so.

BTW, if you are interested in hacking it yourself: Look in juce_mac_CoreMidi.cpp (“native”, getGlobalMidiClient()) and add a NotifyProc like this:

CHECK_ERROR (MIDIClientCreate (appName, NotifyProc, 0, &globalMidiClient));