mirror of
				https://github.com/alsa-project/alsa-lib.git
				synced 2025-11-03 09:01:52 -05:00 
			
		
		
		
	Add accessor to user control elements
Added accessor functions to user control elements, snd_ctl_elem_add_*(), and_ctl_elem_remove() and snd_ctl_elem_info_is_user().
This commit is contained in:
		
							parent
							
								
									77348e830f
								
							
						
					
					
						commit
						0732cce6f0
					
				
					 4 changed files with 133 additions and 33 deletions
				
			
		| 
						 | 
				
			
			@ -339,6 +339,7 @@ int snd_ctl_elem_info_is_volatile(const snd_ctl_elem_info_t *obj);
 | 
			
		|||
int snd_ctl_elem_info_is_inactive(const snd_ctl_elem_info_t *obj);
 | 
			
		||||
int snd_ctl_elem_info_is_locked(const snd_ctl_elem_info_t *obj);
 | 
			
		||||
int snd_ctl_elem_info_is_owner(const snd_ctl_elem_info_t *obj);
 | 
			
		||||
int snd_ctl_elem_info_is_user(const snd_ctl_elem_info_t *obj);
 | 
			
		||||
pid_t snd_ctl_elem_info_get_owner(const snd_ctl_elem_info_t *obj);
 | 
			
		||||
unsigned int snd_ctl_elem_info_get_count(const snd_ctl_elem_info_t *obj);
 | 
			
		||||
long snd_ctl_elem_info_get_min(const snd_ctl_elem_info_t *obj);
 | 
			
		||||
| 
						 | 
				
			
			@ -367,6 +368,12 @@ 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);
 | 
			
		||||
 | 
			
		||||
int snd_ctl_elem_add_integer(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id, unsigned int count, long imin, long imax, long istep);;
 | 
			
		||||
int snd_ctl_elem_add_integer64(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id, unsigned int count, long long imin, long long imax, long long istep);;
 | 
			
		||||
int snd_ctl_elem_add_boolean(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id, unsigned int count);
 | 
			
		||||
int snd_ctl_elem_add_iec958(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id);
 | 
			
		||||
int snd_ctl_elem_remove(snd_ctl_t *ctl, snd_ctl_elem_id_t *id);
 | 
			
		||||
 | 
			
		||||
size_t snd_ctl_elem_value_sizeof(void);
 | 
			
		||||
/** \hideinitializer
 | 
			
		||||
 * \brief allocate an invalid #snd_ctl_elem_value_t using standard alloca
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										10
									
								
								src/Versions
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								src/Versions
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -160,3 +160,13 @@ ALSA_1.0.5 {
 | 
			
		|||
    snd_timer_params_set_early_event;
 | 
			
		||||
    snd_timer_params_get_early_event;
 | 
			
		||||
} ALSA_1.0.4;
 | 
			
		||||
 | 
			
		||||
ALSA_1.0.8 {
 | 
			
		||||
  global:
 | 
			
		||||
 | 
			
		||||
    snd_ctl_elem_add_integer;
 | 
			
		||||
    snd_ctl_elem_add_integer64;
 | 
			
		||||
    snd_ctl_elem_add_boolean;
 | 
			
		||||
    snd_ctl_elem_add_iec958;
 | 
			
		||||
    snd_ctl_elem_remove;
 | 
			
		||||
} ALSA_1.0.5;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -253,31 +253,118 @@ int snd_ctl_elem_info(snd_ctl_t *ctl, snd_ctl_elem_info_t *info)
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief Create and add an user CTL element
 | 
			
		||||
 * \brief Create and add an user INTEGER CTL element
 | 
			
		||||
 * \param ctl CTL handle
 | 
			
		||||
 * \param info CTL element info
 | 
			
		||||
 * \param id CTL element id to add
 | 
			
		||||
 * \param count number of elements
 | 
			
		||||
 * \param min minimum value
 | 
			
		||||
 * \param max maximum value
 | 
			
		||||
 * \param step value step
 | 
			
		||||
 * \return 0 on success otherwise a negative error code
 | 
			
		||||
 *
 | 
			
		||||
 * Note that the new element is locked!
 | 
			
		||||
 */
 | 
			
		||||
int snd_ctl_elem_add(snd_ctl_t *ctl, snd_ctl_elem_info_t *info)
 | 
			
		||||
