Arduino Due MIDIUSB: Lost messages issue

Hi there,

I have built a musical instrument that works a lot like the one sketched in this very good tutorial (thanks, btw):

https://docs.arduino.cc/tutorials/generic/midi-device/

That generally works, but I stumble across this very issue:

I can verify the observations and tests in the last post there - some outbound messages are simply lost (I am positively sure they are sent via MidiUSB.sendMIDI(), so they must get lost on the way to the wire).

Looking through the code in MIDIUSB/src/MIDIUSB.cpp at master · arduino-libraries/MIDIUSB · GitHub , I find that it calls USB_Send() but unfortunately does not propagate the result to the caller (why?), so on the application level, I can not react to USB side errors.

As outlined in this issue: Hardcoded timeout in USB_Send · Issue #478 · arduino/ArduinoCore-avr · GitHub, there is a hardcoded timeout of 250ms in USB_Send(). My suspicion is that the timeout kicks in and the messages are dropped. Unfortunately, the proposed configurability of the timeout has never made it into the libs.

I have tried short circuiting the MidiUSB.sendMIDI() call and go directly to the USB driver to find the return value but can not access the Tx end point.

So I guess my question at hand is: Can you point me to a tutorial to rebuild the MidiUSB lib so I can make further investigations down the chain?

Thanks so much!

More info: There is a related open issue here:

Missing USB packets (Midi) - Hardware / Arduino Due - Arduino Forum

However, that person is writing a MIDI host, whereas I code for a MIDI device (meaning in other words that I do exclusive MIDI output whereas they exclusively read and process inbound MIDI messages). Interesting to see that the problem affects both sides...

The answer must be in

#include "api/PluggableUSB.h"

i would say.

Thanks, but I had already tried that (will agree that that should give me access), but all I get is "no such file or directory."

I found it on my W10 laptop without to much issue searching for PluggableUSB.h"

i found it at

C:\Users\username\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.7\cores\arduino\api

But looking at the file (and the.cpp) i did not get much wiser unfortunately.