From 465aa1afbc107d7bd57769e4c68347ea28437d63 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Sun, 18 May 2014 15:53:18 +0200 Subject: [PATCH] EffectChain: remember original effect plugin data when loading dummy plugin We don't want to loose the settings of an effect plugin even if it's not available and thus can't be instantiated. Therefore remember original settings data and save them back properly. Partly closes #733. --- include/DummyEffect.h | 12 ++++++++++-- src/core/Effect.cpp | 14 +++++++------- src/core/EffectChain.cpp | 42 ++++++++++++++++++++++------------------ 3 files changed, 40 insertions(+), 28 deletions(-) diff --git a/include/DummyEffect.h b/include/DummyEffect.h index a0777bde1..30d267cce 100644 --- a/include/DummyEffect.h +++ b/include/DummyEffect.h @@ -82,9 +82,10 @@ public: class DummyEffect : public Effect { public: - DummyEffect( Model * _parent ) : + DummyEffect( Model * _parent, const QDomElement& originalPluginData ) : Effect( NULL, _parent, NULL ), - m_controls( this ) + m_controls( this ), + m_originalPluginData( originalPluginData ) { } @@ -102,9 +103,16 @@ public: return false; } + const QDomElement& originalPluginData() const + { + return m_originalPluginData; + } + + private: DummyEffectControls m_controls; + const QDomElement m_originalPluginData; } ; diff --git a/src/core/Effect.cpp b/src/core/Effect.cpp index 4917ef8fb..619ed438e 100644 --- a/src/core/Effect.cpp +++ b/src/core/Effect.cpp @@ -2,7 +2,7 @@ * Effect.cpp - base-class for effects * * Copyright (c) 2006-2007 Danny McRae - * Copyright (c) 2006-2009 Tobias Doerffel + * Copyright (c) 2006-2014 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -23,7 +23,6 @@ * */ - #include #include @@ -31,8 +30,8 @@ #include "Effect.h" #include "engine.h" -#include "DummyEffect.h" #include "EffectChain.h" +#include "EffectControls.h" #include "EffectView.h" @@ -110,11 +109,11 @@ void Effect::loadSettings( const QDomElement & _this ) -Effect * Effect::instantiate( const QString & _plugin_name, +Effect * Effect::instantiate( const QString& pluginName, Model * _parent, Descriptor::SubPluginFeatures::Key * _key ) { - Plugin * p = Plugin::instantiate( _plugin_name, _parent, _key ); + Plugin * p = Plugin::instantiate( pluginName, _parent, _key ); // check whether instantiated plugin is an effect if( dynamic_cast( p ) != NULL ) { @@ -124,9 +123,10 @@ Effect * Effect::instantiate( const QString & _plugin_name, return effect; } - // not quite... so delete plugin and return dummy effect + // not quite... so delete plugin and leave it up to the caller to instantiate a DummyEffect delete p; - return new DummyEffect( _parent ); + + return NULL; } diff --git a/src/core/EffectChain.cpp b/src/core/EffectChain.cpp index 54ef54bc5..89e902866 100644 --- a/src/core/EffectChain.cpp +++ b/src/core/EffectChain.cpp @@ -56,12 +56,19 @@ void EffectChain::saveSettings( QDomDocument & _doc, QDomElement & _this ) { _this.setAttribute( "enabled", m_enabledModel.value() ); _this.setAttribute( "numofeffects", m_effects.count() ); - for( EffectList::Iterator it = m_effects.begin(); - it != m_effects.end(); it++ ) + + for( EffectList::Iterator it = m_effects.begin(); it != m_effects.end(); it++ ) { - QDomElement ef = ( *it )->saveState( _doc, _this ); - ef.setAttribute( "name", ( *it )->descriptor()->name ); - ef.appendChild( ( *it )->key().saveXML( _doc ) ); + if( dynamic_cast( *it ) ) + { + _this.appendChild( dynamic_cast( *it )->originalPluginData() ); + } + else + { + QDomElement ef = ( *it )->saveState( _doc, _this ); + ef.setAttribute( "name", ( *it )->descriptor()->name ); + ef.appendChild( ( *it )->key().saveXML( _doc ) ); + } } } @@ -82,26 +89,23 @@ void EffectChain::loadSettings( const QDomElement & _this ) { if( node.isElement() && node.nodeName() == "effect" ) { - QDomElement cn = node.toElement(); - const QString name = cn.attribute( "name" ); - EffectKey key( cn.elementsByTagName( "key" ). - item( 0 ).toElement() ); - Effect * e = Effect::instantiate( name, this, &key ); - if( e->isOkay() ) + QDomElement effectData = node.toElement(); + + const QString name = effectData.attribute( "name" ); + EffectKey key( effectData.elementsByTagName( "key" ).item( 0 ).toElement() ); + + Effect* e = Effect::instantiate( name, this, &key ); + + if( e != NULL && e->isOkay() && e->nodeName() == node.nodeName() ) { - if( node.isElement() ) - { - if( e->nodeName() == node.nodeName() ) - { - e->restoreState( node.toElement() ); - } - } + e->restoreState( effectData ); } else { delete e; - e = new DummyEffect( parentModel() ); + e = new DummyEffect( parentModel(), effectData ); } + m_effects.push_back( e ); ++fx_loaded; }