summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hollerbach <marcel-hollerbach@t-online.de>2016-09-07 11:02:46 +0200
committerMarcel Hollerbach <marcel-hollerbach@t-online.de>2016-09-07 11:05:11 +0200
commit1a3086b2c20c79a63f266ebf8dfddc05e9bc193e (patch)
treec0cb7a05570b39ef9139207c4574d1907b65a0cf
parent1da2bbcd9c8504925b4b585753d4d7061ba073c6 (diff)
mixer: introduce emix_max_volume_get
This lets the module decide what its maximum value is. Everything over 100% is considered overloading. And is protected by the mixer and the gadget.
-rw-r--r--src/modules/mixer/e_mod_main.c8
-rw-r--r--src/modules/mixer/emixer.c12
-rw-r--r--src/modules/mixer/lib/backends/alsa/alsa.c13
-rw-r--r--src/modules/mixer/lib/backends/pulseaudio/pulse.c13
-rw-r--r--src/modules/mixer/lib/emix.c9
-rw-r--r--src/modules/mixer/lib/emix.h7
6 files changed, 45 insertions, 17 deletions
diff --git a/src/modules/mixer/e_mod_main.c b/src/modules/mixer/e_mod_main.c
index bff3be4b8..db7a1d76f 100644
--- a/src/modules/mixer/e_mod_main.c
+++ b/src/modules/mixer/e_mod_main.c
@@ -189,10 +189,10 @@ _volume_increase_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
189 volume.volumes = calloc(s->volume.channel_count, sizeof(int)); 189 volume.volumes = calloc(s->volume.channel_count, sizeof(int));
190 for (i = 0; i < volume.channel_count; i++) 190 for (i = 0; i < volume.channel_count; i++)
191 { 191 {
192 if (s->volume.volumes[i] < (EMIX_VOLUME_MAX + 50) - VOLUME_STEP) 192 if (s->volume.volumes[i] < (emix_max_volume_get()) - VOLUME_STEP)
193 volume.volumes[i] = s->volume.volumes[i] + VOLUME_STEP; 193 volume.volumes[i] = s->volume.volumes[i] + VOLUME_STEP;
194 else if (s->volume.volumes[i] < EMIX_VOLUME_MAX + 50) 194 else if (s->volume.volumes[i] < emix_max_volume_get())
195 volume.volumes[i] = EMIX_VOLUME_MAX + 50; 195 volume.volumes[i] = emix_max_volume_get();
196 else 196 else
197 volume.volumes[i] = s->volume.volumes[i]; 197 volume.volumes[i] = s->volume.volumes[i];
198 } 198 }
@@ -463,7 +463,7 @@ _popup_new(Instance *inst)
463 evas_object_size_hint_align_set(slider, EVAS_HINT_FILL, EVAS_HINT_FILL); 463 evas_object_size_hint_align_set(slider, EVAS_HINT_FILL, EVAS_HINT_FILL);
464 evas_object_size_hint_weight_set(slider, EVAS_HINT_EXPAND, 0.0); 464 evas_object_size_hint_weight_set(slider, EVAS_HINT_EXPAND, 0.0);
465 evas_object_show(slider); 465 evas_object_show(slider);
466 elm_slider_min_max_set(slider, 0.0, EMIX_VOLUME_MAX + 50); 466 elm_slider_min_max_set(slider, 0.0, emix_max_volume_get());
467 evas_object_smart_callback_add(slider, "changed", _slider_changed_cb, NULL); 467 evas_object_smart_callback_add(slider, "changed", _slider_changed_cb, NULL);
468 evas_object_smart_callback_add(slider, "slider,drag,stop", _slider_drag_stop_cb, NULL); 468 evas_object_smart_callback_add(slider, "slider,drag,stop", _slider_drag_stop_cb, NULL);
469 elm_slider_value_set(slider, volume); 469 elm_slider_value_set(slider, volume);
diff --git a/src/modules/mixer/emixer.c b/src/modules/mixer/emixer.c
index 0d5b62e48..61ae83021 100644
--- a/src/modules/mixer/emixer.c
+++ b/src/modules/mixer/emixer.c
@@ -144,8 +144,8 @@ _emix_sink_add(Emix_Sink *sink)
144 144
145 sl = elm_slider_add(win); 145 sl = elm_slider_add(win);
146 evas_object_data_set(bxv, "volume", sl); 146 evas_object_data_set(bxv, "volume", sl);
147 elm_slider_min_max_set(sl, 0.0, EMIX_VOLUME_MAX + 50); 147 elm_slider_min_max_set(sl, 0.0, emix_max_volume_get());
148 elm_slider_span_size_set(sl, (EMIX_VOLUME_MAX + 50) * elm_config_scale_get()); 148 elm_slider_span_size_set(sl, emix_max_volume_get() * elm_config_scale_get());
149 elm_slider_unit_format_set(sl, "%1.0f"); 149 elm_slider_unit_format_set(sl, "%1.0f");
150 elm_slider_indicator_format_set(sl, "%1.0f"); 150 elm_slider_indicator_format_set(sl, "%1.0f");
151 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, 0.5); 151 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, 0.5);
@@ -324,8 +324,8 @@ _emix_sink_input_add(Emix_Sink_Input *input)
324 324
325 sl = elm_slider_add(win); 325 sl = elm_slider_add(win);
326 evas_object_data_set(bxv, "volume", sl); 326 evas_object_data_set(bxv, "volume", sl);
327 elm_slider_min_max_set(sl, 0.0, EMIX_VOLUME_MAX + 50); 327 elm_slider_min_max_set(sl, 0.0, emix_max_volume_get());
328 elm_slider_span_size_set(sl, (EMIX_VOLUME_MAX + 50) * elm_config_scale_get()); 328 elm_slider_span_size_set(sl, (emix_max_volume_get()) * elm_config_scale_get());
329 elm_slider_unit_format_set(sl, "%1.0f"); 329 elm_slider_unit_format_set(sl, "%1.0f");
330 elm_slider_indicator_format_set(sl, "%1.0f"); 330 elm_slider_indicator_format_set(sl, "%1.0f");
331 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, 0.5); 331 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, 0.5);
@@ -476,8 +476,8 @@ _emix_source_add(Emix_Source *source)
476 476
477 sl = elm_slider_add(win); 477 sl = elm_slider_add(win);
478 evas_object_data_set(bxv, "volume", sl); 478 evas_object_data_set(bxv, "volume", sl);
479 elm_slider_min_max_set(sl, 0.0, EMIX_VOLUME_MAX + 50); 479 elm_slider_min_max_set(sl, 0.0, emix_max_volume_get());
480 elm_slider_span_size_set(sl, (EMIX_VOLUME_MAX + 50) * elm_config_scale_get()); 480 elm_slider_span_size_set(sl, (emix_max_volume_get()) * elm_config_scale_get());
481 elm_slider_unit_format_set(sl, "%1.0f"); 481 elm_slider_unit_format_set(sl, "%1.0f");
482 elm_slider_indicator_format_set(sl, "%1.0f"); 482 elm_slider_indicator_format_set(sl, "%1.0f");
483 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, 0.5); 483 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, 0.5);
diff --git a/src/modules/mixer/lib/backends/alsa/alsa.c b/src/modules/mixer/lib/backends/alsa/alsa.c
index add473a15..063cb23c5 100644
--- a/src/modules/mixer/lib/backends/alsa/alsa.c
+++ b/src/modules/mixer/lib/backends/alsa/alsa.c
@@ -1,6 +1,8 @@
1#include "emix.h" 1#include "emix.h"
2#include <alsa/asoundlib.h> 2#include <alsa/asoundlib.h>
3 3
4#define MAX_VOLUME 100
5
4#define ERR(...) EINA_LOG_ERR(__VA_ARGS__) 6#define ERR(...) EINA_LOG_ERR(__VA_ARGS__)
5#define DBG(...) EINA_LOG_DBG(__VA_ARGS__) 7#define DBG(...) EINA_LOG_DBG(__VA_ARGS__)
6#define WRN(...) EINA_LOG_WARN(__VA_ARGS__) 8#define WRN(...) EINA_LOG_WARN(__VA_ARGS__)
@@ -74,7 +76,7 @@ _alsa_channel_volume_get(snd_mixer_elem_t *channel, int *v, Eina_Bool capture)
74 else 76 else
75 snd_mixer_selem_get_playback_volume_range(channel, &min, &max); 77 snd_mixer_selem_get_playback_volume_range(channel, &min, &max);
76 78
77 divide = 100 + min; 79 divide = MAX_VOLUME + min;
78 if (divide == 0) 80 if (divide == 0)
79 { 81 {
80 divide = 1; 82 divide = 1;
@@ -99,7 +101,7 @@ _alsa_channel_volume_set(snd_mixer_elem_t *channel, int v, Eina_Bool capture)
99 long int vol, min, max, divide, range; 101 long int vol, min, max, divide, range;
100 snd_mixer_selem_get_playback_volume_range(channel, &min, &max); 102 snd_mixer_selem_get_playback_volume_range(channel, &min, &max);
101 103
102 divide = 100 + min; 104 divide = MAX_VOLUME + min;
103 range = max - min; 105 range = max - min;
104 if (range < 1) 106 if (range < 1)
105 return; 107 return;
@@ -503,11 +505,18 @@ _alsa_sink_volume_set(Emix_Sink *sink, Emix_Volume v)
503 (Emix_Sink *)s); 505 (Emix_Sink *)s);
504} 506}
505 507
508static int
509_max_volume(void)
510{
511 return MAX_VOLUME;
512}
513
506static Emix_Backend 514static Emix_Backend
507_alsa_backend = 515_alsa_backend =
508{ 516{
509 _alsa_init, 517 _alsa_init,
510 _alsa_shutdown, 518 _alsa_shutdown,
519 _max_volume,
511 _alsa_sinks_get, 520 _alsa_sinks_get,
512 _alsa_support, /*default support*/ 521 _alsa_support, /*default support*/
513 NULL, /*get*/ 522 NULL, /*get*/
diff --git a/src/modules/mixer/lib/backends/pulseaudio/pulse.c b/src/modules/mixer/lib/backends/pulseaudio/pulse.c
index 40dda059d..f558b5b20 100644
--- a/src/modules/mixer/lib/backends/pulseaudio/pulse.c
+++ b/src/modules/mixer/lib/backends/pulseaudio/pulse.c
@@ -11,11 +11,11 @@
11#define WRN(...) EINA_LOG_WARN(__VA_ARGS__) 11#define WRN(...) EINA_LOG_WARN(__VA_ARGS__)
12 12
13#define PA_VOLUME_TO_INT(_vol) \ 13#define PA_VOLUME_TO_INT(_vol) \
14 ((_vol * EMIX_VOLUME_MAX) / \ 14 ((_vol * EMIX_VOLUME_BARRIER) / \
15 PA_VOLUME_NORM) 15 PA_VOLUME_NORM)
16#define INT_TO_PA_VOLUME(_vol) \ 16#define INT_TO_PA_VOLUME(_vol) \
17 ((PA_VOLUME_NORM * _vol) / \ 17 ((PA_VOLUME_NORM * _vol) / \
18 EMIX_VOLUME_MAX) 18 EMIX_VOLUME_BARRIER)
19 19
20typedef struct _Context 20typedef struct _Context
21{ 21{
@@ -491,7 +491,7 @@ _source_changed_cb(pa_context *c EINA_UNUSED,
491 491
492 if (!source) 492 if (!source)
493 { 493 {
494 source = calloc(1, sizeof(Source)); 494 source = calloc(1, sizeof(Source));
495 EINA_SAFETY_ON_NULL_RETURN(source); 495 EINA_SAFETY_ON_NULL_RETURN(source);
496 ctx->sources = eina_list_append(ctx->sources, source); 496 ctx->sources = eina_list_append(ctx->sources, source);
497 } 497 }
@@ -1057,11 +1057,18 @@ _sink_change_support(void)
1057 return EINA_TRUE; 1057 return EINA_TRUE;
1058} 1058}
1059 1059
1060static int
1061_max_volume(void)
1062{
1063 return 150;
1064}
1065
1060static Emix_Backend 1066static Emix_Backend
1061_pulseaudio_backend = 1067_pulseaudio_backend =
1062{ 1068{
1063 _init, 1069 _init,
1064 _shutdown, 1070 _shutdown,
1071 _max_volume,
1065 _sinks_get, 1072 _sinks_get,
1066 _sink_default_support, 1073 _sink_default_support,
1067 _sink_default_get, 1074 _sink_default_get,
diff --git a/src/modules/mixer/lib/emix.c b/src/modules/mixer/lib/emix.c
index 41babec4d..898df3a3b 100644
--- a/src/modules/mixer/lib/emix.c
+++ b/src/modules/mixer/lib/emix.c
@@ -170,6 +170,15 @@ emix_backends_available(void)
170 return ctx->backends_names; 170 return ctx->backends_names;
171} 171}
172 172
173int
174emix_max_volume_get(void)
175{
176 EINA_SAFETY_ON_FALSE_RETURN_VAL((ctx && ctx->loaded &&
177 ctx->loaded->ebackend_max_volume_get),
178 0);
179 return ctx->loaded->ebackend_max_volume_get();
180}
181
173Eina_Bool 182Eina_Bool
174emix_backend_set(const char *backend) 183emix_backend_set(const char *backend)
175{ 184{
diff --git a/src/modules/mixer/lib/emix.h b/src/modules/mixer/lib/emix.h
index d1772206b..1f1ee5e15 100644
--- a/src/modules/mixer/lib/emix.h
+++ b/src/modules/mixer/lib/emix.h
@@ -23,7 +23,7 @@
23#endif 23#endif
24 24
25 25
26#define EMIX_VOLUME_MAX 100 26#define EMIX_VOLUME_BARRIER 100
27 27
28enum Emix_Event { 28enum Emix_Event {
29 EMIX_READY_EVENT = 0, 29 EMIX_READY_EVENT = 0,
@@ -79,6 +79,8 @@ typedef struct _Emix_Backend {
79 Eina_Bool (*ebackend_init)(Emix_Event_Cb cb, const void *data); 79 Eina_Bool (*ebackend_init)(Emix_Event_Cb cb, const void *data);
80 void (*ebackend_shutdown)(void); 80 void (*ebackend_shutdown)(void);
81 81
82 int (*ebackend_max_volume_get)(void);
83
82 const Eina_List* (*ebackend_sinks_get)(void); 84 const Eina_List* (*ebackend_sinks_get)(void);
83 Eina_Bool (*ebackend_sink_default_support)(void); 85 Eina_Bool (*ebackend_sink_default_support)(void);
84 const Emix_Sink* (*ebackend_sink_default_get)(void); 86 const Emix_Sink* (*ebackend_sink_default_get)(void);
@@ -118,6 +120,8 @@ E_API Eina_Bool emix_event_callback_add(Emix_Event_Cb cb,
118 const void *data); 120 const void *data);
119E_API Eina_Bool emix_event_callback_del(Emix_Event_Cb cb); 121E_API Eina_Bool emix_event_callback_del(Emix_Event_Cb cb);
120 122
123E_API int emix_max_volume_get(void);
124
121E_API const Eina_List* emix_sinks_get(void); 125E_API const Eina_List* emix_sinks_get(void);
122E_API Eina_Bool emix_sink_default_support(void); 126E_API Eina_Bool emix_sink_default_support(void);
123E_API const Emix_Sink* emix_sink_default_get(void); 127E_API const Emix_Sink* emix_sink_default_get(void);
@@ -141,7 +145,6 @@ E_API void emix_source_mute_set(Emix_Source *source,
141 Eina_Bool mute); 145 Eina_Bool mute);
142E_API void emix_source_volume_set(Emix_Source *source, 146E_API void emix_source_volume_set(Emix_Source *source,
143 Emix_Volume volume); 147 Emix_Volume volume);
144
145E_API Evas_Object* emix_advanced_options_add(Evas_Object *parent); 148E_API Evas_Object* emix_advanced_options_add(Evas_Object *parent);
146 149
147#endif /* EMIX_H */ 150#endif /* EMIX_H */