1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-23 02:23:02 +01:00

Now supporting device selection

This commit is contained in:
mannol 2014-03-08 01:12:51 +01:00
parent 63745afe09
commit c678d41709
11 changed files with 172 additions and 42 deletions

View File

@ -1 +1,2 @@
127.0.0.1 33447 25530DE8BF0DACA3F2ECD1A2FF07C6E21E5BEE12993F36157A2846DF8E837E33
192.254.75.98 33445 FE3914F4616E227F29B2103450D6B55A836AD4BD23F97144E2C4ABE8D504FE1B
2607:5600:284::2 33445 FE3914F4616E227F29B2103450D6B55A836AD4BD23F97144E2C4ABE8D504FE1B

View File

@ -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 <curses.h>
#include <AL/al.h>
@ -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);
}
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]);
}
#endif /* _SUPPORT_AUDIO */
return;
on_error:
wprintw(window, "%s\n", error_str);
}

View File

@ -5,9 +5,6 @@
#ifndef _audio_h
#define _audio_h
#ifdef _SUPPORT_AUDIO
#include <tox/toxav.h>
typedef struct ToxWindow ToxWindow;
@ -30,5 +27,4 @@ int errors();
int start_transmission();
#endif /* _SUPPORT_AUDIO */
#endif /* _audio_h */

View File

@ -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. */

View File

@ -48,6 +48,10 @@ static struct cmd_func global_commands[] = {
{ "/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[] = {

View File

@ -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 {

View File

@ -378,6 +378,11 @@ void cmd_prompt_help(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*a
wprintw(window, " /clear : Clear the window\n");
wprintw(window, " /quit or /exit : Exit Toxic\n");
#ifdef _SUPPORT_AUDIO
wprintw(window, " /lsdev <type> : List devices where type: in|out\n");
wprintw(window, " /sdev <type> <id> : 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");

View File

@ -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 */

View File

@ -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

View File

@ -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);