nausea

curses audio visualizer
git clone git://git.2f30.org/nausea
Log | Files | Refs | README | LICENSE

commit 6219c4611a4f503b13956bd4a1a9c265cd99fb49
parent 89cce4643d0405b4387e9f0c4a0e98d64566ef80
Author: lostd <lostd@2f30.org>
Date:   Mon,  3 Nov 2014 16:51:35 +0200

Add support for wide characters and configuration

Diffstat:
MMakefile | 13+++++++++++--
Aconfig.alt.h | 3+++
Aconfig.def.h | 3+++
Mnausea.c | 23+++++++++++++++--------
4 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/Makefile b/Makefile @@ -3,11 +3,15 @@ MANPREFIX = $(PREFIX)/man CPPFLAGS = -I/usr/local/include LDFLAGS = -L/usr/local/lib -LDLIBS = -lm -lcurses -lfftw3 +LDLIBS = -lm -lcursesw -lfftw3 +OBJ = nausea.o NAME = nausea + all: $(NAME) +nausea.o: config.h + install: all install -d $(DESTDIR)$(PREFIX)/bin install $(NAME) $(DESTDIR)$(PREFIX)/bin/$(NAME) @@ -19,4 +23,9 @@ uninstall: rm -f $(DESTDIR)$(MANPREFIX)/man1/$(NAME).1 clean: - rm -f $(NAME) + rm -f $(NAME) $(OBJ) + +.SUFFIXES: .def.h + +.def.h.h: + cp $< $@ diff --git a/config.alt.h b/config.alt.h @@ -0,0 +1,3 @@ +#define CHBAR L'▮' +#define CHPEAK L'▪' +#define CHPOINT L'●' diff --git a/config.def.h b/config.def.h @@ -0,0 +1,3 @@ +#define CHBAR L'|' +#define CHPEAK L'.' +#define CHPOINT L'=' diff --git a/nausea.c b/nausea.c @@ -2,22 +2,26 @@ #include <complex.h> #include <curses.h> #include <fcntl.h> +#include <locale.h> #include <stdio.h> #include <string.h> #include <stdint.h> #include <stdlib.h> #include <unistd.h> +#include <wchar.h> #include <fftw3.h> #define LEN(x) (sizeof (x) / sizeof *(x)) #define MIN(x, y) ((x) < (y) ? (x) : (y)) +#include "config.h" + static unsigned msec = 1000 / 25; /* 25 fps */ static unsigned nsamples = 44100 * 2; /* stereo */ -static char chbar = '|'; -static char chpeak = '.'; -static char chpoint = '='; +static wchar_t chbar = CHBAR; +static wchar_t chpeak = CHPEAK; +static wchar_t chpoint = CHPOINT; static char *fname = "/tmp/audio.fifo"; static char *argv0; static int colors; @@ -248,7 +252,7 @@ draw_spectrum(struct frame *fr) for (j = ybegin; j < yend; j++) { move(j, i); setcolor(1, j); - printw("%c", chbar); + printw("%lc", chbar); setcolor(0, j); } @@ -256,7 +260,7 @@ draw_spectrum(struct frame *fr) if (peaks && fr->peak[i] != PK_HIDDEN) { move(fr->peak[i], i); setcolor(1, fr->peak[i]); - printw("%c", chpeak); + printw("%lc", chpeak); setcolor(0, fr->peak[i]); } } @@ -302,7 +306,7 @@ draw_wave(struct frame *fr) /* output points */ y = fr->height / 2 + pt_pos; /* centering */ move(y, i); - printw("%c", chpoint); + printw("%lc", chpoint); /* Output a helper point by averaging with the previous * position. This creates a nice effect. We don't care @@ -310,7 +314,7 @@ draw_wave(struct frame *fr) pt_pos_mid = (pt_pos_prev + pt_pos) / 2.0; y = fr->height / 2 + pt_pos_mid; /* centering */ move(y, i); - printw("%c", chpoint); + printw("%lc", chpoint); pt_pos_prev = pt_pos; } @@ -395,7 +399,7 @@ draw_fountain(struct frame *fr) for (j = ybegin; j < yend; j++) { move(j, i); setcolor(1, j); - printw("%c", chbar); + printw("%lc", chbar); setcolor(0, j); } } @@ -450,6 +454,7 @@ main(int argc, char *argv[]) int c; struct frame fr; void *draw_prev; + int fd; argv0 = argv[0]; while (--argc > 0 && (*++argv)[0] == '-') @@ -500,6 +505,8 @@ main(int argc, char *argv[]) memset(&fr, 0, sizeof(fr)); init(&fr); + setlocale(LC_ALL, ""); + /* init curses */ initscr(); cbreak();