diff --git a/src/fft.c b/src/fft.c index 1aab228..7703a7e 100644 --- a/src/fft.c +++ b/src/fft.c @@ -116,7 +116,7 @@ int i, j, step, k=0; unsigned int avg; // N_SAMPLES / maximum number of columns - step = inLen/(max); + step = inLen/max; for(i=0; i peak) peak = fftAvg[i]; - } - return peak; -} - void main_event() { @@ -125,10 +115,14 @@ bool over = false; fd_set set; int ret; + int c; int cnt = 0; // used to set resolution (wether to skip / not to skip a read) uint32_t sampleRate = 0; int nsamples = N_SAMPLES; // adapt processing to sample rate int sEnergyLen = N_SAMPLES/32; + PATTERN pattern = CURVE; + int statusHeight = 0; + int statusCol = 0; // open mpd fifo while((fifo = open(MPD_FIFO, O_RDONLY)) == -1); @@ -155,9 +149,25 @@ #endif while(!over) { - if (wgetch(stdscr) == 'q') { + if ((c = wgetch(stdscr)) == 'q') { over = true; - } + } else if (c == ' ') { + pattern = (pattern + 1) % 4; + } else if (c == KEY_UP) { + statusHeight -= 1; + } else if (c == KEY_DOWN) { + statusHeight += 1; + } else if (c == KEY_LEFT) { + statusCol -= 1; + } else if (c == KEY_RIGHT) { + statusCol += 1; + } else if (c == 'r') { + statusCol = 0; + statusHeight = 0; + } else if (c == 'h') { + print_help(maxR,maxC); + } + // select on fifo socket // if > 0 means data to be read if ((ret = select(fifo+1, &set, NULL, NULL, NULL)) > 0) { @@ -195,21 +205,22 @@ // clear screen for printing (only if new data on fifo) if(cnt == NICENESS) { erase(); - print_visual(fftAvg); + print_visual(fftAvg, pattern); } } #ifdef STATUS_CHECK // print mpd status even if no new data is avaiable - print_mpd_status(status, maxC, maxR/2+maxR/6); if (status && status->song && status->song->duration_sec) { print_rate_info(sampleRate, nsamples, maxC, status->song->duration_sec, \ - peak_amplitude(fftAvg, maxC), 5*test_beat(fftEHist, sEnergyLen, sEnergy)); + 0, 5*test_beat(fftEHist, sEnergyLen, sEnergy)); } + print_mpd_status(status, maxC, statusHeight+maxR/2+maxR/6, statusCol); #endif // refresh screen refresh(); getmaxyx(stdscr, maxR, maxC); } + #ifdef STATUS_CHECK close_connection(session); free_status_st(status); @@ -225,14 +236,15 @@ main(int argc, char *argv[]) { WINDOW *mainwin; -#ifdef STATUS_CHECK - setlocale(LC_ALL, ""); - import_var_from_settings(); -#endif if((mainwin = curses_init()) == NULL){ exit(EXIT_FAILURE); } +#ifdef STATUS_CHECK + setlocale(LC_ALL, ""); + import_var_from_settings(); + keypad(stdscr, TRUE); // arrow keys +#endif // get screen properties getmaxyx(stdscr, maxR, maxC); diff --git a/src/settings.h b/src/settings.h index c2da4f7..62f31dd 100644 --- a/src/settings.h +++ b/src/settings.h @@ -1,7 +1,7 @@ /* **** MPD options */ -static char defHost[] = "192.168.1.131"; +static char defHost[] = "localhost"; static unsigned int defPort = 6600; @@ -29,7 +29,7 @@ #define MPD_FIFO "/tmp/mpd.fifo" // seconds between each mpd status refresh -#define STATUS_REFRESH 1 +#define STATUS_REFRESH 5 // nuber of buffers whose computation is skipped (cyclically). // More skips mean less precision, nicer on older CPUs @@ -41,9 +41,12 @@ // subtracted to each component (visualized column) // adjust according to screen height -#define Y_CORRECTION 20 +#define Y_CORRECTION 28 // adjust lateral shift on screen // might prevent full borders from being printed, adjust #define X_CORRECTION 1 +// used while printing +#define FULL 'X' +#define EMPTY '.' diff --git a/src/utils_curses.c b/src/utils_curses.c index bb32db4..bcc3524 100644 --- a/src/utils_curses.c +++ b/src/utils_curses.c @@ -1,8 +1,11 @@ +#include + #include "utils_curses.h" #include "utils_mpd.h" #include "string.h" +#include "settings.h" -#include + // initialize color pairs // used in print_col void @@ -35,30 +38,85 @@ return w; } -// print a column to screen -// while doing so, perform a rotation of the color -// modify here to change color output void -print_col(int col, int l, const int maxR, const int maxC) +print_pattern(int col, int row, int l, const int maxR, PATTERN pattern) { - int row, changeCol; - int color = 5; + switch(pattern) { + case CURVE: + if (row > maxR-l && row < maxR-l/3) { // center of the screen + mvaddch(row, col, FULL); + } else { + mvaddch(row, col, EMPTY); + } + break; - /*for(row=maxR; row>=0; row--){*/ - for (row=0; row l && row < maxR-l/3)) { // center of the screen + case MOUTH: + if (row > l && row < maxR-l/3) { // center of the screen + mvaddch(row, col, EMPTY); + } else { + mvaddch(row, col, FULL); + } + break; + + case MOUTH_REV: + if (row > l && row < maxR-l/3) { // center of the screen mvaddch(row, col, FULL); } else { mvaddch(row, col, EMPTY); } + break; + case LINE: + if (row > (maxR-l) && row < maxR) { // center of the screen + mvaddch(row, col, FULL); + } else { + mvaddch(row, col, EMPTY); + } + break; + default: + break; + } +} + +// print a column to screen +// while doing so, perform a rotation of the color +// modify here to change color output +void +print_col(int col, int l, const int maxR, const int maxC, PATTERN pattern) +{ + int row; + int color = 5; + + /*for(row=maxR; row>=0; row--){*/ + for (row=0; row Press any key to continue."); + timeout(-1); + getch(); + timeout(0); +} + #ifdef STATUS_CHECK void print_rate_info(const int rate, const int nsamples, const int maxC, int seed, int amplitude,int beat) @@ -92,7 +150,7 @@ /* prints a STATUS structure to stdout */ void -print_mpd_status(STATUS* status, const int maxC, const int row) +print_mpd_status(STATUS* status, const int maxC, const int row, const int moveCol) { SONG* song = NULL; bool nullFlag = false; @@ -130,6 +188,7 @@ } center = maxC/2 - (maxlen)/2; } + center += moveCol; srand(song->duration_sec); color_set(rand() % 7, NULL); for (i=0; i