Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Paul Davis <paul@linuxaudiosystems.com>
Cc: Takashi Iwai <tiwai@suse.de>, linux-sound@vger.kernel.org
Subject: Re: ALSA USB MIDI port names are poorly constructed and truncate iJACK names
Date: Wed, 23 Apr 2025 08:45:51 +0200	[thread overview]
Message-ID: <871ptjl6jk.wl-tiwai@suse.de> (raw)
In-Reply-To: <CAFa_cKm3ded=1+3-i5BYjTa8JTeqZcGkGhakgQWfqPy_H=NBBg@mail.gmail.com>

On Tue, 22 Apr 2025 19:31:59 +0200,
Paul Davis wrote:
> 
> This patch was developed using the Debian 6.12.12 kernel source, but I
> believe it works without changes for current git.
> 
> The approach taken is to always look for the iProduct name
> (umidi->card->shortname) in the iJACK name (jack_name). If not found,
> the code path is unchanged. If found, a different string format is
> used to create the port name, using only the jack name. Note that
> since finding the product name in the jack name implies the jack name
> is not default_jack_name, there is never any reason to use "number" in
> constructing the port name.
> 
> This generates the expected port names for several USB MIDI devices
> here, some of which have "product name in jack name" and some which do
> not:
> 
> % aplaymidi -l
>  Port    Client name                      Port name
>  14:0    Midi Through                     Midi Through Port-0
>  16:0    Scarlett 18i20 USB               Scarlett 18i20 USB MIDI 1
>  36:0    Keystation 88                    Keystation 88 MIDI 1
>  40:0    Launchkey MK4 49                 Launchkey MK4 49 MIDI In
>  40:1    Launchkey MK4 49                 Launchkey MK4 49 DAW In
>  44:0    MidiSport 2x2                    MidiSport 2x2 MIDI 1
>  44:1    MidiSport 2x2                    MidiSport 2x2 MIDI 2
> 
> 
> Signed-off-by: Paul Davis <paul@linuxaudiosystems.com>
> 
> --- midi.c.orig    2025-04-22 11:20:30.192338737 -0600
> +++ midi.c    2025-04-22 11:20:47.373155820 -0600
> @@ -1817,10 +1817,18 @@ static void snd_usbmidi_init_substream(s
>      }
> 
>      port_info = find_port_info(umidi, number);
> -    name_format = port_info ? port_info->name :
> -        (jack_name != default_jack_name  ? "%s %s" : "%s %s %d");
> -    snprintf(substream->name, sizeof(substream->name),
> -         name_format, umidi->card->shortname, jack_name, number + 1);
> +
> +    if (strncmp (umidi->card->shortname, jack_name, strlen
> (umidi->card->shortname)) != 0) {
> +        name_format = port_info ? port_info->name :
> +            (jack_name != default_jack_name  ? "%s %s" : "%s %s %d");
> +        snprintf(substream->name, sizeof(substream->name),
> +                 name_format, umidi->card->shortname, jack_name, number + 1);
> +    } else {
> +        /* The manufacturer included the iProduct name in the jack
> name, do not use both */
> +        name_format = port_info ? port_info->name : "%s";
> +        snprintf(substream->name, sizeof(substream->name),
> name_format, jack_name);
> +    }

Thanks for the patch.

However, dropping the number suffix will break the uniqueness.
For example, in your case above, MidiSport 2x2 will have two identical
port names, I suppose?

IMO, we should keep adding the suffix number unless the uniqueness is
guaranteed instead of blindly dropping.  Admittedly the current code
isn't in the best form and this also needs more modification, too.

Also, the pre-defined port names defined in snd_usb_midi_port_info[]
have the format like "%s Synth", too, and those should be adjusted, as
well.

Last but not least, after we get a final form, could you try to submit
a patch in the proper format as defined in
  Documentation/process/submitting-patches.rst?


thanks,

Takashi

  reply	other threads:[~2025-04-23  6:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-22 14:31 ALSA USB MIDI port names are poorly constructed and truncate iJACK names Paul Davis
2025-04-22 14:46 ` Takashi Iwai
2025-04-22 17:31   ` Paul Davis
2025-04-23  6:45     ` Takashi Iwai [this message]
2025-04-25 14:39       ` Paul Davis
2025-04-25 15:10         ` Takashi Iwai
2025-04-28 20:36           ` Paul Davis
2025-04-29 18:35             ` Takashi Iwai
2025-04-28 21:15           ` Paul Davis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871ptjl6jk.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=linux-sound@vger.kernel.org \
    --cc=paul@linuxaudiosystems.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox