Skip to content

op/mixer_alsa: alsamixer's volume scale; setting mixer control like aplay does it - #1445

Merged
flyingmutant merged 2 commits into
cmus:masterfrom
ihy123:alsa
Sep 27, 2025
Merged

flyingmutant merged 2 commits into
cmus:masterfrom
ihy123:alsa

Conversation

@ihy123

@ihy123 ihy123 commented Aug 24, 2025

Copy link
Copy Markdown
Contributor

I'm spamming at this point, but this is pretty useful :)

Alsamixer and i3status and aplay (with -M flag) display so-called 'mapped volume' by default (see man alsamixer "VOLUME MAPPING"), so I added it to alsa mixer plugin. mixer.alsa.mapped_volume config option turns it on. It's enabled by default because Alsamixer and i3status do it, I think its ok.

Comment thread op/mixer_alsa.c Resolved
@pgaskin

pgaskin commented Aug 24, 2025

Copy link
Copy Markdown
Member

I'm spamming at this point, but this is pretty useful :)

Keep doing it, as it's very good spam :p

@ihy123

ihy123 commented Aug 25, 2025

Copy link
Copy Markdown
Contributor Author

A little more comments on the changes made.

"Setting mixer control like aplay does it" means that now you can set mixer.alsa.channel to not only Master, but also Master,0 or 'Front Mic',1 and the code is cleaner than previous version.

Seems like getting/setting volume for left/right channels works fine even if the control is mono, because SND_MIXER_SCHN_MONO is just an alias for SND_MIXER_SCHN_FRONT_LEFT. But I'm not 100% sure that mono need not be handled separately (it works as is though), or if controls for more than 2 channels are possible...

@pgaskin pgaskin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work fine with ALSA on PipeWire, code looks fine.

@flyingmutant

Copy link
Copy Markdown
Member

What is the reason for c710412? I understand the intention to have cleaner internal logic, but this has the potential of breakage, which we should avoid. I don't want people upgrading cmus to have to dig through changelogs to find how to make music work again.

@ihy123

ihy123 commented Sep 8, 2025

Copy link
Copy Markdown
Contributor Author

What is the reason for c710412? I understand the intention to have cleaner internal logic, but this has the potential of breakage, which we should avoid. I don't want people upgrading cmus to have to dig through changelogs to find how to make music work again.

I'm not sure how to solve this. My problem with silently falling back to 'Master' is that it's done silently, so if you specify an incorrect control name, 'Master' will be assumed but you will never be notified because alsa_mixer_open() will be successful.

@ihy123

ihy123 commented Sep 9, 2025

Copy link
Copy Markdown
Contributor Author

Old behavior:
incorrect control name -> 'Master' is assumed and its volume is displayed in UI
New behavior:
incorrect control name -> error (no volume in UI)

I personally like the new behavior more. For example, amixer assumes device name to be 'default' if it's unspecified, but leaving control name unspecified is an error.

Right now if I understand correctly assuming control name is needed to try out different defaults: mixer.alsa.channel is 'PCM' by default, but if it doesn't exist we try 'Master'.

IMO it's better to do what amixer does:
mixer.alsa.device is unspecified -> 'default' is assumed
mixer.alsa.device is incorrect -> error
mixer.alsa.channel is incorrect or unspecified -> error, no assumptions

@pgaskin, what do you think about the last paragraph?

Also why is mixer.alsa.channel 'PCM' by default, why not 'Master'?

All this uncertainty made me think if such feature as controlling system volume even belongs in a music player. I think it doesn't. And that is the reason why it's so hard to decide anything

@pgaskin

pgaskin commented Sep 10, 2025

Copy link
Copy Markdown
Member

what do you think about the last paragraph

I do like explicit errors in general, but I don't have a strong opinion about this particular case.

Also why is mixer.alsa.channel 'PCM' by default, why not 'Master'?

IDK, I don't use ALSA, and this plugin predates me. I found https://unix.stackexchange.com/a/243698 though.

All this uncertainty made me think if such feature as controlling system volume even belongs in a music player. I think it doesn't. And that is the reason why it's so hard to decide anything

A few thoughts:

  • Some older players and sound systems (older windows, pulse) used flat volumes, where increasing player volume past the current system volume also raises the system volume. Many (including me) dislike this.
  • Most cmus output plugins control the per-app volume if supported.
  • There is soft volume support in cmus.
  • It's probably best to just do something sane/usable by default, and let the user use soft_volume if desired (as it is currently).

