e_mixer: replace has_capture with capabilities bit map

xx_can_mute and xx_has_capture fuctions can disapear
 !?! e_slider_disabled_set does not work !?!

SVN revision: 83914
This commit is contained in:
Jérémy Zurcher 2013-02-14 20:28:20 +00:00
parent 4085613b1d
commit d80eb52a35
7 changed files with 147 additions and 108 deletions

View File

@ -140,15 +140,26 @@ static void
_update_channel_editor_state(E_Mixer_App_Dialog_Data *app, const E_Mixer_Channel_State state)
{
struct e_mixer_app_ui_channel_editor *ui = &app->ui.channel_editor;
int disabled;
e_widget_disabled_set(ui->left, 0);
e_widget_disabled_set(ui->right, 0);
e_widget_disabled_set(ui->lock_sliders, 0);
if (e_mod_mixer_channel_has_no_volume(app->channel_info))
{
disabled = 1;
e_widget_slider_value_int_set(ui->right, 0);
e_widget_slider_value_int_set(ui->right, 0);
}
else
{
disabled = 0;
e_widget_slider_value_int_set(ui->left, state.left);
e_widget_slider_value_int_set(ui->right, state.right);
}
e_widget_slider_value_int_set(ui->left, state.left);
e_widget_slider_value_int_set(ui->right, state.right);
e_widget_disabled_set(ui->left, disabled);
e_widget_disabled_set(ui->right, disabled);
e_widget_disabled_set(ui->lock_sliders, disabled);
if (e_mod_mixer_mutable_get(app->sys, app->channel_info->id))
if (e_mod_mixer_channel_mutable(app->channel_info))
{
e_widget_disabled_set(ui->mute, 0);
e_widget_check_checked_set(ui->mute, state.mute);
@ -180,7 +191,7 @@ _populate_channel_editor(E_Mixer_App_Dialog_Data *app)
e_widget_entry_text_set(ui->channel, app->channel_name);
if (e_mod_mixer_capture_get(app->sys, app->channel_info->id))
if (e_mod_mixer_channel_has_capture(app->channel_info->id))
e_widget_entry_text_set(ui->type, _("Capture"));
else
e_widget_entry_text_set(ui->type, _("Playback"));
@ -247,7 +258,7 @@ _populate_channels(E_Mixer_App_Dialog_Data *app)
if (app->channel_infos)
{
E_Mixer_Channel_Info *info = app->channel_infos->data;
if (info->has_capture)
if (e_mod_mixer_channel_has_capture(info))
{
e_widget_ilist_header_append(ilist, NULL, _("Input"));
header_input = 1;
@ -265,7 +276,7 @@ _populate_channels(E_Mixer_App_Dialog_Data *app)
{
E_Mixer_Channel_Info *info = l->data;
if ((!header_input) && info->has_capture)
if ((!header_input) && e_mod_mixer_channel_has_capture(info))
{
e_widget_ilist_header_append(ilist, NULL, _("Input"));
header_input = 1;
@ -533,13 +544,13 @@ _find_channel_by_name(E_Mixer_App_Dialog_Data *app, const char *channel_name)
{
info = app->channel_infos->data;
header_input = !!info->has_capture;
header_input = !!e_mod_mixer_channel_has_capture(info);
i = 1;
}
EINA_LIST_FOREACH(app->channel_infos, l, info)
{
if ((!header_input) && info->has_capture)
if ((!header_input) && e_mod_mixer_channel_has_capture(info))
{
header_input = 1;
i++;

View File

@ -366,7 +366,7 @@ _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_info->id))
if (!e_mod_mixer_channel_mutable(inst->channel_info))
return;
state = &inst->mixer_state;
@ -659,28 +659,39 @@ _mixer_popup_new(E_Mixer_Instance *inst)
e_widget_table_object_append(inst->ui.table, inst->ui.label,
0, 0, colspan, 1, 0, 0, 0, 0);
if (state->left >= 0)
if (!e_mod_mixer_channel_has_no_volume(inst->channel_info))
{
inst->ui.left = _mixer_popup_add_slider(
inst, state->left, _mixer_popup_cb_volume_left_change);
e_widget_table_object_append(inst->ui.table, inst->ui.left,
0, 1, 1, 1, 1, 1, 1, 1);
if (state->left >= 0)
{
inst->ui.left = _mixer_popup_add_slider(
inst, state->left, _mixer_popup_cb_volume_left_change);
e_widget_table_object_append(inst->ui.table, inst->ui.left,
0, 1, 1, 1, 1, 1, 1, 1);
}
else
inst->ui.left = NULL;
if ((state->right >= 0) &&
(inst->conf->show_locked || (!inst->conf->lock_sliders)))
{
inst->ui.right = _mixer_popup_add_slider(
inst, state->right, _mixer_popup_cb_volume_right_change);
e_widget_table_object_append(inst->ui.table, inst->ui.right,
1, 1, 1, 1, 1, 1, 1, 1);
}
else
inst->ui.right = NULL;
}
else
inst->ui.left = NULL;
if ((state->right >= 0) &&
(inst->conf->show_locked || (!inst->conf->lock_sliders)))
{
inst->ui.right = _mixer_popup_add_slider(
inst, state->right, _mixer_popup_cb_volume_right_change);
e_widget_table_object_append(inst->ui.table, inst->ui.right,
1, 1, 1, 1, 1, 1, 1, 1);
inst->ui.left = _mixer_popup_add_slider(inst, 0, NULL);
e_widget_table_object_append(inst->ui.table, inst->ui.left,
0, 1, 1, 1, 1, 1, 1, 1);
e_slider_disabled_set(inst->ui.left, 1);
inst->ui.right = NULL;
}
else
inst->ui.right = NULL;
if (e_mod_mixer_mutable_get(inst->sys, inst->channel_info->id))
if (e_mod_mixer_channel_mutable(inst->channel_info))
{
inst->ui.mute = e_widget_check_add(evas, _("Mute"), &state->mute);
evas_object_show(inst->ui.mute);
@ -991,8 +1002,10 @@ e_sys_pulse_ready_cb(Eina_Bool ready)
inst->sys = NULL;
return;
}
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 (_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->channel_info)
{
if ((inst->mixer_state.left > -1) && (inst->mixer_state.right > -1) && (inst->mixer_state.mute > -1))

View File

@ -5,9 +5,7 @@ E_Mixer_Volume_Get_Cb e_mod_mixer_volume_get;
E_Mixer_Volume_Set_Cb e_mod_mixer_volume_set;
E_Mixer_Mute_Get_Cb e_mod_mixer_mute_get;
E_Mixer_Mute_Set_Cb e_mod_mixer_mute_set;
E_Mixer_Capture_Cb e_mod_mixer_mutable_get;
E_Mixer_State_Get_Cb e_mod_mixer_state_get;
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;
@ -26,9 +24,7 @@ e_mixer_default_setup(void)
e_mod_mixer_volume_set = (void *)e_mixer_alsa_set_volume;
e_mod_mixer_mute_get = (void *)e_mixer_alsa_get_mute;
e_mod_mixer_mute_set = (void *)e_mixer_alsa_set_mute;
e_mod_mixer_mutable_get = (void *)e_mixer_alsa_can_mute;
e_mod_mixer_state_get = (void *)e_mixer_alsa_get_state;
e_mod_mixer_capture_get = (void *)e_mixer_alsa_has_capture;
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;
@ -49,9 +45,7 @@ e_mixer_pulse_setup()
e_mod_mixer_volume_set = (void *)e_mixer_pulse_set_volume;
e_mod_mixer_mute_get = (void *)e_mixer_pulse_get_mute;
e_mod_mixer_mute_set = (void *)e_mixer_pulse_set_mute;
e_mod_mixer_mutable_get = (void *)e_mixer_pulse_can_mute;
e_mod_mixer_state_get = (void *)e_mixer_pulse_get_state;
e_mod_mixer_capture_get = (void *)e_mixer_pulse_has_capture;
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;
@ -65,14 +59,41 @@ e_mixer_pulse_setup()
_mixer_using_default = EINA_FALSE;
}
int e_mod_mixer_channel_mutable(const E_Mixer_Channel_Info *channel)
{
return ((channel->capabilities & E_MIXER_CHANNEL_CAN_MUTE )!=0);
}
int e_mod_mixer_channel_has_capture(const E_Mixer_Channel_Info *channel)
{
return ((channel->capabilities & E_MIXER_CHANNEL_HAS_CAPTURE )!=0);
}
int e_mod_mixer_channel_has_playback(const E_Mixer_Channel_Info *channel)
{
return ((channel->capabilities & E_MIXER_CHANNEL_HAS_PLAYBACK )!=0);
}
int e_mod_mixer_channel_is_boost(const E_Mixer_Channel_Info *channel)
{
return ((channel->capabilities & E_MIXER_CHANNEL_HAS_PLAYBACK )!=0 &&
(channel->capabilities & E_MIXER_CHANNEL_HAS_CAPTURE )!=0);
}
int e_mod_mixer_channel_has_no_volume(const E_Mixer_Channel_Info *channel)
{
return ((channel->capabilities & E_MIXER_CHANNEL_HAS_PLAYBACK )==0 &&
(channel->capabilities & E_MIXER_CHANNEL_HAS_CAPTURE )==0);
}
static int
_channel_info_cmp(const void *data_a, const void *data_b)
{
const E_Mixer_Channel_Info *a = data_a, *b = data_b;
if (a->has_capture < b->has_capture)
if (e_mod_mixer_channel_has_capture(a) < e_mod_mixer_channel_has_capture(b))
return -1;
else if (a->has_capture > b->has_capture)
else if (e_mod_mixer_channel_has_capture(a) > e_mod_mixer_channel_has_capture(b))
return 1;
return strcmp(a->name, b->name);

View File

@ -14,9 +14,14 @@ typedef struct _E_Mixer_Channel_State
int right;
} E_Mixer_Channel_State;
#define E_MIXER_CHANNEL_CAN_MUTE 0x01
#define E_MIXER_CHANNEL_HAS_CAPTURE 0x02
#define E_MIXER_CHANNEL_HAS_PLAYBACK 0x04
#define E_MIXER_CHANNEL_MASK 0xFE
typedef struct _E_Mixer_Channel_Info
{
int has_capture;
int capabilities;
const char *name;
E_Mixer_Channel *id;
E_Mixer_App *app;
@ -36,9 +41,7 @@ extern E_Mixer_Volume_Get_Cb e_mod_mixer_volume_get;
extern E_Mixer_Volume_Set_Cb e_mod_mixer_volume_set;
extern E_Mixer_Mute_Get_Cb e_mod_mixer_mute_get;
extern E_Mixer_Mute_Set_Cb e_mod_mixer_mute_set;
extern E_Mixer_Capture_Cb e_mod_mixer_mutable_get;
extern E_Mixer_State_Get_Cb e_mod_mixer_state_get;
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;
@ -55,6 +58,12 @@ void e_mod_mixer_channel_infos_free(Eina_List*);
void e_mod_mixer_channel_names_free(Eina_List*);
void e_mod_mixer_card_names_free(Eina_List*);
int e_mod_mixer_channel_mutable(const E_Mixer_Channel_Info *channel);
int e_mod_mixer_channel_has_capture(const E_Mixer_Channel_Info *channel);
int e_mod_mixer_channel_has_playback(const E_Mixer_Channel_Info *channel);
int e_mod_mixer_channel_is_boost(const E_Mixer_Channel_Info *channel);
int e_mod_mixer_channel_has_no_volume(const E_Mixer_Channel_Info *channel);
void e_mixer_default_setup(void);
void e_mixer_pulse_setup();
@ -75,10 +84,8 @@ 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_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);
int e_mixer_alsa_set_volume(E_Mixer_System *self, E_Mixer_Channel *channel, int left, int right);
int e_mixer_alsa_can_mute(E_Mixer_System *self, E_Mixer_Channel *channel);
int e_mixer_alsa_get_mute(E_Mixer_System *self, E_Mixer_Channel *channel, int *mute);
int e_mixer_alsa_set_mute(E_Mixer_System *self, E_Mixer_Channel *channel, int mute);
int e_mixer_alsa_get_state(E_Mixer_System *self, E_Mixer_Channel *channel, E_Mixer_Channel_State *state);
@ -103,10 +110,8 @@ 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_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);
int e_mixer_pulse_set_volume(E_Mixer_System *self, E_Mixer_Channel *channel, int left, int right);
int e_mixer_pulse_can_mute(E_Mixer_System *self, E_Mixer_Channel *channel);
int e_mixer_pulse_get_mute(E_Mixer_System *self, E_Mixer_Channel *channel, int *mute);
int e_mixer_pulse_set_mute(E_Mixer_System *self, E_Mixer_Channel *channel, int mute);
int e_mixer_pulse_get_state(E_Mixer_System *self, E_Mixer_Channel *channel, E_Mixer_Channel_State *state);

View File

@ -294,11 +294,48 @@ e_mixer_alsa_get_card_name(const char *card)
return eina_stringshare_add(name);
}
static int
_mixer_channel_has_capabilities(snd_mixer_elem_t *elem)
{
if (!snd_mixer_selem_is_active(elem)) return 0;
if (snd_mixer_selem_has_playback_volume(elem)) return 1;
if (snd_mixer_selem_has_capture_volume(elem)) return 1;
if (snd_mixer_selem_has_playback_switch(elem)) return 1;
if (snd_mixer_selem_has_capture_switch(elem)) return 1;
if (snd_mixer_selem_has_playback_switch_joined(elem)) return 1;
if (snd_mixer_selem_has_capture_switch_joined(elem)) return 1;
return 0;
}
static int
_mixer_channel_capabilities(snd_mixer_elem_t *elem)
{
int capabilities = 0;
if (!snd_mixer_selem_is_active(elem))
return 0;
if (snd_mixer_selem_has_capture_volume(elem))
capabilities |= E_MIXER_CHANNEL_HAS_CAPTURE;
if (snd_mixer_selem_has_playback_volume(elem))
capabilities |= E_MIXER_CHANNEL_HAS_PLAYBACK;
if (snd_mixer_selem_has_playback_switch(elem) ||
snd_mixer_selem_has_capture_switch(elem) ||
snd_mixer_selem_has_playback_switch_joined(elem) ||
snd_mixer_selem_has_capture_switch_joined(elem))
capabilities |= E_MIXER_CHANNEL_CAN_MUTE;
return capabilities;
}
Eina_List *
e_mixer_alsa_get_channels(E_Mixer_System *self)
{
int capabilities;
Eina_List *channels;
snd_mixer_elem_t *elem;
E_Mixer_Channel_Info *ch_info;
if (!self)
return NULL;
@ -308,16 +345,14 @@ e_mixer_alsa_get_channels(E_Mixer_System *self)
elem = snd_mixer_first_elem(self);
for (; elem; elem = snd_mixer_elem_next(elem))
{
if ((!snd_mixer_selem_is_active(elem)) ||
(!snd_mixer_selem_has_playback_volume(elem)))
capabilities = _mixer_channel_capabilities(elem);
if (capabilities == 0)
continue;
E_Mixer_Channel_Info *ch_info;
ch_info = malloc(sizeof(*ch_info));
ch_info->id = elem;
ch_info->name = eina_stringshare_add(snd_mixer_selem_get_name(elem));
ch_info->has_capture = snd_mixer_selem_has_capture_switch(elem) || snd_mixer_selem_has_capture_volume(elem);
ch_info->capabilities = capabilities;
channels = eina_list_append(channels, ch_info);
}
@ -342,8 +377,7 @@ e_mixer_alsa_get_channel_names(E_Mixer_System *self)
for (; elem; elem = snd_mixer_elem_next(elem))
{
const char *name;
if ((!snd_mixer_selem_is_active(elem)) ||
(!snd_mixer_selem_has_playback_volume(elem)))
if (!_mixer_channel_has_capabilities(elem))
continue;
snd_mixer_selem_get_id(elem, sid);
@ -370,8 +404,7 @@ e_mixer_alsa_get_default_channel_name(E_Mixer_System *self)
for (; elem; elem = snd_mixer_elem_next(elem))
{
const char *name;
if ((!snd_mixer_selem_is_active(elem)) ||
(!snd_mixer_selem_has_playback_volume(elem)))
if (!_mixer_channel_has_capabilities(elem))
continue;
snd_mixer_selem_get_id(elem, sid);
@ -387,6 +420,7 @@ E_Mixer_Channel_Info *
e_mixer_alsa_get_channel_by_name(E_Mixer_System *self,
const char *name)
{
int capabilities;
snd_mixer_elem_t *elem;
snd_mixer_selem_id_t *sid;
E_Mixer_Channel_Info *ch_info;
@ -400,8 +434,8 @@ e_mixer_alsa_get_channel_by_name(E_Mixer_System *self,
for (; elem; elem = snd_mixer_elem_next(elem))
{
const char *n;
if ((!snd_mixer_selem_is_active(elem)) ||
(!snd_mixer_selem_has_playback_volume(elem)))
capabilities = _mixer_channel_capabilities(elem);
if (capabilities == 0)
continue;
snd_mixer_selem_get_id(elem, sid);
@ -411,7 +445,7 @@ e_mixer_alsa_get_channel_by_name(E_Mixer_System *self,
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);
ch_info->capabilities = capabilities;
return ch_info;
}
@ -526,18 +560,6 @@ e_mixer_alsa_set_volume(E_Mixer_System *self,
return 1;
}
int
e_mixer_alsa_can_mute(E_Mixer_System *self,
E_Mixer_Channel *channel)
{
if ((!self) || (!channel))
return 0;
snd_mixer_handle_events(self);
return snd_mixer_selem_has_playback_switch(channel) ||
snd_mixer_selem_has_playback_switch_joined(channel);
}
int
e_mixer_alsa_get_mute(E_Mixer_System *self,
E_Mixer_Channel *channel,
@ -610,13 +632,3 @@ e_mixer_alsa_set_state(E_Mixer_System *self,
return r;
}
int
e_mixer_alsa_has_capture(E_Mixer_System *self,
E_Mixer_Channel *channel)
{
if ((!self) || (!channel))
return 0;
return snd_mixer_selem_has_capture_switch(channel) || snd_mixer_selem_has_capture_volume(channel);
}

View File

@ -62,14 +62,14 @@ e_mixer_system_get_card_name(const char *card)
Eina_List *
e_mixer_system_get_channels(E_Mixer_System *self __UNUSED__)
{
_e_mixer_dummy_set();
E_Mixer_Channel_Info *ch_info;
_e_mixer_dummy_set();
ch_info = malloc(sizeof(*ch_info));
ch_info->id = (void*)-2;
ch_info->name = eina_stringshare_ref(_name);
ch_info->has_capture = 0;
ch_info->capabilities = E_MIXER_CHANNEL_CAN_MUTE|E_MIXER_CHANNEL_HAS_PLAYBACK;
return eina_list_append(NULL, ch_info);
}
@ -102,7 +102,7 @@ e_mixer_system_get_channel_by_name(E_Mixer_System *self __UNUSED__, const char *
ch_info = malloc(sizeof(*ch_info));
ch_info->id = (void*)-2;
ch_info->name = eina_stringshare_ref(_name);
ch_info->has_capture = 0;
ch_info->capabilities = E_MIXER_CHANNEL_CAN_MUTE|E_MIXER_CHANNEL_HAS_PLAYBACK;
return ch_info;
}
@ -138,12 +138,6 @@ e_mixer_system_set_volume(E_Mixer_System *self __UNUSED__, E_Mixer_Channel *chan
return 0;
}
int
e_mixer_system_can_mute(E_Mixer_System *self __UNUSED__, E_Mixer_Channel *channel __UNUSED__)
{
return 1;
}
int
e_mixer_system_get_mute(E_Mixer_System *self __UNUSED__, E_Mixer_Channel *channel __UNUSED__, int *mute)
{
@ -176,9 +170,3 @@ e_mixer_system_set_state(E_Mixer_System *self __UNUSED__, E_Mixer_Channel *chann
return 0;
}
int
e_mixer_system_has_capture(E_Mixer_System *self __UNUSED__, E_Mixer_Channel *channel __UNUSED__)
{
return 0;
}

View File

@ -487,7 +487,7 @@ e_mixer_pulse_get_channels(E_Mixer_System *self EINA_UNUSED)
ch_info = malloc(sizeof(*ch_info));
ch_info->id = (void*)1;
ch_info->name = eina_stringshare_ref(_name);
ch_info->has_capture = 0;
ch_info->capabilities= E_MIXER_CHANNEL_CAN_MUTE|E_MIXER_CHANNEL_HAS_PLAYBACK;
return eina_list_append(NULL, ch_info);
}
@ -512,7 +512,7 @@ e_mixer_pulse_get_channel_by_name(E_Mixer_System *self EINA_UNUSED, const char *
ch_info = malloc(sizeof(*ch_info));
ch_info->id = (void*)1;
ch_info->name = eina_stringshare_ref(_name);
ch_info->has_capture = 0;
ch_info->capabilities= E_MIXER_CHANNEL_CAN_MUTE|E_MIXER_CHANNEL_HAS_PLAYBACK;
return ch_info;
}
@ -585,12 +585,6 @@ e_mixer_pulse_set_volume(E_Mixer_System *self, E_Mixer_Channel *channel, int lef
return 1;
}
int
e_mixer_pulse_can_mute(E_Mixer_System *self __UNUSED__, E_Mixer_Channel *channel __UNUSED__)
{
return 1;
}
int
e_mixer_pulse_get_mute(E_Mixer_System *self, E_Mixer_Channel *channel __UNUSED__, int *mute)
{
@ -635,8 +629,3 @@ e_mixer_pulse_set_state(E_Mixer_System *self, E_Mixer_Channel *channel, const E_
return 1;
}
int
e_mixer_pulse_has_capture(E_Mixer_System *self __UNUSED__, E_Mixer_Channel *channel __UNUSED__)
{
return 0;
}