# WinRT MIDI Output wrong device names

**URL:** <https://forum.juce.com/t/winrt-midi-output-wrong-device-names/43301>\
**Category:** General JUCE discussion\
**Created:** [December 16, 2020, 11:51pm UTC](https://forum.juce.com/t/winrt-midi-output-wrong-device-names/43301 "2020-12-16T23:51:21Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![benkuper](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/benkuper/32/899_2.png) [@benkuper](https://forum.juce.com/u/benkuper)\
**Post date:** [December 16, 2020, 11:51pm UTC](https://forum.juce.com/t/winrt-midi-output-wrong-device-names/43301/1 "2020-12-16T23:51:21Z")

</div>

Hello,  
I’ve noticed a problem with MIDI output device naming, only on Windows and with WinRT enabled.

This is the detected input devices :  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/1/1b86ccdc69b9b51b820b8f53da5633069c379a94.png)

And this is the detected output devices :  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/5/5e343914deeeae1293628b38ee643080359c3967.png)

“MIDI” and “MIDI-2” should show “Cool” and “loopMIDI Port”.

When disabling WinRT, this works just fine, output devics are shown the right way, without any change in the code.

---

<div class="post-metadata">

**Author:** ![EddieL](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/eddiel/32/4602_2.png) [@EddieL](https://forum.juce.com/u/EddieL)\
**Post date:** [December 26, 2020, 4:08pm UTC](https://forum.juce.com/t/winrt-midi-output-wrong-device-names/43301/2 "2020-12-26T16:08:39Z")

</div>

This is a Microsoft problem. Unfortunately there is nothing that Juce can do about it.  
This was [brought to Microsoft’s attention](https://social.msdn.microsoft.com/Forums/windowsapps/en-US/e956555c-0640-4531-9beb-cba48a847020/winrt-midi-stack-name-handling-flaw-winrt-midi-stack-is-presently-unusable) years ago, but to date has not been fixed. They eventually fixed the SysEx problem, but not the device name problem. ☹

---

<div class="post-metadata">

**Author:** ![benkuper](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/benkuper/32/899_2.png) [@benkuper](https://forum.juce.com/u/benkuper)\
**Post date:** [December 26, 2020, 7:08pm UTC](https://forum.juce.com/t/winrt-midi-output-wrong-device-names/43301/3 "2020-12-26T19:08:04Z")

</div>

Thanks for the update, this is such a shame… Well I’ll just disable WinRT until this is in a better shape, this just feels like a shitty bug from the user perspective, and nothing I can do about it so…

---

<div class="post-metadata">

**Author:** ![benkuper](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/benkuper/32/899_2.png) [@benkuper](https://forum.juce.com/u/benkuper)\
**Post date:** [February 4, 2021, 3:34pm UTC](https://forum.juce.com/t/winrt-midi-output-wrong-device-names/43301/4 "2021-02-04T15:34:33Z")

</div>

Some update, I’m very curious because the software MIDIBerry is able to list the good names in the MIDI outputs… does someone know how they manage it ?

EDIT : From MIDIBerry description " Windows 10 does not report the port name correctly, so we analyzed it independently"  
That may be the best outcome for now to implement in JUCE, since Windows will likely not move a finger on this one…

---

<div class="post-metadata">

**Author:** ![benkuper](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/benkuper/32/899_2.png) [@benkuper](https://forum.juce.com/u/benkuper)\
**Post date:** [October 16, 2021, 8:33am UTC](https://forum.juce.com/t/winrt-midi-output-wrong-device-names/43301/5 "2021-10-16T08:33:25Z")

</div>

Following up on this unresolved problem…  
This is the WINRT\_LOG from Juce using 2 loopMidi ports (“loopMIDI Port” and “DrumLoopback”) the 2 “MIDI” devices are the outputs detected by JUCE that correspond to the 2 loopMidi ports.

```auto
Detected MIDI device: \\?\SWD#MMDEVAPI#MIDII_0AB1A388.P_0000#{6dc23320-ab33-4ce4-80d4-bbb3ebbf2814}
Adding MIDI device: \\?\SWD#MMDEVAPI#MIDII_0AB1A388.P_0000#{6dc23320-ab33-4ce4-80d4-bbb3ebbf2814} {00000000-0000-0000-FFFF-FFFFFFFFFFFF} MIDI
Detected MIDI device: \\?\SWD#MMDEVAPI#MIDII_0AB1A389.P_0004#{504be32c-ccf6-4d2c-b73f-6f8b3747e22b}
Adding MIDI device: \\?\SWD#MMDEVAPI#MIDII_0AB1A389.P_0004#{504be32c-ccf6-4d2c-b73f-6f8b3747e22b} {00000000-0000-0000-FFFF-FFFFFFFFFFFF} loopMIDI Port [1]
Detected MIDI device: \\?\SWD#MMDEVAPI#MIDII_0AB1A388.P_0004#{504be32c-ccf6-4d2c-b73f-6f8b3747e22b}
Adding MIDI device: \\?\SWD#MMDEVAPI#MIDII_0AB1A388.P_0004#{504be32c-ccf6-4d2c-b73f-6f8b3747e22b} {00000000-0000-0000-FFFF-FFFFFFFFFFFF} DrumLoopback [1]
Detected MIDI device: \\?\SWD#MMDEVAPI#MicrosoftGSWavetableSynth#{6dc23320-ab33-4ce4-80d4-bbb3ebbf2814}
Adding MIDI device: \\?\SWD#MMDEVAPI#MicrosoftGSWavetableSynth#{6dc23320-ab33-4ce4-80d4-bbb3ebbf2814} {00000000-0000-0000-FFFF-FFFFFFFFFFFF} Microsoft GS Wavetable Synth
OSC Remote Control::Now receiving on port : 42000
Detected MIDI device: \\?\SWD#MMDEVAPI#MIDII_0AB1A389.P_0000#{6dc23320-ab33-4ce4-80d4-bbb3ebbf2814}
Adding MIDI device: \\?\SWD#MMDEVAPI#MIDII_0AB1A389.P_0000#{6dc23320-ab33-4ce4-80d4-bbb3ebbf2814} {00000000-0000-0000-FFFF-FFFFFFFFFFFF} MIDI

```

We can see that there is a way to match input devices and output devices, they have the same path except for P\_0000 for output and P\_0004 for input. their id next to it (I don’t know what it is but it’s not the device info apparently) are different between input and output, but the same for all loopMIDI ports, even after restarting loopMidi.

Unfortunately the only info we get from Juce’s MidiDeviceInfo class is the deviceInfo property `{00000000-0000-0000-FFFF-FFFFFFFFFFFF}` and the name `MIDI` so there is no way to differentiate any of the loop midi devices if there are more than one.

There seems that the order of detection is not predictable, and everything happens multithread, which does not facilitate the task, but I guess if somehow we can first look for inputs and then outputs, and if the output is weird or with some recognizable pattern, then we can fetch the name from the input device ? That would at least make it readable for users, and definitely not waiting for Microsoft to deal with this sh\*t…

---

<div class="post-metadata">

**Author:** ![bcsuganthan](https://avatars.discourse-cdn.com/v4/letter/b/858c86/32.png) [@bcsuganthan](https://forum.juce.com/u/bcsuganthan)\
**Post date:** [December 26, 2021, 4:32pm UTC](https://forum.juce.com/t/winrt-midi-output-wrong-device-names/43301/6 "2021-12-26T16:32:38Z")

</div>

The same problem still exists.

I have a temporary fix for this - which is to take names from their corresponding MIDI input names, when the midiOutputSelector comboBox gets updated:  
In `AudioDeviceSelectorComp::updateAllControls()`,

```auto

if (midiOutputSelector != nullptr)
    {
        auto newMidiOutputs = MidiOutput::getAvailableDevices();
        auto newMidiInputs = MidiInput::getAvailableDevices();

        if (currentMidiOutputs != newMidiOutputs)
        {
            midiOutputSelector->clear();

            midiOutputSelector->addItem(getNoDeviceString(), -1);
            midiOutputSelector->addSeparator();           

            auto defaultOutputIdentifier = deviceManager.getDefaultMidiOutputIdentifier();
            int i = 1;

            for (auto& out : newMidiOutputs)
            {

#if JUCE_USE_WINRT_MIDI // Temporary fix till https://forum.juce.com/t/winrt-midi-output-wrong-device-names/43301/2 gets solved

                int j = 0, numInputs = newMidiInputs.size();

                while(j < numInputs)
                {
                    if (out.identifier == newMidiInputs[j].identifier)
                        break;
                    j++;
                }

                if(j < numInputs)
                    midiOutputSelector->addItem(newMidiInputs[j].name, i);
                else
#endif
                    midiOutputSelector->addItem(out.name, i);

                if (defaultOutputIdentifier.isNotEmpty() && out.identifier == defaultOutputIdentifier)
                    midiOutputSelector->setSelectedId(i, dontSendNotification);

                ++i;
            }

            currentMidiOutputs = newMidiOutputs;
        }
    }

```

![image](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/d/dc61c30826b8865938a10621f5d5eec3f40d9098.png)

---

<div class="post-metadata">

**Author:** ![yosogawa](https://avatars.discourse-cdn.com/v4/letter/y/f04885/32.png) [@yosogawa](https://forum.juce.com/u/yosogawa)\
**Post date:** [April 6, 2022, 12:55am UTC](https://forum.juce.com/t/winrt-midi-output-wrong-device-names/43301/7 "2022-04-06T00:55:29Z")

</div>

I just wanted to auto-open the MIDI input with the name and identifier of the Xml file saved by the AudioDeviceManager class in the same way as JuceDemo, so I worked around it: All I had to do was issue a dummy scan of Input / Output and it worked.

> void AudioDeviceManager::scanDevicesIfNeeded()  
> {  
> :
> 
> #if JUCE\_USE\_WINRT\_MIDI  
> auto inputs = MidiInput::getAvailableDevices();  
> auto outputs = MidiOutput::getAvailableDevices();  
> #endif  
> }

---

<div class="post-metadata">

**Author:** ![benkuper](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/benkuper/32/899_2.png) [@benkuper](https://forum.juce.com/u/benkuper)\
**Post date:** [April 6, 2022, 7:36am UTC](https://forum.juce.com/t/winrt-midi-output-wrong-device-names/43301/8 "2022-04-06T07:36:54Z")

</div>

@yosogawa I don’t really understand what you mean, these are already the functions I use to get the devices… are you also trying to get the actual names of the output or something else ?

@bcsuganthan Thank you I had not see that ! That’s a good start, but not completely working :  
The device ID’s get something like :  
{00000000-0000-0000-FFFF-FFFFFFFFFFFF}-#  
where # is the index in the list.  
But event without any external midi device, the Microsoft GS Wavetable synth is messing up the order since it has also the same identifier problem.

---

<div class="post-metadata">

**Author:** ![benkuper](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/benkuper/32/899_2.png) [@benkuper](https://forum.juce.com/u/benkuper)\
**Post date:** [April 6, 2022, 7:45am UTC](https://forum.juce.com/t/winrt-midi-output-wrong-device-names/43301/9 "2022-04-06T07:45:01Z")

</div>

Following up and adding a piece to work around the GS Wavetable synth

```auto
Array<MidiDeviceInfo> inputInfos = MidiInput::getAvailableDevices();
Array<MidiDeviceInfo> outputInfos = MidiOutput::getAvailableDevices();
	
	int idIndex = 1; //keep track of ids
	for (auto& i : outputInfos)
	{

		if (i.name == "Microsoft GS Wavetable Synth") continue; // remove this, nobody wants it anyway

		//This is a ugly hack to take name from ordered input with same identifier, because WinRT stack has a bug and is still not fixed.
		//See https://forum.juce.com/t/winrt-midi-output-wrong-device-names/43301/6

		if (i.identifier.startsWith("{00000000-0000-0000-FFFF-FFFFFFFFFFFF}"))
		{
			String expectedID = "{00000000-0000-0000-FFFF-FFFFFFFFFFFF}";
			if (idIndex > 1) expectedID += "-" + String(idIndex);

			for (auto& ii : inputInfos)
			{
				if (ii.identifier == expectedID)
				{
					i.name = ii.name;
					break;
				}
			}

			idIndex++;
		}

		addOutputDeviceIfNotThere(i);
	}

```

---

<div class="post-metadata">

**Author:** ![bcsuganthan](https://avatars.discourse-cdn.com/v4/letter/b/858c86/32.png) [@bcsuganthan](https://forum.juce.com/u/bcsuganthan)\
**Post date:** [April 6, 2022, 7:58am UTC](https://forum.juce.com/t/winrt-midi-output-wrong-device-names/43301/10 "2022-04-06T07:58:08Z")

</div>

Hi Ben,

I am also skipping the “Microsoft GS Wavetable Synth” entry here. But I’m incrementing the `idIndex ` value even if I just continue on `if (i.name == "Microsoft GS Wavetable Synth")`. I’m not sure how you implmented `addOutputDeviceIfNotThere()`, but please check if selecting the midi output in the combobox selects the corresponding desired midioutput.

---

<div class="post-metadata">

**Author:** ![yosogawa](https://avatars.discourse-cdn.com/v4/letter/y/f04885/32.png) [@yosogawa](https://forum.juce.com/u/yosogawa)\
**Post date:** [April 6, 2022, 7:58am UTC](https://forum.juce.com/t/winrt-midi-output-wrong-device-names/43301/11 "2022-04-06T07:58:34Z")

</div>

@benkuper I don’t know the exact reason  
The first getAvailableDevices () returns NULL  
The second and subsequent getAvailableDevices () will return the desired list. It’s an empirical workaround, so don’t use it if you’re not convinced. It worked in my case. (jp → en translation)

---

<div class="post-metadata">

**Author:** ![yosogawa](https://avatars.discourse-cdn.com/v4/letter/y/f04885/32.png) [@yosogawa](https://forum.juce.com/u/yosogawa)\
**Post date:** [April 26, 2022, 1:22am UTC](https://forum.juce.com/t/winrt-midi-output-wrong-device-names/43301/12 "2022-04-26T01:22:00Z")

</div>

I checked Microsoft’s WinRT MIDI sample program.

> **[MIDI - UWP applications](https://docs.microsoft.com/en-us/windows/uwp/audio-video-camera/midi)**
>
> This article shows you how to enumerate MIDI (Musical Instrument Digital Interface) devices and send and receive MIDI messages from a Universal Windows app.

It seems to get the name of the MIDI port using the C#'s ‘await’ syntax. JUCE’s WinRT getArraivableDevices() doesn’t do that. I think it is necessary to implement an asynchronous standby equivalent to C#'s await in C++ of JUCE (I have never used it, but std :: future of C++11 is similar). I would like to request improvements in JUCE.

---

<div class="post-metadata">

**Author:** ![benkuper](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/benkuper/32/899_2.png) [@benkuper](https://forum.juce.com/u/benkuper)\
**Post date:** [May 31, 2023, 6:46pm UTC](https://forum.juce.com/t/winrt-midi-output-wrong-device-names/43301/13 "2023-05-31T18:46:26Z")

</div>

is there any update on that ?

---

<div class="post-metadata">

**Author:** ![EddieL](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/eddiel/32/4602_2.png) [@EddieL](https://forum.juce.com/u/EddieL)\
**Post date:** [June 14, 2023, 1:41pm UTC](https://forum.juce.com/t/winrt-midi-output-wrong-device-names/43301/14 "2023-06-14T13:41:07Z")

</div>

Unfortunately not.

---

<div class="post-metadata">

**Author:** ![afestini](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@afestini](https://forum.juce.com/u/afestini)\
**Post date:** [May 22, 2024, 3:45pm UTC](https://forum.juce.com/t/winrt-midi-output-wrong-device-names/43301/15 "2024-05-22T15:45:59Z")

</div>

After running into the same issue with my own project and finding nothing but questions and wasting an afternoon on the lousy documentation for WinRT:  
-It is not the “wrong” name. The port name is simply a different thing than the device name.  
-You have to get the device container id from the port properties to get the device name  
-A device can have multiple in ports, so don’t just output the device name (the same name multiple times is worse than non-descript names like “midi in”, “daw in”, etc)

The quick and dirty C++ way that works fine for me:

```auto
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();
auto device_name = to_string(device.Name());

```

---

<div class="post-metadata">

**Author:** ![benkuper](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/benkuper/32/899_2.png) [@benkuper](https://forum.juce.com/u/benkuper)\
**Post date:** [June 7, 2024, 7:28am UTC](https://forum.juce.com/t/winrt-midi-output-wrong-device-names/43301/16 "2024-06-07T07:28:04Z")

</div>

Wow thank you I’ll try that when I get time (and sorry for the delayed reply) !
