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

View File

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