Added SND_SW_ITEM_LIST support.

This commit is contained in:
Jaroslav Kysela 2000-05-10 09:36:35 +00:00
parent b625125728
commit 789a35dd5c
2 changed files with 43 additions and 10 deletions

View 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]; csw->s.value.data32[0] = usw->s.value.data32[0];
} }
break; 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: case SND_SW_TYPE_USER_READ_ONLY:
break; break;
case SND_SW_TYPE_USER: case SND_SW_TYPE_USER:

View file

@ -575,7 +575,7 @@ int soundcard_setup_load(const char *cfgfile, int skip)
return 0; 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]; char *s, v[16];
int idx, first, switchok = 0; 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); fprintf(out, "%s; The type is '%s'.\n", space, s);
if (sw->low != 0 || sw->high != 0) 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); 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 && if (interface == SND_INTERFACE_CONTROL && sw->type == SND_SW_TYPE_WORD &&
!strcmp(sw->name, SND_CTL_SW_JOYSTICK_ADDRESS)) { !strcmp(sw->name, SND_CTL_SW_JOYSTICK_ADDRESS)) {
for (idx = 1, first = 1; idx < 16; idx++) { 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); fprintf(out, "%sswitch(\"%s\", ", space, sw->name);
if (!switchok) { if (!switchok) {
fprintf(out, v); 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 */ /* TODO: some well known types should be verbose */
fprintf(out, "rawdata(@"); fprintf(out, "rawdata(@");
for (idx = 0; idx < 31; idx++) { 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"); 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; struct ctl_switch *sw;
if (!(*switches)) if (!(*switches))
return; return;
for (sw = *switches; sw; sw = sw->next) 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) 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); fprintf(out, "soundcard(\"%s\") {\n", first->control.hwinfo.id);
if (first->control.switches) { if (first->control.switches) {
fprintf(out, " control {\n"); 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"); fprintf(out, " }\n");
} }
for (mixer = first->mixers; mixer; mixer = mixer->next) { for (mixer = first->mixers; mixer; mixer = mixer->next) {
fprintf(out, " mixer(\"%s\") {\n", mixer->info.name); 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) for (mixerelement = mixer->elements; mixerelement; mixerelement = mixerelement->next)
soundcard_setup_write_mixer_element(out, mixerelement); soundcard_setup_write_mixer_element(out, mixerelement);
fprintf(out, " }\n"); fprintf(out, " }\n");
@ -900,12 +918,12 @@ int soundcard_setup_write(const char *cfgfile, int cardno)
fprintf(out, " pcm(\"%s\") {\n", pcm->info.name); fprintf(out, " pcm(\"%s\") {\n", pcm->info.name);
if (pcm->pswitches) { if (pcm->pswitches) {
fprintf(out, " playback {\n"); 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"); fprintf(out, " }\n");
} }
if (pcm->rswitches) { if (pcm->rswitches) {
fprintf(out, " capture {\n"); 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");
} }
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); fprintf(out, " rawmidi(\"%s\") {\n", rawmidi->info.name);
if (rawmidi->oswitches) { if (rawmidi->oswitches) {
fprintf(out, " output {\n"); 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"); fprintf(out, " }\n");
} }
if (rawmidi->iswitches) { if (rawmidi->iswitches) {
fprintf(out, " input {\n"); 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");
} }
fprintf(out, " }\n"); fprintf(out, " }\n");