From 01558bb9e9c74295f99cbe2f113a73a8a58a52f2 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 26 Aug 2024 13:33:05 +0200 Subject: [PATCH] alsa: improve midi port.name The port.name should be something fairly unique and stable per node that is also human readable. Make sure we include the ALSA client name and port name in the port.name but try to avoid double client names when the client name is already in the port name. There is also a api.alsa.disable-longname that is now set to true by default. Setting this to false will include the unique client and port id to the port.name. This should make the midi port names much more presentable and more in line with JACK1. --- spa/plugins/alsa/alsa-seq-bridge.c | 62 +++++++++++------------------- 1 file changed, 23 insertions(+), 39 deletions(-) diff --git a/spa/plugins/alsa/alsa-seq-bridge.c b/spa/plugins/alsa/alsa-seq-bridge.c index cd04e4742..f85b41e28 100644 --- a/spa/plugins/alsa/alsa-seq-bridge.c +++ b/spa/plugins/alsa/alsa-seq-bridge.c @@ -24,12 +24,13 @@ #define DEFAULT_DEVICE "default" #define DEFAULT_CLOCK_NAME "clock.system.monotonic" +#define DEFAULT_DISABLE_LONGNAME true static void reset_props(struct props *props) { strncpy(props->device, DEFAULT_DEVICE, sizeof(props->device)); strncpy(props->clock_name, DEFAULT_CLOCK_NAME, sizeof(props->clock_name)); - props->disable_longname = 0; + props->disable_longname = DEFAULT_DISABLE_LONGNAME; } static int impl_node_enum_params(void *object, int seq, @@ -228,9 +229,11 @@ static void emit_port_info(struct seq_state *this, struct seq_port *port, bool f if (port->info.change_mask) { struct spa_dict_item items[6]; uint32_t n_items = 0; - int id; + int card_id; snd_seq_port_info_t *info; snd_seq_client_info_t *client_info; + const char *client_name, *port_name, *dir, *pn; + char prefix[32] = ""; char card[8]; char name[256]; char path[128]; @@ -245,59 +248,40 @@ static void emit_port_info(struct seq_state *this, struct seq_port *port, bool f snd_seq_get_any_client_info(this->sys.hndl, port->addr.client, client_info); - int card_id; + card_id = snd_seq_client_info_get_card(client_info); + client_name = snd_seq_client_info_get_name(client_info); + port_name = snd_seq_port_info_get_name(info); + dir = port->direction == SPA_DIRECTION_OUTPUT ? "capture" : "playback"; - // Failed to obtain card number (software device) or disabled - if (this->props.disable_longname || (card_id = snd_seq_client_info_get_card(client_info)) < 0) { - snprintf(name, sizeof(name), "%s:(%s_%d) %s", - snd_seq_client_info_get_name(client_info), - port->direction == SPA_DIRECTION_OUTPUT ? "capture" : "playback", - port->addr.port, - snd_seq_port_info_get_name(info)); - } else { - char *longname; - if (snd_card_get_longname(card_id, &longname) == 0) { - snprintf(name, sizeof(name), "%s:(%s_%d) %s", - longname, - port->direction == SPA_DIRECTION_OUTPUT ? "capture" : "playback", - port->addr.port, - snd_seq_port_info_get_name(info)); - free(longname); - } else { - // At least add card number to be distinct - snprintf(name, sizeof(name), "%s %d:(%s_%d) %s", - snd_seq_client_info_get_name(client_info), - card_id, - port->direction == SPA_DIRECTION_OUTPUT ? "capture" : "playback", - port->addr.port, - snd_seq_port_info_get_name(info)); - } - } + if (!this->props.disable_longname) + snprintf(prefix, sizeof(prefix), "[%d:%d] ", + port->addr.client, port->addr.port); + + pn = port_name; + if (spa_strstartswith(pn, client_name)) + pn += strlen(client_name); + + snprintf(name, sizeof(name), "%s%s%s (%s)", prefix, + client_name, pn, dir); clean_name(name); snprintf(stream, sizeof(stream), "client_%d", port->addr.client); clean_name(stream); snprintf(path, sizeof(path), "alsa:seq:%s:%s:%s_%d", - this->props.device, - stream, - port->direction == SPA_DIRECTION_OUTPUT ? "capture" : "playback", - port->addr.port); + this->props.device, stream, dir, port->addr.port); clean_name(path); - snprintf(alias, sizeof(alias), "%s:%s", - snd_seq_client_info_get_name(client_info), - snd_seq_port_info_get_name(info)); + snprintf(alias, sizeof(alias), "%s:%s", client_name, port_name); clean_name(alias); - items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_FORMAT_DSP, "32 bit raw UMP"); items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_OBJECT_PATH, path); items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_PORT_NAME, name); items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_PORT_ALIAS, alias); items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_PORT_GROUP, stream); - if ((id = snd_seq_client_info_get_card(client_info)) != -1) { - snprintf(card, sizeof(card), "%d", id); + if (card_id != -1) { + snprintf(card, sizeof(card), "%d", card_id); items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_API_ALSA_CARD, card); } port->info.props = &SPA_DICT_INIT(items, n_items);