diff --git a/plugins/Eq/CMakeLists.txt b/plugins/Eq/CMakeLists.txt index 17af33ff7..1414b5194 100644 --- a/plugins/Eq/CMakeLists.txt +++ b/plugins/Eq/CMakeLists.txt @@ -2,5 +2,5 @@ INCLUDE(BuildPlugin) INCLUDE_DIRECTORIES(${FFTW3F_INCLUDE_DIRS}) LINK_DIRECTORIES(${FFTW3F_LIBRARY_DIRS}) LINK_LIBRARIES(${FFTW3F_LIBRARIES}) -BUILD_PLUGIN(eq EqEffect.cpp EqCurve.cpp EqCurve.h EqControls.cpp EqControlsDialog.cpp EqFilter.h EqParameterWidget.cpp EqFader.h EqSpectrumView.h -MOCFILES EqControls.h EqControlsDialog.h EqCurve.h EqParameterWidget.h EqFader.h EMBEDDED_RESOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.png") +BUILD_PLUGIN(eq EqEffect.cpp EqCurve.cpp EqCurve.h EqControls.cpp EqControlsDialog.cpp EqFilter.h EqParameterWidget.cpp EqFader.h EqSpectrumView.h EqSpectrumView.cpp +MOCFILES EqControls.h EqControlsDialog.h EqCurve.h EqParameterWidget.h EqFader.h EqSpectrumView.h EMBEDDED_RESOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.png") diff --git a/plugins/Eq/EqControls.cpp b/plugins/Eq/EqControls.cpp index 465724c8e..8a58e2892 100644 --- a/plugins/Eq/EqControls.cpp +++ b/plugins/Eq/EqControls.cpp @@ -22,8 +22,10 @@ * */ -#include #include "EqControls.h" + +#include + #include "EqEffect.h" @@ -35,12 +37,12 @@ EqControls::EqControls( EqEffect *effect ) : m_inGainModel( 0.0, -60.0, 20.0, 0.01, this, tr( "Input gain") ), m_outGainModel( -.0, -60.0, 20.0, 0.01, this, tr( "Output gain" ) ), m_lowShelfGainModel( 0.0 , -18, 18, 0.001, this, tr( "Low shelf gain" ) ), - m_para1GainModel( 0.0 , -18, 18, 0.001, this, tr( "Peak 1 gain" ) ), - m_para2GainModel( 0.0 , -18, 18, 0.001, this, tr( "Peak 2 gain" ) ), - m_para3GainModel( 0.0 , -18, 18, 0.001, this, tr( "Peak 3 gain" ) ), - m_para4GainModel( 0.0 , -18, 18, 0.001, this, tr( "Peak 4 gain" ) ), - m_highShelfGainModel( 0.0 , -18, 18, 0.001, this, tr( "High Shelf gain" ) ), - m_hpResModel( 0.707,0.003, 10.0 , 0.001, this, tr( "HP res" ) ), + m_para1GainModel( 0.0 , -18, 18, 0.001, this, tr( "Peak 1 gain" ) ), + m_para2GainModel( 0.0 , -18, 18, 0.001, this, tr( "Peak 2 gain" ) ), + m_para3GainModel( 0.0 , -18, 18, 0.001, this, tr( "Peak 3 gain" ) ), + m_para4GainModel( 0.0 , -18, 18, 0.001, this, tr( "Peak 4 gain" ) ), + m_highShelfGainModel( 0.0 , -18, 18, 0.001, this, tr( "High Shelf gain" ) ), + m_hpResModel( 0.707,0.003, 10.0 , 0.001, this, tr( "HP res" ) ), m_lowShelfResModel( 1.4,0.55, 10.0 , 0.001, this , tr( "Low Shelf res" ) ), m_para1BwModel( 0.3, 0.1, 4 , 0.001, this , tr( "Peak 1 BW" ) ), m_para2BwModel( 0.3, 0.1, 4 , 0.001, this , tr( "Peak 2 BW" ) ), @@ -58,7 +60,7 @@ EqControls::EqControls( EqEffect *effect ) : m_lpFreqModel( 18000.0, 27.0, 20000, 0.001, this , tr( "LP freq" ) ), m_hpActiveModel( false, this , tr( "HP active" ) ), m_lowShelfActiveModel( false, this , tr( "Low shelf active" ) ), - m_para1ActiveModel(false, this , tr( "Peak 1 active" ) ), + m_para1ActiveModel( false, this , tr( "Peak 1 active" ) ), m_para2ActiveModel( false, this , tr( "Peak 2 active" ) ), m_para3ActiveModel( false, this , tr( "Peak 3 active" ) ), m_para4ActiveModel( false, this , tr( "Peak 4 active" ) ), @@ -70,10 +72,10 @@ EqControls::EqControls( EqEffect *effect ) : m_hp12Model( false, this , tr( "HP 12" ) ), m_hp24Model( false, this , tr( "HP 24" ) ), m_hp48Model( false, this , tr( "HP 48" ) ), - m_lpTypeModel( 0,0,2,this, tr( "low pass type") ) , - m_hpTypeModel( 0,0,2,this, tr( "high pass type") ), - m_analyseInModel( true, this , tr( "Analyse IN")), - m_analyseOutModel( true, this, tr( "Analyse OUT")) + m_lpTypeModel( 0,0,2, this, tr( "low pass type" ) ) , + m_hpTypeModel( 0,0,2, this, tr( "high pass type" ) ), + m_analyseInModel( true, this , tr( "Analyse IN" ) ), + m_analyseOutModel( true, this, tr( "Analyse OUT" ) ) { m_hpFeqModel.setScaleLogarithmic( true ); m_lowShelfFreqModel.setScaleLogarithmic( true ); @@ -104,21 +106,21 @@ EqControls::EqControls( EqEffect *effect ) : void EqControls::loadSettings( const QDomElement &_this ) { m_inGainModel.loadSettings( _this, "Inputgain" ); - m_outGainModel.loadSettings( _this, "Outputgain"); + m_outGainModel.loadSettings( _this, "Outputgain" ); m_lowShelfGainModel.loadSettings( _this , "Lowshelfgain" ); m_para1GainModel.loadSettings( _this, "Peak1gain" ); m_para2GainModel.loadSettings( _this, "Peak2gain" ); m_para3GainModel.loadSettings( _this, "Peak3gain" ); m_para4GainModel.loadSettings( _this, "Peak4gain" ); - m_highShelfGainModel.loadSettings( _this , "HighShelfgain"); - m_hpResModel.loadSettings( _this ,"HPres"); + m_highShelfGainModel.loadSettings( _this , "HighShelfgain" ); + m_hpResModel.loadSettings( _this ,"HPres" ); m_lowShelfResModel.loadSettings( _this, "LowShelfres" ); m_para1BwModel.loadSettings( _this ,"Peak1bw" ); m_para2BwModel.loadSettings( _this ,"Peak2bw" ); m_para3BwModel.loadSettings( _this ,"Peak3bw" ); m_para4BwModel.loadSettings( _this ,"Peak4bw" ); m_highShelfResModel.loadSettings( _this, "HighShelfres" ); - m_lpResModel.loadSettings( _this, "LPres"); + m_lpResModel.loadSettings( _this, "LPres" ); m_hpFeqModel.loadSettings( _this, "HPfreq" ); m_lowShelfFreqModel.loadSettings( _this, "LowShelffreq" ); m_para1FreqModel.loadSettings( _this, "Peak1freq" ); @@ -129,10 +131,10 @@ void EqControls::loadSettings( const QDomElement &_this ) m_lpFreqModel.loadSettings( _this, "LPfreq" ); m_hpActiveModel.loadSettings( _this, "HPactive" ); m_lowShelfActiveModel.loadSettings( _this, "Lowshelfactive" ); - m_para1ActiveModel.loadSettings( _this, "Peak1active"); - m_para2ActiveModel.loadSettings( _this, "Peak2active"); - m_para3ActiveModel.loadSettings( _this, "Peak3active"); - m_para4ActiveModel.loadSettings( _this, "Peak4active"); + m_para1ActiveModel.loadSettings( _this, "Peak1active" ); + m_para2ActiveModel.loadSettings( _this, "Peak2active" ); + m_para3ActiveModel.loadSettings( _this, "Peak3active" ); + m_para4ActiveModel.loadSettings( _this, "Peak4active" ); m_highShelfActiveModel.loadSettings( _this, "Highshelfactive" ); m_lpActiveModel.loadSettings( _this, "LPactive" ); m_lp12Model.loadSettings( _this , "LP12" ); @@ -143,8 +145,8 @@ void EqControls::loadSettings( const QDomElement &_this ) m_hp48Model.loadSettings( _this , "HP48" ); m_lpTypeModel.loadSettings( _this, "LP" ); m_hpTypeModel.loadSettings( _this, "HP" ); - m_analyseInModel.loadSettings( _this, "AnalyseIn"); - m_analyseOutModel.loadSettings( _this, "AnalyseOut"); + m_analyseInModel.loadSettings( _this, "AnalyseIn" ); + m_analyseOutModel.loadSettings( _this, "AnalyseOut" ); } @@ -152,7 +154,6 @@ void EqControls::loadSettings( const QDomElement &_this ) void EqControls::saveSettings( QDomDocument &doc, QDomElement &parent ) { - m_inGainModel.saveSettings( doc, parent, "Inputgain" ); m_outGainModel.saveSettings( doc, parent, "Outputgain"); m_lowShelfGainModel.saveSettings( doc, parent , "Lowshelfgain" ); @@ -160,15 +161,15 @@ void EqControls::saveSettings( QDomDocument &doc, QDomElement &parent ) m_para2GainModel.saveSettings( doc, parent, "Peak2gain" ); m_para3GainModel.saveSettings( doc, parent, "Peak3gain" ); m_para4GainModel.saveSettings( doc, parent, "Peak4gain" ); - m_highShelfGainModel.saveSettings( doc, parent, "HighShelfgain"); - m_hpResModel.saveSettings( doc, parent ,"HPres"); + m_highShelfGainModel.saveSettings( doc, parent, "HighShelfgain" ); + m_hpResModel.saveSettings( doc, parent ,"HPres" ); m_lowShelfResModel.saveSettings( doc, parent, "LowShelfres" ); m_para1BwModel.saveSettings( doc, parent,"Peak1bw" ); m_para2BwModel.saveSettings( doc, parent,"Peak2bw" ); m_para3BwModel.saveSettings( doc, parent,"Peak3bw" ); m_para4BwModel.saveSettings( doc, parent,"Peak4bw" ); m_highShelfResModel.saveSettings( doc, parent, "HighShelfres" ); - m_lpResModel.saveSettings( doc, parent, "LPres"); + m_lpResModel.saveSettings( doc, parent, "LPres" ); m_hpFeqModel.saveSettings( doc, parent, "HPfreq" ); m_lowShelfFreqModel.saveSettings( doc, parent, "LowShelffreq" ); m_para1FreqModel.saveSettings( doc, parent, "Peak1freq" ); @@ -193,7 +194,6 @@ void EqControls::saveSettings( QDomDocument &doc, QDomElement &parent ) m_hp48Model.saveSettings( doc, parent, "HP48" ); m_lpTypeModel.saveSettings( doc, parent, "LP" ); m_hpTypeModel.saveSettings( doc, parent, "HP" ); - m_analyseInModel.saveSettings( doc, parent, "AnalyseIn"); - m_analyseOutModel.saveSettings( doc, parent, "AnalyseOut"); + m_analyseInModel.saveSettings( doc, parent, "AnalyseIn" ); + m_analyseOutModel.saveSettings( doc, parent, "AnalyseOut" ); } - diff --git a/plugins/Eq/EqControls.h b/plugins/Eq/EqControls.h index 3bd3ab78b..0f4dbd855 100644 --- a/plugins/Eq/EqControls.h +++ b/plugins/Eq/EqControls.h @@ -27,12 +27,10 @@ #include "EffectControls.h" #include "EqControlsDialog.h" -#include "Knob.h" class EqEffect; - class EqControls : public EffectControls { Q_OBJECT @@ -53,7 +51,7 @@ public: virtual int controlCount() { - return 39; + return 42; } virtual EffectControlDialog* createView() @@ -79,7 +77,7 @@ public: bool visable(); private: - EqEffect* m_effect; + EqEffect *m_effect; FloatModel m_inGainModel; FloatModel m_outGainModel; diff --git a/plugins/Eq/EqControlsDialog.cpp b/plugins/Eq/EqControlsDialog.cpp index f2d8529f3..65b433c54 100644 --- a/plugins/Eq/EqControlsDialog.cpp +++ b/plugins/Eq/EqControlsDialog.cpp @@ -24,37 +24,38 @@ #include "EqControlsDialog.h" -#include "EqControls.h" -#include "embed.h" -#include "Fader.h" -#include "EqFader.h" -#include "Engine.h" -#include "AutomatableButton.h" -#include "LedCheckbox.h" + #include #include #include +#include "AutomatableButton.h" +#include "embed.h" +#include "Engine.h" +#include "EqControls.h" +#include "EqFader.h" +#include "Fader.h" +#include "LedCheckbox.h" + EqControlsDialog::EqControlsDialog( EqControls *controls ) : - EffectControlDialog( controls ) - + EffectControlDialog( controls ), + m_controls( controls ) { - m_controls = controls; setAutoFillBackground( true ); QPalette pal; pal.setBrush( backgroundRole(), PLUGIN_NAME::getIconPixmap( "EqLayout1BG" ) ); setPalette( pal ); setFixedSize( 500, 500 ); - QGridLayout * mainLayout = new QGridLayout( this ); + QGridLayout *mainLayout = new QGridLayout( this ); - m_inSpec = new EqSpectrumView( &controls->m_inFftBands, this ); - mainLayout->addWidget( m_inSpec, 0, 1, 1, 8 ); - m_inSpec->color = QColor( 238, 154, 120, 80 ); + EqSpectrumView *inSpec = new EqSpectrumView( &controls->m_inFftBands, this ); + mainLayout->addWidget( inSpec, 0, 1, 1, 8 ); + inSpec->setColor( QColor( 238, 154, 120, 80 ) ); - m_outSpec = new EqSpectrumView( &controls->m_outFftBands, this ); - m_outSpec->color = QColor( 145, 205, 22, 80 ); - mainLayout->addWidget( m_outSpec, 0, 1, 1, 8 ); + EqSpectrumView *outSpec = new EqSpectrumView( &controls->m_outFftBands, this ); + outSpec->setColor( QColor( 145, 205, 22, 80 ) ); + mainLayout->addWidget( outSpec, 0, 1, 1, 8 ); m_parameterWidget = new EqParameterWidget( this , controls ); mainLayout->addWidget( m_parameterWidget, 0, 1, 1, 8 ); @@ -68,238 +69,215 @@ EqControlsDialog::EqControlsDialog( EqControls *controls ) : setBand( 6, &controls->m_highShelfActiveModel, &controls->m_highShelfFreqModel, &controls->m_highShelfResModel, &controls->m_highShelfGainModel, QColor(255 ,255, 255), tr( "High Shelf" ), &controls->m_highShelfPeakL, &controls->m_highShelfPeakR,0,0,0,0,0,0 ); setBand( 7, &controls->m_lpActiveModel, &controls->m_lpFreqModel, &controls->m_lpResModel, 0, QColor(255 ,255, 255), tr( "LP" ) ,0,0,0,0,0, &controls->m_lp12Model, &controls->m_lp24Model, &controls->m_lp48Model); - m_inGainFader = new EqFader( &controls->m_inGainModel, tr( "In Gain" ), this, - &controls->m_inPeakL, &controls->m_inPeakR ); + EqFader *inGainFader = new EqFader( &controls->m_inGainModel, tr( "In Gain" ), this, &controls->m_inPeakL, &controls->m_inPeakR ); + mainLayout->addWidget( inGainFader, 0, 0 ); + inGainFader->setDisplayConversion( false ); + inGainFader->setHintText( tr( "Gain" ), "dBv"); - mainLayout->addWidget( m_inGainFader, 0, 0 ); - m_inGainFader->setDisplayConversion( false ); - m_inGainFader->setHintText( tr( "Gain" ), "dBv"); - - m_outGainFader = new EqFader( &controls->m_outGainModel, tr( "Out Gain" ), this, - &controls->m_outPeakL, &controls->m_outPeakR ); - mainLayout->addWidget( m_outGainFader, 0, 9 ); - m_outGainFader->setDisplayConversion( false ); - m_outGainFader->setHintText( tr( "Gain" ), "dBv" ); + EqFader *outGainFader = new EqFader( &controls->m_outGainModel, tr( "Out Gain" ), this, &controls->m_outPeakL, &controls->m_outPeakR ); + mainLayout->addWidget( outGainFader, 0, 9 ); + outGainFader->setDisplayConversion( false ); + outGainFader->setHintText( tr( "Gain" ), "dBv" ); // Gain Fader for each Filter exepts the pass filter for( int i = 1; i < m_parameterWidget->bandCount() - 1; i++ ) { - m_gainFader = new EqFader( m_parameterWidget->getBandModels( i )->gain, tr( "" ), this, + EqFader *gainFader = new EqFader( m_parameterWidget->getBandModels( i )->gain, tr( "" ), this, m_parameterWidget->getBandModels( i )->peakL, m_parameterWidget->getBandModels( i )->peakR ); - mainLayout->addWidget( m_gainFader, 2, i+1 ); - mainLayout->setAlignment( m_gainFader, Qt::AlignHCenter ); - m_gainFader->setMinimumHeight(80); - m_gainFader->resize(m_gainFader->width() , 80); - m_gainFader->setDisplayConversion( false ); - m_gainFader->setHintText( tr( "Gain") , "dB"); + mainLayout->addWidget( gainFader, 2, i+1 ); + mainLayout->setAlignment( gainFader, Qt::AlignHCenter ); + gainFader->setMinimumHeight(80); + gainFader->resize(gainFader->width() , 80); + gainFader->setDisplayConversion( false ); + gainFader->setHintText( tr( "Gain") , "dB"); } //Control Button and Knobs for each Band for( int i = 0; i < m_parameterWidget->bandCount() ; i++ ) { - m_resKnob = new Knob( knobBright_26, this ); + Knob *resKnob = new Knob( knobBright_26, this ); mainLayout->setRowMinimumHeight( 4, 33 ); - mainLayout->addWidget( m_resKnob, 5, i+1 ); - mainLayout->setAlignment( m_resKnob, Qt::AlignHCenter ); - m_resKnob->setVolumeKnob(false); - m_resKnob->setModel( m_parameterWidget->getBandModels( i )->res ); - if(i > 1 && i < 6) { m_resKnob->setHintText( tr( "Bandwidth: " ) , tr( " Octave" ) ); } - else { m_resKnob->setHintText( tr( "Resonance : " ) , "" ); } + mainLayout->addWidget( resKnob, 5, i + 1 ); + mainLayout->setAlignment( resKnob, Qt::AlignHCenter ); + resKnob->setVolumeKnob(false); + resKnob->setModel( m_parameterWidget->getBandModels( i )->res ); + if(i > 1 && i < 6) { resKnob->setHintText( tr( "Bandwidth: " ) , tr( " Octave" ) ); } + else { resKnob->setHintText( tr( "Resonance : " ) , "" ); } - m_freqKnob = new Knob( knobBright_26, this ); - mainLayout->addWidget( m_freqKnob, 3, i+1 ); - mainLayout->setAlignment( m_freqKnob, Qt::AlignHCenter ); - m_freqKnob->setVolumeKnob( false ); - m_freqKnob->setModel( m_parameterWidget->getBandModels( i )->freq ); - m_freqKnob->setHintText( tr( "Frequency:" ), "Hz" ); + Knob *freqKnob = new Knob( knobBright_26, this ); + mainLayout->addWidget( freqKnob, 3, i+1 ); + mainLayout->setAlignment( freqKnob, Qt::AlignHCenter ); + freqKnob->setVolumeKnob( false ); + freqKnob->setModel( m_parameterWidget->getBandModels( i )->freq ); + freqKnob->setHintText( tr( "Frequency:" ), "Hz" ); // adds the Number Active buttons - m_activeBox = new PixmapButton( this, NULL ); - m_activeBox->setCheckable(true); - m_activeBox->setModel( m_parameterWidget->getBandModels( i )->active ); - + PixmapButton *activeNumButton = new PixmapButton( this, NULL ); + activeNumButton->setCheckable(true); + activeNumButton->setModel( m_parameterWidget->getBandModels( i )->active ); QString iconActiveFileName = "bandLabel" + QString::number(i+1) + "on"; QString iconInactiveFileName = "bandLabel" + QString::number(i+1); - m_activeBox->setActiveGraphic( PLUGIN_NAME::getIconPixmap( iconActiveFileName.toLatin1() ) ); - m_activeBox->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( iconInactiveFileName.toLatin1() ) ); - - mainLayout->addWidget( m_activeBox, 1, i+1 ); - mainLayout->setAlignment( m_activeBox, Qt::AlignHCenter ); - m_activeBox->setModel( m_parameterWidget->getBandModels( i )->active ); + activeNumButton->setActiveGraphic( PLUGIN_NAME::getIconPixmap( iconActiveFileName.toLatin1() ) ); + activeNumButton->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( iconInactiveFileName.toLatin1() ) ); + mainLayout->addWidget( activeNumButton, 1, i+1 ); + mainLayout->setAlignment( activeNumButton, Qt::AlignHCenter ); + activeNumButton->setModel( m_parameterWidget->getBandModels( i )->active ); // adds the symbols active buttons - m_activeBox = new PixmapButton( this, NULL ); - m_activeBox->setCheckable(true); - m_activeBox->setModel( m_parameterWidget->getBandModels( i )->active ); + PixmapButton *activeButton = new PixmapButton( this, NULL ); + activeButton->setCheckable(true); + activeButton->setModel( m_parameterWidget->getBandModels( i )->active ); switch (i) { case 0: - m_activeBox->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "ActiveHP" ) ); - m_activeBox->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( "ActiveHPoff" ) ); + activeButton->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "ActiveHP" ) ); + activeButton->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( "ActiveHPoff" ) ); break; case 1: - m_activeBox->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "ActiveLS" ) ); - m_activeBox->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( "ActiveLSoff" ) ); + activeButton->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "ActiveLS" ) ); + activeButton->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( "ActiveLSoff" ) ); break; case 6: - m_activeBox->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "ActiveHS" ) ); - m_activeBox->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( "ActiveHSoff" ) ); + activeButton->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "ActiveHS" ) ); + activeButton->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( "ActiveHSoff" ) ); break; case 7: - m_activeBox->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "ActiveLP" ) ); - m_activeBox->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( "ActiveLPoff" ) ); + activeButton->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "ActiveLP" ) ); + activeButton->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( "ActiveLPoff" ) ); break; default: - m_activeBox->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "ActivePeak" ) ); - m_activeBox->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( "ActivePeakoff" ) ); + activeButton->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "ActivePeak" ) ); + activeButton->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( "ActivePeakoff" ) ); } - mainLayout->addWidget( m_activeBox, 7, i+1 ); - mainLayout->setAlignment( m_activeBox, Qt::AlignHCenter); - m_activeBox->setModel( m_parameterWidget->getBandModels( i )->active ); + mainLayout->addWidget( activeButton, 7, i+1 ); + mainLayout->setAlignment( activeButton, Qt::AlignHCenter); + activeButton->setModel( m_parameterWidget->getBandModels( i )->active ); // Connects the knobs, Faders and buttons with the curve graphic - QObject::connect( m_parameterWidget->getBandModels( i )->freq , SIGNAL( dataChanged() ), m_parameterWidget, SLOT ( updateView() ) ); - if ( m_parameterWidget->getBandModels( i )->gain ) QObject::connect( m_parameterWidget->getBandModels( i )->gain, SIGNAL( dataChanged() ), m_parameterWidget, SLOT ( updateView() )); - QObject::connect( m_parameterWidget->getBandModels( i )->res, SIGNAL( dataChanged() ), m_parameterWidget , SLOT ( updateView() ) ); - QObject::connect( m_parameterWidget->getBandModels( i )->active, SIGNAL( dataChanged() ), m_parameterWidget , SLOT ( updateView() ) ); + QObject::connect( m_parameterWidget->getBandModels( i )->freq , SIGNAL( dataChanged() ), m_parameterWidget, SLOT ( updateHandle() ) ); + if ( m_parameterWidget->getBandModels( i )->gain ) QObject::connect( m_parameterWidget->getBandModels( i )->gain, SIGNAL( dataChanged() ), m_parameterWidget, SLOT ( updateHandle() )); + QObject::connect( m_parameterWidget->getBandModels( i )->res, SIGNAL( dataChanged() ), m_parameterWidget , SLOT ( updateHandle() ) ); + QObject::connect( m_parameterWidget->getBandModels( i )->active, SIGNAL( dataChanged() ), m_parameterWidget , SLOT ( updateHandle() ) ); m_parameterWidget->changeHandle( i ); } - // adds the buttons for Spectrum analyser on/off - m_inSpecB = new PixmapButton(this, NULL); - m_inSpecB->setActiveGraphic( PLUGIN_NAME::getIconPixmap( - "ActiveAnalyse" ) ); - m_inSpecB->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( - "ActiveAnalyseoff" ) ); - m_inSpecB->setCheckable(true); - m_inSpecB->setModel( &controls->m_analyseInModel ); + PixmapButton *inSpecB = new PixmapButton(this, NULL); + inSpecB->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "ActiveAnalyse" ) ); + inSpecB->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( "ActiveAnalyseoff" ) ); + inSpecB->setCheckable( true ); + inSpecB->setModel( &controls->m_analyseInModel ); - m_outSpecB = new PixmapButton(this, NULL); - m_outSpecB->setActiveGraphic( PLUGIN_NAME::getIconPixmap( - "ActiveAnalyse" ) ); - m_outSpecB->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( - "ActiveAnalyseoff" ) ); - m_outSpecB->setCheckable(true); - m_outSpecB->setModel( &controls->m_analyseOutModel ); - mainLayout->addWidget( m_inSpecB, 1, 0 ); - mainLayout->addWidget( m_outSpecB, 1, 9 ); - mainLayout->setAlignment( m_inSpecB, Qt::AlignHCenter ); - mainLayout->setAlignment( m_outSpecB, Qt::AlignHCenter ); + PixmapButton *outSpecB = new PixmapButton(this, NULL); + outSpecB->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "ActiveAnalyse" ) ); + outSpecB->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( "ActiveAnalyseoff" ) ); + outSpecB->setCheckable( true ); + outSpecB->setModel( &controls->m_analyseOutModel ); + mainLayout->addWidget( inSpecB, 1, 0 ); + mainLayout->addWidget( outSpecB, 1, 9 ); + mainLayout->setAlignment( inSpecB, Qt::AlignHCenter ); + mainLayout->setAlignment( outSpecB, Qt::AlignHCenter ); //hp filter type - m_hp12Box = new PixmapButton( this , NULL ); - m_hp12Box->setModel( m_parameterWidget->getBandModels( 0 )->hp12 ); - m_hp12Box->setActiveGraphic( PLUGIN_NAME::getIconPixmap( - "12dB" ) ); - m_hp12Box->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( - "12dBoff" ) ); + PixmapButton *hp12Button = new PixmapButton( this , NULL ); + hp12Button->setModel( m_parameterWidget->getBandModels( 0 )->hp12 ); + hp12Button->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "12dB" ) ); + hp12Button->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( "12dBoff" ) ); - m_hp24Box = new PixmapButton( this , NULL ); - m_hp24Box->setModel(m_parameterWidget->getBandModels( 0 )->hp24 ); + PixmapButton *hp24Button = new PixmapButton( this , NULL ); + hp24Button->setModel(m_parameterWidget->getBandModels( 0 )->hp24 ); + hp24Button->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "24dB" ) ); + hp24Button->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( "24dBoff" ) ); - - m_hp24Box->setActiveGraphic( PLUGIN_NAME::getIconPixmap( - "24dB" ) ); - m_hp24Box->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( - "24dBoff" ) ); - - m_hp48Box = new PixmapButton( this , NULL ); - m_hp48Box->setModel( m_parameterWidget->getBandModels(0)->hp48 ); - - m_hp48Box->setActiveGraphic( PLUGIN_NAME::getIconPixmap( - "48dB" ) ); - m_hp48Box->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( - "48dBoff" ) ); + PixmapButton *hp48Button = new PixmapButton( this , NULL ); + hp48Button->setModel( m_parameterWidget->getBandModels(0)->hp48 ); + hp48Button->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "48dB" ) ); + hp48Button->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( "48dBoff" ) ); //LP filter type - m_lp12Box = new PixmapButton( this , NULL ); - mainLayout->addWidget( m_lp12Box, 2,1 ); - m_lp12Box->setModel( m_parameterWidget->getBandModels( 7 )->lp12 ); - m_lp12Box->setActiveGraphic( PLUGIN_NAME::getIconPixmap( - "12dB" ) ); - m_lp12Box->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( - "12dBoff" ) ); + PixmapButton *lp12Button = new PixmapButton( this , NULL ); + mainLayout->addWidget( lp12Button, 2, 1 ); + lp12Button->setModel( m_parameterWidget->getBandModels( 7 )->lp12 ); + lp12Button->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "12dB" ) ); + lp12Button->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( "12dBoff" ) ); - m_lp24Box = new PixmapButton( this , NULL ); - m_lp24Box->setModel( m_parameterWidget->getBandModels( 7 )->lp24 ); - m_lp24Box->setActiveGraphic( PLUGIN_NAME::getIconPixmap( - "24dB" ) ); - m_lp24Box->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( - "24dBoff" ) ); + PixmapButton *lp24Button = new PixmapButton( this , NULL ); + lp24Button->setModel( m_parameterWidget->getBandModels( 7 )->lp24 ); + lp24Button->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "24dB" ) ); + lp24Button->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( "24dBoff" ) ); + + PixmapButton *lp48Button = new PixmapButton( this , NULL ); + lp48Button->setModel( m_parameterWidget->getBandModels( 7 )->lp48 ); + lp48Button->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "48dB" ) ); + lp48Button->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( "48dBoff" ) ); - m_lp48Box = new PixmapButton( this , NULL ); - m_lp48Box->setModel( m_parameterWidget->getBandModels( 7 )->lp48 ); - m_lp48Box->setActiveGraphic( PLUGIN_NAME::getIconPixmap( - "48dB" ) ); - m_lp48Box->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( - "48dBoff" ) ); // the curve has to change its appearance - QObject::connect( m_parameterWidget->getBandModels( 0 )->hp12 , SIGNAL ( dataChanged() ), m_parameterWidget, SLOT( updateView())); - QObject::connect( m_parameterWidget->getBandModels( 0 )->hp24 , SIGNAL ( dataChanged() ), m_parameterWidget, SLOT( updateView())); - QObject::connect( m_parameterWidget->getBandModels( 0 )->hp48 , SIGNAL ( dataChanged() ), m_parameterWidget, SLOT( updateView())); + connect( m_parameterWidget->getBandModels( 0 )->hp12 , SIGNAL ( dataChanged() ), m_parameterWidget, SLOT( updateHandle())); + connect( m_parameterWidget->getBandModels( 0 )->hp24 , SIGNAL ( dataChanged() ), m_parameterWidget, SLOT( updateHandle())); + connect( m_parameterWidget->getBandModels( 0 )->hp48 , SIGNAL ( dataChanged() ), m_parameterWidget, SLOT( updateHandle())); - QObject::connect( m_parameterWidget->getBandModels( 7 )->lp12 , SIGNAL ( dataChanged() ), m_parameterWidget, SLOT( updateView())); - QObject::connect( m_parameterWidget->getBandModels( 7 )->lp24 , SIGNAL ( dataChanged() ), m_parameterWidget, SLOT( updateView())); - QObject::connect( m_parameterWidget->getBandModels( 7 )->lp48 , SIGNAL ( dataChanged() ), m_parameterWidget, SLOT( updateView())); + connect( m_parameterWidget->getBandModels( 7 )->lp12 , SIGNAL ( dataChanged() ), m_parameterWidget, SLOT( updateHandle())); + connect( m_parameterWidget->getBandModels( 7 )->lp24 , SIGNAL ( dataChanged() ), m_parameterWidget, SLOT( updateHandle())); + connect( m_parameterWidget->getBandModels( 7 )->lp48 , SIGNAL ( dataChanged() ), m_parameterWidget, SLOT( updateHandle())); - QVBoxLayout * hpGrpBtnLayout = new QVBoxLayout; - hpGrpBtnLayout->addWidget( m_hp12Box ); - hpGrpBtnLayout->addWidget( m_hp24Box ); - hpGrpBtnLayout->addWidget( m_hp48Box ); + QVBoxLayout *hpGrpBtnLayout = new QVBoxLayout; + hpGrpBtnLayout->addWidget( hp12Button ); + hpGrpBtnLayout->addWidget( hp24Button ); + hpGrpBtnLayout->addWidget( hp48Button ); - QVBoxLayout * lpGrpBtnLayout = new QVBoxLayout; - lpGrpBtnLayout->addWidget( m_lp12Box ); - lpGrpBtnLayout->addWidget( m_lp24Box ); - lpGrpBtnLayout->addWidget( m_lp48Box ); + QVBoxLayout *lpGrpBtnLayout = new QVBoxLayout; + lpGrpBtnLayout->addWidget( lp12Button ); + lpGrpBtnLayout->addWidget( lp24Button ); + lpGrpBtnLayout->addWidget( lp48Button ); mainLayout->addLayout( hpGrpBtnLayout, 2, 1, Qt::AlignCenter ); mainLayout->addLayout( lpGrpBtnLayout, 2, 8, Qt::AlignCenter ); automatableButtonGroup *lpBtnGrp = new automatableButtonGroup(this,tr ( "lp grp" ) ); - lpBtnGrp->addButton( m_lp12Box ); - lpBtnGrp->addButton( m_lp24Box ); - lpBtnGrp->addButton( m_lp48Box ); + lpBtnGrp->addButton( lp12Button ); + lpBtnGrp->addButton( lp24Button ); + lpBtnGrp->addButton( lp48Button ); lpBtnGrp->setModel( &m_controls->m_lpTypeModel, false); automatableButtonGroup *hpBtnGrp = new automatableButtonGroup( this, tr( "hp grp" ) ); - hpBtnGrp->addButton( m_hp12Box ); - hpBtnGrp->addButton( m_hp24Box ); - hpBtnGrp->addButton( m_hp48Box ); + hpBtnGrp->addButton( hp12Button ); + hpBtnGrp->addButton( hp24Button ); + hpBtnGrp->addButton( hp48Button ); hpBtnGrp->setModel( &m_controls->m_hpTypeModel,false); mainLayout->setAlignment( Qt::AlignTop ); + for (int i = 0 ; i < 10; i++) { mainLayout->setColumnMinimumWidth(i, 50); } - mainLayout->setAlignment( m_inGainFader, Qt::AlignHCenter ); - mainLayout->setAlignment( m_outGainFader, Qt::AlignHCenter ); + mainLayout->setAlignment( inGainFader, Qt::AlignHCenter ); + mainLayout->setAlignment( outGainFader, Qt::AlignHCenter ); mainLayout->setRowMinimumHeight( 0,200 ); mainLayout->setRowMinimumHeight( 1, 40 ); mainLayout->setRowMinimumHeight(6,15); mainLayout->setContentsMargins( 0, 11, 0, 0 ); - mainLayout->setAlignment(m_inSpec, Qt::AlignCenter ); - mainLayout->setAlignment(m_outSpec, Qt::AlignCenter ); + mainLayout->setAlignment(inSpec, Qt::AlignCenter ); + mainLayout->setAlignment(outSpec, Qt::AlignCenter ); - m_freqLabel = new QLabel(this); - m_freqLabel->setText("- " + tr( "Frequency")+ " -" ); - m_freqLabel->move( 217 , 377 ); + QLabel *freqLabel = new QLabel( this ); + freqLabel->setText("- " + tr( "Frequency")+ " -" ); + freqLabel->move( 217 , 377 ); - m_resLabel1 = new QLabel(this); - m_resLabel1->setText("- " + tr( "Resonance")+ " -" ); - m_resLabel1->move( 62 , 444 ); + QLabel *resLabel1 = new QLabel( this ); + resLabel1->setText("- " + tr( "Resonance")+ " -" ); + resLabel1->move( 62 , 444 ); - m_resLabel2 = new QLabel(this); - m_resLabel2->setText("- " + tr( "Resonance")+ " -" ); - m_resLabel2->move( 365 , 444 ); + QLabel *resLabel2 = new QLabel( this ); + resLabel2->setText("- " + tr( "Resonance")+ " -" ); + resLabel2->move( 365 , 444 ); - m_bandWidthLabel = new QLabel(this); - m_bandWidthLabel->setText("- " + tr( "Bandwidth")+ " -" ); - m_bandWidthLabel->move( 215 , 444 ); + QLabel *bandWidthLabel = new QLabel( this ); + bandWidthLabel->setText("- " + tr( "Bandwidth")+ " -" ); + bandWidthLabel->move( 215 , 444 ); setLayout(mainLayout); } diff --git a/plugins/Eq/EqControlsDialog.h b/plugins/Eq/EqControlsDialog.h index 09984fe4d..2f7d268c9 100644 --- a/plugins/Eq/EqControlsDialog.h +++ b/plugins/Eq/EqControlsDialog.h @@ -25,16 +25,17 @@ #ifndef EQCONTROLSDIALOG_H #define EQCONTROLSDIALOG_H +#include +#include + #include "EffectControlDialog.h" +#include "EqParameterWidget.h" +#include "EqSpectrumView.h" #include "Fader.h" #include "Knob.h" #include "LedCheckbox.h" -#include "EqParameterWidget.h" #include "MainWindow.h" -#include "EqSpectrumView.h" #include "PixmapButton.h" -#include -#include @@ -44,44 +45,22 @@ class EqControlsDialog : public EffectControlDialog { Q_OBJECT public: - EqControlsDialog( EqControls* controls ); + EqControlsDialog( EqControls * controls ); virtual ~EqControlsDialog() { } - EqBand * setBand(EqControls *controls); + EqBand * setBand( EqControls * controls ); private: EqControls * m_controls; - Fader* m_inGainFader; - Fader* m_outGainFader; - Fader* m_gainFader; - Knob* m_resKnob; - Knob* m_freqKnob; - PixmapButton* m_inSpecB; - PixmapButton* m_outSpecB; - PixmapButton* m_activeBox; - PixmapButton* m_lp12Box; - PixmapButton* m_lp24Box; - PixmapButton* m_lp48Box; - PixmapButton* m_hp12Box; - PixmapButton* m_hp24Box; - PixmapButton* m_hp48Box; - LedCheckBox* m_analyzeBox; - EqParameterWidget* m_parameterWidget; - EqSpectrumView* m_inSpec; - EqSpectrumView* m_outSpec; - QLabel* m_freqLabel; - QLabel* m_resLabel1; - QLabel* m_resLabel2; - QLabel* m_bandWidthLabel; - + EqParameterWidget * m_parameterWidget; virtual void mouseDoubleClickEvent(QMouseEvent *event); - EqBand* setBand( int index, BoolModel* active, FloatModel* freq, FloatModel* res, FloatModel* gain, QColor color, QString name, float* peakL, float* peakR, BoolModel *hp12, BoolModel *hp24, BoolModel *hp48, BoolModel *lp12, BoolModel *lp24, BoolModel *lp48 ) + EqBand *setBand( int index, BoolModel *active, FloatModel *freq, FloatModel *res, FloatModel *gain, QColor color, QString name, float *peakL, float *peakR, BoolModel *hp12, BoolModel *hp24, BoolModel *hp48, BoolModel *lp12, BoolModel *lp24, BoolModel *lp48 ) { - EqBand* filterModels = m_parameterWidget->getBandModels( index ); + EqBand *filterModels = m_parameterWidget->getBandModels( index ); filterModels->active = active; filterModels->freq = freq; filterModels->res = res; @@ -99,9 +78,6 @@ private: } int m_originalHeight; - }; - - #endif // EQCONTROLSDIALOG_H diff --git a/plugins/Eq/EqCurve.cpp b/plugins/Eq/EqCurve.cpp index 54d9b82e7..2154deffa 100644 --- a/plugins/Eq/EqCurve.cpp +++ b/plugins/Eq/EqCurve.cpp @@ -21,28 +21,27 @@ * Boston, MA 02110-1301 USA. * */ - #include "EqCurve.h" -#include "lmms_math.h" + #include "Effect.h" #include "embed.h" +#include "lmms_math.h" -EqHandle::EqHandle( int num, int x, int y ) +EqHandle::EqHandle( int num, int x, int y ) : + m_numb( num ), + m_width( x ), + m_heigth( y ), + m_mousePressed( false ), + m_active( false ), + m_handleMoved( false ) { - PI = LD_PI; - m_numb = num; - setMouseHover( false ); - m_width = x; - m_heigth = y; - m_mousePressed = false; - m_active = false; setFlag( ItemIsMovable ); setFlag( ItemSendsGeometryChanges ); setAcceptHoverEvents( true ); float totalHeight = 36; m_pixelsPerUnitHeight = ( m_heigth ) / ( totalHeight ); - m_handleMoved = false; - QObject::connect( this,SIGNAL( positionChanged() ) , this, SLOT( handleMoved() ) ); + setMouseHover( false ); + connect( this, SIGNAL( positionChanged() ), this, SLOT( handleMoved() ) ); } @@ -56,6 +55,44 @@ QRectF EqHandle::boundingRect() const +float EqHandle::freqToXPixel( float freq , int w ) +{ + float min = log10f( 27 ); + float max = log10f( 20000 ); + float range = max - min; + return ( log10f( freq ) - min ) / range * w; +} + + + + +float EqHandle::xPixelToFreq( float x , int w ) +{ + float min = log10f( 27 ); + float max = log10f( 20000 ); + float range = max - min; + return powf( 10 , x * ( range / w ) + min ); +} + + + + +float EqHandle::gainToYPixel(float gain , int h, int pixelPerUnitHeight) +{ + return h * 0.5 - gain * pixelPerUnitHeight; +} + + + + +float EqHandle::yPixelToGain( float y , int h, int pixelPerUnitHeight ) +{ + return ( ( h * 0.5 ) - y ) / pixelPerUnitHeight; +} + + + + void EqHandle::handleMoved() { m_handleMoved = true; @@ -66,19 +103,16 @@ void EqHandle::handleMoved() void EqHandle::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ) { - painter->setRenderHint( QPainter::Antialiasing, true) ; + painter->setRenderHint( QPainter::Antialiasing, true ); if ( m_mousePressed ) { emit positionChanged(); - } - // graphics for the handles QString fileName = "handle" + QString::number(m_numb+1); if ( !isActiveHandle() ) { fileName = fileName + "inactive"; } QPixmap circlePixmap = PLUGIN_NAME::getIconPixmap( fileName.toLatin1() ); - painter->drawPixmap( -12, -12, circlePixmap ); - + painter->drawPixmap( -12, -12, circlePixmap ); // on mouse hover draw an info box and change the pixmap of the handle if ( isMouseHover() ) { @@ -95,15 +129,15 @@ void EqHandle::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, } if ( EqHandle::x() > m_width - 40 ) { - rectX = rectX - (40 - (m_width - EqHandle::x() ) ); + rectX = rectX - ( 40 - ( m_width - EqHandle::x() ) ); } - painter->drawPixmap( -12, -12, PLUGIN_NAME::getIconPixmap( "handlehover" ) ); + painter->drawPixmap( -12, -12, PLUGIN_NAME::getIconPixmap( "handlehover" ) ); QRectF textRect = QRectF ( rectX, rectY, 80, 30 ); QRectF textRect2 = QRectF ( rectX+1, rectY+1, 80, 30 ); - QString freq = QString::number( xPixelToFreq(EqHandle::x() )) ; + QString freq = QString::number( xPixelToFreq( EqHandle::x(), m_width ) ); QString res; - if ( getType() < 3 || getType() > 3 ) + if ( getType() != para ) { res = tr( "Reso: ") + QString::number( getResonance() ); } @@ -131,15 +165,15 @@ void EqHandle::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QPainterPath EqHandle::getCurvePath() { QPainterPath path; - float y = m_heigth*0.5; - for ( float x=0 ; x < m_width; x++ ) + float y = m_heigth * 0.5; + for ( float x = 0 ; x < m_width; x++ ) { - if ( m_type == 1 ) y = getLowCutCurve( x ); - if ( m_type == 2 ) y = getLowShelfCurve( x ); - if ( m_type == 3 ) y = getPeakCurve( x ); - if ( m_type == 4 ) y = getHighShelfCurve( x ); - if ( m_type == 5 ) y = getHighCutCurve( x ); - if ( x==0 ) path.moveTo( x, y ); // sets the begin of Path + if ( m_type == highpass ) y = getLowCutCurve( x ); + if ( m_type == lowshelf ) y = getLowShelfCurve( x ); + if ( m_type == para ) y = getPeakCurve( x ); + if ( m_type == highshelf ) y = getHighShelfCurve( x ); + if ( m_type == lowpass ) y = getHighCutCurve( x ); + if ( x == 0 ) path.moveTo( x, y ); // sets the begin of Path path.lineTo( x, y ); } return path; @@ -148,69 +182,26 @@ QPainterPath EqHandle::getCurvePath() - -float EqHandle::getPeakCurve(float x) +float EqHandle::getPeakCurve( float x ) { - double freqZ = xPixelToFreq( EqHandle::x() ); - const int SR = Engine::mixer()->processingSampleRate(); - double w0 = 2* PI * freqZ / SR ; - double c = cosf( w0 ); - double s = sinf( w0 ); - double Q = getResonance(); - double A = pow( 10, yPixelToGain(EqHandle::y()) / 40 ); - double alpha = s * sinh( log( 2 ) / 2 * Q * w0 / sinf( w0 ) ); - double a0, a1, a2, b0, b1, b2; // coeffs to calculate - - //calc coefficents - b0 = 1 + alpha*A; - b1 = -2*c; - b2 = 1 - alpha*A; - a0 = 1 + alpha/A; - a1 = -2*c; - a2 = 1 - alpha/A; - - //normalise - b0 /= a0; - b1 /= a0; - b2 /= a0; - a1 /= a0; - a2 /= a0; - a0 = 1; - - double w; - double PHI; - double gain; - double freq = xPixelToFreq( x ); - w = 2*PI * freq / SR; - PHI = pow( sin( w/2 ), 2 )*4; - gain = 10* log10( pow( b0 + b1 + b2 , 2 ) - + ( b0 * b2 * PHI - ( b1*(b0+b2 )+ 4*b0*b2 ) ) *PHI ) - - 10*log10( pow( 1+ a1+ a2 ,2 ) + ( 1* a2 * PHI - ( a1 * ( 1+ a2 ) +4 *1 * a2 ) ) *PHI ); - float y= gainToYPixel( gain ); - return y; -} - - - - -float EqHandle::getHighShelfCurve( float x ) -{ - double freqZ = xPixelToFreq( EqHandle::x() ); + double freqZ = xPixelToFreq( EqHandle::x(), m_width ); const int SR = Engine::mixer()->processingSampleRate(); - double w0 = 2 * PI * freqZ / SR; + double w0 = 2 * LD_PI * freqZ / SR ; double c = cosf( w0 ); double s = sinf( w0 ); - double A = pow( 10, yPixelToGain( EqHandle::y() ) * 0.025 ); - double beta = sqrt( A ) / m_resonance; + double Q = getResonance(); + double A = pow( 10, yPixelToGain( EqHandle::y(), m_heigth, m_pixelsPerUnitHeight ) / 40 ); + double alpha = s * sinh( log( 2 ) / 2 * Q * w0 / sinf( w0 ) ); double a0, a1, a2, b0, b1, b2; // coeffs to calculate //calc coefficents - b0 = A *( ( A +1 ) + ( A - 1 ) * c + beta * s); - b1 = -2 * A * ( ( A - 1 ) + ( A + 1 ) * c ); - b2 = A * ( ( A + 1 ) + ( A - 1 ) * c - beta * s); - a0 = ( A + 1 ) - ( A - 1 ) * c + beta * s; - a1 = 2 * ( ( A - 1 ) - ( A + 1 ) * c ); - a2 = ( A + 1) - ( A - 1 ) * c - beta * s; + b0 = 1 + alpha * A; + b1 = -2 * c; + b2 = 1 - alpha * A; + a0 = 1 + alpha / A; + a1 = -2 * c; + a2 = 1 - alpha / A; + //normalise b0 /= a0; b1 /= a0; @@ -219,16 +210,46 @@ float EqHandle::getHighShelfCurve( float x ) a2 /= a0; a0 = 1; - double w; - double PHI; - double gain; - double freq = xPixelToFreq( x ); - w = 2* PI * freq / SR ; - PHI = pow(sin( w/2 ), 2 ) * 4; - gain = 10* log10( pow( b0 + b1 + b2 , 2 ) - + ( b0 * b2 * PHI - ( b1*( b0+b2 )+ 4*b0*b2 ) ) *PHI ) - - 10*log10( pow(1+ a1+ a2 ,2 ) + ( 1* a2 * PHI - ( a1 * ( 1 + a2 ) + 4 * 1 * a2) ) *PHI ); - float y= gainToYPixel( gain ); + double freq = xPixelToFreq( x, m_width ); + double gain = calculateGain( freq, a1, a2, b0, b1, b2 ); + float y = gainToYPixel( gain, m_heigth, m_pixelsPerUnitHeight ); + + return y; +} + + + + +float EqHandle::getHighShelfCurve( float x ) +{ + double freqZ = xPixelToFreq( EqHandle::x(), m_width ); + const int SR = Engine::mixer()->processingSampleRate(); + double w0 = 2 * LD_PI * freqZ / SR; + double c = cosf( w0 ); + double s = sinf( w0 ); + double A = pow( 10, yPixelToGain( EqHandle::y(), m_heigth, m_pixelsPerUnitHeight ) * 0.025 ); + double beta = sqrt( A ) / m_resonance; + double a0, a1, a2, b0, b1, b2; // coeffs to calculate + + //calc coefficents + b0 = A * ( ( A + 1 ) + ( A - 1 ) * c + beta * s); + b1 = -2 * A * ( ( A - 1 ) + ( A + 1 ) * c ); + b2 = A * ( ( A + 1 ) + ( A - 1 ) * c - beta * s); + a0 = ( A + 1 ) - ( A - 1 ) * c + beta * s; + a1 = 2 * ( ( A - 1 ) - ( A + 1 ) * c ); + a2 = ( A + 1 ) - ( A - 1 ) * c - beta * s; + //normalise + b0 /= a0; + b1 /= a0; + b2 /= a0; + a1 /= a0; + a2 /= a0; + a0 = 1; + + double freq = xPixelToFreq( x, m_width ); + double gain = calculateGain( freq, a1, a2, b0, b1, b2 ); + float y = gainToYPixel( gain, m_heigth, m_pixelsPerUnitHeight ); + return y; } @@ -237,18 +258,18 @@ float EqHandle::getHighShelfCurve( float x ) float EqHandle::getLowShelfCurve( float x ) { - double freqZ = xPixelToFreq( EqHandle::x() ); + double freqZ = xPixelToFreq( EqHandle::x(), m_width ); const int SR = Engine::mixer()->processingSampleRate(); - double w0 = 2 * PI * freqZ / SR ; + double w0 = 2 * LD_PI * freqZ / SR ; double c = cosf( w0 ); double s = sinf( w0 ); - double A = pow( 10, yPixelToGain( EqHandle::y() ) / 40 ); + double A = pow( 10, yPixelToGain( EqHandle::y(), m_heigth, m_pixelsPerUnitHeight ) / 40 ); double beta = sqrt( A ) / m_resonance; double a0, a1, a2, b0, b1, b2; // coeffs to calculate //calc coefficents - b0 = A * ( ( A+1 ) - ( A-1 ) * c + beta * s ); - b1 = 2 * A * ( ( A - 1 ) - ( A + 1 ) * c) ; + b0 = A * ( ( A + 1 ) - ( A - 1 ) * c + beta * s ); + b1 = 2 * A * ( ( A - 1 ) - ( A + 1 ) * c ) ; b2 = A * ( ( A + 1 ) - ( A - 1 ) * c - beta * s); a0 = ( A + 1 ) + ( A - 1 ) * c + beta * s; a1 = -2 * ( ( A - 1 ) + ( A + 1 ) * c ); @@ -262,16 +283,10 @@ float EqHandle::getLowShelfCurve( float x ) a2 /= a0; a0 = 1; - double w; - double PHI; - double gain; - double freq = xPixelToFreq( x ); - w = 2* PI * freq / SR ; - PHI = pow( sin( w/2 ), 2 ) * 4; - gain = 10 * log10( pow( b0 + b1 + b2 , 2 ) - + ( b0 * b2 * PHI - ( b1 * ( b0+b2 ) + 4 * b0 * b2 ) ) *PHI ) - - 10 * log10( pow( 1 + a1 + a2, 2 ) + ( 1 * a2 * PHI - ( a1 * ( 1 + a2 ) + 4 * 1 * a2 ) ) * PHI ); - float y= gainToYPixel( gain ); + double freq = xPixelToFreq( x, m_width ); + double gain = calculateGain( freq, a1, a2, b0, b1, b2 ); + float y = gainToYPixel( gain, m_heigth, m_pixelsPerUnitHeight ); + return y; } @@ -280,13 +295,13 @@ float EqHandle::getLowShelfCurve( float x ) float EqHandle::getLowCutCurve( float x ) { - double freqZ = xPixelToFreq( EqHandle::x() ); + double freqZ = xPixelToFreq( EqHandle::x(), m_width ); const int SR = Engine::mixer()->processingSampleRate(); - double w0 = 2 * PI * freqZ / SR ; + double w0 = 2 * LD_PI * freqZ / SR ; double c = cosf( w0 ); double s = sinf( w0 ); double resonance = getResonance(); - double A = pow( 10, yPixelToGain( EqHandle::y() ) / 20); + double A = pow( 10, yPixelToGain( EqHandle::y(), m_heigth, m_pixelsPerUnitHeight ) / 20); double alpha = s / 2 * sqrt ( ( A +1/A ) * ( 1 / resonance -1 ) +2 ); double a0, a1, a2, b0, b1, b2; // coeffs to calculate @@ -304,37 +319,18 @@ float EqHandle::getLowCutCurve( float x ) a2 /= a0; a0 = 1; - double w; - double PHI; - double gain; - double freq = xPixelToFreq( x ); - w = 2 * PI * freq / SR ; - PHI = pow( sin( w/2), 2 ) * 4; - gain = 10 * log10( pow( b0 + b1 + b2 , 2 ) - + ( b0 * b2 * PHI - ( b1 * ( b0 + b2 ) + 4 * b0 * b2 ) ) * PHI ) - - 10 * log10( pow( 1 + a1 + a2, 2 ) + ( 1 * a2 * PHI - ( a1 * ( 1 + a2 ) + 4 * 1 * a2 ) ) * PHI ); - + double freq = xPixelToFreq( x, m_width ); + double gain = calculateGain( freq, a1, a2, b0, b1, b2 ); if ( m_hp24 ) { - gain = gain + 10 * log10( pow( b0 + b1 + b2 , 2 ) - + ( b0 * b2 * PHI - ( b1 * ( b0 + b2 ) + 4 * b0 * b2 ) ) * PHI ) - - 10 * log10( pow( 1 + a1 + a2, 2 ) + ( 1 * a2 * PHI - ( a1 * ( 1 + a2 ) + 4 * 1 * a2 ) ) * PHI ); - + gain = gain * 2; } - if ( m_hp48 ) { - gain = gain + 10 * log10( pow( b0 + b1 + b2 , 2 ) - + ( b0 * b2 * PHI - ( b1 * ( b0 + b2 ) + 4 * b0 * b2 ) ) * PHI ) - - 10 * log10( pow( 1 + a1 + a2, 2 ) + ( 1 * a2 * PHI - ( a1 * ( 1 + a2 ) + 4 * 1 * a2 ) ) * PHI ); - - gain = gain + ( 10 * log10( pow( b0 + b1 + b2 , 2 ) - + ( b0 * b2 * PHI - ( b1 * ( b0 + b2 ) + 4 * b0 * b2 ) ) * PHI ) - - 10 * log10( pow( 1 + a1 + a2, 2 ) + ( 1 * a2 * PHI - ( a1 * ( 1 + a2 ) + 4 * 1 * a2 ) ) * PHI )); - + gain = gain * 3; } + float y = gainToYPixel( gain, m_heigth, m_pixelsPerUnitHeight ); - float y= gainToYPixel( gain ); return y; } @@ -343,24 +339,22 @@ float EqHandle::getLowCutCurve( float x ) float EqHandle::getHighCutCurve( float x ) { - double freqZ = xPixelToFreq( EqHandle::x() ); + double freqZ = xPixelToFreq( EqHandle::x(), m_width ); const int SR = Engine::mixer()->processingSampleRate(); - double w0 = 2 * PI * freqZ / SR ; + double w0 = 2 * LD_PI * freqZ / SR ; double c = cosf( w0 ); double s = sinf( w0 ); double resonance = getResonance(); - double A = pow( 10, yPixelToGain(EqHandle::y() ) / 20 ); + double A = pow( 10, yPixelToGain( EqHandle::y(), m_heigth, m_pixelsPerUnitHeight ) / 20 ); double alpha = s / 2 * sqrt ( ( A + 1 / A ) * ( 1 / resonance -1 ) +2 ); double a0, a1, a2, b0, b1, b2; // coeffs to calculate - b0 = ( 1 - c ) * 0.5; b1 = 1 - c; b2 = ( 1 - c ) * 0.5; a0 = 1 + alpha; a1 = -2 * c; a2 = 1 - alpha; - //normalise b0 /= a0; b1 /= a0; @@ -369,45 +363,24 @@ float EqHandle::getHighCutCurve( float x ) a2 /= a0; a0 = 1; - double w; - double PHI; - double gain; - double freq = xPixelToFreq( x ); - w = 2 * PI * freq / SR ; - PHI = pow(sin( w/2),2 )*4; - - gain = 10 * log10( pow( b0 + b1 + b2 , 2 ) - + ( b0 * b2 * PHI - ( b1 * ( b0 + b2 ) + 4 * b0 * b2 ) ) * PHI ) - - 10 * log10( pow( 1 + a1 + a2, 2 ) + ( 1 * a2 * PHI - ( a1 * ( 1 + a2 ) + 4 * 1 * a2 ) ) * PHI ); - + double freq = xPixelToFreq( x, m_width ); + double gain = calculateGain( freq, a1, a2, b0, b1, b2 ); if ( m_lp24 ) { - gain = gain + ( 10 * log10( pow( b0 + b1 + b2 , 2 ) - + ( b0 * b2 * PHI - ( b1 * ( b0 + b2 ) + 4 * b0 * b2 ) ) * PHI ) - - 10 * log10( pow( 1 + a1 + a2, 2 ) + ( 1 * a2 * PHI - ( a1 * ( 1 + a2 ) + 4 * 1 * a2 ) ) * PHI ) ); - + gain = gain * 2; } - if ( m_lp48 ) { - gain = gain + ( 10 * log10( pow( b0 + b1 + b2 , 2 ) - + ( b0 * b2 * PHI - ( b1 * ( b0 + b2 ) + 4 * b0 * b2 ) ) * PHI ) - - 10 * log10( pow( 1 + a1 + a2, 2 ) + ( 1 * a2 * PHI - ( a1 * ( 1 + a2 ) + 4 * 1 * a2 ) ) * PHI ) ); - - gain = gain + ( 10 * log10( pow( b0 + b1 + b2 , 2 ) - + ( b0 * b2 * PHI - ( b1 * ( b0 + b2 ) + 4 * b0 * b2 ) ) * PHI ) - - 10 * log10( pow( 1 + a1 + a2, 2 ) + ( 1 * a2 * PHI - ( a1 * ( 1 + a2 ) + 4 * 1 * a2 ) ) * PHI ) ); + gain = gain * 3; } + float y = gainToYPixel( gain, m_heigth, m_pixelsPerUnitHeight ); - - float y= gainToYPixel( gain ); return y; } - float EqHandle::getResonance() { return m_resonance; @@ -424,7 +397,7 @@ int EqHandle::getNum() -void EqHandle::setType(int t) +void EqHandle::setType( int t ) { EqHandle::m_type = t; } @@ -432,7 +405,7 @@ void EqHandle::setType(int t) -void EqHandle::setResonance(float r) +void EqHandle::setResonance( float r ) { EqHandle::m_resonance = r; } @@ -448,7 +421,7 @@ bool EqHandle::isMouseHover() -void EqHandle::setMouseHover(bool d) +void EqHandle::setMouseHover( bool d ) { m_mouseHover = d; } @@ -556,10 +529,29 @@ void EqHandle::setlp48() +double EqHandle::calculateGain(const double freq, const double a1, const double a2, const double b0, const double b1, const double b2 ) +{ + const int SR = Engine::mixer()->processingSampleRate(); + + const double w = 2 * LD_PI * freq / SR ; + const double PHI = pow( sin( w / 2 ), 2 ) * 4; + + double gain = 10 * log10( pow( b0 + b1 + b2 , 2 ) + ( b0 * b2 * PHI - ( b1 * ( b0 + b2 ) + + 4 * b0 * b2 ) ) * PHI ) - 10 * log10( pow( 1 + a1 + a2, 2 ) + + ( 1 * a2 * PHI - ( a1 * ( 1 + a2 ) + 4 * 1 * a2 ) ) * PHI ); + return gain; +} + + + + void EqHandle::mousePressEvent( QGraphicsSceneMouseEvent *event ) { - m_mousePressed = true; - QGraphicsItem::mousePressEvent( event ); + if( event->button() == Qt::LeftButton ) + { + m_mousePressed = true; + QGraphicsItem::mousePressEvent( event ); + } } @@ -567,8 +559,11 @@ void EqHandle::mousePressEvent( QGraphicsSceneMouseEvent *event ) void EqHandle::mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) { - m_mousePressed = false; - QGraphicsItem::mouseReleaseEvent( event ); + if( event->button() == Qt::LeftButton ) + { + m_mousePressed = false; + QGraphicsItem::mouseReleaseEvent( event ); + } } @@ -577,7 +572,7 @@ void EqHandle::mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) void EqHandle::wheelEvent( QGraphicsSceneWheelEvent *wevent ) { float highestBandwich; - if ( m_type < 3 || m_type > 3 ) + if( m_type != para ) { highestBandwich = 10; } @@ -588,7 +583,7 @@ void EqHandle::wheelEvent( QGraphicsSceneWheelEvent *wevent ) int numDegrees = wevent->delta() / 120; float numSteps = 0; - if ( wevent->modifiers() == Qt::ControlModifier ) + if( wevent->modifiers() == Qt::ControlModifier ) { numSteps = numDegrees * 0.01; } @@ -597,16 +592,16 @@ void EqHandle::wheelEvent( QGraphicsSceneWheelEvent *wevent ) numSteps = numDegrees * 0.15; } - if ( wevent->orientation() == Qt::Vertical ) + if( wevent->orientation() == Qt::Vertical ) { m_resonance = m_resonance + ( numSteps ); - if ( m_resonance < 0.1 ) + if( m_resonance < 0.1 ) { m_resonance = 0.1; } - if ( m_resonance > highestBandwich ) + if( m_resonance > highestBandwich ) { m_resonance = highestBandwich; } @@ -636,17 +631,17 @@ void EqHandle::hoverLeaveEvent( QGraphicsSceneHoverEvent *hevent ) QVariant EqHandle::itemChange( QGraphicsItem::GraphicsItemChange change, const QVariant &value ) { - if ( change == ItemPositionChange ) + if( change == ItemPositionChange ) { // pass filter don't move in y direction - if ( EqHandle::m_type == 1 || EqHandle::m_type == 5 ) + if ( m_type == highpass || m_type == lowpass ) { float newX = value.toPointF().x(); - if ( newX < 0 ) + if( newX < 0 ) { newX = 0; } - if ( newX > m_width ) + if( newX > m_width ) { newX = m_width; } @@ -656,7 +651,7 @@ QVariant EqHandle::itemChange( QGraphicsItem::GraphicsItemChange change, const Q QPointF newPos = value.toPointF(); QRectF rect = QRectF( 0, 0, m_width, m_heigth ); - if ( !rect.contains( newPos ) ) + if( !rect.contains( newPos ) ) { // Keep the item inside the scene rect. newPos.setX( qMin( rect.right(), qMax( newPos.x(), rect.left() ) ) ); @@ -678,12 +673,13 @@ QVariant EqHandle::itemChange( QGraphicsItem::GraphicsItemChange change, const Q // // ---------------------------------------------------------------------- -EqCurve::EqCurve( QList *handle, int x, int y ) +EqCurve::EqCurve( QList *handle, int x, int y ) : + m_handle( handle ), + m_width( x ), + m_heigth( y ), + m_alpha( 0 ), + m_modelChanged( false ) { - m_width = x; - m_heigth = y; - m_handle = handle; - m_alpha = 0; } @@ -700,74 +696,82 @@ QRectF EqCurve::boundingRect() const void EqCurve::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ) { painter->setRenderHint( QPainter::Antialiasing, true ); - - //Computes the main curve - //if a band is active the curve will be computed by averaging the curves of each band - QMap mainCurve; - for ( int x = 0; x < m_width ; x++ ) + if( m_modelChanged ) { - mainCurve[x] = 0; - } - int activeHandles=0; - for ( int thatHandle = 0; thatHandlecount(); thatHandle++ ) - { - if ( m_handle->at(thatHandle)->isActiveHandle() == true ) + setModelChanged( false ); + //counts the active bands + int activeHandles=0; + for ( int thatHandle = 0; thatHandlecount(); thatHandle++ ) { - activeHandles++; - } - } - for ( int thatHandle = 0; thatHandlecount(); thatHandle++ ) - { - if ( m_handle->at(thatHandle)->isActiveHandle() == true ) - { - for ( int x = 0; x < m_width ; x=x+1 ) + if ( m_handle->at(thatHandle)->isActiveHandle() == true ) { - if ( m_handle->at( thatHandle )->getType() == 1 ) + activeHandles++; + } + } + //Computes the main curve + //if a band is active the curve will be computed by averaging the curves of each band + QMap mainCurve; + for ( int thatHandle = 0; thatHandlecount(); thatHandle++ ) + { + if ( m_handle->at(thatHandle)->isActiveHandle() == true ) + { + for ( int x = 0; x < m_width ; x=x+1 ) { - mainCurve[x]= ( mainCurve[x] + ( m_handle->at( thatHandle )->getLowCutCurve( x ) * ( activeHandles ) ) - ( ( activeHandles * ( m_heigth/2 ) ) - m_heigth ) ); - } - if ( m_handle->at(thatHandle)->getType() == 2 ) - { - mainCurve[x]= ( mainCurve[x] + ( m_handle->at( thatHandle )->getLowShelfCurve( x ) * ( activeHandles ) ) - ( ( activeHandles * ( m_heigth/2 ) ) - m_heigth ) ); - } - if ( m_handle->at( thatHandle )->getType() == 3 ) - { - mainCurve[x]= ( mainCurve[x] + ( m_handle->at( thatHandle )->getPeakCurve( x ) * ( activeHandles ) ) - ( ( activeHandles * ( m_heigth/2 ) ) - m_heigth ) ); - } - if ( m_handle->at( thatHandle )->getType() == 4 ) - { - mainCurve[x]= ( mainCurve[x] + ( m_handle->at( thatHandle )->getHighShelfCurve( x ) * ( activeHandles ) ) - ( ( activeHandles * ( m_heigth/2 ) ) - m_heigth ) ); - } - if ( m_handle->at(thatHandle)->getType() == 5 ) - { - mainCurve[x]= ( mainCurve[x] + ( m_handle->at( thatHandle )->getHighCutCurve( x ) * ( activeHandles ) ) - ( ( activeHandles * ( m_heigth/2 ) ) - m_heigth ) ); + if ( m_handle->at( thatHandle )->getType() == highpass ) + { + mainCurve[x]= ( mainCurve[x] + ( m_handle->at( thatHandle )->getLowCutCurve( x ) * ( activeHandles ) ) - ( ( activeHandles * ( m_heigth/2 ) ) - m_heigth ) ); + } + if ( m_handle->at(thatHandle)->getType() == lowshelf ) + { + mainCurve[x]= ( mainCurve[x] + ( m_handle->at( thatHandle )->getLowShelfCurve( x ) * ( activeHandles ) ) - ( ( activeHandles * ( m_heigth/2 ) ) - m_heigth ) ); + } + if ( m_handle->at( thatHandle )->getType() == para ) + { + mainCurve[x]= ( mainCurve[x] + ( m_handle->at( thatHandle )->getPeakCurve( x ) * ( activeHandles ) ) - ( ( activeHandles * ( m_heigth/2 ) ) - m_heigth ) ); + } + if ( m_handle->at( thatHandle )->getType() == highshelf ) + { + mainCurve[x]= ( mainCurve[x] + ( m_handle->at( thatHandle )->getHighShelfCurve( x ) * ( activeHandles ) ) - ( ( activeHandles * ( m_heigth/2 ) ) - m_heigth ) ); + } + if ( m_handle->at(thatHandle)->getType() == lowpass ) + { + mainCurve[x]= ( mainCurve[x] + ( m_handle->at( thatHandle )->getHighCutCurve( x ) * ( activeHandles ) ) - ( ( activeHandles * ( m_heigth/2 ) ) - m_heigth ) ); + } } } } - } - - QPainterPath mCurve; - //compute a QPainterPath - for ( int x = 0; x < m_width ; x++ ) - { - mainCurve[x] = ( ( mainCurve[x] / activeHandles ) ) - ( m_heigth/2 ); - if ( x==0 ) + //compute a QPainterPath + m_curve = QPainterPath(); + for ( int x = 0; x < m_width ; x++ ) { - mCurve.moveTo( x, mainCurve[x] ); + mainCurve[x] = ( ( mainCurve[x] / activeHandles ) ) - ( m_heigth/2 ); + if ( x==0 ) + { + m_curve.moveTo( x, mainCurve[x] ); + } + m_curve.lineTo( x, mainCurve[x] ); } - mCurve.lineTo( x, mainCurve[x] ); - } - //and paint it with Pathstroker - QPainterPathStroker stroke; - QPainterPath strokeP; - stroke.setWidth( 2 ); - strokeP = stroke.createStroke( mCurve ); - painter->fillPath( strokeP, QBrush( Qt::white ) ); + //we cache the curve painting in a pixmap for saving cpu + QPixmap cacheMap( boundingRect().size().toSize() ); + cacheMap.fill( QColor( 0, 0, 0, 0 ) ); + QPainter cachePainter( &cacheMap ); + cachePainter.setRenderHint( QPainter::Antialiasing, true ); + QPen pen; + pen.setWidth( 2 ); + pen.setColor( Qt::white ); + cachePainter.setPen( pen ); + cachePainter.drawPath( m_curve ); + cachePainter.end(); + m_curvePixmapCache.fill( QColor( 0, 0, 0, 0 ) ); + m_curvePixmapCache.swap( cacheMap ); + } + //we paint our cached curve pixmap + painter->drawPixmap( 0, 0, m_width, m_heigth, m_curvePixmapCache ); // if mouse hover a handle, m_alpha counts up slow for blend in the filled EQ curve // todo: a smarter way of this "if-monster" QColor curveColor; - if ( m_handle->at( 0 )->isMouseHover() + if( m_handle->at( 0 )->isMouseHover() || m_handle->at( 1 )->isMouseHover() || m_handle->at( 2 )->isMouseHover() || m_handle->at( 3 )->isMouseHover() @@ -778,15 +782,18 @@ void EqCurve::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, ) { if ( m_alpha < 40 ) + { m_alpha = m_alpha + 10; + } } else { if ( m_alpha > 0 ) + { m_alpha = m_alpha - 10; + } } - - //draw on mouse hover the curve of hovered filter + //draw on mouse hover the curve of hovered filter in different colors for ( int i = 0; i < m_handle->count(); i++ ) { if ( m_handle->at(i)->isMouseHover() ) @@ -808,11 +815,18 @@ void EqCurve::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, painter->drawPath( m_handle->at( i )->getCurvePath() ); } } - // draw on mouse hover the EQ curve filled. with m_alpha it blends in and out smooth + //draw on mouse hover the EQ curve filled. with m_alpha it blends in and out smooth QPainterPath cPath; - cPath.addPath( mCurve ); + cPath.addPath( m_curve ); cPath.lineTo( cPath.currentPosition().x(), m_heigth ); cPath.lineTo( cPath.elementAt( 0 ).x , m_heigth ); painter->fillPath( cPath, QBrush ( QColor( 255,255,255, m_alpha ) ) ); - +} + + + + +void EqCurve::setModelChanged( bool mc ) +{ + m_modelChanged = mc; } diff --git a/plugins/Eq/EqCurve.h b/plugins/Eq/EqCurve.h index 65d9aa81e..4bf4f75d8 100644 --- a/plugins/Eq/EqCurve.h +++ b/plugins/Eq/EqCurve.h @@ -29,6 +29,7 @@ #include #include #include "lmms_math.h" +#include "AutomatableModelView.h" enum{ @@ -42,14 +43,19 @@ enum{ - // implements the Eq_Handle to control a band class EqHandle : public QGraphicsObject { Q_OBJECT public: EqHandle( int num, int x, int y ); - void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ); + + static float freqToXPixel( float freq, int w ); + static float xPixelToFreq( float x , int w ); + static float gainToYPixel( float gain, int h, int pixelPerUnitHeight ); + static float yPixelToGain( float y, int h, int pixelPerUnitHeight ); + + QRectF boundingRect() const; QPainterPath getCurvePath(); float getPeakCurve( float x ); float getHighShelfCurve( float x ); @@ -73,8 +79,22 @@ public: void setlp12(); void setlp24(); void setlp48(); + +signals: + void positionChanged(); + +protected: + void mousePressEvent( QGraphicsSceneMouseEvent *event ); + void mouseReleaseEvent( QGraphicsSceneMouseEvent *event ); + void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ); + void wheelEvent( QGraphicsSceneWheelEvent *wevent ); + void hoverEnterEvent( QGraphicsSceneHoverEvent *hevent ); + void hoverLeaveEvent( QGraphicsSceneHoverEvent *hevent ); + QVariant itemChange( GraphicsItemChange change, const QVariant &value ); + private: - long double PI; + double calculateGain( const double freq, const double a1, const double a2, const double b0, const double b1, const double b2 ); + float m_pixelsPerUnitWidth; float m_pixelsPerUnitHeight; float m_scale; @@ -85,125 +105,41 @@ private: bool m_lp24; bool m_lp48; bool m_mouseHover; - bool m_active; int m_type, m_numb; - float m_resonance; float m_width, m_heigth; + float m_resonance; bool m_mousePressed; + bool m_active; bool m_handleMoved; - QRectF boundingRect() const; - - - - inline float freqToXPixel( float freq ) - { - float min = log ( 27) / log( 10 ); - float max = log ( 20000 )/ log( 10 ); - float range = max - min; - return ( log( freq ) / log( 10 ) - min ) / range * m_width; - } - - - - - inline float xPixelToFreq( float x ) - { - float min = log ( 27) / log( 10 ); - float max = log ( 20000 ) / log( 10 ); - float range = max - min; - return pow( 10 , x * ( range / m_width ) + min ); - } - - - - - inline float gainToYPixel( float gain ) - { - return ( m_heigth ) - ( gain * m_pixelsPerUnitHeight ) - ( ( m_heigth ) * 0.5 ); - } - - - - - inline float yPixelToGain( float y ) - { - return ( ( 0.5 * m_heigth ) - y ) / m_pixelsPerUnitHeight; - } - - - - -signals: - void positionChanged(); private slots: void handleMoved(); - -protected: - void mousePressEvent( QGraphicsSceneMouseEvent *event ); - void mouseReleaseEvent( QGraphicsSceneMouseEvent *event ); - void wheelEvent( QGraphicsSceneWheelEvent *wevent ); - void hoverEnterEvent( QGraphicsSceneHoverEvent *hevent ); - void hoverLeaveEvent( QGraphicsSceneHoverEvent *hevent ); - QVariant itemChange( GraphicsItemChange change, const QVariant &value ); }; + class EqCurve : public QGraphicsObject { Q_OBJECT public: EqCurve( QList *handle, int x, int y ); - QList *m_handle; QRectF boundingRect() const; + void setModelChanged(bool mc); + +protected: void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ); + private: + QList *m_handle; + QPainterPath m_curve; + QPixmap m_curvePixmapCache; int m_width, m_heigth; int m_alpha; - + bool m_modelChanged; float m_pixelsPerUnitHeight; float m_scale; - - - - - inline float freqToXPixel( float freq ) - { - float min = log ( 27) / log( 10 ); - float max = log ( 20000 ) / log( 10 ); - float range = max - min; - return ( log( freq ) / log( 10 ) - min ) / range * m_width; - } - - - - - inline float xPixelToFreq( float x ) - { - float min = log ( 27) / log( 10 ); - float max = log ( 20000 ) / log( 10 ); - float range = max - min; - return pow( 10 , x * ( range / m_width ) + min ); - } - - - - - inline float gainToYPixel( float gain ) - { - return ( m_heigth ) - ( gain * m_pixelsPerUnitHeight ) - ( ( m_heigth ) * 0.5 ); - } - - - - - inline float yPixelToGain( float y ) - { - return ( ( 0.5 * m_heigth ) - y ) / m_pixelsPerUnitHeight; - } - }; #endif // EQCURVE_H diff --git a/plugins/Eq/EqEffect.cpp b/plugins/Eq/EqEffect.cpp index 2abfc0711..c3108488c 100644 --- a/plugins/Eq/EqEffect.cpp +++ b/plugins/Eq/EqEffect.cpp @@ -23,13 +23,14 @@ */ #include "EqEffect.h" + #include "embed.cpp" -#include "lmms_math.h" -#include "BasicFilters.h" -#include "interpolation.h" #include "Engine.h" -#include "MainWindow.h" #include "EqFader.h" +#include "interpolation.h" +#include "lmms_math.h" +#include "MainWindow.h" + extern "C" { @@ -50,13 +51,12 @@ Plugin::Descriptor PLUGIN_EXPORT eq_plugin_descriptor = } -EqEffect::EqEffect(Model *parent, const Plugin::Descriptor::SubPluginFeatures::Key *key) : +EqEffect::EqEffect( Model *parent, const Plugin::Descriptor::SubPluginFeatures::Key *key) : Effect( &eq_plugin_descriptor, parent, key ), m_eqControls( this ), m_inGain( 1.0 ), m_outGain( 1.0 ) { - } @@ -69,7 +69,7 @@ EqEffect::~EqEffect() -bool EqEffect::processAudioBuffer(sampleFrame *buf, const fpp_t frames) +bool EqEffect::processAudioBuffer( sampleFrame *buf, const fpp_t frames ) { // setup sample exact controls float hpRes = m_eqControls.m_hpResModel.value(); @@ -164,31 +164,34 @@ bool EqEffect::processAudioBuffer(sampleFrame *buf, const fpp_t frames) float para4Gain = m_eqControls.m_para4GainModel.value(); float highShelfGain = m_eqControls.m_highShelfGainModel.value(); - - if( !isEnabled() || !isRunning () ) { return( false ); } + if( m_eqControls.m_outGainModel.isValueChanged() ) { m_outGain = dbvToAmp(m_eqControls.m_outGainModel.value()); } + if( m_eqControls.m_inGainModel.isValueChanged() ) { m_inGain = dbvToAmp(m_eqControls.m_inGainModel.value()); } + m_eqControls.m_inProgress = true; double outSum = 0.0; + for( fpp_t f = 0; f < frames; ++f ) { outSum += buf[f][0]*buf[f][0] + buf[f][1]*buf[f][1]; } + const float outGain = m_outGain; const int sampleRate = Engine::mixer()->processingSampleRate(); sampleFrame m_inPeak = { 0, 0 }; - if(m_eqControls.m_analyseInModel.value( true ) ) + if(m_eqControls.m_analyseInModel.value( true ) && outSum > 0 ) { m_eqControls.m_inFftBands.analyze( buf, frames ); } @@ -196,14 +199,15 @@ bool EqEffect::processAudioBuffer(sampleFrame *buf, const fpp_t frames) { m_eqControls.m_inFftBands.clear(); } - gain(buf , frames, m_inGain , &m_inPeak ); + + gain( buf, frames, m_inGain, &m_inPeak ); m_eqControls.m_inPeakL = m_eqControls.m_inPeakL < m_inPeak[0] ? m_inPeak[0] : m_eqControls.m_inPeakL; m_eqControls.m_inPeakR = m_eqControls.m_inPeakR < m_inPeak[1] ? m_inPeak[1] : m_eqControls.m_inPeakR; for( fpp_t f = 0; f < frames; f++) { - if( hpActive ){ - + if( hpActive ) + { m_hp12.setParameters( sampleRate, *hpFreqPtr, *hpResPtr, 1 ); buf[f][0] = m_hp12.update( buf[f][0], 0 ); buf[f][1] = m_hp12.update( buf[f][1], 1 ); @@ -287,7 +291,7 @@ bool EqEffect::processAudioBuffer(sampleFrame *buf, const fpp_t frames) buf[f][0] = m_lp480.update( buf[f][0], 0 ); buf[f][1] = m_lp480.update( buf[f][1], 1 ); - m_lp481.setParameters( sampleRate, *lpFreqPtr, *lpResPtr, 1 ); + m_lp481.setParameters( sampleRate, *lpFreqPtr, *lpResPtr, 1 ); buf[f][0] = m_lp481.update( buf[f][0], 0 ); buf[f][1] = m_lp481.update( buf[f][1], 1 ); } @@ -313,20 +317,14 @@ bool EqEffect::processAudioBuffer(sampleFrame *buf, const fpp_t frames) lpFreqPtr += lpFreqInc; } - - - - - - - sampleFrame outPeak = { 0, 0 }; gain( buf, frames, outGain, &outPeak ); m_eqControls.m_outPeakL = m_eqControls.m_outPeakL < outPeak[0] ? outPeak[0] : m_eqControls.m_outPeakL; m_eqControls.m_outPeakR = m_eqControls.m_outPeakR < outPeak[1] ? outPeak[1] : m_eqControls.m_outPeakR; checkGate( outSum / frames ); - if(m_eqControls.m_analyseOutModel.value( true ) ) + + if(m_eqControls.m_analyseOutModel.value( true ) && outSum > 0 ) { m_eqControls.m_outFftBands.analyze( buf, frames ); setBandPeaks( &m_eqControls.m_outFftBands , ( int )( sampleRate * 0.5 ) ); @@ -335,6 +333,7 @@ bool EqEffect::processAudioBuffer(sampleFrame *buf, const fpp_t frames) { m_eqControls.m_outFftBands.clear(); } + m_eqControls.m_inProgress = false; return isRunning(); } @@ -345,19 +344,23 @@ bool EqEffect::processAudioBuffer(sampleFrame *buf, const fpp_t frames) float EqEffect::peakBand( float minF, float maxF, EqAnalyser *fft, int sr ) { float peak = -60; - float * b = fft->m_bands; + float *b = fft->m_bands; float h = 0; - for(int x = 0; x < MAX_BANDS; x++, b++) + for( int x = 0; x < MAX_BANDS; x++, b++ ) { - if( bandToFreq( x ,sr) >= minF && bandToFreq( x,sr ) <= maxF ) + if( bandToFreq( x ,sr) >= minF && bandToFreq( x,sr ) <= maxF ) { - h = 20*( log10( *b / fft->m_energy ) ); + h = 20 * ( log10( *b / fft->getEnergy() ) ); peak = h > peak ? h : peak; } } - return (peak+100)/100; + + return ( peak + 100 ) / 100; } + + + void EqEffect::setBandPeaks(EqAnalyser *fft, int samplerate ) { m_eqControls.m_lowShelfPeakR = m_eqControls.m_lowShelfPeakL = @@ -366,30 +369,30 @@ void EqEffect::setBandPeaks(EqAnalyser *fft, int samplerate ) m_eqControls.m_para1PeakL = m_eqControls.m_para1PeakR = peakBand( m_eqControls.m_para1FreqModel.value() - - (m_eqControls.m_para1FreqModel.value() * m_eqControls.m_para1BwModel.value() * 0.5), + - ( m_eqControls.m_para1FreqModel.value() * m_eqControls.m_para1BwModel.value() * 0.5 ), m_eqControls.m_para1FreqModel.value() - + (m_eqControls.m_para1FreqModel.value() * m_eqControls.m_para1BwModel.value() * 0.5), + + ( m_eqControls.m_para1FreqModel.value() * m_eqControls.m_para1BwModel.value() * 0.5 ), fft , samplerate ); m_eqControls.m_para2PeakL = m_eqControls.m_para2PeakR = peakBand( m_eqControls.m_para2FreqModel.value() - - (m_eqControls.m_para2FreqModel.value() * m_eqControls.m_para2BwModel.value() * 0.5), + - ( m_eqControls.m_para2FreqModel.value() * m_eqControls.m_para2BwModel.value() * 0.5 ), m_eqControls.m_para2FreqModel.value() - + (m_eqControls.m_para2FreqModel.value() * m_eqControls.m_para2BwModel.value() * 0.5), + + ( m_eqControls.m_para2FreqModel.value() * m_eqControls.m_para2BwModel.value() * 0.5 ), fft , samplerate ); m_eqControls.m_para3PeakL = m_eqControls.m_para3PeakR = peakBand( m_eqControls.m_para3FreqModel.value() - - (m_eqControls.m_para3FreqModel.value() * m_eqControls.m_para3BwModel.value() * 0.5), + - ( m_eqControls.m_para3FreqModel.value() * m_eqControls.m_para3BwModel.value() * 0.5 ), m_eqControls.m_para3FreqModel.value() - + (m_eqControls.m_para3FreqModel.value() * m_eqControls.m_para3BwModel.value() * 0.5), + + ( m_eqControls.m_para3FreqModel.value() * m_eqControls.m_para3BwModel.value() * 0.5 ), fft , samplerate ); m_eqControls.m_para4PeakL = m_eqControls.m_para4PeakR = peakBand( m_eqControls.m_para4FreqModel.value() - - (m_eqControls.m_para4FreqModel.value() * m_eqControls.m_para4BwModel.value() * 0.5), + - ( m_eqControls.m_para4FreqModel.value() * m_eqControls.m_para4BwModel.value() * 0.5 ), m_eqControls.m_para4FreqModel.value() - + (m_eqControls.m_para4FreqModel.value() * m_eqControls.m_para4BwModel.value() * 0.5), + + ( m_eqControls.m_para4FreqModel.value() * m_eqControls.m_para4BwModel.value() * 0.5 ), fft , samplerate ); m_eqControls.m_highShelfPeakL = m_eqControls.m_highShelfPeakR = @@ -397,10 +400,6 @@ void EqEffect::setBandPeaks(EqAnalyser *fft, int samplerate ) samplerate * 0.5 , fft, samplerate ); } - - - - extern "C" { diff --git a/plugins/Eq/EqEffect.h b/plugins/Eq/EqEffect.h index 63f76f3dd..e037f0267 100644 --- a/plugins/Eq/EqEffect.h +++ b/plugins/Eq/EqEffect.h @@ -21,29 +21,28 @@ * */ - #ifndef EQEFFECT_H #define EQEFFECT_H +#include "BasicFilters.h" #include "Effect.h" #include "EqControls.h" -#include "lmms_math.h" -#include "BasicFilters.h" #include "EqFilter.h" +#include "lmms_math.h" class EqEffect : public Effect { public: - EqEffect( Model* parent , const Descriptor::SubPluginFeatures::Key* key ); + EqEffect( Model * parent , const Descriptor::SubPluginFeatures::Key * key ); virtual ~EqEffect(); - virtual bool processAudioBuffer( sampleFrame *buf, const fpp_t frames ); - virtual EffectControls* controls() + virtual bool processAudioBuffer( sampleFrame * buf, const fpp_t frames ); + virtual EffectControls * controls() { return &m_eqControls; } - inline void gain( sampleFrame *buf, const fpp_t frames, float scale, sampleFrame* peak ) + inline void gain( sampleFrame * buf, const fpp_t frames, float scale, sampleFrame * peak ) { peak[0][0] = 0.0f; peak[0][1] = 0.0f; for( fpp_t f = 0; f < frames; ++f ) @@ -88,20 +87,14 @@ private: float m_inGain; float m_outGain; - - - - void analyze( sampleFrame *buf, const fpp_t frames, EqAnalyser* fft ); - float peakBand(float minF, float maxF,EqAnalyser*, int); + float peakBand( float minF, float maxF, EqAnalyser *, int ); inline float bandToFreq ( int index , int sampleRate ) { - return index * sampleRate / (MAX_BANDS * 2); + return index * sampleRate / ( MAX_BANDS * 2 ); } - void setBandPeaks( EqAnalyser *fft , int); - - + void setBandPeaks( EqAnalyser * fft , int ); }; #endif // EQEFFECT_H diff --git a/plugins/Eq/EqFader.h b/plugins/Eq/EqFader.h index 05d411f3a..d039d4b15 100644 --- a/plugins/Eq/EqFader.h +++ b/plugins/Eq/EqFader.h @@ -23,14 +23,15 @@ #ifndef EQFADER_H #define EQFADER_H -#include "Fader.h" -#include "EffectControls.h" -#include "MainWindow.h" -#include "GuiApplication.h" -#include "TextFloat.h" #include #include +#include "EffectControls.h" +#include "Fader.h" +#include "GuiApplication.h" +#include "MainWindow.h" +#include "TextFloat.h" + class EqFader : public Fader diff --git a/plugins/Eq/EqParameterWidget.cpp b/plugins/Eq/EqParameterWidget.cpp index ce1a7a289..e9d5f7897 100644 --- a/plugins/Eq/EqParameterWidget.cpp +++ b/plugins/Eq/EqParameterWidget.cpp @@ -24,19 +24,21 @@ */ #include "EqParameterWidget.h" -#include "lmms_math.h" -#include "EqControls.h" + +#include +#include #include #include #include +#include "EqControls.h" +#include "lmms_math.h" + EqParameterWidget::EqParameterWidget( QWidget *parent, EqControls * controls ) : QWidget( parent ), - m_bands ( 0 ), m_displayWidth ( 400 ), m_displayHeigth ( 200 ), - m_notFirst ( false ), m_controls ( controls ) { @@ -44,16 +46,16 @@ EqParameterWidget::EqParameterWidget( QWidget *parent, EqControls * controls ) : resize( m_displayWidth, m_displayHeigth ); float totalHeight = 36; // gain range from -18 to +18 m_pixelsPerUnitHeight = m_displayHeigth / totalHeight; - m_pixelsPerOctave = freqToXPixel( 10000 ) - freqToXPixel( 5000 ); + m_pixelsPerOctave = EqHandle::freqToXPixel( 10000, m_displayWidth ) - EqHandle::freqToXPixel( 5000, m_displayWidth ); //GraphicsScene and GraphicsView stuff - m_scene = new QGraphicsScene(); - m_scene->setSceneRect( 0, 0, m_displayWidth, m_displayHeigth ); - m_view = new QGraphicsView(this); - m_view->setStyleSheet( "border-style: none; background: transparent;"); - m_view->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); - m_view->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); - m_view->setScene( m_scene ); + QGraphicsScene *scene = new QGraphicsScene(); + scene->setSceneRect( 0, 0, m_displayWidth, m_displayHeigth ); + QGraphicsView *view = new QGraphicsView( this ); + view->setStyleSheet( "border-style: none; background: transparent;" ); + view->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); + view->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); + view->setScene( scene ); //adds the handles m_handleList = new QList; @@ -61,13 +63,13 @@ EqParameterWidget::EqParameterWidget( QWidget *parent, EqControls * controls ) : { m_handle = new EqHandle ( i, m_displayWidth, m_displayHeigth ); m_handleList->append( m_handle ); - m_handle->setZValue(1); - m_scene->addItem( m_handle ); + m_handle->setZValue( 1 ); + scene->addItem( m_handle ); } //adds the curve widget m_eqcurve = new EqCurve( m_handleList, m_displayWidth, m_displayHeigth ); - m_scene->addItem( m_eqcurve ); + scene->addItem( m_eqcurve ); for ( int i = 0; i < bandCount(); i++ ) { // if the data of handle position has changed update the models @@ -90,26 +92,37 @@ EqParameterWidget::~EqParameterWidget() -void EqParameterWidget::updateView() +EqBand *EqParameterWidget::getBandModels( int i ) { - for( int i = 0 ; i < bandCount() ; i++ ) + return &m_bands[i]; +} + + + + +void EqParameterWidget::updateHandle() +{ + m_eqcurve->setModelChanged( true ); + for( int i = 0 ; i < bandCount(); i++ ) { if ( m_handleList->at( i )->getHandleMoved() == false ) //prevents a short circuit between handle and data model { //sets the band on active if a fader or a knob is moved - bool hover= false; // prevents an action if handle is moved + bool hover = false; // prevents an action if handle is moved for ( int j = 0; j < bandCount(); j++ ) { - if ( m_handleList->at(j)->isMouseHover() ) hover = true; + if ( m_handleList->at(j)->isMouseHover() ) + { + hover = true; + } } if ( !hover ) { - if ( sender() == m_bands[i].gain ) m_bands[i].active->setValue( true ); + if ( sender() == m_bands[i].gain ) m_bands[i].active->setValue( true ); if ( sender() == m_bands[i].freq ) m_bands[i].active->setValue( true ); if ( sender() == m_bands[i].res ) m_bands[i].active->setValue( true ); } - - changeHandle(i); + changeHandle( i ); } else { @@ -117,8 +130,6 @@ void EqParameterWidget::updateView() m_handleList->at( i )->setHandleMoved( false ); } } - - m_notFirst = true; if ( m_bands[0].hp12->value() ) m_handleList->at( 0 )->sethp12(); if ( m_bands[0].hp24->value() ) m_handleList->at( 0 )->sethp24(); if ( m_bands[0].hp48->value() ) m_handleList->at( 0 )->sethp48(); @@ -133,13 +144,13 @@ void EqParameterWidget::updateView() void EqParameterWidget::changeHandle( int i ) { //fill x, y, and bw with data from model - float x = freqToXPixel( m_bands[i].freq->value() ); + float x = EqHandle::freqToXPixel( m_bands[i].freq->value(), m_displayWidth ); float y = m_handleList->at( i )->y(); //for pass filters there is no gain model if( m_bands[i].gain ) { float gain = m_bands[i].gain->value(); - y = gainToYPixel( gain ); + y = EqHandle::gainToYPixel( gain, m_displayHeigth, m_pixelsPerUnitHeight ); } float bw = m_bands[i].res->value(); @@ -148,7 +159,7 @@ void EqParameterWidget::changeHandle( int i ) { case 0 : m_handleList->at( i )->setType( highpass ); - m_handleList->at( i )->setPos( x, m_displayHeigth/2 ); + m_handleList->at( i )->setPos( x, m_displayHeigth / 2 ); break; case 1: m_handleList->at( i )->setType( lowshelf ); @@ -176,7 +187,7 @@ void EqParameterWidget::changeHandle( int i ) break; case 7: m_handleList->at( i )->setType( lowpass ); - m_handleList->at( i )->setPos( QPointF( x, m_displayHeigth/2 ) ); + m_handleList->at( i )->setPos( QPointF( x, m_displayHeigth / 2 ) ); break; } @@ -194,16 +205,24 @@ void EqParameterWidget::changeHandle( int i ) - +//this is called if a handle is moved void EqParameterWidget::updateModels() { for ( int i=0 ; i < bandCount(); i++ ) { - m_bands[i].freq->setValue( xPixelToFreq( m_handleList->at(i)->x() ) ); - if( m_bands[i].gain ) m_bands[i].gain->setValue( yPixelToGain( m_handleList->at(i)->y() ) ); + m_bands[i].freq->setValue( EqHandle::xPixelToFreq( m_handleList->at( i )->x(), m_displayWidth ) ); + + if( m_bands[i].gain ) + { + m_bands[i].gain->setValue( EqHandle::yPixelToGain( m_handleList->at(i)->y(), m_displayHeigth, m_pixelsPerUnitHeight ) ); + } + m_bands[i].res->setValue( m_handleList->at( i )->getResonance() ); - //sets the band on active if the handle is moved - if ( sender() == m_handleList->at( i ) ) m_bands[i].active->setValue( true ); + //identifies the handle which is moved and set the band active + if ( sender() == m_handleList->at( i ) ) + { + m_bands[i].active->setValue( true ); + } } m_eqcurve->update(); } diff --git a/plugins/Eq/EqParameterWidget.h b/plugins/Eq/EqParameterWidget.h index c503858aa..07230186b 100644 --- a/plugins/Eq/EqParameterWidget.h +++ b/plugins/Eq/EqParameterWidget.h @@ -26,127 +26,70 @@ #ifndef EQPARAMETERWIDGET_H #define EQPARAMETERWIDGET_H -#include -#include -#include -#include -#include "EffectControls.h" -#include "TextFloat.h" -#include "EqCurve.h" +#include + +#include "EffectControls.h" +#include "EqCurve.h" +#include "TextFloat.h" class EqControls; - class EqBand { public : EqBand(); - FloatModel* gain; - FloatModel* res; - FloatModel* freq; - BoolModel* active; - BoolModel* hp12; - BoolModel* hp24; - BoolModel* hp48; - BoolModel* lp12; - BoolModel* lp24; - BoolModel* lp48; + FloatModel *gain; + FloatModel *res; + FloatModel *freq; + BoolModel *active; + BoolModel *hp12; + BoolModel *hp24; + BoolModel *hp48; + BoolModel *lp12; + BoolModel *lp24; + BoolModel *lp48; QColor color; int x; int y; QString name; - float* peakL; - float* peakR; - - + float *peakL; + float *peakR; }; + class EqParameterWidget : public QWidget { Q_OBJECT public: - explicit EqParameterWidget( QWidget *parent = 0, EqControls * controls = 0); + explicit EqParameterWidget( QWidget *parent = 0, EqControls * controls = 0 ); ~EqParameterWidget(); QList *m_handleList; - void changeHandle(int i); - const int bandCount() { return 8; } - - - - EqBand* getBandModels( int i ) - { - return &m_bands[i]; - } - + EqBand* getBandModels( int i ); + void changeHandle( int i ); private: - - EqBand *m_bands; - int m_displayWidth, m_displayHeigth; - bool m_notFirst; - EqControls *m_controls; - - QGraphicsView *m_view; - QGraphicsScene *m_scene; - EqHandle *m_handle; - EqCurve *m_eqcurve; - float m_pixelsPerUnitWidth; float m_pixelsPerUnitHeight; float m_pixelsPerOctave; float m_scale; + int m_displayWidth, m_displayHeigth; + EqControls *m_controls; + EqBand *m_bands; + EqHandle *m_handle; + EqCurve *m_eqcurve; - - - inline float freqToXPixel( float freq ) - { - float min = log ( 27) / log( 10 ); - float max = log ( 20000 )/ log( 10 ); - float range = max - min; - return ( log( freq ) / log( 10 ) - min ) / range * m_displayWidth; - } - - - - - - inline float xPixelToFreq( float x ) - { - float min = log ( 27 ) / log( 10 ); - float max = log ( 20000 ) / log( 10 ); - float range = max - min; - return pow( 10 , x * ( range / m_displayWidth ) + min ); - } - - - - - inline float gainToYPixel( float gain ) - { - return m_displayHeigth - ( gain * m_pixelsPerUnitHeight ) - ( m_displayHeigth * 0.5 ); - } - - - - - inline float yPixelToGain( float y ) - { - return ( ( 0.5 * m_displayHeigth ) - y ) / m_pixelsPerUnitHeight; - } - private slots: void updateModels(); - void updateView(); + void updateHandle(); }; - #endif // EQPARAMETERWIDGET_H diff --git a/plugins/Eq/EqSpectrumView.cpp b/plugins/Eq/EqSpectrumView.cpp new file mode 100644 index 000000000..ec77bb864 --- /dev/null +++ b/plugins/Eq/EqSpectrumView.cpp @@ -0,0 +1,276 @@ +/* eqspectrumview.cpp - implementation of EqSpectrumView class. +* +* Copyright (c) 2014 David French +* +* This file is part of LMMS - http://lmms.io +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public +* License along with this program (see COPYING); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA. +* +*/ + +#include "EqSpectrumView.h" + +#include "Engine.h" +#include "EqCurve.h" +#include "GuiApplication.h" +#include "MainWindow.h" +#include "Mixer.h" + +EqAnalyser::EqAnalyser() : + m_framesFilledUp ( 0 ), + m_energy ( 0 ), + m_sampleRate ( 1 ), + m_active ( true ) +{ + m_inProgress=false; + m_specBuf = ( fftwf_complex * ) fftwf_malloc( ( FFT_BUFFER_SIZE + 1 ) * sizeof( fftwf_complex ) ); + m_fftPlan = fftwf_plan_dft_r2c_1d( FFT_BUFFER_SIZE*2, m_buffer, m_specBuf, FFTW_MEASURE ); + clear(); +} + + + + +EqAnalyser::~EqAnalyser() +{ + fftwf_destroy_plan( m_fftPlan ); + fftwf_free( m_specBuf ); +} + + + + +void EqAnalyser::analyze( sampleFrame *buf, const fpp_t frames ) +{ + //only analyse if the view is visible + if ( m_active ) + { + m_inProgress=true; + const int FFT_BUFFER_SIZE = 2048; + fpp_t f = 0; + if( frames > FFT_BUFFER_SIZE ) + { + m_framesFilledUp = 0; + f = frames - FFT_BUFFER_SIZE; + } + // meger channels + for( ; f < frames; ++f ) + { + m_buffer[m_framesFilledUp] = + ( buf[f][0] + buf[f][1] ) * 0.5; + ++m_framesFilledUp; + } + + if( m_framesFilledUp < FFT_BUFFER_SIZE ) + { + m_inProgress = false; + return; + } + + m_sampleRate = Engine::mixer()->processingSampleRate(); + const int LOWEST_FREQ = 0; + const int HIGHEST_FREQ = m_sampleRate / 2; + + fftwf_execute( m_fftPlan ); + absspec( m_specBuf, m_absSpecBuf, FFT_BUFFER_SIZE+1 ); + + compressbands( m_absSpecBuf, m_bands, FFT_BUFFER_SIZE+1, + MAX_BANDS, + ( int )( LOWEST_FREQ * ( FFT_BUFFER_SIZE + 1 ) / ( float )( m_sampleRate / 2 ) ), + ( int )( HIGHEST_FREQ * ( FFT_BUFFER_SIZE + 1) / ( float )( m_sampleRate / 2 ) ) ); + m_energy = maximum( m_bands, MAX_BANDS ) / maximum( m_buffer, FFT_BUFFER_SIZE ); + + m_framesFilledUp = 0; + m_inProgress = false; + m_active = false; + } +} + + + + +float EqAnalyser::getEnergy() const +{ + return m_energy; +} + + + + +int EqAnalyser::getSampleRate() const +{ + return m_sampleRate; +} + + + + +bool EqAnalyser::getActive() const +{ + return m_active; +} + + + + +void EqAnalyser::setActive(bool active) +{ + m_active = active; +} + + + + +bool EqAnalyser::getInProgress() +{ + return m_inProgress; +} + + + + +void EqAnalyser::clear() +{ + m_framesFilledUp = 0; + m_energy = 0; + memset( m_buffer, 0, sizeof( m_buffer ) ); + memset( m_bands, 0, sizeof( m_bands ) ); +} + + + + +EqSpectrumView::EqSpectrumView(EqAnalyser *b, QWidget *_parent) : + QWidget( _parent ), + m_analyser( b ), + m_periodicalUpdate( false ) +{ + setFixedSize( 400, 200 ); + connect( gui->mainWindow(), SIGNAL( periodicUpdate() ), this, SLOT( periodicalUpdate() ) ); + setAttribute( Qt::WA_TranslucentBackground, true ); + m_skipBands = MAX_BANDS * 0.5; + float totalLength = log10( 20000 ); + m_pixelsPerUnitWidth = width( ) / totalLength ; + m_scale = 1.5; + m_color = QColor( 255, 255, 255, 255 ); + for ( int i = 0 ; i < MAX_BANDS ; i++ ) + { + m_bandHeight.append( 0 ); + } +} + + + + +void EqSpectrumView::paintEvent(QPaintEvent *event) +{ + //only analyse if the view is visible + m_analyser->setActive( isVisible() ); + const float energy = m_analyser->getEnergy(); + if( energy <= 0 && m_peakSum <= 0 ) + { + //dont draw anything + return; + } + + const int fh = height(); + const int LOWER_Y = -36; // dB + QPainter painter( this ); + painter.setPen( QPen( m_color, 1, Qt::SolidLine, Qt::RoundCap, Qt::BevelJoin ) ); + + if( m_analyser->getInProgress() || m_periodicalUpdate == false ) + { + //only paint the cached path + painter.fillPath( m_path, QBrush( m_color ) ); + return; + } + + m_periodicalUpdate = false; + //Now we calculate the path + m_path = QPainterPath(); + float *bands = m_analyser->m_bands; + float peak; + m_path.moveTo( 0, height() ); + m_peakSum = 0; + float fallOff = 1.2; + for( int x = 0; x < MAX_BANDS; ++x, ++bands ) + { + peak = ( fh * 2.0 / 3.0 * ( 20 * ( log10( *bands / energy ) ) - LOWER_Y ) / ( - LOWER_Y ) ); + if( peak < 0 ) + { + peak = 0; + } + else if( peak >= fh ) + { + continue; + } + + if ( peak > m_bandHeight[x] ) + { + m_bandHeight[x] = peak; + } + else + { + m_bandHeight[x] = m_bandHeight[x] / fallOff; + } + + if( m_bandHeight[x] < 0 ) + { + m_bandHeight[x] = 0; + } + + m_path.lineTo( EqHandle::freqToXPixel( bandToFreq( x ), width() ), fh - m_bandHeight[x] ); + m_peakSum += m_bandHeight[x]; + } + + m_path.lineTo( width(), height() ); + m_path.closeSubpath(); + painter.fillPath( m_path, QBrush( m_color ) ); + painter.drawPath( m_path ); +} + + + + +QColor EqSpectrumView::getColor() const +{ + return m_color; +} + + + + +void EqSpectrumView::setColor( const QColor &value ) +{ + m_color = value; +} + + + + +float EqSpectrumView::bandToFreq( int index ) +{ + return index * m_analyser->getSampleRate() / ( MAX_BANDS * 2 ); +} + + + + +void EqSpectrumView::periodicalUpdate() +{ + m_periodicalUpdate = true; + update(); +} diff --git a/plugins/Eq/EqSpectrumView.h b/plugins/Eq/EqSpectrumView.h index b1a084b5c..98a3f9586 100644 --- a/plugins/Eq/EqSpectrumView.h +++ b/plugins/Eq/EqSpectrumView.h @@ -25,9 +25,10 @@ #include #include -#include "fft_helpers.h" -#include "Engine.h" +#include "fft_helpers.h" +#include "lmms_basics.h" +#include "lmms_math.h" const int MAX_BANDS = 2048; @@ -35,220 +36,65 @@ const int MAX_BANDS = 2048; class EqAnalyser { public: + EqAnalyser(); + virtual ~EqAnalyser(); + float m_bands[MAX_BANDS]; + bool getInProgress(); + void clear(); + + void analyze( sampleFrame *buf, const fpp_t frames ); + + float getEnergy() const; + int getSampleRate() const; + bool getActive() const; + + void setActive(bool active); + +private: fftwf_plan m_fftPlan; fftwf_complex * m_specBuf; float m_absSpecBuf[FFT_BUFFER_SIZE+1]; float m_buffer[FFT_BUFFER_SIZE*2]; int m_framesFilledUp; - float m_bands[MAX_BANDS]; float m_energy; - int m_sr; + int m_sampleRate; bool m_active; - - - EqAnalyser() : - m_framesFilledUp ( 0 ), - m_energy ( 0 ), - m_sr ( 1 ), - m_active ( true ) - { - m_inProgress=false; - m_specBuf = ( fftwf_complex * ) fftwf_malloc( ( FFT_BUFFER_SIZE + 1 ) * sizeof( fftwf_complex ) ); - m_fftPlan = fftwf_plan_dft_r2c_1d( FFT_BUFFER_SIZE*2, m_buffer, m_specBuf, FFTW_MEASURE ); - clear(); - } - - virtual ~EqAnalyser() - { - fftwf_destroy_plan( m_fftPlan ); - fftwf_free( m_specBuf ); - } - - - bool getInProgress() - { - return m_inProgress; - } - - - - void clear() - { - m_framesFilledUp = 0; - m_energy = 0; - memset( m_buffer, 0, sizeof( m_buffer ) ); - memset( m_bands, 0, sizeof( m_bands ) ); - } - - - - void analyze( sampleFrame *buf, const fpp_t frames ) - { - if ( m_active ) - { - m_inProgress=true; - const int FFT_BUFFER_SIZE = 2048; - fpp_t f = 0; - if( frames > FFT_BUFFER_SIZE ) - { - m_framesFilledUp = 0; - f = frames - FFT_BUFFER_SIZE; - } - // meger channels - for( ; f < frames; ++f ) - { - m_buffer[m_framesFilledUp] = - ( buf[f][0] + buf[f][1] ) * 0.5; - ++m_framesFilledUp; - } - - if( m_framesFilledUp < FFT_BUFFER_SIZE ) - { - m_inProgress = false; - return; - } - - m_sr = Engine::mixer()->processingSampleRate(); - const int LOWEST_FREQ = 0; - const int HIGHEST_FREQ = m_sr / 2; - - fftwf_execute( m_fftPlan ); - absspec( m_specBuf, m_absSpecBuf, FFT_BUFFER_SIZE+1 ); - - compressbands( m_absSpecBuf, m_bands, FFT_BUFFER_SIZE+1, - MAX_BANDS, - ( int )( LOWEST_FREQ * ( FFT_BUFFER_SIZE + 1 ) / ( float )( m_sr / 2 ) ), - ( int )( HIGHEST_FREQ * ( FFT_BUFFER_SIZE + 1) / ( float )( m_sr / 2 ) ) ); - m_energy = maximum( m_bands, MAX_BANDS ) / maximum( m_buffer, FFT_BUFFER_SIZE ); - - - m_framesFilledUp = 0; - m_inProgress = false; - m_active = false; - } - } -private: bool m_inProgress; }; + + class EqSpectrumView : public QWidget { - + Q_OBJECT public: - explicit EqSpectrumView( EqAnalyser * b, QWidget * _parent = 0 ): - QWidget( _parent ), - m_sa( b ) - { - setFixedSize( 400, 200 ); - QTimer *timer = new QTimer(this); - connect(timer, SIGNAL(timeout()), this, SLOT(update())); - timer->start(20); - setAttribute( Qt::WA_TranslucentBackground, true ); - m_skipBands = MAX_BANDS * 0.5; - float totalLength = log10( 20000 ); - m_pixelsPerUnitWidth = width( ) / totalLength ; - m_scale = 1.5; - color = QColor( 255, 255, 255, 255 ); - for ( int i=0 ; i < MAX_BANDS ; i++ ) - { - m_bandHeight.append( 0 ); - } - } - - - - + explicit EqSpectrumView( EqAnalyser *b, QWidget *_parent = 0 ); virtual ~EqSpectrumView() { } + QColor getColor() const; + void setColor( const QColor &value ); +protected: + virtual void paintEvent( QPaintEvent *event ); - - QColor color; - EqAnalyser *m_sa; - QPainterPath pp; - virtual void paintEvent( QPaintEvent* event ) - { - m_sa->m_active = isVisible(); - const int fh = height(); - const int LOWER_Y = -36; // dB - QPainter p( this ); - p.setPen( QPen( color, 1, Qt::SolidLine, Qt::RoundCap, Qt::BevelJoin ) ); - const float e = m_sa->m_energy; - if( e <= 0 ) - { - //dont draw anything - return; - } - if(m_sa->getInProgress() ){ - p.fillPath( pp ,QBrush( color ) ); - return; - } - pp = QPainterPath(); - float * b = m_sa->m_bands; - float h; - pp.moveTo( 0,height() ); - for( int x = 0; x < MAX_BANDS; ++x, ++b ) - { - h = ( fh * 2.0 / 3.0 * ( 20 * ( log10( *b / e ) ) - LOWER_Y ) / (-LOWER_Y ) ); - if( h < 0 ) - { - h = 0; - } - else if( h >= fh ) - { - continue; - } - if (h > m_bandHeight.at(x)) - { - m_bandHeight[x] = h; - } - else - { - m_bandHeight[x] = m_bandHeight[x] -1; - } - pp.lineTo( freqToXPixel( bandToFreq( x ) ), fh - m_bandHeight.at( x ) ); - } - pp.lineTo( width(), height() ); - pp.closeSubpath(); - p.fillPath( pp, QBrush( color ) ); - p.drawPath( pp ); - } - - - - - inline int bandToXPixel( float band ) - { - return ( log10( band - m_skipBands ) * m_pixelsPerUnitWidth * m_scale ); - } - - - - - inline float bandToFreq ( int index ) - { - return index * m_sa->m_sr / (MAX_BANDS * 2 ); - } - - - - - inline float freqToXPixel( float freq ) - { - float min = log ( 27) / log( 10 ); - float max = log ( 20000 )/ log( 10 ); - float range = max - min; - return ( log( freq ) / log( 10 ) - min ) / range * width(); - } +private slots: + void periodicalUpdate(); private: + QColor m_color; + EqAnalyser *m_analyser; + QPainterPath m_path; + float m_peakSum; float m_pixelsPerUnitWidth; float m_scale; int m_skipBands; + bool m_periodicalUpdate; QList m_bandHeight; -} ; + + float bandToFreq ( int index ); +}; #endif // EQSPECTRUMVIEW_H