ncmixer

ncurses audio mixer for DJ'ing
git clone git://git.2f30.org/ncmixer
Log | Files | Refs | README | LICENSE

commit 0d5b55aa3dba8236043d41e8692b684af56e32ed
parent abea503f73c10d6eb6bad6cbae5e79383ee9c790
Author: sin <sin@2f30.org>
Date:   Fri,  3 Jun 2016 17:41:34 +0100

Add curses warning/error printing functions

Diffstat:
Mncmixer.c | 58++++++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 44 insertions(+), 14 deletions(-)

diff --git a/ncmixer.c b/ncmixer.c @@ -9,6 +9,7 @@ #include <fcntl.h> #include <poll.h> #include <sndio.h> +#include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -73,6 +74,32 @@ struct output { { .name = MONITOR_DEV } }; +void +vprintmsg(char *fmt, va_list ap) +{ + move(LINES - 1, 0); + vwprintw(stdscr, fmt, ap); +} + +void +printwarn(char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vprintmsg(fmt, ap); + va_end(ap); +} + +void +printerr(int ret, char *prefix) +{ + endwin(); + fprintf(stderr, "ncmixer: %s: %s\n", prefix, + strerror(errno)); + exit(ret); +} + struct sio_hdl * audio_open(char *devname) { @@ -81,7 +108,7 @@ audio_open(char *devname) sio_hdl = sio_open(devname, SIO_PLAY, 0); if (sio_hdl == NULL) { - warnx("%s: failed to open audio device", devname); + printwarn("%s: failed to open audio device", devname); return NULL; } @@ -93,35 +120,35 @@ audio_open(char *devname) par.le = SIO_LE_NATIVE; if (sio_setpar(sio_hdl, &par) == 0) { - warnx("%s: failed to set params", devname); + printwarn("%s: failed to set params", devname); goto err0; } if (sio_getpar(sio_hdl, &par) == 0) { - warnx("%s: failed to get params", devname); + printwarn("%s: failed to get params", devname); goto err0; } if (par.pchan != CHANS) { - warnx("%s: failed to set number of channels", devname); + printwarn("%s: failed to set number of channels", devname); goto err0; } if (par.sig != 1 || par.bits != BITS || par.le != SIO_LE_NATIVE) { - warnx("%s: failed to set format", devname); + printwarn("%s: failed to set format", devname); goto err0; } if (par.rate < RATE * 995 / 1000 || par.rate > RATE * 1005 / 1000) { - warnx("%s: failed to set rate", devname); + printwarn("%s: failed to set rate", devname); goto err0; } if (sio_start(sio_hdl) == 0) { - warnx("%s: failed to start audio device", devname); + printwarn("%s: failed to start audio device", devname); goto err0; } @@ -252,7 +279,7 @@ server_listen(char *name) fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd == -1) - err(1, "socket"); + printerr(1, "socket"); unlink(name); memset(&sun, 0, sizeof(sun)); sun.sun_family = AF_UNIX; @@ -260,16 +287,16 @@ server_listen(char *name) len = sizeof(sun); umask(0); if (bind(fd, (SA *)&sun, len) == -1) - err(1, "bind"); + printerr(1, "bind"); if (listen(fd, 5) == -1) - err(1, "listen"); + printerr(1, "listen"); return fd; } void draw(void) { - erase(); + move(0, 0); printw("ch0_monitor: %d\n", inputs[0].monitor); printw("ch1_monitor: %d\n", inputs[1].monitor); printw("speed: %d\n", speed); @@ -317,15 +344,17 @@ loop(void) nready = poll(pfd, LEN(pfd), 1000 / FPS); if (nready == -1) { if (errno != EINTR) - err(1, "poll"); + printerr(1, "poll"); continue; } if (nready == 0) continue; /* XXX: call ui refresh */ + erase(); + for (i = 0; i < LEN(pfd); i++) if (pfd[i].revents & POLLERR) - errx(1, "bad fd"); + printerr(1, "bad fd"); /* handle key presses */ if (pfd[0].revents & POLLIN) @@ -339,7 +368,7 @@ loop(void) clifd = accept(in->listenfd, (SA *)&sun, &len); if (clifd == -1) { if (errno != EINTR) - err(1, "accept"); + printerr(1, "accept"); continue; } if (in->clifd != -1) { @@ -419,6 +448,7 @@ main(int argc, char *argv[]) if (argc > 2) outputs[1].name = argv[2]; curses_init(); + erase(); draw(); loop(); curses_exit();