/* * attach play (rec) abuf structure to the device and * switch to the ``RUN'' state; the play abug must not be empty */ int wav_attach(struct wav *f, int force) { struct abuf *rbuf = NULL, *wbuf = NULL; struct dev *d = f->dev; if (f->mode & MODE_PLAY) rbuf = LIST_FIRST(&f->pipe.file.rproc->outs); if (f->mode & MODE_RECMASK) wbuf = LIST_FIRST(&f->pipe.file.wproc->ins); f->pstate = WAV_RUN; #ifdef DEBUG if (debug_level >= 3) { wav_dbg(f); dbg_puts(": attaching\n"); } #endif /* * start the device (dev_getpos() and dev_attach() must * be called on a started device */ dev_wakeup(d); dev_attach(d, f->pipe.file.name, f->mode, rbuf, &f->hpar, f->join ? d->opar.cmax - d->opar.cmin + 1 : 0, wbuf, &f->hpar, f->join ? d->ipar.cmax - d->ipar.cmin + 1 : 0, f->xrun, f->maxweight); if (f->mode & MODE_PLAY) dev_setvol(d, rbuf, MIDI_TO_ADATA(f->vol)); return 1; }
/* * callback to set the volume, invoked by the MIDI control code */ void wav_setvol(void *arg, unsigned int vol) { struct wav *f = (struct wav *)arg; struct abuf *rbuf; f->vol = vol; if ((f->mode & MODE_PLAY) && f->pstate == WAV_RUN) { rbuf = LIST_FIRST(&f->pipe.file.rproc->outs); dev_setvol(f->dev, rbuf, MIDI_TO_ADATA(vol)); } }
struct opt * mkopt(char *path, struct dev *d, int pmin, int pmax, int rmin, int rmax, int mode, int vol, int mmc, int dup) { struct opt *o; o = opt_new(path, d, pmin, pmax, rmin, rmax, MIDI_TO_ADATA(vol), mmc, dup, mode); if (o == NULL) errx(1, "%s: couldn't create subdev", path); dev_adjpar(d, o->mode, o->pmin, o->pmax, o->rmin, o->rmax); return o; }
struct opt * mkopt(char *path, struct dev *d, struct aparams *rpar, struct aparams *ppar, int mode, int vol, int mmc, int join) { struct opt *o; if (d->reqmode & MODE_LOOP) errx(1, "%s: can't attach to loopback", path); if (d->reqmode & MODE_THRU) mode = MODE_MIDIMASK; if (!rpar->rate) ppar->rate = rpar->rate = DEFAULT_RATE; o = opt_new(path, d, rpar, ppar, MIDI_TO_ADATA(vol), mmc, join, mode); if (o == NULL) errx(1, "%s: couldn't create subdev", path); dev_adjpar(d, o->mode, rpar, ppar); return o; }
/* * create a file reader in the ``INIT'' state */ struct wav * wav_new_in(struct fileops *ops, struct dev *dev, unsigned int mode, char *name, unsigned int hdr, struct aparams *par, unsigned int xrun, unsigned int volctl, int mmc, int join) { int fd; struct wav *f; if (!wav_autohdr(name, dev, &hdr, &mode)) return NULL; if (strcmp(name, "-") == 0) { fd = STDIN_FILENO; if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) perror(name); } else { fd = open(name, O_RDONLY | O_NONBLOCK, 0666); if (fd < 0) { perror(name); return NULL; } } f = (struct wav *)pipe_new(ops, fd, name); if (f == NULL) { close(fd); return NULL; } f->mode = mode; f->pstate = WAV_CFG; f->endpos = f->startpos = 0; f->next = wav_list; wav_list = f; if (hdr == HDR_WAV) { if (!wav_readhdr(f->pipe.fd, par, &f->startpos, &f->rbytes, &f->map)) { file_del((struct file *)f); return NULL; } f->endpos = f->startpos + f->rbytes; } else { f->endpos = pipe_endpos(&f->pipe.file); if (f->endpos > 0) { if (!pipe_seek(&f->pipe.file, 0)) { file_del((struct file *)f); return NULL; } f->rbytes = f->endpos; } else f->rbytes = -1; f->map = NULL; } f->dev = dev; f->mmc = mmc; f->join = join; f->mode = mode; f->hpar = *par; f->hdr = hdr; f->xrun = xrun; f->maxweight = MIDI_TO_ADATA(volctl); f->slot = -1; rwav_new((struct file *)f); #ifdef DEBUG if (debug_level >= 2) { dbg_puts(name); dbg_puts(":"); if (f->mode & MODE_PLAY) { dbg_puts(" playing "); aparams_dbg(par); dbg_puts(" "); dbg_putu(f->startpos); dbg_puts(".."); dbg_putu(f->endpos); if (f->mmc) dbg_puts(", mmc"); } if (f->mode & MODE_MIDIOUT) dbg_puts(" midi/out"); dbg_puts("\n"); } #endif return f; }