[vlc-devel] [PATCH 2/2] add balance tab under audio effects

Valentin Deniaud valentin.deniaud at inpt.fr
Fri Aug 11 14:21:26 CEST 2017


---
 modules/gui/qt/components/extended_panels.cpp | 131 ++++++++++++++++++++++++++
 modules/gui/qt/components/extended_panels.hpp |  51 ++++++++++
 modules/gui/qt/dialogs/extended.cpp           |   5 +
 3 files changed, 187 insertions(+)

diff --git a/modules/gui/qt/components/extended_panels.cpp b/modules/gui/qt/components/extended_panels.cpp
index 9938a39421..0c5ad73588 100644
--- a/modules/gui/qt/components/extended_panels.cpp
+++ b/modules/gui/qt/components/extended_panels.cpp
@@ -1242,6 +1242,137 @@ void Equalizer::enable2Pass( bool b_enable )
     emit configChanged( qfu( "equalizer-2pass" ), QVariant( b_enable ) );
 }
 
+/**********************************************************************
+ * Balancer
+ **********************************************************************/
+
+Balancer::Balancer( intf_thread_t *p_intf, QWidget *parent )
+    : AudioFilterControlWidget( p_intf, parent, "balance" )
+{
+    i_smallfont = 3;
+    const FilterSliderData::slider_data_t slider_data =
+        { "balance-factor",  N_("Left channel"),   N_("Right channel"),  0.0, 1.0, 0.5, 0.01, 1 };
+    controls.append( slider_data );
+
+    const QString radio_data[4][2] = {
+        { "simple",  N_("Simple balance") },
+        { "pan_lin",  N_("Linear panning") },
+        { "pan_sqrt",  N_("Quadratic panning") },
+        { "transfer",  N_("Transfer sound between channels") },
+    };
+    for( int i = 0; i < 4; i++ ) radios.append( radio_data[i] );
+
+    build();
+}
+
+void Balancer::build()
+{
+    QFont smallFont = QApplication::font();
+    smallFont.setPointSize( smallFont.pointSize() + i_smallfont );
+
+    QVBoxLayout *layout = new QVBoxLayout( this );
+    slidersBox = new QGroupBox( qtr( "Enable" ) );
+    slidersBox->setCheckable( true );
+    layout->addWidget( slidersBox );
+
+    QGridLayout *ctrlLayout = new QGridLayout( slidersBox );
+
+    /* Build horizontal slider with left and right tick text */
+    QSlider *slider = new QSlider( Qt::Horizontal );
+    slider->setTickPosition( QSlider::TicksBelow );
+    slider->setTickInterval(10);
+    QLabel *rightLabel = new QLabel();
+    rightLabel->setFont( smallFont );
+    rightLabel->setAlignment( Qt::AlignRight | Qt::AlignTop );
+    QLabel *leftLabel = new QLabel();
+    leftLabel->setFont( smallFont );
+    leftLabel->setAlignment( Qt::AlignLeft | Qt::AlignTop );
+    BalancerSliderData *filter =
+        new BalancerSliderData( this, p_intf,
+                              slider, leftLabel, rightLabel, &controls[0] );
+    ctrlLayout->addWidget( slider, 0, 0, 1, 2 );
+    ctrlLayout->addWidget( leftLabel, 1, 0, 1, 1, Qt::AlignLeft );
+    ctrlLayout->addWidget( rightLabel, 1, 1, 1, 1, Qt::AlignRight );
+    sliderDatas << filter;
+    connectConfigChanged( filter );
+
+    /* Build radio buttons */
+    build_radio( layout );
+
+    char *psz_af = var_InheritString( THEPL, "audio-filter" );
+
+    if( psz_af && filterIsPresent( qfu(psz_af), name ) )
+        slidersBox->setChecked( true );
+    else
+        slidersBox->setChecked( false );
+    CONNECT( slidersBox, toggled(bool), this, enable(bool) );
+
+    free( psz_af );
+}
+
+void Balancer::build_radio( QVBoxLayout *layout )
+{
+    QGroupBox *groupBox = new QGroupBox( "Balance modes" );
+    QVBoxLayout *vbox = new QVBoxLayout;
+    char *name_checked = var_InheritString( p_intf, "balance-mode" );
+    foreach( const QString *data, radios )
+    {
+        QRadioButton *radio = new QRadioButton( data[1] );
+        if( ( !name_checked && data[0] == "simple" ) ||
+                ( name_checked && !strcmp( qtu( data[0] ), name_checked ) ) )
+            radio->setChecked(true);
+        new BalancerRadioData( this, p_intf, radio, data[0], data[1] );
+        vbox->addWidget( radio );
+    }
+    groupBox->setLayout( vbox );
+    layout->addWidget( groupBox );
+}
+
+BalancerRadioData::BalancerRadioData( QObject *parent,
+                                    intf_thread_t *_p_intf,
+                                    QRadioButton *_radio,
+                                    const QString( _name ),
+                                    const QString( _descs )):
+    QObject( parent ), p_intf( _p_intf ), radio( _radio ),
+    name( _name ), descs( _descs )
+{
+    CONNECT( radio, toggled(bool), this, onValueChange(bool) );
+}
+
+void BalancerRadioData::onValueChange(bool b) {
+    if( !b )
+        return;
+    vlc_object_t *p_aout= (vlc_object_t *)THEMIM->getAout();
+
+    if( p_aout )
+    {
+        var_SetString( p_aout, "balance-mode", qtu( name ) );
+        vlc_object_release( p_aout );
+    }
+    emit configChanged( "balance-mode", QVariant( name ) );
+}
+
+BalancerSliderData::BalancerSliderData( QObject *parent,
+                                    intf_thread_t *_p_intf,
+                                    QSlider *slider,
+                                    QLabel *_left, QLabel *_right,
+                                    const slider_data_t *_p_data ):
+    FilterSliderData( parent, slider ), leftLabel( _left ),
+    rightLabel( _right )
+{
+    p_intf = _p_intf;
+    p_data = _p_data;
+
+    slider->setMinimum( p_data->f_min / p_data->f_resolution );
+    slider->setMaximum( p_data->f_max / p_data->f_resolution );
+    /* Workaround slider_data_t QString members naming */
+    leftLabel->setText( p_data->descs );
+    rightLabel->setText( p_data->units );
+    setValue( initialValue() );
+    CONNECT( slider, valueChanged( int ), this, onValueChanged( int ) );
+}
+
+
 /**********************************************************************
  * Audio filters
  **********************************************************************/
