From df4cae2aab47e33f20528b9d35a3c942c4a97eac Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 7 Feb 2011 11:19:17 +0000 Subject: fully functional once again --- src/active-sink.c | 118 +++++++++++++++++++++++++++++-------------------- src/active-sink.h | 6 +-- src/mute-menu-item.c | 8 ++-- src/pulseaudio-mgr.c | 53 +++++++++++++++++----- src/pulseaudio-mgr.h | 3 +- src/slider-menu-item.c | 8 +--- 6 files changed, 121 insertions(+), 75 deletions(-) (limited to 'src') diff --git a/src/active-sink.c b/src/active-sink.c index 16ab784..78eb79f 100644 --- a/src/active-sink.c +++ b/src/active-sink.c @@ -49,6 +49,8 @@ static void active_sink_finalize (GObject *object); static SoundState active_sink_get_state_from_volume (ActiveSink* self); static pa_cvolume active_sink_construct_mono_volume (const pa_cvolume* vol); +static void active_sink_volume_update (ActiveSink* self, gdouble percent); +static void active_sink_mute_update (ActiveSink* self, gboolean muted); G_DEFINE_TYPE (ActiveSink, active_sink, G_TYPE_OBJECT); @@ -65,7 +67,7 @@ active_sink_class_init (ActiveSinkClass *klass) } static void -active_sink_init(ActiveSink *self) +active_sink_init (ActiveSink *self) { ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self); priv->mute_menuitem = NULL; @@ -108,66 +110,37 @@ active_sink_populate (ActiveSink* sink, pa_volume_t vol = pa_cvolume_max (&update->volume); gdouble volume_percent = ((gdouble) vol * 100) / PA_VOLUME_NORM; + active_sink_volume_update (sink, volume_percent); - g_debug ("Active sink has been populated - volume %f", volume_percent); -} + active_sink_mute_update (sink, !!update->mute); -gboolean -active_sink_is_populated (ActiveSink* sink) -{ - ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (sink); - return (priv->index != -1); + g_debug ("Active sink has been populated - volume %f", volume_percent); } void -active_sink_determine_blocking_state (ActiveSink* self) -{ - ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self); - if (mute_menu_item_is_muted (priv->mute_menuitem)){ - /** - We don't want to set the current state to blocking - as this is a fire and forget event. - */ - sound_service_dbus_update_sound_state (priv->service, - BLOCKED); - } -} - -gint -active_sink_get_index (ActiveSink* self) +active_sink_update (ActiveSink* sink, + const pa_sink_info* update) { - ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self); - return priv->index; -} + ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (sink); + active_sink_mute_update (sink, update->mute); + priv->volume = active_sink_construct_mono_volume (&update->volume); + priv->base_volume = update->base_volume; + priv->channel_map = update->channel_map; -void -active_sink_deactivate (ActiveSink* self) -{ - ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self); - priv->current_sound_state = UNAVAILABLE; - sound_service_dbus_update_sound_state (priv->service, - priv->current_sound_state); - priv->index = -1; - g_free(priv->name); - priv->name = NULL; -} + pa_volume_t vol = pa_cvolume_max (&update->volume); + gdouble volume_percent = ((gdouble) vol * 100) / PA_VOLUME_NORM; -SoundState -active_sink_get_state (ActiveSink* self) -{ - ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self); - return priv->current_sound_state; + active_sink_volume_update (sink, volume_percent); + active_sink_mute_update (sink, update->mute); } // To the UI -void +static void active_sink_volume_update (ActiveSink* self, gdouble percent) { ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self); slider_menu_item_update (priv->volume_slider_menuitem, percent); - priv->current_sound_state = active_sink_get_state_from_volume (self); - sound_service_dbus_update_sound_state (priv->service, priv->current_sound_state); } @@ -185,11 +158,11 @@ active_sink_update_volume (ActiveSink* self, gdouble percent) ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self); pa_cvolume_set(&priv->volume, priv->channel_map.channels, new_volume_value); - + pm_update_volume (priv->index, new_volume); } -void +static void active_sink_mute_update (ActiveSink* self, gboolean muted) { ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self); @@ -240,7 +213,54 @@ active_sink_construct_mono_volume (const pa_cvolume* vol) return new_volume; } -ActiveSink* +void +active_sink_determine_blocking_state (ActiveSink* self) +{ + ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self); + if (mute_menu_item_is_muted (priv->mute_menuitem)){ + /** + We don't want to set the current state to blocking + as this is a fire and forget event. + */ + sound_service_dbus_update_sound_state (priv->service, + BLOCKED); + } +} + +gint +active_sink_get_index (ActiveSink* self) +{ + ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self); + return priv->index; +} + +gboolean +active_sink_is_populated (ActiveSink* sink) +{ + ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (sink); + return (priv->index != -1); +} + +void +active_sink_deactivate (ActiveSink* self) +{ + ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self); + priv->current_sound_state = UNAVAILABLE; + sound_service_dbus_update_sound_state (priv->service, + priv->current_sound_state); + priv->index = -1; + g_free(priv->name); + priv->name = NULL; +} + +SoundState +active_sink_get_state (ActiveSink* self) +{ + ActiveSinkPrivate* priv = ACTIVE_SINK_GET_PRIVATE (self); + return priv->current_sound_state; +} + +ActiveSink* active_sink_new (SoundServiceDbus* service) { ActiveSink* sink = g_object_new (ACTIVE_SINK_TYPE, NULL); @@ -250,5 +270,5 @@ active_sink_new (SoundServiceDbus* service) mute_menu_item_get_button (priv->mute_menuitem), DBUSMENU_MENUITEM (priv->volume_slider_menuitem)); pm_establish_pulse_connection (sink); - return sink; + return sink; } diff --git a/src/active-sink.h b/src/active-sink.h index 40dd84e..3d57829 100644 --- a/src/active-sink.h +++ b/src/active-sink.h @@ -51,6 +51,7 @@ struct _ActiveSinkClass { GType active_sink_get_type (void) G_GNUC_CONST; void active_sink_populate (ActiveSink* sink, const pa_sink_info* update); +void active_sink_update (ActiveSink* sink, const pa_sink_info* update); gboolean active_sink_is_populated (ActiveSink* sink); void active_sink_determine_blocking_state (ActiveSink* self); @@ -60,10 +61,9 @@ SoundState active_sink_get_state (ActiveSink* self); void active_sink_deactivate (ActiveSink* self); -void active_sink_volume_update (ActiveSink* self, gdouble vol_percent); -void active_sink_update_volume (ActiveSink* self, gdouble percent); +//void active_sink_volume_update (ActiveSink* self, gdouble vol_percent); -void active_sink_mute_update (ActiveSink* self, gboolean muted); +void active_sink_update_volume (ActiveSink* self, gdouble percent); ActiveSink* active_sink_new (SoundServiceDbus* service); diff --git a/src/mute-menu-item.c b/src/mute-menu-item.c index fdd4391..df98d5d 100644 --- a/src/mute-menu-item.c +++ b/src/mute-menu-item.c @@ -1,4 +1,4 @@ -/* +#/* Copyright 2011 Canonical Ltd. Authors: @@ -24,7 +24,7 @@ with this program. If not, see . #include "common-defs.h" #include "mute-menu-item.h" -#include "pulse-manager.h" +#include "pulseaudio-mgr.h" typedef struct _MuteMenuItemPrivate MuteMenuItemPrivate; @@ -90,10 +90,8 @@ mute_menu_item_set_global_mute_from_ui (gpointer user_data) DbusmenuMenuitem* button = DBUSMENU_MENUITEM (user_data); gboolean current_value = dbusmenu_menuitem_property_get_bool (button, DBUSMENU_MUTE_MENUITEM_VALUE); - gboolean new_value = !current_value; - // pa manager api - to be refactored - //toggle_global_mute (new_value); + pm_update_mute (new_value); } void diff --git a/src/pulseaudio-mgr.c b/src/pulseaudio-mgr.c index c8439e8..736b26d 100644 --- a/src/pulseaudio-mgr.c +++ b/src/pulseaudio-mgr.c @@ -59,6 +59,10 @@ static void pm_update_active_sink (pa_context *c, const pa_sink_info *info, int eol, void *userdata); +static void pm_toggle_mute_for_every_sink_callback (pa_context *c, + const pa_sink_info *sink, + int eol, + void* userdata); static gboolean reconnect_to_pulse (gpointer user_data); @@ -137,6 +141,23 @@ reconnect_to_pulse (gpointer user_data) } } +void +pm_update_volume (gint sink_index, pa_cvolume new_volume) +{ + pa_operation_unref (pa_context_set_sink_volume_by_index (pulse_context, + sink_index, + &new_volume, + NULL, + NULL) ); +} + +void +pm_update_mute (gboolean update) +{ + pa_operation_unref (pa_context_get_sink_info_list (pulse_context, + pm_toggle_mute_for_every_sink_callback, + GINT_TO_POINTER (update))); +} /**********************************************************************************************************************/ // Pulse-Audio asychronous call-backs @@ -212,17 +233,16 @@ pm_context_state_callback (pa_context *c, void *userdata) if (reconnect_idle_id == 0){ reconnect_idle_id = g_timeout_add_seconds (RECONNECT_DELAY, reconnect_to_pulse, - userdata); - } + userdata); + } break; case PA_CONTEXT_TERMINATED: break; case PA_CONTEXT_READY: - connection_attempts = 0; g_debug("PA_CONTEXT_READY"); pa_operation *o; - + pa_context_set_subscribe_callback(c, pm_subscribed_events_callback, userdata); if (!(o = pa_context_subscribe (c, (pa_subscription_mask_t) @@ -318,8 +338,7 @@ pm_default_sink_info_callback (pa_context *c, if (IS_ACTIVE_SINK (userdata) == FALSE){ g_warning ("Default sink info callback - our user data is not what we think it should be"); return; - } - + } g_debug ("server has handed us a default sink"); active_sink_populate (ACTIVE_SINK (userdata), info); } @@ -366,11 +385,25 @@ pm_update_active_sink (pa_context *c, g_warning ("update_active_sink - our user data is not what we think it should be"); return; } - pa_volume_t vol = pa_cvolume_max (&info->volume); - gdouble volume_percent = ((gdouble) vol * 100) / PA_VOLUME_NORM; - active_sink_volume_update (ACTIVE_SINK(userdata), volume_percent); - active_sink_mute_update (ACTIVE_SINK(userdata), info->mute); + active_sink_update (ACTIVE_SINK(userdata), info); } } +static void +pm_toggle_mute_for_every_sink_callback (pa_context *c, + const pa_sink_info *sink, + int eol, + void* userdata) +{ + if (eol > 0) { + return; + } + else { + pa_operation_unref (pa_context_set_sink_mute_by_index (c, + sink->index, + GPOINTER_TO_INT(userdata), + NULL, + NULL)); + } +} diff --git a/src/pulseaudio-mgr.h b/src/pulseaudio-mgr.h index 524b323..c0ab9c0 100644 --- a/src/pulseaudio-mgr.h +++ b/src/pulseaudio-mgr.h @@ -21,7 +21,8 @@ with this program. If not, see . void pm_establish_pulse_connection (ActiveSink* active_sink); void close_pulse_activites(); -//void pm_update_volume (gint sink_index); +void pm_update_volume (gint sink_index, pa_cvolume new_volume); +void pm_update_mute (gboolean update); diff --git a/src/slider-menu-item.c b/src/slider-menu-item.c index 31d4774..aaa6787 100644 --- a/src/slider-menu-item.c +++ b/src/slider-menu-item.c @@ -98,13 +98,7 @@ handle_event (DbusmenuMenuitem * mi, if (IS_SLIDER_MENU_ITEM (mi)) { SliderMenuItemPrivate* priv = SLIDER_MENU_ITEM_GET_PRIVATE (SLIDER_MENU_ITEM (mi)); active_sink_update_volume (priv->a_sink, volume_input); - } - - //active_sink_update_volume ( - // TODO - when the ACTIVESINK instance exists this will be handled nicely - // PA MANAGER will be refactored first. - - //set_sink_volume(volume_input); + } /*if (default_sink_is_muted () == TRUE){ toggle_global_mute (FALSE); }*/ -- cgit v1.2.3