mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-05 13:30:00 -05:00
Added bag operations for the high-level control interface.
Added event layer for simple mixer controls (not fully finished).
This commit is contained in:
parent
5bb1fcb00a
commit
7376ad380e
7 changed files with 304 additions and 85 deletions
|
|
@ -29,6 +29,9 @@
|
|||
#include "asoundlib.h"
|
||||
#include "mixer_local.h"
|
||||
|
||||
static void snd_mixer_simple_read_rebuild(snd_ctl_t *ctl_handle, void *private_data);
|
||||
static void snd_mixer_simple_read_add(snd_ctl_t *ctl_handle, void *private_data, snd_hcontrol_t *hcontrol);
|
||||
|
||||
int snd_mixer_open(snd_mixer_t **r_handle, int card)
|
||||
{
|
||||
snd_mixer_t *handle;
|
||||
|
|
@ -40,12 +43,21 @@ int snd_mixer_open(snd_mixer_t **r_handle, int card)
|
|||
*r_handle = NULL;
|
||||
if ((err = snd_ctl_open(&ctl_handle, card)) < 0)
|
||||
return err;
|
||||
if ((err = snd_ctl_hcallback_rebuild(ctl_handle, snd_mixer_simple_read_rebuild, handle)) < 0) {
|
||||
snd_ctl_close(ctl_handle);
|
||||
return err;
|
||||
}
|
||||
if ((err = snd_ctl_hcallback_add(ctl_handle, snd_mixer_simple_read_add, handle)) < 0) {
|
||||
snd_ctl_close(ctl_handle);
|
||||
return err;
|
||||
}
|
||||
handle = (snd_mixer_t *) calloc(1, sizeof(snd_mixer_t));
|
||||
if (handle == NULL) {
|
||||
snd_ctl_close(ctl_handle);
|
||||
return -ENOMEM;
|
||||
}
|
||||
handle->ctl_handle = ctl_handle;
|
||||
INIT_LIST_HEAD(&handle->simples);
|
||||
*r_handle = handle;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -88,10 +100,10 @@ const char *snd_mixer_simple_channel_name(int channel)
|
|||
|
||||
int snd_mixer_simple_control_list(snd_mixer_t *handle, snd_mixer_simple_control_list_t *list)
|
||||
{
|
||||
struct list_head *lh;
|
||||
mixer_simple_t *s;
|
||||
snd_mixer_sid_t *p;
|
||||
int err;
|
||||
unsigned int tmp;
|
||||
int err, idx;
|
||||
|
||||
if (handle == NULL || list == NULL)
|
||||
return -EINVAL;
|
||||
|
|
@ -99,25 +111,34 @@ int snd_mixer_simple_control_list(snd_mixer_t *handle, snd_mixer_simple_control_
|
|||
if ((err = snd_mixer_simple_build(handle)) < 0)
|
||||
return err;
|
||||
list->controls_count = 0;
|
||||
tmp = list->controls_offset;
|
||||
for (s = handle->simple_first; s != NULL && tmp > 0; s = s->next);
|
||||
tmp = list->controls_request;
|
||||
p = list->pids;
|
||||
if (tmp > 0 && p == NULL)
|
||||
if (list->controls_request > 0 && p == NULL)
|
||||
return -EINVAL;
|
||||
for (; s != NULL && tmp > 0; s = s->next, tmp--, p++, list->controls_count++)
|
||||
memcpy(p, &s->sid, sizeof(*p));
|
||||
idx = 0;
|
||||
list_for_each(lh, &handle->simples) {
|
||||
if (idx >= list->controls_offset + list->controls_request)
|
||||
break;
|
||||
if (idx >= list->controls_offset) {
|
||||
s = list_entry(lh, mixer_simple_t, list);
|
||||
memcpy(p, &s->sid, sizeof(*p)); p++;
|
||||
list->controls_count++;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
list->controls = handle->simple_count;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static mixer_simple_t *look_for_simple(snd_mixer_t *handle, snd_mixer_sid_t *sid)
|
||||
{
|
||||
struct list_head *list;
|
||||
mixer_simple_t *s;
|
||||
|
||||
for (s = handle->simple_first; s != NULL; s = s->next)
|
||||
list_for_each(list, &handle->simples) {
|
||||
s = list_entry(list, mixer_simple_t, list);
|
||||
if (!strcmp(s->sid.name, sid->name) && s->sid.index == sid->index)
|
||||
return s;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -162,53 +183,26 @@ static void snd_mixer_simple_read_rebuild(snd_ctl_t *ctl_handle, void *private_d
|
|||
handle->simple_changes++;
|
||||
}
|
||||
|
||||
static void event_for_all_simple_controls(snd_mixer_t *handle, snd_ctl_event_type_t etype, snd_control_id_t *id)
|
||||
static void snd_mixer_simple_read_add(snd_ctl_t *ctl_handle, void *private_data, snd_hcontrol_t *hcontrol)
|
||||
{
|
||||
snd_mixer_t *handle = (snd_mixer_t *)private_data;
|
||||
mixer_simple_t *s;
|
||||
struct list_head *list;
|
||||
|
||||
for (s = handle->simple_first; s != NULL; s = s->next) {
|
||||
if (s->event)
|
||||
s->event(handle, etype, id);
|
||||
list_for_each(list, &handle->simples) {
|
||||
s = list_entry(list, mixer_simple_t, list);
|
||||
if (s->event_add)
|
||||
s->event_add(handle, hcontrol);
|
||||
}
|
||||
}
|
||||
|
||||
static void snd_mixer_simple_read_value(snd_ctl_t *ctl_handle, void *private_data, snd_control_id_t *id)
|
||||
{
|
||||
snd_mixer_t *handle = (snd_mixer_t *)private_data;
|
||||
if (handle->ctl_handle != ctl_handle)
|
||||
return;
|
||||
event_for_all_simple_controls(handle, SND_CTL_EVENT_VALUE, id);
|
||||
}
|
||||
|
||||
static void snd_mixer_simple_read_change(snd_ctl_t *ctl_handle, void *private_data, snd_control_id_t *id)
|
||||
{
|
||||
snd_mixer_t *handle = (snd_mixer_t *)private_data;
|
||||
if (handle->ctl_handle != ctl_handle)
|
||||
return;
|
||||
event_for_all_simple_controls(handle, SND_CTL_EVENT_CHANGE, id);
|
||||
}
|
||||
|
||||
static void snd_mixer_simple_read_add(snd_ctl_t *ctl_handle, void *private_data, snd_control_id_t *id)
|
||||
{
|
||||
snd_mixer_t *handle = (snd_mixer_t *)private_data;
|
||||
if (handle->ctl_handle != ctl_handle)
|
||||
return;
|
||||
event_for_all_simple_controls(handle, SND_CTL_EVENT_ADD, id);
|
||||
}
|
||||
|
||||
static void snd_mixer_simple_read_remove(snd_ctl_t *ctl_handle, void *private_data, snd_control_id_t *id)
|
||||
{
|
||||
snd_mixer_t *handle = (snd_mixer_t *)private_data;
|
||||
if (handle->ctl_handle != ctl_handle)
|
||||
return;
|
||||
event_for_all_simple_controls(handle, SND_CTL_EVENT_REMOVE, id);
|
||||
}
|
||||
|
||||
int snd_mixer_simple_read(snd_mixer_t *handle, snd_mixer_simple_callbacks_t *callbacks)
|
||||
{
|
||||
mixer_simple_t *s;
|
||||
struct list_head *list;
|
||||
int err;
|
||||
|
||||
if (handle == NULL)
|
||||
if (handle == NULL || callbacks == NULL)
|
||||
return -EINVAL;
|
||||
if (!handle->simple_valid)
|
||||
snd_mixer_simple_build(handle);
|
||||
|
|
@ -219,5 +213,13 @@ int snd_mixer_simple_read(snd_mixer_t *handle, snd_mixer_simple_callbacks_t *cal
|
|||
return err;
|
||||
}
|
||||
handle->callbacks = NULL;
|
||||
list_for_each(list, &handle->simples) {
|
||||
s = list_entry(list, mixer_simple_t, list);
|
||||
if (s->change > 0) {
|
||||
s->change = 0;
|
||||
if (callbacks->value)
|
||||
callbacks->value(handle, callbacks->private_data, &s->sid);
|
||||
}
|
||||
}
|
||||
return handle->simple_changes;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue