]> git.alsa-project.org Git - alsa-utils.git/commitdiff
Added SND_SW_ITEM_LIST support.
authorJaroslav Kysela <perex@perex.cz>
Wed, 10 May 2000 09:36:35 +0000 (09:36 +0000)
committerJaroslav Kysela <perex@perex.cz>
Wed, 10 May 2000 09:36:35 +0000 (09:36 +0000)
alsactl/merge.c
alsactl/setup.c

index 0062d348b64312d3be4f500b7799eb42de6be409..025bed4ad8b2f8189eae27e56242d5358726041b 100644 (file)
@@ -99,6 +99,21 @@ static int merge_one_sw(struct ctl_switch *csw, struct ctl_switch *usw, int card
                        csw->s.value.data32[0] = usw->s.value.data32[0];
                }
                break;
+       case SND_SW_TYPE_LIST:
+               if (usw->s.type != SND_SW_TYPE_LIST) {
+                       error("A wrong type for the switch %s. The type list is expected. Skipping...", sw_id(usw->s.name, cardno, devno, id));
+                       return 1;
+               }
+               if (csw->s.low > usw->s.value.item_number ||
+                   csw->s.high < usw->s.value.item_number) {
+                       error("The value %i for the switch %s is out of range %i-%i.", usw->s.value.item_number, sw_id(usw->s.name, cardno, devno, id), csw->s.low, csw->s.high);
+                       return 1;
+               }
+               if (csw->s.value.item_number != usw->s.value.item_number) {
+                       csw->change = 1;
+                       csw->s.value.item_number = usw->s.value.item_number;
+               }
+               break;
        case SND_SW_TYPE_USER_READ_ONLY:
                break;
        case SND_SW_TYPE_USER:
index 5acedd06b7e8c5eaf7dee63b36c2c1446b922fd5..c6fbefd9e6a9da6d4fb7e369b70451bb1ebe5f49 100644 (file)
@@ -575,7 +575,7 @@ int soundcard_setup_load(const char *cfgfile, int skip)
        return 0;
 }
 
