mixer: take advantage of Channel capabilities bitmap
authorJérémy Zurcher <jeremy@asynk.ch>
Thu, 28 Feb 2013 22:09:58 +0000 (23:09 +0100)
committerJérémy Zurcher <jeremy@asynk.ch>
Wed, 6 Mar 2013 15:05:20 +0000 (16:05 +0100)
split channels list into 4 groups:
   Playback, Capture, Switch, Boost
nicely disable volume sliders and mute check when appropriate

src/modules/mixer/app_mixer.c
src/modules/mixer/e_mod_main.c
src/modules/mixer/e_mod_mixer.c

index 3ef1e2d..fdb06b4 100644 (file)
@@ -141,23 +141,19 @@ _update_channel_editor_state(E_Mixer_App_Dialog_Data *app, const E_Mixer_Channel
 {
    struct e_mixer_app_ui_channel_editor *ui = &app->ui.channel_editor;
 
-   e_widget_disabled_set(ui->left, 0);
-   e_widget_disabled_set(ui->right, 0);
-   e_widget_disabled_set(ui->lock_sliders, 0);
-
-   e_widget_slider_value_int_set(ui->left, state.left);
-   e_widget_slider_value_int_set(ui->right, state.right);
-
-   if (e_mod_mixer_mutable_get(app->sys, app->channel_info))
-     {
-        e_widget_disabled_set(ui->mute, 0);
-        e_widget_check_checked_set(ui->mute, state.mute);
-     }
-   else
+   if (!e_mod_mixer_channel_has_no_volume(app->channel_info))
      {
-        e_widget_disabled_set(ui->mute, 1);
-        e_widget_check_checked_set(ui->mute, 0);
+        if (e_mod_mixer_channel_is_mono(app->channel_info))
+          e_widget_slider_value_int_set(ui->left, state.left);
+        else
+          {
+             e_widget_slider_value_int_set(ui->left, state.left);
+             e_widget_slider_value_int_set(ui->right, state.right);
+          }
      }
+
+   if (e_mod_mixer_channel_is_mutable(app->channel_info))
+     e_widget_check_checked_set(ui->mute, state.mute);
 }
 
 static void
@@ -180,15 +176,52 @@ _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))
+   if (e_mod_mixer_channel_is_boost(app->channel_info))
+     e_widget_entry_text_set(ui->type, _("Boost"));
+   else if (e_mod_mixer_channel_has_playback(app->channel_info))
+     e_widget_entry_text_set(ui->type, _("Playback"));
+   else if (e_mod_mixer_channel_has_capture(app->channel_info))
      e_widget_entry_text_set(ui->type, _("Capture"));
    else
-     e_widget_entry_text_set(ui->type, _("Playback"));
+      e_widget_entry_text_set(ui->type, _("Switch"));
 
    e_mod_mixer_state_get(app->sys, app->channel_info, &state);
    _update_channel_editor_state(app, state);
 
-   app->lock_sliders = (state.left == state.right);
+   if (e_mod_mixer_channel_is_mutable(app->channel_info))
+     {
+        e_widget_disabled_set(ui->mute, 0);
+     }
+   else
+     {
+        e_widget_disabled_set(ui->mute, 1);
+        e_widget_check_checked_set(ui->mute, 0);
+     }
+
+   if (e_mod_mixer_channel_has_no_volume(app->channel_info))
+     {
+        app->lock_sliders = 1;
+        e_widget_slider_value_int_set(ui->left, 0);
+        e_widget_slider_value_int_set(ui->right, 0);
+        e_widget_disabled_set(ui->lock_sliders, 1);
+        e_widget_disabled_set(ui->left, 1);
+        e_widget_disabled_set(ui->right, 1);
+     }
+   else if (e_mod_mixer_channel_is_mono(app->channel_info))
+     {
+        app->lock_sliders = 0;
+        e_widget_slider_value_int_set(ui->right, 0);
+        e_widget_disabled_set(ui->lock_sliders, 1);
+        e_widget_disabled_set(ui->left, 0);
+        e_widget_disabled_set(ui->right, 1);
+     }
+   else
+     {
+        app->lock_sliders = (state.left == state.right);
+        e_widget_disabled_set(ui->lock_sliders, 0);
+        e_widget_disabled_set(ui->left, 0);
+        e_widget_disabled_set(ui->right, 0);
+     }
    e_widget_check_checked_set(ui->lock_sliders, app->lock_sliders);
 }
 
@@ -244,31 +277,23 @@ _populate_channels(E_Mixer_App_Dialog_Data *app)
      e_mod_mixer_channel_infos_free(app->channel_infos);
    app->channel_infos = e_mod_mixer_channel_infos_get(app->sys);
 
