#364 added key controls for noncurses mode

master
karlstav 6 years ago
parent 19f6ab6480
commit 1165d81998
  1. 26
      cava.c
  2. 4
      output/terminal_noncurses.c

@ -243,6 +243,7 @@ int main(int argc, char **argv) {
double eq[256]; double eq[256];
float g; float g;
struct timespec req = {.tv_sec = 0, .tv_nsec = 0}; struct timespec req = {.tv_sec = 0, .tv_nsec = 0};
struct timespec sleep_mode_timer = {.tv_sec = 0, .tv_nsec = 0};
char configPath[PATH_MAX]; char configPath[PATH_MAX];
char *usage = "\n\ char *usage = "\n\
Usage : " PACKAGE " [options]\n\ Usage : " PACKAGE " [options]\n\
@ -746,6 +747,14 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
number_of_bars = number_of_bars * 2; number_of_bars = number_of_bars * 2;
bool resizeTerminal = false; bool resizeTerminal = false;
fcntl(0, F_SETFL, O_NONBLOCK);
if (p.framerate <= 1) {
req.tv_sec = 1 / (float)p.framerate;
} else {
req.tv_sec = 0;
req.tv_nsec = (1 / (float)p.framerate) * 1e9;
}
while (!resizeTerminal) { while (!resizeTerminal) {
@ -754,6 +763,8 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
if (output_mode == OUTPUT_NCURSES) if (output_mode == OUTPUT_NCURSES)
ch = getch(); ch = getch();
#endif #endif
if (output_mode == OUTPUT_NONCURSES)
ch = fgetc(stdin);
switch (ch) { switch (ch) {
case 65: // key up case 65: // key up
@ -880,9 +891,9 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
printw("no sound detected for 5 sec, going to sleep mode\n"); printw("no sound detected for 5 sec, going to sleep mode\n");
#endif #endif
// wait 0.1 sec, then check sound again. // wait 0.1 sec, then check sound again.
req.tv_sec = 0; sleep_mode_timer.tv_sec = 0;
req.tv_nsec = 100000000; sleep_mode_timer.tv_nsec = 100000000;
nanosleep(&req, NULL); nanosleep(&sleep_mode_timer, NULL);
continue; continue;
} }
@ -1015,14 +1026,6 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
resizeTerminal = true; resizeTerminal = true;
#endif #endif
if (p.framerate <= 1) {
req.tv_sec = 1 / (float)p.framerate;
} else {
req.tv_sec = 0;
req.tv_nsec = (1 / (float)p.framerate) * 1000000000;
}
nanosleep(&req, NULL);
memcpy(previous_frame, bars, 256 * sizeof(int)); memcpy(previous_frame, bars, 256 * sizeof(int));
@ -1033,6 +1036,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
nanosleep(&req, NULL);
} // resize terminal } // resize terminal
} // reloading config } // reloading config

@ -25,9 +25,9 @@ int setecho(int fd, int onoff) {
return -1; return -1;
if (onoff == 0) if (onoff == 0)
t.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); t.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL | ICANON);
else else
t.c_lflag |= (ECHO | ECHOE | ECHOK | ECHONL); t.c_lflag |= (ECHO | ECHOE | ECHOK | ECHONL | ICANON);
if (tcsetattr(fd, TCSANOW, &t) == -1) if (tcsetattr(fd, TCSANOW, &t) == -1)
return -1; return -1;

Loading…
Cancel
Save