mixer: use (name, unit) couple for groups as well

This commit is contained in:
Alexandre Ratchov 2017-08-03 01:53:40 +02:00
parent 8c7d6cd46c
commit 7178903317
10 changed files with 57 additions and 36 deletions

View File

@ -140,11 +140,10 @@ struct amsg_mix_chan {
* description of a control (index, value) pair
*/
struct amsg_mix_desc {
struct amsg_mix_chan group; /* group of the control */
struct amsg_mix_chan chan0; /* affected channels */
struct amsg_mix_chan chan1; /* dito for AMSG_MIX_{SEL,VEC,LIST} */
char func[AMSG_MIX_NAMEMAX]; /* parameter function name */
char group[AMSG_MIX_NAMEMAX];
uint32_t __pad[1];
uint8_t type; /* see siomix_desc structure */
uint8_t __pad1[1];
uint16_t addr; /* control address */

View File

@ -82,7 +82,8 @@ siomix_aucat_rdata(struct siomix_aucat_hdl *hdl)
c = hdl->buf;
rpos = 0;
while (rpos < hdl->buf_wpos) {
strlcpy(desc.group, c->group, SIOMIX_NAMEMAX);
strlcpy(desc.group.str, c->group.str, SIOMIX_NAMEMAX);
desc.group.unit = (int16_t)ntohs(c->group.unit);
strlcpy(desc.chan0.str, c->chan0.str, SIOMIX_NAMEMAX);
desc.chan0.unit = (int16_t)ntohs(c->chan0.unit);
strlcpy(desc.chan1.str, c->chan1.str, SIOMIX_NAMEMAX);

View File

@ -122,16 +122,16 @@ struct siomix_chan {
};
struct siomix_desc {
unsigned int addr; /* control's address */
#define SIOMIX_NUM 2 /* number in the 0..127 range */
#define SIOMIX_SW 3 /* on/off switch */
#define SIOMIX_VEC 4 /* element of array of numbers */
#define SIOMIX_LIST 5 /* element of array of switches */
unsigned int addr; /* control address */
#define SIOMIX_NUM 2 /* integer in the 0..127 range */
#define SIOMIX_SW 3 /* on/off switch (0 or 1) */
#define SIOMIX_VEC 4 /* number, element of vector */
#define SIOMIX_LIST 5 /* switch, element of a list */
unsigned int type; /* one of above */
char namespace[SIOMIX_NAMEMAX]; /* group this control belongs to */
char func[SIOMIX_NAMEMAX]; /* function name */
struct siomix_chan group; /* group this control belongs to */
struct siomix_chan chan0; /* affected channels */
struct siomix_chan chan1; /* dito for vec, and list */
struct siomix_chan chan1; /* dito for SIOMIX_{VEC,LIST} */
};
.Ed
.Pp

View File

@ -224,6 +224,8 @@ scanvol(struct siomix_sun_hdl *hdl, struct wskbd_vol *vol)
int i, val;
memset(&desc, 0, sizeof(struct siomix_desc));
strlcpy(desc.group.str, "hw", sizeof(desc.group.str));
desc.group.unit = -1;
if (vol->level_idx >= 0) {
ctrl.dev = vol->level_idx;
ctrl.type = AUDIO_MIXER_VALUE;

View File

@ -111,8 +111,8 @@ struct siomix_desc {
#define SIOMIX_VEC 4 /* number, element of vector */
#define SIOMIX_LIST 5 /* switch, element of a list */
unsigned int type; /* one of above */
char group[SIOMIX_NAMEMAX]; /* or class name */
char func[SIOMIX_NAMEMAX]; /* function name */
struct siomix_chan group; /* group this control belongs to */
struct siomix_chan chan0; /* affected channels */
struct siomix_chan chan1; /* dito for SIOMIX_{VEC,LIST} */
};

View File

@ -78,7 +78,10 @@ cmpdesc(struct siomix_desc *d1, struct siomix_desc *d2)
{
int res;
res = strcmp(d1->group, d2->group);
res = strcmp(d1->group.str, d2->group.str);
if (res != 0)
return res;
res = d1->group.unit - d2->group.unit;
if (res != 0)
return res;
res = strcmp(d1->chan0.str, d2->chan0.str);
@ -395,8 +398,12 @@ print_val(struct info *p, int mono)
void
print_par(struct info *p, int mono, char *comment)
{
if (p->desc.group[0] != 0)
printf("%s/", p->desc.group);
if (p->desc.group.str[0] != 0) {
printf("%s", p->desc.group.str);
if (p->desc.group.unit >= 0)
printf("%d", p->desc.group.unit);
printf("/");
}
print_chan(&p->desc.chan0, mono);
printf(".%s=", p->desc.func);
if (i_flag)

View File

@ -1056,7 +1056,8 @@ dev_adjpar(struct dev *d, int mode,
int
dev_open(struct dev *d)
{
int i;
int i, gunit;
struct ctl *c;
d->mode = d->reqmode;
d->round = d->reqround;
@ -1134,13 +1135,32 @@ dev_open(struct dev *d)
log_puts(" frames\n");
}
/*
* we use the "sndiod" group name. find a unused
* unit number for it
*/
gunit = 0;
c = d->ctl_list;
while (1) {
if (c == NULL)
break;
if (strcmp(c->group.str, "sndiod") == 0 &&
c->group.unit == gunit) {
gunit++;
c = d->ctl_list;
continue;
}
c = c->next;
}
for (i = 0; i < DEV_NSLOT; i++) {
dev_addctl(d, "", CTL_NUM,
dev_addctl(d, "sndiod", gunit, CTL_NUM,
CTLADDR_SLOT_LEVEL(i),
d->slot[i].name, d->slot[i].unit, "level",
NULL, -1, d->slot[i].vol);
}
dev_addctl(d, "", CTL_NUM,
dev_addctl(d, "sndiod", gunit, CTL_NUM,
CTLADDR_MASTER, "master", -1, "level", NULL, -1, d->master);
return 1;
}
@ -2024,8 +2044,8 @@ ctl_chan_log(struct ctl_chan *c)
void
ctl_log(struct ctl *c)
{
if (c->group[0] != 0) {
log_puts(c->group);
if (c->group.str[0] != 0) {
ctl_chan_log(&c->group);
log_puts("/");
}
ctl_chan_log(&c->chan0);
@ -2051,15 +2071,16 @@ ctl_log(struct ctl *c)
* add a ctl
*/
struct ctl *
dev_addctl(struct dev *d, char *group, int type, int addr,
dev_addctl(struct dev *d, char *gstr, int gunit, int type, int addr,
char *str0, int unit0, char *func, char *str1, int unit1, int val)
{
struct ctl *c;
c = xmalloc(sizeof(struct ctl));
c->type = type;
strlcpy(c->group, group, CTL_NAMEMAX);
strlcpy(c->func, func, CTL_NAMEMAX);
strlcpy(c->group.str, gstr, CTL_NAMEMAX);
c->group.unit = gunit;
strlcpy(c->chan0.str, str0, CTL_NAMEMAX);
c->chan0.unit = unit0;
if (c->type == CTL_VEC || c->type == CTL_LIST) {

View File

@ -114,11 +114,10 @@ struct ctl {
unsigned int addr; /* control address */
#define CTL_NAMEMAX 16 /* max name lenght */
char func[CTL_NAMEMAX]; /* parameter function name */
char group[CTL_NAMEMAX]; /* parameter group name */
struct ctl_chan {
char str[CTL_NAMEMAX]; /* stream name */
int unit;
} chan0, chan1; /* affected channels */
} group, chan0, chan1; /* affected channels */
unsigned int val_mask;
unsigned int desc_mask;
unsigned int curval;
@ -287,7 +286,7 @@ int dev_setctl(struct dev *, int, int);
int dev_onctl(struct dev *, int, int);
int dev_nctl(struct dev *);
void dev_label(struct dev *, int);
struct ctl *dev_addctl(struct dev *, char *, int, int,
struct ctl *dev_addctl(struct dev *, char *, int, int, int,
char *, int, char *, char *, int, int);
void dev_rmctl(struct dev *, int);
int dev_makeunit(struct dev *, char *);

View File

@ -52,23 +52,14 @@ void
dev_siomix_ondesc(void *arg, struct siomix_desc *desc, int val)
{
struct dev *d = arg;
char ns[CTL_NAMEMAX];
int addr;
if (desc == NULL)
return;
addr = CTLADDR_END + desc->addr;
dev_rmctl(d, addr);
strlcpy(ns, "dev", CTL_NAMEMAX);
if (sizeof("dev") + 1 + strlen(desc->group) >= CTL_NAMEMAX) {
log_puts("group name too, long skipped\n");
return;
}
if (desc->group[0] != 0) {
strlcat(ns, "/", CTL_NAMEMAX);
strlcat(ns, desc->group, CTL_NAMEMAX);
}
dev_addctl(d, ns, desc->type, addr,
dev_addctl(d,
desc->group.str, desc->group.unit, desc->type, addr,
desc->chan0.str, desc->chan0.unit, desc->func,
desc->chan1.str, desc->chan1.unit, val);
}

View File

@ -1571,8 +1571,9 @@ sock_buildmsg(struct sock *f)
break;
c->desc_mask &= ~mask;
c->val_mask &= ~mask;
strlcpy(desc->group, c->group,
strlcpy(desc->group.str, c->group.str,
AMSG_MIX_NAMEMAX);
desc->group.unit = ntohs(c->group.unit);
strlcpy(desc->chan0.str, c->chan0.str,
AMSG_MIX_NAMEMAX);
desc->chan0.unit = ntohs(c->chan0.unit);