-   if (app->channel_infos)
-     {
-        E_Mixer_Channel_Info *info = app->channel_infos->data;
-        if (e_mod_mixer_channel_has_capture(info))
-          {
-             e_widget_ilist_header_append(ilist, NULL, _("Input"));
-             header_input = 1;
-             i = 1;
-          }
-        else
-          {
-             e_widget_ilist_header_append(ilist, NULL, _("Output"));
-             header_input = 0;
-             i = 1;
-          }
-     }
-
+   i = 0;
+   header_input = 0;
    for (l = app->channel_infos; l; l = l->next, i++)
      {
         E_Mixer_Channel_Info *info = l->data;
 
-        if ((!header_input) && e_mod_mixer_channel_has_capture(info))
+        if (header_input != e_mod_mixer_channel_group_get(info))
           {
-             e_widget_ilist_header_append(ilist, NULL, _("Input"));
-             header_input = 1;
+             if (e_mod_mixer_channel_is_boost(info))
+               e_widget_ilist_header_append(ilist, NULL, _("Boost"));
+             else if (e_mod_mixer_channel_has_playback(info))
+               e_widget_ilist_header_append(ilist, NULL, _("Playback"));
+             else if (e_mod_mixer_channel_has_capture(info))
+               e_widget_ilist_header_append(ilist, NULL, _("Capture"));
+             else
+               e_widget_ilist_header_append(ilist, NULL, _("Switch"));
+             header_input = e_mod_mixer_channel_group_get(info);
              i++;
           }
 
@@ -529,19 +554,12 @@ _find_channel_by_name(E_Mixer_App_Dialog_Data *app, const char *channel_name)
    if (!channel_name)
      return 0;
 
-   if (app->channel_infos)
-     {
-        info = app->channel_infos->data;
-
-        header_input = !!e_mod_mixer_channel_has_capture(info);
-        i = 1;
-     }
-
+   header_input = 0;
    EINA_LIST_FOREACH(app->channel_infos, l, info)
      {
-        if ((!header_input) && e_mod_mixer_channel_has_capture(info))
+        if (header_input != e_mod_mixer_channel_group_get(info))
           {
-             header_input = 1;
+             header_input = e_mod_mixer_channel_group_get(info);
              i++;
           }
 
index 99991fa..7640740 100644 (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))
+   if (!e_mod_mixer_channel_is_mutable(inst->channel))
      return;
 
    state = &inst->mixer_state;
@@ -588,11 +588,12 @@ _mixer_popup_new(E_Mixer_Instance *inst)
    state = &inst->mixer_state;
    e_mod_mixer_state_get(inst->sys, inst->channel, state);
 
-   if ((state->right >= 0) &&
-       (inst->conf->show_locked || (!inst->conf->lock_sliders)))
-     colspan = 2;
-   else
+   if (e_mod_mixer_channel_has_no_volume(inst->channel) ||
+       e_mod_mixer_channel_is_mono(inst->channel) ||
+       (inst->conf->lock_sliders && !inst->conf->show_locked))
      colspan = 1;
+   else
+     colspan = 2;
 
    inst->popup = e_gadcon_popup_new(inst->gcc);
    evas = inst->popup->win->evas;
@@ -603,28 +604,38 @@ _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 (colspan==2)
      {
-        inst->ui.left = _mixer_popup_add_slider(
-            inst, state->left, _mixer_popup_cb_volume_left_change);
+        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);
+        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;
+     {
+        if (e_mod_mixer_channel_has_no_volume(inst->channel))
+          {
+             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);
+          }
+        else
+          {
+             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);
+          }
+        inst->ui.right = NULL;
+     }
 
-   if (e_mod_mixer_mutable_get(inst->sys, inst->channel))
+   if (e_mod_mixer_channel_is_mutable(inst->channel))
      {
         inst->ui.mute = e_widget_check_add(evas, _("Mute"), &state->mute);
         evas_object_show(inst->ui.mute);
index b76d716..0d320df 100644 (file)
@@ -70,12 +70,15 @@ _channel_info_cmp(const void *data_a, const void *data_b)
 {
    const E_Mixer_Channel_Info *a = data_a, *b = data_b;
 
-   if (e_mod_mixer_channel_has_capture(a) < e_mod_mixer_channel_has_capture(b))
+   if (e_mod_mixer_channel_group_get(a) == e_mod_mixer_channel_group_get(b))
+     return strcmp(a->name, b->name);
+   if (e_mod_mixer_channel_is_boost(a))
+     return 1;
+   if (e_mod_mixer_channel_is_boost(b))
      return -1;
-   else if (e_mod_mixer_channel_has_capture(a) > e_mod_mixer_channel_has_capture(b))
+   if (e_mod_mixer_channel_group_get(a) < e_mod_mixer_channel_group_get(b))
      return 1;
-
-   return strcmp(a->name, b->name);
+   return -1;
 }
 
 void e_mod_mixer_channel_info_free(E_Mixer_Channel_Info* info)