]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/extended_panels.cpp
Qt extended panels: do not spam about options about modules that don't exist in 1.2
[vlc] / modules / gui / qt4 / components / extended_panels.cpp
index ac2eb923fc51325b1b747993b7a4a1fb69699cfe..51952fd121327e108c9997d2a3448c0f51f8e2fb 100644 (file)
@@ -46,6 +46,7 @@
 #include <vlc_intf_strings.h>
 #include <vlc_vout.h>
 #include <vlc_osd.h>
+#include <vlc_modules.h>
 
 #include <vlc_charset.h> /* us_strtod */
 
@@ -395,6 +396,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 ) );
@@ -504,11 +506,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()
@@ -843,7 +846,7 @@ static const QString band_frequencies[] =
 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
                             QWidget( _parent ) , p_intf( _p_intf )
 {
-    QFont smallFont = QApplication::font( static_cast<QWidget*>( 0 ) );
+    QFont smallFont = QApplication::font();
     smallFont.setPointSize( smallFont.pointSize() - 3 );
 
     ui.setupUi( this );
@@ -886,14 +889,6 @@ Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
     updateUIFromCore();
 }
 
-Equalizer::~Equalizer()
-{
-}
-
-void Equalizer::clean()
-{
-    enable();
-}
 /* Write down initial values */
 void Equalizer::updateUIFromCore()
 {
@@ -933,7 +928,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 );
@@ -1118,19 +1113,191 @@ 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( static_cast<QWidget*>( 0 ) );
+    QFont smallFont = QApplication::font();
     smallFont.setPointSize( smallFont.pointSize() - 3 );
 
     QGridLayout *layout = new QGridLayout( this );
@@ -1153,15 +1320,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() );
@@ -1175,7 +1347,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 );
     }
@@ -1184,7 +1356,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 )
@@ -1194,15 +1366,10 @@ Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent ) :
     setValues( controlVars );
 }
 
-Spatializer::~Spatializer()
-{
-}
-
 void Spatializer::enable()
 {
     bool en = enableCheck->isChecked();
-    aout_EnableFilter( VLC_OBJECT( p_intf ), "spatializer",
-            en ? true : false );
+    aout_EnableFilter( THEPL, "spatializer", en );
     enable( en );
 }
 
@@ -1235,9 +1402,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();
             }