diff options
author | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2011-06-20 20:18:45 +0000 |
---|---|---|
committer | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2011-06-20 20:18:45 +0000 |
commit | 2d5cc9e3a3a39bee477dd8511442616575a69eae (patch) | |
tree | 745b112917e4dd5823763d2ddb3459ca31fe6185 /usr.bin/aucat | |
parent | 7524ae50770c7f7b472558d9bfa36036d44ae25f (diff) |
Make -aoff option apply to MIDI ports (-q) as well, ensuring the device
stays closed also if -q is used. As we're at it, add -a to midicat so
it behaves like aucat.
Diffstat (limited to 'usr.bin/aucat')
-rw-r--r-- | usr.bin/aucat/aucat.1 | 5 | ||||
-rw-r--r-- | usr.bin/aucat/aucat.c | 24 | ||||
-rw-r--r-- | usr.bin/aucat/dev.c | 103 | ||||
-rw-r--r-- | usr.bin/aucat/dev.h | 11 | ||||
-rw-r--r-- | usr.bin/aucat/midicat.1 | 20 | ||||
-rw-r--r-- | usr.bin/aucat/miofile.c | 9 | ||||
-rw-r--r-- | usr.bin/aucat/miofile.h | 4 |
7 files changed, 118 insertions, 58 deletions
diff --git a/usr.bin/aucat/aucat.1 b/usr.bin/aucat/aucat.1 index bae846a6688..e7a63fea5b4 100644 --- a/usr.bin/aucat/aucat.1 +++ b/usr.bin/aucat/aucat.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: aucat.1,v 1.84 2011/06/03 16:20:10 ratchov Exp $ +.\" $OpenBSD: aucat.1,v 1.85 2011/06/20 20:18:44 ratchov Exp $ .\" .\" Copyright (c) 2006 Alexandre Ratchov <alex@caoua.org> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: June 3 2011 $ +.Dd $Mdocdate: June 20 2011 $ .Dt AUCAT 1 .Os .Sh NAME @@ -75,6 +75,7 @@ The options are as follows: Control whether .Nm opens the audio device only when needed or keeps it open all the time. +This applies to MIDI ports controlling the device as well. If the flag is .Va on then the device is kept open all the time, ensuring no other program can diff --git a/usr.bin/aucat/aucat.c b/usr.bin/aucat/aucat.c index 34c74f75ac8..83595262ac9 100644 --- a/usr.bin/aucat/aucat.c +++ b/usr.bin/aucat/aucat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aucat.c,v 1.117 2011/06/03 17:04:47 ratchov Exp $ */ +/* $OpenBSD: aucat.c,v 1.118 2011/06/20 20:18:44 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -341,7 +341,7 @@ void cfmid_add(struct cfmidlist *list, char *path) { struct cfmid *cm; - + cm = malloc(sizeof(struct cfmid)); if (cm == NULL) { perror("malloc"); @@ -751,8 +751,8 @@ aucat_main(int argc, char **argv) while (!SLIST_EMPTY(&cd->mids)) { cm = SLIST_FIRST(&cd->mids); SLIST_REMOVE_HEAD(&cd->mids, entry); - if (!dev_thruadd(d, cm->path, 1, 1)) - errx(1, "%s: can't open device", cm->path); + if (!devctl_add(d, cm->path, MODE_MIDIMASK)) + errx(1, "%s: can't open port", cm->path); free(cm); } @@ -869,8 +869,9 @@ aucat_main(int argc, char **argv) void midicat_usage(void) { - (void)fputs("usage: " PROG_MIDICAT " [-dl] " - "[-i file] [-L addr] [-o file] [-q port] [-s name] [-U unit]\n", + (void)fputs("usage: " PROG_MIDICAT " [-dl] [-a flag] " + "[-i file] [-L addr] [-o file] [-q port]\n\t" + "[-s name] [-U unit]\n", stderr); } @@ -908,7 +909,7 @@ midicat_main(int argc, char **argv) cs = cfstr_new(NULL); cd = cfdev_new(NULL); - while ((c = getopt(argc, argv, "di:o:ls:q:U:L:")) != -1) { + while ((c = getopt(argc, argv, "di:o:ls:a:q:U:L:")) != -1) { switch (c) { case 'd': #ifdef DEBUG @@ -925,6 +926,9 @@ midicat_main(int argc, char **argv) cfstr_add(&cd->outs, cs, optarg); cs = cfstr_new(cs); break; + case 'a': + cd->hold = opt_onoff(); + break; case 'q': cfmid_add(&cd->mids, optarg); break; @@ -1001,7 +1005,7 @@ midicat_main(int argc, char **argv) cd = SLIST_FIRST(&cfdevs); SLIST_REMOVE_HEAD(&cfdevs, entry); - d = dev_new_thru(); + d = dev_new_thru(cd->hold); if (d == NULL) errx(1, "%s: can't open device", cd->path); if (SLIST_EMPTY(&cd->opts) && APROC_OK(d->midi)) @@ -1013,8 +1017,8 @@ midicat_main(int argc, char **argv) while (!SLIST_EMPTY(&cd->mids)) { cm = SLIST_FIRST(&cd->mids); SLIST_REMOVE_HEAD(&cd->mids, entry); - if (!dev_thruadd(d, cm->path, 1, 1)) - errx(1, "%s: can't open device", cm->path); + if (!devctl_add(d, cm->path, MODE_MIDIMASK)) + errx(1, "%s: can't open port", cm->path); free(cm); } diff --git a/usr.bin/aucat/dev.c b/usr.bin/aucat/dev.c index 86ae039516f..d674f2454ac 100644 --- a/usr.bin/aucat/dev.c +++ b/usr.bin/aucat/dev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dev.c,v 1.65 2011/05/26 07:18:40 ratchov Exp $ */ +/* $OpenBSD: dev.c,v 1.66 2011/06/20 20:18:44 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -105,6 +105,7 @@ void dev_close(struct dev *); void dev_start(struct dev *); void dev_stop(struct dev *); void dev_clear(struct dev *); +int devctl_open(struct dev *, struct devctl *); struct dev *dev_list = NULL; @@ -123,6 +124,7 @@ dev_new_sio(char *path, perror("malloc"); exit(1); } + d->ctl_list = NULL; d->path = path; d->reqmode = mode; if (mode & MODE_PLAY) @@ -158,6 +160,7 @@ dev_new_loop(struct aparams *dipar, struct aparams *dopar, unsigned bufsz) perror("malloc"); exit(1); } + d->ctl_list = NULL; cmin = (dipar->cmin < dopar->cmin) ? dipar->cmin : dopar->cmin; cmax = (dipar->cmax > dopar->cmax) ? dipar->cmax : dopar->cmax; rate = (dipar->rate > dopar->rate) ? dipar->rate : dopar->rate; @@ -180,7 +183,7 @@ dev_new_loop(struct aparams *dipar, struct aparams *dopar, unsigned bufsz) * Create a MIDI thru box device */ struct dev * -dev_new_thru(void) +dev_new_thru(int hold) { struct dev *d; @@ -189,9 +192,10 @@ dev_new_thru(void) perror("malloc"); exit(1); } + d->ctl_list = NULL; d->reqmode = MODE_MIDIMASK; d->pstate = DEV_CLOSED; - d->hold = 0; + d->hold = hold; d->path = "midithru"; d->next = dev_list; dev_list = d; @@ -199,6 +203,57 @@ dev_new_thru(void) } /* + * Add a MIDI port to the device + */ +int +devctl_add(struct dev *d, char *name, unsigned mode) +{ + struct devctl *c; + + c = malloc(sizeof(struct devctl)); + if (c == NULL) { + perror("malloc"); + exit(1); + } + c->path = name; + c->mode = mode; + c->next = d->ctl_list; + d->ctl_list = c; + if (d->pstate != DEV_CLOSED) { + if (!devctl_open(d, c)) + return 0; + } + return 1; +} + +/* + * Open a MIDI device and connect it to the thru box + */ +int +devctl_open(struct dev *d, struct devctl *c) +{ + struct file *f; + struct abuf *rbuf = NULL, *wbuf = NULL; + struct aproc *rproc, *wproc; + + f = (struct file *)miofile_new(&miofile_ops, c->path, c->mode); + if (f == NULL) + return 0; + if (c->mode & MODE_MIDIIN) { + rproc = rfile_new(f); + rbuf = abuf_new(MIDI_BUFSZ, &aparams_none); + aproc_setout(rproc, rbuf); + } + if (c->mode & MODE_MIDIOUT) { + wproc = wfile_new(f); + wbuf = abuf_new(MIDI_BUFSZ, &aparams_none); + aproc_setin(wproc, wbuf); + } + dev_midiattach(d, rbuf, wbuf); + return 1; +} + +/* * Open the device with the dev_reqxxx capabilities. Setup a mixer, demuxer, * monitor, midi control, and any necessary conversions. */ @@ -206,6 +261,7 @@ int dev_open(struct dev *d) { struct file *f; + struct devctl *c; struct aparams par; struct aproc *conv; struct abuf *buf; @@ -399,6 +455,18 @@ dev_open(struct dev *d) } #endif d->pstate = DEV_INIT; + for (c = d->ctl_list; c != NULL; c = c->next) { + if (!devctl_open(d, c)) { +#ifdef DEBUG + if (debug_level >= 1) { + dbg_puts(c->path); + dbg_puts(": couldn't open MIDI port\n"); + } +#endif + dev_close(d); + return 0; + } + } return 1; } @@ -576,35 +644,6 @@ dev_del(struct dev *d) } /* - * Open a MIDI device and connect it to the thru box - */ -int -dev_thruadd(struct dev *d, char *name, int in, int out) -{ - struct file *f; - struct abuf *rbuf = NULL, *wbuf = NULL; - struct aproc *rproc, *wproc; - - if (!dev_ref(d)) - return 0; - f = (struct file *)miofile_new(&miofile_ops, name, in, out); - if (f == NULL) - return 0; - if (in) { - rproc = rfile_new(f); - rbuf = abuf_new(MIDI_BUFSZ, &aparams_none); - aproc_setout(rproc, rbuf); - } - if (out) { - wproc = wfile_new(f); - wbuf = abuf_new(MIDI_BUFSZ, &aparams_none); - aproc_setin(wproc, wbuf); - } - dev_midiattach(d, rbuf, wbuf); - return 1; -} - -/* * Attach a bi-directional MIDI stream to the MIDI device */ void diff --git a/usr.bin/aucat/dev.h b/usr.bin/aucat/dev.h index 4f6bc88397f..24ae338a0fe 100644 --- a/usr.bin/aucat/dev.h +++ b/usr.bin/aucat/dev.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dev.h,v 1.28 2011/05/26 07:18:40 ratchov Exp $ */ +/* $OpenBSD: dev.h,v 1.29 2011/06/20 20:18:44 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -52,6 +52,11 @@ struct dev { struct aproc *mix, *sub, *submon; struct aproc *rec, *play, *mon; struct aproc *midi; + struct devctl { + struct devctl *next; + unsigned mode; + char *path; + } *ctl_list; }; extern struct dev *dev_list; @@ -62,12 +67,12 @@ void dev_unref(struct dev *); void dev_del(struct dev *); void dev_wakeup(struct dev *); void dev_drain(struct dev *); -struct dev *dev_new_thru(void); +struct dev *dev_new_thru(int); struct dev *dev_new_loop(struct aparams *, struct aparams *, unsigned); struct dev *dev_new_sio(char *, unsigned, struct aparams *, struct aparams *, unsigned, unsigned, unsigned, unsigned); -int dev_thruadd(struct dev *, char *, int, int); +int devctl_add(struct dev *, char *, unsigned); void dev_midiattach(struct dev *, struct abuf *, struct abuf *); unsigned dev_roundof(struct dev *, unsigned); int dev_getpos(struct dev *); diff --git a/usr.bin/aucat/midicat.1 b/usr.bin/aucat/midicat.1 index eaeb0fef740..761cfd7ab1c 100644 --- a/usr.bin/aucat/midicat.1 +++ b/usr.bin/aucat/midicat.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: midicat.1,v 1.16 2011/05/03 08:00:54 ratchov Exp $ +.\" $OpenBSD: midicat.1,v 1.17 2011/06/20 20:18:44 ratchov Exp $ .\" .\" Copyright (c) 2006 Alexandre Ratchov <alex@caoua.org> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: May 3 2011 $ +.Dd $Mdocdate: June 20 2011 $ .Dt MIDICAT 1 .Os .Sh NAME @@ -23,6 +23,7 @@ .Sh SYNOPSIS .Nm midicat .Op Fl dl +.Op Fl a Ar flag .Op Fl i Ar file .Op Fl L Ar addr .Op Fl o Ar file @@ -47,6 +48,21 @@ MIDI hardware or to another application in a uniform way. .Pp The options are as follows: .Bl -tag -width Ds +.It Fl a Ar flag +Control whether +.Nm +opens MIDI ports connected to the thru box only when needed +or keeps them open all the time. +If the flag is +.Va on +then MIDI ports are kept open all the time, ensuring no other program can +steal any of them. +If the flag is +.Va off , +then they are automatically closed, allowing other programs to have direct +access to MIDI ports, or the corresponding hardware to be disconnected. +The default is +.Va on . .It Fl d Increase log verbosity. .Nm diff --git a/usr.bin/aucat/miofile.c b/usr.bin/aucat/miofile.c index b457ec0cb53..17f28077643 100644 --- a/usr.bin/aucat/miofile.c +++ b/usr.bin/aucat/miofile.c @@ -1,4 +1,4 @@ -/* $OpenBSD: miofile.c,v 1.5 2010/06/04 06:15:28 ratchov Exp $ */ +/* $OpenBSD: miofile.c,v 1.6 2011/06/20 20:18:44 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -62,18 +62,13 @@ struct fileops miofile_ops = { * open the device */ struct miofile * -miofile_new(struct fileops *ops, char *path, int input, int output) +miofile_new(struct fileops *ops, char *path, unsigned mode) { char *siopath; struct mio_hdl *hdl; struct miofile *f; - int mode = 0; siopath = (strcmp(path, "default") == 0) ? NULL : path; - if (input) - mode |= MIO_IN; - if (output) - mode |= MIO_OUT; hdl = mio_open(siopath, mode, 1); if (hdl == NULL) return NULL; diff --git a/usr.bin/aucat/miofile.h b/usr.bin/aucat/miofile.h index e1b2e7324fe..a948fcc135b 100644 --- a/usr.bin/aucat/miofile.h +++ b/usr.bin/aucat/miofile.h @@ -1,4 +1,4 @@ -/* $OpenBSD: miofile.h,v 1.1 2009/07/25 08:44:27 ratchov Exp $ */ +/* $OpenBSD: miofile.h,v 1.2 2011/06/20 20:18:44 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -21,7 +21,7 @@ struct file; struct fileops; struct miofile; -struct miofile *miofile_new(struct fileops *, char *, int, int); +struct miofile *miofile_new(struct fileops *, char *, unsigned); extern struct fileops miofile_ops; |