keijiro / MidiJack

MIDI input plugin for Unity
695 stars 113 forks source link

Duplicate device detection not working on Win10 #36

Closed cdwfs closed 5 years ago

cdwfs commented 5 years ago

Hello -- I'm trying to use MidiJack with a nanoKONTROL2 on Windows 10, and when I open the MidiJack window I see an endless spew of duplicate devices appearing over time (each with a unique DeviceHandle). I'm using the MidiJackPlugin.dll in a C++ test project to debug the issue, and I can reproduce the problem there as well, so I don't think Unity is involved.

Tracing into the DLL code: every time I call MidiJackDequeueIncomingData(), it calls RefreshDevices(), which in turn calls OpenAllDevices(). This function correctly detects 1 connected device, and calls OpenDevice(0). This is where the problem seems to occur -- OpenDevice calls midiInOpen() with index=0, which gets a new DeviceHandle and returns MMSYSERR_NOERROR, even though the device at index 0 is already open. This handle is immediately passed to midiInStart(), which also returns MMSYSERR_NOERROR. The plugin now believes it's detected and started a brand new device, so it adds it to active_handles array. This array just continues to grow, filling up with new handles all referring to the same device.

I'm not sure what the actual error is; is either midiInOpen() or midiInStart() supposed to return an error code if the specified device has already been opened/started, or is the application's responsibility to query all handles after opening them and filtering out/closing those that have already been opened & started? If the latter, then MidiJack just seems to be broken as written -- yet I see plenty of successful reports of it working on Windows, so that seems unlikely. Could it instead be a driver issue on KORG's side? I'm using the latest WIn10 driver I can find (1.15 r25e).

Any help would be appreciated; thanks!

cdwfs commented 5 years ago

Ah, I just found the troubleshooting entry regarding problems with KORG controllers. I'll try uninstalling the KORG driver as recommended and post my results.

cdwfs commented 5 years ago

Sure enough, after switching back to the default USB Audio Device driver, midiInOpen() now fails when attempting to re-open a device that's already opened. I'll happily blame the KORG driver for this one.

keijiro commented 5 years ago

I'm closing the issue now. Please feel free to reopen for further issues.