Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/mixer/mixer.c
Show All 32 Lines | |||||
static void usage(void) __dead2; | static void usage(void) __dead2; | ||||
static void initctls(struct mixer *); | static void initctls(struct mixer *); | ||||
static void printall(struct mixer *, int); | static void printall(struct mixer *, int); | ||||
static void printminfo(struct mixer *, int); | static void printminfo(struct mixer *, int); | ||||
static void printdev(struct mixer *, int); | static void printdev(struct mixer *, int); | ||||
static void printrecsrc(struct mixer *, int); /* XXX: change name */ | static void printrecsrc(struct mixer *, int); /* XXX: change name */ | ||||
/* Control handlers */ | /* Control handlers */ | ||||
static int mod_dunit(struct mix_dev *, void *); | static int mod_default_unit(struct mix_dev *, void *); | ||||
static int mod_volume(struct mix_dev *, void *); | static int mod_volume(struct mix_dev *, void *); | ||||
static int mod_mute(struct mix_dev *, void *); | static int mod_mute(struct mix_dev *, void *); | ||||
static int mod_recsrc(struct mix_dev *, void *); | static int mod_recsrc(struct mix_dev *, void *); | ||||
static int print_volume(struct mix_dev *, void *); | static int print_volume(struct mix_dev *, void *); | ||||
static int print_mute(struct mix_dev *, void *); | static int print_mute(struct mix_dev *, void *); | ||||
static int print_recsrc(struct mix_dev *, void *); | static int print_recsrc(struct mix_dev *, void *); | ||||
static const mix_ctl_t ctl_dunit = { | static const mix_ctl_t ctl_default_unit = { | ||||
.parent_dev = NULL, | .parent_dev = NULL, | ||||
.id = -1, | .id = -1, | ||||
.name = "default_unit", | .name = "default_unit", | ||||
.mod = mod_dunit, | .mod = mod_default_unit, | ||||
.print = NULL | .print = NULL | ||||
}; | }; | ||||
int | int | ||||
main(int argc, char *argv[]) | main(int argc, char *argv[]) | ||||
{ | { | ||||
struct mixer *m; | struct mixer *m; | ||||
mix_ctl_t *cp; | mix_ctl_t *cp; | ||||
char *name = NULL, buf[NAME_MAX]; | char *name = NULL, buf[NAME_MAX]; | ||||
char *p, *bufp, *devstr, *ctlstr, *valstr = NULL; | char *p, *bufp, *devstr, *ctlstr, *valstr = NULL; | ||||
int dunit, i, n, pall = 1; | int du, i, n, pall = 1; | ||||
int aflag = 0, dflag = 0, oflag = 0, sflag = 0; | int aflag = 0, dflag = 0, oflag = 0, sflag = 0; | ||||
int ch; | int ch; | ||||
while ((ch = getopt(argc, argv, "ad:f:os")) != -1) { | while ((ch = getopt(argc, argv, "ad:f:os")) != -1) { | ||||
switch (ch) { | switch (ch) { | ||||
case 'a': | case 'a': | ||||
aflag = 1; | aflag = 1; | ||||
break; | break; | ||||
case 'd': | case 'd': | ||||
dunit = strtol(optarg, NULL, 10); | du = strtol(optarg, NULL, 10); | ||||
if (errno == EINVAL || errno == ERANGE) | if (errno == EINVAL || errno == ERANGE) | ||||
err(1, "strtol"); | err(1, "strtol"); | ||||
dflag = 1; | dflag = 1; | ||||
break; | break; | ||||
case 'f': | case 'f': | ||||
name = optarg; | name = optarg; | ||||
break; | break; | ||||
case 'o': | case 'o': | ||||
Show All 31 Lines | if (aflag) { | ||||
return (0); | return (0); | ||||
} | } | ||||
if ((m = mixer_open(name)) == NULL) | if ((m = mixer_open(name)) == NULL) | ||||
err(1, "mixer_open: %s", name); | err(1, "mixer_open: %s", name); | ||||
initctls(m); | initctls(m); | ||||
if (dflag && ctl_dunit.mod(m->dev, &dunit) < 0) | if (dflag && ctl_default_unit.mod(m->dev, &du) < 0) | ||||
goto parse; | goto parse; | ||||
if (sflag) { | if (sflag) { | ||||
printrecsrc(m, oflag); | printrecsrc(m, oflag); | ||||
(void)mixer_close(m); | (void)mixer_close(m); | ||||
return (0); | return (0); | ||||
} | } | ||||
parse: | parse: | ||||
▲ Show 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | if (MIX_ISRECSRC(m, dp->devno)) { | ||||
mixer_get_ctl(dp, C_SRC)->name, | mixer_get_ctl(dp, C_SRC)->name, | ||||
n ? " " : ""); | n ? " " : ""); | ||||
} | } | ||||
} | } | ||||
printf("\n"); | printf("\n"); | ||||
} | } | ||||
static int | static int | ||||
mod_dunit(struct mix_dev *d, void *p) | mod_default_unit(struct mix_dev *d, void *p) | ||||
{ | { | ||||
int dunit = *((int *)p); | int du = *((int *)p); | ||||
int n; | int n; | ||||
if ((n = mixer_get_dunit()) < 0) { | if ((n = mixer_get_default_unit()) < 0) { | ||||
warn("cannot get default unit"); | warn("cannot get default unit"); | ||||
return (-1); | return (-1); | ||||
} | } | ||||
if (mixer_set_dunit(d->parent_mixer, dunit) < 0) { | if (mixer_set_default_unit(d->parent_mixer, du) < 0) { | ||||
warn("cannot set default unit to: %d", dunit); | warn("cannot set default unit to: %d", du); | ||||
return (-1); | return (-1); | ||||
} | } | ||||
printf("%s: %d -> %d\n", ctl_dunit.name, n, dunit); | printf("%s: %d -> %d\n", ctl_default_unit.name, n, du); | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
mod_volume(struct mix_dev *d, void *p) | mod_volume(struct mix_dev *d, void *p) | ||||
{ | { | ||||
struct mixer *m; | struct mixer *m; | ||||
▲ Show 20 Lines • Show All 173 Lines • Show Last 20 Lines |