you can now stop the wav player with the X key

This commit is contained in:
tTh 2024-08-22 00:49:48 +02:00
parent b372e0428d
commit ffbc4a13d4
2 changed files with 49 additions and 2 deletions

View File

@ -6,9 +6,14 @@
* *
*/ */
#define _POSIX_C_SOURCE 600L /* for fileno(3) */
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <sys/select.h>
#include "ecoute.h" #include "ecoute.h"
/*==------------------------------------------------------------------==*/ /*==------------------------------------------------------------------==*/
@ -79,6 +84,42 @@ foo = 42;
return foo; return foo;
} }
/*==------------------------------------------------------------------==*/ /*==------------------------------------------------------------------==*/
/*
* detection de la frappe d'une touche clavier -- remember kbhit() ?
*/
int is_a_key_hitted(void)
{
int fd,retv;
fd_set in_fds;
struct timeval tv;
fd = fileno(stdin);
#if DEBUG_LEVEL
fprintf(stderr, "%s: fileno -> %d\n", __func__, fd);
#endif
FD_ZERO(&in_fds); FD_SET(fd, &in_fds);
tv.tv_sec = tv.tv_usec = 0;
retv = select(1, &in_fds, NULL, NULL, &tv);
#if DEBUG_LEVEL
fprintf(stderr, "%s: select -> %d\n", __func__, retv);
#endif
if (-1 == retv) {
perror("select()");
}
else if (0 == retv) {
/* no key hit */
}
else {
/* got a keypress */
return 1;
}
return 0;
}
/*==------------------------------------------------------------------==*/
void termine_ecran(void) void termine_ecran(void)
{ {
endwin(); exit(0); endwin(); exit(0);

View File

@ -20,7 +20,7 @@ ao_sample_format format;
ao_device * device; ao_device * device;
char chaine[120]; char chaine[120];
short * samples; short * samples;
int lu; int lu, key;
long total_lu; long total_lu;
#if DEBUG_LEVEL #if DEBUG_LEVEL
@ -103,7 +103,13 @@ while ( (lu=sf_read_short(sndf, samples, T_BUFFER)) > 0 )
wrefresh(popup); wrefresh(popup);
/* HERE WE HAVE TO DETECT A 'STOP LISTEN' FUNCTION. */ /* HERE WE HAVE TO DETECT A 'STOP LISTEN' FUNCTION. */
if (is_a_key_hitted()) {
key = getch();
fprintf(stderr, "%s key pressed 0x%X\n", __func__, key);
if ('X' == key) {
break;
}
}
} }
/* /*