I got a Windows MIDI programming problem (partially solved)

DSP, Plugin and Host development discussion.
Post Reply New Topic
RELATED
PRODUCTS

Post

Or rather, a usability problem.

If I open a USB-attached MIDI masterkeyboard using the good old midiInOpen(..., CALLBACK_FUNCTION), all works nicely... until I decide to be not so nice and simply disconnect the USB-attached keyboard while the MIDI connection is still open and in recording state. I would have expected to receive a notification, but no - nothing happens. If I then reconnect the device, the old connection doesn't see any MIDI message; I have to close and re-open it to make it work again (I haven't looked yet whether midiInStop() / midiInStart() would also be sufficient).

I've spent the best part of two days now trying to find any information on how to deal with detached USB MIDI devices, but either my Google skills aren't up to the task or nobody else has this problem (hard to believe in these days of ubiquitous USB devices).

Is there a way that I can receive notifications about the fact that my MIDI connection is actually dead?
Last edited by arakula on Mon Jan 27, 2014 8:28 pm, edited 1 time in total.
"Until you spread your wings, you'll have no idea how far you can walk." Image

Post

arakula wrote:Or rather, a usability problem.

If I open a USB-attached MIDI masterkeyboard using the good old midiInOpen(..., CALLBACK_FUNCTION), all works nicely... until I decide to be not so nice and simply disconnect the USB-attached keyboard while the MIDI connection is still open and in recording state. I would have expected to receive a notification, but no - nothing happens. If I then reconnect the device, the old connection doesn't see any MIDI message; I have to close and re-open it to make it work again (I haven't looked yet whether midiInStop() / midiInStart() would also be sufficient).
Not much experience on the programming side, but for what it's worth, I'm not sure if I've ever seen a host where you wouldn't need to do some sort of rescan or something afterwards. My nanoKontrol seems to drop out every once in a while and needs to be replugged, and it always seems to require some manual action with the host.

Post

arakula wrote:Or rather, a usability problem.

If I open a USB-attached MIDI masterkeyboard using the good old midiInOpen(..., CALLBACK_FUNCTION), all works nicely... until I decide to be not so nice and simply disconnect the USB-attached keyboard while the MIDI connection is still open and in recording state. I would have expected to receive a notification, but no - nothing happens. If I then reconnect the device, the old connection doesn't see any MIDI message; I have to close and re-open it to make it work again (I haven't looked yet whether midiInStop() / midiInStart() would also be sufficient).

I've spent the best part of two days now trying to find any information on how to deal with detached USB MIDI devices, but either my Google skills aren't up to the task or nobody else has this problem (hard to believe in these days of ubiquitous USB devices).

Is there a way that I can receive notifications about the fact that my MIDI connection is actually dead?
RegisterDeviceNotification seems to be an option:

http://msdn.microsoft.com/en-us/library ... 85%29.aspx

Post

That's an interesting route. Looks like processing WM_DEVICECHANGE should be sufficient, even without registering anything; I'll investigate whether it's possible to match the DBT_DEVNODES_CHANGED data with the device names reported by midiInMessage(., DRV_QUERYDEVICEINTERFACE, ...).
"Until you spread your wings, you'll have no idea how far you can walk." Image

Post

Just a little note en route, in case anybody might be interested in this arcane little problem:

RegisterDeviceNotification is necessary, since without it only DBT_DEVNODES_CHANGED is broadcast, and this doesn't contain information about the device that's been added or removed. Using

Code: Select all

DEV_BROADCAST_DEVICEINTERFACE dvbi = 
  {
  sizeof(dvbi),
  DBT_DEVTYP_DEVICEINTERFACE
  };
hdn = RegisterDeviceNotification(hMainWnd,
                                 &dvbi,
                                 DEVICE_NOTIFY_WINDOW_HANDLE |
                                     DEVICE_NOTIFY_ALL_INTERFACE_CLASSES);
I can receive WM_DEVICECHANGE messages with DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE, too.
And yes, it looks like the device interface name can be directly compared to the device interface name I can get with midiInMessage() / midiOutMessage().

Hehe...

Automatic re-open seems to work, at least with my acorn masterkey 25 on Windows XP.
Next on the agenda: more tests on other machines with other OS versions and other interfaces...
"Until you spread your wings, you'll have no idea how far you can walk." Image

Post

if you need a beta test, I have XP and Win7 boxes, and Alesis QX49, Korg nanoKey and a CME UF6, oh and a MIDI->USB lead - that's 8 test cases right there!
Image

Post

Duncan, if you want to test it, I've just uploaded a beta of VSTHost and SAVIHost to the usual location, which is
http://www.hermannseib.com/programs/beta/
Have fun!

The MIDI Input part seems to work; in theory, detachable MIDI Output devices should also be auto-reconnected, but I haven't tested that yet. In theory, the code should be effective on any OS starting with Windows 2000 (ME, 2000, XP, Vista, 7, 8 ). Earlier versions (NT4, Win98) don't have the necessary capabilities - but VSTHost (the "w98" version) should still run on them.

(BTW, is the nanokey really as flaky as the reviews I've read seem to suggest? I'm looking for a small device to go with my laptop...)
"Until you spread your wings, you'll have no idea how far you can walk." Image

Post

I have a nanoKontrol (original; it's my favorite controller 'cos it fits between my keyboard and screen) and that one occasionally likes to stop sending MIDI until replugged (I guess it typically works for a couple of days at a time without reboot). Not a big deal, just detaching the cord for a second fixes the problem, but still somewhat annoying. :P

Post Reply

Return to “DSP and Plugin Development”