]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/extended_panels.cpp
Qt: extended panels, remove last tab and simplify code
[vlc] / modules / gui / qt4 / components / extended_panels.cpp
index e10dceb05bc597d065a98d722e654533a9e44735..2c15dfa7aa39f62a25961500b54893e6b2dcc6dc 100644 (file)
@@ -73,7 +73,7 @@ private:
 };
 #endif
 
-QString ModuleFromWidgetName( QObject *obj )
+const QString ModuleFromWidgetName( QObject *obj )
 {
     return obj->objectName().replace( "Enable","" );
 }
@@ -240,10 +240,6 @@ ExtVideo::ExtVideo( intf_thread_t *_p_intf, QTabWidget *_parent ) :
              ui.cropRightPx, setDisabled( bool ) );
 }
 
-ExtVideo::~ExtVideo()
-{
-}
-
 void ExtVideo::cropChange()
 {
     if( ui.topBotCropSync->isChecked() )
@@ -362,12 +358,6 @@ void ExtVideo::ChangeVFiltersString( const char *psz_name, bool b_add )
     }
     /* Vout is not kept, so put that in the config */
     config_PutPsz( p_intf, psz_filter_type, psz_string );
-    if( !strcmp( psz_filter_type, "video-filter" ) )
-        ui.videoFilterText->setText( psz_string );
-    else if( !strcmp( psz_filter_type, "vout-filter" ) )
-        ui.voutFilterText->setText( psz_string );
-    else if( !strcmp( psz_filter_type, "sub-filter" ) )
-        ui.subpictureFilterText->setText( psz_string );
 
     /* Try to set on the fly */
     p_vout = THEMIM->getVout();
@@ -396,6 +386,7 @@ void ExtVideo::initComboBoxItems( QObject *widget )
 {
     QComboBox *combobox = qobject_cast<QComboBox*>( widget );
     if( !combobox ) return;
+
     QString option = OptionFromWidgetName( widget );
     module_config_t *p_item = config_FindConfig( VLC_OBJECT( p_intf ),
                                                  qtu( option ) );
@@ -505,11 +496,12 @@ void ExtVideo::setWidgetValue( QObject *widget )
         free( val.psz_string );
     }
     else
-        msg_Err( p_intf,
-                 "Module %s's %s variable is of an unsupported type ( %d )",
-                 qtu( module ),
-                 qtu( option ),
-                 i_type );
+        if( p_obj )
+            msg_Err( p_intf,
+                     "Module %s's %s variable is of an unsupported type ( %d )",
+                     qtu( module ),
+                     qtu( option ),
+                     i_type );
 }
 
 void ExtVideo::updateFilterOptions()
@@ -644,11 +636,6 @@ ExtV4l2::ExtV4l2( intf_thread_t *_p_intf, QWidget *_parent )
     box = NULL;
 }
 
-ExtV4l2::~ExtV4l2()
-{
-    delete box;
-}
-
 void ExtV4l2::showEvent( QShowEvent *event )
 {
     QWidget::showEvent( event );
@@ -887,14 +874,6 @@ Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
     updateUIFromCore();
 }
 
