diff options
author | Robin Gareus <robin@gareus.org> | 2019-05-08 19:58:05 +0200 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2019-05-08 19:58:53 +0200 |
commit | 4185ad80a6f884990f79b60d26efe5bfe4f645c8 (patch) | |
tree | 35371da0fe4661126d2d6941024f6ed05be124a7 | |
parent | ba41ac3cecca0a449e1a1ee44b4a7d9bf01d45d7 (diff) |
Prepare for Ardour/ALSA multiple identical MIDI devices
The engine setup identifies devices by name (device list is a map<>
with the device-name as key). To support multiple devices with the
same name, the name needs to be unique.
So far this is achieved by simply adding a number suffix starting with
the 2nd device (this allows to re-use configurations).
Ideally we'd use UUIDs or unique device IDs to handle this, and also
somehow clarify which device is which...
-rw-r--r-- | libs/ardouralsautil/devicelist.cc | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/libs/ardouralsautil/devicelist.cc b/libs/ardouralsautil/devicelist.cc index c2d83aab85..29aeb996a1 100644 --- a/libs/ardouralsautil/devicelist.cc +++ b/libs/ardouralsautil/devicelist.cc @@ -94,6 +94,29 @@ ARDOUR::get_alsa_audio_device_names (std::map<std::string, std::string>& devices } } +static void +insert_unique_device_name (std::map<std::string, std::string>& devices, std::string const& card_name, std::string const& devname) +{ + std::pair<std::map<std::string, std::string>::iterator, bool> rv; + char cnt = '1'; + std::string cn = card_name; + /* Add numbers first this is be independent of physical ID (sequencer vs rawmidi). + * If this fails (>= 10 devices) add the device-name for uniqness + * + * XXX: Perhaps this is a bad idea, and `devname` should always be added if + * there is more than one device with the same name. + */ + do { + rv = devices.insert (std::make_pair (cn, devname)); + cn = card_name + " (" + cnt + ")"; + } while (!rv.second && ++cnt <= '9'); + + if (!rv.second) { + rv = devices.insert (std::make_pair (card_name + " (" + devname + ")", devname)); + assert (rv.second == true); + } +} + void ARDOUR::get_alsa_rawmidi_device_names (std::map<std::string, std::string>& devices) { @@ -156,7 +179,7 @@ ARDOUR::get_alsa_rawmidi_device_names (std::map<std::string, std::string>& devic if (sub < subs_out) card_name += "O"; card_name += ")"; - devices.insert (std::make_pair (card_name, devname)); + insert_unique_device_name (devices, card_name, devname); break; } else { devname = "hw:"; @@ -171,7 +194,7 @@ ARDOUR::get_alsa_rawmidi_device_names (std::map<std::string, std::string>& devic if (sub < subs_in) card_name += "I"; if (sub < subs_out) card_name += "O"; card_name += ")"; - devices.insert (std::make_pair (card_name, devname)); + insert_unique_device_name (devices, card_name, devname); } } } @@ -226,7 +249,7 @@ ARDOUR::get_alsa_sequencer_names (std::map<std::string, std::string>& devices) devname = PBD::to_string(snd_seq_port_info_get_client (pinfo)); devname += ":"; devname += PBD::to_string(snd_seq_port_info_get_port (pinfo)); - devices.insert (std::make_pair (card_name, devname)); + insert_unique_device_name (devices, card_name, devname); } } snd_seq_close (seq); |