]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - fade.c
fade: Introduce --mixer-api to choose between ALSA and OSS.
[paraslash.git] / fade.c
diff --git a/fade.c b/fade.c
index 1bfa0ba1ee8e9ca862de62fef4104d6c3e9cd4a4..cbfb62308a79ab85aa73b2d3f88c77cb25a6c725 100644 (file)
--- a/fade.c
+++ b/fade.c
@@ -23,6 +23,7 @@ enum mixer_id {MIXER_ENUM};
 static char *mixer_name[] = {MIXER_NAMES};
 DECLARE_MIXER_INITS;
 static struct mixer supported_mixer[] = {MIXER_ARRAY};
+#define FOR_EACH_MIXER(i) for ((i) = 0; (i) < NUM_SUPPORTED_MIXERS; (i)++)
 
 __printf_2_3 void date_log(__a_unused int ll, const char *fmt, ...)
 {
@@ -233,7 +234,7 @@ static void init_mixers(void)
 {
        int i;
 
-       for (i = 0; i < NUM_SUPPORTED_MIXERS; i++) {
+       FOR_EACH_MIXER(i) {
                struct mixer *m = &supported_mixer[i];
                PARA_DEBUG_LOG("initializing mixer API #%d (%s)\n",
                        i, mixer_name[i]);
@@ -259,6 +260,29 @@ static int set_channel(struct mixer *m, struct mixer_handle *h)
        return ret;
 }
 
+static struct mixer *get_mixer_or_die(void)
+{
+       int i;
+
+       if (!conf.mixer_api_given)
+               i = DEFAULT_MIXER;
+       else
+               FOR_EACH_MIXER(i)
+                       if (!strcmp(mixer_name[i], conf.mixer_api_arg))
+                               break;
+       if (i < NUM_SUPPORTED_MIXERS) {
+               PARA_NOTICE_LOG("using %s mixer API\n", mixer_name[i]);
+               return supported_mixer + i;
+       }
+       printf("available mixer APIs: ");
+       FOR_EACH_MIXER(i) {
+               int d = (i == DEFAULT_MIXER);
+               printf("%s%s%s ", d? "[" : "", mixer_name[i], d? "]" : "");
+       }
+       printf("\n");
+       exit(EXIT_FAILURE);
+}
+
 int main(int argc, char *argv[])
 {
        int ret;
@@ -286,8 +310,7 @@ int main(int argc, char *argv[])
                        &conf, &params);
        }
        init_mixers();
-       m = &supported_mixer[DEFAULT_MIXER];
-       PARA_INFO_LOG("using %s mixer\n", mixer_name[DEFAULT_MIXER]);
+       m = get_mixer_or_die();
        ret = m->open(conf.mixer_device_arg, &h);
        if (ret < 0)
                goto out;