summaryrefslogtreecommitdiff
path: root/usr.bin/aucat
diff options
context:
space:
mode:
authorAlexandre Ratchov <ratchov@cvs.openbsd.org>2009-08-26 06:10:16 +0000
committerAlexandre Ratchov <ratchov@cvs.openbsd.org>2009-08-26 06:10:16 +0000
commit1e78dc2f8b840876b9df843f3496de43b308ca7d (patch)
treecb643c412072875d8d91234ddee0d1d76de7f3e7 /usr.bin/aucat
parentfdfcad50cd46134e6b15b4f18ae4ac7e1975b83e (diff)
don't mess with audio internals from within the midi bits. Instead
use a call-back interface. This allows easily sending volume changes feedback to audio applications.
Diffstat (limited to 'usr.bin/aucat')
-rw-r--r--usr.bin/aucat/aproc.h5
-rw-r--r--usr.bin/aucat/midi.c37
-rw-r--r--usr.bin/aucat/midi.h4
-rw-r--r--usr.bin/aucat/sock.c33
-rw-r--r--usr.bin/aucat/sock.h3
5 files changed, 51 insertions, 31 deletions
diff --git a/usr.bin/aucat/aproc.h b/usr.bin/aucat/aproc.h
index 353fc593dc4..6911d849473 100644
--- a/usr.bin/aucat/aproc.h
+++ b/usr.bin/aucat/aproc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: aproc.h,v 1.19 2009/08/21 16:48:03 ratchov Exp $ */
+/* $OpenBSD: aproc.h,v 1.20 2009/08/26 06:10:15 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -170,7 +170,8 @@ struct aproc {
#define CTL_NSLOT 8
#define CTL_NAMEMAX 8
struct ctl_slot {
- struct aproc *owner;
+ void (*cb)(void *, unsigned);
+ void *arg;
unsigned unit;
char name[CTL_NAMEMAX];
} slot[CTL_NSLOT];
diff --git a/usr.bin/aucat/midi.c b/usr.bin/aucat/midi.c
index 766054de53c..f93f05d2a43 100644
--- a/usr.bin/aucat/midi.c
+++ b/usr.bin/aucat/midi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: midi.c,v 1.4 2009/08/23 13:40:45 ratchov Exp $ */
+/* $OpenBSD: midi.c,v 1.5 2009/08/26 06:10:15 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -325,7 +325,7 @@ ctl_sendmsg(struct aproc *p, struct abuf *ibuf, unsigned char *msg, unsigned len
}
int
-ctl_slotnew(struct aproc *p, char *reqname, struct aproc *owner)
+ctl_slotnew(struct aproc *p, char *who, void (*cb)(void *, unsigned), void *arg)
{
char *s;
struct ctl_slot *slot;
@@ -335,7 +335,7 @@ ctl_slotnew(struct aproc *p, char *reqname, struct aproc *owner)
/*
* create a ``valid'' control name (lowcase, remove [^a-z], trucate)
*/
- for (i = 0, s = reqname; ; s++) {
+ for (i = 0, s = who; ; s++) {
if (i == CTL_NAMEMAX - 1 || *s == '\0') {
name[i] = '\0';
break;
@@ -351,7 +351,7 @@ ctl_slotnew(struct aproc *p, char *reqname, struct aproc *owner)
* find the instance number of the control name
*/
for (i = 0, slot = p->u.ctl.slot; i < CTL_NSLOT; i++, slot++) {
- if (slot->owner == NULL)
+ if (slot->cb == NULL)
continue;
if (strcmp(slot->name, name) == 0)
umap |= (1 << i);
@@ -369,10 +369,11 @@ ctl_slotnew(struct aproc *p, char *reqname, struct aproc *owner)
* find a free controller slot with the same name/unit
*/
for (i = 0, slot = p->u.ctl.slot; i < CTL_NSLOT; i++, slot++) {
- if (slot->owner == NULL &&
+ if (slot->cb == NULL &&
strcmp(slot->name, name) == 0 &&
slot->unit == unit) {
- slot->owner = owner;
+ slot->cb = cb;
+ slot->arg = arg;
DPRINTFN(1, "ctl_newslot: reusing %u\n", i);
return i;
}
@@ -384,20 +385,21 @@ ctl_slotnew(struct aproc *p, char *reqname, struct aproc *owner)
for (i = 0, slot = p->u.ctl.slot; ; i++, slot++) {
if (i == CTL_NSLOT)
return -1;
- if (slot->owner == NULL)
+ if (slot->cb == NULL)
break;
}
DPRINTFN(1, "ctl_newslot: overwritten %u\n", i);
strlcpy(slot->name, name, CTL_NAMEMAX);
slot->unit = unit;
- slot->owner = owner;
+ slot->cb = cb;
+ slot->arg = arg;
return i;
}
void
ctl_slotdel(struct aproc *p, int index)
{
- p->u.ctl.slot[index].owner = NULL;
+ p->u.ctl.slot[index].cb = NULL;
}
void
@@ -417,7 +419,7 @@ ctl_ev(struct aproc *p, struct abuf *ibuf)
{
unsigned i;
unsigned chan;
- struct aproc *owner;
+ struct ctl_slot *slot;
#ifdef DEBUG
if (debug_level > 0) {
@@ -432,12 +434,10 @@ ctl_ev(struct aproc *p, struct abuf *ibuf)
chan = ibuf->mdata[0] & MIDI_CHANMASK;
if (chan >= CTL_NSLOT)
return;
- owner = p->u.ctl.slot[chan].owner;
- if (owner == NULL || LIST_EMPTY(&owner->obuflist))
+ slot = p->u.ctl.slot + chan;
+ if (slot->cb == NULL)
return;
- dev_setvol(
- LIST_FIRST(&owner->obuflist),
- MIDI_TO_ADATA(ibuf->mdata[2]));
+ slot->cb(slot->arg, ibuf->mdata[2]);
ctl_sendmsg(p, ibuf, ibuf->mdata, ibuf->mlen);
}
}
@@ -508,7 +508,7 @@ ctl_done(struct aproc *p)
struct ctl_slot *s;
for (i = 0, s = p->u.ctl.slot; i < CTL_NSLOT; i++, s++) {
- if (s->owner)
+ if (s->cb != NULL)
DPRINTF("ctl_done: %s%u not freed\n", s->name, s->unit);
}
}
@@ -530,12 +530,13 @@ struct aproc *
ctl_new(char *name)
{
struct aproc *p;
+ struct ctl_slot *s;
unsigned i;
p = aproc_new(&ctl_ops, name);
- for (i = 0; i < CTL_NSLOT; i++) {
+ for (i = 0, s = p->u.ctl.slot; i < CTL_NSLOT; i++, s++) {
p->u.ctl.slot[i].unit = i;
- p->u.ctl.slot[i].owner = NULL;
+ p->u.ctl.slot[i].cb = NULL;
strlcpy(p->u.ctl.slot[i].name, "unknown", CTL_NAMEMAX);
}
return p;
diff --git a/usr.bin/aucat/midi.h b/usr.bin/aucat/midi.h
index d48fbb2f3b6..74ba8389807 100644
--- a/usr.bin/aucat/midi.h
+++ b/usr.bin/aucat/midi.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: midi.h,v 1.2 2009/08/21 16:48:03 ratchov Exp $ */
+/* $OpenBSD: midi.h,v 1.3 2009/08/26 06:10:15 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -20,7 +20,7 @@
struct aproc *thru_new(char *);
struct aproc *ctl_new(char *);
-int ctl_slotnew(struct aproc *, char *, struct aproc *);
+int ctl_slotnew(struct aproc *, char *, void (*)(void *, unsigned), void *);
void ctl_slotdel(struct aproc *, int);
void ctl_slotvol(struct aproc *, int, unsigned);
diff --git a/usr.bin/aucat/sock.c b/usr.bin/aucat/sock.c
index 8e1cd9f551e..2fdfb13bb63 100644
--- a/usr.bin/aucat/sock.c
+++ b/usr.bin/aucat/sock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sock.c,v 1.24 2009/08/21 16:48:03 ratchov Exp $ */
+/* $OpenBSD: sock.c,v 1.25 2009/08/26 06:10:15 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -301,7 +301,7 @@ sock_new(struct fileops *ops, int fd)
f->round = dev_round;
f->delta = 0;
f->tickpending = 0;
- f->vol = ADATA_UNIT;
+ f->vol = f->lastvol = MIDI_MAXCTL;
f->slot = -1;
wproc = aproc_new(&wsock_ops, f->pipe.file.name);
@@ -363,20 +363,23 @@ sock_allocbuf(struct sock *f)
}
/*
- * Set volume.
+ * Set volume. Callback invoked when volume is modified externally
*/
void
-sock_setvol(struct sock *f, int vol)
+sock_setvol(void *arg, unsigned vol)
{
+ struct sock *f = (struct sock *)arg;
struct abuf *rbuf;
f->vol = vol;
+ if (f->pstate <= SOCK_START)
+ f->lastvol = f->vol;
rbuf = LIST_FIRST(&f->pipe.file.rproc->obuflist);
if (!rbuf) {
DPRINTF("sock_setvol: no read buffer yet\n");
return;
}
- dev_setvol(rbuf, vol);
+ dev_setvol(rbuf, MIDI_TO_ADATA(vol));
}
/*
@@ -408,7 +411,7 @@ sock_attach(struct sock *f, int force)
(f->mode & AMSG_REC) ? wbuf : NULL, &f->wpar, f->xrun,
f->opt->maxweight);
if (f->mode & AMSG_PLAY)
- dev_setvol(rbuf, f->vol);
+ dev_setvol(rbuf, MIDI_TO_ADATA(f->vol));
/*
* Send the initial position, if needed.
@@ -778,7 +781,7 @@ sock_hello(struct sock *f)
f->mode |= AMSG_REC;
}
if (dev_midi) {
- f->slot = ctl_slotnew(dev_midi, p->who, f->pipe.file.rproc);
+ f->slot = ctl_slotnew(dev_midi, p->who, sock_setvol, f);
if (f->slot < 0) {
DPRINTF("sock_hello: out of mixer slots\n");
return 0;
@@ -926,7 +929,7 @@ sock_execmsg(struct sock *f)
return 0;
}
DPRINTF("sock_execmsg: SETVOL %u\n", m->u.vol.ctl);
- sock_setvol(f, MIDI_TO_ADATA(m->u.vol.ctl));
+ sock_setvol(f, m->u.vol.ctl);
if (dev_midi && f->slot >= 0)
ctl_slotvol(dev_midi, f->slot, m->u.vol.ctl);
f->rtodo = sizeof(struct amsg);
@@ -1001,6 +1004,20 @@ sock_buildmsg(struct sock *f)
}
/*
+ * if volume changed build a SETVOL message
+ */
+ if (f->vol != f->lastvol) {
+ DPRINTFN(4, "sock_buildmsg: %p: SETVOL: %d\n", f, f->vol);
+ AMSG_INIT(&f->wmsg);
+ f->wmsg.cmd = AMSG_SETVOL;
+ f->wmsg.u.vol.ctl = f->vol;
+ f->wtodo = sizeof(struct amsg);
+ f->wstate = SOCK_WMSG;
+ f->lastvol = f->vol;
+ return 1;
+ }
+
+ /*
* If data available, build a DATA message.
*/
p = f->pipe.file.wproc;
diff --git a/usr.bin/aucat/sock.h b/usr.bin/aucat/sock.h
index 517264f3aee..3f6c1f5e6d5 100644
--- a/usr.bin/aucat/sock.h
+++ b/usr.bin/aucat/sock.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sock.h,v 1.9 2009/08/21 16:48:03 ratchov Exp $ */
+/* $OpenBSD: sock.h,v 1.10 2009/08/26 06:10:15 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -55,6 +55,7 @@ struct sock {
unsigned round; /* block size */
unsigned xrun; /* one of AMSG_IGNORE, ... */
int vol; /* requested volume */
+ int lastvol; /* last volume */
int slot; /* mixer ctl slot number */
struct opt *opt; /* "subdevice" definition */
};