[Xfce4-commits] <xfce4-mixer:master> Mute a track when the volume is set to 0% and unmute when set to a higher value
Guido Berhoerster
noreply at xfce.org
Thu Sep 27 16:46:12 CEST 2012
Updating branch refs/heads/master
to f543917aea0dd551490cf25806c4260d9740b288 (commit)
from e749d2a409a4228ac1f0a59c081f4d14b01b8297 (commit)
commit f543917aea0dd551490cf25806c4260d9740b288
Author: Guido Berhoerster <guido+xfce at berhoerster.name>
Date: Thu Sep 27 16:31:08 2012 +0200
Mute a track when the volume is set to 0% and unmute when set to a higher value
Mute a track automatically when the volume button reaches 0% and unmute it
again when above 0% (bug #8291).
Improve the volume calculations by using round() rather than truncating.
NEWS | 2 +
configure.ac.in | 6 ++++
panel-plugin/xfce-mixer-plugin.c | 6 +++-
panel-plugin/xfce-volume-button.c | 43 ++++++++++++++++++++---------
xfce4-mixer/xfce-mixer-track.c | 54 ++++++++++++++++++++++++++++++++----
5 files changed, 91 insertions(+), 20 deletions(-)
diff --git a/NEWS b/NEWS
index c4ccfac..80a8b8a 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,8 @@
- Avoid the deprecated GtkTooltips API and let XfceVolumeButton handle
tooltips.
- Indicate in the plugin tooltip whether the track is muted.
+- Mute a track when the volume is set to 0% and unmute when set to a higher
+ value (bug #8291).
4.8.0
diff --git a/configure.ac.in b/configure.ac.in
index 6a42c74..f391d31 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -84,6 +84,12 @@ dnl *** Check for i18n support ***
dnl ******************************
XDT_I18N([@LINGUAS@])
+dnl **********************
+dnl *** Check for libm ***
+dnl **********************
+AC_CHECK_HEADERS([math.h])
+AC_CHECK_LIB([m],[round])
+
dnl ***********************************
dnl *** Check for required packages ***
dnl ***********************************
diff --git a/panel-plugin/xfce-mixer-plugin.c b/panel-plugin/xfce-mixer-plugin.c
index 73fbef0..1dc6d97 100644
--- a/panel-plugin/xfce-mixer-plugin.c
+++ b/panel-plugin/xfce-mixer-plugin.c
@@ -23,6 +23,10 @@
#include <config.h>
#endif
+#ifdef HAVE_MATH_H
+#include <math.h>
+#endif
+
#include <gtk/gtk.h>
#include <gst/gst.h>
@@ -537,7 +541,7 @@ xfce_mixer_plugin_volume_changed (XfceMixerPlugin *mixer_plugin,
volume_range = mixer_plugin->track->max_volume - mixer_plugin->track->min_volume;
/* Determine new volume */
- new_volume = mixer_plugin->track->min_volume + (volume * volume_range);
+ new_volume = (gint) round (mixer_plugin->track->min_volume + (volume * volume_range));
/* Set all channel volumes to the new volume */
for (i = 0; i < mixer_plugin->track->num_channels; ++i)
diff --git a/panel-plugin/xfce-volume-button.c b/panel-plugin/xfce-volume-button.c
index e80c792..826d4be 100644
--- a/panel-plugin/xfce-volume-button.c
+++ b/panel-plugin/xfce-volume-button.c
@@ -23,6 +23,10 @@
#include <config.h>
#endif
+#ifdef HAVE_MATH_H
+#include <math.h>
+#endif
+
#include <gdk/gdk.h>
#include <gtk/gtk.h>
@@ -216,7 +220,7 @@ xfce_volume_button_class_init (XfceVolumeButtonClass *klass)
g_param_spec_boolean ("is-muted",
"is-muted",
"is-muted",
- FALSE,
+ TRUE,
G_PARAM_READABLE | G_PARAM_WRITABLE));
button_signals[VOLUME_CHANGED] = g_signal_new ("volume-changed",
@@ -240,15 +244,15 @@ xfce_volume_button_init (XfceVolumeButton *button)
button->is_configured = FALSE;
- /* By default we expect the button not to be muted */
- button->is_muted = FALSE;
-
/* Allocate array for preloaded icons */
button->pixbufs = g_new0 (GdkPixbuf*, G_N_ELEMENTS (icons)-1);
/* Create adjustment for the button (from 0.0 to 1.0 in 5% steps) */
button->adjustment = gtk_adjustment_new (0.0, 0.0, 1.0, 0.05, 0.05, 0.0);
+ /* Set to muted by default since the initial adjustment value is 0 */
+ button->is_muted = TRUE;
+
/* Create a new scaled image for the button icon */
button->image = xfce_panel_image_new ();
gtk_container_add (GTK_CONTAINER (button), button->image);
@@ -478,7 +482,8 @@ xfce_volume_button_scrolled (GtkWidget *widget,
GdkEventScroll *event,
XfceVolumeButton *button)
{
- gdouble value;
+ gdouble old_value;
+ gdouble new_value;
gdouble step_increment;
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
@@ -489,7 +494,7 @@ xfce_volume_button_scrolled (GtkWidget *widget,
return TRUE;
/* Get current adjustment value and the step increment size */
- g_object_get (G_OBJECT (button->adjustment), "value", &value, "step-increment", &step_increment, NULL);
+ g_object_get (G_OBJECT (button->adjustment), "value", &old_value, "step-increment", &step_increment, NULL);
/* Distinguish between scroll directions */
switch (event->direction)
@@ -497,20 +502,32 @@ xfce_volume_button_scrolled (GtkWidget *widget,
case GDK_SCROLL_UP:
case GDK_SCROLL_RIGHT:
/* Increase one step when scrolling up/right */
- gtk_adjustment_set_value (GTK_ADJUSTMENT (button->adjustment), value + step_increment);
+ gtk_adjustment_set_value (GTK_ADJUSTMENT (button->adjustment), old_value + step_increment);
break;
case GDK_SCROLL_DOWN:
case GDK_SCROLL_LEFT:
/* Decrease one step when scrolling down/left */
- gtk_adjustment_set_value (GTK_ADJUSTMENT (button->adjustment), value - step_increment);
+ gtk_adjustment_set_value (GTK_ADJUSTMENT (button->adjustment), old_value - step_increment);
break;
}
- /* Update the state of the button */
- xfce_volume_button_update (button);
+ new_value = gtk_adjustment_get_value (GTK_ADJUSTMENT (button->adjustment));
+ if (fabs (new_value - old_value) < VOLUME_EPSILON)
+ {
+ /* Mute when volume reaches 0%, unmute if volume is raised from 0% */
+ if (new_value < VOLUME_EPSILON && !button->is_muted)
+ xfce_volume_button_set_muted (button, TRUE);
+ else if (old_value < VOLUME_EPSILON && button->is_muted)
+ xfce_volume_button_set_muted (button, FALSE);
+ else
+ {
+ /* Update the state of the button */
+ xfce_volume_button_update (button);
+ }
- /* Notify listeners of the new volume */
- g_signal_emit_by_name (button, "volume-changed", gtk_adjustment_get_value (GTK_ADJUSTMENT (button->adjustment)));
+ /* Notify listeners of the new volume */
+ g_signal_emit_by_name (button, "volume-changed", new_value);
+ }
/* The scroll event has been handled, stop other handlers from being invoked */
return TRUE;
@@ -566,7 +583,7 @@ xfce_volume_button_update (XfceVolumeButton *button)
if (button->is_muted)
tip_text = g_strdup_printf (_("%s: muted"), button->track_label);
else
- tip_text = g_strdup_printf (_("%s: %i%%"), button->track_label, (gint) (value * 100));
+ tip_text = g_strdup_printf (_("%s: %i%%"), button->track_label, (gint) round (value * 100));
gtk_widget_set_tooltip_text (GTK_WIDGET (button), tip_text);
g_free (tip_text);
}
diff --git a/xfce4-mixer/xfce-mixer-track.c b/xfce4-mixer/xfce-mixer-track.c
index c984cb3..579f562 100644
--- a/xfce4-mixer/xfce-mixer-track.c
+++ b/xfce4-mixer/xfce-mixer-track.c
@@ -277,8 +277,11 @@ xfce_mixer_track_fader_changed (GtkRange *range,
XfceMixerTrack *track)
{
GList *iter;
- gint *volumes;
+ gint *old_volumes;
+ gint *new_volumes;
gint channel;
+ gint old_max_volume;
+ gint new_max_volume;
/* Locking mechanism: If locked, the volume change should be applied to all
* channels, but only one should deliver the change to GStreamer. */
@@ -295,8 +298,15 @@ xfce_mixer_track_fader_changed (GtkRange *range,
/* Otherwise, block the other faders */
locked = TRUE;
+ /* Get current volumes of the track */
+ old_volumes = g_new (gint, track->gst_track->num_channels);
+ gst_mixer_get_volume (GST_MIXER (track->card), track->gst_track, old_volumes);
+
+ /* Determine maximum value of all channels */
+ old_max_volume = xfce_mixer_get_max_volume (old_volumes, track->gst_track->num_channels);
+
/* Allocate array for the volumes to be sent to GStreamer */
- volumes = g_new (gint, track->gst_track->num_channels);
+ new_volumes = g_new (gint, track->gst_track->num_channels);
/* Collect volumes of all channels */
for (iter = track->channel_faders, channel = 0; iter != NULL; iter = g_list_next (iter), ++channel)
@@ -305,14 +315,46 @@ xfce_mixer_track_fader_changed (GtkRange *range,
if (G_LIKELY (track->gst_track->num_channels >= 2 && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (track->lock_button))))
gtk_range_set_value (GTK_RANGE (iter->data), gtk_range_get_value (range));
- volumes[channel] = (gint) gtk_range_get_value (GTK_RANGE (iter->data));
+ new_volumes[channel] = (gint) gtk_range_get_value (GTK_RANGE (iter->data));
}
/* Deliver the volume update to GStreamer */
- gst_mixer_set_volume (GST_MIXER (track->card), track->gst_track, volumes);
+ gst_mixer_set_volume (GST_MIXER (track->card), track->gst_track, new_volumes);
- /* Free volume array */
- g_free (volumes);
+ /* Determine new maximum value of all channels */
+ new_max_volume = xfce_mixer_get_max_volume (new_volumes, track->gst_track->num_channels);
+
+ /* Mute when volume reaches the minimum, unmute if volume is raised from the minimum */
+ if (old_max_volume > track->gst_track->min_volume && new_max_volume == track->gst_track->min_volume)
+ {
+ if (xfce_mixer_track_type_new (track->gst_track) != XFCE_MIXER_TRACK_TYPE_CAPTURE)
+ {
+ gst_mixer_set_mute (GST_MIXER (track->card), track->gst_track, TRUE);
+ xfce_mixer_track_update_mute (track);
+ }
+ else
+ {
+ gst_mixer_set_record (GST_MIXER (track->card), track->gst_track, TRUE);
+ xfce_mixer_track_update_record (track);
+ }
+ }
+ else if (old_max_volume == track->gst_track->min_volume && new_max_volume > track->gst_track->min_volume)
+ {
+ if (xfce_mixer_track_type_new (track->gst_track) != XFCE_MIXER_TRACK_TYPE_CAPTURE)
+ {
+ gst_mixer_set_mute (GST_MIXER (track->card), track->gst_track, FALSE);
+ xfce_mixer_track_update_mute (track);
+ }
+ else
+ {
+ gst_mixer_set_record (GST_MIXER (track->card), track->gst_track, FALSE);
+ xfce_mixer_track_update_record (track);
+ }
+ }
+
+ /* Free volume arrays */
+ g_free (old_volumes);
+ g_free (new_volumes);
/* We're done, unlock this function */
locked = FALSE;
More information about the Xfce4-commits
mailing list