I'm working on a java project that receives midi events from midi hardware using the javax.sound.midi library. In the documentation, it says that MidiSystem.getMidiDeviceInfo()
returns a list of all connected midi hardware. It works for me, but the problem is, it only works once. It takes a moment the first time to actually scan for the devices, but each time after that it will immediately return that same list even if new devices have been connected. Is there a way to force it to rescan? It will rescan if the application is restarted, but I don't want my users to have to restart if they connect a new midi device.
BTW, I'm using Mac OS X... it's been pointed out that behavior may be different for different OS's.
The
MidiSystem.getMidiDeviceInfo()
gets the full providers list, and extracts the info of the device from each provider.The MIDIs provider list is recovered from the JDK underlaying class com.sun.media.sound.JDK13Services, through the static method
getProviders()
So, it seems that this class holds thee Providers list in a cache, wich will be reloaded after a certain period. You can set this period to a custom value using the method
setCachingPeriod(int seconds)
. As long as I know, the default caching period is set to 60 seconds.As an example, to refresh this cache every second, you coud add this line to your code:
Please, note that this solution makes use of a Sun propietary class, so it could not be 100% portable.