Udostępnij za pośrednictwem


Enumerating MIDI devices

This blog post has moved to https://matthewvaneerde.wordpress.com/2012/09/21/enumerating-midi-devices/

Comments

  • Anonymous
    November 15, 2016
    The comment has been removed
    • Anonymous
      November 15, 2016
      You can use the "container ID" device property to see if two device interfaces are on the same piece of physical hardware. This is how the "Devices and Printers" control panel works.
  • Anonymous
    February 03, 2017
    I'm pulling my hair out trying to get a "device has been (re)attached, so (re)open the matching MIDI Input and Output devices with midiInOpen() and midiOutOpen()" logic to work. It works partially with MIDI devices that do report a device interface. "Partially", because the midiIn... and midiOut... functionality refuses to acknowledge any changes when a USB MIDI device is attached or detached, so I can't open a MIDI device that has been attached AFTER the program has been started. That's all on Windows 7, by the way; I haven't tried it on other versions yet.With a KORG nanoKEY2, which is what I got here, I'm totally out of luck. While I do get WM_DEVICECHANGE messages when it's pluggied in or out, I can't match the reported device ID to any of the nanoKEY2's MIDI device names.Using SetupDiGetClassDevs() / SetupDiGetDeviceInstanceId() / SetupDiGetDeviceRegistryProperty(), I can only find out the attached device's device description, which is "KORG nanoKEY2"; the nanoKEY2 device doesn't report a friendly name. The device description has nothing to do with the names reported by midiInGetDevCaps() and midiOutGetDevCaps(), which are in: nanoKEY2 1 KEYBOARD out: nanoKEY2 1 CTRLNeither input nor output MIDI device report a device interface, so I can't try to match that.I tried to use the "container ID" device property for the attached device, but that doesn't work.Assuming that you mean (Pseudocode): SetupDiGetDeviceProperty(..., DEVPKEY_ContainerId, guid ...) hdi2 = SetupDiGetClassDevs(NULL,NULL,NULL,DIGCF_ALLCLASSES) for each SetupDiEnumDeviceInfo(did2) in hdi2 SetupDiGetDeviceProperty(..., DEVPKEY_ContainerId, guid2 ...) if (guid equals guid2) we got a match!... there's exactly one device with this container ID - the one being attached or detached. No other devnodes.Do you have any idea how to match the attached/detached device to the corresponding MIDI devices? How is this done in the WinMM system (apart from the unfortunate little fact that it's obviously only done once, when winmm.dll is loaded)?
    • Anonymous
      February 21, 2017
      A MIDI device may afford multiple MIDI interfaces. These interfaces will have unique interface IDs.You can discover the interface ID via the MIDI APIs as outlined above.With the interface ID in hand, you can query the associated device instance, container ID, etc.The WinMM MIDI API is considered "legacy" at this point. New apps should use the WinRT API. There's a sample here:https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/MIDI