MIDI device rescan (Windows)


#1

When adding MIDI devices/ports on Windows, a lot of audio applications have to be restarted in order to see the new changes because Windows doesn’t support MIDI hotplugging (unlike macOS/Linux). Some apps (Renoise, Live, Reaper, and FL Studio are ones I’ve found) get around this by adding a “rescan” button to their MIDI preferences page which does some sort of magic in the background to reinitialize all MIDI ports/devices.

Does anyone have any idea how to accomplish this, and/or could it possibly be added as a feature to JUCE? This feels like a major convenience thing that all JUCE apps could benefit from.


#2

We have a button like that in Tracktion, but IIRC it doesn’t do anything fancy, it just calls MidiInput::getDevices() again.


#3

That’s what I’ve been trying to do, but MidiInput::getDevices() (or its MidiOutput equivalent) always return the same values regardless of how the MIDI I/O configurations have changed. From what I’ve been reading, it’s a Windows-specific limitation related to MME that JUCE’s implementation isn’t taking into consideration.

I was trying to do some analysis of Windows API calls being made by programs which can detect these changes, but haven’t been able to come up with anything super useful, just that they appear to be shutting down/resetting Windows MIDI then restarting it somehow rather than just re-polling via midiInGet*/midiOutGet*, which doesn’t actually return any configuration changes made after the application started.


#4

Most MIDI devices are USB, on Windows you can get messages when USB devices get plugged/unplugged. Enumerate your devices again with MidiInput::getDevices() and you’ll probably have covered 99% of the use cases. Trick is though to wait a little bit after you get the callback from Windows, it sometimes takes a while before the system actually knows what kind of device has been connected. So if you refresh your devices at the moment you get the callback you might miss out.


#5

My specific use case is adding virtual MIDI ports via virtualMIDI - what you’re suggesting may very well work for USB MIDI (though I’m not sure based on what I’ve read about how Windows handles MIDI ports) but virtualMIDI appears to create actual WDM devices without any sort of USB intermediary which JUCE’s Windows MIDI implementation seems to have trouble picking up without restarting the application while the mentioned apps’ “rescan” functions handle it fine.

In the meantime I’m also contacting the virtualMIDI author to see if he has any ideas.


Refresh AudioDeviceSelectorComponent?
#6

I worked on a project where we had to do the Windows MIDI API calls in a background process. The actual app would communicate with this background process through IPC calls. When the user wanted to re-scan the devices, we would re-launch the background process. This was the only workaround we could find.


#7

Clever, I had thought of that too but I was really hoping there would be an easier way to do it. The more I read the more it seems like that’s the real answer…


#8

BTW this may have been fixed with the new Windows Runtime Midi API. Can anyone confirm?

See this thread on how to enable Windows Runtime Midi:
https://forum.juce.com/t/experimental-support-for-the-windows-runtime-midi-api?source_topic_id=20307

As long as you don’t use bluetooth, the new API should work quite well.