melanchall / drywetmidi

.NET library to read, write, process MIDI files and to work with MIDI devices

Home Page:https://melanchall.github.io/drywetmidi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Connection issues and how to debug them?

nejdu opened this issue · comments

Hi! Thank you so much for the time you have spent on this library!

I have a problem with a MIDI controller in Windows, and I'm struggling to create a reliable test case or useful log files.

What happens is I have DryWet connect to it, and everything works fine - sometimes for several days - and then after being connected for a long time it just stops working. If I then try to disconnect and connect again I get a "Device is already in use (IN_OPENRESULT_ALLOCATED)" error, so the connection is there, it just doesn't register any input or can be properly disconnected anymore.

With nothing else to go on I'm thinking it could be a flaky USB connection, but the controller is working fine with other pieces of software so the problem is restricted to DryWet. It also only seem to happen when I'm away from it for some time, so possibly maybe it could be something in Windows that goes into sleep mode, or something being memory recycled in some way. But it's all random which makes it so hard to pin point.

The code I'm using to connect is about as straight forward as can be.

// get all devices
using Melanchall.DryWetMidi.Multimedia;
...
var devices = InputDevice.GetAll().Select(device => device.Name);

// connect to the device I want
var input = InputDevice.GetByName(name);

// start listening to input
input.EventReceived += InputDeviceReceivedMidiEvent;
input.StartEventsListening();

so nothing fancy there. And it does work fine like this, just not if I leave it connected for a an extended period of time, except not always. Grrr.

Question: is there any way to turn on more low level debug output to see what's going on here?

Hi,

Thanks for using the library!

From the description you've provided I can conclude following:

  1. The error is not related with the library. DryWetMIDI just uses appropriate Windows MIDI API to get things work.
  2. Your assumptions about something with USB or Windows itself look reasonable. My additional assumptions are issues in the device driver or maybe Windows MIDI API can silently interrupt MIDI connection for some reason.

Windows MIDI API is pretty poor. We can't even get any notifications if something went wrong. Your code is simple and fine.

If I then try to disconnect and connect again I get a "Device is already in use (IN_OPENRESULT_ALLOCATED)" error

Well, it just means what I've said before:

maybe Windows MIDI API can silently interrupt MIDI connection for some reason

As for your question:

Question: is there any way to turn on more low level debug output to see what's going on here?

My suggestions are:

  1. Try to log the time when last event was received (you can build a simple app that sends an event to virtual MIDI device every second and receive events from your app from that virtual device logging current time).
  2. Then you can look at the Windows Event Viewer for some errors or messages in system logs near the time last event was received.
  3. Also you can search on the Internet for the same error in general or regarding your device.

Thanks,
Max

Thanks! I like the idea of talking to a virtual device, I'll see what I can do. I can definitely agree that the Windows MIDI stack is... lacking. But, the controller does work fine with everything else on the same computer, it's only with the DryWet implementation I'm experiencing this problem. I'll do some more debugging on my end and see if I can find something more to go on!

Any news? Or the issue can be closed?

Sorry for the delay, I’ve had a lot on my plate lately. I will reach some conclusion on this when I return home, I promise I’ll let you know so please don’t close it :-)

After many days of testing by switching out midi controllers I've reached the conclusion that it's either faulty gear (probably) or faulty drivers (unlikely). Windows certainly isn't helping to debug the problem, but it's not an issue in DryWet since another piece of gear isn't exhibiting any problems when using the same usb cable and port. Also, at one point I had the buggy controller lose connection in another software so that convinced me that I'm on the wrong path; this has nothing to do with DryWet. So that's something at least!