summaryrefslogtreecommitdiff
path: root/mate-volume-control/src/mvc-helpers.c
diff options
context:
space:
mode:
authorMichal Ratajsky <[email protected]>2014-07-18 17:55:53 +0200
committerinfirit <[email protected]>2014-10-09 16:53:00 +0200
commit0c558fac14266f8c18cfb8bc1d4669ed35868c2f (patch)
treefb7479547b7c1032b13a1adc0f33e9c71861251a /mate-volume-control/src/mvc-helpers.c
parent25445eb4cb2d7b49bc435113056587f83b742104 (diff)
downloadmate-media-0c558fac14266f8c18cfb8bc1d4669ed35868c2f.tar.bz2
mate-media-0c558fac14266f8c18cfb8bc1d4669ed35868c2f.tar.xz
More porting work along with fixes and cleanups
Diffstat (limited to 'mate-volume-control/src/mvc-helpers.c')
-rw-r--r--mate-volume-control/src/mvc-helpers.c240
1 files changed, 212 insertions, 28 deletions
diff --git a/mate-volume-control/src/mvc-helpers.c b/mate-volume-control/src/mvc-helpers.c
index 2861bbd..b82d6c8 100644
--- a/mate-volume-control/src/mvc-helpers.c
+++ b/mate-volume-control/src/mvc-helpers.c
@@ -18,8 +18,11 @@
*
*/
+#include "config.h"
+
#include <glib.h>
#include <glib/gi18n.h>
+#include <gtk/gtk.h>
#include <libmatemixer/matemixer.h>
@@ -30,7 +33,7 @@
#include "mvc-helpers.h"
#ifdef HAVE_PULSEAUDIO
-static pa_position_t
+static pa_channel_position_t
position_to_pulse (MateMixerChannelPosition position)
{
switch (position) {
@@ -101,55 +104,236 @@ mvc_channel_map_to_pretty_string (MateMixerStream *stream)
{
g_return_val_if_fail (MATE_MIXER_IS_STREAM (stream), NULL);
+#define HAS_POSITION(p) (mate_mixer_stream_has_channel_position (stream, (p)))
+
/* Modeled after PulseAudio 5.0, probably could be extended with other combinations */
switch (mate_mixer_stream_get_num_channels (stream)) {
case 1:
- if (mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_MONO))
+ if (HAS_POSITION (MATE_MIXER_CHANNEL_MONO))
return _("Mono");
break;
case 2:
- if (mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_FRONT_LEFT) &&
- mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_FRONT_RIGHT))
+ if (HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_LEFT) &&
+ HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_RIGHT))
return _("Stereo");
break;
case 4:
- if (mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_FRONT_LEFT) &&
- mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_FRONT_RIGHT) &&
- mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_BACK_LEFT) &&
- mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_BACK_RIGHT))
+ if (HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_LEFT) &&
+ HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_RIGHT) &&
+ HAS_POSITION (MATE_MIXER_CHANNEL_BACK_LEFT) &&
+ HAS_POSITION (MATE_MIXER_CHANNEL_BACK_RIGHT))
return _("Surround 4.0");
break;
case 5:
- if (mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_FRONT_LEFT) &&
- mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_FRONT_RIGHT) &&
- mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_BACK_LEFT) &&
- mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_BACK_RIGHT))
- if (mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_LFE))
+ if (HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_LEFT) &&
+ HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_RIGHT) &&
+ HAS_POSITION (MATE_MIXER_CHANNEL_BACK_LEFT) &&
+ HAS_POSITION (MATE_MIXER_CHANNEL_BACK_RIGHT))
+ if (HAS_POSITION (MATE_MIXER_CHANNEL_LFE))
return _("Surround 4.1");
- if (mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_FRONT_CENTER))
+ if (HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_CENTER))
return _("Surround 5.0");
break;
case 6:
- if (mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_FRONT_LEFT) &&
- mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_FRONT_RIGHT) &&
- mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_FRONT_CENTER) &&
- mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_BACK_LEFT) &&
- mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_BACK_RIGHT) &&
- mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_LFE))
+ if (HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_LEFT) &&
+ HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_RIGHT) &&
+ HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_CENTER) &&
+ HAS_POSITION (MATE_MIXER_CHANNEL_BACK_LEFT) &&
+ HAS_POSITION (MATE_MIXER_CHANNEL_BACK_RIGHT) &&
+ HAS_POSITION (MATE_MIXER_CHANNEL_LFE))
return _("Surround 5.1");
break;
case 8:
- if (mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_FRONT_LEFT) &&
- mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_FRONT_RIGHT) &&
- mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_FRONT_CENTER) &&
- mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_BACK_LEFT) &&
- mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_BACK_RIGHT) &&
- mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_SIDE_LEFT) &&
- mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_SIDE_RIGHT) &&
- mate_mixer_stream_has_position (stream, MATE_MIXER_CHANNEL_LFE))
+ if (HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_LEFT) &&
+ HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_RIGHT) &&
+ HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_CENTER) &&
+ HAS_POSITION (MATE_MIXER_CHANNEL_BACK_LEFT) &&
+ HAS_POSITION (MATE_MIXER_CHANNEL_BACK_RIGHT) &&
+ HAS_POSITION (MATE_MIXER_CHANNEL_SIDE_LEFT) &&
+ HAS_POSITION (MATE_MIXER_CHANNEL_SIDE_RIGHT) &&
+ HAS_POSITION (MATE_MIXER_CHANNEL_LFE))
return _("Surround 7.1");
break;
}
+#undef HAS_POSITION
+
return NULL;
}
+
+#if GTK_CHECK_VERSION (3, 0, 0)
+/* Taken from gtkstyle.c */
+static void rgb_to_hls (gdouble *r, gdouble *g, gdouble *b);
+static void hls_to_rgb (gdouble *h, gdouble *l, gdouble *s);
+
+void
+mvc_color_shade (GdkRGBA *a, GdkRGBA *b, gdouble k)
+{
+ gdouble red;
+ gdouble green;
+ gdouble blue;
+
+ red = (gdouble) a->red / 65535.0;
+ green = (gdouble) a->green / 65535.0;
+ blue = (gdouble) a->blue / 65535.0;
+
+ rgb_to_hls (&red, &green, &blue);
+
+ green *= k;
+ if (green > 1.0)
+ green = 1.0;
+ else if (green < 0.0)
+ green = 0.0;
+
+ blue *= k;
+ if (blue > 1.0)
+ blue = 1.0;
+ else if (blue < 0.0)
+ blue = 0.0;
+
+ hls_to_rgb (&red, &green, &blue);
+
+ b->red = red * 65535.0;
+ b->green = green * 65535.0;
+ b->blue = blue * 65535.0;
+}
+
+static void
+rgb_to_hls (gdouble *r, gdouble *g, gdouble *b)
+{
+ gdouble min;
+ gdouble max;
+ gdouble red;
+ gdouble green;
+ gdouble blue;
+ gdouble h, l, s;
+ gdouble delta;
+
+ red = *r;
+ green = *g;
+ blue = *b;
+
+ if (red > green) {
+ if (red > blue)
+ max = red;
+ else
+ max = blue;
+
+ if (green < blue)
+ min = green;
+ else
+ min = blue;
+ } else {
+ if (green > blue)
+ max = green;
+ else
+ max = blue;
+
+ if (red < blue)
+ min = red;
+ else
+ min = blue;
+ }
+
+ l = (max + min) / 2;
+ s = 0;
+ h = 0;
+
+ if (max != min) {
+ if (l <= 0.5)
+ s = (max - min) / (max + min);
+ else
+ s = (max - min) / (2 - max - min);
+
+ delta = max - min;
+ if (red == max)
+ h = (green - blue) / delta;
+ else if (green == max)
+ h = 2 + (blue - red) / delta;
+ else if (blue == max)
+ h = 4 + (red - green) / delta;
+
+ h *= 60;
+ if (h < 0.0)
+ h += 360;
+ }
+
+ *r = h;
+ *g = l;
+ *b = s;
+}
+
+static void
+hls_to_rgb (gdouble *h, gdouble *l, gdouble *s)
+{
+ gdouble hue;
+ gdouble lightness;
+ gdouble saturation;
+ gdouble m1, m2;
+ gdouble r, g, b;
+
+ lightness = *l;
+ saturation = *s;
+
+ if (lightness <= 0.5)
+ m2 = lightness * (1 + saturation);
+ else
+ m2 = lightness + saturation - lightness * saturation;
+ m1 = 2 * lightness - m2;
+
+ if (saturation == 0) {
+ *h = lightness;
+ *l = lightness;
+ *s = lightness;
+ } else {
+ hue = *h + 120;
+ while (hue > 360)
+ hue -= 360;
+ while (hue < 0)
+ hue += 360;
+
+ if (hue < 60)
+ r = m1 + (m2 - m1) * hue / 60;
+ else if (hue < 180)
+ r = m2;
+ else if (hue < 240)
+ r = m1 + (m2 - m1) * (240 - hue) / 60;
+ else
+ r = m1;
+
+ hue = *h;
+ while (hue > 360)
+ hue -= 360;
+ while (hue < 0)
+ hue += 360;
+
+ if (hue < 60)
+ g = m1 + (m2 - m1) * hue / 60;
+ else if (hue < 180)
+ g = m2;
+ else if (hue < 240)
+ g = m1 + (m2 - m1) * (240 - hue) / 60;
+ else
+ g = m1;
+
+ hue = *h - 120;
+ while (hue > 360)
+ hue -= 360;
+ while (hue < 0)
+ hue += 360;
+
+ if (hue < 60)
+ b = m1 + (m2 - m1) * hue / 60;
+ else if (hue < 180)
+ b = m2;
+ else if (hue < 240)
+ b = m1 + (m2 - m1) * (240 - hue) / 60;
+ else
+ b = m1;
+
+ *h = r;
+ *l = g;
+ *s = b;
+ }
+}
+#endif