From 81241ffb8176bde284699e5839bb944db39c773c Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 17 Feb 2009 16:58:12 +0100 Subject: Change numid properly with external ctl plugins So far, external ctl plugins don't change numid. Some apps expect the non-zero numids with list, and the plugin doesn't work for them. This patch adds a fake numid to each control based on the offset number. The lookup with non-zero numid is supported but is pretty inefficient. Eventually the plugin side may be optimized to look at the numid, too. Signed-off-by: Takashi Iwai --- src/control/control_ext.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/control/control_ext.c b/src/control/control_ext.c index a8675c13..d1fe8eaa 100644 --- a/src/control/control_ext.c +++ b/src/control/control_ext.c @@ -107,6 +107,7 @@ static int snd_ctl_ext_elem_list(snd_ctl_t *handle, snd_ctl_elem_list_t *list) ret = ext->callback->elem_list(ext, offset, ids); if (ret < 0) return ret; + ids->numid = offset + 1; /* fake number */ list->used++; offset++; ids++; @@ -114,13 +115,24 @@ static int snd_ctl_ext_elem_list(snd_ctl_t *handle, snd_ctl_elem_list_t *list) return 0; } +static snd_ctl_ext_key_t get_elem(snd_ctl_ext_t *ext, snd_ctl_elem_id_t *id) +{ + int numid = id->numid; + if (numid > 0) { + ext->callback->elem_list(ext, numid - 1, id); + id->numid = numid; + } else + id->numid = 0; + return ext->callback->find_elem(ext, id); +} + static int snd_ctl_ext_elem_info(snd_ctl_t *handle, snd_ctl_elem_info_t *info) { snd_ctl_ext_t *ext = handle->private_data; snd_ctl_ext_key_t key; int type, ret; - key = ext->callback->find_elem(ext, &info->id); + key = get_elem(ext, &info->id); if (key == SND_CTL_EXT_KEY_NOT_FOUND) return -ENOENT; ret = ext->callback->get_attribute(ext, key, &type, &info->access, &info->count); @@ -200,7 +212,7 @@ static int snd_ctl_ext_elem_read(snd_ctl_t *handle, snd_ctl_elem_value_t *contro int type, ret; unsigned int access, count; - key = ext->callback->find_elem(ext, &control->id); + key = get_elem(ext, &control->id); if (key == SND_CTL_EXT_KEY_NOT_FOUND) return -ENOENT; ret = ext->callback->get_attribute(ext, key, &type, &access, &count); @@ -254,7 +266,7 @@ static int snd_ctl_ext_elem_write(snd_ctl_t *handle, snd_ctl_elem_value_t *contr int type, ret; unsigned int access, count; - key = ext->callback->find_elem(ext, &control->id); + key = get_elem(ext, &control->id); if (key == SND_CTL_EXT_KEY_NOT_FOUND) return -ENOENT; ret = ext->callback->get_attribute(ext, key, &type, &access, &count); -- cgit v1.2.1