danomatika / ofxMidi

(maintained) Midi addon for openFrameworks
Other
262 stars 72 forks source link

How to detect usb MIDI controller disconnect? #78

Closed antoniomechas closed 10 months ago

antoniomechas commented 3 years ago

Hello, I'm using an AKAI APC mini controller with an application made in OF to control the light in some performers LED ligths in the street. I'm on the go with a computer inside a backpack while walking. Sometimes, due to the movement, the USB cable of the controller unplugs and plugs again in the computer, so, I loose the MIDI controller and need to restart the application (stop walking, take the computer out of the backpack, etc) Is there a way to detect that the OF application lost the controller and try to open de port again? I tried to use the isOpen() method, but is returning true even if the controller has been disconnected. Using windows 10 and OF 0.11.0 Thanks! Antonio.

danomatika commented 3 years ago

I believe newer versions of RtMidi may support "hot plugging." If so, the device connect/disconnect notifications used on iOS could also be used on desktop.

danomatika commented 3 years ago

Can you try the rtmidi-error-cb branch? It should print an error message when something goes wrong, ie. unexpected disconnect. If that works, then the port could be closed and a message sent which you could handle by reopening the port after a delay, say 2 seconds.

Note: On macOS, I don't see an error printed when unplugging a USB MIDI keyboard and I'm able to plug it back in and the midiInputExample keeps working. This may be a difference with how MIDI is handled by the system, hence my need for you to test on yours.

danomatika commented 2 years ago

...any updates on this?

danomatika commented 10 months ago

Closing due to lack of activity.