summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Ratchov <ratchov@cvs.openbsd.org>2021-03-10 08:22:26 +0000
committerAlexandre Ratchov <ratchov@cvs.openbsd.org>2021-03-10 08:22:26 +0000
commitcb903f575ecd4b1e917c41cf2a60b844f7107424 (patch)
treef14d169f11e6fa6543e57162829d5133ed9e45cd
parenta7f440a7fa8ec890eb937a1c075583b1ef1a42bb (diff)
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.
-rw-r--r--usr.bin/sndiod/dev.c35
1 files changed, 8 insertions, 27 deletions
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 <alex@caoua.org>
*
@@ -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;
-}