diff --git a/config.c b/config.c index d140450..23fe257 100644 --- a/config.c +++ b/config.c @@ -1,4 +1,5 @@ #include "config.h" +#include "util.h" #include #include @@ -9,6 +10,13 @@ double smoothDef[5] = {1, 1, 1, 1, 1}; +enum input_method default_methods[] = { + INPUT_FIFO, + INPUT_PORTAUDIO, + INPUT_ALSA, + INPUT_PULSE, +}; + char *outputMethod, *channels; const char *input_method_names[] = { @@ -466,10 +474,11 @@ bool load_config(char configPath[255], struct config_params *p, bool colorsOnly, free(p->audio_source); char *input_method_name; - for (int i = INPUT_MAX - 1; i >= 0; i--) { - if (has_input_method[i]) { + for (size_t i = 0; i < ARRAY_SIZE(default_methods); i++) { + enum input_method method = default_methods[i]; + if (has_input_method[method]) { input_method_name = - (char *)iniparser_getstring(ini, "input:method", input_method_names[i]); + (char *)iniparser_getstring(ini, "input:method", input_method_names[method]); } } diff --git a/util.h b/util.h index 6deb36e..962faac 100644 --- a/util.h +++ b/util.h @@ -6,3 +6,5 @@ __typeof__(b) _b = (b); \ _a > _b ? _a : _b; \ }) + +#define ARRAY_SIZE(x) ((sizeof(x) / sizeof(0 [x])) / ((size_t)(!(sizeof(x) % sizeof(0 [x])))))