git: cc7479d7dc9b - main - mixer(8): Improve mute and recsrc controls

From: Christos Margiolis <christos_at_FreeBSD.org>
Date: Mon, 12 Feb 2024 11:00:22 UTC
The branch main has been updated by christos:

URL: https://cgit.FreeBSD.org/src/commit/?id=cc7479d7dc9b895c0a2f4d3805315437e03d0cf6

commit cc7479d7dc9b895c0a2f4d3805315437e03d0cf6
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2024-02-12 10:59:22 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2024-02-12 11:00:05 +0000

    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
---
 usr.sbin/mixer/mixer.8 | 33 +++++++++++++++++---------------
 usr.sbin/mixer/mixer.c | 52 +++++++++++++++++++++++---------------------------
 2 files changed, 42 insertions(+), 43 deletions(-)

diff --git a/usr.sbin/mixer/mixer.8 b/usr.sbin/mixer/mixer.8
index db0ec5f23a0c..75c6a81e3a55 100644
--- a/usr.sbin/mixer/mixer.8
+++ b/usr.sbin/mixer/mixer.8
@@ -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
diff --git a/usr.sbin/mixer/mixer.c b/usr.sbin/mixer/mixer.c
index 0c0c37ccb2bc..83e97df19116 100644
--- a/usr.sbin/mixer/mixer.c
+++ b/usr.sbin/mixer/mixer.c
@@ -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);
 }