Commit 92934c1
Fix ALSA hardware volume detection for CARD=<name> and bare sysdefault devices (#279)
## Summary
- `parse_alsa_card()` in `sendspin/alsa_volume.py` only recognized
PortAudio's numeric `hw:N,M` card annotation. Devices selected via
`--audio-device` using the `plughw:CARD=<name>,DEV=<n>` /
`dmix:CARD=<name>,DEV=<n>` convention — often needed because raw
`hw:N,M` bypasses ALSA's `plug`/`dmix` conversion layer and fails to
open for playback at all — weren't recognized, so hardware volume
control silently fell back to software volume even when a real mixer
element existed.
- `parse_alsa_card()` now also extracts the card's string name from a
`CARD=<name>` pattern, and
`find_mixer_element()`/`AlsaVolumeController`/`async_check_alsa_available()`
were generalized to accept `int | str` card identifiers. Confirmed via
the `amixer` source that `-c` resolves either a numeric index or a card
name through `snd_card_get_index()` internally, so passing the name
straight through works.
- Also handles PortAudio's bare `sysdefault`/`default` device
enumeration (no card info at all in the name), which turned up in
real-world testing on an ODROID-N2. Since the string carries no card
identity, this cross-references `aplay -L`'s fully-qualified hints (e.g.
`sysdefault:CARD=ODROIDN2`) to recover the card, and only resolves when
exactly one hint matches — on a system with multiple cards each exposing
their own default hint, it backs off to software volume rather than
guessing which one is meant.
## Test plan
- [x] `uv run ruff check --fix .`
- [x] `uv run ruff format .`
- [x] `uv run mypy sendspin` — no issues
- [x] `uv run pytest tests/ -q` — 150 passed (11 new tests covering
`CARD=<name>` parsing, the plughw/dmix discovery flow, and the
bare-sysdefault resolution including the ambiguous multi-card and
no-hint cases)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>1 parent 22b9ff3 commit 92934c1
2 files changed
Lines changed: 177 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
37 | 43 | | |
38 | | - | |
39 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
40 | 71 | | |
41 | 72 | | |
42 | 73 | | |
| 74 | + | |
43 | 75 | | |
44 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
45 | 85 | | |
46 | 86 | | |
47 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
48 | 93 | | |
49 | 94 | | |
50 | | - | |
| 95 | + | |
51 | 96 | | |
52 | 97 | | |
53 | 98 | | |
| |||
75 | 120 | | |
76 | 121 | | |
77 | 122 | | |
78 | | - | |
| 123 | + | |
79 | 124 | | |
80 | 125 | | |
81 | 126 | | |
| |||
100 | 145 | | |
101 | 146 | | |
102 | 147 | | |
103 | | - | |
| 148 | + | |
104 | 149 | | |
105 | 150 | | |
106 | 151 | | |
107 | 152 | | |
108 | | - | |
| 153 | + | |
109 | 154 | | |
110 | 155 | | |
111 | 156 | | |
| |||
119 | 164 | | |
120 | 165 | | |
121 | 166 | | |
122 | | - | |
| 167 | + | |
123 | 168 | | |
124 | 169 | | |
125 | 170 | | |
| |||
128 | 173 | | |
129 | 174 | | |
130 | 175 | | |
131 | | - | |
| 176 | + | |
132 | 177 | | |
133 | 178 | | |
134 | 179 | | |
135 | 180 | | |
136 | | - | |
| 181 | + | |
137 | 182 | | |
138 | 183 | | |
139 | 184 | | |
140 | 185 | | |
141 | 186 | | |
142 | | - | |
| 187 | + | |
143 | 188 | | |
144 | 189 | | |
145 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
146 | 195 | | |
147 | 196 | | |
148 | 197 | | |
149 | 198 | | |
150 | 199 | | |
| 200 | + | |
| 201 | + | |
151 | 202 | | |
152 | 203 | | |
153 | 204 | | |
| |||
165 | 216 | | |
166 | 217 | | |
167 | 218 | | |
168 | | - | |
| 219 | + | |
169 | 220 | | |
170 | 221 | | |
171 | 222 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
65 | 79 | | |
66 | 80 | | |
67 | 81 | | |
| |||
202 | 216 | | |
203 | 217 | | |
204 | 218 | | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
205 | 237 | | |
206 | 238 | | |
207 | 239 | | |
| |||
355 | 387 | | |
356 | 388 | | |
357 | 389 | | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
358 | 470 | | |
359 | 471 | | |
360 | 472 | | |
| |||
0 commit comments