[vlc-devel] [PATCH 13/14] Updated QT Synchronization GUI

Roland Bewick roland.bewick at gmail.com
Sat May 11 08:32:17 CEST 2019


Set secondary subtitle synchronization
---
 modules/gui/qt/components/extended_panels.cpp     | 44 ++++++++++++++++++-----
 modules/gui/qt/components/extended_panels.hpp     |  2 ++
 modules/gui/qt/components/player_controller.cpp   | 12 ++++++-
 modules/gui/qt/components/player_controller.hpp   |  4 +++
 modules/gui/qt/components/player_controller_p.hpp |  1 +
 5 files changed, 53 insertions(+), 10 deletions(-)

diff --git a/modules/gui/qt/components/extended_panels.cpp b/modules/gui/qt/components/extended_panels.cpp
index 358fbc2479..63166a8de1 100644
--- a/modules/gui/qt/components/extended_panels.cpp
+++ b/modules/gui/qt/components/extended_panels.cpp
@@ -1374,16 +1374,25 @@ SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent )
     subsBox = new QGroupBox( qtr( "Subtitles/Video" ) );
     QGridLayout *subsLayout = new QGridLayout( subsBox );
 
-    QLabel *subsLabel = new QLabel;
-    subsLabel->setText( qtr( "Subtitle track synchronization:" ) );
-    subsLayout->addWidget( subsLabel, 0, 0, 1, 1 );
+    QGroupBox *subsTrackSyncBox = new QGroupBox( qtr( "Subtitle track synchronization" ) );
+    QGridLayout *synchronizationLayout = new QGridLayout( subsTrackSyncBox );
 
-    subsSpin = new SyncWidget( this );
-    subsLayout->addWidget( subsSpin, 0, 2, 1, 1 );
+    for( int i = 0; i < 2; i++ )
+    {
+        QLabel *subsLabel = new QLabel;
+        subsLabel->setText( qtr( i == 0 ? "Primary subtitle Track:" : "Secondary subtitle track:" ) );
+        synchronizationLayout->addWidget( subsLabel, i, 0, 1, 1 );
+        SyncWidget **p_subsSpin = i == 0 ? &subsSpin : &secondarySubsSpin;
+
+        *p_subsSpin = new SyncWidget( this );
+        synchronizationLayout->addWidget( *p_subsSpin, i, 2, 1, 1 );
+    }
+
+    subsLayout->addWidget( subsTrackSyncBox, 0, 0, 2, 5 );
 
     QLabel *subSpeedLabel = new QLabel;
     subSpeedLabel->setText( qtr( "Subtitle speed:" ) );
-    subsLayout->addWidget( subSpeedLabel, 1, 0, 1, 1 );
+    subsLayout->addWidget( subSpeedLabel, 2, 0, 1, 1 );
 
     subSpeedSpin = new QDoubleSpinBox;
     subSpeedSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
@@ -1393,11 +1402,11 @@ SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent )
     subSpeedSpin->setSingleStep( 0.2 );
     subSpeedSpin->setSuffix( " fps" );
     subSpeedSpin->setButtonSymbols( QDoubleSpinBox::PlusMinus );
-    subsLayout->addWidget( subSpeedSpin, 1, 2, 1, 1 );
+    subsLayout->addWidget( subSpeedSpin, 2, 2, 1, 1 );
 
     QLabel *subDurationLabel = new QLabel;
     subDurationLabel->setText( qtr( "Subtitle duration factor:" ) );
-    subsLayout->addWidget( subDurationLabel, 2, 0, 1, 1 );
+    subsLayout->addWidget( subDurationLabel, 3, 0, 1, 1 );
 
     subDurationSpin = new QDoubleSpinBox;
     subDurationSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
@@ -1406,7 +1415,7 @@ SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent )
     subDurationSpin->setMaximum( 20 );
     subDurationSpin->setSingleStep( 0.2 );
     subDurationSpin->setButtonSymbols( QDoubleSpinBox::PlusMinus );
-    subsLayout->addWidget( subDurationSpin, 2, 2, 1, 1 );
+    subsLayout->addWidget( subDurationSpin, 3, 2, 1, 1 );
 
     mainLayout->addWidget( subsBox, 2, 0, 2, 5 );
 
