What is KVR Audio? | Submit News | Advertise | Developer Account

Options (Affects News & Product results only):

OS:
Format:
Include:
Quick Search KVR

"Quick Search" KVR Audio's Product Database, News Items, Developer Listings, Forum Topics and videos here. For advanced Product Database searching please use the full product search. For the forum you can use the phpBB forum search.

To utilize the power of Google you can use the integrated Google Site Search.

Products 0

Developers 0

News 0

Forum 0

Videos 0

Search  

I got a Windows MIDI programming problem (partially solved)

DSP, Plug-in and Host development discussion.

Moderator: Moderators (Main)

arakula
KVRAF
 
1932 posts since 16 Aug, 2004, from Vienna, Austria

Postby arakula; Sat Jan 25, 2014 8:10 am I got a Windows MIDI programming problem (partially solved)

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 12:28 pm, edited 1 time in total.
"Until you spread your wings, you'll have no idea how far you can walk." Image
mystran
KVRAF
 
4155 posts since 11 Feb, 2006, from Helsinki, Finland

Postby mystran; Sat Jan 25, 2014 8:26 am Re: I got a Windows MIDI programming problem...

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.
Image <- plugins | forum
bitwise
KVRist
 
90 posts since 18 Mar, 2012

Postby bitwise; Sat Jan 25, 2014 1:53 pm Re: I got a Windows MIDI programming problem...

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
arakula
KVRAF
 
1932 posts since 16 Aug, 2004, from Vienna, Austria

Postby arakula; Sun Jan 26, 2014 12:57 am Re: I got a Windows MIDI programming problem...

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
arakula
KVRAF
 
1932 posts since 16 Aug, 2004, from Vienna, Austria

Postby arakula; Mon Jan 27, 2014 12:37 pm Re: I got a Windows MIDI programming problem (partially solv

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
duncanparsons
KVRAF
 
8375 posts since 11 Apr, 2003, from now on the flat

Postby duncanparsons; Mon Jan 27, 2014 5:10 pm Re: I got a Windows MIDI programming problem (partially solv

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
arakula
KVRAF
 
1932 posts since 16 Aug, 2004, from Vienna, Austria

Postby arakula; Tue Jan 28, 2014 10:15 am Re: I got a Windows MIDI programming problem (partially solv

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
mystran
KVRAF
 
4155 posts since 11 Feb, 2006, from Helsinki, Finland

Postby mystran; Tue Jan 28, 2014 10:44 am Re: I got a Windows MIDI programming problem (partially solv

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
Image <- plugins | forum

Moderator: Moderators (Main)

Return to DSP and Plug-in Development