void buttonproc(void *) { int i, fd, b; char err[32]; byte buf[1]; Audiocontrol *c; fd = buttondev->dfd; c = &controls[Play][Volume_control]; for(;;){ if((b = read(fd, buf, 1)) < 0){ rerrstr(err, sizeof err); if(strcmp(err, "interrupted") == 0){ dprint(2, "read interrupted\n"); continue; } sysfatal("read %s/data: %r", buttondev->dir); } if(b == 0 || buf[0] == 0){ continue; }else if(buf[0] == 1){ if(c->chans == 0) c->value[0] += c->step; else for(i = 1; i < 8; i++) if(c->chans & 1 << i) c->value[i] += c->step; chanprint(controlchan, "0 volume playback %A", c); }else if(buf[0] == 2){ if(c->chans == 0) c->value[0] -= c->step; else for(i = 1; i < 8; i++) if(c->chans & 1 << i) c->value[i] -= c->step; chanprint(controlchan, "0 volume playback %A", c); }else if(usbdebug){ fprint(2, "button"); for(i = 0; i < b; i++) fprint(2, " %#2.2x", buf[i]); fprint(2, "\n"); } } }
void volumeproc(void *arg) { int fd, n, nf, nnf, i, nlines; static char buf[1024]; char *lines[32]; char *fields[8]; char *subfields[8]; Channel *ctl; int volume, minvolume, maxvolume, nvolume; ctl = arg; threadsetname("volumeproc"); fd = open(volumefile, OREAD); if(fd < 0){ fprint(2, "%s: %r\n", volumefile); threadexits(nil); } for(;;){ n = read(fd, buf, sizeof buf -1); if(n == 0) continue; if(n < 0){ fprint(2, "volumeproc: read: %r\n"); threadexits("volumeproc"); } buf[n] = '\0'; nlines = getfields(buf, lines, nelem(lines), 1, "\n"); for(i = 0; i < nlines; i++){ nf = tokenize(lines[i], fields, nelem(fields)); if(nf == 0) continue; if(nf != 6 || strcmp(fields[0], "volume") || strcmp(fields[1], "out")) continue; minvolume = strtol(fields[3], nil, 0); maxvolume = strtol(fields[4], nil, 0); if(minvolume >= maxvolume) continue; nnf = tokenize(fields[2], subfields, nelem(subfields)); if(nnf <= 0 || nnf > 8){ fprint(2, "volume format error\n"); threadexits(nil); } volume = 0; nvolume = 0; for(i = 0; i < nnf; i++){ volume += strtol(subfields[i], nil, 0); nvolume++; } volume /= nvolume; volume = 100*(volume - minvolume)/(maxvolume-minvolume); chanprint(ctl, "volume value %d", volume); } } }
Wind* windmk(char *label, char *target) { Wind *w; w = mallocz(sizeof(*w), 1); w->cs = newcontrolset(screen, nil, nil, nil); w->column = createcolumn(w->cs, "column"); w->top = createlabel(w->cs, "top"); w->body = createtext(w->cs, "body"); w->input = createentry(w->cs, "input"); w->event = chancreate(sizeof(char*), 0); w->blines = 0; if(target != nil) w->target = strdup(target); ctlprint(w->top, "value %s", label); ctlprint(w->top, "border 1"); ctlprint(w->top, "size %d %d %d %d", 10, font->height+1, 10000, font->height+1); ctlprint(w->body, "border 1"); ctlprint(w->body, "scroll 1"); ctlprint(w->input, "border 1"); ctlprint(w->input, "size %d %d %d %d", 10, font->height+1, 10000, font->height+1); controlwire(w->input, "event", w->event); chanprint(w->cs->ctl, "column add top"); chanprint(w->cs->ctl, "column add body"); chanprint(w->cs->ctl, "column add input"); activate(w->input); return w; }
void playctlproc(void*a) { int fd, n, nf; static char buf[512+1]; char *fields[4]; Channel *chan; threadsetname("playctlproc"); chan = a; fd = open(playctlfile, OREAD); if(fd < 0) sysfatal("%s: %r", playctlfile); for(;;){ n = read(fd, buf, sizeof buf -1); if(n == 0) continue; if(n < 0) sysfatal("%s: %r", playctlfile); buf[n] = '\0'; nf = tokenize(buf, fields, nelem(fields)); if(nf == 0) continue; switch (nf){ default: sysfatal("playctlproc: [%d]: %s", nf, fields[0]); case 3: chanprint(chan, "playctlproc: error %lud %q", strtoul(fields[1], nil, 0), fields[2]); if(strcmp(fields[0], "error") == 0) break; // fall through case 2: chanprint(chan, "playctlproc: %s %lud", fields[0], strtoul(fields[1], nil, 0)); } } }
void playvolproc(void*a) { int fd, n, nf, volume, nvolume, i; static char buf[256+1]; static errors; char *fields[3], *subfields[9]; Channel *chan; threadsetname("playvolproc"); chan = a; fd = open(playvolfile, OREAD); if(fd < 0) sysfatal("%s: %r", playvolfile); for(;;){ n = read(fd, buf, sizeof buf -1); if(n == 0) continue; if(n < 0){ fprint(2, "%s: %r\n", playvolfile); threadexits("playvolproc"); } buf[n] = '\0'; if(debug) fprint(2, "volumestring: %s\n", buf); nf = tokenize(buf, fields, nelem(fields)); if(nf == 0) continue; if(nf != 2 || strcmp(fields[0], "volume")){ fprint(2, "playvolproc: [%d]: %s\n", nf, fields[0]); if(errors++ > 32) threadexits("playvolproc"); continue; } nvolume = tokenize(fields[1], subfields, nelem(subfields)); if(nvolume <= 0 || nvolume > 8){ fprint(2, "volume format error\n"); if(errors++ > 32) threadexits("playvolproc"); continue; } volume = 0; for(i = 0; i < nvolume; i++) volume += strtol(subfields[i], nil, 0); volume /= nvolume; chanprint(chan, "volume value %d", volume); } }
void controlproc(void *) { /* Proc that looks after /dev/usb/%d/ctl */ int i, nf; char *req, *args[8]; Audiocontrol *c; long value[8]; Channel *replchan; while(req = recvp(controlchan)){ int rec; nf = tokenize(req, args, nelem(args)); if(nf < 3) sysfatal("controlproc: not enough arguments"); replchan = (Channel*)strtol(args[0], nil, 0); if(strcmp(args[2], "playback") == 0) rec = Play; else if(strcmp(args[2], "record") == 0) rec = Record; else{ /* illegal request */ dprint(2, "%s must be record or playback", args[2]); if(replchan) chanprint(replchan, "%s must be record or playback", args[2]); free(req); continue; } c = nil; for(i = 0; i < Ncontrol; i++){ c = &controls[rec][i]; if(strcmp(args[1], c->name) == 0) break; } if(i == Ncontrol){ dprint(2, "Illegal control name: %s", args[1]); if(replchan) chanprint(replchan, "Illegal control name: %s", args[1]); }else if(!c->settable){ dprint(2, "%s %s is not settable", args[1], args[2]); if(replchan) chanprint(replchan, "%s %s is not settable", args[1], args[2]); }else if(nf < 4){ dprint(2, "insufficient arguments for %s %s", args[1], args[2]); if(replchan) chanprint(replchan, "insufficient arguments for %s %s", args[1], args[2]); }else if(ctlparse(args[3], c, value) < 0){ if(replchan) chanprint(replchan, "parse error in %s %s", args[1], args[2]); }else{ dprint(2, "controlproc: setcontrol %s %s %s\n", rec?"in":"out", args[1], args[3]); if(setcontrol(rec, args[1], value) < 0){ if(replchan) chanprint(replchan, "setting %s %s failed", args[1], args[2]); }else{ if(replchan) chanprint(replchan, "ok"); } ctlevent(); } free(req); } }