@@ -1417,6 +1426,7 @@ SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent )
     /* Various Connects */
     connect( AVSpin, &SyncWidget::valueChanged, this, &SyncControls::advanceAudio ) ;
     connect( subsSpin, &SyncWidget::valueChanged, this, &SyncControls::advanceSubs ) ;
+    connect( secondarySubsSpin, &SyncWidget::valueChanged, this, &SyncControls::advanceSecondarySubs ) ;
     connect( subSpeedSpin, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &SyncControls::adjustSubsSpeed);
     connect( subDurationSpin, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &SyncControls::adjustSubsDuration);
 
@@ -1425,6 +1435,11 @@ SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent )
         subsSpin->setValue(secf_from_vlc_tick(value));
         b_userAction = true;
     });
+    connect( THEMIM, &PlayerController::secondarySubtitleDelayChanged, [this](vlc_tick_t value) {
+        b_userAction = false;
+        secondarySubsSpin->setValue(secf_from_vlc_tick(value));
+        b_userAction = true;
+    });
     connect( THEMIM, &PlayerController::audioDelayChanged, [this](vlc_tick_t value) {
         b_userAction = false;
         AVSpin->setValue(secf_from_vlc_tick(value));
@@ -1452,6 +1467,7 @@ void SyncControls::clean()
     b_userAction = false;
     AVSpin->setValue( 0.0 );
     subsSpin->setValue( 0.0 );
+    secondarySubsSpin->setValue( 0.0 );
     subSpeedSpin->setValue( 1.0 );
     subsdelayClean();
     b_userAction = true;
@@ -1463,6 +1479,7 @@ void SyncControls::update()
     if( THEMIM->getInput() )
     {
         subsSpin->setValue(secf_from_vlc_tick(THEMIM->getSubtitleDelay()));
+        secondarySubsSpin->setValue(secf_from_vlc_tick(THEMIM->getSecondarySubtitleDelay()));
         AVSpin->setValue(secf_from_vlc_tick(THEMIM->getAudioDelay()));
         subSpeedSpin->setValue(THEMIM->getSubtitleFPS());
         subDurationSpin->setValue(m_SubsDelayCfgFactor.getValue());
@@ -1488,6 +1505,15 @@ void SyncControls::advanceSubs( double f_advance )
     }
 }
 
+void SyncControls::advanceSecondarySubs( double f_advance )
+{
+    if( THEMIM->getInput() && b_userAction )
+    {
+        vlc_tick_t i_delay = vlc_tick_from_sec( f_advance );
+        THEMIM->setSecondarySubtitleDelay( i_delay );
+    }
+}
+
 void SyncControls::adjustSubsSpeed( double f_fps )
 {
     if( THEMIM->getInput() && b_userAction )
diff --git a/modules/gui/qt/components/extended_panels.hpp b/modules/gui/qt/components/extended_panels.hpp
index a96240d67a..a06704bbcb 100644
--- a/modules/gui/qt/components/extended_panels.hpp
+++ b/modules/gui/qt/components/extended_panels.hpp
@@ -248,6 +248,7 @@ private:
     intf_thread_t *p_intf;
     SyncWidget *AVSpin;
     SyncWidget *subsSpin;
+    SyncWidget *secondarySubsSpin;
     QDoubleSpinBox *subSpeedSpin;
     QDoubleSpinBox *subDurationSpin;
     QVLCFloat m_SubsDelayCfgFactor;
@@ -265,6 +266,7 @@ public slots:
 private slots:
     void advanceAudio( double );
     void advanceSubs( double );
+    void advanceSecondarySubs( double );
     void adjustSubsSpeed( double );
     void adjustSubsDuration( double );
 };
diff --git a/modules/gui/qt/components/player_controller.cpp b/modules/gui/qt/components/player_controller.cpp
index 4f10514c6e..85759324f0 100644
--- a/modules/gui/qt/components/player_controller.cpp
+++ b/modules/gui/qt/components/player_controller.cpp
@@ -600,7 +600,8 @@ static void on_player_subtitle_delay_changed(vlc_player_t *, vlc_tick_t new_dela
         }
         else
         {
-            // TODO: Support dual subtitles
+            that->m_secondarySubtitleDelay = new_delay;
+            emit that->q_func()->secondarySubtitleDelayChanged( new_delay );
         }
     });
 }