-Equalizer::~Equalizer()
-{
-}
-
-void Equalizer::clean()
-{
-    enable();
-}
 /* Write down initial values */
 void Equalizer::updateUIFromCore()
 {
@@ -934,7 +913,7 @@ void Equalizer::updateUIFromCore()
 
     if( psz_bands && strlen( psz_bands ) > 1 )
     {
-       char *psz_bands_orig = psz_bands;
+        char *psz_bands_orig = psz_bands;
         for( int i = 0; i < BANDS; i++ )
         {
             const float f = us_strtod(psz_bands, &psz_bands );
@@ -1119,17 +1098,189 @@ void Equalizer::addCallbacks( aout_instance_t *p_aout )
  * Audio filters
  **********************************************************************/
 
+/**********************************************************************
+ * Dynamic range compressor
+ **********************************************************************/
+
+typedef struct
+{
+    const char *psz_name;
+    const char *psz_descs;
+    const char *psz_units;
+    const float f_min;      // min
+    const float f_max;      // max
+    const float f_value;    // value
+    const float f_resolution; // resolution
+} comp_controls_t;
+
+static const comp_controls_t comp_controls[] =
+{
+    { "compressor-rms-peak",    _("RMS/peak"),       "",       0.0f,   1.0f,   0.00f, 0.001f },
+    { "compressor-attack",      _("Attack"),       _(" ms"),   1.5f, 400.0f,  25.00f, 0.100f },
+    { "compressor-release",     _("Release"),      _(" ms"),   2.0f, 800.0f, 100.00f, 0.100f },
+    { "compressor-threshold",   _("Threshold"),    _(" dB"), -30.0f,   0.0f, -11.00f, 0.010f },
+    { "compressor-ratio",       _("Ratio"),          ":1",     1.0f,  20.0f,   8.00f, 0.010f },
+    { "compressor-knee",        _("Knee\nradius"), _(" dB"),   1.0f,  10.0f,   2.50f, 0.010f },
+    { "compressor-makeup-gain", _("Makeup\ngain"), _(" dB"),   0.0f,  24.0f,   7.00f, 0.010f },
+};
+
+Compressor::Compressor( intf_thread_t *_p_intf, QWidget *_parent )
+           : QWidget( _parent ) , p_intf( _p_intf )
+{
+    QFont smallFont = QApplication::font();
+    smallFont.setPointSize( smallFont.pointSize() - 3 );
+
+    QGridLayout *layout = new QGridLayout( this );
+    layout->setMargin( 0 );
+
+    enableCheck = new QCheckBox( qtr( "Enable dynamic range compressor" ) );
+    layout->addWidget( enableCheck, 0, 0, 1, NUM_CP_CTRL );
+
+    for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
+    {
+        const int i_min = (int)( comp_controls[i].f_min
+                               / comp_controls[i].f_resolution );
+        const int i_max = (int)( comp_controls[i].f_max
+                               / comp_controls[i].f_resolution );
+        const int i_val = (int)( comp_controls[i].f_value
+                               / comp_controls[i].f_resolution );
+
+        compCtrl[i] = new QSlider( Qt::Vertical );
+        compCtrl[i]->setMinimum( i_min );
+        compCtrl[i]->setMaximum( i_max );
+        compCtrl[i]->setValue(   i_val );
+
+        oldControlVars[i] = comp_controls[i].f_value;
+
+        CONNECT( compCtrl[i], valueChanged( int ), this, setInitValues() );
+
+        ctrl_texts[i] = new QLabel( qtr( comp_controls[i].psz_descs ) + "\n" );
+        ctrl_texts[i]->setFont( smallFont );
+        ctrl_texts[i]->setAlignment( Qt::AlignHCenter );
+
+        ctrl_readout[i] = new QLabel;
+        ctrl_readout[i]->setFont( smallFont );
+        ctrl_readout[i]->setAlignment( Qt::AlignHCenter );
+
+        layout->addWidget( compCtrl[i],     1, i, Qt::AlignHCenter );
+        layout->addWidget( ctrl_readout[i], 2, i, Qt::AlignHCenter );
+        layout->addWidget( ctrl_texts[i],   3, i, Qt::AlignHCenter );
+    }
+
+    BUTTONACT( enableCheck, enable() );
+
+    /* Write down initial values */
+    aout_instance_t *p_aout = THEMIM->getAout();
+    char *psz_af;
+
+    if( p_aout )
+    {
+        psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
+        for( int i = 0; i < NUM_CP_CTRL; i++ )
+        {
+            controlVars[i] = var_GetFloat( p_aout,
+                                           comp_controls[i].psz_name );
+        }
+        vlc_object_release( p_aout );
+    }
+    else
+    {
+        psz_af = config_GetPsz( p_intf, "audio-filter" );
+        for( int i = 0; i < NUM_CP_CTRL; i++ )
+        {
+            controlVars[i] = config_GetFloat( p_intf,
+                                              comp_controls[i].psz_name );
+        }
+    }
+    if( psz_af && strstr( psz_af, "compressor" ) != NULL )
+    {
+        enableCheck->setChecked( true );
+    }
+    free( psz_af );
+    enable( enableCheck->isChecked() );
+    updateSliders( controlVars );
+    setValues( controlVars );
+}
+
+void Compressor::enable()
+{
+    bool en = enableCheck->isChecked();
+    aout_EnableFilter( THEPL, "compressor", en );
+    enable( en );
+}
+
+void Compressor::enable( bool en )
+{
+    for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
+    {
+        compCtrl[i]->setEnabled( en );
+        ctrl_texts[i]->setEnabled( en );
+        ctrl_readout[i]->setEnabled( en );
+    }
+}
+
+void Compressor::updateSliders( float * controlVars )
+{
+    for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
+    {
+        if( oldControlVars[i] != controlVars[i] )
+        {
+            compCtrl[i]->setValue(
+                    (int)( controlVars[i] / comp_controls[i].f_resolution ) );
+        }
+    }
+}
+
+void Compressor::setInitValues()
+{
+    setValues( controlVars );
+}
+
+void Compressor::setValues( float * controlVars )
+{
+    aout_instance_t *p_aout = THEMIM->getAout();
+
+    for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
+    {
+        float f = (float)( compCtrl[i]->value() ) * ( comp_controls[i].f_resolution );
+        ctrl_readout[i]->setText( QString::number( f, 'f', 1 )
+                                + qtr( comp_controls[i].psz_units ) );
+        if( oldControlVars[i] != f )
+        {
+            if( p_aout )
+            {
+                var_SetFloat( p_aout, comp_controls[i].psz_name, f );
+            }
+            config_PutFloat( p_intf, comp_controls[i].psz_name, f );
+            oldControlVars[i] = f;
+        }
+    }
+    if( p_aout )
+    {
+        vlc_object_release( p_aout );
+    }
+}
+
 /**********************************************************************
  * Spatializer
  **********************************************************************/
-static const char *psz_control_names[] =
+typedef struct
 {
-    "spatializer-roomsize", "spatializer-width",
-    "spatializer-wet", "spatializer-dry", "spatializer-damp"
+    const char *psz_name;
+    const char *psz_desc;
+} spat_controls_t;
+
+static const spat_controls_t spat_controls[] =
+{
+    { "spatializer-roomsize", _("Size") },
+    { "spatializer-width",    _("Width") },
+    { "spatializer-wet",      _("Wet") },
+    { "spatializer-dry",      _("Dry") },
+    { "spatializer-damp",     _("Damp") },
 };
 
-Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent ) :
-    QWidget( _parent ) , p_intf( _p_intf )
+Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent )
+            : QWidget( _parent ) , p_intf( _p_intf )
 {
     QFont smallFont = QApplication::font();
     smallFont.setPointSize( smallFont.pointSize() - 3 );
@@ -1154,15 +1305,20 @@ Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent ) :
             spatCtrl[i]->setValue( 0 );
             spatCtrl[i]->setMinimum( -10 );
         }
