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.
This commit is contained in:
Alexandre Ratchov 2021-03-08 06:38:48 +01:00
parent 302865ddd8
commit 6869540f3b
1 changed files with 7 additions and 26 deletions

View File

@ -1712,6 +1712,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;
@ -1786,6 +1787,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++;
@ -1793,6 +1795,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)) {
@ -1828,7 +1835,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
@ -2588,28 +2594,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;
}