From 71bcd4d370484e6e5c5f56cd7a45f12d13177287 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 1 Apr 2024 20:46:47 +0300 Subject: [PATCH] fixed --- README.md | 2 +- audio_vis.sh | 0 spark_ncurses.c | 37 ++++++++++++++++++++++--------------- 3 files changed, 23 insertions(+), 16 deletions(-) mode change 100755 => 100644 audio_vis.sh diff --git a/README.md b/README.md index fbb8ae1..f36c29d 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,6 @@ ~ # modprobe snd-aloop -~ $ cc spark_ncurses.c -lm -lncurses -s -ospark +~ $ cc spark_ncurses.c -lncurses -s -ospark ~ $ chmod +x audio_vis.sh ~ $ ./audio_vis.sh diff --git a/audio_vis.sh b/audio_vis.sh old mode 100755 new mode 100644 diff --git a/spark_ncurses.c b/spark_ncurses.c index 7a9d3cb..7044fb9 100644 --- a/spark_ncurses.c +++ b/spark_ncurses.c @@ -7,7 +7,6 @@ #include #include #include -#include #define NARGS 1024 #define ARG_SIZE 50 @@ -61,6 +60,14 @@ void sig_handler(int sig) { exit(0); } +void print(int y, int x, char *str, int val) { + if (val < 0) + mvprintw(y, x, "%s", str); + + else + mvprintw(y, x, "%s", str); +} + int main(void) { signal(SIGINT, sig_handler); signal(SIGTERM, sig_handler); @@ -82,24 +89,24 @@ int main(void) { clear(); for (int i = 0; i < args; i++) { - if (values[i] < min) - min = values[i]; + int val = values[i]; + if (val < 0) + val *= -1; - else if (values[i] > max) - max = values[i]; + if (val < min) + min = val; - int val = (values[i] - min) * 10 / ((max - min) + 1); - for (int j = 0; j < val; j++) { - mvprintw(middle - 2 - j, i, "#"); - mvprintw(middle + 2 + j, i, "#"); + else if (val > max) + max = val; + + int lvl = (val - min) * (ws.ws_row / 5) / ((max - min) + 1); + for (int j = 0; j < lvl; j++) { + print(middle - j, i, "$", values[i]); + print(middle + j, i, "$", values[i]); } - } - /* Vol */ - int val = (values[args - 1] - min) * ws.ws_col / ((max - min) + 1); - for (int j = 0; j < val; j++) { - mvprintw(middle - 1, ws.ws_col - j, "<="); - mvprintw(middle + 1, ws.ws_col - j, "<="); + print(middle - lvl, i, ".", values[i]); + print(middle + lvl, i, "'", values[i]); } refresh();