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 )
}
}
/**********************************************************************
* 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
**********************************************************************/
......@@ -1230,7 +1311,7 @@ void Equalizer::addCallbacks( vlc_object_t *p_aout )
* 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-attack", _("Attack"), _(" ms"), 1.5f, 400.0f, 25.00f, 0.100f },
......@@ -1253,61 +1334,33 @@ Compressor::Compressor( intf_thread_t *_p_intf, QWidget *_parent )
layout->addWidget( compressorBox );
QGridLayout *ctrlLayout = new QGridLayout( compressorBox );
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;
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 );
QSlider *slider = new QSlider( Qt::Vertical );
QLabel *valueLabel = new QLabel();
valueLabel->setFont( smallFont );
valueLabel->setAlignment( Qt::AlignHCenter );
QLabel *nameLabel = new QLabel();
nameLabel->setFont( smallFont );
nameLabel->setAlignment( Qt::AlignHCenter );
FilterSliderData *filter =
new FilterSliderData( this, p_intf,
slider, valueLabel, nameLabel, & comp_controls[i] );
ctrlLayout->addWidget( slider, 0, i, Qt::AlignHCenter );
ctrlLayout->addWidget( valueLabel, 1, i, Qt::AlignHCenter );
ctrlLayout->addWidget( nameLabel, 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();
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 )
compressorBox->setChecked( true );
......@@ -1316,8 +1369,6 @@ Compressor::Compressor( intf_thread_t *_p_intf, QWidget *_parent )
CONNECT( compressorBox, toggled(bool), this, enable() );
free( psz_af );
updateSliders();
setValues();
}
void Compressor::enable()
......@@ -1325,42 +1376,6 @@ void Compressor::enable()
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
......
......@@ -83,6 +83,43 @@ private slots:
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
{
Q_OBJECT
......@@ -122,32 +159,12 @@ public:
Compressor( intf_thread_t *, QWidget * );
private:
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[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];
static const FilterSliderData::slider_data_t comp_controls[NUM_CP_CTRL];
QGroupBox *compressorBox;
intf_thread_t *p_intf;
void updateSliders();
private slots:
void enable();
void setValues();
};
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