sound: Fix volume sliders regression

GVC added additional checks that break where we were using a NULL value instead
of a GvcMixerControl. Solution is to pass this object where appropriate.

(gnome-control-center:833): Gvc-CRITICAL **: 11:09:33.818: gvc_mixer_control_get_vol_max_norm: assertion 'GVC_IS_MIXER_CONTROL (control)' failed

Fixes #636
This commit is contained in:
Robert Ancell 2019-08-13 11:11:05 +12:00 committed by Robert Ancell
parent 299647f970
commit 9d612ff1c7
5 changed files with 70 additions and 28 deletions

View file

@ -260,6 +260,9 @@ cc_sound_panel_init (CcSoundPanel *self)
gvc_mixer_control_open (self->mixer_control);
cc_stream_list_box_set_mixer_control (self->stream_list_box, self->mixer_control);
cc_volume_slider_set_mixer_control (self->input_volume_slider, self->mixer_control);
cc_volume_slider_set_mixer_control (self->output_volume_slider, self->mixer_control);
cc_subwoofer_slider_set_mixer_control (self->subwoofer_slider, self->mixer_control);
cc_device_combo_box_set_mixer_control (self->input_device_combo_box, self->mixer_control, FALSE);
cc_device_combo_box_set_mixer_control (self->output_device_combo_box, self->mixer_control, TRUE);
}

View file

@ -91,13 +91,20 @@ cc_subwoofer_slider_class_init (CcSubwooferSliderClass *klass)
void
cc_subwoofer_slider_init (CcSubwooferSlider *self)
{
gdouble vol_max_norm;
g_resources_register (cc_sound_get_resource ());
gtk_widget_init_template (GTK_WIDGET (self));
}
vol_max_norm = gvc_mixer_control_get_vol_max_norm (NULL);
void
cc_subwoofer_slider_set_mixer_control (CcSubwooferSlider *self,
GvcMixerControl *mixer_control)
{
gdouble vol_max_norm;
g_return_if_fail (CC_IS_SUBWOOFER_SLIDER (self));
vol_max_norm = gvc_mixer_control_get_vol_max_norm (mixer_control);
gtk_adjustment_set_upper (self->adjustment, vol_max_norm);
gtk_adjustment_set_page_increment (self->adjustment, vol_max_norm / 100.0);
}

View file

@ -21,13 +21,17 @@
#include <gtk/gtk.h>
#include <pulse/pulseaudio.h>
#include <gvc-channel-map.h>
#include <gvc-mixer-control.h>
G_BEGIN_DECLS
#define CC_TYPE_SUBWOOFER_SLIDER (cc_subwoofer_slider_get_type ())
G_DECLARE_FINAL_TYPE (CcSubwooferSlider, cc_subwoofer_slider, CC, SUBWOOFER_SLIDER, GtkBox)
void cc_subwoofer_slider_set_channel_map (CcSubwooferSlider *slider,
GvcChannelMap *channel_map);
void cc_subwoofer_slider_set_mixer_control (CcSubwooferSlider *slider,
GvcMixerControl *mixer_control);
void cc_subwoofer_slider_set_channel_map (CcSubwooferSlider *slider,
GvcChannelMap *channel_map);
G_END_DECLS

View file

