From ebcbc7497bdb39604ba54758b80bc78e62b17a5f Mon Sep 17 00:00:00 2001 From: Enni Rosario Date: Tue, 31 Oct 2017 17:32:34 +0200 Subject: [PATCH 1/2] Indicate selected device when printing. --- src/audio_device.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/audio_device.c b/src/audio_device.c index 7586293..2fe0ff7 100644 --- a/src/audio_device.c +++ b/src/audio_device.c @@ -481,8 +481,9 @@ void print_devices(ToxWindow *self, DeviceType type) { int i; - for (i = 0; i < size[type]; ++i) - line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%d: %s", i, devices_names[type][i]); + for (i = 0; i < size[type]; ++i) { + line_info_add(self, NULL, NULL, NULL, SYS_MSG, i == primary_device[type] ? 1 : 0, 0, "%d: %s", i, devices_names[type][i]); + } return; } From e1bfa3076983db45e5fa3cbae16e018be51c5796 Mon Sep 17 00:00:00 2001 From: Enni Rosario Date: Tue, 31 Oct 2017 18:08:06 +0200 Subject: [PATCH 2/2] Refresh device list on /lsdev. --- src/audio_call.c | 3 +++ src/audio_device.c | 61 +++++++++++++++++++++++++--------------------- src/audio_device.h | 1 + 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/src/audio_call.c b/src/audio_call.c index 62dee02..4009d42 100644 --- a/src/audio_call.c +++ b/src/audio_call.c @@ -633,6 +633,9 @@ void cmd_list_devices(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (* return; } + // Refresh device list. + get_devices_names(); + print_devices(self, type); return; diff --git a/src/audio_device.c b/src/audio_device.c index 2fe0ff7..9dfa2fc 100644 --- a/src/audio_device.c +++ b/src/audio_device.c @@ -100,34 +100,7 @@ DeviceError init_devices(ToxAV *av_) DeviceError init_devices() #endif /* AUDIO */ { - const char *stringed_device_list; - - size[input] = 0; - - if ( (stringed_device_list = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER)) ) { - ddevice_names[input] = alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER); - - for ( ; *stringed_device_list && size[input] < MAX_DEVICES; ++size[input] ) { - devices_names[input][size[input]] = stringed_device_list; - stringed_device_list += strlen( stringed_device_list ) + 1; - } - } - - size[output] = 0; - - if (alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE) - stringed_device_list = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER); - else - stringed_device_list = alcGetString(NULL, ALC_DEVICE_SPECIFIER); - - if (stringed_device_list) { - ddevice_names[output] = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER); - - for ( ; *stringed_device_list && size[output] < MAX_DEVICES; ++size[output] ) { - devices_names[output][size[output]] = stringed_device_list; - stringed_device_list += strlen( stringed_device_list ) + 1; - } - } + get_devices_names(); // Start poll thread if (pthread_mutex_init(&mutex, NULL) != 0) @@ -160,6 +133,38 @@ DeviceError terminate_devices() return (DeviceError) de_None; } +void get_devices_names() { + + const char *stringed_device_list; + + size[input] = 0; + + if ( (stringed_device_list = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER)) ) { + ddevice_names[input] = alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER); + + for ( ; *stringed_device_list && size[input] < MAX_DEVICES; ++size[input] ) { + devices_names[input][size[input]] = stringed_device_list; + stringed_device_list += strlen( stringed_device_list ) + 1; + } + } + + size[output] = 0; + + if (alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE) + stringed_device_list = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER); + else + stringed_device_list = alcGetString(NULL, ALC_DEVICE_SPECIFIER); + + if (stringed_device_list) { + ddevice_names[output] = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER); + + for ( ; *stringed_device_list && size[output] < MAX_DEVICES; ++size[output] ) { + devices_names[output][size[output]] = stringed_device_list; + stringed_device_list += strlen( stringed_device_list ) + 1; + } + } +} + DeviceError device_mute(DeviceType type, uint32_t device_idx) { if (device_idx >= MAX_DEVICES) return de_InvalidSelection; diff --git a/src/audio_device.h b/src/audio_device.h index 9b73791..969588a 100644 --- a/src/audio_device.h +++ b/src/audio_device.h @@ -61,6 +61,7 @@ DeviceError init_devices(ToxAV *av); DeviceError init_devices(); #endif /* AUDIO */ +void get_devices_names(); DeviceError terminate_devices(); /* Callback handles ready data from INPUT device */