Commit 79ece335 authored by Francois Cartegnie's avatar Francois Cartegnie

Qt: Compressor: rewrite values handling logic.

Also remove the N*N controls config/var updates.
parent cc7d4e44
...@@ -914,6 +914,87 @@ void ExtV4l2::ValueChange( int value ) ...@@ -914,6 +914,87 @@ void ExtV4l2::ValueChange( int value )
} }
} }
/**********************************************************************
* Sliders
**********************************************************************/
FilterSliderData::FilterSliderData( QObject *parent,
intf_thread_t *_p_intf,
QSlider *_slider,
QLabel *_label, QLabel *_nameLabel,
const slider_data_t *_p_data ):
QObject( parent ), slider( _slider ), p_intf( _p_intf ),
valueLabel( _label ), nameLabel( _nameLabel ), p_data( _p_data )
{
slider->setMinimum( p_data->f_min / p_data->f_resolution );
slider->setMaximum( p_data->f_max / p_data->f_resolution );
nameLabel->setText( qfu( p_data->psz_descs ) );
CONNECT( slider, valueChanged( int ), this, updateText( int ) );
setValue( initialValue() );
/* In case current == min|max text would not be first updated */
if ( slider->value() == slider->maximum() ||
slider->value() == slider->minimum() )
updateText( slider->value() );
CONNECT( slider, valueChanged( int ), this, onValueChanged( int ) );
}
void FilterSliderData::setValue( float f )
{
slider->setValue( f / p_data->f_resolution );
}
void FilterSliderData::updateText( int i )
{
float f = ((float) i) * p_data->f_resolution;
valueLabel->setText( qfu( p_data->psz_units )
.prepend( "%1" )
.arg( QString::number( f, 'f', 1 ) ) );
}
float FilterSliderData::initialValue()
{
vlc_object_t *p_aout = (vlc_object_t *) THEMIM->getAout();
float f = p_data->f_value;
if( p_aout )
{
if ( var_Type( p_aout, p_data->psz_name ) == 0 )
{
vlc_object_release( p_aout );
/* Not found, will try in config */
}
else
{
f = var_GetFloat( p_aout, p_data->psz_name );
vlc_object_release( p_aout );
return f;
}
}
if ( ! config_FindConfig( VLC_OBJECT(p_intf), p_data->psz_name ) )
return f;
f = config_GetFloat( p_intf, p_data->psz_name );
return f;
}
void FilterSliderData::onValueChanged( int i )
{
float f = ((float) i) * p_data->f_resolution;
vlc_object_t *p_aout = (vlc_object_t *) THEMIM->getAout();
if ( p_aout )
{
var_SetFloat( p_aout, p_data->psz_name, f );
vlc_object_release( p_aout );
}
writeToConfig();
}
void FilterSliderData::writeToConfig()
{
float f = ((float) slider->value()) * p_data->f_resolution;
config_PutFloat( p_intf, p_data->psz_name, f );
}
/********************************************************************** /**********************************************************************
* Equalizer * Equalizer
**********************************************************************/ **********************************************************************/
...@@ -1230,7 +1311,7 @@ void Equalizer::addCallbacks( vlc_object_t *p_aout ) ...@@ -1230,7 +1311,7 @@ void Equalizer::addCallbacks( vlc_object_t *p_aout )
* Dynamic range compressor * Dynamic range compressor
**********************************************************************/ **********************************************************************/
const Compressor::comp_controls_t Compressor::comp_controls[] = const FilterSliderData::slider_data_t Compressor::comp_controls[] =
{ {
{ "compressor-rms-peak", _("RMS/peak"), "", 0.0f, 1.0f, 0.00f, 0.001f }, { "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-attack", _("Attack"), _(" ms"), 1.5f, 400.0f, 25.00f, 0.100f },
...@@ -1253,61 +1334,33 @@ Compressor::Compressor( intf_thread_t *_p_intf, QWidget *_parent ) ...@@ -1253,61 +1334,33 @@ Compressor::Compressor( intf_thread_t *_p_intf, QWidget *_parent )
layout->addWidget( compressorBox ); layout->addWidget( compressorBox );
QGridLayout *ctrlLayout = new QGridLayout( compressorBox ); QGridLayout *ctrlLayout = new QGridLayout( compressorBox );
for( int i = 0 ; i < NUM_CP_CTRL ; i++ ) for( int i = 0 ; i < NUM_CP_CTRL ; i++ )
{ {
const int i_min = (int)( comp_controls[i].f_min QSlider *slider = new QSlider( Qt::Vertical );
/ comp_controls[i].f_resolution ); QLabel *valueLabel = new QLabel();
const int i_max = (int)( comp_controls[i].f_max valueLabel->setFont( smallFont );
/ comp_controls[i].f_resolution ); valueLabel->setAlignment( Qt::AlignHCenter );
const int i_val = (int)( comp_controls[i].f_value QLabel *nameLabel = new QLabel();
/ comp_controls[i].f_resolution ); nameLabel->setFont( smallFont );
nameLabel->setAlignment( Qt::AlignHCenter );
compCtrl[i] = new QSlider( Qt::Vertical ); FilterSliderData *filter =
compCtrl[i]->setMinimum( i_min ); new FilterSliderData( this, p_intf,
compCtrl[i]->setMaximum( i_max ); slider, valueLabel, nameLabel, & comp_controls[i] );
compCtrl[i]->setValue( i_val ); ctrlLayout->addWidget( slider, 0, i, Qt::AlignHCenter );
ctrlLayout->addWidget( valueLabel, 1, i, Qt::AlignHCenter );
oldControlVars[i] = comp_controls[i].f_value; ctrlLayout->addWidget( nameLabel, 2, i, Qt::AlignHCenter );
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 );
ctrlLayout->addWidget( compCtrl[i], 0, i, Qt::AlignHCenter );
ctrlLayout->addWidget( ctrl_readout[i], 1, i, Qt::AlignHCenter );
ctrlLayout->addWidget( ctrl_texts[i], 2, i, Qt::AlignHCenter );
} }
for( int i = 0; i < NUM_CP_CTRL; i++ )
CONNECT( compCtrl[i], valueChanged( int ), this, setValues() );
/* Write down initial values */
vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout(); vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
char *psz_af; char *psz_af;
if( p_aout ) if( p_aout )
{ {
psz_af = var_GetNonEmptyString( p_aout, "audio-filter" ); 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 ); vlc_object_release( p_aout );
} }
else else
{
psz_af = config_GetPsz( p_intf, "audio-filter" ); 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 ) if( psz_af && strstr( psz_af, "compressor" ) != NULL )
compressorBox->setChecked( true ); compressorBox->setChecked( true );
...@@ -1316,8 +1369,6 @@ Compressor::Compressor( intf_thread_t *_p_intf, QWidget *_parent ) ...@@ -1316,8 +1369,6 @@ Compressor::Compressor( intf_thread_t *_p_intf, QWidget *_parent )
CONNECT( compressorBox, toggled(bool), this, enable() ); CONNECT( compressorBox, toggled(bool), this, enable() );
free( psz_af ); free( psz_af );
updateSliders();
setValues();
} }
void Compressor::enable() void Compressor::enable()
...@@ -1325,42 +1376,6 @@ void Compressor::enable() ...@@ -1325,42 +1376,6 @@ void Compressor::enable()
playlist_EnableAudioFilter( THEPL, "compressor", compressorBox->isChecked() ); playlist_EnableAudioFilter( THEPL, "compressor", compressorBox->isChecked() );
} }
void Compressor::updateSliders()
{
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::setValues()
{
vlc_object_t *p_aout = (vlc_object_t *)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 * Spatializer
......
...@@ -83,6 +83,43 @@ private slots: ...@@ -83,6 +83,43 @@ private slots:
void ValueChange( bool value ); void ValueChange( bool value );
}; };
class FilterSliderData : public QObject
{
Q_OBJECT
public:
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
} slider_data_t;
FilterSliderData( QObject *parent, intf_thread_t *p_intf,
QSlider *slider,
QLabel *valueLabel, QLabel *nameLabel,
const slider_data_t *p_data );
void setValue( float f );
protected:
float initialValue();
public slots:
void onValueChanged( int i );
void updateText( int i );
void writeToConfig();
private:
intf_thread_t *p_intf;
QSlider *slider;
QLabel *valueLabel;
QLabel *nameLabel;
const slider_data_t *p_data;
};
class Equalizer: public QWidget class Equalizer: public QWidget
{ {
Q_OBJECT Q_OBJECT
...@@ -122,32 +159,12 @@ public: ...@@ -122,32 +159,12 @@ public:
Compressor( intf_thread_t *, QWidget * ); Compressor( intf_thread_t *, QWidget * );
private: private:
typedef struct static const FilterSliderData::slider_data_t comp_controls[NUM_CP_CTRL];
{
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[NUM_CP_CTRL];
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];
QGroupBox *compressorBox; QGroupBox *compressorBox;
intf_thread_t *p_intf; intf_thread_t *p_intf;
void updateSliders();
private slots: private slots:
void enable(); void enable();
void setValues();
}; };
class Spatializer: public QWidget class Spatializer: public QWidget
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment