[vlc-devel] [PATCH v2 5/9] Qt: Add support for extra sets of equalizer ISO bands

Ronald Wright logiconcepts819 at gmail.com
Sun Nov 29 00:11:19 CET 2015


Note:  This patch cannot be applied without patches 2 and 4, which depend on
patch 1.  Patch 3 is also required so that all the new symbol definitions from
patches 1 and 2 are included in VLC.  Patches 4 through 9 must be applied all
together.
---
 modules/gui/qt4/components/extended_panels.cpp | 213 ++++++++++++++++---------
 modules/gui/qt4/components/extended_panels.hpp |   5 +-
 2 files changed, 144 insertions(+), 74 deletions(-)

diff --git a/modules/gui/qt4/components/extended_panels.cpp b/modules/gui/qt4/components/extended_panels.cpp
index 9482a9c..ab9c1bd 100644
--- a/modules/gui/qt4/components/extended_panels.cpp
+++ b/modules/gui/qt4/components/extended_panels.cpp
@@ -34,6 +34,7 @@
 #include <QString>
 #include <QFont>
 #include <QGridLayout>
+#include <QScrollArea>
 #include <QComboBox>
 #include <QTimer>
 #include <QFileDialog>
@@ -51,6 +52,7 @@
 #include <vlc_vout.h>
 #include <vlc_modules.h>
 #include <vlc_plugin.h>
+#include <vlc_eqz_util.h>
 
 static char *ChangeFiltersString( struct intf_thread_t *p_intf, const char *psz_filter_type, const char *psz_name, bool b_add );
 static void ChangeAFiltersString( struct intf_thread_t *p_intf, const char *psz_name, bool b_add );
