From 56fd8a3eb28cfec8a87ca0511c550f59903b64cd Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Sat, 12 Apr 2008 15:11:28 +0000 Subject: [PATCH] made LADSPA-effect-hoster handle samplerate-changes so that we've proper effect-processing in HQ-mode git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@914 0778d3d1-df1d-0410-868b-ea421aaaa00d --- ChangeLog | 30 ++++++++ include/effect_control_dialog.h | 2 - plugins/ladspa_effect/Makefile.am | 2 +- .../ladspa_effect/ladspa_control_dialog.cpp | 69 ++++++++++++++----- plugins/ladspa_effect/ladspa_control_dialog.h | 10 +++ plugins/ladspa_effect/ladspa_controls.cpp | 5 +- plugins/ladspa_effect/ladspa_controls.h | 10 ++- plugins/ladspa_effect/ladspa_effect.cpp | 65 ++++++++++++++--- plugins/ladspa_effect/ladspa_effect.h | 14 +++- 9 files changed, 169 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index 44de7136d..5f120757f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,33 @@ +2008-04-12 Tobias Doerffel + + * plugins/ladspa_effect/ladspa_effect.cpp: + * plugins/ladspa_effect/ladspa_control_dialog.cpp: + * plugins/ladspa_effect/ladspa_effect.h: + * plugins/ladspa_effect/ladspa_controls.cpp: + * plugins/ladspa_effect/Makefile.am: + * plugins/ladspa_effect/ladspa_control_dialog.h: + * plugins/ladspa_effect/ladspa_controls.h: + * include/effect_control_dialog.h: + made LADSPA-effect-hoster handle samplerate-changes so that we've + proper effect-processing in HQ-mode + + * include/lmms_constants.h: + more accurate constants + + * src/gui/export_project_dialog.cpp: + fixed progress-bar after change of tick-resolution from 64 to 192 + + * include/mixer.h: + * src/core/mixer.cpp: + made clearAudioBuffer() static + + * include/song.h: + * src/core/ladspa_manager.cpp: + coding-style-stuff + + * src/core/oscillator.cpp: + do not synthesize anything if frequency is above half of samplerate + 2008-04-09 Tobias Doerffel * plugins/flp_import/flp_import.cpp: diff --git a/include/effect_control_dialog.h b/include/effect_control_dialog.h index b0a6a4f6d..82fb3866b 100644 --- a/include/effect_control_dialog.h +++ b/include/effect_control_dialog.h @@ -49,8 +49,6 @@ signals: protected: virtual void closeEvent( QCloseEvent * _ce ); - -private: effectControls * m_effectControls; } ; diff --git a/plugins/ladspa_effect/Makefile.am b/plugins/ladspa_effect/Makefile.am index eec271be3..054b7a8d4 100644 --- a/plugins/ladspa_effect/Makefile.am +++ b/plugins/ladspa_effect/Makefile.am @@ -15,7 +15,7 @@ AM_CXXFLAGS := $(AM_CXXFLAGS) $(QT_CXXFLAGS) -DPLUGIN_NAME="ladspaeffect" $(MOC) -o $@ $< -MOC_FILES = ./ladspa_controls.moc +MOC_FILES = ./ladspa_effect.moc ./ladspa_controls.moc ./ladspa_control_dialog.moc BUILT_SOURCES = $(MOC_FILES) ./embedded_resources.h diff --git a/plugins/ladspa_effect/ladspa_control_dialog.cpp b/plugins/ladspa_effect/ladspa_control_dialog.cpp index a869913f2..0bac6dcb9 100644 --- a/plugins/ladspa_effect/ladspa_control_dialog.cpp +++ b/plugins/ladspa_effect/ladspa_control_dialog.cpp @@ -35,11 +35,49 @@ ladspaControlDialog::ladspaControlDialog( ladspaControls * _ctl ) : - effectControlDialog( _ctl ) + effectControlDialog( _ctl ), + m_effectLayout( NULL ), + m_stereoLink( NULL ) { QVBoxLayout * mainLay = new QVBoxLayout( this ); - QHBoxLayout * effectLay = new QHBoxLayout(); - mainLay->addLayout( effectLay ); + + m_effectLayout = new QHBoxLayout(); + mainLay->addLayout( m_effectLayout ); + + updateEffectView( _ctl ); + + if( _ctl->m_processors > 1 ) + { + mainLay->addSpacing( 3 ); + QHBoxLayout * center = new QHBoxLayout(); + mainLay->addLayout( center ); + m_stereoLink = new ledCheckBox( tr( "Link Channels" ), this ); + m_stereoLink->setModel( &_ctl->m_stereoLinkModel ); + center->addWidget( m_stereoLink ); + } +} + + + + +ladspaControlDialog::~ladspaControlDialog() +{ +} + + + + +void ladspaControlDialog::updateEffectView( ladspaControls * _ctl ) +{ + QList list = findChildren(); + for( QList::iterator it = list.begin(); it != list.end(); + ++it ) + { + delete *it; + } + + m_effectControls = _ctl; + const int cols = static_cast( sqrt( static_cast( _ctl->m_controlCount / @@ -56,7 +94,7 @@ ladspaControlDialog::ladspaControlDialog( ladspaControls * _ctl ) : { grouper = new QGroupBox( tr( "Channel " ) + QString::number( proc + 1 ), - this ); + this ); } else { @@ -94,26 +132,19 @@ ladspaControlDialog::ladspaControlDialog( ladspaControls * _ctl ) : } } - effectLay->addWidget( grouper ); + m_effectLayout->addWidget( grouper ); } - if( _ctl->m_processors > 1 ) + if( _ctl->m_processors > 1 && m_stereoLink != NULL ) { - mainLay->addSpacing( 3 ); - QHBoxLayout * center = new QHBoxLayout(); - mainLay->addLayout( center ); - ledCheckBox * stereoLink = new ledCheckBox( - tr( "Link Channels" ), this ); - stereoLink->setModel( &_ctl->m_stereoLinkModel ); - center->addWidget( stereoLink ); + m_stereoLink->setModel( &_ctl->m_stereoLinkModel ); } + + connect( _ctl, SIGNAL( effectModelChanged( ladspaControls * ) ), + this, SLOT( updateEffectView( ladspaControls * ) ), + Qt::DirectConnection ); } - - -ladspaControlDialog::~ladspaControlDialog() -{ -} - +#include "ladspa_control_dialog.moc" diff --git a/plugins/ladspa_effect/ladspa_control_dialog.h b/plugins/ladspa_effect/ladspa_control_dialog.h index 5d05841cc..b51dba973 100644 --- a/plugins/ladspa_effect/ladspa_control_dialog.h +++ b/plugins/ladspa_effect/ladspa_control_dialog.h @@ -29,16 +29,26 @@ #include "effect_control_dialog.h" +class QHBoxLayout; class ladspaControls; +class ledCheckBox; class ladspaControlDialog : public effectControlDialog { + Q_OBJECT public: ladspaControlDialog( ladspaControls * _ctl ); ~ladspaControlDialog(); +private slots: + void updateEffectView( ladspaControls * _ctl ); + + +private: + QHBoxLayout * m_effectLayout; + ledCheckBox * m_stereoLink; } ; diff --git a/plugins/ladspa_effect/ladspa_controls.cpp b/plugins/ladspa_effect/ladspa_controls.cpp index 6fcc9ec1c..bb26ae51b 100644 --- a/plugins/ladspa_effect/ladspa_controls.cpp +++ b/plugins/ladspa_effect/ladspa_controls.cpp @@ -101,8 +101,7 @@ ladspaControls::~ladspaControls() -void FASTCALL ladspaControls::saveSettings( QDomDocument & _doc, - QDomElement & _this ) +void ladspaControls::saveSettings( QDomDocument & _doc, QDomElement & _this ) { if( m_processors > 1 ) { @@ -123,7 +122,7 @@ void FASTCALL ladspaControls::saveSettings( QDomDocument & _doc, -void FASTCALL ladspaControls::loadSettings( const QDomElement & _this ) +void ladspaControls::loadSettings( const QDomElement & _this ) { if( m_processors > 1 ) { diff --git a/plugins/ladspa_effect/ladspa_controls.h b/plugins/ladspa_effect/ladspa_controls.h index 007f8906a..ec1b00c95 100644 --- a/plugins/ladspa_effect/ladspa_controls.h +++ b/plugins/ladspa_effect/ladspa_controls.h @@ -47,9 +47,8 @@ public: return( m_controlCount ); } - virtual void FASTCALL saveSettings( QDomDocument & _doc, - QDomElement & _parent ); - virtual void FASTCALL loadSettings( const QDomElement & _this ); + virtual void saveSettings( QDomDocument & _doc, QDomElement & _parent ); + virtual void loadSettings( const QDomElement & _this ); inline virtual QString nodeName( void ) const { return( "ladspacontrols" ); @@ -77,6 +76,11 @@ private: friend class ladspaControlDialog; + friend class ladspaEffect; + + +signals: + void effectModelChanged( ladspaControls * ); } ; diff --git a/plugins/ladspa_effect/ladspa_effect.cpp b/plugins/ladspa_effect/ladspa_effect.cpp index 37aebbc83..829a01ff0 100644 --- a/plugins/ladspa_effect/ladspa_effect.cpp +++ b/plugins/ladspa_effect/ladspa_effect.cpp @@ -23,10 +23,10 @@ */ -#include "ladspa_effect.h" - #include +#include "ladspa_effect.h" +#include "mmp.h" #include "audio_device.h" #include "config_mgr.h" #include "ladspa_2_lmms.h" @@ -78,7 +78,46 @@ ladspaEffect::ladspaEffect( model * _parent, } setPublicName( manager->getShortName( m_key ) ); - + + pluginInstantiation(); + + connect( engine::getMixer(), SIGNAL( sampleRateChanged() ), + this, SLOT( changeSampleRate() ) ); +} + + + + +ladspaEffect::~ladspaEffect() +{ + pluginDestruction(); +} + + + + +void ladspaEffect::changeSampleRate( void ) +{ + multimediaProject mmp( multimediaProject::EffectSettings ); + m_controls->saveState( mmp, mmp.content() ); + ladspaControls * controls = m_controls; + m_controls = NULL; + m_pluginMutex.lock(); + pluginDestruction(); + pluginInstantiation(); + m_pluginMutex.unlock(); + m_controls->restoreState( mmp.content().firstChild().toElement() ); + controls->effectModelChanged( m_controls ); + delete controls; +} + + + + +void ladspaEffect::pluginInstantiation( void ) +{ + ladspa2LMMS * manager = engine::getLADSPAManager(); + // Calculate how many processing units are needed. const ch_cnt_t lmms_chnls = engine::getMixer()->audioDev()->channels(); m_effectChannels = manager->getDescription( m_key )->inputChannels; @@ -293,8 +332,8 @@ ladspaEffect::ladspaEffect( model * _parent, { manager->activate( m_key, m_handles[proc] ); } - track * t = dynamic_cast( _parent ) ? - dynamic_cast( _parent )->getTrack() : + track * t = dynamic_cast( parent() ) ? + dynamic_cast( parent() )->getTrack() : NULL; m_controls = new ladspaControls( this, t ); } @@ -302,13 +341,15 @@ ladspaEffect::ladspaEffect( model * _parent, -ladspaEffect::~ladspaEffect() +void ladspaEffect::pluginDestruction( void ) { if( !isOkay() ) { return; } + delete m_controls; + for( ch_cnt_t proc = 0; proc < getProcessorCount(); proc++ ) { ladspa2LMMS * manager = engine::getLADSPAManager(); @@ -323,6 +364,7 @@ ladspaEffect::~ladspaEffect() } m_ports.clear(); m_handles.clear(); + m_portControls.clear(); } @@ -331,8 +373,10 @@ ladspaEffect::~ladspaEffect() bool ladspaEffect::processAudioBuffer( sampleFrame * _buf, const fpp_t _frames ) { + m_pluginMutex.lock(); if( !isOkay() || dontRun() || !isRunning() || !isEnabled() ) { + m_pluginMutex.unlock(); return( FALSE ); } @@ -455,13 +499,15 @@ bool ladspaEffect::processAudioBuffer( sampleFrame * _buf, resetBufferCount(); } - return( isRunning() ); + bool is_running = isRunning(); + m_pluginMutex.unlock(); + return( is_running ); } -void FASTCALL ladspaEffect::setControl( Uint16 _control, LADSPA_Data _value ) +void ladspaEffect::setControl( Uint16 _control, LADSPA_Data _value ) { if( !isOkay() ) { @@ -484,3 +530,6 @@ plugin * lmms_plugin_main( model * _parent, void * _data ) } + +#include "ladspa_effect.moc" + diff --git a/plugins/ladspa_effect/ladspa_effect.h b/plugins/ladspa_effect/ladspa_effect.h index 127a7fcfb..4c9eb4e9f 100644 --- a/plugins/ladspa_effect/ladspa_effect.h +++ b/plugins/ladspa_effect/ladspa_effect.h @@ -25,7 +25,7 @@ #ifndef _LADSPA_EFFECT_H #define _LADSPA_EFFECT_H -#include +#include #include "effect.h" #include "engine.h" @@ -39,6 +39,7 @@ typedef QVector multi_proc_t; class ladspaEffect : public effect { + Q_OBJECT public: ladspaEffect( model * _parent, const descriptor::subPluginFeatures::key * _key ); @@ -47,7 +48,7 @@ public: virtual bool processAudioBuffer( sampleFrame * _buf, const fpp_t _frames ); - void FASTCALL setControl( Uint16 _control, LADSPA_Data _data ); + void setControl( Uint16 _control, LADSPA_Data _data ); virtual effectControls * getControls( void ) { @@ -70,7 +71,16 @@ public: } +private slots: + void changeSampleRate( void ); + + private: + void pluginInstantiation( void ); + void pluginDestruction( void ); + + + QMutex m_pluginMutex; ladspaControls * m_controls; QString m_effName;