summaryrefslogtreecommitdiff
path: root/usr.bin/sndiod/dev.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/sndiod/dev.c')
-rw-r--r--usr.bin/sndiod/dev.c90
1 files changed, 55 insertions, 35 deletions
diff --git a/usr.bin/sndiod/dev.c b/usr.bin/sndiod/dev.c
index 1a98fa39fc7..a221558f512 100644
--- a/usr.bin/sndiod/dev.c
+++ b/usr.bin/sndiod/dev.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dev.c,v 1.83 2021/01/28 11:17:58 ratchov Exp $ */
+/* $OpenBSD: dev.c,v 1.84 2021/01/29 10:51:24 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -109,6 +109,24 @@ struct slotops zomb_slotops = {
struct dev *dev_list = NULL;
unsigned int dev_sndnum = 0;
+struct slot slot_array[DEV_NSLOT];
+unsigned int slot_serial; /* for slot allocation */
+
+void
+slot_array_init(void)
+{
+ unsigned int i;
+
+ for (i = 0; i < DEV_NSLOT; i++) {
+ slot_array[i].unit = i;
+ slot_array[i].ops = NULL;
+ slot_array[i].vol = MIDI_MAXCTL;
+ slot_array[i].dev = NULL;
+ slot_array[i].serial = slot_serial++;
+ memset(slot_array[i].name, 0, SLOT_NAMEMAX);
+ }
+}
+
void
dev_log(struct dev *d)
{
@@ -331,7 +349,7 @@ dev_midi_vol(struct dev *d, struct slot *s)
{
unsigned char msg[3];
- msg[0] = MIDI_CTL | (s - d->slot);
+ msg[0] = MIDI_CTL | (s - slot_array);
msg[1] = MIDI_CTL_VOL;
msg[2] = s->vol;
midi_send(d->midi, msg, 3);
@@ -391,7 +409,7 @@ dev_midi_slotdesc(struct dev *d, struct slot *s)
x.id1 = SYSEX_AUCAT_SLOTDESC;
if (*s->name != '\0')
slot_ctlname(s, (char *)x.u.slotdesc.name, SYSEX_NAMELEN);
- x.u.slotdesc.chan = s - d->slot;
+ x.u.slotdesc.chan = (s - slot_array);
x.u.slotdesc.end = SYSEX_END;
midi_send(d->midi, (unsigned char *)&x, SYSEX_SIZE(slotdesc));
}
@@ -404,7 +422,9 @@ dev_midi_dump(struct dev *d)
int i;
dev_midi_master(d);
- for (i = 0, s = d->slot; i < DEV_NSLOT; i++, s++) {
+ for (i = 0, s = slot_array; i < DEV_NSLOT; i++, s++) {
+ if (s->dev != d)
+ continue;
dev_midi_slotdesc(d, s);
dev_midi_vol(d, s);
}
@@ -440,7 +460,9 @@ dev_midi_omsg(void *arg, unsigned char *msg, int len)
chan = msg[0] & MIDI_CHANMASK;
if (chan >= DEV_NSLOT)
return;
- slot_setvol(d->slot + chan, msg[2]);
+ if (slot_array[chan].dev != d)
+ return;
+ slot_setvol(slot_array + chan, msg[2]);
dev_onval(d, CTLADDR_SLOT_LEVEL(chan), msg[2]);
return;
}
@@ -1044,14 +1066,6 @@ dev_new(char *path, struct aparams *par,
d->autovol = autovol;
d->refcnt = 0;
d->pstate = DEV_CFG;
- d->serial = 0;
- for (i = 0; i < DEV_NSLOT; i++) {
- d->slot[i].unit = i;
- d->slot[i].ops = NULL;
- d->slot[i].vol = MIDI_MAXCTL;
- d->slot[i].serial = d->serial++;
- memset(d->slot[i].name, 0, SLOT_NAMEMAX);
- }
for (i = 0; i < DEV_NCTLSLOT; i++) {
d->ctlslot[i].ops = NULL;
d->ctlslot[i].dev = d;
@@ -1203,6 +1217,7 @@ dev_open(struct dev *d)
int i;
char name[CTL_NAMEMAX];
struct dev_alt *a;
+ struct slot *s;
d->master_enabled = 0;
d->mode = d->reqmode;
@@ -1226,14 +1241,14 @@ dev_open(struct dev *d)
if (!dev_allocbufs(d))
return 0;
- for (i = 0; i < DEV_NSLOT; i++) {
- if (d->slot[i].name[0] == 0)
+ for (i = 0, s = slot_array; i < DEV_NSLOT; i++, s++) {
+ if (s->dev != d || s->name[0] == 0)
continue;
- slot_ctlname(&d->slot[i], name, CTL_NAMEMAX);
+ slot_ctlname(s, name, CTL_NAMEMAX);
dev_addctl(d, "app", CTL_NUM,
CTLADDR_SLOT_LEVEL(i),
name, -1, "level",
- NULL, -1, 127, d->slot[i].vol);
+ NULL, -1, 127, s->vol);
}
/* if there are multiple alt devs, add server.device knob */
@@ -1261,7 +1276,9 @@ dev_abort(struct dev *d)
struct slot *s;
struct ctlslot *c;
- for (s = d->slot, i = DEV_NSLOT; i > 0; i--, s++) {
+ for (i = 0, s = slot_array; i < DEV_NSLOT; i++, s++) {
+ if (s->dev != d)
+ continue;
if (s->ops)
s->ops->exit(s->arg);
s->ops = NULL;
@@ -1562,9 +1579,9 @@ dev_sync_attach(struct dev *d)
}
return;
}
- for (i = 0; i < DEV_NSLOT; i++) {
- s = d->slot + i;
- if (!s->ops || !s->opt->mmc)
+
+ for (i = 0, s = slot_array; i < DEV_NSLOT; i++, s++) {
+ if (s->dev != d || !s->ops || !s->opt->mmc)
continue;
if (s->pstate != SLOT_READY) {
#ifdef DEBUG
@@ -1578,9 +1595,9 @@ dev_sync_attach(struct dev *d)
}
if (!dev_ref(d))
return;
- for (i = 0; i < DEV_NSLOT; i++) {
- s = d->slot + i;
- if (!s->ops || !s->opt->mmc)
+
+ for (i = 0, s = slot_array; i < DEV_NSLOT; i++, s++) {
+ if (s->dev != d || !s->ops || !s->opt->mmc)
continue;
slot_attach(s);
s->pstate = SLOT_RUN;
@@ -1845,8 +1862,7 @@ slot_new(struct dev *d, struct opt *opt, unsigned int id, char *who,
*/
for (i = 0; i < DEV_NSLOT; i++)
unit[i] = NULL;
- for (i = 0; i < DEV_NSLOT; i++) {
- s = d->slot + i;
+ for (i = 0, s = slot_array; i < DEV_NSLOT; i++, s++) {
if (strcmp(s->name, name) == 0)
unit[s->unit] = s;
}
@@ -1877,20 +1893,20 @@ slot_new(struct dev *d, struct opt *opt, unsigned int id, char *who,
*/
bestser = 0;
bestidx = DEV_NSLOT;
- for (i = 0, s = d->slot; i < DEV_NSLOT; i++, s++) {
+ for (i = 0, s = slot_array; i < DEV_NSLOT; i++, s++) {
if (s->ops != NULL)
continue;
- ser = d->serial - s->serial;
+ ser = slot_serial - s->serial;
if (ser > bestser) {
bestser = ser;
bestidx = i;
}
}
if (bestidx != DEV_NSLOT) {
- s = d->slot + bestidx;
+ s = slot_array + bestidx;
s->vol = MIDI_MAXCTL;
strlcpy(s->name, name, SLOT_NAMEMAX);
- s->serial = d->serial++;
+ s->serial = slot_serial++;
for (i = 0; unit[i] != NULL; i++)
; /* nothing */
s->unit = i;
@@ -1918,7 +1934,7 @@ found:
}
if (!dev_ref(d))
return NULL;
- dev_label(d, s - d->slot);
+ dev_label(d, s - slot_array);
if ((mode & d->mode) != mode) {
if (log_level >= 1) {
slot_log(s);
@@ -2505,6 +2521,7 @@ int
dev_setctl(struct dev *d, int addr, int val)
{
struct ctl *c;
+ struct slot *s;
int num;
c = d->ctl_list;
@@ -2559,8 +2576,11 @@ dev_setctl(struct dev *d, int addr, int val)
}
} else {
num = addr - CTLADDR_SLOT_LEVEL(0);
- slot_setvol(d->slot + num, val);
- dev_midi_vol(d, d->slot + num);
+ s = slot_array + num;
+ if (s->dev != d)
+ return 1;
+ slot_setvol(s, val);
+ dev_midi_vol(d, s);
}
c->val_mask = ~0U;
}
@@ -2592,7 +2612,7 @@ dev_label(struct dev *d, int i)
struct ctl *c;
char name[CTL_NAMEMAX];
- slot_ctlname(&d->slot[i], name, CTL_NAMEMAX);
+ slot_ctlname(&slot_array[i], name, CTL_NAMEMAX);
c = d->ctl_list;
for (;;) {
@@ -2600,7 +2620,7 @@ dev_label(struct dev *d, int i)
dev_addctl(d, "app", CTL_NUM,
CTLADDR_SLOT_LEVEL(i),
name, -1, "level",
- NULL, -1, 127, d->slot[i].vol);
+ NULL, -1, 127, slot_array[i].vol);
return;
}
if (c->addr == CTLADDR_SLOT_LEVEL(i))