mixer(8): Improve mute and recsrc controls

The input options of "dev.mute" (+, -, ^) and "dev.recsrc" (+, -, ^, =)
are quite cryptic. Allow the input to also be an actual description of
what these options do.

+ -> add (recsrc)
- -> remove (recsrc)
^ -> toggle (recsrc, mute)
= -> set (recsrc)
0 -> off (mute)
1 -> on (mute)

Also, deprecate the use of the symbol options in the EXAMPLES section of
the man page, by using the new descriptive options.

In the future, we might want to get rid of the symbol options
altogether, but preserve backwards compatibility for now.

Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
Reviewed by:	dev_submerge.ch, imp
Differential Revision:	https://reviews.freebsd.org/D43796
This commit is contained in:
Christos Margiolis 2024-02-12 12:59:22 +02:00
parent 7bd14d09a9
commit cc7479d7dc
2 changed files with 42 additions and 43 deletions

View file

@ -114,7 +114,9 @@ with one of the available devices):
.Oo Cm \&: Oo Cm \&+ | Cm \&- Oc Ar rvol Oo % Oc Oc .Oo Cm \&: Oo Cm \&+ | Cm \&- Oc Ar rvol Oo % Oc Oc
.Xc .Xc
.It Ar dev Cm .mute Ta Cm 0 | 1 | ^ .It Ar dev Cm .mute Ta Cm 0 | 1 | ^
.It Ar dev Cm .mute Ta Cm off | on | toggle
.It Ar dev Cm .recsrc Ta Cm ^ | + | - | = .It Ar dev Cm .recsrc Ta Cm ^ | + | - | =
.It Ar dev Cm .recsrc Ta Cm toggle | add | remove | set
.El .El
.Sm on .Sm on
.Pp .Pp
@ -150,14 +152,14 @@ The
.Ar dev Ns Cm .mute .Ar dev Ns Cm .mute
control (un)mutes a device. control (un)mutes a device.
The following values are available: The following values are available:
.Bl -tag -width = -offset indent .Bl -tag -width "xxxxxxxxxx" -offset indent
.It Cm 0 .It Cm 0 | off
unmutes unmutes
.Ar dev .Ar dev
.It Cm 1 .It Cm 1 | on
mutes mutes
.Ar dev .Ar dev
.It Cm ^ .It Cm ^ | toggle
toggles the mute of toggles the mute of
.Ar dev .Ar dev
.El .El
@ -174,22 +176,23 @@ To modify the recording source you can use one of the following modifiers
on a on a
.Sy rec .Sy rec
device: device:
.Bl -tag -width = -offset indent .Bl -tag -width "xxxxxxxxxx" -offset indent
.It Cm ^ .It Cm ^ | toggle
toggles toggles
.Ar dev .Ar dev
of possible recording devices of possible recording devices
.It Cm + .It Cm + | add
adds adds
.Ar dev .Ar dev
to possible recording devices to possible recording devices
.It Cm - .It Cm - | remove
removes removes
.Ar dev .Ar dev
from possible recording devices from possible recording devices
.It Cm = .It Cm = | set
sets the recording device to makes
.Ar dev .Ar dev
the only recording device.
.El .El
.Sh FILES .Sh FILES
.Bl -tag -width /dev/mixerN -compact .Bl -tag -width /dev/mixerN -compact
@ -250,16 +253,16 @@ $ mixer mic.volume=+0.10:-0.05
Toggle the mute for Toggle the mute for
.Cm vol : .Cm vol :
.Bd -literal -offset indent .Bd -literal -offset indent
$ mixer vol.mute=^ $ mixer vol.mute=toggle
.Ed .Ed
.Pp .Pp
Set Add
.Cm mic .Cm mic
and toggle and remove
.Cm line .Cm line
recording sources: from the recording devices:
.Bd -literal -offset indent .Bd -literal -offset indent
$ mixer mic.recsrc=+ line.recsrc=^ $ mixer mic.recsrc=add line.recsrc=remove
.Ed .Ed
.Pp .Pp
Dump Dump

View file

