=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/aucat/Attic/dev.c,v retrieving revision 1.65 retrieving revision 1.66 diff -u -r1.65 -r1.66 --- src/usr.bin/aucat/Attic/dev.c 2011/05/26 07:18:40 1.65 +++ src/usr.bin/aucat/Attic/dev.c 2011/06/20 20:18:44 1.66 @@ -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 * @@ -105,6 +105,7 @@ 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 @@ perror("malloc"); exit(1); } + d->ctl_list = NULL; d->path = path; d->reqmode = mode; if (mode & MODE_PLAY) @@ -158,6 +160,7 @@ 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 @@ * Create a MIDI thru box device */ struct dev * -dev_new_thru(void) +dev_new_thru(int hold) { struct dev *d; @@ -189,9 +192,10 @@ 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 @@ } /* + * 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 @@ dev_open(struct dev *d) { struct file *f; + struct devctl *c; struct aparams par; struct aproc *conv; struct abuf *buf; @@ -399,6 +455,18 @@ } #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; } @@ -573,35 +641,6 @@ } *p = d->next; free(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; } /*