Slightly better error handling during effect initialization

It at least detects load failures now.  ;-)
This commit is contained in:
lllucius 2014-11-05 20:41:29 +00:00
parent b20cadd01f
commit 3d8de17c22
3 changed files with 75 additions and 66 deletions

View File

@ -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()
{

View File

@ -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;

View File

@ -9,6 +9,7 @@
**********************************************************************/
#include <wx/msgdlg.h>
#include <wx/stopwatch.h>
#include <wx/tokenzr.h>
@ -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<EffectClientInterface *>(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<EffectClientInterface *>(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;
}