diff --git a/modules/gui/qt/components/extended_panels.hpp b/modules/gui/qt/components/extended_panels.hpp
index e44dc29dd6..e9e7e452a8 100644
--- a/modules/gui/qt/components/extended_panels.hpp
+++ b/modules/gui/qt/components/extended_panels.hpp
@@ -36,6 +36,7 @@
 #include "ui/video_effects.h"
 
 #include <QTabWidget>
+#include <QRadioButton>
 
 #define BANDS 10
 
@@ -190,6 +191,56 @@ private slots:
     void enable2Pass( bool );
 };
 
+class BalancerSliderData : public FilterSliderData
+{
+    Q_OBJECT
+
+public:
+    BalancerSliderData( QObject *parent, intf_thread_t *p_intf,
+                         QSlider *slider,
+                         QLabel *left, QLabel *right,
+                         const slider_data_t *p_data );
+
+protected:
+    QLabel *leftLabel;
+    QLabel *rightLabel;
+};
+
+class BalancerRadioData : public QObject
+{
+    Q_OBJECT
+
+public:
+    BalancerRadioData( QObject *parent, intf_thread_t *p_intf,
+                        QRadioButton *radio, const QString name,
+                        const QString descs );
+
+protected:
+    intf_thread_t *p_intf;
+    QRadioButton *radio;
+    const QString name;
+    const QString descs;
+
+public slots:
+    void onValueChange( bool b );
+
+signals:
+    void configChanged( QString name, QVariant value );
+};
+
+class Balancer: public AudioFilterControlWidget
+{
+    Q_OBJECT
+
+public:
+    Balancer( intf_thread_t *, QWidget * );
+
+protected:
+    void build() Q_DECL_OVERRIDE;
+    void build_radio( QVBoxLayout *layout );
+    QVector<const QString *> radios;
+};
+
 class Compressor: public AudioFilterControlWidget
 {
     Q_OBJECT
diff --git a/modules/gui/qt/dialogs/extended.cpp b/modules/gui/qt/dialogs/extended.cpp
index 541a0598d1..5cf181dae2 100644
--- a/modules/gui/qt/dialogs/extended.cpp
+++ b/modules/gui/qt/dialogs/extended.cpp
@@ -80,6 +80,11 @@ ExtendedDialog::ExtendedDialog( intf_thread_t *_p_intf )
     audioTab->addTab( stereowiden, qtr( "Stereo Widener" ) );
     audioLayout->addWidget( audioTab );
 
+    Balancer *balance = new Balancer( p_intf, audioTab );
+    CONNECT( balance, configChanged(QString, QVariant), this, putAudioConfig(QString, QVariant) );
+    audioTab->addTab( balance, qtr( "Balance" ) );
+    audioLayout->addWidget( audioTab );
+
     mainTabW->insertTab( AUDIO_TAB, audioWidget, qtr( "Audio Effects" ) );
 
     /* Video Effects */
-- 
2.14.0


More information about the vlc-devel mailing list