e - mixer - allow to 150% volume with some "stickynedd" from 100 to 120
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>
Sun, 14 Jun 2015 06:01:44 +0000 (15:01 +0900)
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>
Sun, 14 Jun 2015 06:01:44 +0000 (15:01 +0900)
src/modules/mixer/e_mod_main.c
src/modules/mixer/emixer.c
src/modules/mixer/lib/backends/alsa/alsa.c
src/modules/mixer/lib/backends/pulseaudio/pulse.c

index 0eb632f..47df15e 100644 (file)
@@ -89,12 +89,10 @@ _notify(const int val)
    char *icon, buf[56];
    int ret;
 
-   if (!emix_config_notify_get())
-     return;
+   if (!emix_config_notify_get()) return;
 
    memset(&n, 0, sizeof(E_Notification_Notify));
-   if (val > EMIX_VOLUME_MAX || val < 0)
-     return;
+   if (val < 0) return;
 
    ret = snprintf(buf, (sizeof(buf) - 1), "%s: %d%%", _("New volume"), val);
    if ((ret < 0) || ((unsigned int)ret > sizeof(buf)))
@@ -325,8 +323,7 @@ _emixer_exec_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_
    char buf[PATH_MAX];
 
    _popup_del(inst);
-   if (mixer_context->emixer)
-      return;
+   if (mixer_context->emixer) return;
 
    snprintf(buf, sizeof(buf), "%s/%s/emixer %s",
             e_module_dir_get(mixer_context->module),
@@ -355,18 +352,28 @@ static void
 _slider_changed_cb(void *data EINA_UNUSED, Evas_Object *obj,
                    void *event EINA_UNUSED)
 {
-   int val;
+   int val, pval;
    Emix_Volume v;
    unsigned int i;
    Emix_Sink *s = (Emix_Sink *)mixer_context->sink_default;
 
+   pval = s->volume.volumes[0];
    val = (int)elm_slider_value_get(obj);
+   if ((pval > 80) && (pval <= 100) && (val > 100) && (val < 120)) val = 100;
    v.volumes = calloc(s->volume.channel_count, sizeof(int));
    v.channel_count = s->volume.channel_count;
-   for (i = 0; i < s->volume.channel_count; i++)
-     v.volumes[i] = val;
-
+   for (i = 0; i < s->volume.channel_count; i++) v.volumes[i] = val;
    emix_sink_volume_set(s, v);
+   elm_slider_value_set(obj, val);
+}
+
+static void
+_slider_drag_stop_cb(void *data EINA_UNUSED, Evas_Object *obj,
+                     void *event EINA_UNUSED)
+{
+   Emix_Sink *s = (Emix_Sink *)mixer_context->sink_default;
+   int val = s->volume.volumes[0];
+   elm_slider_value_set(obj, val);
 }
 
 static void
@@ -430,8 +437,9 @@ _popup_new(Instance *inst)
    evas_object_size_hint_align_set(slider, EVAS_HINT_FILL, EVAS_HINT_FILL);
    evas_object_size_hint_weight_set(slider, EVAS_HINT_EXPAND, 0.0);
    evas_object_show(slider);
-   elm_slider_min_max_set(slider, 0.0, EMIX_VOLUME_MAX);
+   elm_slider_min_max_set(slider, 0.0, EMIX_VOLUME_MAX + 50);
    evas_object_smart_callback_add(slider, "changed", _slider_changed_cb, NULL);
+   evas_object_smart_callback_add(slider, "slider,drag,stop", _slider_drag_stop_cb, NULL);
    elm_slider_value_set(slider, volume);
    elm_box_pack_end(bx, slider);
    evas_object_show(slider);
index 61cceaa..0d5b62e 100644 (file)
@@ -29,6 +29,9 @@ _backend_init(const char *back)
 #define VOLSET(vol, srcvol, target, func) \
    do { \
       Emix_Volume _v; \
+      int _pvol = srcvol.volumes[0]; \
+      if ((_pvol > 80) && (_pvol <= 100) && \
+          (vol > 100) && (vol < 120)) vol = 100; \
       _v.channel_count = srcvol.channel_count; \
       _v.volumes = calloc(srcvol.channel_count, sizeof(int)); \
       if (_v.volumes) { \
@@ -62,6 +65,18 @@ _cb_sink_volume_change(void *data,
    Emix_Sink *sink = evas_object_data_get(bxv, "sink");
    double vol = elm_slider_value_get(obj);
    VOLSET(vol, sink->volume, sink, emix_sink_volume_set);
+   elm_slider_value_set(obj, vol);
+}
+
+static void
+_cb_sink_volume_drag_stop(void *data,
+                          Evas_Object *obj,
+                          void *event EINA_UNUSED)
+{
+   Evas_Object *bxv = data;
+   Emix_Sink *sink = evas_object_data_get(bxv, "sink");
+   int vol = sink->volume.volumes[0];
+   elm_slider_value_set(obj, vol);
 }
 
 static void
@@ -129,8 +144,8 @@ _emix_sink_add(Emix_Sink *sink)
 
    sl = elm_slider_add(win);
    evas_object_data_set(bxv, "volume", sl);
-   elm_slider_min_max_set(sl, 0.0, 100.0);
-   elm_slider_span_size_set(sl, 100 * elm_config_scale_get());
+   elm_slider_min_max_set(sl, 0.0, EMIX_VOLUME_MAX + 50);
+   elm_slider_span_size_set(sl, (EMIX_VOLUME_MAX + 50) * elm_config_scale_get());
    elm_slider_unit_format_set(sl, "%1.0f");
    elm_slider_indicator_format_set(sl, "%1.0f");
    evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, 0.5);
@@ -139,6 +154,8 @@ _emix_sink_add(Emix_Sink *sink)
    elm_box_pack_end(bx, sl);
    evas_object_show(sl);
    evas_object_smart_callback_add(sl, "changed", _cb_sink_volume_change, bxv);
+   evas_object_smart_callback_add(sl, "slider,drag,stop",
+                                  _cb_sink_volume_drag_stop, bxv);
 
    ck = elm_check_add(win);
    evas_object_data_set(bxv, "mute", ck);
@@ -228,6 +245,18 @@ _cb_sink_input_volume_change(void *data,
    Emix_Sink_Input *input = evas_object_data_get(bxv, "input");
    double vol = elm_slider_value_get(obj);
    VOLSET(vol, input->volume, input, emix_sink_input_volume_set);
+   elm_slider_value_set(obj, vol);
+}
+
+static void
+_cb_sink_input_volume_drag_stop(void *data,
+                                Evas_Object *obj,
+                                void *event EINA_UNUSED)
+{
+   Evas_Object *bxv = data;
+   Emix_Sink_Input *input = evas_object_data_get(bxv, "input");
+   int vol = input->volume.volumes[0];
+   elm_slider_value_set(obj, vol);
 }
 
 static void
@@ -295,8 +324,8 @@ _emix_sink_input_add(Emix_Sink_Input *input)
 
    sl = elm_slider_add(win);
    evas_object_data_set(bxv, "volume", sl);
-   elm_slider_min_max_set(sl, 0.0, 100.0);
-   elm_slider_span_size_set(sl, 100 * elm_config_scale_get());
+   elm_slider_min_max_set(sl, 0.0, EMIX_VOLUME_MAX + 50);
+   elm_slider_span_size_set(sl, (EMIX_VOLUME_MAX + 50) * elm_config_scale_get());
    elm_slider_unit_format_set(sl, "%1.0f");
    elm_slider_indicator_format_set(sl, "%1.0f");
    evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, 0.5);
@@ -306,6 +335,8 @@ _emix_sink_input_add(Emix_Sink_Input *input)
    evas_object_show(sl);
    evas_object_smart_callback_add(sl, "changed",
                                   _cb_sink_input_volume_change, bxv);
+   evas_object_smart_callback_add(sl, "slider,drag,stop",
+                                  _cb_sink_input_volume_drag_stop, bxv);
 
    ck = elm_check_add(win);
    evas_object_data_set(bxv, "mute", ck);
@@ -384,6 +415,18 @@ _cb_source_volume_change(void *data,
    Emix_Source *source = evas_object_data_get(bxv, "source");
    double vol = elm_slider_value_get(obj);
    VOLSET(vol, source->volume, source, emix_source_volume_set);
+   elm_slider_value_set(obj, vol);
+}
+
+static void
+_cb_source_volume_drag_stop(void *data,
+                            Evas_Object *obj,
+                            void *event EINA_UNUSED)
+{
+   Evas_Object *bxv = data;
+   Emix_Source *source = evas_object_data_get(bxv, "source");
+   int vol = source->volume.volumes[0];
+   elm_slider_value_set(obj, vol);
 }
 
 static void
@@ -433,8 +476,8 @@ _emix_source_add(Emix_Source *source)
 
    sl = elm_slider_add(win);
    evas_object_data_set(bxv, "volume", sl);
-   elm_slider_min_max_set(sl, 0.0, 100.0);
-   elm_slider_span_size_set(sl, 100 * elm_config_scale_get());
+   elm_slider_min_max_set(sl, 0.0, EMIX_VOLUME_MAX + 50);
+   elm_slider_span_size_set(sl, (EMIX_VOLUME_MAX + 50) * elm_config_scale_get());
    elm_slider_unit_format_set(sl, "%1.0f");
    elm_slider_indicator_format_set(sl, "%1.0f");
    evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, 0.5);
