Skip to content

seq: snd_seq_parse_address() accepts port name - #528

Open
thanks4opensource wants to merge 1 commit into
alsa-project:masterfrom
thanks4opensource:thanks4opensource_parse_address
Open

thanks4opensource wants to merge 1 commit into
alsa-project:masterfrom
thanks4opensource:thanks4opensource_parse_address

Conversation

@thanks4opensource

Copy link
Copy Markdown

This pull requests allows snd_seq_parse_address() to accept port names as well as port id numbers. This improves the usability of aconnect, particularly within shell scripts where port names are more readable/self-documenting than port numbers, and are also more robust as client updates are more likely to reorder/renumber ports than to change their names.

The functionality could be added within aconnect itself, but doing so inside alsa-lib makes it available for all programs, e.g. ones that use snd_seq_subscribe_port(),etc to connect themselves to other clients.

The new code is almost completely compatible with existing use-cases, with one exception: If passed a non-numeric port, a bug in the current snd_seq_parse_address() sets 0 for the port id/number without returning an error. This causes aconnect to silently make an incorrect connection or fail with a confusing error message.

Consider the following example:

$ aconnect -oil
client 128: 'arbitrary_client' [type=user,pid=837984]
    0 'output          '
    1 'input           '
client 129: 'synthesizer' [type=user,pid=837982]
    0 'outside_speaker_input'
    1 'headphone_input '
client 130: 'virtual_piano' [type=user,pid=837983]
    0 'output          '

Until I looked at the source code, I never understood:

$ aconnect 130 128:100
Connection failed (Invalid argument)
$ aconnect 130 128:input
Connection failed (Operation not permitted)
$ aconnect 130 128:1 
$ aconnect -oil     
client 128: 'arbitrary_client' [type=user,pid=837984]
    0 'output          '
    1 'input           '
	Connected From: 130:0
client 129: 'synthesizer' [type=user,pid=837982]
    0 'outside_speaker_input'
    1 'headphone_input '
client 130: 'virtual_piano' [type=user,pid=837983]
    0 'output          '
	Connecting To: 128:1

If the error message had been "Invalid argument" instead of "Operation not permitted" (why can't I connect an output to an input?) it would have been less of a mystery.

Equally confusing, and potentially dangerous:

$ aconnect -x
$ aconnect 130 129:headphone_input
$ aconnect -oil                   
client 128: 'arbitrary_client' [type=user,pid=838343]
    0 'output          '
    1 'input           '
client 129: 'synthesizer' [type=user,pid=838347]
    0 'outside_speaker_input'
	Connected From: 130:0
    1 'headphone_input '
client 130: 'virtual_piano' [type=user,pid=838350]
    0 'output          '
	Connecting To: 129:0

That's a somewhat contrived example, but imagine it's 3 AM and you want to practice some loud heavy metal keyboard riffs. Suddenly you're in big trouble with your neighbors. ;)

This pull request "does the right thing" in all cases. My general policy is to never change existing behavior, but in this case the "silently convert to port 0" is at best an undocumented feature, and at worst an undeniable bug. Anything relying on it really should be fixed.

The code maintains current feature of accepting a prefix of a client name ("FLU" instead of "FLUID Synth"). If accepts any substring for port names because several common ALSA clients have long port names which differ only at their ends ("alt" for "Synth input alternate"). In both cases an exact name match overrides a prefix/substring.

The branch includes test/address.c which extensively validates snd_seq_parse_address() (4349 tests at latest count), including checking returned errors in cases of nonexistent client or port names, out of range client/port id numbers, etc. As necessitated by the sequencer API, and as per the current code, it requires a non-NULL snd_seq_t* argument to handle names but will parse purely numeric ids without. It currently does not check whether there are existing clients/ports matching the requested client/port numbers.

I apologize for completely rewriting snd_seq_parse_address(), but the existing version parsed the port string before the client, including multiple early returns from the function. The client is required for searching port names, and the code would have been a mess if the order of operations had been retained. Of course I also believe the new version, particularly the parsing of the input string into client and port, is simpler and more readable.

Please consider merging this pull request. Thank you.

@github-actions github-actions Bot added the signed off by Missing Signed-off-by: line. label Oct 3, 2026
@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

⚠️ Signed-off-by Validation Issues

The following commits have issues with their Signed-off-by lines:

Commit e97154f

Author: thanks4opensource 31165662+thanks4opensource@users.noreply.github.com
Committer: thanks4opensource 31165662+thanks4opensource@users.noreply.github.com
Signed-off-by lines:

Issues:

Each commit must include a proper Signed-off-by: Your Name <your.email@example.com> line. Additionally, both the commit author and committer emails must either match one of the Signed-off-by lines or use a valid (non-anonymous) email address.

Tip: You can inspect your commits locally using:

git log --format=fuller

Missing correct Signed-off-by line

This pull request has commits that are missing proper Signed-off-by lines or use invalid email addresses.

Requirements:

  • Each commit must include at least one Signed-off-by: Your Name <your.email@example.com> line
  • Commit author email must appear in at least one Signed-off-by line
  • Commit committer email must appear in at least one Signed-off-by line (if not a GitHub bot)
  • Multiple Signed-off-by lines are allowed for co-authored commits
  • Anonymous GitHub emails (like @users.noreply.github.com) are not allowed
  • The Signed-off-by line indicates that you agree to the Developer Certificate of Origin (DCO)

How to fix:

# 1. Configure your git identity first (if needed):
git config user.name "Your Name"
git config user.email "your.email@example.com"

# 2. For adding Signed-off-by to the last commit:
git commit --amend --signoff

# 3. For adding Signed-off-by to multiple commits:
git rebase -i HEAD~N --signoff

# 4. If commit author email is wrong, fix it:
# For the last commit only:
git commit --amend --author="Your Name <your.email@example.com>" --signoff

# For multiple commits:
git rebase -i HEAD~N
# Mark commits as 'edit', then for each:
git commit --amend --author="Your Name <your.email@example.com>" --signoff
git rebase --continue

# 5. For co-authored commits, add multiple Signed-off-by lines manually:
git commit --amend
# Then add in the commit message:
# Signed-off-by: Author One <author1@example.com>
# Signed-off-by: Author Two <author2@example.com>

# 6. Finally, force push your changes:
git push --force-with-lease

Reference: Developer Certificate of Origin

…r-or-name

Previously only client-number-or-name:port-number. Accepts prefix for
client-name, substring for port-name. Exact name match overrides in
both cases. Includes new test/address.c to validate old and new
functionality.

Signed-off-by: thanks4opensource <31165662+thanks4opensource@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

signed off by Missing Signed-off-by: line.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant