WinRT MIDI API returns invalid MIDI port names

Joss Gray 1 Reputation point
2022-06-03T00:18:12.957+00:00

The WinRT MIDI api in latest Windows 10 returns the name "MIDI" for some devices, which have a different name with the Win32 MIDI API.

For example the RME HDSPe AIO has a port name "AIO Midi" in Win32 API but just "MIDI" in WinRT API.

Is there any fix for this? Or a way to relate Win32 API midi ports to the WinRT counterpart?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,449 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Trienco 0 Reputation points
    2024-05-22T16:27:44.3166667+00:00

    I had the same issue. Proper hot plugging and a way to identify the devices that isn't as useless as an index. I found tons of threads and bug reports over many years and not once did MS explain how to use their API or at least point at the generic part about device handling.

    Win32 seems to return the device name, WinRT is technically more correct in returning the port name (since you enumerate/watch ports and not devices). To get the device name, get the device container id from the ports properties and create the device information for that id. Now you should be getting the proper name (the top level name you see in the device manager).

    watcher.Added([this](DeviceWatcher, DeviceInformation port) {
    	const auto cont_id = port.Properties().Lookup(L"System.Devices.ContainerId").as<winrt::guid>();
    	const auto device = DeviceInformation::CreateFromIdAsync(to_hstring(cont_id), {}, DeviceInformationKind::DeviceContainer).get();o device_id = to_string(device.Id());
    	auto device_name = to_string(device.Name());
      ...
    

    In my case it's followed by some logic to check if the device id is already listed for a different port. The easy option would be to display "device_name (port_name)", but I do some extra work to avoid showing the port name at all if a device has only one port anyway.

    0 comments No comments