aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorConor Curran <conor.curran@canonical.com>2010-04-22 18:31:48 +0100
committerConor Curran <conor.curran@canonical.com>2010-04-22 18:31:48 +0100
commit632922b21c8b6d0d313bdd2711b4865b876ad1e7 (patch)
tree45db4ef77bbc56351af4fa94b4163dd76b50bcfa /src
parent132bf8d107161102b63bf254056624bc00b8d01f (diff)
parent5b74cf4b47b34fc53b89cc98fab413c603e2c80a (diff)
downloadayatana-indicator-sound-632922b21c8b6d0d313bdd2711b4865b876ad1e7.tar.gz
ayatana-indicator-sound-632922b21c8b6d0d313bdd2711b4865b876ad1e7.tar.bz2
ayatana-indicator-sound-632922b21c8b6d0d313bdd2711b4865b876ad1e7.zip
Panning is now honoured at all times plus version bumped for new 0.2.3 release
Diffstat (limited to 'src')
-rw-r--r--src/indicator-sound.c12
-rw-r--r--src/pulse-manager.c72
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");