From 199a8f1931a33fc6c3bdd557918aba6ae0c72bae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Wed, 24 Feb 2021 11:09:42 +0100 Subject: [PATCH] Bind volume scale with player volume prop Now that player API itself is operating on a cubic scale (no value conversion required), the volume slider can be bind to the volume property. Thanks to that, player volume scale will correctly reflect Clapper volume set via external applications e.g. gnome-settings. --- src/controls.js | 41 ++++++++++++++++------------------------- src/widget.js | 23 ++++------------------- 2 files changed, 20 insertions(+), 44 deletions(-) diff --git a/src/controls.js b/src/controls.js index 3636f879..586d4bb2 100644 --- a/src/controls.js +++ b/src/controls.js @@ -24,7 +24,6 @@ class ClapperControls extends Gtk.Box can_focus: false, }); - this.currentVolume = 0; this.currentPosition = 0; this.currentDuration = 0; this.isPositionDragging = false; @@ -409,26 +408,6 @@ class ClapperControls extends Gtk.Box this.volumeButton.popoverBox.append(this.volumeScale); } - _updateVolumeButtonIcon(volume) - { - const icon = (volume <= 0) - ? 'muted' - : (volume <= 0.3) - ? 'low' - : (volume <= 0.7) - ? 'medium' - : (volume <= 1) - ? 'high' - : 'overamplified'; - - const iconName = `audio-volume-${icon}-symbolic`; - if(this.volumeButton.icon_name === iconName) - return; - - this.volumeButton.set_icon_name(iconName); - debug(`set volume icon: ${icon}`); - } - _setChapterVisible(isVisible) { const type = (isVisible) ? 'Show' : 'Hide'; @@ -567,9 +546,6 @@ class ClapperControls extends Gtk.Box _onVolumeScaleValueChanged(scale) { const volume = scale.get_value(); - const { player } = this.get_ancestor(Gtk.Grid); - - player.set_volume(volume); /* FIXME: All of below should be placed in 'volume-changed' * event once we move to message bus API */ @@ -585,7 +561,22 @@ class ClapperControls extends Gtk.Box scale.remove_css_class(cssClass); } - this._updateVolumeButtonIcon(volume); + const icon = (volume <= 0) + ? 'muted' + : (volume <= 0.3) + ? 'low' + : (volume <= 0.7) + ? 'medium' + : (volume <= 1) + ? 'high' + : 'overamplified'; + + const iconName = `audio-volume-${icon}-symbolic`; + if(this.volumeButton.icon_name === iconName) + return; + + this.volumeButton.icon_name = iconName; + debug(`set volume icon: ${icon}`); } _onPositionScaleDragging(scale) diff --git a/src/widget.js b/src/widget.js index b1d53dfe..ee5d6fb9 100644 --- a/src/widget.js +++ b/src/widget.js @@ -65,16 +65,16 @@ class ClapperWidget extends Gtk.Grid const playerWidget = this.player.widget; this.controls.elapsedButton.scrolledWindow.set_child(this.player.playlistWidget); + this.controls.speedAdjustment.bind_property( 'value', this.player, 'rate', GObject.BindingFlags.BIDIRECTIONAL ); - + this.controls.volumeAdjustment.bind_property( + 'value', this.player, 'volume', GObject.BindingFlags.BIDIRECTIONAL + ); this.player.connect('position-updated', this._onPlayerPositionUpdated.bind(this)); this.player.connect('duration-changed', this._onPlayerDurationChanged.bind(this)); - /* FIXME: re-enable once ported to new GstPlayer API with messages bus */ - //this.player.connect('volume-changed', this._onPlayerVolumeChanged.bind(this)); - this.overlay.set_child(playerWidget); this.overlay.add_overlay(this.revealerTop); this.overlay.add_overlay(this.revealerBottom); @@ -528,21 +528,6 @@ class ClapperWidget extends Gtk.Grid this.controls.positionScale.set_value(positionSeconds); } - _onPlayerVolumeChanged(player) - { - const volume = player.volume; - - /* FIXME: This check should not be needed, GstPlayer should not - * emit 'volume-changed' with the same values, but it does. */ - if(volume === this.controls.currentVolume) - return; - - /* Once above is fixed in GstPlayer, remove this var too */ - this.controls.currentVolume = volume; - - this.controls._updateVolumeButtonIcon(volume); - } - _onStateNotify(toplevel) { const isMaximized = Boolean(