=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/aucat/Attic/sock.c,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- src/usr.bin/aucat/Attic/sock.c 2009/08/21 16:48:03 1.24 +++ src/usr.bin/aucat/Attic/sock.c 2009/08/26 06:10:15 1.25 @@ -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 * @@ -301,7 +301,7 @@ 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 @@ } /* - * 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 @@ (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 @@ 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 @@ 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); @@ -997,6 +1000,20 @@ f->wstate = SOCK_WMSG; f->delta = 0; f->tickpending = 0; + return 1; + } + + /* + * 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; }