diff --git a/lib/gst/clapper/gstclapper.c b/lib/gst/clapper/gstclapper.c index 6e13c755..0e44f71b 100644 --- a/lib/gst/clapper/gstclapper.c +++ b/lib/gst/clapper/gstclapper.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -331,7 +332,7 @@ gst_clapper_class_init (GstClapperClass * klass) param_specs[PROP_VOLUME] = g_param_spec_double ("volume", "Volume", "Volume", - 0, 10.0, DEFAULT_VOLUME, G_PARAM_READWRITE | + 0, 1.5, DEFAULT_VOLUME, G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); param_specs[PROP_MUTE] = @@ -656,10 +657,22 @@ gst_clapper_set_property (GObject * object, guint prop_id, gst_clapper_set_suburi_internal, self, NULL); break; } - case PROP_VOLUME: - GST_DEBUG_OBJECT (self, "Set volume=%lf", g_value_get_double (value)); - g_object_set_property (G_OBJECT (self->playbin), "volume", value); + case PROP_VOLUME: { + GValue volume_linear = G_VALUE_INIT; + gdouble volume = g_value_get_double (value); + + GST_DEBUG_OBJECT (self, "Set volume=%lf", volume); + volume = gst_stream_volume_convert_volume ( + GST_STREAM_VOLUME_FORMAT_CUBIC, GST_STREAM_VOLUME_FORMAT_LINEAR, volume); + GST_DEBUG_OBJECT (self, "Converted linear volume=%lf", volume); + + g_value_init (&volume_linear, G_TYPE_DOUBLE); + g_value_set_double (&volume_linear, volume); + g_object_set_property (G_OBJECT (self->playbin), "volume", &volume_linear); + + g_value_unset (&volume_linear); break; + } case PROP_RATE: g_mutex_lock (&self->lock); self->rate = g_value_get_double (value); @@ -757,11 +770,17 @@ gst_clapper_get_property (GObject * object, guint prop_id, g_value_take_object (value, subtitle_info); break; } - case PROP_VOLUME: + case PROP_VOLUME: { + gdouble volume; + g_object_get_property (G_OBJECT (self->playbin), "volume", value); - GST_TRACE_OBJECT (self, "Returning volume=%lf", - g_value_get_double (value)); + volume = g_value_get_double (value); + volume = gst_stream_volume_convert_volume ( + GST_STREAM_VOLUME_FORMAT_LINEAR, GST_STREAM_VOLUME_FORMAT_CUBIC, volume); + g_value_set_double (value, volume); + GST_TRACE_OBJECT (self, "Returning volume=%lf", volume); break; + } case PROP_RATE: g_mutex_lock (&self->lock); g_value_set_double (value, self->rate); diff --git a/src/controls.js b/src/controls.js index 43d76ade..3636f879 100644 --- a/src/controls.js +++ b/src/controls.js @@ -489,7 +489,7 @@ class ClapperControls extends Gtk.Box const initialVolume = (settings.get_string('volume-initial') === 'custom') ? settings.get_int('volume-value') / 100 - : Misc.getCubicValue(settings.get_double('volume-last')); + : settings.get_double('volume-last'); this.volumeScale.set_value(initialVolume); } @@ -567,10 +567,9 @@ class ClapperControls extends Gtk.Box _onVolumeScaleValueChanged(scale) { const volume = scale.get_value(); - const linearVolume = Misc.getLinearValue(volume); const { player } = this.get_ancestor(Gtk.Grid); - player.set_volume(linearVolume); + player.set_volume(volume); /* FIXME: All of below should be placed in 'volume-changed' * event once we move to message bus API */ diff --git a/src/misc.js b/src/misc.js index 8bc98aed..695b4380 100644 --- a/src/misc.js +++ b/src/misc.js @@ -95,21 +95,3 @@ function getFormattedTime(time, showHours) const parsed = (hours) ? `${hours}:` : ''; return parsed + `${minutes}:${seconds}`; } - -function getCubicValue(linearVal) -{ - return GstAudio.StreamVolume.convert_volume( - GstAudio.StreamVolumeFormat.LINEAR, - GstAudio.StreamVolumeFormat.CUBIC, - linearVal - ); -} - -function getLinearValue(cubicVal) -{ - return GstAudio.StreamVolume.convert_volume( - GstAudio.StreamVolumeFormat.CUBIC, - GstAudio.StreamVolumeFormat.LINEAR, - cubicVal - ); -} diff --git a/src/player.js b/src/player.js index 66856a81..6e9dc054 100644 --- a/src/player.js +++ b/src/player.js @@ -24,8 +24,6 @@ class ClapperPlayer extends PlayerBase this.keyPressCount = 0; - this._maxVolume = Misc.getLinearValue(Misc.maxVolume); - const keyController = new Gtk.EventControllerKey(); keyController.connect('key-pressed', this._onWidgetKeyPressed.bind(this)); keyController.connect('key-released', this._onWidgetKeyReleased.bind(this)); @@ -180,17 +178,6 @@ class ClapperPlayer extends PlayerBase this.seek_seconds(seconds); } - set_volume(volume) - { - if(volume < 0) - volume = 0; - else if(volume > this._maxVolume) - volume = this._maxVolume; - - super.set_volume(volume); - debug(`set player volume: ${volume}`); - } - adjust_position(isIncrease) { this.seek_done = false; @@ -316,7 +303,9 @@ class ClapperPlayer extends PlayerBase } settings.set_string('resume-database', JSON.stringify([resumeInfo])); } - settings.set_double('volume-last', this.volume); + const volume = this.volume; + debug(`saving last volume: ${volume}`); + settings.set_double('volume-last', volume); clapperWidget.controls._onCloseRequest(); } diff --git a/src/widget.js b/src/widget.js index 950d9f81..2571857f 100644 --- a/src/widget.js +++ b/src/widget.js @@ -530,7 +530,7 @@ class ClapperWidget extends Gtk.Grid _onPlayerVolumeChanged(player) { - const volume = player.get_volume(); + const volume = player.volume; /* FIXME: This check should not be needed, GstPlayer should not * emit 'volume-changed' with the same values, but it does. */ @@ -540,8 +540,7 @@ class ClapperWidget extends Gtk.Grid /* Once above is fixed in GstPlayer, remove this var too */ this.controls.currentVolume = volume; - const cubicVolume = Misc.getCubicValue(volume); - this.controls._updateVolumeButtonIcon(cubicVolume); + this.controls._updateVolumeButtonIcon(volume); } _onStateNotify(toplevel)