summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlavio Ceolin <flavio.ceolin@gmail.com>2014-07-13 12:31:18 -0300
committerFlavio Ceolin <flavio.ceolin@gmail.com>2014-08-14 23:33:18 -0300
commitc522e149d8db8191b9054c7c4ee72970a1fbd486 (patch)
tree17a9f745c4c02056ea7076a6c2a521085cda4566 /src
parent12efeaa9da7f4604f716b21b5faf4252b4ce161a (diff)
module: Avoiding volume underflow/overflow
Diffstat (limited to 'src')
-rw-r--r--src/lib/backends/pulseaudio/pulse.c2
-rw-r--r--src/lib/emix.h2
-rw-r--r--src/module/e_mod_main.c22
3 files changed, 21 insertions, 5 deletions
diff --git a/src/lib/backends/pulseaudio/pulse.c b/src/lib/backends/pulseaudio/pulse.c
index 950bfa4..d0c5bd3 100644
--- a/src/lib/backends/pulseaudio/pulse.c
+++ b/src/lib/backends/pulseaudio/pulse.c
@@ -10,7 +10,7 @@
10#define WRN(...) EINA_LOG_WARN(__VA_ARGS__) 10#define WRN(...) EINA_LOG_WARN(__VA_ARGS__)
11 11
12#define PA_VOLUME_TO_INT(_vol) \ 12#define PA_VOLUME_TO_INT(_vol) \
13 ((_vol*100+PA_VOLUME_NORM/2)/PA_VOLUME_NORM) 13 (((_vol+1)*EMIX_VOLUME_MAX+PA_VOLUME_NORM/2)/PA_VOLUME_NORM)
14#define INT_TO_PA_VOLUME(_vol) \ 14#define INT_TO_PA_VOLUME(_vol) \
15 (!_vol) ? 0 : ((PA_VOLUME_NORM*(_vol+1)-PA_VOLUME_NORM/2)/EMIX_VOLUME_MAX) 15 (!_vol) ? 0 : ((PA_VOLUME_NORM*(_vol+1)-PA_VOLUME_NORM/2)/EMIX_VOLUME_MAX)
16 16
diff --git a/src/lib/emix.h b/src/lib/emix.h
index e0a5b0c..86443f8 100644
--- a/src/lib/emix.h
+++ b/src/lib/emix.h
@@ -3,6 +3,8 @@
3 3
4#include <Eina.h> 4#include <Eina.h>
5 5
6#define EMIX_VOLUME_MAX 100
7
6EAPI extern int EMIX_READY_EVENT; 8EAPI extern int EMIX_READY_EVENT;
7EAPI extern int EMIX_DISCONNECTED_EVENT; 9EAPI extern int EMIX_DISCONNECTED_EVENT;
8EAPI extern int EMIX_SINK_ADDED_EVENT; 10EAPI extern int EMIX_SINK_ADDED_EVENT;
diff --git a/src/module/e_mod_main.c b/src/module/e_mod_main.c
index 36c3bc2..db5a8bb 100644
--- a/src/module/e_mod_main.c
+++ b/src/module/e_mod_main.c
@@ -96,7 +96,7 @@ _notify(const int val)
96 return; 96 return;
97 97
98 memset(&n, 0, sizeof(E_Notification_Notify)); 98 memset(&n, 0, sizeof(E_Notification_Notify));
99 if (val > 100 || val < 0) 99 if (val > EMIX_VOLUME_MAX || val < 0)
100 return; 100 return;
101 101
102 ret = snprintf(buf, (sizeof(buf) - 1), "%s: %d%%", _("New volume"), val); 102 ret = snprintf(buf, (sizeof(buf) - 1), "%s: %d%%", _("New volume"), val);
@@ -181,7 +181,14 @@ _volume_increase_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
181 volume.channel_count = s->volume.channel_count; 181 volume.channel_count = s->volume.channel_count;
182 volume.volumes = calloc(s->volume.channel_count, sizeof(int)); 182 volume.volumes = calloc(s->volume.channel_count, sizeof(int));
183 for (i = 0; i < volume.channel_count; i++) 183 for (i = 0; i < volume.channel_count; i++)
184 volume.volumes[i] = s->volume.volumes[i] + VOLUME_STEP; 184 {
185 if (s->volume.volumes[i] < EMIX_VOLUME_MAX - VOLUME_STEP)
186 volume.volumes[i] = s->volume.volumes[i] + VOLUME_STEP;
187 else if (s->volume.volumes[i] < EMIX_VOLUME_MAX)
188 volume.volumes[i] = EMIX_VOLUME_MAX;
189 else
190 volume.volumes[i] = s->volume.volumes[i];
191 }
185 192
186 emix_sink_volume_set(s, volume); 193 emix_sink_volume_set(s, volume);
187 free(volume.volumes); 194 free(volume.volumes);
@@ -198,7 +205,14 @@ _volume_decrease_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
198 volume.channel_count = s->volume.channel_count; 205 volume.channel_count = s->volume.channel_count;
199 volume.volumes = calloc(s->volume.channel_count, sizeof(int)); 206 volume.volumes = calloc(s->volume.channel_count, sizeof(int));
200 for (i = 0; i < volume.channel_count; i++) 207 for (i = 0; i < volume.channel_count; i++)
201 volume.volumes[i] = s->volume.volumes[i] - VOLUME_STEP; 208 {
209 if (s->volume.volumes[i] > VOLUME_STEP)
210 volume.volumes[i] = s->volume.volumes[i] - VOLUME_STEP;
211 else if (s->volume.volumes[i] < VOLUME_STEP)
212 volume.volumes[i] = 0;
213 else
214 volume.volumes[i] = s->volume.volumes[i];
215 }
202 216
203 emix_sink_volume_set(s, volume); 217 emix_sink_volume_set(s, volume);
204 free(volume.volumes); 218 free(volume.volumes);
@@ -367,7 +381,7 @@ _popup_add_slider(Instance *inst)
367 381
368 evas_object_show(slider); 382 evas_object_show(slider);
369 e_slider_orientation_set(slider, 1); 383 e_slider_orientation_set(slider, 1);
370 e_slider_value_range_set(slider, 0.0, 100.0); 384 e_slider_value_range_set(slider, 0.0, (double) EMIX_VOLUME_MAX);
371 e_slider_value_format_display_set(slider, NULL); 385 e_slider_value_format_display_set(slider, NULL);
372 evas_object_smart_callback_add(slider, "changed", _slider_changed_cb, 386 evas_object_smart_callback_add(slider, "changed", _slider_changed_cb,
373 NULL); 387 NULL);