+
         oldControlVars[i] = spatCtrl[i]->value();
+
         CONNECT( spatCtrl[i], valueChanged( int ), this, setInitValues() );
-        ctrl_texts[i] = new QLabel( qfu( psz_control_names[i] ) + "\n" );
+
+        ctrl_texts[i] = new QLabel( qtr( spat_controls[i].psz_desc ) + "\n" );
         ctrl_texts[i]->setFont( smallFont );
-        ctrl_readout[i] = new QLabel( "" );
+
+        ctrl_readout[i] = new QLabel;
         ctrl_readout[i]->setFont( smallFont );
-        layout->addWidget( spatCtrl[i], 1, i );
-        layout->addWidget( ctrl_readout[i], 2, i );
-        layout->addWidget( ctrl_texts[i], 3, i );
+
+        layout->addWidget( spatCtrl[i],     1, i, Qt::AlignHCenter );
+        layout->addWidget( ctrl_readout[i], 2, i, Qt::AlignHCenter );
+        layout->addWidget( ctrl_texts[i],   3, i, Qt::AlignHCenter );
     }
 
     BUTTONACT( enableCheck, enable() );
@@ -1176,7 +1332,7 @@ Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent ) :
         psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
         for( int i = 0; i < NUM_SP_CTRL ; i++ )
         {
-            controlVars[i] = var_GetFloat( p_aout, psz_control_names[i] );
+            controlVars[i] = var_GetFloat( p_aout, spat_controls[i].psz_name );
         }
         vlc_object_release( p_aout );
     }
@@ -1185,7 +1341,7 @@ Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent ) :
         psz_af = config_GetPsz( p_intf, "audio-filter" );
         for( int i = 0; i < NUM_SP_CTRL ; i++ )
         {
-            controlVars[i] = config_GetFloat( p_intf, psz_control_names[i] );
+            controlVars[i] = config_GetFloat( p_intf, spat_controls[i].psz_name );
         }
     }
     if( psz_af && strstr( psz_af, "spatializer" ) != NULL )
@@ -1195,10 +1351,6 @@ Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent ) :
     setValues( controlVars );
 }
 
-Spatializer::~Spatializer()
-{
-}
-
 void Spatializer::enable()
 {
     bool en = enableCheck->isChecked();
@@ -1235,9 +1387,9 @@ void Spatializer::setValues( float *controlVars )
         {
             if( oldControlVars[i] != spatCtrl[i]->value() )
             {
-                var_SetFloat( p_aout, psz_control_names[i],
+                var_SetFloat( p_aout, spat_controls[i].psz_name,
                         ( float )spatCtrl[i]->value() );
-                config_PutFloat( p_intf, psz_control_names[i],
+                config_PutFloat( p_intf, spat_controls[i].psz_name,
                         ( float ) spatCtrl[i]->value() );
                 oldControlVars[i] = ( float ) spatCtrl[i]->value();
             }