Add audio and subtitle offset settings to prefs

This commit is contained in:
Rafostar
2020-11-20 21:19:23 +01:00
parent ac27c364f3
commit 7ccd6ad424
5 changed files with 70 additions and 4 deletions

View File

@@ -158,6 +158,19 @@ class ClapperPrefsDialog extends Gtk.Dialog
} }
] ]
}, },
{
title: 'Playback',
pages: [
{
title: 'Audio',
widget: Prefs.AudioPage,
},
{
title: 'Subtitles',
widget: Prefs.SubtitlesPage,
}
]
},
{ {
title: 'Advanced', title: 'Advanced',
pages: [ pages: [

View File

@@ -82,6 +82,8 @@ class ClapperPlayerBase extends GstPlayer.Player
{ {
let settingsToSet = [ let settingsToSet = [
'seeking-mode', 'seeking-mode',
'audio-offset',
'subtitle-offset',
]; ];
for(let key of settingsToSet) for(let key of settingsToSet)
@@ -176,6 +178,8 @@ class ClapperPlayerBase extends GstPlayer.Player
_onSettingsKeyChanged(settings, key) _onSettingsKeyChanged(settings, key)
{ {
let value;
switch(key) { switch(key) {
case 'seeking-mode': case 'seeking-mode':
let isSeekMode = (typeof this.set_seek_mode !== 'undefined'); let isSeekMode = (typeof this.set_seek_mode !== 'undefined');
@@ -219,6 +223,16 @@ class ClapperPlayerBase extends GstPlayer.Player
root[action + '_css_class'](cssClass); root[action + '_css_class'](cssClass);
} }
break; 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: default:
break; break;
} }

View File

@@ -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( var GStreamerPage = GObject.registerClass(
class ClapperGStreamerPage extends PrefsBase.Grid class ClapperGStreamerPage extends PrefsBase.Grid
{ {

View File

@@ -112,10 +112,10 @@ class ClapperPrefsGrid extends Gtk.Grid
return this.addToGrid(label, widget); return this.addToGrid(label, widget);
} }
addSpinButton(text, min, max, setting) addSpinButton(text, min, max, setting, precision)
{ {
let label = this.getLabel(text + ':'); 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); return this.addToGrid(label, widget);
} }
@@ -162,11 +162,14 @@ class ClapperPrefsGrid extends Gtk.Grid
return comboBox; return comboBox;
} }
getSpinButton(min, max, setting) getSpinButton(min, max, setting, precision)
{ {
precision = precision || 1;
let spinButton = new Gtk.SpinButton(this.widgetDefaults); let spinButton = new Gtk.SpinButton(this.widgetDefaults);
spinButton.set_range(min, max); 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); settings.bind(setting, spinButton, 'value', this.flag);
return spinButton; return spinButton;

View File

@@ -33,6 +33,18 @@
<summary>Unit to use with seeking value</summary> <summary>Unit to use with seeking value</summary>
</key> </key>
<!-- Audio -->
<key name="audio-offset" type="d">
<default>0</default>
<summary>Offset time for audio tracks relative to video (milliseconds)</summary>
</key>
<!-- Subtitles -->
<key name="subtitle-offset" type="d">
<default>0</default>
<summary>Offset time for subtitle tracks relative to video (milliseconds)</summary>
</key>
<!-- Tweaks --> <!-- Tweaks -->
<key name="render-shadows" type="b"> <key name="render-shadows" type="b">
<default>true</default> <default>true</default>