@ -34,6 +34,8 @@ struct _CcVolumeSlider
GtkAdjustment *volume_adjustment;
GtkScale *volume_scale;
gboolean is_amplified;
GvcMixerControl *mixer_control;
GvcMixerStream *stream;
guint notify_volume_handler_id;
guint notify_is_muted_handler_id;
@ -41,6 +43,32 @@ struct _CcVolumeSlider
G_DEFINE_TYPE (CcVolumeSlider, cc_volume_slider, GTK_TYPE_BOX)
static void
update_ranges (CcVolumeSlider *self)
{
gdouble vol_max_norm;
if (self->mixer_control == NULL)
return;
vol_max_norm = gvc_mixer_control_get_vol_max_norm (self->mixer_control);
gtk_scale_clear_marks (self->volume_scale);
if (self->is_amplified)
{
gtk_adjustment_set_upper (self->volume_adjustment, gvc_mixer_control_get_vol_max_amplified (self->mixer_control));
gtk_scale_add_mark (self->volume_scale,
vol_max_norm,
GTK_POS_BOTTOM,
C_("volume", "100%"));
}
else
{
gtk_adjustment_set_upper (self->volume_adjustment, vol_max_norm);
}
gtk_adjustment_set_page_increment (self->volume_adjustment, vol_max_norm / 100.0);
}
static void
volume_changed_cb (CcVolumeSlider *self)
{
@ -94,6 +122,7 @@ cc_volume_slider_dispose (GObject *object)
{
CcVolumeSlider *self = CC_VOLUME_SLIDER (object);
g_clear_object (&self->mixer_control);
g_clear_object (&self->stream);
G_OBJECT_CLASS (cc_volume_slider_parent_class)->dispose (object);
@ -121,15 +150,20 @@ cc_volume_slider_class_init (CcVolumeSliderClass *klass)
void
cc_volume_slider_init (CcVolumeSlider *self)
{
gdouble vol_max_norm;
g_resources_register (cc_sound_get_resource ());
gtk_widget_init_template (GTK_WIDGET (self));
}
vol_max_norm = gvc_mixer_control_get_vol_max_norm (NULL);
gtk_adjustment_set_upper (self->volume_adjustment, vol_max_norm);
gtk_adjustment_set_page_increment (self->volume_adjustment, vol_max_norm / 100.0);
void
cc_volume_slider_set_mixer_control (CcVolumeSlider *self,
GvcMixerControl *mixer_control)
{
g_return_if_fail (CC_IS_VOLUME_SLIDER (self));
g_set_object (&self->mixer_control, mixer_control);
update_ranges (self);
}
void
@ -190,17 +224,7 @@ cc_volume_slider_set_is_amplified (CcVolumeSlider *self,
{
g_return_if_fail (CC_IS_VOLUME_SLIDER (self));
gtk_scale_clear_marks (self->volume_scale);
if (is_amplified)
{
gtk_adjustment_set_upper (self->volume_adjustment, gvc_mixer_control_get_vol_max_amplified (NULL));
gtk_scale_add_mark (self->volume_scale,
gvc_mixer_control_get_vol_max_norm (NULL),
GTK_POS_BOTTOM,
C_("volume", "100%"));
}
else
{
gtk_adjustment_set_upper (self->volume_adjustment, gvc_mixer_control_get_vol_max_norm (NULL));
}
self->is_amplified = is_amplified;
update_ranges (self);
}

View file

@ -20,6 +20,7 @@
#include <gtk/gtk.h>
#include <pulse/pulseaudio.h>
#include <gvc-mixer-control.h>
#include <gvc-mixer-stream.h>
#include "cc-sound-enums.h"
@ -29,11 +30,14 @@ G_BEGIN_DECLS
#define CC_TYPE_VOLUME_SLIDER (cc_volume_slider_get_type ())
G_DECLARE_FINAL_TYPE (CcVolumeSlider, cc_volume_slider, CC, VOLUME_SLIDER, GtkBox)
void cc_volume_slider_set_stream (CcVolumeSlider *slider,
GvcMixerStream *stream,
CcStreamType type);
void cc_volume_slider_set_mixer_control (CcVolumeSlider *slider,
GvcMixerControl *mixer_control);
void cc_volume_slider_set_is_amplified (CcVolumeSlider *slider,
gboolean is_amplified);
void cc_volume_slider_set_stream (CcVolumeSlider *slider,
GvcMixerStream *stream,
CcStreamType type);
void cc_volume_slider_set_is_amplified (CcVolumeSlider *slider,
gboolean is_amplified);
G_END_DECLS