@ -413,26 +413,24 @@ mod_mute(struct mix_dev *d, void *p)
m = d->parent_mixer; m = d->parent_mixer;
cp = mixer_get_ctl(m->dev, C_MUT); cp = mixer_get_ctl(m->dev, C_MUT);
val = p; val = p;
switch (*val) { if (strncmp(val, "off", strlen(val)) == 0 || *val == '0')
case '0':
opt = MIX_UNMUTE; opt = MIX_UNMUTE;
break; else if (strncmp(val, "on", strlen(val)) == 0 || *val == '1')
case '1':
opt = MIX_MUTE; opt = MIX_MUTE;
break; else if (strncmp(val, "toggle", strlen(val)) == 0 || *val == '^')
case '^':
opt = MIX_TOGGLEMUTE; opt = MIX_TOGGLEMUTE;
break; else {
default: warnx("%s: no such modifier", val);
warnx("%c: no such modifier", *val);
return (-1); return (-1);
} }
n = MIX_ISMUTE(m, m->dev->devno); n = MIX_ISMUTE(m, m->dev->devno);
if (mixer_set_mute(m, opt) < 0) if (mixer_set_mute(m, opt) < 0)
warn("%s.%s=%c", m->dev->name, cp->name, *val); warn("%s.%s=%s", m->dev->name, cp->name, val);
else else
printf("%s.%s: %d -> %d\n", printf("%s.%s: %s -> %s\n",
m->dev->name, cp->name, n, MIX_ISMUTE(m, m->dev->devno)); m->dev->name, cp->name,
n ? "on" : "off",
MIX_ISMUTE(m, m->dev->devno) ? "on" : "off");
return (0); return (0);
} }
@ -448,29 +446,26 @@ mod_recsrc(struct mix_dev *d, void *p)
m = d->parent_mixer; m = d->parent_mixer;
cp = mixer_get_ctl(m->dev, C_SRC); cp = mixer_get_ctl(m->dev, C_SRC);
val = p; val = p;
switch (*val) { if (strncmp(val, "add", strlen(val)) == 0 || *val == '+')
case '+':
opt = MIX_ADDRECSRC; opt = MIX_ADDRECSRC;
break; else if (strncmp(val, "remove", strlen(val)) == 0 || *val == '-')
case '-':
opt = MIX_REMOVERECSRC; opt = MIX_REMOVERECSRC;
break; else if (strncmp(val, "set", strlen(val)) == 0 || *val == '=')
case '=':
opt = MIX_SETRECSRC; opt = MIX_SETRECSRC;
break; else if (strncmp(val, "toggle", strlen(val)) == 0 || *val == '^')
case '^':
opt = MIX_TOGGLERECSRC; opt = MIX_TOGGLERECSRC;
break; else {
default: warnx("%s: no such modifier", val);
warnx("%c: no such modifier", *val);
return (-1); return (-1);
} }
n = MIX_ISRECSRC(m, m->dev->devno); n = MIX_ISRECSRC(m, m->dev->devno);
if (mixer_mod_recsrc(m, opt) < 0) if (mixer_mod_recsrc(m, opt) < 0)
warn("%s.%s=%c", m->dev->name, cp->name, *val); warn("%s.%s=%s", m->dev->name, cp->name, val);
else else
printf("%s.%s: %d -> %d\n", printf("%s.%s: %s -> %s\n",
m->dev->name, cp->name, n, MIX_ISRECSRC(m, m->dev->devno)); m->dev->name, cp->name,
n ? "add" : "remove",
MIX_ISRECSRC(m, m->dev->devno) ? "add" : "remove");
return (0); return (0);
} }
@ -493,7 +488,8 @@ print_mute(struct mix_dev *d, void *p)
struct mixer *m = d->parent_mixer; struct mixer *m = d->parent_mixer;
const char *ctl_name = p; const char *ctl_name = p;
printf("%s.%s=%d\n", m->dev->name, ctl_name, MIX_ISMUTE(m, m->dev->devno)); printf("%s.%s=%s\n", m->dev->name, ctl_name,
MIX_ISMUTE(m, m->dev->devno) ? "on" : "off");
return (0); return (0);
} }
@ -506,7 +502,7 @@ print_recsrc(struct mix_dev *d, void *p)
if (!MIX_ISRECSRC(m, m->dev->devno)) if (!MIX_ISRECSRC(m, m->dev->devno))
return (-1); return (-1);
printf("%s.%s=+\n", m->dev->name, ctl_name); printf("%s.%s=add\n", m->dev->name, ctl_name);
return (0); return (0);
} }