-static void soundcard_setup_write_switch(FILE * out, const char *space, int interface, snd_switch_t *sw)
+static void soundcard_setup_write_switch(FILE * out, const char *space, int card, int interface, snd_switch_t *sw)
 {
        char *s, v[16];
        int idx, first, switchok = 0;
@@ -625,6 +625,24 @@ static void soundcard_setup_write_switch(FILE * out, const char *space, int inte
        fprintf(out, "%s; The type is '%s'.\n", space, s);
        if (sw->low != 0 || sw->high != 0)
                fprintf(out, "%s; The accepted switch range is from %u to %u.\n", space, sw->low, sw->high);
+       if (sw->type == SND_SW_TYPE_LIST) {
+               snd_ctl_t *handle;
+               snd_switch_t swi;
+               memset(&swi, 0, sizeof(swi));
+               swi.iface = sw->iface;
+               swi.device = sw->device;
+               swi.channel = sw->channel;
+               strncpy(swi.name, sw->name, sizeof(swi.name));
+               swi.type = SND_SW_TYPE_LIST_ITEM;
+               if (snd_ctl_open(&handle, card) >= 0) {
+                       for (idx = sw->low; idx <= sw->high; idx++) {
+                               swi.low = swi.high = idx;
+                               if (snd_ctl_switch_read(handle, &swi) >= 0)
+                                       fprintf(out, "%s; Item #%i - %s\n", space, swi.low, swi.value.item);
+                       }
+                       snd_ctl_close(handle);
+               }
+       }
        if (interface == SND_INTERFACE_CONTROL && sw->type == SND_SW_TYPE_WORD &&
            !strcmp(sw->name, SND_CTL_SW_JOYSTICK_ADDRESS)) {
                for (idx = 1, first = 1; idx < 16; idx++) {
@@ -677,7 +695,7 @@ static void soundcard_setup_write_switch(FILE * out, const char *space, int inte
        fprintf(out, "%sswitch(\"%s\", ", space, sw->name);
        if (!switchok) {
                fprintf(out, v);
-               if (sw->type < 0 || sw->type > SND_SW_TYPE_LIST_ITEM) {
+               if (sw->type < 0 || sw->type > SND_SW_TYPE_LAST) {
                        /* TODO: some well known types should be verbose */
                        fprintf(out, "rawdata(@");
                        for (idx = 0; idx < 31; idx++) {
@@ -690,14 +708,14 @@ static void soundcard_setup_write_switch(FILE * out, const char *space, int inte
        fprintf(out, ")\n");
 }
 
-static void soundcard_setup_write_switches(FILE *out, const char *space, int interface, struct ctl_switch **switches)
+static void soundcard_setup_write_switches(FILE *out, const char *space, int card, int interface, struct ctl_switch **switches)
 {
        struct ctl_switch *sw;
 
        if (!(*switches))
                return;
        for (sw = *switches; sw; sw = sw->next)
-               soundcard_setup_write_switch(out, space, interface, &sw->s);
+               soundcard_setup_write_switch(out, space, card, interface, &sw->s);
 }
 
 static void soundcard_setup_write_mixer_element(FILE * out, struct mixer_element * xelement)
@@ -884,12 +902,12 @@ int soundcard_setup_write(const char *cfgfile, int cardno)
                fprintf(out, "soundcard(\"%s\") {\n", first->control.hwinfo.id);
                if (first->control.switches) {
                        fprintf(out, "  control {\n");
-                       soundcard_setup_write_switches(out, "    ", SND_INTERFACE_CONTROL, &first->control.switches);
+                       soundcard_setup_write_switches(out, "    ", first->no, SND_INTERFACE_CONTROL, &first->control.switches);
                        fprintf(out, "  }\n");
                }
                for (mixer = first->mixers; mixer; mixer = mixer->next) {
                        fprintf(out, "  mixer(\"%s\") {\n", mixer->info.name);
-                       soundcard_setup_write_switches(out, "    ", SND_INTERFACE_MIXER, &mixer->switches);
+                       soundcard_setup_write_switches(out, "    ", first->no, SND_INTERFACE_MIXER, &mixer->switches);
                        for (mixerelement = mixer->elements; mixerelement; mixerelement = mixerelement->next)
                                soundcard_setup_write_mixer_element(out, mixerelement);
                        fprintf(out, "  }\n");
@@ -900,12 +918,12 @@ int soundcard_setup_write(const char *cfgfile, int cardno)
                        fprintf(out, "  pcm(\"%s\") {\n", pcm->info.name);
                        if (pcm->pswitches) {
                                fprintf(out, "    playback {\n");
-                               soundcard_setup_write_switches(out, "      ", SND_INTERFACE_PCM, &pcm->pswitches);
+                               soundcard_setup_write_switches(out, "      ", first->no, SND_INTERFACE_PCM, &pcm->pswitches);
                                fprintf(out, "    }\n");
                        }
                        if (pcm->rswitches) {
                                fprintf(out, "    capture {\n");
-                               soundcard_setup_write_switches(out, "      ", SND_INTERFACE_PCM, &pcm->rswitches);
+                               soundcard_setup_write_switches(out, "      ", first->no, SND_INTERFACE_PCM, &pcm->rswitches);
                                fprintf(out, "    }\n");
                        }
                        fprintf(out, "  }\n");
@@ -916,12 +934,12 @@ int soundcard_setup_write(const char *cfgfile, int cardno)
                        fprintf(out, "  rawmidi(\"%s\") {\n", rawmidi->info.name);
                        if (rawmidi->oswitches) {
                                fprintf(out, "    output {\n");
-                               soundcard_setup_write_switches(out, "      ", SND_INTERFACE_RAWMIDI, &rawmidi->oswitches);
+                               soundcard_setup_write_switches(out, "      ", first->no, SND_INTERFACE_RAWMIDI, &rawmidi->oswitches);
                                fprintf(out, "    }\n");
                        }
                        if (rawmidi->iswitches) {
                                fprintf(out, "    input {\n");
-                               soundcard_setup_write_switches(out, "      ", SND_INTERFACE_RAWMIDI, &rawmidi->iswitches);
+                               soundcard_setup_write_switches(out, "      ", first->no, SND_INTERFACE_RAWMIDI, &rawmidi->iswitches);
                                fprintf(out, "    }\n");
                        }
                        fprintf(out, "  }\n");