#include #include #include #include #include #include "csoundbox.h" #include "config.h" #include "sound.h" #include "udpserver.h" int main(int argc, char *argv[]) { const char *short_options = "hsi:l"; struct option long_options[] = { {"server", no_argument, NULL, 's'}, {"ip", required_argument, NULL, 'i'}, {"help", no_argument, NULL, 'h'}, {"local", no_argument, NULL, 'l'} }; int c; //initialize libconfig cfginit(); while ( (c = getopt_long(argc, argv, short_options, long_options, NULL)) != -1 ) { switch (c) { case 's': //start server printf("Server.\n"); udpserver(); break; case 'h': //show the help page break; case 'i': //connect to a csoundbox server inputNetwork(optarg); break; case 'l': default: //start local inputLocal(); break; } } if (argc < 2) { inputLocal(); } cfgdestroy(); return 0; } void inputLocal(void) { initscr(); nonl(); //no newline noecho(); keypad(stdscr, FALSE); //Disable the F1-12 keypad curs_set(0); //Disable the cursor printCursesWelcome(); char input; while ((input = getch()) != 13) { playSound(lookupSounds(input)); } endwin(); } void inputNetwork(char *server) { initscr(); nonl(); //no newline noecho(); keypad(stdscr, FALSE); //Disable the F1-12 keypad curs_set(0); //Disable the cursor printCursesWelcome(); char input[2]; while ((input[0] = getch()) != 13) { input[1] = '\0'; sendKeyUDP(server, input); } endwin(); } void printCursesWelcome(void) { int y, x; getmaxyx(stdscr, y, x); //center y /= 2; x /= 2; const char *msg = "Press enter to exit."; mvprintw(y, x - (strlen(msg) / 2), msg); }