From 3d8de17c226712f6c4a831a5343f747ce5514190 Mon Sep 17 00:00:00 2001 From: lllucius Date: Wed, 5 Nov 2014 20:41:29 +0000 Subject: [PATCH] Slightly better error handling during effect initialization It at least detects load failures now. ;-) --- src/effects/Effect.cpp | 120 +++++++++++++++++----------------- src/effects/Effect.h | 2 +- src/effects/EffectManager.cpp | 19 ++++-- 3 files changed, 75 insertions(+), 66 deletions(-) diff --git a/src/effects/Effect.cpp b/src/effects/Effect.cpp index 3ae2ac471..5bd1196e1 100644 --- a/src/effects/Effect.cpp +++ b/src/effects/Effect.cpp @@ -67,65 +67,6 @@ wxString Effect::StripAmpersand(const wxString& str) // Legacy (or full blown effect) Effect::Effect() -{ - CommonInit(); -} - -// Effect hosting an effect client -Effect::Effect(EffectClientInterface *client) -{ - CommonInit(); - - mClient = client; - mClient->SetHost(this); - mClient->Startup(); - - mNumAudioIn = mClient->GetAudioInCount(); - mNumAudioOut = mClient->GetAudioOutCount(); - - mInBuffer = NULL; - mOutBuffer = NULL; - mInBufPos = NULL; - mOutBufPos = NULL; - - mBufferSize = 0; - mBlockSize = 0; - mNumChannels = 0; - - int flags = PLUGIN_EFFECT; - switch (mClient->GetType()) - { - case EffectTypeGenerate: - flags |= INSERT_EFFECT; - break; - - case EffectTypeProcess: - flags |= PROCESS_EFFECT; - break; - - case EffectTypeAnalyze: - flags |= INSERT_EFFECT; - break; - } - - SetEffectFlags(flags); -} - -Effect::~Effect() -{ - if (mClient) - { - mClient->Shutdown(); - delete mClient; - } - - if (mWarper != NULL) - { - delete mWarper; - } -} - -void Effect::CommonInit() { mClient = NULL; @@ -142,6 +83,31 @@ void Effect::CommonInit() // Can change effect flags later (this is the new way) // OR using the old way, over-ride GetEffectFlags(). mFlags = BUILTIN_EFFECT | PROCESS_EFFECT | ADVANCED_EFFECT; + + mNumAudioIn = 0; + mNumAudioOut = 0; + + mInBuffer = NULL; + mOutBuffer = NULL; + mInBufPos = NULL; + mOutBufPos = NULL; + + mBufferSize = 0; + mBlockSize = 0; + mNumChannels = 0; +} + +Effect::~Effect() +{ + if (mClient) + { + mClient->Shutdown(); + } + + if (mWarper != NULL) + { + delete mWarper; + } } // EffectIdentInterface implementation @@ -416,6 +382,42 @@ bool Effect::SetPrivateConfig(const wxString & group, const wxString & key, cons // Effect implementation +bool Effect::Startup(EffectClientInterface *client) +{ + // Need to set host now so client startup can use our services + client->SetHost(this); + + // Bail if the client startup fails + if (!client->Startup()) + { + return false; + } + + // Let destructor know we need to be shutdown + mClient = client; + + mNumAudioIn = mClient->GetAudioInCount(); + mNumAudioOut = mClient->GetAudioOutCount(); + + int flags = PLUGIN_EFFECT; + switch (mClient->GetType()) + { + case EffectTypeGenerate: + flags |= INSERT_EFFECT; + break; + + case EffectTypeProcess: + flags |= PROCESS_EFFECT; + break; + + case EffectTypeAnalyze: + flags |= INSERT_EFFECT; + break; + } + + SetEffectFlags(flags); +} + // All legacy effects should have this overridden wxString Effect::GetEffectName() { diff --git a/src/effects/Effect.h b/src/effects/Effect.h index e0f82125e..5aedbf50a 100644 --- a/src/effects/Effect.h +++ b/src/effects/Effect.h @@ -74,7 +74,6 @@ class AUDACITY_DLL_API Effect : public EffectHostInterface // The constructor is called once by each subclass at the beginning of the program. // Avoid allocating memory or doing time-consuming processing here. Effect(); - Effect(EffectClientInterface *client); virtual ~Effect(); // IdentInterface implementation @@ -131,6 +130,7 @@ class AUDACITY_DLL_API Effect : public EffectHostInterface virtual bool SetPrivateConfig(const wxString & group, const wxString & key, const sampleCount & value); // Effect implementation + virtual bool Startup(EffectClientInterface *client); // Each subclass of Effect should override this method. // This name will go in the menu bar; diff --git a/src/effects/EffectManager.cpp b/src/effects/EffectManager.cpp index 8027efccf..965305178 100644 --- a/src/effects/EffectManager.cpp +++ b/src/effects/EffectManager.cpp @@ -9,6 +9,7 @@ **********************************************************************/ +#include #include #include @@ -633,20 +634,26 @@ Effect *EffectManager::GetEffect(const PluginID & ID) // TODO: This is temporary and should be redone when all effects are converted if (mEffectPlugins.Index(wxString(ID)) == wxNOT_FOUND) { - // This will instantiate the effect client if it hasn't already been done - EffectClientInterface *client = static_cast(PluginManager::Get().GetInstance(ID)); - if (client) + effect = new Effect(); + if (effect) { - effect = new Effect(client); - if (effect) + // This will instantiate the effect client if it hasn't already been done + EffectClientInterface *client = static_cast(PluginManager::Get().GetInstance(ID)); + if (client && effect->Startup(client)) { effect->SetEffectID(mNumEffects++); PluginManager::Get().SetInstance(ID, effect); mEffectPlugins.Add(ID); + return effect; } - return effect; + delete effect; } + + wxMessageBox(wxString::Format(_("Attempting to initialize the following effect failed:\n\n%s\n\nMore information may be available in Help->Show Log"), + PluginManager::Get().GetName(ID)), + _("Effect failed to initialize")); + return NULL; }