=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/sndiod/dev.c,v retrieving revision 1.74 retrieving revision 1.75 diff -u -r1.74 -r1.75 --- src/usr.bin/sndiod/dev.c 2020/06/28 05:17:25 1.74 +++ src/usr.bin/sndiod/dev.c 2020/06/28 05:21:39 1.75 @@ -1,4 +1,4 @@ -/* $OpenBSD: dev.c,v 1.74 2020/06/28 05:17:25 ratchov Exp $ */ +/* $OpenBSD: dev.c,v 1.75 2020/06/28 05:21:39 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * @@ -67,6 +67,7 @@ void dev_done(struct dev *); struct dev *dev_bynum(int); void dev_del(struct dev *); +void dev_setalt(struct dev *, unsigned int); unsigned int dev_roundof(struct dev *, unsigned int); void dev_wakeup(struct dev *); void dev_sync_attach(struct dev *); @@ -1088,6 +1089,30 @@ } /* + * set prefered alt device name + */ +void +dev_setalt(struct dev *d, unsigned int idx) +{ + struct dev_alt **pa, *a; + + /* find alt with given index */ + for (pa = &d->alt_list; (a = *pa)->idx != idx; pa = &a->next) + ; + + /* detach from list */ + *pa = a->next; + + /* attach at head */ + a->next = d->alt_list; + d->alt_list = a; + + /* reopen device with the new alt */ + if (idx != d->alt_num) + dev_reopen(d); +} + +/* * adjust device parameters and mode */ void @@ -1176,6 +1201,7 @@ { int i; char name[CTL_NAMEMAX]; + struct dev_alt *a; d->master_enabled = 0; d->mode = d->reqmode; @@ -1209,6 +1235,14 @@ NULL, -1, 127, d->slot[i].vol); } + for (a = d->alt_list; a != NULL; a = a->next) { + snprintf(name, sizeof(name), "%d", a->idx); + dev_addctl(d, "", CTL_SEL, + CTLADDR_ALT_SEL + a->idx, + "server", -1, "device", + name, -1, 1, a->idx == d->alt_num); + } + d->pstate = DEV_INIT; return 1; } @@ -2472,7 +2506,13 @@ c->dirty = 1; dev_ref(d); } else { - if (addr == CTLADDR_MASTER) { + if (addr >= CTLADDR_ALT_SEL) { + if (val) { + num = addr - CTLADDR_ALT_SEL; + dev_setalt(d, num); + } + return 1; + } else if (addr == CTLADDR_MASTER) { if (d->master_enabled) { dev_master(d, val); dev_midi_master(d);