#include #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(); ao_shutdown(); return 0; } void inputLocal(void) { initscr(); nonl(); //no newline noecho(); keypad(stdscr, TRUE); //Disable the F1-12 keypad curs_set(0); //Disable the cursor printCursesWelcome(); int input; //Key 13 --> ENTER //Key 265 --> F1 while ((input = getch()) != 13 && input != 265) { playSound(lookupSounds(input)); } endwin(); } void inputNetwork(char *server) { initscr(); nonl(); //no newline noecho(); keypad(stdscr, TRUE); //Disable the F1-12 keypad curs_set(0); //Disable the cursor printCursesWelcome(); char input[2]; 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(); } void printCursesWelcome(void) { int y, x; getmaxyx(stdscr, y, x); //center 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); }