diff --git a/.gitignore b/.gitignore index 328f4e2..77bc26b 100644 --- a/.gitignore +++ b/.gitignore @@ -53,3 +53,5 @@ dkms.conf *.mp3 /csoundbox +/sounds +/csoundbox.cfg diff --git a/csoundbox.c b/csoundbox.c index 0f4f4ad..d76219b 100644 --- a/csoundbox.c +++ b/csoundbox.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "csoundbox.h" #include "config.h" @@ -50,6 +51,7 @@ int main(int argc, char *argv[]) { inputLocal(); } cfgdestroy(); + ao_shutdown(); return 0; } @@ -57,13 +59,15 @@ void inputLocal(void) { initscr(); nonl(); //no newline noecho(); - keypad(stdscr, FALSE); //Disable the F1-12 keypad + keypad(stdscr, TRUE); //Disable the F1-12 keypad curs_set(0); //Disable the cursor printCursesWelcome(); - char input; - while ((input = getch()) != 13) { + int input; + //Key 13 --> ENTER + //Key 265 --> F1 + while ((input = getch()) != 13 && input != 265) { playSound(lookupSounds(input)); } @@ -74,17 +78,22 @@ void inputNetwork(char *server) { initscr(); nonl(); //no newline noecho(); - keypad(stdscr, FALSE); //Disable the F1-12 keypad + keypad(stdscr, TRUE); //Disable the F1-12 keypad curs_set(0); //Disable the cursor printCursesWelcome(); char input[2]; - while ((input[0] = getch()) != 13) { + int inp; + //Key 13 --> ENTER + //Key 265 --> F1 + while ((input[0] = inp = getch()) != 13 && inp != 265) { input[1] = '\0'; sendKeyUDP(server, input); } - + if (inp == 265) { + sendKeyUDP(server, "exit"); + } endwin(); } @@ -95,7 +104,9 @@ void printCursesWelcome(void) { y /= 2; x /= 2; const char *msg = "Press enter to exit."; + const char *msg2 = "Press F1 to kill the server + client"; mvprintw(y, x - (strlen(msg) / 2), msg); + mvprintw(y + 1, x - (strlen(msg2) / 2), msg2); } diff --git a/csoundbox.cfg.example b/csoundbox.cfg.example new file mode 100644 index 0000000..6bc89e9 --- /dev/null +++ b/csoundbox.cfg.example @@ -0,0 +1,10 @@ +soundmap = { + sounds = ( {path = "ballsofsteel.mp3"; + key = "a"}, + {path = "neck.mp3"; + key = "b"} + ); + +} + +udpport = 8888; diff --git a/makefile b/makefile index 1525a6a..ad00810 100644 --- a/makefile +++ b/makefile @@ -3,9 +3,9 @@ VERSION = 1.0 CC = cc -CFLAGS = -Wall -O3 -DVERSION=\"$(VERSION)\" +CFLAGS = -Wall -g -O3 -DVERSION=\"$(VERSION)\" #LDFLAGS = -lm -lpthread `gtk-config --cflags` `gtk-config --libs` -lgthread -LDFLAGS = -lmpg123 -lao -lconfig -lncurses +LDFLAGS = -lmpg123 -lao -lconfig -lncurses -lpthread OBJ = csoundbox.o config.o sound.o udpserver.o diff --git a/sound.c b/sound.c index fd2a833..e4a447d 100644 --- a/sound.c +++ b/sound.c @@ -1,12 +1,26 @@ #include #include - +#include +#include +#include +#include #include "sound.h" - +#include "config.h" #define BITS 8 + void playSound(const char *path) { + pthread_t pth; //thread identifier + //Create thread + pthread_create(&pth, NULL, playThreadFunc, (void *) path); + pthread_detach(pth); //detach to call this function multiple times +} + + +void *playThreadFunc(void *arg) { + const char *path = (const char *) arg; + mpg123_handle *mh; unsigned char *buffer; size_t buffer_size; @@ -50,5 +64,9 @@ void playSound(const char *path) { mpg123_close(mh); mpg123_delete(mh); mpg123_exit(); - ao_shutdown(); + //ao_shutdown(); //don't call inside a thread + + pthread_exit(NULL); } + + diff --git a/sound.h b/sound.h index c4a549e..ef88859 100644 --- a/sound.h +++ b/sound.h @@ -1 +1,2 @@ void playSound(const char *path); +void *playThreadFunc(void *arg);