Commit 33352675 authored by Francois Cartegnie's avatar Francois Cartegnie

Qt: Spatializer: factorize

parent 20fbfbaf
...@@ -997,13 +997,13 @@ void FilterSliderData::writeToConfig() ...@@ -997,13 +997,13 @@ void FilterSliderData::writeToConfig()
AudioFilterControlWidget::AudioFilterControlWidget AudioFilterControlWidget::AudioFilterControlWidget
( intf_thread_t *_p_intf, QWidget *parent, const char *_name ) : ( intf_thread_t *_p_intf, QWidget *parent, const char *_name ) :
QWidget( parent ), p_intf( _p_intf ), name( _name ) QWidget( parent ), p_intf( _p_intf ), name( _name ), i_smallfont(0)
{} {}
void AudioFilterControlWidget::build() void AudioFilterControlWidget::build()
{ {
QFont smallFont = QApplication::font(); QFont smallFont = QApplication::font();
smallFont.setPointSize( smallFont.pointSize() - 2 ); smallFont.setPointSize( smallFont.pointSize() + i_smallfont );
QVBoxLayout *layout = new QVBoxLayout( this ); QVBoxLayout *layout = new QVBoxLayout( this );
slidersBox = new QGroupBox( qtr( "Enable" ) ); slidersBox = new QGroupBox( qtr( "Enable" ) );
...@@ -1379,6 +1379,7 @@ void Equalizer::addCallbacks( vlc_object_t *p_aout ) ...@@ -1379,6 +1379,7 @@ void Equalizer::addCallbacks( vlc_object_t *p_aout )
Compressor::Compressor( intf_thread_t *p_intf, QWidget *parent ) Compressor::Compressor( intf_thread_t *p_intf, QWidget *parent )
: AudioFilterControlWidget( p_intf, parent, "compressor" ) : AudioFilterControlWidget( p_intf, parent, "compressor" )
{ {
i_smallfont = -2;
const FilterSliderData::slider_data_t a[7] = const FilterSliderData::slider_data_t a[7] =
{ {
{ "compressor-rms-peak", qtr("RMS/peak"), "", 0.0f, 1.0f, 0.00f, 0.001f }, { "compressor-rms-peak", qtr("RMS/peak"), "", 0.0f, 1.0f, 0.00f, 0.001f },
...@@ -1396,124 +1397,21 @@ Compressor::Compressor( intf_thread_t *p_intf, QWidget *parent ) ...@@ -1396,124 +1397,21 @@ Compressor::Compressor( intf_thread_t *p_intf, QWidget *parent )
/********************************************************************** /**********************************************************************
* Spatializer * Spatializer
**********************************************************************/ **********************************************************************/
const Spatializer::spat_controls_t Spatializer::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 ) Spatializer::Spatializer( intf_thread_t *p_intf, QWidget *parent )
: QWidget( _parent ) , p_intf( _p_intf ) : AudioFilterControlWidget( p_intf, parent, "spatializer" )
{ {
QFont smallFont = QApplication::font(); i_smallfont = -1;
smallFont.setPointSize( smallFont.pointSize() - 1 ); const FilterSliderData::slider_data_t a[5] =
QVBoxLayout *layout = new QVBoxLayout( this );
spatializerBox = new QGroupBox( qtr( "Enable" ) );
spatializerBox->setCheckable( true );
layout->addWidget( spatializerBox );
QGridLayout *ctrlLayout = new QGridLayout( spatializerBox );
for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
{
spatCtrl[i] = new QSlider( Qt::Vertical );
spatCtrl[i]->setValue( (int)var_InheritFloat( p_intf, spat_controls[i].psz_name ) * 10. );
oldControlVars[i] = spatCtrl[i]->value();
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]->setFont( smallFont );
ctrlLayout->addWidget( spatCtrl[i], 0, i, Qt::AlignHCenter );
ctrlLayout->addWidget( ctrl_readout[i], 1, i, Qt::AlignHCenter );
ctrlLayout->addWidget( ctrl_texts[i], 2, i, Qt::AlignHCenter );
spatCtrl[i]->setRange( 0, 10 );
}
spatCtrl[0]->setRange( 0, 11 );
for( int i = 0; i < NUM_SP_CTRL; i++ )
CONNECT( spatCtrl[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_SP_CTRL ; i++ )
{ {
controlVars[i] = var_GetFloat( p_aout, spat_controls[i].psz_name ); { "spatializer-roomsize", qtr("Size"), "", 0.0f, 11.0f, 0.0f, 1.0f },
} { "spatializer-width", qtr("Width"), "", 0.0f, 10.0f, 0.0f, 1.0f },
vlc_object_release( p_aout ); { "spatializer-wet", qtr("Wet"), "", 0.0f, 10.0f, 0.0f, 1.0f },
} { "spatializer-dry", qtr("Dry"), "", 0.0f, 10.0f, 0.0f, 1.0f },
else { "spatializer-damp", qtr("Damp"), "", 0.0f, 10.0f, 0.0f, 1.0f },
{ };
psz_af = config_GetPsz( p_intf, "audio-filter" ); for( int i=0; i<5 ;i++ ) controls.append( a[i] );
for( int i = 0; i < NUM_SP_CTRL ; i++ ) build();
{
controlVars[i] = config_GetFloat( p_intf, spat_controls[i].psz_name );
}
}
if( psz_af && strstr( psz_af, "spatializer" ) != NULL )
spatializerBox->setChecked( true );
else
spatializerBox->setChecked( false );
CONNECT( spatializerBox, toggled(bool), this, enable() );
free( psz_af );
setValues();
}
void Spatializer::enable()
{
playlist_EnableAudioFilter( THEPL, "spatializer", spatializerBox->isChecked() );
}
void Spatializer::setValues()
{
vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
{
float f = (float)( spatCtrl[i]->value() ) / 10;
ctrl_readout[i]->setText( QString::number( f, 'f', 1 ) );
}
if( p_aout )
{
for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
{
float f = (float)( spatCtrl[i]->value() ) / 10 ;
if( oldControlVars[i] != spatCtrl[i]->value() )
{
var_SetFloat( p_aout, spat_controls[i].psz_name, f );
config_PutFloat( p_intf, spat_controls[i].psz_name, f );
oldControlVars[i] = spatCtrl[i]->value();
}
}
vlc_object_release( p_aout );
}
}
void Spatializer::delCallbacks( vlc_object_t *p_aout )
{
VLC_UNUSED( p_aout );
// var_DelCallback( p_aout, "Spatializer-bands", EqzCallback, this );
// var_DelCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
}
void Spatializer::addCallbacks( vlc_object_t *p_aout )
{
VLC_UNUSED( p_aout );
// var_AddCallback( p_aout, "Spatializer-bands", EqzCallback, this );
// var_AddCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
} }
#include <QToolButton> #include <QToolButton>
......
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include <QTabWidget> #include <QTabWidget>
#define BANDS 10 #define BANDS 10
#define NUM_SP_CTRL 5
class QSignalMapper; class QSignalMapper;
...@@ -133,6 +132,7 @@ protected: ...@@ -133,6 +132,7 @@ protected:
QGroupBox *slidersBox; QGroupBox *slidersBox;
intf_thread_t *p_intf; intf_thread_t *p_intf;
QString name; // filter's module name QString name; // filter's module name
int i_smallfont;
protected slots: protected slots:
void enable(); void enable();
...@@ -177,35 +177,12 @@ public: ...@@ -177,35 +177,12 @@ public:
Compressor( intf_thread_t *, QWidget * ); Compressor( intf_thread_t *, QWidget * );
}; };
class Spatializer: public QWidget class Spatializer: public AudioFilterControlWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
Spatializer( intf_thread_t *, QWidget * ); Spatializer( intf_thread_t *, QWidget * );
private:
typedef struct
{
const char *psz_name;
const char *psz_desc;
} spat_controls_t;
static const spat_controls_t spat_controls[NUM_SP_CTRL];
QSlider *spatCtrl[NUM_SP_CTRL];
QLabel *ctrl_texts[NUM_SP_CTRL];
QLabel *ctrl_readout[NUM_SP_CTRL];
float controlVars[NUM_SP_CTRL];
float oldControlVars[NUM_SP_CTRL];
QGroupBox *spatializerBox;
void delCallbacks( vlc_object_t * );
void addCallbacks( vlc_object_t * );
intf_thread_t *p_intf;
private slots:
void enable();
void setValues();
}; };
class SyncWidget : public QWidget class SyncWidget : 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