diff --git a/misc/DHTnodes b/misc/DHTnodes index d82237c..5e27942 100644 --- a/misc/DHTnodes +++ b/misc/DHTnodes @@ -1 +1,2 @@ -127.0.0.1 33447 25530DE8BF0DACA3F2ECD1A2FF07C6E21E5BEE12993F36157A2846DF8E837E33 +192.254.75.98 33445 FE3914F4616E227F29B2103450D6B55A836AD4BD23F97144E2C4ABE8D504FE1B +2607:5600:284::2 33445 FE3914F4616E227F29B2103450D6B55A836AD4BD23F97144E2C4ABE8D504FE1B diff --git a/src/audio_call.c b/src/audio_call.c index e14a343..778eb9d 100644 --- a/src/audio_call.c +++ b/src/audio_call.c @@ -6,12 +6,10 @@ #include "config.h" #endif -#ifdef _SUPPORT_AUDIO - - #include "audio_call.h" #include "toxic_windows.h" #include "chat_commands.h" +#include "global_commands.h" #include "toxic_windows.h" #include #include @@ -33,11 +31,11 @@ typedef struct _DeviceIx { int dix; /* Index of default device */ } DeviceIx; -enum _devices +typedef enum _devices { input, output, -}; +} _devices; struct _ASettings { @@ -87,8 +85,6 @@ ToxAv* init_audio(ToxWindow* window, Tox* tox) stringed_device_list += strlen( stringed_device_list ) + 1; } - - ++ASettins.device[input].size; } if ( ASettins.device[input].size ) { /* Have device */ @@ -125,8 +121,6 @@ ToxAv* init_audio(ToxWindow* window, Tox* tox) stringed_device_list += strlen( stringed_device_list ) + 1; } - - ++ASettins.device[output].size; } if ( ASettins.device[output].size ) { /* Have device */ @@ -491,7 +485,119 @@ on_error: } +void cmd_list_devices(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) +{ + const char* error_str; + + if ( argc != 1 ) { + if ( argc < 1 ) error_str = "Type must be specified!"; + else error_str = "Only one argument allowed!"; + + goto on_error; + } + + _devices type; + + if ( strcmp(argv[1], "in") == 0 ) /* Input devices */ + type = input; + + else if ( strcmp(argv[1], "out") == 0 ) /* Output devices */ + type = output; + + else { + wprintw(window, "Invalid type: %s\n", argv[1]); + return; + } + + int i = 0; + for ( ; i < ASettins.device[type].size; i ++) + wprintw(window, "%d: %s\n", i, ASettins.device[type].devices[i]); + + return; +on_error: + wprintw(window, "%s\n", error_str); +} - - -#endif /* _SUPPORT_AUDIO */ \ No newline at end of file +void cmd_change_device(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) +{ + const char* error_str; + + if ( argc != 2 ) { + if ( argc < 1 ) error_str = "Type must be specified!"; + else if ( argc < 2 ) error_str = "Must have id!"; + else error_str = "Only two arguments allowed!"; + + goto on_error; + } + + _devices type; + + if ( strcmp(argv[1], "in") == 0 ) /* Input devices */ + type = input; + + else if ( strcmp(argv[1], "out") == 0 ) /* Output devices */ + type = output; + + else { + wprintw(window, "Invalid type: %s\n", argv[1]); + return; + } + + + char *end; + long int selection = strtol(argv[2], &end, 10); + + if ( *end ) { + error_str = "Invalid input"; + goto on_error; + } + + if ( selection < 0 || selection >= ASettins.device[type].size ) { + error_str = "No device with such index"; + goto on_error; + } + + /* Close default device */ + if ( ASettins.device[type].dhndl ) { + alcCloseDevice(ASettins.device[type].dhndl); + + if ( ASettins.device[type].ctx) { /* Output device has context with it */ + alcMakeContextCurrent(NULL); + alcDestroyContext(ASettins.device[type].ctx); + } + } + + /* Open new device */ + + if ( type == input ) { + ASettins.device[input].dhndl = alcCaptureOpenDevice( + ASettins.device[input].devices[selection], AUDIO_SAMPLE_RATE, AL_FORMAT_MONO16, AUDIO_FRAME_SIZE * 4); + + if (alcGetError(ASettins.device[input].dhndl) != AL_NO_ERROR) { + error_str = "Error starting input device!"; + ASettins.errors |= ErrorStartingCaptureDevice; + } + + ASettins.device[input].ctx = NULL; + + wprintw(window, "Input device: %s\n", ASettins.device[type].devices[selection]); + } + else { + ASettins.device[output].dhndl = alcOpenDevice(ASettins.device[output].devices[selection]); + + if (alcGetError(ASettins.device[output].dhndl) != AL_NO_ERROR) { + error_str = "Error starting output device!"; + ASettins.errors |= ErrorStartingOutputDevice; + } + + ASettins.device[output].ctx = alcCreateContext(ASettins.device[output].dhndl, NULL); + + wprintw(window, "Output device: %s\n", ASettins.device[type].devices[selection]); + } + + + + return; +on_error: + wprintw(window, "%s\n", error_str); +} \ No newline at end of file diff --git a/src/audio_call.h b/src/audio_call.h index 3fb38b6..1b8801d 100644 --- a/src/audio_call.h +++ b/src/audio_call.h @@ -5,9 +5,6 @@ #ifndef _audio_h #define _audio_h -#ifdef _SUPPORT_AUDIO - - #include typedef struct ToxWindow ToxWindow; @@ -30,5 +27,4 @@ int errors(); int start_transmission(); -#endif /* _SUPPORT_AUDIO */ #endif /* _audio_h */ \ No newline at end of file diff --git a/src/chat.c b/src/chat.c index 7e0b29f..cd4aa18 100644 --- a/src/chat.c +++ b/src/chat.c @@ -47,9 +47,9 @@ extern ToxicFriend friends[MAX_FRIENDS_NUM]; #ifdef _SUPPORT_AUDIO -#define AC_NUM_CHAT_COMMANDS 22 + #define AC_NUM_CHAT_COMMANDS 22 #else -#define AC_NUM_CHAT_COMMANDS 18 + #define AC_NUM_CHAT_COMMANDS 18 #endif /* _SUPPORT_AUDIO */ /* Array of chat command names used for tab completion. */ diff --git a/src/chat_commands.c b/src/chat_commands.c index 9bac9a3..6ca7945 100644 --- a/src/chat_commands.c +++ b/src/chat_commands.c @@ -54,10 +54,10 @@ void cmd_chat_help(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg #ifdef _SUPPORT_AUDIO - wprintw(window, " /call : Audio call\n"); - wprintw(window, " /cancel : Cancel call\n"); - wprintw(window, " /answer : Answer incomming call\n"); - wprintw(window, " /hangup : Hangup active call\n"); + wprintw(window, " /call : Audio call\n"); + wprintw(window, " /cancel : Cancel call\n"); + wprintw(window, " /answer : Answer incomming call\n"); + wprintw(window, " /hangup : Hangup active call\n"); #endif /* _SUPPORT_AUDIO */ diff --git a/src/execute.c b/src/execute.c index 462749d..3be7619 100644 --- a/src/execute.c +++ b/src/execute.c @@ -34,20 +34,24 @@ struct cmd_func { }; static struct cmd_func global_commands[] = { - { "/accept", cmd_accept }, - { "/add", cmd_add }, - { "/clear", cmd_clear }, - { "/connect", cmd_connect }, - { "/exit", cmd_quit }, - { "/groupchat", cmd_groupchat }, - { "/help", cmd_prompt_help }, - { "/log", cmd_log }, - { "/myid", cmd_myid }, - { "/nick", cmd_nick }, - { "/note", cmd_note }, - { "/q", cmd_quit }, - { "/quit", cmd_quit }, - { "/status", cmd_status }, + { "/accept", cmd_accept }, + { "/add", cmd_add }, + { "/clear", cmd_clear }, + { "/connect", cmd_connect }, + { "/exit", cmd_quit }, + { "/groupchat", cmd_groupchat }, + { "/help", cmd_prompt_help }, + { "/log", cmd_log }, + { "/myid", cmd_myid }, + { "/nick", cmd_nick }, + { "/note", cmd_note }, + { "/q", cmd_quit }, + { "/quit", cmd_quit }, + { "/status", cmd_status }, +#ifdef _SUPPORT_AUDIO + { "/lsdev", cmd_list_devices }, + { "/sdev", cmd_change_device }, +#endif /* _SUPPORT_AUDIO */ }; static struct cmd_func chat_commands[] = { diff --git a/src/execute.h b/src/execute.h index 42b90b9..cf84cb9 100644 --- a/src/execute.h +++ b/src/execute.h @@ -21,12 +21,13 @@ */ #define MAX_NUM_ARGS 4 /* Includes command */ -#define GLOBAL_NUM_COMMANDS 14 #ifdef _SUPPORT_AUDIO -#define CHAT_NUM_COMMANDS 9 + #define GLOBAL_NUM_COMMANDS 16 + #define CHAT_NUM_COMMANDS 9 #else -#define CHAT_NUM_COMMANDS 5 + #define GLOBAL_NUM_COMMANDS 14 + #define CHAT_NUM_COMMANDS 5 #endif /* _SUPPORT_AUDIO */ enum { diff --git a/src/global_commands.c b/src/global_commands.c index 80a2978..e0a7c78 100644 --- a/src/global_commands.c +++ b/src/global_commands.c @@ -377,7 +377,12 @@ void cmd_prompt_help(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*a wprintw(window, " /help : Print this message again\n"); wprintw(window, " /clear : Clear the window\n"); wprintw(window, " /quit or /exit : Exit Toxic\n"); - + + #ifdef _SUPPORT_AUDIO + wprintw(window, " /lsdev : List devices where type: in|out\n"); + wprintw(window, " /sdev : Set active device\n"); + #endif /* _SUPPORT_AUDIO */ + wattron(window, COLOR_PAIR(CYAN) | A_BOLD); wprintw(window, " * Argument messages must be enclosed in quotation marks.\n"); wprintw(window, " * Use ctrl-o and ctrl-p to navigate through the tabs.\n\n"); diff --git a/src/global_commands.h b/src/global_commands.h index 5b0a66b..f8aec5b 100644 --- a/src/global_commands.h +++ b/src/global_commands.h @@ -32,3 +32,8 @@ void cmd_note(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE] void cmd_prompt_help(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_quit(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_status(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]); + +#ifdef _SUPPORT_AUDIO +void cmd_list_devices(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]); +void cmd_change_device(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]); +#endif /* _SUPPORT_AUDIO */ \ No newline at end of file diff --git a/src/prompt.c b/src/prompt.c index bda06e0..1539f6a 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -54,6 +54,13 @@ const uint8_t glob_cmd_list[AC_NUM_GLOB_COMMANDS][MAX_CMDNAME_SIZE] = { { "/note" }, { "/quit" }, { "/status" }, + +#ifdef _SUPPORT_AUDIO + + { "/lsdev" }, + { "/sdev" }, + +#endif /* _SUPPORT_AUDIO */ }; /* prevents input string from eating system messages: call this prior to printing a prompt message diff --git a/src/prompt.h b/src/prompt.h index 51acd59..aca8844 100644 --- a/src/prompt.h +++ b/src/prompt.h @@ -25,7 +25,12 @@ #define X_OFST 2 /* offset to account for prompt char */ -#define AC_NUM_GLOB_COMMANDS 15 + +#ifdef _SUPPORT_AUDIO + #define AC_NUM_GLOB_COMMANDS 17 +#else + #define AC_NUM_GLOB_COMMANDS 15 +#endif /* _SUPPORT_AUDIO */ ToxWindow new_prompt(void); void prep_prompt_win(void);