@@ -1068,6 +1069,14 @@ void PlayerController::setSubtitleDelay(VLCTick delay)
                                  VLC_PLAYER_WHENCE_ABSOLUTE, SPU_ID_PRIMARY );
 }
 
+void PlayerController::setSecondarySubtitleDelay(VLCTick delay)
+{
+    Q_D(PlayerController);
+    vlc_player_locker lock{ d->m_player };
+    vlc_player_SetSubtitleDelay( d->m_player, delay,
+                                 VLC_PLAYER_WHENCE_ABSOLUTE, SPU_ID_SECONDARY_START );
+}
+
 void PlayerController::setSubtitleFPS(float fps)
 {
     Q_D(PlayerController);
@@ -1492,6 +1501,7 @@ PRIMITIVETYPE_GETTER(float, getPosition, m_position)
 PRIMITIVETYPE_GETTER(VLCTick, getLength, m_length)
 PRIMITIVETYPE_GETTER(VLCTick, getAudioDelay, m_audioDelay)
 PRIMITIVETYPE_GETTER(VLCTick, getSubtitleDelay, m_subtitleDelay)
+PRIMITIVETYPE_GETTER(VLCTick, getSecondarySubtitleDelay, m_secondarySubtitleDelay)
 PRIMITIVETYPE_GETTER(bool, isSeekable, m_capabilities & VLC_INPUT_CAPABILITIES_SEEKABLE)
 PRIMITIVETYPE_GETTER(bool, isRewindable, m_capabilities & VLC_INPUT_CAPABILITIES_REWINDABLE)
 PRIMITIVETYPE_GETTER(bool, isPausable, m_capabilities & VLC_INPUT_CAPABILITIES_PAUSEABLE)
diff --git a/modules/gui/qt/components/player_controller.hpp b/modules/gui/qt/components/player_controller.hpp
index dc474d836f..c9f3935a0f 100644
--- a/modules/gui/qt/components/player_controller.hpp
+++ b/modules/gui/qt/components/player_controller.hpp
@@ -124,6 +124,7 @@ public:
 
     Q_PROPERTY(VLCTick audioDelay READ getAudioDelay WRITE setAudioDelay NOTIFY audioDelayChanged)
     Q_PROPERTY(VLCTick subtitleDelay READ getSubtitleDelay WRITE setSubtitleDelay NOTIFY subtitleDelayChanged)
+    Q_PROPERTY(VLCTick secondarySubtitleDelay READ getSecondarySubtitleDelay WRITE setSecondarySubtitleDelay NOTIFY secondarySubtitleDelayChanged)
     Q_PROPERTY(float subtitleFPS READ getSubtitleFPS WRITE setSubtitleFPS NOTIFY subtitleFPSChanged)
     Q_PROPERTY(bool dualSubtitlesEnabled READ areDualSubtitlesEnabled WRITE setDualSubtitlesEnabled NOTIFY dualSubtitlesEnabledChanged)
 
@@ -269,7 +270,9 @@ public slots:
     VLCTick getAudioDelay() const;
     void setAudioDelay( VLCTick );
     VLCTick getSubtitleDelay() const;
+    VLCTick getSecondarySubtitleDelay() const;
     void setSubtitleDelay( VLCTick );
+    void setSecondarySubtitleDelay( VLCTick );
     float getSubtitleFPS( ) const;
     void setSubtitleFPS( float );
     bool areDualSubtitlesEnabled() const;
@@ -355,6 +358,7 @@ signals:
     //tracks
     void audioDelayChanged(VLCTick);
     void subtitleDelayChanged(VLCTick);
+    void secondarySubtitleDelayChanged(VLCTick);
     void subtitleFPSChanged(float);
     void dualSubtitlesEnabledChanged(bool);
 
diff --git a/modules/gui/qt/components/player_controller_p.hpp b/modules/gui/qt/components/player_controller_p.hpp
index c03da62da7..3f791acd47 100644
--- a/modules/gui/qt/components/player_controller_p.hpp
+++ b/modules/gui/qt/components/player_controller_p.hpp
@@ -91,6 +91,7 @@ public:
 
     VLCTick      m_audioDelay = 0;
     VLCTick      m_subtitleDelay = 0;
+    VLCTick      m_secondarySubtitleDelay = 0;
     float        m_subtitleFPS = 1.0;
     bool         m_dualSubtitlesEnabled = false;
 
-- 
2.11.0



More information about the vlc-devel mailing list