mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2026-03-27 07:58:02 -04:00
control: improve snd_ctl_add_*_elem_set functions (access flags)
The access flags are useful for the user space elements with the custom access flags. Introduce snd_ctl_elem_info_set_*() functions to set those flags in the info structure. Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
8e3ee8473b
commit
bbd32bbd37
2 changed files with 114 additions and 15 deletions
|
|
@ -557,6 +557,11 @@ void snd_ctl_elem_info_set_device(snd_ctl_elem_info_t *obj, unsigned int val);
|
|||
void snd_ctl_elem_info_set_subdevice(snd_ctl_elem_info_t *obj, unsigned int val);
|
||||
void snd_ctl_elem_info_set_name(snd_ctl_elem_info_t *obj, const char *val);
|
||||
void snd_ctl_elem_info_set_index(snd_ctl_elem_info_t *obj, unsigned int val);
|
||||
void snd_ctl_elem_info_set_read_write(snd_ctl_elem_info_t *obj, int rval, int wval);
|
||||
void snd_ctl_elem_info_set_tlv_read_write(snd_ctl_elem_info_t *obj, int rval, int wval);
|
||||
void snd_ctl_elem_info_set_volatile(snd_ctl_elem_info_t *obj, int val);
|
||||
void snd_ctl_elem_info_set_inactive(snd_ctl_elem_info_t *obj, int val);
|
||||
void snd_ctl_elem_info_set_led_group(snd_ctl_elem_info_t *obj, snd_ctl_led_group_t val);
|
||||
|
||||
int snd_ctl_add_integer_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
|
||||
unsigned int element_count,
|
||||
|
|
|
|||
|
|
@ -409,6 +409,33 @@ static bool validate_element_member_dimension(snd_ctl_elem_info_t *info)
|
|||
#define validate_element_member_dimension(info) true
|
||||
#endif /* deprecated */
|
||||
|
||||
#define USER_ACCESS_DEFAULT (\
|
||||
SNDRV_CTL_ELEM_ACCESS_READWRITE |\
|
||||
SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE |\
|
||||
SNDRV_CTL_ELEM_ACCESS_USER)
|
||||
|
||||
#define USER_ACCESS_SETTABLE (\
|
||||
SNDRV_CTL_ELEM_ACCESS_READWRITE |\
|
||||
SNDRV_CTL_ELEM_ACCESS_VOLATILE |\
|
||||
SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE |\
|
||||
SNDRV_CTL_ELEM_ACCESS_INACTIVE |\
|
||||
SNDRV_CTL_ELEM_ACCESS_LED_MASK |\
|
||||
SNDRV_CTL_ELEM_ACCESS_USER)
|
||||
|
||||
static inline int set_user_access(snd_ctl_elem_info_t *info)
|
||||
{
|
||||
if (info->access == 0) {
|
||||
info->access = USER_ACCESS_DEFAULT;
|
||||
} else {
|
||||
if ((info->access & SNDRV_CTL_ELEM_ACCESS_READWRITE) == 0)
|
||||
return -1;
|
||||
if (info->access & ~USER_ACCESS_SETTABLE)
|
||||
return -1;
|
||||
info->access |= SNDRV_CTL_ELEM_ACCESS_USER;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Create and add some user-defined control elements of integer type.
|
||||
* \param ctl A handle of backend module for control interface.
|
||||
|
|
@ -465,10 +492,10 @@ int snd_ctl_add_integer_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
|
|||
if (ctl == NULL || info == NULL || info->id.name[0] == '\0')
|
||||
return -EINVAL;
|
||||
|
||||
if (set_user_access(info))
|
||||
return -EINVAL;
|
||||
|
||||
info->type = SND_CTL_ELEM_TYPE_INTEGER;
|
||||
info->access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
|
||||
SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE |
|
||||
SNDRV_CTL_ELEM_ACCESS_USER;
|
||||
info->owner = element_count;
|
||||
info->count = member_count;
|
||||
info->value.integer.min = min;
|
||||
|
|
@ -555,10 +582,10 @@ int snd_ctl_add_integer64_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
|
|||
if (ctl == NULL || info == NULL || info->id.name[0] == '\0')
|
||||
return -EINVAL;
|
||||
|
||||
if (set_user_access(info))
|
||||
return -EINVAL;
|
||||
|
||||
info->type = SND_CTL_ELEM_TYPE_INTEGER64;
|
||||
info->access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
|
||||
SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE |
|
||||
SNDRV_CTL_ELEM_ACCESS_USER;
|
||||
info->owner = element_count;
|
||||
info->count = member_count;
|
||||
info->value.integer64.min = min;
|
||||
|
|
@ -634,10 +661,10 @@ int snd_ctl_add_boolean_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
|
|||
if (ctl == NULL || info == NULL || info->id.name[0] == '\0')
|
||||
return -EINVAL;
|
||||
|
||||
if (set_user_access(info))
|
||||
return -EINVAL;
|
||||
|
||||
info->type = SND_CTL_ELEM_TYPE_BOOLEAN;
|
||||
info->access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
|
||||
SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE |
|
||||
SNDRV_CTL_ELEM_ACCESS_USER;
|
||||
info->owner = element_count;
|
||||
info->count = member_count;
|
||||
info->value.integer.min = 0;
|
||||
|
|
@ -706,10 +733,10 @@ int snd_ctl_add_enumerated_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
|
|||
labels == NULL)
|
||||
return -EINVAL;
|
||||
|
||||
if (set_user_access(info))
|
||||
return -EINVAL;
|
||||
|
||||
info->type = SND_CTL_ELEM_TYPE_ENUMERATED;
|
||||
info->access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
|
||||
SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE |
|
||||
SNDRV_CTL_ELEM_ACCESS_USER;
|
||||
info->owner = element_count;
|
||||
info->count = member_count;
|
||||
info->value.enumerated.items = items;
|
||||
|
|
@ -786,10 +813,10 @@ int snd_ctl_add_bytes_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
|
|||
if (ctl == NULL || info == NULL || info->id.name[0] == '\0')
|
||||
return -EINVAL;
|
||||
|
||||
if (set_user_access(info))
|
||||
return -EINVAL;
|
||||
|
||||
info->type = SND_CTL_ELEM_TYPE_BYTES;
|
||||
info->access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
|
||||
SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE |
|
||||
SNDRV_CTL_ELEM_ACCESS_USER;
|
||||
info->owner = element_count;
|
||||
info->count = member_count;
|
||||
|
||||
|
|
@ -2901,6 +2928,73 @@ void snd_ctl_elem_info_set_index(snd_ctl_elem_info_t *obj, unsigned int val)
|
|||
obj->id.index = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set readability/writeability parameter of a CTL element id/info
|
||||
* \param obj CTL element id/info
|
||||
* \param rval readability part of element identifier
|
||||
* \param wval writeability part of element identifier
|
||||
*/
|
||||
void snd_ctl_elem_info_set_read_write(snd_ctl_elem_info_t *obj, int rval, int wval)
|
||||
{
|
||||
assert(obj);
|
||||
obj->access = (obj->access & ~SNDRV_CTL_ELEM_ACCESS_READWRITE) |
|
||||
(rval ? SNDRV_CTL_ELEM_ACCESS_READ : 0) |
|
||||
(wval ? SNDRV_CTL_ELEM_ACCESS_WRITE : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set TLV readability/writeability parameter of a CTL element id/info
|
||||
* \param obj CTL element id/info
|
||||
* \param rval TLV readability part of element identifier
|
||||
* \param wval TLV writeability part of element identifier
|
||||
*/
|
||||
void snd_ctl_elem_info_set_tlv_read_write(snd_ctl_elem_info_t *obj, int rval, int wval)
|
||||
{
|
||||
assert(obj);
|
||||
obj->access = (obj->access & ~SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE) |
|
||||
(rval ? SNDRV_CTL_ELEM_ACCESS_TLV_READ : 0) |
|
||||
(wval ? SNDRV_CTL_ELEM_ACCESS_TLV_WRITE : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set volatile parameter of a CTL element id/info
|
||||
* \param obj CTL element id/info
|
||||
* \param val volatile part of element identifier
|
||||
*/
|
||||
void snd_ctl_elem_info_set_volatile(snd_ctl_elem_info_t *obj, int val)
|
||||
{
|
||||
assert(obj);
|
||||
obj->access = (obj->access & ~SNDRV_CTL_ELEM_ACCESS_VOLATILE) |
|
||||
(val ? SNDRV_CTL_ELEM_ACCESS_VOLATILE : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set inactive parameter of a CTL element id/info
|
||||
* \param obj CTL element id/info
|
||||
* \param val inactive part of element identifier
|
||||
*/
|
||||
void snd_ctl_elem_info_set_inactive(snd_ctl_elem_info_t *obj, int val)
|
||||
{
|
||||
assert(obj);
|
||||
obj->access = (obj->access & ~SNDRV_CTL_ELEM_ACCESS_INACTIVE) |
|
||||
(val ? SNDRV_CTL_ELEM_ACCESS_INACTIVE : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set LED group parameter of a CTL element id/info
|
||||
* \param obj CTL element id/info
|
||||
* \param val LED group part of element identifier
|
||||
*/
|
||||
void snd_ctl_elem_info_set_led_group(snd_ctl_elem_info_t *obj, snd_ctl_led_group_t led)
|
||||
{
|
||||
assert(obj);
|
||||
if (led > SND_CTL_ELEM_LED_MICROPHONE)
|
||||
led = SND_CTL_ELEM_LED_NONE;
|
||||
obj->access = (obj->access & ~SNDRV_CTL_ELEM_ACCESS_LED_MASK) |
|
||||
(led << SNDRV_CTL_ELEM_ACCESS_LED_SHIFT);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Get size of data structure for an element.
|
||||
* \return Size in bytes.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue