-/* $OpenBSD: dev.c,v 1.88 2021/01/29 11:36:44 ratchov Exp $ */
+/* $OpenBSD: dev.c,v 1.89 2021/01/29 11:38:23 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
slot_array[i].unit = i;
slot_array[i].ops = NULL;
slot_array[i].vol = MIDI_MAXCTL;
- slot_array[i].dev = NULL;
+ slot_array[i].opt = NULL;
slot_array[i].serial = slot_serial++;
memset(slot_array[i].name, 0, SLOT_NAMEMAX);
}
x.dev = SYSEX_DEV_ANY;
x.id0 = SYSEX_AUCAT;
x.id1 = SYSEX_AUCAT_SLOTDESC;
- if (*s->name != '\0')
+ if (s->opt != NULL && s->opt->dev == d)
slot_ctlname(s, (char *)x.u.slotdesc.name, SYSEX_NAMELEN);
x.u.slotdesc.chan = (s - slot_array);
x.u.slotdesc.end = SYSEX_END;
dev_midi_master(d);
for (i = 0, s = slot_array; i < DEV_NSLOT; i++, s++) {
- if (s->dev != d)
+ if (s->opt != NULL && s->opt->dev != d)
continue;
dev_midi_slotdesc(d, s);
dev_midi_vol(d, s);
chan = msg[0] & MIDI_CHANMASK;
if (chan >= DEV_NSLOT)
return;
- if (slot_array[chan].dev != d)
+ if (slot_array[chan].opt == NULL ||
+ slot_array[chan].opt->dev != d)
return;
slot_setvol(slot_array + chan, msg[2]);
dev_onval(d, CTLADDR_SLOT_LEVEL(chan), msg[2]);
return 0;
for (i = 0, s = slot_array; i < DEV_NSLOT; i++, s++) {
- if (s->dev != d || s->name[0] == 0)
+ if (s->opt == NULL || s->opt->dev != d || s->name[0] == 0)
continue;
slot_ctlname(s, name, CTL_NAMEMAX);
dev_addctl(d, "app", CTL_NUM,
struct ctlslot *c;
for (i = 0, s = slot_array; i < DEV_NSLOT; i++, s++) {
- if (s->dev != d)
+ if (s->opt == NULL || s->opt->dev != d)
continue;
- if (s->ops)
+ if (s->ops) {
s->ops->exit(s->arg);
- s->ops = NULL;
+ s->ops = NULL;
+ }
}
d->slot_list = NULL;
for (c = ctlslot_array, i = DEV_NCTLSLOT; i > 0; i--, c++) {
if (c->opt->dev != d)
continue;
- if (c->ops)
+ if (c->ops) {
c->ops->exit(c->arg);
- c->ops = NULL;
+ c->ops = NULL;
+ }
}
midi_abort(d->midi);
}
for (i = 0, s = slot_array; i < DEV_NSLOT; i++, s++) {
- if (s->dev != d || !s->ops || !s->opt->mmc)
+ if (s->opt == NULL || s->opt->dev != d || !s->ops || !s->opt->mmc)
continue;
if (s->pstate != SLOT_READY) {
#ifdef DEBUG
return;
for (i = 0, s = slot_array; i < DEV_NSLOT; i++, s++) {
- if (s->dev != d || !s->ops || !s->opt->mmc)
+ if (s->opt == NULL || s->opt->dev != d || !s->ops || !s->opt->mmc)
continue;
slot_attach(s);
s->pstate = SLOT_RUN;
slot_initconv(struct slot *s)
{
unsigned int dev_nch;
- struct dev *d = s->dev;
+ struct dev *d = s->opt->dev;
if (s->mode & MODE_PLAY) {
cmap_init(&s->mix.cmap,
void
slot_allocbufs(struct slot *s)
{
- struct dev *d = s->dev;
+ struct dev *d = s->opt->dev;
if (s->mode & MODE_PLAY) {
s->mix.bpf = s->par.bps * s->mix.nch;
* allocate a new slot and register the given call-backs
*/
struct slot *
-slot_new(struct dev *d, struct opt *opt, unsigned int id, char *who,
+slot_new(struct opt *opt, unsigned int id, char *who,
struct slotops *ops, void *arg, int mode)
{
char *p;
slot_log(s);
log_puts(": requested mode not allowed\n");
}
- return 0;
+ return NULL;
}
- if (!dev_ref(d))
+ if (!dev_ref(opt->dev))
return NULL;
- dev_label(d, s - slot_array);
- if ((mode & d->mode) != mode) {
+ if ((mode & opt->dev->mode) != mode) {
if (log_level >= 1) {
slot_log(s);
log_puts(": requested mode not supported\n");
}
- dev_unref(d);
+ dev_unref(opt->dev);
return NULL;
}
- s->dev = d;
s->opt = opt;
s->ops = ops;
s->arg = arg;
if (s->mode & MODE_RECMASK)
s->sub.nch = s->opt->rmax - s->opt->rmin + 1;
s->xrun = s->opt->mmc ? XRUN_SYNC : XRUN_IGNORE;
- s->appbufsz = d->bufsz;
- s->round = d->round;
- s->rate = d->rate;
- dev_midi_slotdesc(d, s);
- dev_midi_vol(d, s);
+ 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
if (log_level >= 3) {
slot_log(s);
log_puts(": using ");
- dev_log(d);
+ dev_log(s->opt->dev);
log_puts(".");
- log_puts(opt->name);
+ log_puts(s->opt->name);
log_puts(", mode = ");
log_putx(mode);
log_puts("\n");
slot_stop(s, 0);
break;
}
- dev_unref(s->dev);
- s->dev = NULL;
+ dev_unref(s->opt->dev);
}
/*
void
slot_attach(struct slot *s)
{
- struct dev *d = s->dev;
+ struct dev *d = s->opt->dev;
long long pos;
/*
* device may be disconnected, and if so we're called from
* slot->ops->exit() on a closed device
*/
- if (s->dev->pstate == DEV_CFG)
+ if (s->opt->dev->pstate == DEV_CFG)
return;
if (!s->opt->mmc) {
slot_attach(s);
s->pstate = SLOT_RUN;
} else
- dev_sync_attach(s->dev);
+ dev_sync_attach(s->opt->dev);
}
/*
void
slot_start(struct slot *s)
{
- struct dev *d = s->dev;
+ struct dev *d = s->opt->dev;
#ifdef DEBUG
if (s->pstate != SLOT_INIT) {
slot_log(s);
slot_detach(struct slot *s)
{
struct slot **ps;
- struct dev *d = s->dev;
+ struct dev *d = s->opt->dev;
long long pos;
for (ps = &d->slot_list; *ps != s; ps = &(*ps)->next) {
} else {
num = addr - CTLADDR_SLOT_LEVEL(0);
s = slot_array + num;
- if (s->dev != d)
+ if (s->opt->dev != d)
return 1;
slot_setvol(s, val);
dev_midi_vol(d, s);
-/* $OpenBSD: dev.h,v 1.36 2021/01/29 11:36:44 ratchov Exp $ */
+/* $OpenBSD: dev.h,v 1.37 2021/01/29 11:38:23 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
struct slot {
struct slotops *ops; /* client callbacks */
struct slot *next; /* next on the play list */
- struct dev *dev; /* device this belongs to */
struct opt *opt; /* config used */
void *arg; /* user data for callbacks */
struct aparams par; /* socket side params */
int xrun; /* underrun policy */
int skip; /* cycles to skip (for xrun) */
#define SLOT_BUFSZ(s) \
- ((s)->appbufsz + (s)->dev->bufsz / (s)->dev->round * (s)->round)
+ ((s)->appbufsz + (s)->opt->dev->bufsz / (s)->opt->dev->round * (s)->round)
int appbufsz; /* slot-side buffer size */
int round; /* slot-side block size */
int rate; /* slot-side sample rate */
* sio_open(3) like interface for clients
*/
void slot_log(struct slot *);
-struct slot *slot_new(struct dev *, struct opt *, unsigned int, char *,
+struct slot *slot_new(struct opt *, unsigned int, char *,
struct slotops *, void *, int);
void slot_del(struct slot *);
void slot_setvol(struct slot *, unsigned int);
-/* $OpenBSD: sock.c,v 1.40 2021/01/29 11:36:44 ratchov Exp $ */
+/* $OpenBSD: sock.c,v 1.41 2021/01/29 11:38:23 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
sock_setpar(struct sock *f)
{
struct slot *s = f->slot;
- struct dev *d = s->dev;
+ struct dev *d = s->opt->dev;
struct amsg_par *p = &f->rmsg.u.par;
unsigned int min, max;
uint32_t rate, appbufsz;
opt = opt_byname(d, p->opt);
if (opt == NULL)
return 0;
- f->slot = slot_new(d, opt, id, p->who, &sock_slotops, f, mode);
+ f->slot = slot_new(opt, id, p->who, &sock_slotops, f, mode);
if (f->slot == NULL)
return 0;
f->midi = NULL;
f->rstate = SOCK_RMSG;
f->lastvol = ctl; /* dont trigger feedback message */
slot_setvol(s, ctl);
- dev_midi_vol(s->dev, s);
- dev_onval(s->dev,
+ dev_midi_vol(s->opt->dev, s);
+ dev_onval(s->opt->dev,
CTLADDR_SLOT_LEVEL(f->slot - slot_array), ctl);
break;
case AMSG_CTLSUB: