From 80365e3a179e1b33beb0cf029871928a6357e557 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 31 Mar 2010 16:10:16 +0100 Subject: bumped the release number to 2.2 --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index a0812d3..c20771b 100644 --- a/configure.ac +++ b/configure.ac @@ -1,10 +1,10 @@ -AC_INIT(indicator-sound, 0.2.1, conor.curran@canonical.com) +AC_INIT(indicator-sound, 0.2.2, conor.curran@canonical.com) AC_PREREQ(2.53) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(indicator-sound, 0.2.1) +AM_INIT_AUTOMAKE(indicator-sound, 0.2.2) AM_MAINTAINER_MODE -- cgit v1.2.3 From 132bf8d107161102b63bf254056624bc00b8d01f Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 14 Apr 2010 17:13:43 +0100 Subject: Remove unnecessary warning at start up - thx njpatel --- src/indicator-sound.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 6c8f4e1..7f1f1d6 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -457,11 +457,14 @@ static void fetch_sink_availability_from_dbus() return; } device_available = *available_input; - if (device_available == FALSE) + if (device_available == FALSE){ update_state(STATE_SINKS_NONE); g_debug("NO DEVICE AVAILABLE"); + } - gtk_widget_set_sensitive(volume_slider, device_available); + if (GTK_IS_WIDGET (volume_slider)) + gtk_widget_set_sensitive(volume_slider, device_available); + g_free(available_input); g_debug("IndicatorSound::fetch_sink_availability_from_dbus -> AVAILABILTY returned from dbus method is %i", device_available); -- cgit v1.2.3 From 5b74cf4b47b34fc53b89cc98fab413c603e2c80a Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 22 Apr 2010 17:58:50 +0100 Subject: panning now honoured at all times, more feedback loop noise removed also from the indicator side --- src/indicator-sound.c | 12 ++++++--- src/pulse-manager.c | 72 +++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 70 insertions(+), 14 deletions(-) diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 7f1f1d6..96b151a 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -117,10 +117,11 @@ static GtkImage *speaker_image = NULL; static gint current_state = 0; static gint previous_state = 0; -static gdouble initial_volume_percent = 0; +static gdouble initial_volume_percent; static gboolean initial_mute ; static gboolean device_available; -static gboolean slider_in_direct_use = FALSE; +static gboolean slider_in_direct_use; +static gdouble exterior_vol_update; static GtkIconSize design_team_size; static gint blocked_id; @@ -163,6 +164,7 @@ static void indicator_sound_init (IndicatorSound *self) initial_mute = FALSE; device_available = TRUE; slider_in_direct_use = FALSE; + exterior_vol_update = 0; g_signal_connect(G_OBJECT(self->service), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_changed), self); return; @@ -551,6 +553,7 @@ static void catch_signal_sink_volume_update(DBusGProxy *proxy, gdouble volume_pe // DEBUG gdouble current_value = gtk_range_get_value(range); g_debug("SIGNAL- update sink volume - current_value : %f and new value : %f", current_value, volume_percent); + exterior_vol_update = volume_percent; gtk_range_set_value(range, volume_percent); determine_state_from_volume(volume_percent); } @@ -597,6 +600,10 @@ This callback will get triggered irregardless of whether its a user change or a static gboolean value_changed_event_cb(GtkRange *range, gpointer user_data) { gdouble current_value = CLAMP(gtk_range_get_value(range), 0, 100); + if(current_value == exterior_vol_update){ + g_debug("ignore the value changed event - its come from the outside"); + return FALSE; + } DbusmenuMenuitem *item = (DbusmenuMenuitem*)user_data; GValue value = {0}; g_value_init(&value, G_TYPE_DOUBLE); @@ -623,7 +630,6 @@ static void slider_released (GtkWidget *widget, gpointer user_data) } - /** key_press_cb: **/ diff --git a/src/pulse-manager.c b/src/pulse-manager.c index 1ce94d0..e3fa097 100644 --- a/src/pulse-manager.c +++ b/src/pulse-manager.c @@ -46,6 +46,18 @@ static void destroy_sink_info(void *value); static gboolean determine_sink_availability(); static void reconnect_to_pulse(); +static gboolean has_volume_changed(const pa_sink_info* new_sink, sink_info* cached_sink); +/*static gdouble construct_volume_with_respect_to_balance(pa_cvolume* new_vol, pa_cvolume* cached_vol, pa_channel_map* cached_map);*/ + + +enum { + VOLUME, + BALANCE, + FADE, + LFE, +}; + +#define NUM_TYPES LFE + 1 /** Refactoring notes @@ -223,25 +235,38 @@ void set_sink_volume(gdouble percent) if(pa_server_available == FALSE) return; 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; } - sink_info *s = g_hash_table_lookup(sink_hash, GINT_TO_POINTER(DEFAULT_SINK_INDEX)); - + sink_info *s = g_hash_table_lookup(sink_hash, GINT_TO_POINTER(DEFAULT_SINK_INDEX)); + pa_volume_t cached_volume = pa_cvolume_max(&s->volume); pa_volume_t new_volume = (pa_volume_t) ((percent * PA_VOLUME_NORM) / 100); - g_debug("new_volume double check :%f", pa_sw_volume_to_linear(new_volume)); - g_debug("new volume calculated :%f", (gdouble)new_volume); - pa_cvolume dev_vol; - pa_cvolume_set(&dev_vol, s->volume.channels, new_volume); - s->volume = dev_vol; - pa_operation_unref(pa_context_set_sink_volume_by_index(pulse_context, DEFAULT_SINK_INDEX, &dev_vol, NULL, NULL)); - + pa_volume_t difference = 0; + + if( cached_volume > new_volume ){ + g_debug("I'm moving down down ..."); + difference = cached_volume - new_volume; + pa_cvolume_dec(&s->volume, difference); + } + else if ( cached_volume < new_volume ){ + g_debug("I'm moving up up ..."); + difference = new_volume - cached_volume; + pa_cvolume_inc(&s->volume, difference); + } + + g_debug("Calculated difference : %f", (gdouble)difference); + g_debug("new_volume calculated from percentage input :%f", pa_sw_volume_to_linear(new_volume)); + g_debug("new volume calculated from resultant output :%f", pa_sw_volume_to_linear(pa_cvolume_max(&s->volume))); + + pa_operation_unref(pa_context_set_sink_volume_by_index(pulse_context, DEFAULT_SINK_INDEX, &s->volume, NULL, NULL)); } + /**********************************************************************************************************************/ // Pulse-Audio asychronous call-backs /**********************************************************************************************************************/ @@ -373,9 +398,18 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v s->name = g_strdup(info->name); gboolean mute_changed = s->mute != !!info->mute; s->mute = !!info->mute; - gboolean volume_changed = (pa_cvolume_equal(&info->volume, &s->volume) == 0); + g_debug("new balance : %i", (int)(pa_cvolume_get_balance(&info->volume, &info->channel_map) * 100)); + g_debug("cached balance : %i", (int)(pa_cvolume_get_balance(&s->volume, &s->channel_map) * 100)); + g_debug("update_sink_info: new_volume input : %f", (gdouble)(pa_cvolume_avg(&info->volume))); + g_debug("update sink info: cached volume is at: %f", (gdouble)(pa_cvolume_avg(&s->volume))); + gboolean volume_changed = has_volume_changed(info, s); + + g_debug("update sink info : volume changed = %i", volume_changed); + g_debug("update sink info : compatibility = %i", pa_cvolume_compatible_with_channel_map(&info->volume, &s->channel_map)); + s->volume = info->volume; - s->base_volume = info->base_volume; + s->channel_map = info->channel_map; + if(DEFAULT_SINK_INDEX == s->index) { //update the UI @@ -409,6 +443,7 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v value->name = g_strdup(info->name); value->mute = !!info->mute; value->volume = info->volume; + value->channel_map = info->channel_map; value->base_volume = info->base_volume; g_hash_table_insert(sink_hash, GINT_TO_POINTER(value->index), value); g_debug("pulse-manager:update_sink_info -> After adding a new sink to our hash"); @@ -417,6 +452,21 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v } +static gboolean has_volume_changed(const pa_sink_info* new_sink, sink_info* cached_sink) +{ + if(pa_cvolume_compatible_with_channel_map(&new_sink->volume, &cached_sink->channel_map) == FALSE) + return FALSE; + + if(pa_cvolume_equal(&new_sink->volume, &cached_sink->volume) == TRUE) + return FALSE; + + if((int)(pa_cvolume_get_balance(&new_sink->volume, &new_sink->channel_map) * 100) != (int)(pa_cvolume_get_balance(&cached_sink->volume, &cached_sink->channel_map) * 100)) + return FALSE; + + return TRUE; +} + + static void pulse_server_info_callback(pa_context *c, const pa_server_info *info, void *userdata) { g_debug("server info callback"); -- cgit v1.2.3 From f39d4f300543d4b5717b39e45e47fbbb51c96a97 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 22 Apr 2010 19:24:45 +0100 Subject: greatly simplified the volume setting code without messing with balance --- src/pulse-manager.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/src/pulse-manager.c b/src/pulse-manager.c index e3fa097..c527d6d 100644 --- a/src/pulse-manager.c +++ b/src/pulse-manager.c @@ -242,27 +242,16 @@ void set_sink_volume(gdouble percent) return; } - sink_info *s = g_hash_table_lookup(sink_hash, GINT_TO_POINTER(DEFAULT_SINK_INDEX)); - pa_volume_t cached_volume = pa_cvolume_max(&s->volume); - pa_volume_t new_volume = (pa_volume_t) ((percent * PA_VOLUME_NORM) / 100); - pa_volume_t difference = 0; - - if( cached_volume > new_volume ){ - g_debug("I'm moving down down ..."); - difference = cached_volume - new_volume; - pa_cvolume_dec(&s->volume, difference); - } - else if ( cached_volume < new_volume ){ - g_debug("I'm moving up up ..."); - difference = new_volume - cached_volume; - pa_cvolume_inc(&s->volume, difference); - } + sink_info *cached_sink = g_hash_table_lookup(sink_hash, GINT_TO_POINTER(DEFAULT_SINK_INDEX)); - g_debug("Calculated difference : %f", (gdouble)difference); - g_debug("new_volume calculated from percentage input :%f", pa_sw_volume_to_linear(new_volume)); - g_debug("new volume calculated from resultant output :%f", pa_sw_volume_to_linear(pa_cvolume_max(&s->volume))); + pa_cvolume new_volume; + pa_cvolume_init(&new_volume); + new_volume.channels = 1; + pa_volume_t new_volume_value = (pa_volume_t) ((percent * PA_VOLUME_NORM) / 100); + pa_cvolume_set(&new_volume, 1, new_volume_value); + pa_cvolume_set(&cached_sink->volume, cached_sink->channel_map.channels, new_volume_value); - pa_operation_unref(pa_context_set_sink_volume_by_index(pulse_context, DEFAULT_SINK_INDEX, &s->volume, NULL, NULL)); + pa_operation_unref(pa_context_set_sink_volume_by_index(pulse_context, DEFAULT_SINK_INDEX, &new_volume, NULL, NULL)); } -- cgit v1.2.3 From 069f29434cb928f76131c068911ec06e0b946d98 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 23 Apr 2010 12:00:02 +0100 Subject: volume comparision now far more efficient due to caching of mono volumes as opposed to stereo --- src/pulse-manager.c | 123 ++++++++++++++++++++++------------------------------ 1 file changed, 53 insertions(+), 70 deletions(-) diff --git a/src/pulse-manager.c b/src/pulse-manager.c index c527d6d..c84cfcc 100644 --- a/src/pulse-manager.c +++ b/src/pulse-manager.c @@ -41,32 +41,22 @@ static void context_success_callback(pa_context *c, int success, void *userdata) static void pulse_sink_input_info_callback(pa_context *c, const pa_sink_input_info *info, int eol, void *userdata); static void pulse_server_info_callback(pa_context *c, const pa_server_info *info, void *userdata); static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, void *userdata); -static void pulse_source_info_callback(pa_context *c, const pa_source_info *i, int eol, void *userdata); static void destroy_sink_info(void *value); static gboolean determine_sink_availability(); static void reconnect_to_pulse(); static gboolean has_volume_changed(const pa_sink_info* new_sink, sink_info* cached_sink); -/*static gdouble construct_volume_with_respect_to_balance(pa_cvolume* new_vol, pa_cvolume* cached_vol, pa_channel_map* cached_map);*/ - - -enum { - VOLUME, - BALANCE, - FADE, - LFE, -}; - -#define NUM_TYPES LFE + 1 +static pa_cvolume construct_mono_volume(const pa_cvolume* vol); /** -Refactoring notes -Push all UI updates out through update PA state in the service. +Future Refactoring notes + - Push all UI updates out through update PA state in the service. + - Collapse 3 update_sink_info into one. The essentially do the same thing from different contexts. **/ -/* +/** Entry point -*/ +**/ void establish_pulse_activities(SoundServiceDbus *service) { dbus_service = service; @@ -83,11 +73,19 @@ void establish_pulse_activities(SoundServiceDbus *service) pa_context_connect(pulse_context, NULL, PA_CONTEXT_NOFAIL, NULL); } +/** +get_context() +Needed for testing - bah! +**/ pa_context* get_context() { return pulse_context; } +/** +close_pulse_activites() +Gracefully close our connection with the Pulse async library. +**/ void close_pulse_activites() { if (pulse_context != NULL){ @@ -130,6 +128,10 @@ static void reconnect_to_pulse() pa_context_connect(pulse_context, NULL, PA_CONTEXT_NOFAIL, NULL); } +/** +destroy_sink_info() +item destructor method for the sink_info hash +**/ static void destroy_sink_info(void *value) { sink_info *sink = (sink_info*)value; @@ -184,12 +186,10 @@ static void check_sink_input_while_muted_event(gint sink_index) { g_debug("SINKINPUTWHILEMUTED SIGNAL EVENT TO BE SENT FROM PA MANAGER - check trace for value"); - if (default_sink_is_muted(sink_index) == TRUE) - { + if (default_sink_is_muted(sink_index) == TRUE){ sound_service_dbus_sink_input_while_muted (dbus_service, TRUE); } - else - { + else{ sound_service_dbus_sink_input_while_muted(dbus_service, FALSE); } } @@ -250,11 +250,19 @@ void set_sink_volume(gdouble percent) pa_volume_t new_volume_value = (pa_volume_t) ((percent * PA_VOLUME_NORM) / 100); pa_cvolume_set(&new_volume, 1, new_volume_value); pa_cvolume_set(&cached_sink->volume, cached_sink->channel_map.channels, new_volume_value); - pa_operation_unref(pa_context_set_sink_volume_by_index(pulse_context, DEFAULT_SINK_INDEX, &new_volume, NULL, NULL)); } +static pa_cvolume construct_mono_volume(const pa_cvolume* vol) +{ + pa_cvolume new_volume; + pa_cvolume_init(&new_volume); + new_volume.channels = 1; + pa_volume_t max_vol = pa_cvolume_max(vol); + pa_cvolume_set(&new_volume, 1, max_vol); + return new_volume; +} /**********************************************************************************************************************/ // Pulse-Audio asychronous call-backs @@ -313,7 +321,7 @@ static void pulse_sink_info_callback(pa_context *c, const pa_sink_info *sink, in value->index = sink->index; value->name = g_strdup(sink->name); value->mute = !!sink->mute; - value->volume = sink->volume; + value->volume = construct_mono_volume(&sink->volume); value->base_volume = sink->base_volume; value->channel_map = sink->channel_map; g_hash_table_insert(sink_hash, GINT_TO_POINTER(sink->index), value); @@ -387,16 +395,16 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v s->name = g_strdup(info->name); gboolean mute_changed = s->mute != !!info->mute; s->mute = !!info->mute; - g_debug("new balance : %i", (int)(pa_cvolume_get_balance(&info->volume, &info->channel_map) * 100)); - g_debug("cached balance : %i", (int)(pa_cvolume_get_balance(&s->volume, &s->channel_map) * 100)); - g_debug("update_sink_info: new_volume input : %f", (gdouble)(pa_cvolume_avg(&info->volume))); - g_debug("update sink info: cached volume is at: %f", (gdouble)(pa_cvolume_avg(&s->volume))); gboolean volume_changed = has_volume_changed(info, s); - g_debug("update sink info : volume changed = %i", volume_changed); - g_debug("update sink info : compatibility = %i", pa_cvolume_compatible_with_channel_map(&info->volume, &s->channel_map)); +/* g_debug("new balance : %i", (int)(pa_cvolume_get_balance(&info->volume, &info->channel_map) * 100));*/ +/* g_debug("cached balance : %i", (int)(pa_cvolume_get_balance(&s->volume, &s->channel_map) * 100));*/ +/* g_debug("update_sink_info: new_volume input : %f", (gdouble)(pa_cvolume_max(&info->volume)));*/ +/* g_debug("update sink info: cached volume is at: %f", (gdouble)(pa_cvolume_max(&s->volume)));*/ +/* g_debug("update sink info : volume changed = %i", volume_changed);*/ +/* g_debug("update sink info : compatibility = %i", pa_cvolume_compatible_with_channel_map(&info->volume, &s->channel_map));*/ - s->volume = info->volume; + s->volume = construct_mono_volume(&info->volume); s->channel_map = info->channel_map; if(DEFAULT_SINK_INDEX == s->index) @@ -404,7 +412,7 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v //update the UI if (volume_changed == TRUE && s->mute == FALSE) { - pa_volume_t vol = pa_cvolume_avg(&s->volume); + pa_volume_t vol = pa_cvolume_max(&s->volume); gdouble volume_percent = ((gdouble) vol * 100) / PA_VOLUME_NORM; g_debug("Updating volume from PA manager with volume = %f", volume_percent); sound_service_dbus_update_sink_volume(dbus_service, volume_percent); @@ -416,7 +424,7 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v sound_service_dbus_update_sink_mute(dbus_service, s->mute); dbus_menu_manager_update_mute_ui(s->mute); if(s->mute == FALSE){ - pa_volume_t vol = pa_cvolume_avg(&s->volume); + pa_volume_t vol = pa_cvolume_max(&s->volume); gdouble volume_percent = ((gdouble) vol * 100) / PA_VOLUME_NORM; g_debug("Updating volume from PA manager with volume = %f", volume_percent); sound_service_dbus_update_sink_volume(dbus_service, volume_percent); @@ -431,7 +439,7 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v value->index = info->index; value->name = g_strdup(info->name); value->mute = !!info->mute; - value->volume = info->volume; + value->volume = construct_mono_volume(&info->volume); value->channel_map = info->channel_map; value->base_volume = info->base_volume; g_hash_table_insert(sink_hash, GINT_TO_POINTER(value->index), value); @@ -446,12 +454,13 @@ static gboolean has_volume_changed(const pa_sink_info* new_sink, sink_info* cach if(pa_cvolume_compatible_with_channel_map(&new_sink->volume, &cached_sink->channel_map) == FALSE) return FALSE; - if(pa_cvolume_equal(&new_sink->volume, &cached_sink->volume) == TRUE) - return FALSE; + pa_cvolume new_vol = construct_mono_volume(&new_sink->volume); - if((int)(pa_cvolume_get_balance(&new_sink->volume, &new_sink->channel_map) * 100) != (int)(pa_cvolume_get_balance(&cached_sink->volume, &cached_sink->channel_map) * 100)) + if(pa_cvolume_equal(&new_vol, &(cached_sink->volume)) == TRUE){ + g_debug("has_volume_changed: volumes appear to be equal? no change triggered!"); return FALSE; - + } + return TRUE; } @@ -487,11 +496,6 @@ static void pulse_server_info_callback(pa_context *c, const pa_server_info *info pa_operation_unref(operation); } -static void pulse_source_info_callback(pa_context *c, const pa_source_info *i, int eol, void *userdata) -{ - g_debug("pulse source info callback"); -} - static void subscribed_events_callback(pa_context *c, enum pa_subscription_event_type t, uint32_t index, void *userdata) { @@ -503,24 +507,24 @@ static void subscribed_events_callback(pa_context *c, enum pa_subscription_event if(index == DEFAULT_SINK_INDEX) sound_service_dbus_update_sink_availability(dbus_service, FALSE); - g_debug(" - removing sink of index %i from our sink hash - keep the cache tidy !", index); + g_debug("Subscribed_events_callback - removing sink of index %i from our sink hash - keep the cache tidy !", index); g_hash_table_remove(sink_hash, GINT_TO_POINTER(index)); if(index == DEFAULT_SINK_INDEX){ - g_debug("PA_SUBSCRIPTION_EVENT_SINK REMOVAL: default sink %i has been removed.", DEFAULT_SINK_INDEX); + g_debug("subscribed_events_callback - PA_SUBSCRIPTION_EVENT_SINK REMOVAL: default sink %i has been removed.", DEFAULT_SINK_INDEX); DEFAULT_SINK_INDEX = -1; determine_sink_availability(); } - g_debug(" - Now what is our default sink : %i", DEFAULT_SINK_INDEX); + g_debug("subscribed_events_callback - Now what is our default sink : %i", DEFAULT_SINK_INDEX); } else { - g_debug("PA_SUBSCRIPTION_EVENT_SINK: a generic sink event - will trigger an update"); + g_debug("subscribed_events_callback - PA_SUBSCRIPTION_EVENT_SINK: a generic sink event - will trigger an update"); pa_operation_unref(pa_context_get_sink_info_by_index(c, index, update_sink_info, userdata)); } break; case PA_SUBSCRIPTION_EVENT_SINK_INPUT: - g_debug("PA_SUBSCRIPTION_EVENT_SINK_INPUT event triggered!!"); + g_debug("subscribed_events_callback - PA_SUBSCRIPTION_EVENT_SINK_INPUT event triggered!!"); if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) { //handle the sink input remove event - not relevant for current design @@ -530,29 +534,12 @@ static void subscribed_events_callback(pa_context *c, enum pa_subscription_event pa_operation_unref(pa_context_get_sink_input_info(c, index, pulse_sink_input_info_callback, userdata)); } break; - case PA_SUBSCRIPTION_EVENT_SOURCE: - g_debug("PA_SUBSCRIPTION_EVENT_SOURCE of some description ???"); - - if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) - { - //TODO handle the remove event - } - else - { - pa_operation *o; - if (!(o = pa_context_get_source_info_by_index(c, index, pulse_source_info_callback, userdata))) { - g_warning("pa_context_get_source_info_by_index() failed"); - return; - } - pa_operation_unref(o); - } - break; case PA_SUBSCRIPTION_EVENT_SERVER: - g_debug("PA_SUBSCRIPTION_EVENT_SERVER change of some description ???"); + g_debug("subscribed_events_callback - PA_SUBSCRIPTION_EVENT_SERVER change of some description ???"); pa_operation *o; if(!(o = pa_context_get_server_info(c, pulse_server_info_callback, userdata))) { - g_warning("pa_context_get_server_info() failed"); + g_warning("subscribed_events_callback - pa_context_get_server_info() failed"); return; } pa_operation_unref(o); @@ -591,12 +578,8 @@ static void context_state_callback(pa_context *c, void *userdata) { if (!(o = pa_context_subscribe(c, (pa_subscription_mask_t) (PA_SUBSCRIPTION_MASK_SINK| - PA_SUBSCRIPTION_MASK_SOURCE| PA_SUBSCRIPTION_MASK_SINK_INPUT| - PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT| - PA_SUBSCRIPTION_MASK_CLIENT| - PA_SUBSCRIPTION_MASK_SERVER| - PA_SUBSCRIPTION_MASK_CARD), NULL, NULL))) { + PA_SUBSCRIPTION_MASK_SERVER), NULL, NULL))) { g_warning("pa_context_subscribe() failed"); return; } -- cgit v1.2.3 From 6bc7f6e56456c88bf4ce0d1f34c1d2c249b80471 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 26 Apr 2010 18:48:19 +0100 Subject: not the nicest of fixes but this filters further feedback loops between the slider and the service when there is a third party app involved --- src/indicator-sound.c | 72 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 96b151a..3cddb78 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -164,7 +164,7 @@ static void indicator_sound_init (IndicatorSound *self) initial_mute = FALSE; device_available = TRUE; slider_in_direct_use = FALSE; - exterior_vol_update = 0; + exterior_vol_update = -10; g_signal_connect(G_OBJECT(self->service), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_changed), self); return; @@ -237,7 +237,6 @@ slider_parent_changed (GtkWidget *widget, { gtk_widget_set_size_request (widget, 200, -1); g_debug("slider parent changed"); - //fetch_volume_percent_from_dbus(); } /** @@ -370,13 +369,13 @@ static void prepare_blocked_animation() temp_image = indicator_image_helper(blocked_name); GdkPixbuf* blocked_buf = gtk_image_get_pixbuf(temp_image); - int i; - if(mute_buf == NULL || blocked_buf == NULL){ - g_debug("Don bother with the animation, the theme aint got the goods"); + g_debug("Don bother with the animation, the theme aint got the goods !"); return; } + int i; + // sample 51 snapshots - range : 0-256 for(i = 0; i < 51; i++) { @@ -386,6 +385,9 @@ static void prepare_blocked_animation() 0, 0, 1, 1, GDK_INTERP_BILINEAR, MIN(255, i * 5)); blocked_animation_list = g_list_append(blocked_animation_list, gdk_pixbuf_copy(blocked_buf)); } + g_object_unref(temp_image); + g_object_unref(mute_buf); + g_object_unref(blocked_buf); } @@ -446,6 +448,35 @@ void determine_state_from_volume(gdouble volume_percent) } +static gboolean start_animation() +{ + blocked_iter = blocked_animation_list; + blocked_id = 0; + g_debug("exit from blocked hold start the animation\n"); + animation_id = g_timeout_add(50, fade_back_to_mute_image, NULL); + return FALSE; +} + +static gboolean fade_back_to_mute_image() +{ + if(blocked_iter != NULL) + { + g_debug("in animation 'loop'\n"); + gtk_image_set_from_pixbuf(speaker_image, blocked_iter->data); + blocked_iter = blocked_iter->next; + return TRUE; + } + else{ + animation_id = 0; +/* update_state(STATE_MUTED);*/ + g_debug("exit from animation\n"); + return FALSE; + } +} + +/** +DBus method handlers +**/ static void fetch_sink_availability_from_dbus() { GError * error = NULL; @@ -509,6 +540,9 @@ static void fetch_mute_value_from_dbus() g_debug("at the indicator start up and the MUTE returned from dbus method is %i", initial_mute); } +/** +DBus signal catchers +**/ static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gboolean block_value, gpointer userdata) { g_debug("signal caught - sink input while muted with value %i", block_value); @@ -519,30 +553,6 @@ static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gboolean blo } } -static gboolean start_animation() -{ - blocked_iter = blocked_animation_list; - blocked_id = 0; - g_debug("exit from blocked hold start the animation\n"); - animation_id = g_timeout_add(50, fade_back_to_mute_image, NULL); - return FALSE; -} - -static gboolean fade_back_to_mute_image() -{ - if(blocked_iter != NULL) - { - g_debug("in animation 'loop'\n"); - gtk_image_set_from_pixbuf(speaker_image, blocked_iter->data); - blocked_iter = blocked_iter->next; - return TRUE; - } - else{ - animation_id = 0; - g_debug("exit from animation\n"); - return FALSE; - } -} static void catch_signal_sink_volume_update(DBusGProxy *proxy, gdouble volume_percent, gpointer userdata) { @@ -592,6 +602,9 @@ static void catch_signal_sink_availability_update(DBusGProxy *proxy, gboolean av g_debug("signal caught - sink availability update with value: %i", available_value); } +/** +UI callbacks +**/ /** value_changed_event_cb: @@ -687,6 +700,7 @@ static gboolean key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer dat if(new_value != current_value && current_state != STATE_MUTED) { g_debug("Attempting to set the range from the key listener to %f", new_value); + exterior_vol_update = -10; gtk_range_set_value(range, new_value); } } -- cgit v1.2.3 From c4255ba79a9ec11c3697347a767b53e6722af070 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 26 Apr 2010 20:45:56 +0100 Subject: theme changing now handling for the mute blocking stage --- src/indicator-sound.c | 150 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 100 insertions(+), 50 deletions(-) diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 3cddb78..8867abd 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -89,6 +89,7 @@ static gboolean value_changed_event_cb(GtkRange *range, gpointer user_data); static gboolean key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data); static void slider_grabbed(GtkWidget *widget, gpointer user_data); static void slider_released(GtkWidget *widget, gpointer user_data); +static void style_changed_cb(GtkWidget *widget, gpointer user_data); // DBUS communication static DBusGProxy *sound_dbus_proxy = NULL; @@ -132,8 +133,10 @@ static GList * blocked_iter = NULL; static void prepare_blocked_animation(); static gboolean fade_back_to_mute_image(); static gboolean start_animation(); +static void reset_mute_blocking_animation(); +static void free_the_animation_list(); + -// Construction static void indicator_sound_class_init (IndicatorSoundClass *klass) { @@ -153,7 +156,8 @@ indicator_sound_class_init (IndicatorSoundClass *klass) return; } -static void indicator_sound_init (IndicatorSound *self) +static void +indicator_sound_init (IndicatorSound *self) { self->service = NULL; self->service = indicator_service_manager_new_version(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_VERSION); @@ -181,13 +185,20 @@ indicator_sound_dispose (GObject *object) } g_hash_table_destroy(volume_states); + free_the_animation_list(); + + G_OBJECT_CLASS (indicator_sound_parent_class)->dispose (object); + return; +} + +static void +free_the_animation_list() +{ if(blocked_animation_list != NULL){ g_list_foreach (blocked_animation_list, (GFunc)g_object_unref, NULL); g_list_free(blocked_animation_list); + blocked_animation_list = NULL; } - - G_OBJECT_CLASS (indicator_sound_parent_class)->dispose (object); - return; } static void @@ -243,7 +254,8 @@ slider_parent_changed (GtkWidget *widget, new_slider_item: Create a new dBusMenu Slider item. **/ -static gboolean new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +static gboolean +new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) { IndicatorObject *io = NULL; @@ -271,6 +283,8 @@ static gboolean new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * p g_signal_connect(slider, "value-changed", G_CALLBACK(value_changed_event_cb), newitem); g_signal_connect(volume_slider, "slider-grabbed", G_CALLBACK(slider_grabbed), NULL); g_signal_connect(volume_slider, "slider-released", G_CALLBACK(slider_released), NULL); + g_signal_connect(slider, "style-set", G_CALLBACK(style_changed_cb), NULL); + // Set images on the ido GtkWidget* primary_image = ido_scale_menu_item_get_primary_image((IdoScaleMenuItem*)volume_slider); @@ -341,7 +355,8 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u /* Prepare states Array. */ -void prepare_state_machine() +void +prepare_state_machine() { volume_states = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free); g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED), g_strdup("audio-volume-muted-panel")); @@ -358,7 +373,8 @@ prepare_blocked_animation: Prepares the array of images to be used in the blocked animation. Only called at startup. */ -static void prepare_blocked_animation() +static void +prepare_blocked_animation() { gchar* blocked_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT)); gchar* muted_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_MUTED)); @@ -391,28 +407,33 @@ static void prepare_blocked_animation() } -gint get_state() +gint +get_state() { return current_state; } -gchar* get_state_image_name(gint state) +gchar* +get_state_image_name(gint state) { return g_hash_table_lookup(volume_states, GINT_TO_POINTER(state)); } -void prepare_for_tests(IndicatorObject *io) +void +prepare_for_tests(IndicatorObject *io) { prepare_state_machine(); get_icon(io); } -void tidy_up_hash() +void +tidy_up_hash() { g_hash_table_destroy(volume_states); } -static void update_state(const gint state) +static void +update_state(const gint state) { /* g_debug("update state beginning - previous_state = %i", previous_state);*/ @@ -426,7 +447,8 @@ static void update_state(const gint state) } -void determine_state_from_volume(gdouble volume_percent) +void +determine_state_from_volume(gdouble volume_percent) { /* g_debug("determine_state_from_volume - previous_state = %i", previous_state);*/ if (device_available == FALSE) @@ -448,7 +470,8 @@ void determine_state_from_volume(gdouble volume_percent) } -static gboolean start_animation() +static gboolean +start_animation() { blocked_iter = blocked_animation_list; blocked_id = 0; @@ -457,7 +480,8 @@ static gboolean start_animation() return FALSE; } -static gboolean fade_back_to_mute_image() +static gboolean +fade_back_to_mute_image() { if(blocked_iter != NULL) { @@ -468,16 +492,16 @@ static gboolean fade_back_to_mute_image() } else{ animation_id = 0; -/* update_state(STATE_MUTED);*/ - g_debug("exit from animation\n"); + g_debug("exit from animation now\n"); return FALSE; } } -/** -DBus method handlers -**/ -static void fetch_sink_availability_from_dbus() +/*******************************************************************/ +//DBus method handlers +/*******************************************************************/ +static void +fetch_sink_availability_from_dbus() { GError * error = NULL; gboolean * available_input; @@ -503,7 +527,8 @@ static void fetch_sink_availability_from_dbus() } -static void fetch_volume_percent_from_dbus() +static void +fetch_volume_percent_from_dbus() { GError * error = NULL; gdouble *volume_percent_input; @@ -521,7 +546,8 @@ static void fetch_volume_percent_from_dbus() g_debug("at the indicator start up and the volume percent returned from dbus method is %f", initial_volume_percent); } -static void fetch_mute_value_from_dbus() +static void +fetch_mute_value_from_dbus() { GError * error = NULL; gboolean *mute_input; @@ -540,10 +566,11 @@ static void fetch_mute_value_from_dbus() g_debug("at the indicator start up and the MUTE returned from dbus method is %i", initial_mute); } -/** -DBus signal catchers -**/ -static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gboolean block_value, gpointer userdata) +/*******************************************************************/ +//DBus signal catchers +/*******************************************************************/ +static void +catch_signal_sink_input_while_muted(DBusGProxy * proxy, gboolean block_value, gpointer userdata) { g_debug("signal caught - sink input while muted with value %i", block_value); if (block_value == 1 && blocked_id == 0 && animation_id == 0 && blocked_animation_list != NULL) { @@ -554,7 +581,8 @@ static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gboolean blo } -static void catch_signal_sink_volume_update(DBusGProxy *proxy, gdouble volume_percent, gpointer userdata) +static void +catch_signal_sink_volume_update(DBusGProxy *proxy, gdouble volume_percent, gpointer userdata) { if (slider_in_direct_use == FALSE){ GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); @@ -569,7 +597,8 @@ static void catch_signal_sink_volume_update(DBusGProxy *proxy, gdouble volume_pe } } -static void catch_signal_sink_mute_update(DBusGProxy *proxy, gboolean mute_value, gpointer userdata) +static void +catch_signal_sink_mute_update(DBusGProxy *proxy, gboolean mute_value, gpointer userdata) { //We can be sure the service won't send a mute signal unless it has changed ! //UNMUTE's force a volume update therefore icon is updated appropriately => no need for unmute handling here. @@ -578,22 +607,29 @@ static void catch_signal_sink_mute_update(DBusGProxy *proxy, gboolean mute_value update_state(STATE_MUTED); } else{ - if(animation_id != 0){ - g_debug("about to remove the animation_id callback from the mainloop!!**"); - g_source_remove(animation_id); - animation_id = 0; - } - if(blocked_id != 0){ - g_debug("about to remove the blocked_id callback from the mainloop!!**"); - g_source_remove(blocked_id); - blocked_id = 0; - } + reset_mute_blocking_animation(); } g_debug("signal caught - sink mute update with mute value: %i", mute_value); gtk_widget_set_sensitive(volume_slider, !mute_value); } -static void catch_signal_sink_availability_update(DBusGProxy *proxy, gboolean available_value, gpointer userdata) +static void +reset_mute_blocking_animation() +{ + if(animation_id != 0){ + g_debug("about to remove the animation_id callback from the mainloop!!**"); + g_source_remove(animation_id); + animation_id = 0; + } + if(blocked_id != 0){ + g_debug("about to remove the blocked_id callback from the mainloop!!**"); + g_source_remove(blocked_id); + blocked_id = 0; + } +} + +static void +catch_signal_sink_availability_update(DBusGProxy *proxy, gboolean available_value, gpointer userdata) { device_available = available_value; if (device_available == FALSE){ @@ -602,15 +638,19 @@ static void catch_signal_sink_availability_update(DBusGProxy *proxy, gboolean av g_debug("signal caught - sink availability update with value: %i", available_value); } -/** -UI callbacks -**/ + + + +/*******************************************************************/ +//UI callbacks +/******************************************************************/ /** value_changed_event_cb: This callback will get triggered irregardless of whether its a user change or a programmatic change. **/ -static gboolean value_changed_event_cb(GtkRange *range, gpointer user_data) +static gboolean +value_changed_event_cb(GtkRange *range, gpointer user_data) { gdouble current_value = CLAMP(gtk_range_get_value(range), 0, 100); if(current_value == exterior_vol_update){ @@ -630,13 +670,15 @@ static gboolean value_changed_event_cb(GtkRange *range, gpointer user_data) } -static void slider_grabbed (GtkWidget *widget, gpointer user_data) +static void +slider_grabbed (GtkWidget *widget, gpointer user_data) { slider_in_direct_use = TRUE; g_debug ("!!!!!! grabbed\n"); } -static void slider_released (GtkWidget *widget, gpointer user_data) +static void +slider_released (GtkWidget *widget, gpointer user_data) { slider_in_direct_use = FALSE; g_debug ("!!!!!! released\n"); @@ -646,7 +688,8 @@ static void slider_released (GtkWidget *widget, gpointer user_data) /** key_press_cb: **/ -static gboolean key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) +static gboolean +key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) { gboolean digested = FALSE; @@ -707,6 +750,15 @@ static gboolean key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer dat return digested; } +static void +style_changed_cb(GtkWidget *widget, gpointer user_data) +{ + g_debug("Just caught a style change event"); + reset_mute_blocking_animation(); + update_state(current_state); + free_the_animation_list(); + prepare_blocked_animation(); +} static void scroll (IndicatorObject *io, gint delta, IndicatorScrollDirection direction) @@ -718,8 +770,6 @@ scroll (IndicatorObject *io, gint delta, IndicatorScrollDirection direction) GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (sound->slider)); gdouble value = gtk_range_get_value (GTK_RANGE (sound->slider)); - //g_debug("the scroll step size = %f", adj->step_increment); - if (direction == INDICATOR_OBJECT_SCROLL_UP){ value += adj->step_increment; } -- cgit v1.2.3 From 1bd0797b8597cb6657860d326483f0b6fc7957fc Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 27 Apr 2010 09:22:36 +0100 Subject: clarified the reset code --- src/indicator-sound.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 8867abd..03e1d7e 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -112,6 +112,7 @@ static const gint STATE_MEDIUM = 3; static const gint STATE_HIGH = 4; static const gint STATE_MUTED_WHILE_INPUT = 5; static const gint STATE_SINKS_NONE = 6; +static const gint OUT_OF_RANGE = -10; static GHashTable *volume_states = NULL; static GtkImage *speaker_image = NULL; @@ -168,7 +169,7 @@ indicator_sound_init (IndicatorSound *self) initial_mute = FALSE; device_available = TRUE; slider_in_direct_use = FALSE; - exterior_vol_update = -10; + exterior_vol_update = OUT_OF_RANGE; g_signal_connect(G_OBJECT(self->service), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_changed), self); return; @@ -285,7 +286,6 @@ new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuC g_signal_connect(volume_slider, "slider-released", G_CALLBACK(slider_released), NULL); g_signal_connect(slider, "style-set", G_CALLBACK(style_changed_cb), NULL); - // Set images on the ido GtkWidget* primary_image = ido_scale_menu_item_get_primary_image((IdoScaleMenuItem*)volume_slider); GIcon * primary_gicon = g_themed_icon_new_with_default_fallbacks(g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_ZERO))); @@ -743,7 +743,9 @@ key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) if(new_value != current_value && current_state != STATE_MUTED) { g_debug("Attempting to set the range from the key listener to %f", new_value); - exterior_vol_update = -10; + // In order to ensure that the exterior filtering does not catch this, reset the exterior_vol_update + // to ensure these updates. + exterior_vol_update = OUT_OF_RANGE; gtk_range_set_value(range, new_value); } } -- cgit v1.2.3 From 3002d85c7ceb0006e1603da173628bb050a56884 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 27 Apr 2010 11:33:38 +0100 Subject: 64bit tested and tweaked --- src/indicator-sound.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) mode change 100644 => 100755 src/indicator-sound.c diff --git a/src/indicator-sound.c b/src/indicator-sound.c old mode 100644 new mode 100755 index 03e1d7e..18f48d8 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -310,7 +310,6 @@ new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuC static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata) { - // TODO: This could be safer. if (connected) { if (sound_dbus_proxy == NULL) { GError * error = NULL; @@ -347,6 +346,7 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u } else { //TODO : will need to handle this scenario + // Not much can we do here really, if there is no dbus connection tis goosed. } return; @@ -401,9 +401,10 @@ prepare_blocked_animation() 0, 0, 1, 1, GDK_INTERP_BILINEAR, MIN(255, i * 5)); blocked_animation_list = g_list_append(blocked_animation_list, gdk_pixbuf_copy(blocked_buf)); } - g_object_unref(temp_image); - g_object_unref(mute_buf); - g_object_unref(blocked_buf); + g_object_ref_sink(mute_buf); + g_object_unref(mute_buf); + g_object_ref_sink(blocked_buf); + g_object_unref(blocked_buf); } @@ -756,6 +757,7 @@ static void style_changed_cb(GtkWidget *widget, gpointer user_data) { g_debug("Just caught a style change event"); + update_state(current_state); reset_mute_blocking_animation(); update_state(current_state); free_the_animation_list(); -- cgit v1.2.3