From: ratchov Date: Wed, 10 Mar 2021 08:22:25 +0000 (+0000) Subject: sndiod: When a slot structure is recycled allocate new control X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=d0ac6fca86a4b5e180d607ae17223249021e624d;p=openbsd sndiod: When a slot structure is recycled allocate new control Trying to rename the program level control is not needed anymore. When a slot is given to another program, the new ctl_{new,del}() functions can be used to delete the control of the old program and create a new one for the new program. Cleaner, simpler. --- diff --git a/usr.bin/sndiod/dev.c b/usr.bin/sndiod/dev.c index e011882a64e..4135f3c1d06 100644 --- a/usr.bin/sndiod/dev.c +++ b/usr.bin/sndiod/dev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dev.c,v 1.98 2021/03/10 08:21:27 ratchov Exp $ */ +/* $OpenBSD: dev.c,v 1.99 2021/03/10 08:22:25 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * @@ -1713,6 +1713,7 @@ slot_new(struct opt *opt, unsigned int id, char *who, { char *p; char name[SLOT_NAMEMAX]; + char ctl_name[CTL_NAMEMAX]; unsigned int i, ser, bestser, bestidx; struct slot *unit[DEV_NSLOT]; struct slot *s; @@ -1787,6 +1788,7 @@ slot_new(struct opt *opt, unsigned int id, char *who, } s = slot_array + bestidx; + ctl_del(CTL_SLOT_LEVEL, s, NULL); s->vol = MIDI_MAXCTL; strlcpy(s->name, name, SLOT_NAMEMAX); s->serial = slot_serial++; @@ -1794,6 +1796,11 @@ slot_new(struct opt *opt, unsigned int id, char *who, ; /* nothing */ s->unit = i; s->id = id; + s->opt = opt; + slot_ctlname(s, ctl_name, CTL_NAMEMAX); + ctl_new(CTL_SLOT_LEVEL, s, NULL, + CTL_NUM, "app", ctl_name, -1, "level", + NULL, -1, 127, s->vol); found: if ((mode & MODE_REC) && (opt->mode & MODE_MON)) { @@ -1829,7 +1836,6 @@ found: s->appbufsz = s->opt->dev->bufsz; s->round = s->opt->dev->round; s->rate = s->opt->dev->rate; - dev_label(s->opt->dev, s - slot_array); dev_midi_slotdesc(s->opt->dev, s); dev_midi_vol(s->opt->dev, s); #ifdef DEBUG @@ -2591,28 +2597,3 @@ dev_ctlsync(struct dev *d) } } -void -dev_label(struct dev *d, int i) -{ - struct ctl *c; - char name[CTL_NAMEMAX]; - - slot_ctlname(&slot_array[i], name, CTL_NAMEMAX); - - c = ctl_list; - for (;;) { - if (c == NULL) { - ctl_new(CTL_SLOT_LEVEL, slot_array + i, NULL, - CTL_NUM, "app", name, -1, "level", - NULL, -1, 127, slot_array[i].vol); - return; - } - if (ctl_match(c, CTL_SLOT_LEVEL, slot_array + i, NULL)) - break; - c = c->next; - } - if (strcmp(c->node0.name, name) == 0) - return; - strlcpy(c->node0.name, name, CTL_NAMEMAX); - c->desc_mask = ~0; -}