@@ -444,6 +487,8 @@ _emix_source_add(Emix_Source *source)
    evas_object_show(sl);
    evas_object_smart_callback_add(sl, "changed",
                                   _cb_source_volume_change, bxv);
+   evas_object_smart_callback_add(sl, "slider,drag,stop",
+                                  _cb_source_volume_drag_stop, bxv);
 
    ck = elm_check_add(win);
    evas_object_data_set(bxv, "mute", ck);
index 156522c..941bb71 100644 (file)
@@ -90,7 +90,7 @@ _alsa_channel_volume_get(snd_mixer_elem_t *channel, int *v, Eina_Bool capture)
    else
      snd_mixer_selem_get_playback_volume(channel, 0, &vol);
 
-   *v = (((vol + min) * divide) - ((double) range / 2)) / range + 0.5;
+   *v = ((vol + min) * divide) / range;
 }
 
 static void
@@ -104,7 +104,7 @@ _alsa_channel_volume_set(snd_mixer_elem_t *channel, int v, Eina_Bool capture)
    if (range < 1)
      return;
 
-   vol = (((v * range) + (range / 2)) / divide) - min;
+   vol = ((v * range) / divide) - min;
    if (!capture)
      snd_mixer_selem_set_playback_volume_all(channel, vol);
    else
