1
0
mirror of https://github.com/Tha14/toxic.git synced 2025-07-04 23:46:44 +02:00

add audio settings for conf file

This commit is contained in:
Jfreegman
2014-04-08 17:20:21 -04:00
parent 9fbf7bd1c1
commit 4643996c3a
6 changed files with 69 additions and 22 deletions

View File

@ -21,7 +21,6 @@
#include <unistd.h>
#include <stdlib.h>
#define MAX_DEVICES 32
#define _cbend pthread_exit(NULL)
#define AUDIO_FRAME_SIZE (av_DefaultSettings.audio_sample_rate * av_DefaultSettings.audio_frame_duration / 1000)
@ -36,12 +35,6 @@ typedef struct _DeviceIx {
int index; /* Current index */
} DeviceIx;
typedef enum _Devices
{
input,
output,
} _Devices;
struct _ASettings {
DeviceIx device[2];
@ -72,6 +65,21 @@ static void print_err (ToxWindow *self, uint8_t *error_str)
line_info_add(self, NULL, NULL, NULL, error_str, SYS_MSG, 0, 0);
}
int device_set(ToxWindow *self, _Devices type, long int selection)
{
uint8_t error_str[MAX_STR_SIZE];
uint8_t *s_type = type == input ? "input" : "output";
if ( selection < 0 || selection >= ASettins.device[type].size ) {
snprintf(error_str, sizeof(error_str), "Cannot set audio %s device: Invalid index", s_type);
line_info_add(self, NULL, NULL, NULL, error_str, SYS_MSG, 0, 0);
return -1;
}
ASettins.device[type].index = selection;
return 0;
}
/* Opens device under current index
*/
int device_open (ToxWindow *self, _Devices type)
@ -709,16 +717,12 @@ void cmd_change_device(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (
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;
if ( device_set(self, type, selection ) == 0) {
snprintf(msg, sizeof(msg), "Selected: %s", ASettins.device[type].devices[selection]);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
}
ASettins.device[type].index = selection;
snprintf(msg, sizeof(msg), "Selected: %s", ASettins.device[type].devices[selection]);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
return;
on_error:
print_err (self, error_str);