libremidi
libremidi copied to clipboard
Hotplug support?
How complete is hotplug support?
You mention that callbacks for device connects/disconnects is still TODO. But does enumerating/reconnecting devices work while some devices are still in use?
You mention that callbacks for device connects/disconnects is still TODO.
yep, basically it has only been implemented when using UWP so far as it was the easiest (it provides very simple-to-use callbacks for that itself). e.g. for MME ~or ALSA~ I'm not sure that the APIs provide a way to detect new devices and one may have to resort to enumerating e.g. USB devices regularly and rescan.
But does enumerating/reconnecting devices work while some devices are still in use?
I would assume that this depends on the underlying APIs - gonna check.
I'm not sure that the APIs provide a way to detect new devices and one may have to resort to enumerating e.g. USB devices regularly and rescan
I mean in theory this could be done by the application. Unfortunately, the API of libremidi makes this extremely hard, because it uses port indices for devices enumeration which lead to time-of-check/time-of-use issues.
Let's say you detected the port count, and then compare the device names to check if a device disconnected previously was reattached. What if a device is pulled during the loop that compares device names? What if another device is attached? Can it happen that I know "device with index X is the device I want", but because the user pulls and replugs devices, index X is suddenly a valid but completely different device?
This is why there should be something used for enumeration that is unambigous, e.g. the device name or some descriptor object. I had a look at https://github.com/Boddlnagg/midir (Rust MIDI library) and it uses the latter. You can query the name from the descriptor object. If that call fails, you know that the device is not connected.
This is a feature that I would love to have with ALSA, is this something we can expect to be implemented in the near(ish) future ? I see that it is marked as WIP on the feature matrix.
I tried the callbacks with ALSA and they seem to work, though I'm not sure how to implement them to establish connections reliably.
I've implemented it for alsa-raw in addition of seq, in https://github.com/jcelerier/libremidi/tree/v4 ... last thing to fix is to change the API to use handles as mentioned above and we'll be good
done :) now the api uses a more complete descriptor to create the port - port name on ALSA & JACK, uuid on macOS, name on winmm... see https://github.com/jcelerier/libremidi/blob/v4/include/libremidi/libremidi.hpp
also hotplug is now implemented everywhere except jack (which will come soon).
just pushed a first implementation of jack observation