From 7ccd6ad4241e2eeb1469e1fe6180d1c3111e857e Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Fri, 20 Nov 2020 21:19:23 +0100 Subject: [PATCH] Add audio and subtitle offset settings to prefs --- clapper_src/dialogs.js | 13 +++++++++++ clapper_src/playerBase.js | 14 ++++++++++++ clapper_src/prefs.js | 24 ++++++++++++++++++++ clapper_src/prefsBase.js | 11 +++++---- data/com.github.rafostar.Clapper.gschema.xml | 12 ++++++++++ 5 files changed, 70 insertions(+), 4 deletions(-) diff --git a/clapper_src/dialogs.js b/clapper_src/dialogs.js index 80144bfc..c22d7c2c 100644 --- a/clapper_src/dialogs.js +++ b/clapper_src/dialogs.js @@ -158,6 +158,19 @@ class ClapperPrefsDialog extends Gtk.Dialog } ] }, + { + title: 'Playback', + pages: [ + { + title: 'Audio', + widget: Prefs.AudioPage, + }, + { + title: 'Subtitles', + widget: Prefs.SubtitlesPage, + } + ] + }, { title: 'Advanced', pages: [ diff --git a/clapper_src/playerBase.js b/clapper_src/playerBase.js index 2d4aec3f..47b4830f 100644 --- a/clapper_src/playerBase.js +++ b/clapper_src/playerBase.js @@ -82,6 +82,8 @@ class ClapperPlayerBase extends GstPlayer.Player { let settingsToSet = [ 'seeking-mode', + 'audio-offset', + 'subtitle-offset', ]; for(let key of settingsToSet) @@ -176,6 +178,8 @@ class ClapperPlayerBase extends GstPlayer.Player _onSettingsKeyChanged(settings, key) { + let value; + switch(key) { case 'seeking-mode': let isSeekMode = (typeof this.set_seek_mode !== 'undefined'); @@ -219,6 +223,16 @@ class ClapperPlayerBase extends GstPlayer.Player root[action + '_css_class'](cssClass); } break; + case 'audio-offset': + value = Math.round(settings.get_double(key) * -1000000); + this.set_audio_video_offset(value); + debug(`set audio-video offset: ${value}`); + break; + case 'subtitle-offset': + value = Math.round(settings.get_double(key) * -1000000); + this.set_subtitle_video_offset(value); + debug(`set subtitle-video offset: ${value}`); + break; default: break; } diff --git a/clapper_src/prefs.js b/clapper_src/prefs.js index b2865a4d..84ee475a 100644 --- a/clapper_src/prefs.js +++ b/clapper_src/prefs.js @@ -56,6 +56,30 @@ class ClapperBehaviourPage extends PrefsBase.Grid } }); +var AudioPage = GObject.registerClass( +class ClapperAudioPage extends PrefsBase.Grid +{ + _init() + { + super._init(); + + this.addTitle('Synchronization'); + this.addSpinButton('Offset (milliseconds)', -1000, 1000, 'audio-offset', 25); + } +}); + +var SubtitlesPage = GObject.registerClass( +class ClapperSubtitlesPage extends PrefsBase.Grid +{ + _init() + { + super._init(); + + this.addTitle('Synchronization'); + this.addSpinButton('Offset (milliseconds)', -5000, 5000, 'subtitle-offset', 25); + } +}); + var GStreamerPage = GObject.registerClass( class ClapperGStreamerPage extends PrefsBase.Grid { diff --git a/clapper_src/prefsBase.js b/clapper_src/prefsBase.js index 4bbc4b8b..5fac2c07 100644 --- a/clapper_src/prefsBase.js +++ b/clapper_src/prefsBase.js @@ -112,10 +112,10 @@ class ClapperPrefsGrid extends Gtk.Grid return this.addToGrid(label, widget); } - addSpinButton(text, min, max, setting) + addSpinButton(text, min, max, setting, precision) { let label = this.getLabel(text + ':'); - let widget = this.getSpinButton(min, max, setting); + let widget = this.getSpinButton(min, max, setting, precision); return this.addToGrid(label, widget); } @@ -162,11 +162,14 @@ class ClapperPrefsGrid extends Gtk.Grid return comboBox; } - getSpinButton(min, max, setting) + getSpinButton(min, max, setting, precision) { + precision = precision || 1; + let spinButton = new Gtk.SpinButton(this.widgetDefaults); spinButton.set_range(min, max); - spinButton.set_increments(1, 2); + spinButton.set_digits(precision % 1 === 0 ? 0 : 3); + spinButton.set_increments(precision, 1); settings.bind(setting, spinButton, 'value', this.flag); return spinButton; diff --git a/data/com.github.rafostar.Clapper.gschema.xml b/data/com.github.rafostar.Clapper.gschema.xml index 5deace13..74b449ab 100644 --- a/data/com.github.rafostar.Clapper.gschema.xml +++ b/data/com.github.rafostar.Clapper.gschema.xml @@ -33,6 +33,18 @@ Unit to use with seeking value + + + 0 + Offset time for audio tracks relative to video (milliseconds) + + + + + 0 + Offset time for subtitle tracks relative to video (milliseconds) + + true