mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-01 22:58:50 -04:00
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.
This commit is contained in:
parent
2ef3ced380
commit
01558bb9e9
1 changed files with 23 additions and 39 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue