Skip to content

Commit

Permalink
add option to remove idle bar heads #550
Browse files Browse the repository at this point in the history
  • Loading branch information
karlstav committed Feb 10, 2024
1 parent fdc1706 commit 32fc24a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 22 deletions.
5 changes: 3 additions & 2 deletions cava.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions example_files/config
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
38 changes: 19 additions & 19 deletions output/terminal_ncurses.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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++) {
Expand All @@ -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.
Expand All @@ -284,20 +284,20 @@ 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);
} else {
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, ' ');
}
}
Expand Down

0 comments on commit 32fc24a

Please sign in to comment.