2021-09-22 13:42:51 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2021 Christos Margiolis <christos@FreeBSD.org>
|
1995-02-15 17:33:04 +00:00
|
|
|
*
|
2021-09-22 13:42:51 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
1995-02-15 17:33:04 +00:00
|
|
|
*
|
2021-09-22 13:42:51 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
1995-02-15 17:33:04 +00:00
|
|
|
*
|
2021-09-22 13:42:51 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
1995-02-15 17:33:04 +00:00
|
|
|
*/
|
|
|
|
|
1997-09-29 06:38:49 +00:00
|
|
|
#include <err.h>
|
2021-09-22 13:42:51 +00:00
|
|
|
#include <errno.h>
|
2022-03-20 16:28:08 +00:00
|
|
|
#include <mixer.h>
|
1997-09-29 06:38:49 +00:00
|
|
|
#include <stdio.h>
|
1997-09-19 13:38:51 +00:00
|
|
|
#include <stdlib.h>
|
2021-09-22 13:42:51 +00:00
|
|
|
#include <string.h>
|
1997-09-19 13:38:51 +00:00
|
|
|
#include <unistd.h>
|
1995-02-15 17:33:04 +00:00
|
|
|
|
2022-03-20 19:08:13 +00:00
|
|
|
enum {
|
|
|
|
C_VOL = 0,
|
|
|
|
C_MUT,
|
|
|
|
C_SRC,
|
|
|
|
};
|
2021-09-22 13:42:51 +00:00
|
|
|
|
|
|
|
static void usage(void) __dead2;
|
|
|
|
static void initctls(struct mixer *);
|
|
|
|
static void printall(struct mixer *, int);
|
|
|
|
static void printminfo(struct mixer *, int);
|
|
|
|
static void printdev(struct mixer *, int);
|
|
|
|
static void printrecsrc(struct mixer *, int); /* XXX: change name */
|
2023-01-16 13:02:54 +00:00
|
|
|
static int set_dunit(struct mixer *, int);
|
2021-09-22 13:42:51 +00:00
|
|
|
/* Control handlers */
|
|
|
|
static int mod_volume(struct mix_dev *, void *);
|
|
|
|
static int mod_mute(struct mix_dev *, void *);
|
|
|
|
static int mod_recsrc(struct mix_dev *, void *);
|
|
|
|
static int print_volume(struct mix_dev *, void *);
|
|
|
|
static int print_mute(struct mix_dev *, void *);
|
|
|
|
static int print_recsrc(struct mix_dev *, void *);
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
1995-02-15 17:33:04 +00:00
|
|
|
{
|
2021-09-22 13:42:51 +00:00
|
|
|
struct mixer *m;
|
|
|
|
mix_ctl_t *cp;
|
|
|
|
char *name = NULL, buf[NAME_MAX];
|
2022-03-20 16:28:08 +00:00
|
|
|
char *p, *q, *devstr, *ctlstr, *valstr = NULL;
|
2022-03-20 19:08:13 +00:00
|
|
|
int dunit, i, n, pall = 1, shorthand;
|
2021-09-22 13:42:51 +00:00
|
|
|
int aflag = 0, dflag = 0, oflag = 0, sflag = 0;
|
2021-09-22 18:56:34 +00:00
|
|
|
int ch;
|
2021-09-22 13:42:51 +00:00
|
|
|
|
2021-10-16 08:39:18 +00:00
|
|
|
while ((ch = getopt(argc, argv, "ad:f:hos")) != -1) {
|
2021-09-22 13:42:51 +00:00
|
|
|
switch (ch) {
|
|
|
|
case 'a':
|
|
|
|
aflag = 1;
|
|
|
|
break;
|
|
|
|
case 'd':
|
2024-02-12 10:59:02 +00:00
|
|
|
if (strncmp(optarg, "pcm", 3) == 0)
|
|
|
|
optarg += 3;
|
2024-02-12 10:58:55 +00:00
|
|
|
errno = 0;
|
2021-09-22 13:42:51 +00:00
|
|
|
dunit = strtol(optarg, NULL, 10);
|
|
|
|
if (errno == EINVAL || errno == ERANGE)
|
2024-02-12 10:58:55 +00:00
|
|
|
err(1, "strtol(%s)", optarg);
|
2021-09-22 13:42:51 +00:00
|
|
|
dflag = 1;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
name = optarg;
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
oflag = 1;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
sflag = 1;
|
|
|
|
break;
|
2022-03-20 16:28:08 +00:00
|
|
|
case 'h': /* FALLTHROUGH */
|
2021-09-22 13:42:51 +00:00
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
2008-03-15 01:09:47 +00:00
|
|
|
}
|
2021-09-22 13:42:51 +00:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
/* Print all mixers and exit. */
|
|
|
|
if (aflag) {
|
|
|
|
if ((n = mixer_get_nmixers()) < 0)
|
2024-02-12 10:58:55 +00:00
|
|
|
errx(1, "no mixers present in the system");
|
2021-09-22 13:42:51 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
2024-05-23 00:57:43 +00:00
|
|
|
(void)mixer_get_path(buf, sizeof(buf), i);
|
2021-09-22 13:42:51 +00:00
|
|
|
if ((m = mixer_open(buf)) == NULL)
|
2024-05-23 00:57:25 +00:00
|
|
|
continue;
|
2021-09-22 13:42:51 +00:00
|
|
|
initctls(m);
|
|
|
|
if (sflag)
|
|
|
|
printrecsrc(m, oflag);
|
|
|
|
else {
|
|
|
|
printall(m, oflag);
|
|
|
|
if (oflag)
|
|
|
|
printf("\n");
|
2008-03-15 01:09:47 +00:00
|
|
|
}
|
2021-09-22 13:42:51 +00:00
|
|
|
(void)mixer_close(m);
|
|
|
|
}
|
|
|
|
return (0);
|
2008-03-15 01:09:47 +00:00
|
|
|
}
|
2021-09-22 13:42:51 +00:00
|
|
|
|
|
|
|
if ((m = mixer_open(name)) == NULL)
|
2024-02-12 10:58:55 +00:00
|
|
|
errx(1, "%s: no such mixer", name);
|
2021-09-22 13:42:51 +00:00
|
|
|
|
|
|
|
initctls(m);
|
|
|
|
|
2024-02-12 10:59:28 +00:00
|
|
|
if (dflag) {
|
|
|
|
if (set_dunit(m, dunit) < 0)
|
|
|
|
goto parse;
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* Open current mixer since we changed the default
|
|
|
|
* unit, otherwise we'll print and apply changes to the
|
|
|
|
* old one.
|
|
|
|
*/
|
|
|
|
(void)mixer_close(m);
|
|
|
|
if ((m = mixer_open(NULL)) == NULL)
|
|
|
|
errx(1, "cannot open default mixer");
|
|
|
|
initctls(m);
|
|
|
|
}
|
|
|
|
}
|
2021-09-22 13:42:51 +00:00
|
|
|
if (sflag) {
|
|
|
|
printrecsrc(m, oflag);
|
|
|
|
(void)mixer_close(m);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
parse:
|
|
|
|
while (argc > 0) {
|
2022-03-20 16:28:08 +00:00
|
|
|
if ((p = strdup(*argv)) == NULL)
|
2021-09-22 13:42:51 +00:00
|
|
|
err(1, "strdup(%s)", *argv);
|
2022-03-20 19:08:13 +00:00
|
|
|
|
|
|
|
/* Check if we're using the shorthand syntax for volume setting. */
|
|
|
|
shorthand = 0;
|
|
|
|
for (q = p; *q != '\0'; q++) {
|
|
|
|
if (*q == '=') {
|
|
|
|
q++;
|
|
|
|
shorthand = ((*q >= '0' && *q <= '9') ||
|
|
|
|
*q == '+' || *q == '-' || *q == '.');
|
|
|
|
break;
|
|
|
|
} else if (*q == '.')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-09-22 13:42:51 +00:00
|
|
|
/* Split the string into device, control and value. */
|
2022-03-20 16:28:08 +00:00
|
|
|
devstr = strsep(&p, ".=");
|
2021-09-22 13:42:51 +00:00
|
|
|
if ((m->dev = mixer_get_dev_byname(m, devstr)) == NULL) {
|
|
|
|
warnx("%s: no such device", devstr);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
/* Input: `dev`. */
|
|
|
|
if (p == NULL) {
|
|
|
|
printdev(m, 1);
|
|
|
|
pall = 0;
|
|
|
|
goto next;
|
2022-03-20 19:08:13 +00:00
|
|
|
} else if (shorthand) {
|
|
|
|
/*
|
|
|
|
* Input: `dev=N` -> shorthand for `dev.volume=N`.
|
|
|
|
*
|
|
|
|
* We don't care what the rest of the string contains as
|
|
|
|
* long as we're sure the very beginning is right,
|
|
|
|
* mod_volume() will take care of parsing it properly.
|
|
|
|
*/
|
|
|
|
cp = mixer_get_ctl(m->dev, C_VOL);
|
|
|
|
cp->mod(cp->parent_dev, p);
|
|
|
|
goto next;
|
2021-09-22 13:42:51 +00:00
|
|
|
}
|
|
|
|
ctlstr = strsep(&p, "=");
|
|
|
|
if ((cp = mixer_get_ctl_byname(m->dev, ctlstr)) == NULL) {
|
|
|
|
warnx("%s.%s: no such control", devstr, ctlstr);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
/* Input: `dev.control`. */
|
|
|
|
if (p == NULL) {
|
|
|
|
(void)cp->print(cp->parent_dev, cp->name);
|
|
|
|
pall = 0;
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
valstr = p;
|
|
|
|
/* Input: `dev.control=val`. */
|
|
|
|
cp->mod(cp->parent_dev, valstr);
|
|
|
|
next:
|
|
|
|
free(p);
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pall)
|
|
|
|
printall(m, oflag);
|
|
|
|
(void)mixer_close(m);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __dead2
|
|
|
|
usage(void)
|
|
|
|
{
|
2024-02-12 10:59:02 +00:00
|
|
|
fprintf(stderr, "usage: %1$s [-f device] [-d pcmN | N] [-os] [dev[.control[=value]]] ...\n"
|
|
|
|
" %1$s [-os] -a\n"
|
2021-10-16 08:39:18 +00:00
|
|
|
" %1$s -h\n", getprogname());
|
1995-02-15 17:33:04 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2021-09-22 13:42:51 +00:00
|
|
|
static void
|
|
|
|
initctls(struct mixer *m)
|
1997-09-19 13:38:51 +00:00
|
|
|
{
|
2021-09-22 13:42:51 +00:00
|
|
|
struct mix_dev *dp;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(dp, &m->devs, devs) {
|
|
|
|
rc += mixer_add_ctl(dp, C_VOL, "volume", mod_volume, print_volume);
|
|
|
|
rc += mixer_add_ctl(dp, C_MUT, "mute", mod_mute, print_mute);
|
|
|
|
rc += mixer_add_ctl(dp, C_SRC, "recsrc", mod_recsrc, print_recsrc);
|
|
|
|
}
|
|
|
|
if (rc) {
|
|
|
|
(void)mixer_close(m);
|
2024-02-12 10:58:55 +00:00
|
|
|
errx(1, "cannot make mixer controls");
|
2021-09-22 13:42:51 +00:00
|
|
|
}
|
|
|
|
}
|
1997-09-19 13:38:51 +00:00
|
|
|
|
2021-09-22 13:42:51 +00:00
|
|
|
static void
|
|
|
|
printall(struct mixer *m, int oflag)
|
|
|
|
{
|
|
|
|
struct mix_dev *dp;
|
1997-09-19 13:38:51 +00:00
|
|
|
|
2021-09-22 13:42:51 +00:00
|
|
|
printminfo(m, oflag);
|
|
|
|
TAILQ_FOREACH(dp, &m->devs, devs) {
|
|
|
|
m->dev = dp;
|
|
|
|
printdev(m, oflag);
|
|
|
|
}
|
1997-09-19 13:38:51 +00:00
|
|
|
}
|
|
|
|
|
2008-03-15 01:20:05 +00:00
|
|
|
static void
|
2021-09-22 13:42:51 +00:00
|
|
|
printminfo(struct mixer *m, int oflag)
|
1995-02-15 17:33:04 +00:00
|
|
|
{
|
2021-09-22 13:42:51 +00:00
|
|
|
int playrec = MIX_MODE_PLAY | MIX_MODE_REC;
|
2006-01-01 20:19:49 +00:00
|
|
|
|
2021-09-22 13:42:51 +00:00
|
|
|
if (oflag)
|
2008-03-15 01:09:47 +00:00
|
|
|
return;
|
2021-10-15 09:11:44 +00:00
|
|
|
printf("%s:", m->mi.name);
|
|
|
|
if (*m->ci.longname != '\0')
|
|
|
|
printf(" <%s>", m->ci.longname);
|
|
|
|
if (*m->ci.hw_info != '\0')
|
|
|
|
printf(" %s", m->ci.hw_info);
|
|
|
|
|
|
|
|
if (m->mode != 0)
|
|
|
|
printf(" (");
|
2021-09-22 13:42:51 +00:00
|
|
|
if (m->mode & MIX_MODE_PLAY)
|
|
|
|
printf("play");
|
|
|
|
if ((m->mode & playrec) == playrec)
|
|
|
|
printf("/");
|
|
|
|
if (m->mode & MIX_MODE_REC)
|
|
|
|
printf("rec");
|
2021-10-15 09:11:44 +00:00
|
|
|
if (m->mode != 0)
|
|
|
|
printf(")");
|
|
|
|
|
2021-09-22 13:42:51 +00:00
|
|
|
if (m->f_default)
|
|
|
|
printf(" (default)");
|
|
|
|
printf("\n");
|
|
|
|
}
|
2008-03-15 01:09:47 +00:00
|
|
|
|
2021-09-22 13:42:51 +00:00
|
|
|
static void
|
|
|
|
printdev(struct mixer *m, int oflag)
|
|
|
|
{
|
|
|
|
struct mix_dev *d = m->dev;
|
|
|
|
mix_ctl_t *cp;
|
|
|
|
|
|
|
|
if (!oflag) {
|
2022-03-20 16:23:37 +00:00
|
|
|
printf(" %-10s= %.2f:%.2f ",
|
|
|
|
d->name, d->vol.left, d->vol.right);
|
2021-09-22 13:42:51 +00:00
|
|
|
if (!MIX_ISREC(m, d->devno))
|
|
|
|
printf(" pbk");
|
|
|
|
if (MIX_ISREC(m, d->devno))
|
|
|
|
printf(" rec");
|
|
|
|
if (MIX_ISRECSRC(m, d->devno))
|
|
|
|
printf(" src");
|
|
|
|
if (MIX_ISMUTE(m, d->devno))
|
|
|
|
printf(" mute");
|
|
|
|
printf("\n");
|
|
|
|
} else {
|
|
|
|
TAILQ_FOREACH(cp, &d->ctls, ctls) {
|
|
|
|
(void)cp->print(cp->parent_dev, cp->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1995-02-15 17:33:04 +00:00
|
|
|
|
2021-09-22 13:42:51 +00:00
|
|
|
static void
|
|
|
|
printrecsrc(struct mixer *m, int oflag)
|
|
|
|
{
|
|
|
|
struct mix_dev *dp;
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
if (!m->recmask)
|
|
|
|
return;
|
|
|
|
if (!oflag)
|
|
|
|
printf("%s: ", m->mi.name);
|
|
|
|
TAILQ_FOREACH(dp, &m->devs, devs) {
|
|
|
|
if (MIX_ISRECSRC(m, dp->devno)) {
|
|
|
|
if (n++ && !oflag)
|
2006-01-01 20:19:49 +00:00
|
|
|
printf(", ");
|
2021-09-22 13:42:51 +00:00
|
|
|
printf("%s", dp->name);
|
|
|
|
if (oflag)
|
|
|
|
printf(".%s=+%s",
|
2022-03-20 16:28:08 +00:00
|
|
|
mixer_get_ctl(dp, C_SRC)->name, n ? " " : "");
|
1995-02-15 17:33:04 +00:00
|
|
|
}
|
2021-09-22 13:42:51 +00:00
|
|
|
}
|
|
|
|
printf("\n");
|
1995-02-15 17:33:04 +00:00
|
|
|
}
|
|
|
|
|
2021-09-22 13:42:51 +00:00
|
|
|
static int
|
2023-01-16 13:02:54 +00:00
|
|
|
set_dunit(struct mixer *m, int dunit)
|
1995-02-15 17:33:04 +00:00
|
|
|
{
|
2021-09-22 13:42:51 +00:00
|
|
|
int n;
|
1997-09-19 13:38:51 +00:00
|
|
|
|
2021-09-22 13:42:51 +00:00
|
|
|
if ((n = mixer_get_dunit()) < 0) {
|
|
|
|
warn("cannot get default unit");
|
|
|
|
return (-1);
|
2008-03-15 01:09:47 +00:00
|
|
|
}
|
2023-01-16 13:02:54 +00:00
|
|
|
if (mixer_set_dunit(m, dunit) < 0) {
|
2024-02-12 10:58:55 +00:00
|
|
|
warn("cannot set default unit to %d", dunit);
|
2021-09-22 13:42:51 +00:00
|
|
|
return (-1);
|
1996-01-31 18:01:22 +00:00
|
|
|
}
|
2023-01-16 13:02:54 +00:00
|
|
|
printf("default_unit: %d -> %d\n", n, dunit);
|
1996-01-31 18:01:22 +00:00
|
|
|
|
2021-09-22 13:42:51 +00:00
|
|
|
return (0);
|
|
|
|
}
|
1997-09-19 13:38:51 +00:00
|
|
|
|
2021-09-22 13:42:51 +00:00
|
|
|
static int
|
|
|
|
mod_volume(struct mix_dev *d, void *p)
|
|
|
|
{
|
|
|
|
struct mixer *m;
|
|
|
|
mix_ctl_t *cp;
|
|
|
|
mix_volume_t v;
|
|
|
|
const char *val;
|
2022-04-30 03:12:56 +00:00
|
|
|
char *endp, lstr[8], rstr[8];
|
2021-09-22 13:42:51 +00:00
|
|
|
float lprev, rprev, lrel, rrel;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
m = d->parent_mixer;
|
|
|
|
cp = mixer_get_ctl(m->dev, C_VOL);
|
|
|
|
val = p;
|
|
|
|
n = sscanf(val, "%7[^:]:%7s", lstr, rstr);
|
|
|
|
if (n == EOF) {
|
|
|
|
warnx("invalid volume value: %s", val);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
lrel = rrel = 0;
|
|
|
|
if (n > 0) {
|
|
|
|
if (*lstr == '+' || *lstr == '-')
|
2022-04-30 03:12:56 +00:00
|
|
|
lrel = 1;
|
|
|
|
v.left = strtof(lstr, &endp);
|
|
|
|
if (*endp != '\0' && (*endp != '%' || *(endp + 1) != '\0')) {
|
|
|
|
warnx("invalid volume value: %s", lstr);
|
|
|
|
return (-1);
|
|
|
|
}
|
2021-09-22 13:42:51 +00:00
|
|
|
|
2022-04-30 03:12:56 +00:00
|
|
|
if (*endp == '%')
|
2021-09-22 13:42:51 +00:00
|
|
|
v.left /= 100.0f;
|
|
|
|
}
|
|
|
|
if (n > 1) {
|
|
|
|
if (*rstr == '+' || *rstr == '-')
|
|
|
|
rrel = 1;
|
2022-04-30 03:12:56 +00:00
|
|
|
v.right = strtof(rstr, &endp);
|
|
|
|
if (*endp != '\0' && (*endp != '%' || *(endp + 1) != '\0')) {
|
|
|
|
warnx("invalid volume value: %s", rstr);
|
|
|
|
return (-1);
|
|
|
|
}
|
2021-09-22 13:42:51 +00:00
|
|
|
|
2022-04-30 03:12:56 +00:00
|
|
|
if (*endp == '%')
|
2021-09-22 13:42:51 +00:00
|
|
|
v.right /= 100.0f;
|
|
|
|
}
|
|
|
|
switch (n) {
|
|
|
|
case 1:
|
|
|
|
v.right = v.left; /* FALLTHROUGH */
|
2022-04-30 03:12:56 +00:00
|
|
|
rrel = lrel;
|
2021-09-22 13:42:51 +00:00
|
|
|
case 2:
|
|
|
|
if (lrel)
|
|
|
|
v.left += m->dev->vol.left;
|
|
|
|
if (rrel)
|
|
|
|
v.right += m->dev->vol.right;
|
|
|
|
|
|
|
|
if (v.left < MIX_VOLMIN)
|
|
|
|
v.left = MIX_VOLMIN;
|
|
|
|
else if (v.left > MIX_VOLMAX)
|
|
|
|
v.left = MIX_VOLMAX;
|
|
|
|
if (v.right < MIX_VOLMIN)
|
|
|
|
v.right = MIX_VOLMIN;
|
|
|
|
else if (v.right > MIX_VOLMAX)
|
|
|
|
v.right = MIX_VOLMAX;
|
|
|
|
|
|
|
|
lprev = m->dev->vol.left;
|
|
|
|
rprev = m->dev->vol.right;
|
|
|
|
if (mixer_set_vol(m, v) < 0)
|
|
|
|
warn("%s.%s=%.2f:%.2f",
|
|
|
|
m->dev->name, cp->name, v.left, v.right);
|
|
|
|
else
|
|
|
|
printf("%s.%s: %.2f:%.2f -> %.2f:%.2f\n",
|
|
|
|
m->dev->name, cp->name, lprev, rprev, v.left, v.right);
|
|
|
|
}
|
2003-04-09 15:25:52 +00:00
|
|
|
|
2021-09-22 13:42:51 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2003-04-09 15:25:52 +00:00
|
|
|
|
2021-09-22 13:42:51 +00:00
|
|
|
static int
|
|
|
|
mod_mute(struct mix_dev *d, void *p)
|
|
|
|
{
|
|
|
|
struct mixer *m;
|
|
|
|
mix_ctl_t *cp;
|
|
|
|
const char *val;
|
|
|
|
int n, opt = -1;
|
|
|
|
|
|
|
|
m = d->parent_mixer;
|
|
|
|
cp = mixer_get_ctl(m->dev, C_MUT);
|
|
|
|
val = p;
|
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
2024-02-12 10:59:22 +00:00
|
|
|
if (strncmp(val, "off", strlen(val)) == 0 || *val == '0')
|
2021-09-22 13:42:51 +00:00
|
|
|
opt = MIX_UNMUTE;
|
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
2024-02-12 10:59:22 +00:00
|
|
|
else if (strncmp(val, "on", strlen(val)) == 0 || *val == '1')
|
2021-09-22 13:42:51 +00:00
|
|
|
opt = MIX_MUTE;
|
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
2024-02-12 10:59:22 +00:00
|
|
|
else if (strncmp(val, "toggle", strlen(val)) == 0 || *val == '^')
|
2021-09-22 13:42:51 +00:00
|
|
|
opt = MIX_TOGGLEMUTE;
|
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
2024-02-12 10:59:22 +00:00
|
|
|
else {
|
|
|
|
warnx("%s: no such modifier", val);
|
2021-09-22 13:42:51 +00:00
|
|
|
return (-1);
|
1995-02-15 17:33:04 +00:00
|
|
|
}
|
2021-09-22 13:42:51 +00:00
|
|
|
n = MIX_ISMUTE(m, m->dev->devno);
|
|
|
|
if (mixer_set_mute(m, opt) < 0)
|
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
2024-02-12 10:59:22 +00:00
|
|
|
warn("%s.%s=%s", m->dev->name, cp->name, val);
|
2021-09-22 13:42:51 +00:00
|
|
|
else
|
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
2024-02-12 10:59:22 +00:00
|
|
|
printf("%s.%s: %s -> %s\n",
|
|
|
|
m->dev->name, cp->name,
|
|
|
|
n ? "on" : "off",
|
|
|
|
MIX_ISMUTE(m, m->dev->devno) ? "on" : "off");
|
1995-02-15 17:33:04 +00:00
|
|
|
|
2021-09-22 13:42:51 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2000-08-15 05:42:39 +00:00
|
|
|
|
2021-09-22 13:42:51 +00:00
|
|
|
static int
|
|
|
|
mod_recsrc(struct mix_dev *d, void *p)
|
|
|
|
{
|
|
|
|
struct mixer *m;
|
|
|
|
mix_ctl_t *cp;
|
|
|
|
const char *val;
|
|
|
|
int n, opt = -1;
|
|
|
|
|
|
|
|
m = d->parent_mixer;
|
|
|
|
cp = mixer_get_ctl(m->dev, C_SRC);
|
|
|
|
val = p;
|
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
2024-02-12 10:59:22 +00:00
|
|
|
if (strncmp(val, "add", strlen(val)) == 0 || *val == '+')
|
2021-09-22 13:42:51 +00:00
|
|
|
opt = MIX_ADDRECSRC;
|
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
2024-02-12 10:59:22 +00:00
|
|
|
else if (strncmp(val, "remove", strlen(val)) == 0 || *val == '-')
|
2021-09-22 13:42:51 +00:00
|
|
|
opt = MIX_REMOVERECSRC;
|
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
2024-02-12 10:59:22 +00:00
|
|
|
else if (strncmp(val, "set", strlen(val)) == 0 || *val == '=')
|
2021-09-22 13:42:51 +00:00
|
|
|
opt = MIX_SETRECSRC;
|
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
2024-02-12 10:59:22 +00:00
|
|
|
else if (strncmp(val, "toggle", strlen(val)) == 0 || *val == '^')
|
2021-09-22 13:42:51 +00:00
|
|
|
opt = MIX_TOGGLERECSRC;
|
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
2024-02-12 10:59:22 +00:00
|
|
|
else {
|
|
|
|
warnx("%s: no such modifier", val);
|
2021-09-22 13:42:51 +00:00
|
|
|
return (-1);
|
1997-09-19 13:38:51 +00:00
|
|
|
}
|
2021-09-22 13:42:51 +00:00
|
|
|
n = MIX_ISRECSRC(m, m->dev->devno);
|
|
|
|
if (mixer_mod_recsrc(m, opt) < 0)
|
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
2024-02-12 10:59:22 +00:00
|
|
|
warn("%s.%s=%s", m->dev->name, cp->name, val);
|
2021-09-22 13:42:51 +00:00
|
|
|
else
|
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
2024-02-12 10:59:22 +00:00
|
|
|
printf("%s.%s: %s -> %s\n",
|
|
|
|
m->dev->name, cp->name,
|
|
|
|
n ? "add" : "remove",
|
|
|
|
MIX_ISRECSRC(m, m->dev->devno) ? "add" : "remove");
|
2021-09-22 13:42:51 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
2008-03-15 01:20:05 +00:00
|
|
|
|
2021-09-22 13:42:51 +00:00
|
|
|
static int
|
|
|
|
print_volume(struct mix_dev *d, void *p)
|
|
|
|
{
|
|
|
|
struct mixer *m = d->parent_mixer;
|
|
|
|
const char *ctl_name = p;
|
|
|
|
|
|
|
|
printf("%s.%s=%.2f:%.2f\n",
|
|
|
|
m->dev->name, ctl_name, m->dev->vol.left, m->dev->vol.right);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
print_mute(struct mix_dev *d, void *p)
|
|
|
|
{
|
|
|
|
struct mixer *m = d->parent_mixer;
|
|
|
|
const char *ctl_name = p;
|
|
|
|
|
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
2024-02-12 10:59:22 +00:00
|
|
|
printf("%s.%s=%s\n", m->dev->name, ctl_name,
|
|
|
|
MIX_ISMUTE(m, m->dev->devno) ? "on" : "off");
|
2021-09-22 13:42:51 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
print_recsrc(struct mix_dev *d, void *p)
|
|
|
|
{
|
|
|
|
struct mixer *m = d->parent_mixer;
|
|
|
|
const char *ctl_name = p;
|
1997-09-19 13:38:51 +00:00
|
|
|
|
2021-09-22 13:42:51 +00:00
|
|
|
if (!MIX_ISRECSRC(m, m->dev->devno))
|
|
|
|
return (-1);
|
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
2024-02-12 10:59:22 +00:00
|
|
|
printf("%s.%s=add\n", m->dev->name, ctl_name);
|
1997-09-19 13:38:51 +00:00
|
|
|
|
2008-03-15 01:20:05 +00:00
|
|
|
return (0);
|
1995-02-15 17:33:04 +00:00
|
|
|
}
|