Skip to content

Commit

Permalink
Rework pretty-name metadata.
Browse files Browse the repository at this point in the history
The rawmidi and seqmidi pretty-name metadata now uses the same Jack1
port name as the 1st alias, without the alsa_midi: prefix.
  • Loading branch information
agraef committed Jul 27, 2023
1 parent fd4ab30 commit c3b6d56
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
10 changes: 7 additions & 3 deletions linux/alsa/alsa_rawmidi.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,20 +441,23 @@ inline int midi_port_open_jack(alsa_rawmidi_t *midi, midi_port_t *port, int type
type | JackPortIsPhysical | JackPortIsTerminal, 0);

// Like in alsa_seqmidi.c, use the Jack1 port name as alias. -ag
const char *prefix = "alsa_midi:";
const char* device_name = port->device_name;
const char* port_name = port->subdev_name;
const char *type_name = (type & JackPortIsOutput) ? "out" : "in";
if (strstr (port_name, device_name) == port_name) {
/* entire client name is part of the port name so don't replicate it */
snprintf (name,
sizeof(name),
"alsa_midi:%s (%s)",
"%s%s (%s)",
prefix,
port_name,
type_name);
} else {
snprintf (name,
sizeof(name),
"alsa_midi:%s %s (%s)",
"%s%s %s (%s)",
prefix,
device_name,
port_name,
type_name);
Expand All @@ -472,7 +475,8 @@ inline int midi_port_open_jack(alsa_rawmidi_t *midi, midi_port_t *port, int type
// we just ignore the given alias argument, and use the Jack1
// port name from above instead -ag
jack_port_set_alias(port->jack, name);
jack_port_set_default_metadata(port->jack, port->device_name);
// Pretty-name metadata is the same as alias without the prefix.
jack_port_set_default_metadata (port->jack, name+strlen(prefix));
}

return port->jack == NULL;
Expand Down
11 changes: 7 additions & 4 deletions linux/alsa/alsa_seqmidi.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ port_t* port_create(alsa_seqmidi_t *self, int type, snd_seq_addr_t addr, const s
goto failed;

// First alias: Jack1-compatible port name. -ag
const char *prefix = "alsa_midi:";
const char *device_name = snd_seq_client_info_get_name(client_info);
const char* port_name = snd_seq_port_info_get_name (info);
const char* type_name = jack_caps & JackPortIsOutput ? "out" : "in";
Expand All @@ -520,13 +521,15 @@ port_t* port_create(alsa_seqmidi_t *self, int type, snd_seq_addr_t addr, const s
/* entire client name is part of the port name so don't replicate it */
snprintf (port->name,
sizeof(port->name),
"alsa_midi:%s (%s)",
"%s%s (%s)",
prefix,
port_name,
type_name);
} else {
snprintf (port->name,
sizeof(port->name),
"alsa_midi:%s %s (%s)",
"%s%s %s (%s)",
prefix,
device_name,
port_name,
type_name);
Expand All @@ -540,7 +543,8 @@ port_t* port_create(alsa_seqmidi_t *self, int type, snd_seq_addr_t addr, const s
}

jack_port_set_alias (port->jack_port, port->name);
jack_port_set_default_metadata (port->jack_port, device_name);
// Pretty-name metadata is the same as first alias without the prefix.
jack_port_set_default_metadata (port->jack_port, port->name+strlen(prefix));

// Second alias: Strip the alsa_midi prefix, so that devices appear
// under their ALSA names. Use the ALSA port names (without device
Expand All @@ -562,7 +566,6 @@ port_t* port_create(alsa_seqmidi_t *self, int type, snd_seq_addr_t addr, const s
}

jack_port_set_alias (port->jack_port, port->name);
jack_port_set_default_metadata (port->jack_port, device_name);

if (type == PORT_INPUT)
err = alsa_connect_from(self, port->remote.client, port->remote.port);
Expand Down

0 comments on commit c3b6d56

Please sign in to comment.