diff --git a/cava.c b/cava.c index ab8b7327..f5a5903e 100644 --- a/cava.c +++ b/cava.c @@ -1013,8 +1013,9 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co #endif for (int n = 0; n < number_of_bars; n++) { bars[n] = bars_raw[n]; - // zero values causes divided by zero segfault (if not raw) - if (output_mode != OUTPUT_RAW && output_mode != OUTPUT_NORITAKE && bars[n] < 1) + // show idle bar heads + if (output_mode != OUTPUT_RAW && output_mode != OUTPUT_NORITAKE && + bars[n] < 1 && p.show_idle_bar_heads == 1) bars[n] = 1; #ifdef SDL_GLSL diff --git a/config.c b/config.c index c134ccb1..4d07b721 100644 --- a/config.c +++ b/config.c @@ -654,6 +654,8 @@ bool load_config(char configPath[PATH_MAX], struct config_params *p, bool colors p->disable_blanking = iniparser_getint(ini, "output:disable_blanking", 0); + p->show_idle_bar_heads = iniparser_getint(ini, "output:show_idle_bar_heads", 1); + p->sync_updates = iniparser_getint(ini, "output:alacritty_sync", 0); vertexShader = strdup(iniparser_getstring(ini, "output:vertex_shader", "pass_through.vert")); @@ -800,6 +802,7 @@ bool load_config(char configPath[PATH_MAX], struct config_params *p, bool colors p->sdl_y = GetPrivateProfileInt("output", "sdl_y", -1, configPath); p->sync_updates = GetPrivateProfileInt("output", "alacritty_sync", 0, configPath); + p->show_idle_bar_heads = GetPrivateProfileInt("output", "show_idle_bar_heads", 1, configPath); p->userEQ_enabled = 0; diff --git a/config.h b/config.h index 857b6569..0daaa097 100644 --- a/config.h +++ b/config.h @@ -113,7 +113,8 @@ struct config_params { bit_format, gradient, gradient_count, fixedbars, framerate, bar_width, bar_spacing, bar_height, autosens, overshoot, waves, samplerate, samplebits, channels, autoconnect, sleep_timer, sdl_width, sdl_height, sdl_x, sdl_y, sdl_full_screen, draw_and_quit, zero_test, - non_zero_test, reverse, sync_updates, continuous_rendering, disable_blanking; + non_zero_test, reverse, sync_updates, continuous_rendering, disable_blanking, + show_idle_bar_heads; }; struct error_s { diff --git a/example_files/config b/example_files/config index c564cc30..af0e5664 100644 --- a/example_files/config +++ b/example_files/config @@ -204,6 +204,9 @@ # (Not supported on FreeBSD) ; disable_blanking = 0 +# show a flat bar at the bottom of the screen when idle, 1 = on, 0 = off +; show_idle_bar_heads = 1 + [color] # Colors can be one of seven predefined: black, blue, cyan, green, magenta, red, white, yellow. diff --git a/output/terminal_ncurses.c b/output/terminal_ncurses.c index 2bd3e6ac..9127c836 100644 --- a/output/terminal_ncurses.c +++ b/output/terminal_ncurses.c @@ -77,24 +77,24 @@ static NCURSES_COLOR_T change_color_definition(NCURSES_COLOR_T color_number, return return_color_number; } -static void get_screen_coords(int val, int col, int max_value, enum orientation orientation, int *x, - int *y) { +static void get_screen_coords(int line, int col, int max_value, enum orientation orientation, + int *x, int *y) { switch (orientation) { case ORIENT_LEFT: - *x = val; + *x = line; *y = col; break; case ORIENT_RIGHT: - *x = max_value - val; + *x = max_value - line; *y = col; break; case ORIENT_TOP: *x = col; - *y = val; + *y = line; break; default: *x = col; - *y = max_value - val; + *y = max_value - line; break; } } @@ -254,9 +254,9 @@ int draw_terminal_ncurses(int is_tty, int dimension_value, int dimension_bar, in max_update_value = (max_update_value + num_bar_heights) / num_bar_heights; - for (int val = 0; val < max_update_value; val++) { + for (int line = 0; line < max_update_value; line++) { if (gradient) { - change_colors(val, max_value); + change_colors(line, max_value); } for (int bar = 0; bar < bars_count; bar++) { @@ -265,17 +265,17 @@ int draw_terminal_ncurses(int is_tty, int dimension_value, int dimension_bar, in } int cur_col = bar * bar_width + bar * bar_spacing + rest; - int f_cell = (bars[bar] - 1) / num_bar_heights; - int f_last_cell = (previous_frame[bar] - 1) / num_bar_heights; + int bar_line_height = bars[bar] / num_bar_heights; + int previous_bar_line_heigh = previous_frame[bar] / num_bar_heights; - if (f_cell >= val) { + if (bars[bar] >= line * num_bar_heights + 1) { int bar_step; - if (f_cell == val) { - // The "cap" of the bar occurs at this [val]. - bar_step = (bars[bar] - 1) % num_bar_heights; - } else if (f_last_cell <= val) { - // The bar is full at this [val]. + if (bar_line_height == line) { + // The "cap" of the bar occurs at this [line]. + bar_step = bars[bar] % num_bar_heights - 1; + } else if (previous_bar_line_heigh <= line) { + // The bar is full at this line and wasn't before. bar_step = num_bar_heights - 1; } else { // No update necessary since last frame. @@ -284,7 +284,7 @@ int draw_terminal_ncurses(int is_tty, int dimension_value, int dimension_bar, in for (int col = cur_col, i = 0; i < bar_width; i++, col++) { int x, y; - get_screen_coords(val, col, max_value, orientation, &x, &y); + get_screen_coords(line, col, max_value, orientation, &x, &y); if (is_tty) { mvaddch(y, x, 0x41 + bar_step); @@ -292,12 +292,12 @@ int draw_terminal_ncurses(int is_tty, int dimension_value, int dimension_bar, in mvaddwstr(y, x, bar_heights[orientation][bar_step]); } } - } else if (f_last_cell >= val) { + } else if (previous_bar_line_heigh >= line) { // This bar was taller during the last frame than during this frame, so // clear the excess characters. for (int col = cur_col, i = 0; i < bar_width; i++, col++) { int x, y; - get_screen_coords(val, col, max_value, orientation, &x, &y); + get_screen_coords(line, col, max_value, orientation, &x, &y); mvaddch(y, x, ' '); } }