mirror of
https://github.com/Tha14/toxic.git
synced 2024-12-23 11:53:26 +01:00
add audio settings for conf file
This commit is contained in:
parent
9fbf7bd1c1
commit
4643996c3a
@ -6,3 +6,9 @@ autolog:0;
|
||||
|
||||
# 1 to use native terminal colours, 0 to use toxic default colour theme
|
||||
colour_theme:0;
|
||||
|
||||
# preferred audio input device; numbers correspond to /lsdev in
|
||||
audio_in_dev:0;
|
||||
|
||||
# preferred audio output device; numbers correspond to /lsdev out
|
||||
audio_out_dev:0;
|
||||
|
@ -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);
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
#include <tox/toxav.h>
|
||||
|
||||
#define MAX_DEVICES 32
|
||||
|
||||
typedef struct ToxWindow ToxWindow;
|
||||
|
||||
typedef enum _AudioError
|
||||
@ -17,6 +19,12 @@ typedef enum _AudioError
|
||||
ErrorStartingCoreAudio = 1 << 2
|
||||
} AudioError;
|
||||
|
||||
typedef enum _Devices
|
||||
{
|
||||
input,
|
||||
output,
|
||||
} _Devices;
|
||||
|
||||
/* You will have to pass pointer to first member of 'windows'
|
||||
* declared in windows.c otherwise undefined behaviour will
|
||||
*/
|
||||
@ -26,5 +34,6 @@ void terminate_audio();
|
||||
int errors();
|
||||
|
||||
int start_transmission(ToxWindow *self);
|
||||
int device_set(ToxWindow *self, _Devices type, long int selection);
|
||||
|
||||
#endif /* _audio_h */
|
@ -505,6 +505,8 @@ int main(int argc, char *argv[])
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
memset(user_settings, 0, sizeof(struct user_settings));
|
||||
|
||||
int settings_err = settings_load(user_settings, NULL);
|
||||
|
||||
init_term();
|
||||
@ -538,12 +540,15 @@ int main(int argc, char *argv[])
|
||||
av = init_audio(prompt, m);
|
||||
|
||||
if ( errors() == NoError )
|
||||
msg = "Audio started with no problems.";
|
||||
msg = "Audio initiated with no problems.";
|
||||
else /* Get error code and stuff */
|
||||
msg = "Error starting audio!";
|
||||
msg = "Error initiating audio!";
|
||||
|
||||
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
|
||||
|
||||
device_set(prompt, input, user_settings->audio_in_dev);
|
||||
device_set(prompt, output, user_settings->audio_out_dev);
|
||||
|
||||
#endif /* _SUPPORT_AUDIO */
|
||||
|
||||
if (f_loadfromfile)
|
||||
|
@ -25,11 +25,14 @@
|
||||
|
||||
#include "toxic_windows.h"
|
||||
#include "configdir.h"
|
||||
#include "audio_call.h"
|
||||
#include "settings.h"
|
||||
|
||||
static void uset_autolog(struct user_settings *s, int val);
|
||||
static void uset_time(struct user_settings *s, int val);
|
||||
static void uset_colours(struct user_settings *s, int val);
|
||||
static void uset_ain_dev(struct user_settings *s, int val);
|
||||
static void uset_aout_dev(struct user_settings *s, int val);
|
||||
|
||||
struct {
|
||||
const char *name;
|
||||
@ -38,10 +41,12 @@ struct {
|
||||
{ "autolog", uset_autolog },
|
||||
{ "time", uset_time },
|
||||
{ "colour_theme", uset_colours },
|
||||
{ "audio_in_dev", uset_ain_dev },
|
||||
{ "audio_out_dev", uset_aout_dev },
|
||||
};
|
||||
|
||||
static void uset_autolog(struct user_settings *s, int val)
|
||||
{
|
||||
{
|
||||
/* default off if invalid value */
|
||||
s->autolog = val == AUTOLOG_ON ? AUTOLOG_ON : AUTOLOG_OFF;
|
||||
}
|
||||
@ -58,6 +63,22 @@ static void uset_colours(struct user_settings *s, int val)
|
||||
s->colour_theme = val == NATIVE_COLS ? NATIVE_COLS : DFLT_COLS;
|
||||
}
|
||||
|
||||
static void uset_ain_dev(struct user_settings *s, int val)
|
||||
{
|
||||
if (val < 0 || val > MAX_DEVICES)
|
||||
val = (long int) 0;
|
||||
|
||||
s->audio_in_dev = (long int) val;
|
||||
}
|
||||
|
||||
static void uset_aout_dev(struct user_settings *s, int val)
|
||||
{
|
||||
if (val < 0 || val > MAX_DEVICES)
|
||||
val = (long int) 0;
|
||||
|
||||
s->audio_out_dev = (long int) val;
|
||||
}
|
||||
|
||||
int settings_load(struct user_settings *s, char *path)
|
||||
{
|
||||
char *user_config_dir = get_user_config_dir();
|
||||
|
@ -20,13 +20,15 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#define NUM_SETTINGS 3
|
||||
#define NUM_SETTINGS 5
|
||||
|
||||
/* holds user setting values */
|
||||
struct user_settings {
|
||||
int autolog; /* boolean */
|
||||
int time; /* 12 or 24 */
|
||||
int colour_theme; /* boolean (0 for default toxic colours) */
|
||||
int autolog; /* boolean */
|
||||
int time; /* 12 or 24 */
|
||||
int colour_theme; /* boolean (0 for default toxic colours) */
|
||||
long int audio_in_dev;
|
||||
long int audio_out_dev;
|
||||
};
|
||||
|
||||
enum {
|
||||
|
Loading…
Reference in New Issue
Block a user