From: Ronald Wright Date: Fri, 3 Sep 2010 18:18:14 +0000 (+0200) Subject: Qt: Add control to the compressor module X-Git-Tag: 1.2.0-pre1~5333 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=c285701c03180320ebf89a5068b9d873aaa04d15;p=vlc Qt: Add control to the compressor module Modified by jb@videolan.org --- diff --git a/modules/gui/qt4/components/extended_panels.cpp b/modules/gui/qt4/components/extended_panels.cpp index e10dceb05b..47dadbd3cd 100644 --- a/modules/gui/qt4/components/extended_panels.cpp +++ b/modules/gui/qt4/components/extended_panels.cpp @@ -1119,6 +1119,176 @@ void Equalizer::addCallbacks( aout_instance_t *p_aout ) * Audio filters **********************************************************************/ +/********************************************************************** + * Dynamic range compressor + **********************************************************************/ +static const char *psz_comp_control_names[] = +{ + "compressor-rms-peak", "compressor-attack", "compressor-release", + "compressor-threshold", "compressor-ratio", "compressor-knee", + "compressor-makeup-gain" +}; + +static const char *psz_comp_control_descs[] = +{ + "RMS/peak", "Attack", + "Release", "Threshold", "Ratio", "Knee\nradius", "Makeup\ngain" +}; + +static const char *psz_comp_control_units[] = +{ + "", " ms", " ms", " dB", ":1", " dB", " dB" +}; + +static const float f_comp_min_max_val_res_data[] = +{ + // min max value resolution + //---- ------ ------ ---------- + 0.0f, 1.0f, 0.00f, 0.001f, // RMS/peak + 1.5f, 400.0f, 25.00f, 0.100f, // Attack + 2.0f, 800.0f, 100.00f, 0.100f, // Release + -30.0f, 0.0f, -11.00f, 0.010f, // Threshold + 1.0f, 20.0f, 8.00f, 0.010f, // Ratio + 1.0f, 10.0f, 2.50f, 0.010f, // Knee radius + 0.0f, 24.0f, 7.00f, 0.010f // Makeup gain +}; + +Compressor::Compressor( intf_thread_t *_p_intf, QWidget *_parent ) : + QWidget( _parent ) , p_intf( _p_intf ) +{ + QFont smallFont = QApplication::font( static_cast( 0 ) ); + 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++ ) + { + compCtrl[i] = new QSlider( Qt::Vertical ); + + const int i_min = (int)( f_comp_min_max_val_res_data[4 * i + 0] + / f_comp_min_max_val_res_data[4 * i + 3] ); + const int i_max = (int)( f_comp_min_max_val_res_data[4 * i + 1] + / f_comp_min_max_val_res_data[4 * i + 3] ); + const int i_val = (int)( f_comp_min_max_val_res_data[4 * i + 2] + / f_comp_min_max_val_res_data[4 * i + 3] ); + + compCtrl[i]->setMinimum( i_min ); + compCtrl[i]->setMaximum( i_max ); + compCtrl[i]->setValue( i_val ); + oldControlVars[i] = f_comp_min_max_val_res_data[4 * i + 2]; + CONNECT( compCtrl[i], valueChanged( int ), this, setInitValues() ); + ctrl_texts[i] = new QLabel( qtr( psz_comp_control_descs[i] ) + + qtr( "\n" ) ); + ctrl_texts[i]->setFont( smallFont ); + ctrl_texts[i]->setAlignment( Qt::AlignHCenter ); + ctrl_readout[i] = new QLabel( qtr( "" ) ); + 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, + psz_comp_control_names[i] ); + } + 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, + psz_comp_control_names[i] ); + } + } + 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] ) + { + const int i_val = (int)( controlVars[i] + / f_comp_min_max_val_res_data[4 * i + 3] ); + compCtrl[i]->setValue( i_val ); + } + } +} + +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() ) + * ( f_comp_min_max_val_res_data[4 * i + 3] ); + ctrl_readout[i]->setText( QString::number( f, 'f', 1 ) + + qtr( psz_comp_control_units[i] ) ); + if( oldControlVars[i] != f ) + { + if( p_aout ) + { + var_SetFloat( p_aout, psz_comp_control_names[i], f ); + } + config_PutFloat( p_intf, psz_comp_control_names[i], f ); + oldControlVars[i] = f; + } + } + if( p_aout ) + { + vlc_object_release( p_aout ); + } +} + /********************************************************************** * Spatializer **********************************************************************/ diff --git a/modules/gui/qt4/components/extended_panels.hpp b/modules/gui/qt4/components/extended_panels.hpp index a4bbb4f3c3..5fe7dd5e05 100644 --- a/modules/gui/qt4/components/extended_panels.hpp +++ b/modules/gui/qt4/components/extended_panels.hpp @@ -38,6 +38,7 @@ #include #define BANDS 10 +#define NUM_CP_CTRL 7 #define NUM_SP_CTRL 5 class QSignalMapper; @@ -115,6 +116,32 @@ private slots: void setCorePreset(int); }; +class Compressor: public QWidget +{ + Q_OBJECT +public: + Compressor( intf_thread_t *, QWidget * ); + +private: + QSlider *compCtrl[NUM_CP_CTRL]; + QLabel *ctrl_texts[NUM_CP_CTRL]; + QLabel *ctrl_readout[NUM_CP_CTRL]; + float controlVars[NUM_CP_CTRL]; + float oldControlVars[NUM_CP_CTRL]; + + QCheckBox *enableCheck; + + void delCallbacks( aout_instance_t * ); + void addCallbacks( aout_instance_t * ); + intf_thread_t *p_intf; +private slots: + void enable(bool); + void enable(); + void updateSliders(float *); + void setValues(float *); + void setInitValues(); +}; + class Spatializer: public QWidget { Q_OBJECT diff --git a/modules/gui/qt4/dialogs/extended.cpp b/modules/gui/qt4/dialogs/extended.cpp index 3db42237db..8e7756515f 100644 --- a/modules/gui/qt4/dialogs/extended.cpp +++ b/modules/gui/qt4/dialogs/extended.cpp @@ -55,6 +55,9 @@ ExtendedDialog::ExtendedDialog( intf_thread_t *_p_intf ): QVLCFrame( _p_intf ) equal = new Equalizer( p_intf, audioTab ); audioTab->addTab( equal, qtr( "Graphic Equalizer" ) ); + Compressor *compres = new Compressor( p_intf, audioTab ); + audioTab->addTab( compres, qtr( "Compressor" ) ); + Spatializer *spatial = new Spatializer( p_intf, audioTab ); audioTab->addTab( spatial, qtr( "Spatializer" ) ); audioLayout->addWidget( audioTab );