From 994491d687c55e13bdce81d2a50887ee5251865e Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Tue, 19 Jan 2021 16:20:22 +0100 Subject: [PATCH] Add playback speed control Adjustable playback speed control in the form of a slider with a range from 0.01x to 2x. Closes #33 --- clapper_src/controls.js | 37 ++++++++++++++++++++++++++++++------- clapper_src/player.js | 5 +++++ clapper_src/widget.js | 3 +++ 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/clapper_src/controls.js b/clapper_src/controls.js index e4362290..6c1fc072 100644 --- a/clapper_src/controls.js +++ b/clapper_src/controls.js @@ -40,13 +40,7 @@ class ClapperControls extends Gtk.Box this.chapterHideId = null; this._addTogglePlayButton(); - - const elapsedRevealer = new Revealers.ButtonsRevealer('SLIDE_RIGHT'); - this.elapsedButton = this.addElapsedPopoverButton('00:00/00:00', elapsedRevealer); - elapsedRevealer.set_reveal_child(true); - this.revealersArr.push(elapsedRevealer); - this.append(elapsedRevealer); - + this._addElapsedButton(); this._addPositionScale(); const revealTracksButton = new Buttons.IconToggleButton( @@ -318,6 +312,35 @@ class ClapperControls extends Gtk.Box this.addButton(this.togglePlayButton); } + _addElapsedButton() + { + const elapsedRevealer = new Revealers.ButtonsRevealer('SLIDE_RIGHT'); + this.elapsedButton = this.addElapsedPopoverButton('00:00/00:00', elapsedRevealer); + elapsedRevealer.set_reveal_child(true); + this.revealersArr.push(elapsedRevealer); + + const speedScale = new Gtk.Scale({ + orientation: Gtk.Orientation.HORIZONTAL, + value_pos: Gtk.PositionType.BOTTOM, + draw_value: false, + round_digits: 2, + hexpand: true, + valign: Gtk.Align.CENTER, + }); + + this.speedAdjustment = speedScale.get_adjustment(); + this.speedAdjustment.set_lower(0.01); + this.speedAdjustment.set_upper(2); + this.speedAdjustment.set_value(1); + + speedScale.add_mark(0.25, Gtk.PositionType.BOTTOM, '0.25x'); + speedScale.add_mark(1, Gtk.PositionType.BOTTOM, 'normal'); + speedScale.add_mark(2, Gtk.PositionType.BOTTOM, '2x'); + + this.elapsedButton.popoverBox.append(speedScale); + this.append(elapsedRevealer); + } + _addPositionScale() { this.positionScale = new Gtk.Scale({ diff --git a/clapper_src/player.js b/clapper_src/player.js index 58895181..e0af0fe4 100644 --- a/clapper_src/player.js +++ b/clapper_src/player.js @@ -78,6 +78,11 @@ class ClapperPlayer extends PlayerBase set_uri(uri) { + /* FIXME: Player does not notify about + * rate change after file load */ + if(this.rate !== 1) + this.set_rate(1); + if(Gst.Uri.get_protocol(uri) !== 'file') return super.set_uri(uri); diff --git a/clapper_src/widget.js b/clapper_src/widget.js index 51633324..c0dfd8e2 100644 --- a/clapper_src/widget.js +++ b/clapper_src/widget.js @@ -46,6 +46,9 @@ class ClapperWidget extends Gtk.Grid this.player = new Player(); this.controls.elapsedButton.scrolledWindow.set_child(this.player.playlistWidget); + this.controls.speedAdjustment.bind_property( + 'value', this.player, 'rate', GObject.BindingFlags.BIDIRECTIONAL + ); this.player.connect('position-updated', this._onPlayerPositionUpdated.bind(this)); this.player.connect('duration-changed', this._onPlayerDurationChanged.bind(this));