added rainbow mode

master
karlstav 9 years ago
parent f76f24d4d0
commit 6bb1a70261
  1. 17
      cava.c
  2. 10
      example_files/config
  3. 50
      output/terminal_ncurses.c
  4. 4
      output/terminal_ncurses.h

@ -71,6 +71,7 @@ int rc;
char *inputMethod, *outputMethod, *modeString, *color, *bcolor, *style, *raw_target, *data_format;
// *bar_delim, *frame_delim ;
char *rainbow_colors[7];
double monstercat, integral, gravity, ignore, smh, sens;
int fixedbars, framerate, bw, bs, autosens, overshoot;
unsigned int lowcf, highcf;
@ -97,6 +98,7 @@ char bar_delim = ';';
char frame_delim = '\n';
int ascii_range = 1000;
int bit_format = 16;
int rainbow = 0;
// whether we should reload the config or not
int should_reload = 0;
@ -209,6 +211,17 @@ FILE *fp;
color = (char *)iniparser_getstring(ini, "color:foreground", "default");
bcolor = (char *)iniparser_getstring(ini, "color:background", "default");
rainbow = iniparser_getint(ini, "color:rainbow", 0);
if (rainbow) {
rainbow_colors[0] = (char *)iniparser_getstring(ini, "color:rainbow_color_1", "#3366ff");
rainbow_colors[1] = (char *)iniparser_getstring(ini, "color:rainbow_color_2", "#6666ff");
rainbow_colors[2] = (char *)iniparser_getstring(ini, "color:rainbow_color_3", "#9966ff");
rainbow_colors[3] = (char *)iniparser_getstring(ini, "color:rainbow_color_4", "#cc33ff");
rainbow_colors[4] = (char *)iniparser_getstring(ini, "color:rainbow_color_5", "#ff00ff");
rainbow_colors[5] = (char *)iniparser_getstring(ini, "color:rainbow_color_6", "#cc0099");
rainbow_colors[6] = (char *)iniparser_getstring(ini, "color:rainbow_color_7", "#990099");
}
fixedbars = iniparser_getint(ini, "general:bars", 0);
bw = iniparser_getint(ini, "general:bar_width", 2);
bs = iniparser_getint(ini, "general:bar_spacing", 1);
@ -794,7 +807,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
#ifdef NCURSES
//output: start ncurses mode
if (om == 1 || om == 2) {
init_terminal_ncurses(color, bcolor, col, bgcol);
init_terminal_ncurses(color, bcolor, col, bgcol, rainbow, rainbow_colors);
get_terminal_dim_ncurses(&w, &h);
}
#endif
@ -1119,7 +1132,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
switch (om) {
case 1:
#ifdef NCURSES
rc = draw_terminal_ncurses(inAtty, h, w, bars, bw, bs, rest, f, flastd);
rc = draw_terminal_ncurses(inAtty, h, w, bars, bw, bs, rest, f, flastd, rainbow);
break;
#endif
case 2:

@ -97,6 +97,16 @@
; background = black
; foreground = cyan
#
; rainbow = 0
; rainbow_color_1 = '#3366ff'
; rainbow_color_2 = '#6666ff'
; rainbow_color_3 = '#9966ff'
; rainbow_color_4 = '#cc33ff'
; rainbow_color_5 = '#ff00ff'
; rainbow_color_6 = '#cc0099'
; rainbow_color_7 = '#990099'
[smoothing]

@ -11,7 +11,7 @@ struct colors {
#define COLOR_REDEFINITION -2
#define MAX_COLOR_REDEFINITION 2
#define MAX_COLOR_REDEFINITION 8
static struct colors the_color_redefinitions[MAX_COLOR_REDEFINITION];
@ -59,7 +59,7 @@ char* const color_string, NCURSES_COLOR_T predef_color) {
}
void init_terminal_ncurses(char* const fg_color_string,
char* const bg_color_string, int predef_fg_color, int predef_bg_color) {
char* const bg_color_string, int predef_fg_color, int predef_bg_color, int rainbow, char* const rainbow_colors[7]) {
initscr();
curs_set(0);
timeout(0);
@ -71,12 +71,27 @@ char* const bg_color_string, int predef_fg_color, int predef_bg_color) {
fg_color_number = change_color_definition(1, fg_color_string, predef_fg_color);
NCURSES_COLOR_T bg_color_number;
bg_color_number = change_color_definition(2, bg_color_string, predef_bg_color);
bg_color_number = change_color_definition(0, bg_color_string, predef_bg_color);
// do not forget to increase MAX_COLOR_REDEFINITION if you change more color
// definitions
NCURSES_COLOR_T color_pair_number = 1;
init_pair(color_pair_number, fg_color_number, bg_color_number);
if (rainbow) {
init_pair(1, COLOR_RED, 0);
init_pair(2, COLOR_GREEN, 0);
init_pair(3, COLOR_YELLOW, 0);
init_pair(4, COLOR_BLUE, 0);
init_pair(5, COLOR_MAGENTA, 0);
init_pair(6, COLOR_CYAN, 0);
init_pair(7, COLOR_WHITE, 0);
bkgd(COLOR_PAIR(1));
for (int n = 0; n < 7; n++)
change_color_definition(n + 1, rainbow_colors[n], n + 1);
}
if (bg_color_number != -1)
bkgd(COLOR_PAIR(color_pair_number));
@ -84,6 +99,16 @@ char* const bg_color_string, int predef_fg_color, int predef_bg_color) {
refresh();
}
void change_colors(int cur_height, int tot_height) {
if (cur_height >= 0 && cur_height < tot_height / 7) attron(COLOR_PAIR(1));
else if (cur_height >= tot_height / 7 && cur_height < tot_height * 2 / 7) attron(COLOR_PAIR(2));
else if (cur_height >= tot_height * 2 / 7 && cur_height < tot_height * 3 / 7) attron(COLOR_PAIR(3));
else if (cur_height >= tot_height * 3 / 7 && cur_height < tot_height * 4 / 7) attron(COLOR_PAIR(4));
else if (cur_height >= tot_height * 4 / 7 && cur_height < tot_height * 5 / 7) attron(COLOR_PAIR(5));
else if (cur_height >= tot_height * 5 / 7 && cur_height < tot_height * 6 / 7) attron(COLOR_PAIR(6));
else if (cur_height >= tot_height * 6 / 7 && cur_height <= tot_height * 7 / 7) attron(COLOR_PAIR(7));
}
void get_terminal_dim_ncurses(int* width, int* height) {
getmaxyx(stdscr, *height, *width);
clear(); // clearing in case of resieze
@ -93,7 +118,8 @@ void get_terminal_dim_ncurses(int* width, int* height) {
int draw_terminal_ncurses(int is_tty, int terminal_height, int terminal_width,
int bars_count, int bar_width, int bar_spacing, int rest, const int f[200],
int flastd[200]) {
int flastd[200], int rainbow) {
const wchar_t* bar_heights[] = {L"\u2581", L"\u2582", L"\u2583",
L"\u2584", L"\u2585", L"\u2586", L"\u2587", L"\u2588"};
#define LAST ((sizeof(bar_heights) / sizeof(bar_heights[0])) - 1)
@ -107,17 +133,22 @@ int flastd[200]) {
const int height = terminal_height - 1;
#define CURRENT_COLUMN bar*bar_width + width + bar*bar_spacing + rest
for (int bar = 0; bar < bars_count; bar++) {
if (f[bar] > flastd[bar]) { // higher then last one
if (f[bar] > flastd[bar]) { // higher then last frame
if (is_tty) {
for (int n = flastd[bar] / 8; n < f[bar] / 8; n++)
for (int n = flastd[bar] / 8; n < f[bar] / 8; n++) {
if (rainbow) change_colors(n, height);
for (int width = 0; width < bar_width; width++)
mvprintw((height - n), CURRENT_COLUMN, "%d", 8);
}
} else {
for (int n = flastd[bar] / 8; n < f[bar] / 8; n++)
for (int n = flastd[bar] / 8; n < f[bar] / 8; n++) {
if (rainbow) change_colors(n, height);
for (int width = 0; width < bar_width; width++)
mvaddwstr((height - n), CURRENT_COLUMN,
bar_heights[LAST]);
}
}
if (rainbow) change_colors(f[bar] / 8, height);
if (f[bar] % 8) {
if (is_tty) {
for (int width = 0; width < bar_width; width++)
@ -129,11 +160,12 @@ int flastd[200]) {
bar_heights[(f[bar] % 8) - 1]);
}
}
} else if(f[bar] < flastd[bar]) { // lower then last one
} else if(f[bar] < flastd[bar]) { // lower then last frame
for (int n = f[bar] / 8; n < flastd[bar]/8 + 1; n++)
for (int width = 0; width < bar_width; width++)
mvaddstr((height - n), CURRENT_COLUMN, " ");
if (f[bar] % 8) {
if (rainbow) change_colors(f[bar] / 8, height);
if (is_tty) {
for (int width = 0; width < bar_width; width++)
mvprintw((height - f[bar] / 8), CURRENT_COLUMN, "%d",
@ -152,6 +184,8 @@ int flastd[200]) {
return 0;
}
// general: cleanup
void cleanup_terminal_ncurses(void) {
echo();

@ -1,7 +1,7 @@
void init_terminal_ncurses(char* const fg_color_string,
char* const bg_color_string, int predef_fg_color, int predef_bg_color);
char* const bg_color_string, int predef_fg_color, int predef_bg_color, int rainbow, char* const rainbow_colors[7]);
void get_terminal_dim_ncurses(int* width, int* height);
int draw_terminal_ncurses(int is_tty, int terminal_height, int terminal_width,
int bars_count, int bar_width, int bar_spacing, int rest, const int f[200],
int flastd[200]);
int flastd[200], int rainbow);
void cleanup_terminal_ncurses(void);

Loading…
Cancel
Save