removed check if in tty if ouput is raw ti fix #110

master
karlstav 10 years ago
parent 3487ca681e
commit 0360e8872e
  1. 33
      cava.c
  2. 4
      output/terminal_bcircle.c
  3. 10
      output/terminal_ncurses.c
  4. 8
      output/terminal_noncurses.c

@ -559,7 +559,7 @@ int main(int argc, char **argv)
int flast[200]; int flast[200];
int flastd[200]; int flastd[200];
int sleep = 0; int sleep = 0;
int i, n, o, height, h, w, c, rest, inAVirtualConsole, silence, fp, fptest; int i, n, o, height, h, w, c, rest, inAtty, silence, fp, fptest;
float temp; float temp;
double inr[2 * (M / 2 + 1)]; double inr[2 * (M / 2 + 1)];
fftw_complex outr[M / 2 + 1][2]; fftw_complex outr[M / 2 + 1][2];
@ -625,15 +625,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
n = 0; n = 0;
} }
// Check if we're running in a Virtual console todo: replace virtual console with terminal emulator
inAVirtualConsole = 1;
if (strncmp(ttyname(0), "/dev/tty", 8) == 0 || strcmp(ttyname(0), "/dev/console") == 0) inAVirtualConsole = 0;
if (!inAVirtualConsole) {
system("setfont cava.psf >/dev/null 2>&1");
system("echo yep > /tmp/testing123");
system("setterm -blank 0");
}
@ -645,6 +637,19 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
validate_config(); validate_config();
if (om != 4) {
// Check if we're running in a Virtual console todo: replace virtual console with terminal emulator
inAtty = 0;
if (strncmp(ttyname(0), "/dev/tty", 8) == 0 || strcmp(ttyname(0), "/dev/console") == 0) inAtty = 1;
if (inAtty) {
system("setfont cava.psf >/dev/null 2>&1");
system("echo yep > /tmp/testing123");
system("setterm -blank 0");
}
}
//input: init //input: init
audio.format = -1; audio.format = -1;
audio.rate = 0; audio.rate = 0;
@ -740,10 +745,8 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
//output: start ncurses mode //output: start ncurses mode
if (om == 1 || om == 2) { if (om == 1 || om == 2) {
init_terminal_ncurses(col, bgcol); init_terminal_ncurses(col, bgcol);
get_terminal_dim_ncurses(&w, &h);
} }
// output: get terminal's geometry
if (om == 1 || om == 2) get_terminal_dim_ncurses(&w, &h);
#endif #endif
if (om == 3) get_terminal_dim_noncurses(&w, &h); if (om == 3) get_terminal_dim_noncurses(&w, &h);
@ -1065,16 +1068,16 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
switch (om) { switch (om) {
case 1: case 1:
#ifdef NCURSES #ifdef NCURSES
rc = draw_terminal_ncurses(inAVirtualConsole, h, w, bars, bw, bs, rest, f, flastd); rc = draw_terminal_ncurses(inAtty, h, w, bars, bw, bs, rest, f, flastd);
break; break;
#endif #endif
case 2: case 2:
#ifdef NCURSES #ifdef NCURSES
rc = draw_terminal_bcircle(inAVirtualConsole, h, w, f); rc = draw_terminal_bcircle(inAtty, h, w, f);
break; break;
#endif #endif
case 3: case 3:
rc = draw_terminal_noncurses(inAVirtualConsole, h, w, bars, bw, bs, rest, f, flastd); rc = draw_terminal_noncurses(inAtty, h, w, bars, bw, bs, rest, f, flastd);
break; break;
case 4: case 4:
rc = print_raw_out(bars, fp, is_bin, bit_format, ascii_range, bar_delim, frame_delim,f); rc = print_raw_out(bars, fp, is_bin, bit_format, ascii_range, bar_delim, frame_delim,f);

@ -36,12 +36,12 @@ void get_terminal_dim_bcircle(int *w, int *h) {
} }
int draw_terminal_bcircle(int virt, int h, int w, int f[200]) { int draw_terminal_bcircle(int tty, int h, int w, int f[200]) {
const wchar_t* bars[] = {L"\u2581", L"\u2582", L"\u2583", L"\u2584", L"\u2585", L"\u2586", L"\u2587", L"\u2588"}; const wchar_t* bars[] = {L"\u2581", L"\u2582", L"\u2583", L"\u2584", L"\u2585", L"\u2586", L"\u2587", L"\u2588"};
// output: check if terminal has been resized // output: check if terminal has been resized
if (virt != 0) { if (!tty) {
if ( LINES != h || COLS != w) { if ( LINES != h || COLS != w) {
return -1; return -1;
} }

@ -30,13 +30,13 @@ void get_terminal_dim_ncurses(int *w, int *h) {
} }
int draw_terminal_ncurses(int virt, int h, int w, int bars, int bw, int bs, int rest, int f[200], int flastd[200]) { int draw_terminal_ncurses(int tty, int h, int w, int bars, int bw, int bs, int rest, int f[200], int flastd[200]) {
int i, n, q; int i, n, q;
const wchar_t* bh[] = {L"\u2581", L"\u2582", L"\u2583", L"\u2584", L"\u2585", L"\u2586", L"\u2587", L"\u2588"}; const wchar_t* bh[] = {L"\u2581", L"\u2582", L"\u2583", L"\u2584", L"\u2585", L"\u2586", L"\u2587", L"\u2588"};
// output: check if terminal has been resized // output: check if terminal has been resized
if (virt != 0) { if (!tty) {
if ( LINES != h || COLS != w) { if ( LINES != h || COLS != w) {
return -1; return -1;
} }
@ -47,16 +47,16 @@ int draw_terminal_ncurses(int virt, int h, int w, int bars, int bw, int bs, int
for (i = 0; i < bars; i++) { for (i = 0; i < bars; i++) {
if(f[i] > flastd[i]){//higher then last one if(f[i] > flastd[i]){//higher then last one
if (virt == 0) for (n = flastd[i] / 8; n < f[i] / 8; n++) for (q = 0; q < bw; q++) mvprintw((h - n), i*bw + q + i*bs + rest, "%d",8); if (tty) for (n = flastd[i] / 8; n < f[i] / 8; n++) for (q = 0; q < bw; q++) mvprintw((h - n), i*bw + q + i*bs + rest, "%d",8);
else for (n = flastd[i] / 8; n < f[i] / 8; n++) for (q = 0; q < bw; q++) mvaddwstr((h - n), i*bw + q + i*bs + rest, bh[7]); else for (n = flastd[i] / 8; n < f[i] / 8; n++) for (q = 0; q < bw; q++) mvaddwstr((h - n), i*bw + q + i*bs + rest, bh[7]);
if (f[i] % 8 != 0) { if (f[i] % 8 != 0) {
if (virt == 0) for (q = 0; q < bw; q++) mvprintw( (h - n), i*bw + q + i*bs + rest, "%d",(f[i] % 8) ); if (tty) for (q = 0; q < bw; q++) mvprintw( (h - n), i*bw + q + i*bs + rest, "%d",(f[i] % 8) );
else for (q = 0; q < bw; q++) mvaddwstr( (h - n), i*bw + q + i*bs + rest, bh[(f[i] % 8) - 1]); else for (q = 0; q < bw; q++) mvaddwstr( (h - n), i*bw + q + i*bs + rest, bh[(f[i] % 8) - 1]);
} }
}else if(f[i] < flastd[i]){//lower then last one }else if(f[i] < flastd[i]){//lower then last one
for (n = f[i] / 8; n < flastd[i]/8 + 1; n++) for (q = 0; q < bw; q++) mvaddstr( (h - n), i*bw + q + i*bs + rest, " "); for (n = f[i] / 8; n < flastd[i]/8 + 1; n++) for (q = 0; q < bw; q++) mvaddstr( (h - n), i*bw + q + i*bs + rest, " ");
if (f[i] % 8 != 0) { if (f[i] % 8 != 0) {
if (virt == 0) for (q = 0; q < bw; q++) mvprintw((h - f[i] / 8), i*bw + q + i*bs + rest, "%d",(f[i] % 8) ); if (tty) for (q = 0; q < bw; q++) mvprintw((h - f[i] / 8), i*bw + q + i*bs + rest, "%d",(f[i] % 8) );
else for (q = 0; q < bw; q++) mvaddwstr((h - f[i] / 8), i*bw + q + i*bs + rest, bh[(f[i] % 8) - 1]); else for (q = 0; q < bw; q++) mvaddwstr((h - f[i] / 8), i*bw + q + i*bs + rest, bh[(f[i] % 8) - 1]);
} }
} }

@ -105,14 +105,14 @@ void get_terminal_dim_noncurses(int *w, int *h) {
} }
int draw_terminal_noncurses(int virt, int h, int w, int bars, int bw, int bs, int rest, int f[200], int flastd[200]) { int draw_terminal_noncurses(int tty, int h, int w, int bars, int bw, int bs, int rest, int f[200], int flastd[200]) {
int c, move, n, o; int c, move, n, o;
struct winsize dim; struct winsize dim;
// output: check if terminal has been resized // output: check if terminal has been resized
if (virt != 0) { if (!tty) {
ioctl(STDOUT_FILENO, TIOCGWINSZ, &dim); ioctl(STDOUT_FILENO, TIOCGWINSZ, &dim);
@ -142,11 +142,11 @@ int draw_terminal_noncurses(int virt, int h, int w, int bars, int bw, int bs, in
else move += bw; else move += bw;
} else if (c > 7) { } else if (c > 7) {
if (n > flastd[o] / 8 - 1) { if (n > flastd[o] / 8 - 1) {
if (virt == 0) printf("%d", ttybarstring[7]); // block tty if (tty) printf("%d", ttybarstring[7]); // block tty
else printf("%ls", barstring[0]); //block else printf("%ls", barstring[0]); //block
} else move += bw; } else move += bw;
} else { } else {
if (virt == 0) printf("%d", ttybarstring[c - 1]); // fractioned block tty if (tty) printf("%d", ttybarstring[c - 1]); // fractioned block tty
else printf("%ls", barstring[c] ); // fractioned block vt else printf("%ls", barstring[c] ); // fractioned block vt
} }

Loading…
Cancel
Save