aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/pulse-manager.c86
-rw-r--r--src/sound-service-dbus.c31
-rw-r--r--src/sound-service-dbus.h3
-rw-r--r--src/sound-service.xml6
4 files changed, 75 insertions, 51 deletions
diff --git a/src/pulse-manager.c b/src/pulse-manager.c
index e7570c6..858ae7b 100644
--- a/src/pulse-manager.c
+++ b/src/pulse-manager.c
@@ -22,33 +22,10 @@ static void pulse_server_info_callback(pa_context *c, const pa_server_info *info
static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, void *userdata);
static void destroy_sink_info(void *value);
+
/*
-Refine the resolution of the slider or binary scale it to achieve a more subtle volume control.
-Use the base volume stored in the sink struct to calculate actual linear volumes.
+Entry point
*/
-void set_sink_volume(gdouble percent)
-{
- g_debug("in the pulse manager:set_sink_volume with percent %f", percent);
- if(DEFAULT_SINK_INDEX < 0)
- {
- g_warning("We have no default sink !!! - returning after not attempting to set any volume of any sink");
- return;
- }
- gdouble linear_input = (gdouble)(percent);
- linear_input /= 100.0;
- g_debug("linear double input = %f", linear_input);
- pa_volume_t new_volume = pa_sw_volume_from_linear(linear_input);
- // Use this to achieve more accurate scaling using the base volume (in the sink struct already!)
- //pa_volume_t new_volume = (pa_volume_t) ((GPOINTER_TO_INT(linear_input) * s->base_volume) / 100);
- g_debug("about to try to set the sw volume to a linear volume of %f", pa_sw_volume_to_linear(new_volume));
- g_debug("and an actual volume of %f", (gdouble)new_volume);
- pa_cvolume dev_vol;
- sink_info *s = g_hash_table_lookup(sink_hash, GINT_TO_POINTER(DEFAULT_SINK_INDEX));
- pa_cvolume_set(&dev_vol, s->volume.channels, new_volume);
- // TODO - really this needs to be set in the success callback - if call fails then the ui will not be updated indefinitely!
- pa_operation_unref(pa_context_set_sink_volume_by_index(pulse_context, DEFAULT_SINK_INDEX, &dev_vol, NULL, NULL));
-}
-
void establish_pulse_activities(SoundServiceDbus *service)
{
dbus_service = service;
@@ -75,18 +52,6 @@ void close_pulse_activites()
g_debug("I just closed communication with Pulse");
}
-static void mute_each_sink(gpointer key, gpointer value, gpointer user_data)
-{
- sink_info *info = (sink_info*)value;
- pa_operation_unref(pa_context_set_sink_mute_by_index(pulse_context, info->index, GPOINTER_TO_INT(user_data), context_success_callback, NULL));
- g_debug("in the pulse manager: mute each sink %i", GPOINTER_TO_INT(user_data));
-}
-
-void toggle_global_mute(gboolean mute_value)
-{
- g_hash_table_foreach(sink_hash, mute_each_sink, GINT_TO_POINTER(mute_value));
- g_debug("in the pulse manager: toggle global mute value %i", mute_value);
-}
static void destroy_sink_info(void *value)
{
@@ -107,6 +72,10 @@ static void test_hash(){
}
+/*
+Controllers & Utilities
+*/
+
static gboolean sink_available()
{
if (g_hash_table_size(sink_hash) < 1)
@@ -150,6 +119,46 @@ static gdouble get_default_sink_volume()
return value;
}
+static void mute_each_sink(gpointer key, gpointer value, gpointer user_data)
+{
+ sink_info *info = (sink_info*)value;
+ pa_operation_unref(pa_context_set_sink_mute_by_index(pulse_context, info->index, GPOINTER_TO_INT(user_data), context_success_callback, NULL));
+ g_debug("in the pulse manager: mute each sink %i", GPOINTER_TO_INT(user_data));
+}
+
+void toggle_global_mute(gboolean mute_value)
+{
+ g_hash_table_foreach(sink_hash, mute_each_sink, GINT_TO_POINTER(mute_value));
+ g_debug("in the pulse manager: toggle global mute value %i", mute_value);
+}
+
+
+/*
+Refine the resolution of the slider or binary scale it to achieve a more subtle volume control.
+Use the base volume stored in the sink struct to calculate actual linear volumes.
+*/
+void set_sink_volume(gdouble percent)
+{
+ g_debug("in the pulse manager:set_sink_volume with percent %f", percent);
+ if(DEFAULT_SINK_INDEX < 0)
+ {
+ g_warning("We have no default sink !!! - returning after not attempting to set any volume of any sink");
+ return;
+ }
+ gdouble linear_input = (gdouble)(percent);
+ linear_input /= 100.0;
+ g_debug("linear double input = %f", linear_input);
+ pa_volume_t new_volume = pa_sw_volume_from_linear(linear_input);
+ // Use this to achieve more accurate scaling using the base volume (in the sink struct already!)
+ //pa_volume_t new_volume = (pa_volume_t) ((GPOINTER_TO_INT(linear_input) * s->base_volume) / 100);
+ g_debug("about to try to set the sw volume to a linear volume of %f", pa_sw_volume_to_linear(new_volume));
+ g_debug("and an actual volume of %f", (gdouble)new_volume);
+ pa_cvolume dev_vol;
+ sink_info *s = g_hash_table_lookup(sink_hash, GINT_TO_POINTER(DEFAULT_SINK_INDEX));
+ pa_cvolume_set(&dev_vol, s->volume.channels, new_volume);
+ pa_operation_unref(pa_context_set_sink_volume_by_index(pulse_context, DEFAULT_SINK_INDEX, &dev_vol, NULL, NULL));
+}
+
/**********************************************************************************************************************/
// Pulse-Audio asychronous call-backs
@@ -293,7 +302,8 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v
gdouble volume_percent = (vol/s->base_volume) * 100;
g_debug("When using base volume => volume = %f", volume_percent);
g_debug("about to update ui with linear volume of %f", pa_sw_volume_to_linear(vol));
- sound_service_dbus_update_sink_volume(dbus_service, pa_sw_volume_to_linear(vol) * 100);
+ sound_service_dbus_update_sink_volume(dbus_service, pa_sw_volume_to_linear(vol));
+
update_mute_ui(s->mute);
}
else{
diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c
index ac92a06..00a2692 100644
--- a/src/sound-service-dbus.c
+++ b/src/sound-service-dbus.c
@@ -49,6 +49,7 @@ struct _SoundServiceDbusPrivate
enum {
SINK_INPUT_WHILE_MUTED,
SINK_VOLUME_UPDATE,
+ SINK_MUTE_UPDATE,
LAST_SIGNAL
};
@@ -96,6 +97,14 @@ sound_service_dbus_class_init (SoundServiceDbusClass *klass)
g_cclosure_marshal_VOID__DOUBLE,
G_TYPE_NONE, 1, G_TYPE_DOUBLE);
+ signals[SINK_MUTE_UPDATE] = g_signal_new("sink-mute-update",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__BOOLEAN,
+ G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+
}
static void
@@ -177,23 +186,23 @@ void sound_service_dbus_sink_input_while_muted(SoundServiceDbus* obj, gint sink_
void sound_service_dbus_update_sink_volume(SoundServiceDbus* obj, gdouble sink_volume)
{
SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (obj);
- priv->volume_percent = sink_volume;
+ priv->volume_percent = sink_volume * 100;
- g_debug("Emitting signal: SINK_VOLUME_UPDATE, with sink_volme %f", sink_volume);
+ g_debug("Emitting signal: SINK_VOLUME_UPDATE, with sink_volme %f", priv->volume_percent);
g_signal_emit(obj,
signals[SINK_VOLUME_UPDATE],
0,
- sink_volume);
+ priv->volume_percent);
}
-/*void sound_service_dbus_update_sink_mute(SoundServiceDbus* obj, gboolean sink_mute)*/
-/*{*/
-/* g_debug("Emitting signal: SINK_MUTE_UPDATE, with sink mute %i", sink_mute);*/
-/* g_signal_emit(obj,*/
-/* signals[SINK_MUTE_UPDATE],*/
-/* 0,*/
-/* sink_mute);*/
-/*}*/
+void sound_service_dbus_update_sink_mute(SoundServiceDbus* obj, gboolean sink_mute)
+{
+ g_debug("Emitting signal: SINK_MUTE_UPDATE, with sink mute %i", sink_mute);
+ g_signal_emit(obj,
+ signals[SINK_MUTE_UPDATE],
+ 0,
+ sink_mute);
+}
diff --git a/src/sound-service-dbus.h b/src/sound-service-dbus.h
index 08d4bbd..3103d98 100644
--- a/src/sound-service-dbus.h
+++ b/src/sound-service-dbus.h
@@ -52,12 +52,13 @@ struct _SoundServiceDbusClass {
/* Signals -> outward messages to the DBUS and beyond*/
void (* sink_input_while_muted) (SoundServiceDbus *self, gint sink_index, gboolean is_muted, gpointer sound_data);
void (* sink_volume_update) (SoundServiceDbus *self, gdouble sink_volume, gpointer sound_data);
-};
+};
GType sound_service_dbus_get_type (void) G_GNUC_CONST;
// Utility methods to get the messages across into the sound-service-dbus
void sound_service_dbus_sink_input_while_muted (SoundServiceDbus* obj, gint sink_index, gboolean value);
void sound_service_dbus_update_sink_volume(SoundServiceDbus* obj, gdouble sink_volume);
+void sound_service_dbus_update_sink_mute(SoundServiceDbus* obj, gboolean sink_mute);
// DBUS METHODS
void sound_service_dbus_set_sink_volume(SoundServiceDbus* service, const guint volume_percent, GError** gerror);
diff --git a/src/sound-service.xml b/src/sound-service.xml
index 4a88aab..65d88ab 100644
--- a/src/sound-service.xml
+++ b/src/sound-service.xml
@@ -15,13 +15,17 @@ Our respective UI element should listen to this and therefore will be updated wi
<!-- Triggered when a sink is muted but the input has been sent to that sink -->
<signal name="SinkInputWhileMuted">
<arg name="sink_index" type="x" direction="out"/>
- <arg name="mute_value" type="b" direction="out"/>
+ <arg name="block_value" type="b" direction="out"/>
</signal>
<signal name="SinkVolumeUpdate">
<arg name="volume_percent" type="u" direction="out"/>
</signal>
+ <signal name="SinkMuteUpdate">
+ <arg name="mute_value" type="b" direction="out"/>
+ </signal>
+
</interface>
</node>