diff options
author | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2009-08-19 05:54:16 +0000 |
---|---|---|
committer | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2009-08-19 05:54:16 +0000 |
commit | 51981d62fa8b7abd8c45c2c2a89289815d32e08e (patch) | |
tree | 91390bf7bb03d854164e7aef8c5928c1309df617 /usr.bin | |
parent | daaacba46fd094ed7a3ab2731d784cd6f24953b0 (diff) |
organize midi code like audio code, no functional change
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/aucat/aucat.c | 40 | ||||
-rw-r--r-- | usr.bin/aucat/dev.c | 57 | ||||
-rw-r--r-- | usr.bin/aucat/dev.h | 7 | ||||
-rw-r--r-- | usr.bin/aucat/midi.c | 4 | ||||
-rw-r--r-- | usr.bin/aucat/sock.c | 11 |
5 files changed, 73 insertions, 46 deletions
diff --git a/usr.bin/aucat/aucat.c b/usr.bin/aucat/aucat.c index ac3fb7ee743..699bcd10989 100644 --- a/usr.bin/aucat/aucat.c +++ b/usr.bin/aucat/aucat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aucat.c,v 1.64 2009/08/17 16:17:46 ratchov Exp $ */ +/* $OpenBSD: aucat.c,v 1.65 2009/08/19 05:54:15 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -317,18 +317,13 @@ newmidi(struct farg *fa, int in, int out) rproc = rpipe_new(dev); rbuf = abuf_new(MIDI_BUFSZ, &aparams_none); aproc_setout(rproc, rbuf); - aproc_setin(thrubox, rbuf); } if (out) { wproc = wpipe_new(dev); wbuf = abuf_new(MIDI_BUFSZ, &aparams_none); aproc_setin(wproc, wbuf); - aproc_setout(thrubox, wbuf); - if (in) { - rbuf->duplex = wbuf; - wbuf->duplex = rbuf; - } } + dev_midiattach(rbuf, wbuf); } void @@ -701,7 +696,7 @@ midicat_main(int argc, char **argv) struct farglist dfiles, ifiles, ofiles; char base[PATH_MAX], path[PATH_MAX]; struct farg *fa; - struct file *stdx, *f; + struct file *stdx; struct aproc *p; struct abuf *buf; @@ -759,9 +754,7 @@ midicat_main(int argc, char **argv) setsig(); filelist_init(); - thrubox = thru_new("thru"); - thrubox->refs++; - + dev_thruinit(); if ((!SLIST_EMPTY(&ifiles) || !SLIST_EMPTY(&ofiles)) && SLIST_EMPTY(&dfiles)) { farg_add(&dfiles, &aparams_none, &aparams_none, @@ -798,7 +791,7 @@ midicat_main(int argc, char **argv) p = rpipe_new(stdx); buf = abuf_new(MIDI_BUFSZ, &aparams_none); aproc_setout(p, buf); - aproc_setin(thrubox, buf); + dev_midiattach(buf, NULL); free(fa); } while (!SLIST_EMPTY(&ofiles)) { @@ -818,7 +811,7 @@ midicat_main(int argc, char **argv) p = wpipe_new(stdx); buf = abuf_new(MIDI_BUFSZ, &aparams_none); aproc_setin(p, buf); - aproc_setout(thrubox, buf); + dev_midiattach(NULL, buf); free(fa); } @@ -829,7 +822,7 @@ midicat_main(int argc, char **argv) if (quit_flag) { break; } - if (!l_flag && LIST_EMPTY(&thrubox->ibuflist)) + if (!l_flag && LIST_EMPTY(&dev_midi->ibuflist)) break; if (!file_poll()) break; @@ -839,24 +832,7 @@ midicat_main(int argc, char **argv) if (rmdir(base) < 0) warn("rmdir(\"%s\")", base); } - if (thrubox) { - restart_thrubox: - LIST_FOREACH(f, &file_list, entry) { - if (f->rproc && aproc_depend(thrubox, f->rproc)) { - file_eof(f); - goto restart_thrubox; - } - } - while (!LIST_EMPTY(&thrubox->ibuflist)) { - if (!file_poll()) - break; - } - thrubox->refs--; - aproc_del(thrubox); - thrubox = NULL; - while (file_poll()) - ; /* nothing */ - } + dev_thrudone(); filelist_done(); unsetsig(); return 0; diff --git a/usr.bin/aucat/dev.c b/usr.bin/aucat/dev.c index 097838d6e5e..3fde1b2905f 100644 --- a/usr.bin/aucat/dev.c +++ b/usr.bin/aucat/dev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dev.c,v 1.27 2009/07/25 10:52:18 ratchov Exp $ */ +/* $OpenBSD: dev.c,v 1.28 2009/08/19 05:54:15 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -25,10 +25,65 @@ #include "dev.h" #include "pipe.h" #include "safile.h" +#include "midi.h" unsigned dev_bufsz, dev_round, dev_rate; struct aparams dev_ipar, dev_opar; struct aproc *dev_mix, *dev_sub, *dev_rec, *dev_play; +struct aproc *dev_midi; + +/* + * Create a MIDI thru box as the MIDI end of the device + */ +void +dev_thruinit(void) +{ + dev_midi = thru_new("thru"); + dev_midi->refs++; +} + +/* + * Terminate the MIDI thru box + */ +void +dev_thrudone(void) +{ + struct file *f; + + restart: + LIST_FOREACH(f, &file_list, entry) { + if (f->rproc && aproc_depend(dev_midi, f->rproc)) { + file_eof(f); + goto restart; + } + } + while (!LIST_EMPTY(&dev_midi->ibuflist)) { + if (!file_poll()) + break; + } + dev_midi->refs--; + aproc_del(dev_midi); + dev_midi = NULL; + while (file_poll()) + ; /* nothing */ +} + +/* + * Attach a bi-directional MIDI stream to the MIDI device + */ +void +dev_midiattach(struct abuf *ibuf, struct abuf *obuf) +{ + if (ibuf) + aproc_setin(dev_midi, ibuf); + if (obuf) { + aproc_setout(dev_midi, obuf); + if (ibuf) { + ibuf->duplex = obuf; + obuf->duplex = ibuf; + } + } +} /* * Same as dev_init(), but create a fake device that records what is diff --git a/usr.bin/aucat/dev.h b/usr.bin/aucat/dev.h index 5de327e2ed3..e62553c0b8f 100644 --- a/usr.bin/aucat/dev.h +++ b/usr.bin/aucat/dev.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dev.h,v 1.11 2009/07/25 10:52:19 ratchov Exp $ */ +/* $OpenBSD: dev.h,v 1.12 2009/08/19 05:54:15 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -24,8 +24,11 @@ struct abuf; extern unsigned dev_bufsz, dev_round, dev_rate; extern unsigned dev_rate_div, dev_round_div; extern struct aparams dev_ipar, dev_opar; -extern struct aproc *dev_mix, *dev_sub, *dev_rec, *dev_play; +extern struct aproc *dev_mix, *dev_sub, *dev_rec, *dev_play, *dev_midi; +void dev_thruinit(void); +void dev_thrudone(void); +void dev_midiattach(struct abuf *, struct abuf *); unsigned dev_roundof(unsigned); void dev_loopinit(struct aparams *, struct aparams *, unsigned); void dev_loopdone(void); diff --git a/usr.bin/aucat/midi.c b/usr.bin/aucat/midi.c index c9889992b94..58bfd6feaaa 100644 --- a/usr.bin/aucat/midi.c +++ b/usr.bin/aucat/midi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: midi.c,v 1.1 2009/07/25 08:44:27 ratchov Exp $ */ +/* $OpenBSD: midi.c,v 1.2 2009/08/19 05:54:15 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -41,8 +41,6 @@ #define MIDITHRU_XFER 340 #define MIDITHRU_TIMO 100000 -struct aproc *thrubox = NULL; - unsigned voice_len[] = { 3, 3, 3, 3, 2, 2, 3 }; unsigned common_len[] = { 0, 2, 3, 2, 0, 0, 1, 1 }; diff --git a/usr.bin/aucat/sock.c b/usr.bin/aucat/sock.c index 504349b4bf0..79f0aa092ca 100644 --- a/usr.bin/aucat/sock.c +++ b/usr.bin/aucat/sock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sock.c,v 1.22 2009/08/17 16:17:46 ratchov Exp $ */ +/* $OpenBSD: sock.c,v 1.23 2009/08/19 05:54:15 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -720,17 +720,12 @@ sock_midiattach(struct sock *f, unsigned mode) if (mode & AMSG_MIDIOUT) { rbuf = abuf_new(MIDI_BUFSZ, &aparams_none); aproc_setout(f->pipe.file.rproc, rbuf); - aproc_setin(thrubox, rbuf); } if (mode & AMSG_MIDIIN) { wbuf = abuf_new(MIDI_BUFSZ, &aparams_none); aproc_setin(f->pipe.file.wproc, wbuf); - aproc_setout(thrubox, wbuf); - if (mode & AMSG_MIDIOUT) { - rbuf->duplex = wbuf; - wbuf->duplex = rbuf; - } } + dev_midiattach(rbuf, wbuf); } int @@ -740,7 +735,7 @@ sock_hello(struct sock *f) DPRINTF("sock_hello: from <%s>, mode = %x\n", p->who, p->proto); - if (thrubox && (p->proto & (AMSG_MIDIIN | AMSG_MIDIOUT))) { + if (dev_midi && (p->proto & (AMSG_MIDIIN | AMSG_MIDIOUT))) { if (p->proto & ~(AMSG_MIDIIN | AMSG_MIDIOUT)) { DPRINTF("sock_hello: %x: bad proto\n", p->proto); return 0; |