@@ -1101,8 +1103,8 @@ void AudioFilterControlWidget::setSaveToConfig( bool b_save )
 EqualizerSliderData::EqualizerSliderData( QObject *parent, intf_thread_t *_p_intf,
                                           QSlider *slider, QLabel *_label,
                                           QLabel *_nameLabel, const slider_data_t *_p_data,
-                                          int _index )
-    : FilterSliderData( parent, slider ), index( _index )
+                                          int _index, int _type )
+    : FilterSliderData( parent, slider ), index( _index ), type( _type )
 {
     p_intf = _p_intf;
     valueLabel = _label;
@@ -1120,60 +1122,35 @@ EqualizerSliderData::EqualizerSliderData( QObject *parent, intf_thread_t *_p_int
 
 QStringList EqualizerSliderData::getBandsFromAout() const
 {
-    vlc_object_t *p_aout = (vlc_object_t *) THEMIM->getAout();
     QStringList bands;
-    if( p_aout )
+    QVector<float> float_bands = Equalizer::getEqzBands( p_intf, p_data->name,
+                                                         type );
+    foreach( float f_band, float_bands )
     {
-        if ( var_Type( p_aout, qtu(p_data->name) ) == VLC_VAR_STRING )
-        {
-            char *psz_bands = var_GetString( p_aout, qtu(p_data->name) );
-            if ( psz_bands )
-            {
-                bands = QString( psz_bands ).split( " ", QString::SkipEmptyParts );
-                free( psz_bands );
-            }
-        }
-        vlc_object_release( p_aout );
+        bands << QLocale( QLocale::C ).toString( f_band );
     }
-
-    if ( bands.count() ) return bands;
-    /* Or try config then */
-
-    if ( ! config_FindConfig( VLC_OBJECT(p_intf), qtu(p_data->name) ) )
-        return bands;
-
-    char *psz_bands = config_GetPsz( p_intf, qtu(p_data->name) );
-    if ( psz_bands )
-    {
-        bands = QString( psz_bands ).split( " ", QString::SkipEmptyParts );
-        free( psz_bands );
-    }
-
     return bands;
 }
 
 float EqualizerSliderData::initialValue()
 {
-    float f = p_data->f_value;
-    QStringList bands = getBandsFromAout();
-
-    if ( bands.count() > index )
-        f = QLocale( QLocale::C ).toFloat( bands[ index ] );
-
-    return f;
+    return p_data->f_value;
 }
 
 void EqualizerSliderData::onValueChanged( int i ) const
 {
     QStringList bands = getBandsFromAout();
-    if ( bands.count() > index )
+    if( bands.count() > index )
     {
         float f = ((float) i) * p_data->f_resolution;
         bands[ index ] = QLocale( QLocale::C ).toString( f );
+        if( bands.count() == EQZ_ISO10_BANDS_MAX )
+            bands << QChar( EqzGetIdentifier( type ) );
         vlc_object_t *p_aout = (vlc_object_t *) THEMIM->getAout();
         if ( p_aout )
         {
-            var_SetString( p_aout, qtu(p_data->name), qtu(bands.join( " " )) );
+            var_SetString( p_aout, qtu(p_data->name),
+                    qtu(bands.join( " " )) );
             vlc_object_release( p_aout );
         }
         writeToConfig();
@@ -1188,6 +1165,8 @@ void EqualizerSliderData::writeToConfig() const
     {
         float f = (float) slider->value() * p_data->f_resolution;
         bands[ index ] = QLocale( QLocale::C ).toString( f );
+        if( bands.count() == EQZ_ISO10_BANDS_MAX )
+            bands << QChar( EqzGetIdentifier( type ) );
         config_PutPsz( p_intf, qtu(p_data->name), qtu(bands.join( " " )) );
     }
 }
@@ -1196,42 +1175,108 @@ Equalizer::Equalizer( intf_thread_t *p_intf, QWidget *parent )
     : AudioFilterControlWidget( p_intf, parent, "equalizer" )
 {
     i_smallfont = -3;
-    bool b_vlcBands = var_InheritBool( p_intf, "equalizer-vlcfreqs" );
 
-    const FilterSliderData::slider_data_t vlc_bands[10] =
+    /* Fetch the type of equalizer */
+    const char *psz_eqz_count = var_InheritString( p_intf,
+            "equalizer-bands-count" );
+    bool b_vlcFreqs = var_InheritBool( p_intf, "equalizer-vlcfreqs" );
+    i_type = EqzGetTypeNumber( VLC_OBJECT( p_intf ), atoi( psz_eqz_count ),
+                               b_vlcFreqs );
+    if( i_type == EQZ_UNKNOWN_TYPE )
     {
-        { "equalizer-bands", qtr("60 Hz"),  qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
-        { "equalizer-bands", qtr("170 Hz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
-        { "equalizer-bands", qtr("310 Hz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
-        { "equalizer-bands", qtr("600 Hz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
-        { "equalizer-bands", qtr("1 KHz"),  qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
-        { "equalizer-bands", qtr("3 KHz"),  qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
-        { "equalizer-bands", qtr("6 KHz"),  qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
-        { "equalizer-bands", qtr("12 KHz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
-        { "equalizer-bands", qtr("14 KHz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
-        { "equalizer-bands", qtr("16 KHz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
-    };
-    const FilterSliderData::slider_data_t iso_bands[10] =
+        i_type = EQZ_VLC10_TYPE;
+        msg_Warn( p_intf, "band count specification of '%s' is invalid; "
+                          "defaulting to 10-band VLC equalizer",
+                          psz_eqz_count );
+        msg_Info( p_intf, "full list of valid band counts:" );
+        for( unsigned i = 0; i < NB_EQZ_BAND_COUNTS; i++ )
+             msg_Info( p_intf, "  - '%s'", eqz_band_counts[i] );
+    }
+
+    const QString bands_name = "equalizer-bands";
+    int i_bands = EqzGetNumBandsByType( i_type );
+    const QVector<float> init_bands = getEqzBands( p_intf, bands_name, i_type );
+    const eqz_base_freqtable_t * p_table = EqzGetFrequencyTable( i_type );
+    const float * pf_freq = EqzGetFrequencyPtr( p_table );
+    for( int i = 0; i < i_bands; i++ )
     {
-        { "equalizer-bands", qtr("31 Hz"),  qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
-        { "equalizer-bands", qtr("63 Hz"),  qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
-        { "equalizer-bands", qtr("125 Hz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
-        { "equalizer-bands", qtr("250 Hz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
-        { "equalizer-bands", qtr("500 Hz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
-        { "equalizer-bands", qtr("1 KHz"),  qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
-        { "equalizer-bands", qtr("2 KHz"),  qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
-        { "equalizer-bands", qtr("4 KHz"),  qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
-        { "equalizer-bands", qtr("8 KHz"),  qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
-        { "equalizer-bands", qtr("16 KHz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
-    };
+        float f = pf_freq[i];
+        FilterSliderData::slider_data_t data;
+        data.name = bands_name;
+        if( f >= 1000.0f )
+            data.descs = QString( "%1 kHz" )
+                    .arg( QString::number( f / 1000.0f, 'g', 3 ) );
+        else
+            data.descs = QString( "%1 Hz" )
+                    .arg( QString::number( f, 'g', 3 ) );
+        data.units = qtr( "dB" );
+        data.f_min = -20.0f;
+        data.f_max = 20.0f;
+        data.f_value = init_bands[i];
+        data.f_resolution = 0.1f;
+        data.f_visual_multiplier = 1.0f;
+        controls.append( data );
+    }
+
     const FilterSliderData::slider_data_t preamp_vals =
         { "equalizer-preamp", qtr("Preamp"),  qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 };
 
-    for( int i=0; i<10 ;i++ ) controls.append( (b_vlcBands) ? vlc_bands[i] : iso_bands[i] );
     preamp_values = preamp_vals;
     build();
 }
 
+QVector<float> Equalizer::getEqzBands( intf_thread_t * p_intf,
+                                       const QString & bands_name, int i_type )
+{
+    char eqz_identifier;
+    QVector<float> final_bands;
+    final_bands.resize( EqzGetNumBandsByType( i_type ) );
+
+    char *psz_bands = NULL;
+    vlc_object_t *p_aout = (vlc_object_t *) THEMIM->getAout();
+    QStringList bands;
+    if( p_aout )
+    {
+        if ( var_Type( p_aout, qtu(bands_name) ) == VLC_VAR_STRING )
+        {
+            psz_bands = var_GetString( p_aout, qtu(bands_name) );
+            if ( psz_bands )
+            {
+                bands = QString( psz_bands ).split( " ", QString::SkipEmptyParts );
+            }
+        }
+        vlc_object_release( p_aout );
+    }
+
+    if ( !bands.count() )
+    {
+        /* Or try config then */
+
+        if ( config_FindConfig( VLC_OBJECT(p_intf), qtu(bands_name) ) )
+        {
+            psz_bands = config_GetPsz( p_intf, qtu(bands_name) );
+            if ( psz_bands )
+            {
+                bands = QString( psz_bands ).split( " ", QString::SkipEmptyParts );
+            }
+        }
+    }
+
+    if( psz_bands )
+    {
+        vlc_band_parser_t *p_ctx;
+        if( vlc_eqz_util_band_parser_init( VLC_OBJECT( p_intf ), &p_ctx,
+                psz_bands, i_type, final_bands.data() ) == VLC_SUCCESS )
+        {
+            VLC_UNUSED( vlc_eqz_util_get_amp_array( p_ctx ) );
+            vlc_eqz_util_band_parser_destroy( p_ctx );
+        }
+        free( psz_bands );
+    }
+
+    return final_bands;
+}
+
 void Equalizer::build()
 {
     QFont smallFont = QApplication::font();
@@ -1240,7 +1285,20 @@ void Equalizer::build()
     Ui::EqualizerWidget ui;
     ui.setupUi( this );
 
-    QGridLayout *ctrlLayout = new QGridLayout( ui.slidersPlaceholder );
+    /* Set up scroll area for equalizer controls.  The 31-band equalizer is
+     * massive, and it will not fit on many users' screens without the help of
+     * a scroll area */
+    QVBoxLayout *scrollLayout = new QVBoxLayout( ui.slidersPlaceholder );
+
+    QScrollArea *scrollarea = new QScrollArea();
+    scrollarea->setFrameShape( QFrame::NoFrame );
+    scrollarea->setStyleSheet( "QScrollArea{background-color:transparent;}" );
+    scrollarea->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
+    scrollarea->setWidgetResizable( true );
+
+    QWidget *viewport = new QWidget();
+    viewport->setStyleSheet( "background-color:transparent;" );
+    QGridLayout *ctrlLayout = new QGridLayout();
 
     /* set up preamp control */
     ui.preampLabel->setFont( smallFont );
@@ -1264,33 +1322,40 @@ void Equalizer::build()
         nameLabel->setAlignment( Qt::AlignHCenter );
         EqualizerSliderData *filter =
             new EqualizerSliderData( this, p_intf,
-                                     slider, valueLabel, nameLabel, & data, i );
+                                     slider, valueLabel, nameLabel, & data, i,
+                                     i_type );
         ctrlLayout->addWidget( slider, 0, i, Qt::AlignHCenter );
         ctrlLayout->addWidget( valueLabel, 2, i, Qt::AlignHCenter );
         ctrlLayout->addWidget( nameLabel, 1, i, Qt::AlignHCenter );
         sliderDatas << filter; /* keep track for applying presets */
         i++;
     }
+    viewport->setLayout( ctrlLayout );
+    scrollarea->setWidget( viewport );
+    scrollLayout->addWidget( scrollarea );
 
     /* Add the listed presets */
     ui.presetsCombo->addItem( "", QVariant() ); /* 1st entry = custom/modified */
+    const eqz_base_preset_t * p_table = EqzGetPresetTable( i_type );
     for( i = 0 ; i < NB_PRESETS ; i ++ )
     {
         QGraphicsScene scene;
         QPixmap icon( 40, 40 );
         icon.fill( Qt::transparent );
         QPainter painter( &icon );
-        for ( int j = 0; j < eqz_preset_10b[i].i_band; j++ )
+        const eqz_base_preset_t * p_preset = EqzGetPresetAt( p_table, i );
+        const float * pf_amp = EqzGetAmpPtr( p_preset );
+        for ( int j = 0; j < p_preset->i_band; j++ )
         {
-            float f_value = eqz_preset_10b[i].f_amp[j];
+            float f_value = pf_amp[j];
             if ( f_value > 20.0 ) f_value = 20.0;
             if ( f_value < -20.0 ) f_value = -20.0;
             QRectF shape( j, 20.0 - f_value, 1, f_value );
             scene.addRect( shape, QPen(), palette().brush( QPalette::WindowText ) );
         }
-        scene.addLine( 0.0, 20.0, eqz_preset_10b[i].i_band, 20.0,
+        scene.addLine( 0.0, 20.0, p_preset->i_band, 20.0,
                        palette().color( QPalette::WindowText ) );
-        scene.setSceneRect( 0.0, 0.0, eqz_preset_10b[i].i_band , 40.0 );
+        scene.setSceneRect( 0.0, 0.0, p_preset->i_band, 40.0 );
         scene.render( &painter, icon.rect(), scene.sceneRect(), Qt::IgnoreAspectRatio );
         ui.presetsCombo->addItem( icon, qtr( preset_list_text[i] ),
                                      QVariant( preset_list[i] ) );
@@ -1347,10 +1412,12 @@ void Equalizer::setCorePreset( int i_preset )
 
     i_preset--;/* 1st in index was an empty entry */
 
-    preamp->setValue( eqz_preset_10b[i_preset].f_preamp );
-    for ( int i=0; i< qMin( eqz_preset_10b[i_preset].i_band,
-                            sliderDatas.count() ) ; i++ )
-        sliderDatas[i]->setValue( eqz_preset_10b[i_preset].f_amp[i] );
+    const eqz_base_preset_t * p_table = EqzGetPresetTable( i_type );
+    const eqz_base_preset_t * p_preset = EqzGetPresetAt( p_table, i_preset );
+    const float * pf_amp = EqzGetAmpPtr( p_preset );
+    preamp->setValue( p_preset->f_preamp );
+    for ( int i=0; i< qMin( p_preset->i_band, sliderDatas.count() ) ; i++ )
+        sliderDatas[i]->setValue( pf_amp[i] );
 
     vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
     if( p_aout )
diff --git a/modules/gui/qt4/components/extended_panels.hpp b/modules/gui/qt4/components/extended_panels.hpp
index 006d602..4b9880b 100644
--- a/modules/gui/qt4/components/extended_panels.hpp
+++ b/modules/gui/qt4/components/extended_panels.hpp
@@ -154,11 +154,12 @@ public:
     EqualizerSliderData( QObject *parent, intf_thread_t *p_intf,
                          QSlider *slider,
                          QLabel *valueLabel, QLabel *nameLabel,
-                         const slider_data_t *p_data, int index );
+                         const slider_data_t *p_data, int index, int type );
 
 protected:
     float initialValue() Q_DECL_OVERRIDE;
     int index;
+    int type;
     QStringList getBandsFromAout() const;
 
 public slots:
@@ -172,6 +173,7 @@ class Equalizer: public AudioFilterControlWidget
 
 public:
     Equalizer( intf_thread_t *, QWidget * );
+    static QVector<float> getEqzBands( intf_thread_t *, const QString &, int );
 
 protected:
     void build() Q_DECL_OVERRIDE;
@@ -182,6 +184,7 @@ protected slots:
 private:
     FilterSliderData *preamp;
     FilterSliderData::slider_data_t preamp_values;
+    int i_type;
 
 private slots:
     void setCorePreset( int );
-- 
1.9.1



More information about the vlc-devel mailing list