@ihy123

ihy123 commented Sep 10, 2025

Copy link
Copy Markdown
Contributor Author

IDK, I don't use ALSA, and this plugin predates me. I found https://unix.stackexchange.com/a/243698 though.

Most guides about volume in ALSA mention both 'PCM' and 'Master' so there's probably no best guess. I don't have 'PCM' on Intel HDA. Some sound cards may not have 'Master' volume control and ALSA has softvol plugin to emulate it.

Most cmus output plugins control the per-app volume if supported.

ALSA doesn't have per-application volume, every volume control is per-device even if the device is virtual. And there's no per-stream volume (at least I couldn't find anything about it).

So I'm going to reintroduce falling back to 'Master' but a little differently:
mixer.alsa.device is unspecified -> 'default' is assumed
mixer.alsa.device is incorrect -> error
mixer.alsa.channel is unspecified -> error
mixer.alsa.channel is incorrect -> try 'Master'. If successful, change mixer.alsa.channel to 'Master' to be more transparent. But how to implement this? If I change the variable it won't reflect in the UI in the near future, right?

Note about the above paragraph: when alsa_mixer_open() returns error code you don't get an error message. The volume just doesn't show up in UI. So if you leave mixer.alsa.channel unspecified you can turn off this mixer.

For new users who didn't change mixer's config variables it will work by default same as it currently does. For those who have both variables set to valid values it will work too. One thing that is different is that currently you leave device empty to turn off the mixer, but then you will have to leave channel empty.

@ihy123

ihy123 commented Sep 21, 2025

Copy link
Copy Markdown
Contributor Author

Tidied the history a bit by merging a couple of commits into one and just abandoned trying to change the previous behavior of assuming 'Master' etc.

@pgaskin pgaskin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Volume stuff looks good, no strong opinion on the mixer selem selection, one nitpick about the commits.

Comment thread Makefile Resolved
Comment thread op/mixer_alsa.c
Comment on lines +75 to +79
if (!snd_mixer_selem_has_playback_volume(elem)) {
d_print("simple control '%s',%i does not have playback volume\n",
snd_mixer_selem_id_get_name(sid),
snd_mixer_selem_id_get_index(sid));
return NULL;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other difference here compare to the old code (if I'm understanding it correctly) is it won't fall back to the next selem with snd_mixer_selem_has_playback_volume is the chosen one doesn't. I don't personally have a strong opinion on this though, so I guess it's okay.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it is the original behavior. Previously there was elem = NULL; break;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I overlooked that.

Comment thread op/mixer_alsa.c
Comment on lines +75 to +79
if (!snd_mixer_selem_has_playback_volume(elem)) {
d_print("simple control '%s',%i does not have playback volume\n",
snd_mixer_selem_id_get_name(sid),
snd_mixer_selem_id_get_index(sid));
return NULL;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I overlooked that.

@flyingmutant
flyingmutant merged commit 226a046 into cmus:master Sep 27, 2025
@ihy123
ihy123 deleted the alsa branch September 28, 2025 11:20
@BrewTestBot BrewTestBot mentioned this pull request Oct 28, 2026
1 task done
bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this pull request Nov 2, 2026
https://build.opensuse.org/request/show/1394501
by user mia + anag_factory
- Update to 2.13.0
  * Set the minimum requested AAudio buffer capacity
    gh#cmus/cmus#1386
  * Check for libavutil pkg-config
    gh#cmus/cmus#1388
  * Add sort by duration
    gh#cmus/cmus#1440
  * Respect scroll_offset setting when resizing window
    gh#cmus/cmus#1413
  * Try to fallback to any plugin upon failure to init output
    plugin
    gh#cmus/cmus#1416
  * PulseAudio bugfixes and APPLICATION_ID
    gh#cmus/cmus#1405
  * ip/ffmpeg fixes and ffmpeg 8.0 support
    gh#cmus/cmus#1444
  * CUE handling improvements and replaygain/genre support
    gh#cmus/cmus#1406
  * Fix for missing Icecast streaming bitrate display.
    gh#cmus/cmus#1451
  * op/mixer_alsa: alsamixer's volume scale; setting mixer control
    like aplay does it
    gh#cmus/cmus#1445
  * ip/ffmpeg: fix seeking and
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants