From 4085613b1dbbccb28caf1ce3c852e71642d622c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 14 Feb 2013 20:28:17 +0000 Subject: [PATCH] e_mixer: channel_get_by_name returns a E_Mixer_Channel_Info this opens the gates to capabilities bit map stored in E_Mixer_Channel_Info SVN revision: 83913 --- src/modules/mixer/e_mod_main.c | 75 +++++++++++++++++---------------- src/modules/mixer/e_mod_main.h | 2 +- src/modules/mixer/e_mod_mixer.c | 17 +++++--- src/modules/mixer/e_mod_mixer.h | 11 ++--- src/modules/mixer/sys_alsa.c | 17 +++++--- src/modules/mixer/sys_dummy.c | 18 +++++--- src/modules/mixer/sys_pulse.c | 14 +++--- 7 files changed, 83 insertions(+), 71 deletions(-) diff --git a/src/modules/mixer/e_mod_main.c b/src/modules/mixer/e_mod_main.c index ad0159eb0..62af0e5dd 100644 --- a/src/modules/mixer/e_mod_main.c +++ b/src/modules/mixer/e_mod_main.c @@ -251,7 +251,7 @@ _mixer_balance_left(E_Mixer_Instance *inst) E_Mixer_Channel_State *state; state = &inst->mixer_state; - e_mod_mixer_volume_get(inst->sys, inst->channel, + e_mod_mixer_volume_get(inst->sys, inst->channel_info->id, &state->left, &state->right); if (state->left >= 0) { @@ -268,7 +268,7 @@ _mixer_balance_left(E_Mixer_Instance *inst) state->right = 100; } - e_mod_mixer_volume_set(inst->sys, inst->channel, + e_mod_mixer_volume_set(inst->sys, inst->channel_info->id, state->left, state->right); _mixer_gadget_update(inst); } @@ -279,7 +279,7 @@ _mixer_balance_right(E_Mixer_Instance *inst) E_Mixer_Channel_State *state; state = &inst->mixer_state; - e_mod_mixer_volume_get(inst->sys, inst->channel, + e_mod_mixer_volume_get(inst->sys, inst->channel_info->id, &state->left, &state->right); if (state->left >= 0) { @@ -295,7 +295,7 @@ _mixer_balance_right(E_Mixer_Instance *inst) else state->right = 0; } - e_mod_mixer_volume_set(inst->sys, inst->channel, + e_mod_mixer_volume_set(inst->sys, inst->channel_info->id, state->left, state->right); _mixer_gadget_update(inst); } @@ -306,7 +306,7 @@ _mixer_volume_increase(E_Mixer_Instance *inst, Eina_Bool non_ui) E_Mixer_Channel_State *state; state = &inst->mixer_state; - e_mod_mixer_volume_get(inst->sys, inst->channel, + e_mod_mixer_volume_get(inst->sys, inst->channel_info->id, &state->left, &state->right); if (state->left >= 0) { @@ -324,7 +324,7 @@ _mixer_volume_increase(E_Mixer_Instance *inst, Eina_Bool non_ui) state->right = 100; } - e_mod_mixer_volume_set(inst->sys, inst->channel, + e_mod_mixer_volume_set(inst->sys, inst->channel_info->id, state->left, state->right); _mixer_gadget_update(inst); if (non_ui) @@ -337,7 +337,7 @@ _mixer_volume_decrease(E_Mixer_Instance *inst, Eina_Bool non_ui) E_Mixer_Channel_State *state; state = &inst->mixer_state; - e_mod_mixer_volume_get(inst->sys, inst->channel, + e_mod_mixer_volume_get(inst->sys, inst->channel_info->id, &state->left, &state->right); if (state->left >= 0) { @@ -354,7 +354,7 @@ _mixer_volume_decrease(E_Mixer_Instance *inst, Eina_Bool non_ui) state->right = 0; } - e_mod_mixer_volume_set(inst->sys, inst->channel, + e_mod_mixer_volume_set(inst->sys, inst->channel_info->id, state->left, state->right); _mixer_gadget_update(inst); if (non_ui) @@ -366,14 +366,14 @@ _mixer_toggle_mute(E_Mixer_Instance *inst, Eina_Bool non_ui) { E_Mixer_Channel_State *state; - if (!e_mod_mixer_mutable_get(inst->sys, inst->channel)) + if (!e_mod_mixer_mutable_get(inst->sys, inst->channel_info->id)) return; state = &inst->mixer_state; - e_mod_mixer_mute_get(inst->sys, inst->channel, &state->mute); + e_mod_mixer_mute_get(inst->sys, inst->channel_info->id, &state->mute); state->mute = !state->mute; - e_mod_mixer_mute_set(inst->sys, inst->channel, state->mute); - if (!state->mute) e_mod_mixer_volume_set(inst->sys, inst->channel, state->left, state->right); + e_mod_mixer_mute_set(inst->sys, inst->channel_info->id, state->mute); + if (!state->mute) e_mod_mixer_volume_set(inst->sys, inst->channel_info->id, state->left, state->right); _mixer_gadget_update(inst); if (non_ui) { @@ -390,7 +390,7 @@ _mixer_popup_cb_volume_left_change(void *data, Evas_Object *obj, void *event __U E_Mixer_Instance *inst = data; E_Mixer_Channel_State *state = &inst->mixer_state; - e_mod_mixer_volume_get(inst->sys, inst->channel, + e_mod_mixer_volume_get(inst->sys, inst->channel_info->id, &state->left, &state->right); state->left = (int)e_slider_value_get(obj); @@ -400,7 +400,7 @@ _mixer_popup_cb_volume_left_change(void *data, Evas_Object *obj, void *event __U e_slider_value_set(inst->ui.right, state->right); } - e_mod_mixer_volume_set(inst->sys, inst->channel, + e_mod_mixer_volume_set(inst->sys, inst->channel_info->id, state->left, state->right); if (!_mixer_using_default) _mixer_gadget_update(inst); } @@ -411,7 +411,7 @@ _mixer_popup_cb_volume_right_change(void *data, Evas_Object *obj, void *event __ E_Mixer_Instance *inst = data; E_Mixer_Channel_State *state = &inst->mixer_state; - e_mod_mixer_volume_get(inst->sys, inst->channel, + e_mod_mixer_volume_get(inst->sys, inst->channel_info->id, &state->left, &state->right); state->right = (int)e_slider_value_get(obj); @@ -421,7 +421,7 @@ _mixer_popup_cb_volume_right_change(void *data, Evas_Object *obj, void *event __ e_slider_value_set(inst->ui.left, state->left); } - e_mod_mixer_volume_set(inst->sys, inst->channel, + e_mod_mixer_volume_set(inst->sys, inst->channel_info->id, state->left, state->right); if (!_mixer_using_default) _mixer_gadget_update(inst); } @@ -433,7 +433,7 @@ _mixer_popup_cb_mute_change(void *data, Evas_Object *obj, void *event __UNUSED__ E_Mixer_Channel_State *state = &inst->mixer_state; state->mute = e_widget_check_checked_get(obj); - e_mod_mixer_mute_set(inst->sys, inst->channel, state->mute); + e_mod_mixer_mute_set(inst->sys, inst->channel_info->id, state->mute); if (!_mixer_using_default) _mixer_gadget_update(inst); } @@ -642,7 +642,7 @@ _mixer_popup_new(E_Mixer_Instance *inst) return; state = &inst->mixer_state; - e_mod_mixer_state_get(inst->sys, inst->channel, state); + e_mod_mixer_state_get(inst->sys, inst->channel_info->id, state); if ((state->right >= 0) && (inst->conf->show_locked || (!inst->conf->lock_sliders))) @@ -680,7 +680,7 @@ _mixer_popup_new(E_Mixer_Instance *inst) else inst->ui.right = NULL; - if (e_mod_mixer_mutable_get(inst->sys, inst->channel)) + if (e_mod_mixer_mutable_get(inst->sys, inst->channel_info->id)) { inst->ui.mute = e_widget_check_add(evas, _("Mute"), &state->mute); evas_object_show(inst->ui.mute); @@ -835,19 +835,19 @@ _mixer_sys_setup(E_Mixer_Instance *inst) inst->sys = e_mod_mixer_new(conf->card); if (!inst->sys) { - inst->channel = NULL; + inst->channel_info = NULL; return 0; } - inst->channel = e_mod_mixer_channel_get_by_name(inst->sys, conf->channel_name); - return !!inst->channel; + inst->channel_info = e_mod_mixer_channel_info_get_by_name(inst->sys, conf->channel_name); + return !!inst->channel_info->id; } static int _mixer_system_cb_update(void *data, E_Mixer_System *sys __UNUSED__) { E_Mixer_Instance *inst = data; - e_mod_mixer_state_get(inst->sys, inst->channel, &inst->mixer_state); + e_mod_mixer_state_get(inst->sys, inst->channel_info->id, &inst->mixer_state); _mixer_gadget_update(inst); return 1; @@ -911,8 +911,8 @@ _mixer_sys_setup_default_channel(E_Mixer_Instance *inst) if (!channel_name) goto error; - inst->channel = e_mod_mixer_channel_get_by_name(inst->sys, channel_name); - if (!inst->channel) + inst->channel_info = e_mod_mixer_channel_info_get_by_name(inst->sys, channel_name); + if (!inst->channel_info) goto system_error; conf->channel_name = channel_name; @@ -971,9 +971,9 @@ e_sys_pulse_ready_cb(Eina_Bool ready) { EINA_LIST_FOREACH(ctxt->instances, l, inst) { - e_mod_mixer_channel_del(inst->channel); + e_mod_mixer_channel_info_free(inst->channel_info); e_mod_mixer_del(inst->sys); - inst->channel = NULL; + inst->channel_info = NULL; inst->sys = NULL; } } @@ -993,11 +993,14 @@ e_sys_pulse_ready_cb(Eina_Bool ready) } if (_mixer_using_default) e_mixer_alsa_callback_set(inst->sys, _mixer_system_cb_update, inst); else e_mixer_alsa_callback_set(inst->sys, NULL, NULL); - if ((inst->mixer_state.left > -1) && (inst->mixer_state.right > -1) && (inst->mixer_state.mute > -1)) - e_mod_mixer_volume_set(inst->sys, inst->channel, - inst->mixer_state.left, inst->mixer_state.right); - else - e_mod_mixer_state_get(inst->sys, inst->channel, &inst->mixer_state); + if (inst->channel_info) + { + if ((inst->mixer_state.left > -1) && (inst->mixer_state.right > -1) && (inst->mixer_state.mute > -1)) + e_mod_mixer_volume_set(inst->sys, inst->channel_info->id, + inst->mixer_state.left, inst->mixer_state.right); + else + e_mod_mixer_state_get(inst->sys, inst->channel_info->id, &inst->mixer_state); + } _mixer_gadget_update(inst); } called = EINA_TRUE; @@ -1017,7 +1020,7 @@ e_sys_pulse_update_cb(void) { if (inst->conf->using_default) _mixer_sys_setup_default_card(inst); - e_mod_mixer_state_get(inst->sys, inst->channel, &inst->mixer_state); + e_mod_mixer_state_get(inst->sys, inst->channel_info->id, &inst->mixer_state); _mixer_gadget_update(inst); } } @@ -1088,10 +1091,10 @@ _gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style) { if (_mixer_using_default && ((inst->mixer_state.left > -1) && (inst->mixer_state.right > -1) && (inst->mixer_state.mute > -1))) - e_mod_mixer_volume_set(inst->sys, inst->channel, + e_mod_mixer_volume_set(inst->sys, inst->channel_info->id, inst->mixer_state.left, inst->mixer_state.right); else - e_mod_mixer_state_get(inst->sys, inst->channel, &inst->mixer_state); + e_mod_mixer_state_get(inst->sys, inst->channel_info->id, &inst->mixer_state); _mixer_gadget_update(inst); } @@ -1130,7 +1133,7 @@ _gc_shutdown(E_Gadcon_Client *gcc) inst->conf->state.left = inst->mixer_state.left; inst->conf->state.right = inst->mixer_state.right; evas_object_del(inst->ui.gadget); - e_mod_mixer_channel_del(inst->channel); + e_mod_mixer_channel_info_free(inst->channel_info); e_mod_mixer_del(inst->sys); inst->conf->instance = NULL; diff --git a/src/modules/mixer/e_mod_main.h b/src/modules/mixer/e_mod_main.h index 2d0523633..ffad6ca8b 100644 --- a/src/modules/mixer/e_mod_main.h +++ b/src/modules/mixer/e_mod_main.h @@ -56,7 +56,7 @@ typedef struct E_Mixer_Instance } ui; E_Mixer_System *sys; - E_Mixer_Channel *channel; + E_Mixer_Channel_Info *channel_info; E_Mixer_Channel_State mixer_state; E_Mixer_Gadget_Config *conf; diff --git a/src/modules/mixer/e_mod_mixer.c b/src/modules/mixer/e_mod_mixer.c index 6173bdc76..fe1dcd778 100644 --- a/src/modules/mixer/e_mod_mixer.c +++ b/src/modules/mixer/e_mod_mixer.c @@ -11,10 +11,8 @@ E_Mixer_Capture_Cb e_mod_mixer_capture_get; E_Mixer_Cb e_mod_mixer_new; E_Mixer_Cb e_mod_mixer_del; E_Mixer_Cb e_mod_mixer_channel_default_name_get; -E_Mixer_Cb e_mod_mixer_channel_get_by_name; +E_Mixer_Cb e_mod_mixer_channel_info_get_by_name; E_Mixer_Cb e_mod_mixer_channel_name_get; -E_Mixer_Cb e_mod_mixer_channel_del; -E_Mixer_Cb e_mod_mixer_channel_free; E_Mixer_Cb e_mod_mixer_channels_get; E_Mixer_Cb e_mod_mixer_channel_names_get; E_Mixer_Cb e_mod_mixer_card_name_get; @@ -34,9 +32,8 @@ e_mixer_default_setup(void) e_mod_mixer_new = (void *)e_mixer_alsa_new; e_mod_mixer_del = (void *)e_mixer_alsa_del; e_mod_mixer_channel_default_name_get = (void *)e_mixer_alsa_get_default_channel_name; - e_mod_mixer_channel_get_by_name = (void *)e_mixer_alsa_get_channel_by_name; + e_mod_mixer_channel_info_get_by_name = (void *)e_mixer_alsa_get_channel_by_name; e_mod_mixer_channel_name_get = (void *)e_mixer_alsa_get_channel_name; - e_mod_mixer_channel_del = (void *)e_mixer_alsa_channel_del; e_mod_mixer_channels_get = (void *)e_mixer_alsa_get_channels; e_mod_mixer_channel_names_get = (void *)e_mixer_alsa_get_channel_names; e_mod_mixer_card_name_get = (void *)e_mixer_alsa_get_card_name; @@ -58,9 +55,8 @@ e_mixer_pulse_setup() e_mod_mixer_new = (void *)e_mixer_pulse_new; e_mod_mixer_del = (void *)e_mixer_pulse_del; e_mod_mixer_channel_default_name_get = (void *)e_mixer_pulse_get_default_channel_name; - e_mod_mixer_channel_get_by_name = (void *)e_mixer_pulse_get_channel_by_name; + e_mod_mixer_channel_info_get_by_name = (void *)e_mixer_pulse_get_channel_by_name; e_mod_mixer_channel_name_get = (void *)e_mixer_pulse_get_channel_name; - e_mod_mixer_channel_del = (void *)e_mixer_pulse_channel_del; e_mod_mixer_channels_get = (void *)e_mixer_pulse_get_channels; e_mod_mixer_channel_names_get = (void *)e_mixer_pulse_get_channel_names; e_mod_mixer_card_name_get = (void *)e_mixer_pulse_get_card_name; @@ -82,6 +78,13 @@ _channel_info_cmp(const void *data_a, const void *data_b) return strcmp(a->name, b->name); } +void e_mod_mixer_channel_info_free(E_Mixer_Channel_Info* info) +{ + if (!info) return; + eina_stringshare_del(info->name); + free(info); +} + Eina_List * e_mod_mixer_channel_infos_get(E_Mixer_System *sys) { diff --git a/src/modules/mixer/e_mod_mixer.h b/src/modules/mixer/e_mod_mixer.h index 118bd5558..3abe1e869 100644 --- a/src/modules/mixer/e_mod_mixer.h +++ b/src/modules/mixer/e_mod_mixer.h @@ -42,15 +42,14 @@ extern E_Mixer_Capture_Cb e_mod_mixer_capture_get; extern E_Mixer_Cb e_mod_mixer_new; extern E_Mixer_Cb e_mod_mixer_del; extern E_Mixer_Cb e_mod_mixer_channel_default_name_get; -extern E_Mixer_Cb e_mod_mixer_channel_get_by_name; +extern E_Mixer_Cb e_mod_mixer_channel_info_get_by_name; extern E_Mixer_Cb e_mod_mixer_channel_name_get; -extern E_Mixer_Cb e_mod_mixer_channel_del; -extern E_Mixer_Cb e_mod_mixer_channel_free; extern E_Mixer_Cb e_mod_mixer_channel_names_get; extern E_Mixer_Cb e_mod_mixer_card_name_get; extern E_Mixer_Cb e_mod_mixer_card_names_get; extern E_Mixer_Cb e_mod_mixer_card_default_get; +void e_mod_mixer_channel_info_free(E_Mixer_Channel_Info*); Eina_List *e_mod_mixer_channel_infos_get(E_Mixer_System *sys); void e_mod_mixer_channel_infos_free(Eina_List*); void e_mod_mixer_channel_names_free(Eina_List*); @@ -74,8 +73,7 @@ Eina_List *e_mixer_alsa_get_channels(E_Mixer_System *self); Eina_List *e_mixer_alsa_get_channel_names(E_Mixer_System *self); const char *e_mixer_alsa_get_default_channel_name(E_Mixer_System *self); -E_Mixer_Channel *e_mixer_alsa_get_channel_by_name(E_Mixer_System *self, const char *name); -void e_mixer_alsa_channel_del(E_Mixer_Channel *channel); +E_Mixer_Channel_Info *e_mixer_alsa_get_channel_by_name(E_Mixer_System *self, const char *name); int e_mixer_alsa_has_capture(E_Mixer_System *self, E_Mixer_Channel *channel); int e_mixer_alsa_get_volume(E_Mixer_System *self, E_Mixer_Channel *channel, int *left, int *right); @@ -103,8 +101,7 @@ Eina_List *e_mixer_pulse_get_channels(E_Mixer_System *self); Eina_List *e_mixer_pulse_get_channel_names(E_Mixer_System *self); const char *e_mixer_pulse_get_default_channel_name(E_Mixer_System *self); -E_Mixer_Channel *e_mixer_pulse_get_channel_by_name(E_Mixer_System *self, const char *name); -void e_mixer_pulse_channel_del(E_Mixer_Channel *channel); +E_Mixer_Channel_Info *e_mixer_pulse_get_channel_by_name(E_Mixer_System *self, const char *name); int e_mixer_pulse_has_capture(E_Mixer_System *self, E_Mixer_Channel *channel); int e_mixer_pulse_get_volume(E_Mixer_System *self, E_Mixer_Channel *channel, int *left, int *right); diff --git a/src/modules/mixer/sys_alsa.c b/src/modules/mixer/sys_alsa.c index b8003c94b..6fe2611be 100644 --- a/src/modules/mixer/sys_alsa.c +++ b/src/modules/mixer/sys_alsa.c @@ -383,12 +383,13 @@ e_mixer_alsa_get_default_channel_name(E_Mixer_System *self) return NULL; } -E_Mixer_Channel * +E_Mixer_Channel_Info * e_mixer_alsa_get_channel_by_name(E_Mixer_System *self, const char *name) { snd_mixer_elem_t *elem; snd_mixer_selem_id_t *sid; + E_Mixer_Channel_Info *ch_info; if ((!self) || (!name)) return NULL; @@ -406,17 +407,19 @@ e_mixer_alsa_get_channel_by_name(E_Mixer_System *self, snd_mixer_selem_get_id(elem, sid); n = snd_mixer_selem_id_get_name(sid); if (n && (strcmp(n, name) == 0)) - return elem; + { + ch_info = malloc(sizeof(*ch_info)); + ch_info->id = elem; + ch_info->name = eina_stringshare_add(n); + ch_info->has_capture = snd_mixer_selem_has_capture_switch(elem) || snd_mixer_selem_has_capture_volume(elem); + + return ch_info; + } } return NULL; } -void -e_mixer_alsa_channel_del(E_Mixer_Channel *channel __UNUSED__) -{ -} - const char * e_mixer_alsa_get_channel_name(E_Mixer_System *self, E_Mixer_Channel *channel) diff --git a/src/modules/mixer/sys_dummy.c b/src/modules/mixer/sys_dummy.c index 82036ac0c..0c1534501 100644 --- a/src/modules/mixer/sys_dummy.c +++ b/src/modules/mixer/sys_dummy.c @@ -90,22 +90,26 @@ e_mixer_system_get_default_channel_name(E_Mixer_System *self __UNUSED__) return eina_stringshare_ref(_name); } -E_Mixer_Channel * +E_Mixer_Channel_Info * e_mixer_system_get_channel_by_name(E_Mixer_System *self __UNUSED__, const char *name) { + E_Mixer_Channel_Info *ch_info; + _e_mixer_dummy_set(); if (name == _name || strcmp(name, _name) == 0) - return (E_Mixer_Channel *)-2; + { + ch_info = malloc(sizeof(*ch_info)); + ch_info->id = (void*)-2; + ch_info->name = eina_stringshare_ref(_name); + ch_info->has_capture = 0; + + return ch_info; + } else return NULL; } -void -e_mixer_system_channel_del(E_Mixer_Channel *channel __UNUSED__) -{ -} - const char * e_mixer_system_get_channel_name(E_Mixer_System *self __UNUSED__, E_Mixer_Channel *channel) { diff --git a/src/modules/mixer/sys_pulse.c b/src/modules/mixer/sys_pulse.c index f4e99f5f9..295891899 100644 --- a/src/modules/mixer/sys_pulse.c +++ b/src/modules/mixer/sys_pulse.c @@ -504,15 +504,17 @@ e_mixer_pulse_get_default_channel_name(E_Mixer_System *self EINA_UNUSED) return eina_stringshare_ref(_name); } -E_Mixer_Channel * +E_Mixer_Channel_Info * e_mixer_pulse_get_channel_by_name(E_Mixer_System *self EINA_UNUSED, const char *name EINA_UNUSED) { - return (E_Mixer_Channel *)1; -} + E_Mixer_Channel_Info *ch_info; -void -e_mixer_pulse_channel_del(E_Mixer_Channel *channel __UNUSED__) -{ + ch_info = malloc(sizeof(*ch_info)); + ch_info->id = (void*)1; + ch_info->name = eina_stringshare_ref(_name); + ch_info->has_capture = 0; + + return ch_info; } const char *