int snd_ctl_elem_add_integer(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
 | 
			
		||||
			     unsigned int count, long min, long max, long step)
 | 
			
		||||
{
 | 
			
		||||
	assert(ctl && info && info->id.name[0]);
 | 
			
		||||
	snd_ctl_elem_info_t *info;
 | 
			
		||||
	snd_ctl_elem_value_t *val;
 | 
			
		||||
	unsigned int i;
 | 
			
		||||
	int err;
 | 
			
		||||
 | 
			
		||||
	assert(ctl && id && id->name[0]);
 | 
			
		||||
	snd_ctl_elem_info_alloca(&info);
 | 
			
		||||
	info->id = *id;
 | 
			
		||||
	info->type = SND_CTL_ELEM_TYPE_INTEGER;
 | 
			
		||||
	info->count = count;
 | 
			
		||||
	info->value.integer.min = min;
 | 
			
		||||
	info->value.integer.max = max;
 | 
			
		||||
	info->value.integer.step = step;
 | 
			
		||||
	err = ctl->ops->element_add(ctl, info);
 | 
			
		||||
	if (err < 0)
 | 
			
		||||
		return err;
 | 
			
		||||
	snd_ctl_elem_value_alloca(&val);
 | 
			
		||||
	val->id = *id;
 | 
			
		||||
	for (i = 0; i < count; i++)
 | 
			
		||||
		val->value.integer.value[i] = min;
 | 
			
		||||
	err = ctl->ops->element_write(ctl, val);
 | 
			
		||||
	return err;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief Create and add an user INTEGER64 CTL element
 | 
			
		||||
 * \param ctl CTL handle
 | 
			
		||||
 * \param id CTL element id to add
 | 
			
		||||
 * \param count number of elements
 | 
			
		||||
 * \param min minimum value
 | 
			
		||||
 * \param max maximum value
 | 
			
		||||
 * \param step value step
 | 
			
		||||
 * \return 0 on success otherwise a negative error code
 | 
			
		||||
 */
 | 
			
		||||
int snd_ctl_elem_add_integer64(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
 | 
			
		||||
			       unsigned int count, long long min, long long max,
 | 
			
		||||
			       long long step)
 | 
			
		||||
{
 | 
			
		||||
	snd_ctl_elem_info_t *info;
 | 
			
		||||
	snd_ctl_elem_value_t *val;
 | 
			
		||||
	unsigned int i;
 | 
			
		||||
	int err;
 | 
			
		||||
 | 
			
		||||
	assert(ctl && id && id->name[0]);
 | 
			
		||||
	snd_ctl_elem_info_alloca(&info);
 | 
			
		||||
	info->id = *id;
 | 
			
		||||
	info->type = SND_CTL_ELEM_TYPE_INTEGER64;
 | 
			
		||||
	info->count = count;
 | 
			
		||||
	info->value.integer64.min = min;
 | 
			
		||||
	info->value.integer64.max = max;
 | 
			
		||||
	info->value.integer64.step = step;
 | 
			
		||||
	err = ctl->ops->element_add(ctl, info);
 | 
			
		||||
	if (err < 0)
 | 
			
		||||
		return err;
 | 
			
		||||
	snd_ctl_elem_value_alloca(&val);
 | 
			
		||||
	val->id = *id;
 | 
			
		||||
	for (i = 0; i < count; i++)
 | 
			
		||||
		val->value.integer64.value[i] = min;
 | 
			
		||||
	err = ctl->ops->element_write(ctl, val);
 | 
			
		||||
	return err;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief Create and add an user BOOLEAN CTL element
 | 
			
		||||
 * \param ctl CTL handle
 | 
			
		||||
 * \param id CTL element id to add
 | 
			
		||||
 * \param count number of elements
 | 
			
		||||
 * \return 0 on success otherwise a negative error code
 | 
			
		||||
 */
 | 
			
		||||
int snd_ctl_elem_add_boolean(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
 | 
			
		||||
			     unsigned int count)
 | 
			
		||||
{
 | 
			
		||||
	snd_ctl_elem_info_t *info;
 | 
			
		||||
 | 
			
		||||
	assert(ctl && id && id->name[0]);
 | 
			
		||||
	snd_ctl_elem_info_alloca(&info);
 | 
			
		||||
	info->id = *id;
 | 
			
		||||
	info->type = SND_CTL_ELEM_TYPE_BOOLEAN;
 | 
			
		||||
	info->count = count;
 | 
			
		||||
	info->value.integer.min = 0;
 | 
			
		||||
	info->value.integer.max = 1;
 | 
			
		||||
	return ctl->ops->element_add(ctl, info);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief Replace an user CTL element
 | 
			
		||||
 * \brief Create and add an user IEC958 CTL element
 | 
			
		||||
 * \param ctl CTL handle
 | 
			
		||||
 * \param info CTL element info
 | 
			
		||||
 * \param id CTL element info to add
 | 
			
		||||
 * \return 0 on success otherwise a negative error code
 | 
			
		||||
 *
 | 
			
		||||
 * Note that the new element is locked!
 | 
			
		||||
 */
 | 
			
		||||
int snd_ctl_elem_replace(snd_ctl_t *ctl, snd_ctl_elem_info_t *info)
 | 
			
		||||
int snd_ctl_elem_add_iec958(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id)
 | 
			
		||||
{
 | 
			
		||||
	assert(ctl && info && info->id.name[0]);
 | 
			
		||||
	return ctl->ops->element_replace(ctl, info);
 | 
			
		||||
	snd_ctl_elem_info_t *info;
 | 
			
		||||
 | 
			
		||||
	assert(ctl && id && id->name[0]);
 | 
			
		||||
	snd_ctl_elem_info_alloca(&info);
 | 
			
		||||
	info->id = *id;
 | 
			
		||||
	info->type = SND_CTL_ELEM_TYPE_IEC958;
 | 
			
		||||
	info->count = 1;
 | 
			
		||||
	return ctl->ops->element_add(ctl, info);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
| 
						 | 
				
			
			@ -285,8 +372,6 @@ int snd_ctl_elem_replace(snd_ctl_t *ctl, snd_ctl_elem_info_t *info)
 | 
			
		|||
 * \param ctl CTL handle
 | 
			
		||||
 * \param id CTL element identification
 | 
			
		||||
 * \return 0 on success otherwise a negative error code
 | 
			
		||||
 *
 | 
			
		||||
 * Note that the new element is locked!
 | 
			
		||||
 */
 | 
			
		||||
int snd_ctl_elem_remove(snd_ctl_t *ctl, snd_ctl_elem_id_t *id)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -1569,6 +1654,17 @@ int snd_ctl_elem_info_is_owner(const snd_ctl_elem_info_t *obj)
 | 
			
		|||
	return !!(obj->access & SNDRV_CTL_ELEM_ACCESS_OWNER);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief Get info if it's a user element
 | 
			
		||||
 * \param obj CTL element id/info
 | 
			
		||||
 * \return 0 if element value is a system element, 1 if it's a user-created element
 | 
			
		||||
 */
 | 
			
		||||
int snd_ctl_elem_info_is_user(const snd_ctl_elem_info_t *obj)
 | 
			
		||||
{
 | 
			
		||||
	assert(obj);
 | 
			
		||||
	return !!(obj->access & SNDRV_CTL_ELEM_ACCESS_USER);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief (DEPRECATED) Get info about values passing policy from a CTL element value
 | 
			
		||||
 * \param obj CTL element id/info
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -333,23 +333,9 @@ static void snd_pcm_softvol_dump(snd_pcm_t *pcm, snd_output_t *out)
 | 
			
		|||
int snd_ctl_elem_add(snd_ctl_t *ctl, snd_ctl_elem_info_t *info);
 | 
			
		||||
int snd_ctl_elem_replace(snd_ctl_t *ctl, snd_ctl_elem_info_t *info);
 | 
			
		||||
 | 
			
		||||
static int add_user_ctl(snd_pcm_softvol_t *svol, snd_ctl_elem_info_t *cinfo, int replace)
 | 
			
		||||
static int add_user_ctl(snd_pcm_softvol_t *svol, snd_ctl_elem_info_t *cinfo)
 | 
			
		||||
{
 | 
			
		||||
	int err;
 | 
			
		||||
 | 
			
		||||
	cinfo->type = SND_CTL_ELEM_TYPE_INTEGER;
 | 
			
		||||
	cinfo->count = 1;
 | 
			
		||||
	cinfo->value.integer.min = 0;
 | 
			
		||||
	cinfo->value.integer.max = svol->max_val;
 | 
			
		||||
	if (replace)
 | 
			
		||||
		err = snd_ctl_elem_replace(svol->ctl, cinfo);
 | 
			
		||||
	else
 | 
			
		||||
		err = snd_ctl_elem_add(svol->ctl, cinfo);
 | 
			
		||||
	if (err < 0)
 | 
			
		||||
		return err;
 | 
			
		||||
	/* initialize */
 | 
			
		||||
	svol->elem.value.integer.value[0] = 0;
 | 
			
		||||
	return snd_ctl_elem_write(svol->ctl, &svol->elem);
 | 
			
		||||
	return snd_ctl_elem_add_integer(svol->ctl, &cinfo->id, 1, 0, svol->max_val, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int softvol_load_control(snd_pcm_t *pcm, snd_pcm_softvol_t *svol,
 | 
			
		||||
| 
						 | 
				
			
			@ -392,7 +378,7 @@ static int softvol_load_control(snd_pcm_t *pcm, snd_pcm_softvol_t *svol,
 | 
			
		|||
			SNDERR("Cannot get info for CTL %s", ctl_name);
 | 
			
		||||
			return err;
 | 
			
		||||
		}
 | 
			
		||||
		err = add_user_ctl(svol, cinfo, 0);
 | 
			
		||||
		err = add_user_ctl(svol, cinfo);
 | 
			
		||||
		if (err < 0) {
 | 
			
		||||
			SNDERR("Cannot add a control");
 | 
			
		||||
			return err;
 | 
			
		||||
| 
						 | 
				
			
			@ -406,7 +392,8 @@ static int softvol_load_control(snd_pcm_t *pcm, snd_pcm_softvol_t *svol,
 | 
			
		|||
				SNDERR("Invalid control");
 | 
			
		||||
				return -EINVAL;
 | 
			
		||||
			}
 | 
			
		||||
			err = add_user_ctl(svol, cinfo, 1);
 | 
			
		||||
			snd_ctl_elem_remove(svol->ctl, &cinfo->id);
 | 
			
		||||
			err = add_user_ctl(svol, cinfo);
 | 
			
		||||
			if (err < 0) {
 | 
			
		||||
				SNDERR("Cannot replace a control");
 | 
			
		||||
				return err;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue