0

When using the UWP MIDI API with a physical MIDI device, the app hangs on exit and cannot be forcefully terminated neither from command line nor from the Task Manager.

This happens for all UWP apps that use MIDI, including the official example from MSDN, without modifications.

I have raised an issue on GitHub about this, but it does not seem to be a new problem. MIDI is supposedly broken since 2014.

Is there a way to circumvent this problem in UWP through other means? I'm writing in C#, but I am fluent in C++ and could use lower-level APIs, if they existed. I only need to get MIDI input from a selected MIDI device (keyboard).

I also tried using the winmm.dll as suggested in the related post (Getting signals from a MIDI port in C#), but this does not work for me. The midiInGetNumDevs() method returns 0 when used from a UWP app.

I am using M-Audio Fast Track USB sound card (connected via USB) and an M-Audio 88es Keystation MIDI Keyboard (connected via USB). I haven't had problems in desktop applications.

I have discovered a partial workaround where I move the deallocation code to the App Suspending event handler instead of having it in a destructor. However, the problem still arises when a device is unplugged during app's lifetime. If the MIDI device is plugged in while the app is running, the app closes without problems (with the workaround). If the MIDI device is plugged in before the app is run and remains plugged in while the app is running, the app closes without problems (with the workaround). Only if the device is plugged out while the app is running will the app hang on close, regardless of whether the deallocation code is done in the destructor or in the App Suspending handler.

Igor Ševo
  • 5,459
  • 3
  • 35
  • 80
  • That's strange. I used UWP MIDI API and had no issues. Try to run you app on the other machine using windows provided default midi device – Jet Chopper Jan 28 '19 at 18:46
  • Everything seems to work fine until the app is closed. I receive events and can process them, but when I close the app (either by clicking close or by trying to end the process), the app hangs. – Igor Ševo Jan 28 '19 at 18:50
  • Really strange that winmm not working for you. Can you try [DryWetMIDI](https://github.com/melanchall/drywetmidi) to capture MIDI data from an input device (see [Input device](https://github.com/melanchall/drywetmidi/wiki/Input-device) article for details)? – Maxim Jan 30 '19 at 17:17
  • Could you share more detail. What version of the OS is the customer using? What type of MIDI device are the using/what is the end point device? What MIDI interface are they using? – Nico Zhu Feb 14 '19 at 02:07
  • @NicoZhu-MSFT I added more details and a partial workaround. – Igor Ševo Feb 15 '19 at 11:40
  • @IgorŠevo, Please share more about your sounds card driver, we are testing the sounds card driver to make sure it’s universal. – Nico Zhu Feb 28 '19 at 06:23

1 Answers1

0

I’m unable to reproduce this issue. I believe it could be related to the audio card’s driver.

Using the sample you mentioned, https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/MIDI • App did not hang when I closed it. • I was able to remove the cable during app lifecycle, without issue. I was still able to send and receive messages after reconnecting. • I was able to plug in the device mid-lifecycle, without issue. I was still able to send and receive messages.

Although it's currently working from desktop, it’s required to be “universal” for it to work well in UWP. Is the audio card driver universal?

In our developing drivers doc, we see a note to Use the InfVerif tool to verify that your driver package's INF file is universal. https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/infverif. In the app developer documentation, I see a note to test the device metadata. https://learn.microsoft.com/en-us/windows-hardware/drivers/devapps/step-4--test-device-metadata

Additional documentation related to your question: Building UWP device apps
https://learn.microsoft.com/en-us/windows-hardware/drivers/devapps/the-workflow

Test the device metadata for your UWP device app
https://learn.microsoft.com/en-us/windows-hardware/drivers/devapps/step-4--test-device-metadata

Getting Started with Universal Windows drivers
https://learn.microsoft.com/en-us/windows-hardware/drivers/develop/getting-started-with-universal-drivers

MIDI sample https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/MIDI

Releasing resources in app suspend
https://learn.microsoft.com/en-us/windows/uwp/launch-resume/suspend-an-app#release-resources

Use Dispose to suppress finalization NOTE: depending on a finalizer will keep resources in memory longer than necessary. They won’t be released until a full GC is performed or when the process exits.
https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-dispose

David Hollowell - MSFT
  • 1,065
  • 2
  • 9
  • 18