index ab8e154..f0a04a7 100644 (file)
@@ -9,9 +9,11 @@
 #define WRN(...)      EINA_LOG_WARN(__VA_ARGS__)
 
 #define PA_VOLUME_TO_INT(_vol) \
-   (((_vol+1)*EMIX_VOLUME_MAX+PA_VOLUME_NORM/2)/PA_VOLUME_NORM)
+   ((_vol * EMIX_VOLUME_MAX) / \
+    PA_VOLUME_NORM)
 #define INT_TO_PA_VOLUME(_vol) \
-   (!_vol) ? 0 : ((PA_VOLUME_NORM*(_vol+1)-PA_VOLUME_NORM/2)/EMIX_VOLUME_MAX)
+   ((PA_VOLUME_NORM * _vol) / \
+    EMIX_VOLUME_MAX)
 
 typedef struct _Context
 {
@@ -57,8 +59,7 @@ _emix_volume_convert(const Emix_Volume volume)
 
    vol.channels = volume.channel_count;
    for (i = 0; i < volume.channel_count; i++)
-      vol.values[i] = INT_TO_PA_VOLUME(volume.volumes[i]);
-
+     vol.values[i] = INT_TO_PA_VOLUME(volume.volumes[i]);
    return vol;
 }
 
@@ -79,7 +80,6 @@ _pa_cvolume_convert(const pa_cvolume volume)
    vol.channel_count = volume.channels;
    for (i = 0; i < volume.channels; i++)
      vol.volumes[i] = PA_VOLUME_TO_INT(volume.values[i]);
-
    return vol;
 }