From 2651195b640500c13e18e4d6bca84889a7c4c088 Mon Sep 17 00:00:00 2001 From: karlstav Date: Sat, 18 Jul 2015 11:56:15 +0200 Subject: [PATCH] added legacy ouput mode noncurses --- README.md | 38 +++++++++++++++++- cava.c | 63 +++++++++++++----------------- iniparser/README.md | 15 +++++++ output/terminal_ncurses.c | 8 ++-- output/terminal_noncurses.c | 78 +++++++++++++++++++++++++------------ output/terminal_noncurses.h | 2 +- 6 files changed, 139 insertions(+), 65 deletions(-) diff --git a/README.md b/README.md index f5f1051..dc878df 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,47 @@ thanks to [anko](https://github.com/anko) for the gif, here is the [recipe]( htt [Demo video](http://youtu.be/vA4RyatP064) (old) + + +**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* + +- [C.A.V.A. ](#cava) + - [Updates](#updates) + - [What it is](#what-it-is) + - [Build requirements](#build-requirements) + - [Getting started](#getting-started) + - [Installing](#installing) + - [Uninstalling](#uninstalling) + - [Capturing audio](#capturing-audio) + - [Straight from output](#straight-from-output) + - [PulseAudio (easy)](#pulseaudio-easy) + - [ALSA (hard)](#alsa-hard) + - [From mpd's fifo output](#from-mpds-fifo-output) + - [Running via ssh](#running-via-ssh) + - [Font notes](#font-notes) + - [In ttys](#in-ttys) + - [In terminal emulators](#in-terminal-emulators) + - [Latency notes](#latency-notes) + - [Usage](#usage) + - [Controls](#controls) + - [Configuration](#configuration) + - [Example file:](#example-file) + - [Sections:](#sections) + - [[general]](#general) + - [[input]](#input) + - [[output]](#output) + - [[color]](#color) + - [[smoothing]](#smoothing) + - [[eq]](#eq) + + Updates ------- +7/16/2015 - 0.3.2 - added legacy ouput mode 'noncurses', for people experiencing issues with ncurses + 7/15/2015 - 0.3.1 - added config file 7/12/2015 - 0.3.0 - Modular source code @@ -210,7 +246,7 @@ Usage Options: -b 1..(console columns/2-1) or 200 number of bars in the spectrum (default 25 + fills up the console), program will automatically adjust if there are too many frequency bands) -i 'input method' method used for listnening to audio, supports: 'alsa' and 'fifo' - -o 'output method' method used for outputting processed data, only supports 'terminal' + -o 'output method' method used for outputting processed data, supports: 'ncurses', 'noncurses' and 'circle' -d 'alsa device' name of alsa capture device (default 'hw:1,1') -p 'fifo path' path to fifo (default '/tmp/mpd.fifo') -c foreground color suported colors: red, green, yellow, magenta, cyan, white, blue, black (default: cyan) diff --git a/cava.c b/cava.c index 90004b8..eb38ef2 100644 --- a/cava.c +++ b/cava.c @@ -103,10 +103,9 @@ void load_config() } } } - // config: create directory mkdir(configPath, 0777); - + // config: create empty file strcat(configPath, configFile); FILE *fp = fopen(configPath, "ab+"); @@ -155,7 +154,7 @@ void load_config() void validate_config() { // validate: input method - if (im == 0) { + if (im == 0) { fprintf(stderr, "input method %s is not supported, supported methods are: 'alsa' and 'fifo'\n", inputMethod); @@ -169,7 +168,7 @@ void validate_config() om = 3; bgcol = 0; } - if (om == 0) { + if (om == 0) { fprintf(stderr, "output method %s is not supported, supported methods are: 'terminal', 'circle'\n", outputMethod); @@ -184,7 +183,7 @@ void validate_config() if (strcmp(modeString, "normal") == 0) mode = 1; if (strcmp(modeString, "scientific") == 0) mode = 2; if (strcmp(modeString, "waves") == 0) mode = 3; - if (mode == 0) { + if (mode == 0) { fprintf(stderr, "smoothing mode %s is not supported, supported modes are: 'normal', 'scientific', 'waves'\n", modeString); @@ -192,7 +191,7 @@ void validate_config() } // validate: framerate - if (framerate < 0) { + if (framerate < 0) { fprintf(stderr, "framerate can't be negative!\n"); exit(EXIT_FAILURE); @@ -289,11 +288,8 @@ Options:\n\ audio.format = -1; audio.rate = 0; - - setlocale(LC_ALL, ""); - - + setlocale(LC_ALL, ""); for (i = 0; i < M; i++)audio.audio_out[i] = 0; @@ -343,10 +339,10 @@ Options:\n\ bgcol = -2; bcolor = optarg; break; - case 'h': // argument: print usage - printf ("%s", usage); + case 'h': // argument: print usage + printf ("%s", usage); return 0; - case '?': // argument: print usage + case '?': // argument: print usage printf ("%s", usage); return 1; case 'v': // argument: print version @@ -381,7 +377,7 @@ Options:\n\ } } #ifdef DEBUG - printf("got format: %d and rate %d\n", format, rate); + printf("got format: %d and rate %d\n", format, rate); #endif } @@ -405,11 +401,6 @@ Options:\n\ init_terminal_ncurses(col, bgcol); } - //output: start noncurses mode - if (om == 3) { - get_terminal_dim_noncurses(&w, &h); - init_terminal_noncurses(col, bgcol, w, h); - } while (1) {//jumbing back to this loop means that you resized the screen @@ -421,18 +412,17 @@ Options:\n\ fmem[i] = 0; } - - + //getting orignial numbers of bands incase of resize if (autoband == 1) { bands = 25; } else bands = fixedbands; - + // output: get terminal's geometry - if (om == 1 || om == 2) get_terminal_dim_ncurses(&w, &h); + if (om == 1 || om == 2) get_terminal_dim_ncurses(&w, &h); - if (om == 3) get_terminal_dim_noncurses(&w, &h); + if (om == 3) get_terminal_dim_noncurses(&w, &h); if (bands > w / 2 - 1)bands = w / 2 - @@ -459,15 +449,19 @@ Options:\n\ if (rest < 0)rest = 0; if ((smcount > 0) && (bands > 0)) { - smh = (double)(((double)smcount)/((double)bands)); + smh = (double)(((double)smcount)/((double)bands)); } + #ifdef DEBUG printw("hoyde: %d bredde: %d bands:%d bandbredde: %d rest: %d\n", w, h, bands, bw, rest); #endif + //output: start noncurses mode + if (om == 3) init_terminal_noncurses(col, bgcol, w, h, bw); + // process: calculate cutoff frequencies for (n = 0; n < bands + 1; n++) { fc[n] = 10000 * pow(10, -2.37 + ((((float)n + 1) / ((float)bands + 1)) * @@ -475,7 +469,7 @@ Options:\n\ fr[n] = fc[n] / (audio.rate / 2); //remember nyquist!, pr my calculations this should be rate/2 and nyquist freq in M/2 but testing shows it is not... or maybe the nq freq is in M/4 lcf[n] = fr[n] * (M / - 4); //lfc stores the lower cut frequency foo each band in the fft out buffer + 4); //lfc stores the lower cut frequency foo each band in the fft out buffer if (n != 0) { hcf[n - 1] = lcf[n] - 1; if (lcf[n] <= lcf[n - 1])lcf[n] = lcf[n - 1] + @@ -490,16 +484,16 @@ Options:\n\ } #endif } - + // process: weigh signal to frequencies for (n = 0; n < bands; n++)k[n] = pow(fc[n],0.85) * ((float)height/(M*4000)) * smooth[(int)floor(((double)n) * smh)]; - - cont = 1; + + cont = 1; // general: main loop while (cont) { - // general: keyboard controls + // general: keyboard controls if (om == 1 || om == 2) ch = getch(); switch (ch) { case 65: // key up @@ -528,7 +522,7 @@ Options:\n\ cleanup(); return EXIT_SUCCESS; } - + #ifdef DEBUG @@ -571,7 +565,6 @@ Options:\n\ if (temp <= ignore)temp = 0; f[o] = temp; - } } else { //**if in sleep mode wait and continue**// @@ -591,7 +584,7 @@ Options:\n\ int z; // process [smoothing]: monstercat-style "average" - + int m_y, de; if (mode == 3) { for (z = 0; z < bands; z++) { // waves @@ -670,10 +663,10 @@ Options:\n\ } if (rc == -1) break; //terminal has been resized breaking to recalibrating values - + if (framerate <= 1) { req.tv_sec = 1 / (float)framerate; - } else { + } else { req.tv_sec = 0; req.tv_nsec = (1 / (float)framerate) * 1000000000; //sleeping for set us } diff --git a/iniparser/README.md b/iniparser/README.md index 1f41000..7a8a523 100644 --- a/iniparser/README.md +++ b/iniparser/README.md @@ -1,3 +1,18 @@ + + +**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* + +- [Iniparser 4](#iniparser-4) + - [I - Overview](#i---overview) + - [II - Building project](#ii---building-project) + - [III - License](#iii---license) + - [IV - Versions](#iv---versions) + - [V - FAQ](#v---faq) + - [Is Iniparser thread safe ?](#is-iniparser-thread-safe-) + - [Your build system isn't portable, let me help you...](#your-build-system-isnt-portable-let-me-help-you) + + + [![Build Status](https://travis-ci.org/ndevilla/iniparser.svg?branch=master)](https://travis-ci.org/ndevilla/iniparser) # Iniparser 4 # diff --git a/output/terminal_ncurses.c b/output/terminal_ncurses.c index 86f1046..07866b6 100644 --- a/output/terminal_ncurses.c +++ b/output/terminal_ncurses.c @@ -9,7 +9,7 @@ int init_terminal_ncurses(int col, int bgcol) { curs_set(0); timeout(0); noecho(); - start_color(); + start_color(); use_default_colors(); init_pair(1, col, bgcol); if(bgcol != -1) @@ -35,8 +35,8 @@ int draw_terminal_ncurses(int virt, int h, int w, int bands, int bw, int rest, i // output: check if terminal has been resized if (virt != 0) { if ( LINES != h || COLS != w) { - return -1; - } + return -1; + } } h = h - 1; @@ -57,7 +57,7 @@ int draw_terminal_ncurses(int virt, int h, int w, int bands, int bw, int rest, i else for (q = 0; q < bw; q++) mvaddwstr((h - f[i] / 8), (i * bw) + q + i + rest, bars[(f[i] % 8) - 1]); } } - flastd[i] = f[i]; //memmory for falloff func + flastd[i] = f[i]; //memmory for falloff func } refresh(); diff --git a/output/terminal_noncurses.c b/output/terminal_noncurses.c index 53a5075..12f168d 100644 --- a/output/terminal_noncurses.c +++ b/output/terminal_noncurses.c @@ -3,42 +3,71 @@ #include #include #include - + +wchar_t barstring[8][100]; +int ttybarstring[8]; +char spacestring[100]; + + int setecho(int fd, int onoff) { struct termios t; - + if (tcgetattr(fd, &t) == -1) return -1; - + if (onoff == 0) t.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); else t.c_lflag |= (ECHO | ECHOE | ECHOK | ECHONL); - + if (tcsetattr(fd, TCSANOW, &t) == -1) return -1; return 0; } -int init_terminal_noncurses(int col, int bgcol, int w, int h) { +int init_terminal_noncurses(int col, int bgcol, int w, int h, int bw) { int n, i; + //clearing barstrings + for (n = 0; n < 8; n++) { + + ttybarstring[n] = 0; + barstring[n][0] ='\0'; + spacestring[0] ='\0'; + } + + //creating barstrings for drawing + for (n = 0; n < bw; n++) { + + wcscat(barstring[0],L"\u2588"); + wcscat(barstring[1],L"\u2581"); + wcscat(barstring[2],L"\u2582"); + wcscat(barstring[3],L"\u2583"); + wcscat(barstring[4],L"\u2584"); + wcscat(barstring[5],L"\u2585"); + wcscat(barstring[6],L"\u2586"); + wcscat(barstring[7],L"\u2587"); + strcat(spacestring, " "); + + for (i = 0; i < 8; i++) { + ttybarstring[i] += (i + 1) * pow(10, n); + } + } col += 30; bgcol += 40; system("setterm -cursor off"); system("setterm -blank 0"); - // output: reset console printf("\033[0m\n"); system("clear"); printf("\033[%dm", col); //setting color - + printf("\033[1m"); //setting "bright" color mode, looks cooler... I think @@ -55,7 +84,7 @@ int init_terminal_noncurses(int col, int bgcol, int w, int h) { } printf("\033[%dA", h); //moving cursor back up } - + setecho(STDIN_FILENO, 0); @@ -77,7 +106,8 @@ void get_terminal_dim_noncurses(int *w, int *h) { int draw_terminal_noncurses(int virt, int h, int w, int bands, int bw, int rest, int f[200], int flastd[200]) { - int c, move, i, n, o; + int c, move, n, o; + struct winsize dim; @@ -87,42 +117,42 @@ int draw_terminal_noncurses(int virt, int h, int w, int bands, int bw, int rest, ioctl(STDOUT_FILENO, TIOCGWINSZ, &dim); if ( (int)dim.ws_row != h || (int)dim.ws_col != w) { - return -1; - } + return -1; + } } + + for (n = h - 2; n >= 0; n--) { move = rest; //center adjustment for (o = 0; o < bands; o++) { - // output: draw and move to another one, check whether we're not too far if (f[o] != flastd[o]) { //change? - if (move != 0)printf("\033[%dC", move); + + if (move != 0) printf("\033[%dC", move); move = 0; c = f[o] - n * 8; - if (c < 1) { - if (f[o] < flastd[o]) for (i = 0; i < bw; i++) printf(" "); //blank + if (n * 8 < flastd[o]) printf("%s", spacestring); //blank else move += bw; } else if (c > 7) { - if (f[o] > flastd[o]) { - if (virt == 0) for (i = 0; i < bw; i++) printf("%d", 8); // block tty - else for (i = 0; i < bw; i++) printf("\u2588"); //block + if (n > flastd[o] / 8 - 1) { + if (virt == 0) printf("%d", ttybarstring[7]); // block tty + else printf("%ls", barstring[0]); //block } else move += bw; - } else { - if (virt == 0) for (i = 0; i < bw; i++) printf("%d", c); // fractioned block tty - else for (i = 0; i < bw; i++) printf("%lc", L'\u2580' + c); // fractioned block vt + } else { + if (virt == 0) printf("%d", ttybarstring[c - 1]); // fractioned block tty + else printf("%ls", barstring[c] ); // fractioned block vt } - - + } else move += bw; //no change, moving along - + move++;//move to next bar } diff --git a/output/terminal_noncurses.h b/output/terminal_noncurses.h index fc63cf4..1c2a0b5 100644 --- a/output/terminal_noncurses.h +++ b/output/terminal_noncurses.h @@ -1,4 +1,4 @@ -int init_terminal_noncurses(int col, int bgcol, int w, int h); +int init_terminal_noncurses(int col, int bgcol, int w, int h, int bw); void get_terminal_dim_noncurses(int *w, int *h); int draw_terminal_noncurses(int virt, int height, int width, int bands, int bw, int rest, int f[200], int flastd[200]); void cleanup_terminal_noncurses(void);