mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-28 06:08:40 +02:00
Plugin instances managed without naked new and delete
This commit is contained in:
parent
3481e678ea
commit
a9afad17ca
@ -1053,13 +1053,17 @@ PluginDescriptor::PluginDescriptor()
|
||||
}
|
||||
|
||||
PluginDescriptor::~PluginDescriptor()
|
||||
{
|
||||
DeleteInstance();
|
||||
}
|
||||
|
||||
void PluginDescriptor::DeleteInstance()
|
||||
{
|
||||
if (mInstance)
|
||||
{
|
||||
ModuleManager::Get().DeleteInstance(GetProviderID(), mInstance);
|
||||
mInstance = nullptr;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool PluginDescriptor::IsInstantiated() const
|
||||
@ -1086,6 +1090,12 @@ IdentInterface *PluginDescriptor::GetInstance()
|
||||
|
||||
void PluginDescriptor::SetInstance(IdentInterface *instance)
|
||||
{
|
||||
if (mInstance && mInstance != instance)
|
||||
{
|
||||
// Be sure not to leak resources!!
|
||||
DeleteInstance();
|
||||
}
|
||||
|
||||
mInstance = instance;
|
||||
|
||||
return;
|
||||
|
@ -117,8 +117,13 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
void DeleteInstance();
|
||||
|
||||
// Common
|
||||
|
||||
// Among other purposes, PluginDescriptor acts as the resouce handle,
|
||||
// or smart pointer, to a resource created in a plugin library, and is responsible
|
||||
// for a cleanup of this pointer.
|
||||
IdentInterface *mInstance;
|
||||
|
||||
PluginType mPluginType;
|
||||
|
@ -327,16 +327,17 @@ bool BuiltinEffectsModule::IsPluginValid(const wxString & path)
|
||||
|
||||
IdentInterface *BuiltinEffectsModule::CreateInstance(const wxString & path)
|
||||
{
|
||||
// Acquires a resource for the application.
|
||||
// Safety of this depends on complementary calls to DeleteInstance on the module manager side.
|
||||
return Instantiate(path);
|
||||
}
|
||||
|
||||
void BuiltinEffectsModule::DeleteInstance(IdentInterface *instance)
|
||||
{
|
||||
Effect *effect = dynamic_cast<Effect *>(instance);
|
||||
if (effect)
|
||||
{
|
||||
delete effect;
|
||||
}
|
||||
// Releases the resource.
|
||||
std::unique_ptr < Effect > {
|
||||
dynamic_cast<Effect *>(instance)
|
||||
};
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
@ -623,17 +623,17 @@ bool VSTEffectsModule::IsPluginValid(const wxString & path)
|
||||
|
||||
IdentInterface *VSTEffectsModule::CreateInstance(const wxString & path)
|
||||
{
|
||||
// Acquires a resource for the application.
|
||||
// For us, the ID is simply the path to the effect
|
||||
return new VSTEffect(path);
|
||||
// Safety of this depends on complementary calls to DeleteInstance on the module manager side.
|
||||
return safenew VSTEffect(path);
|
||||
}
|
||||
|
||||
void VSTEffectsModule::DeleteInstance(IdentInterface *instance)
|
||||
{
|
||||
VSTEffect *effect = dynamic_cast<VSTEffect *>(instance);
|
||||
if (effect)
|
||||
{
|
||||
delete effect;
|
||||
}
|
||||
std::unique_ptr < VSTEffect > {
|
||||
dynamic_cast<VSTEffect *>(instance)
|
||||
};
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
@ -176,6 +176,7 @@ bool AudioUnitEffectsModule::IsPluginValid(const wxString & path)
|
||||
|
||||
IdentInterface *AudioUnitEffectsModule::CreateInstance(const wxString & path)
|
||||
{
|
||||
// Acquires a resource for the application.
|
||||
wxString name;
|
||||
AudioComponent component = FindAudioUnit(path, name);
|
||||
if (component == NULL)
|
||||
@ -183,16 +184,15 @@ IdentInterface *AudioUnitEffectsModule::CreateInstance(const wxString & path)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return new AudioUnitEffect(path, name, component);
|
||||
// Safety of this depends on complementary calls to DeleteInstance on the module manager side.
|
||||
return safenew AudioUnitEffect(path, name, component);
|
||||
}
|
||||
|
||||
void AudioUnitEffectsModule::DeleteInstance(IdentInterface *instance)
|
||||
{
|
||||
AudioUnitEffect *effect = dynamic_cast<AudioUnitEffect *>(instance);
|
||||
if (effect)
|
||||
{
|
||||
delete effect;
|
||||
}
|
||||
std::unique_ptr < AudioUnitEffect > {
|
||||
dynamic_cast<AudioUnitEffect *>(instance)
|
||||
};
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
@ -261,6 +261,7 @@ bool LadspaEffectsModule::IsPluginValid(const wxString & path)
|
||||
|
||||
IdentInterface *LadspaEffectsModule::CreateInstance(const wxString & path)
|
||||
{
|
||||
// Acquires a resource for the application.
|
||||
// For us, the path is two words.
|
||||
// 1) The library's path
|
||||
// 2) The LADSPA descriptor index
|
||||
@ -268,16 +269,15 @@ IdentInterface *LadspaEffectsModule::CreateInstance(const wxString & path)
|
||||
wxString realPath = path.BeforeFirst(wxT(';'));
|
||||
path.AfterFirst(wxT(';')).ToLong(&index);
|
||||
|
||||
return new LadspaEffect(realPath, (int) index);
|
||||
// Safety of this depends on complementary calls to DeleteInstance on the module manager side.
|
||||
return safenew LadspaEffect(realPath, (int)index);
|
||||
}
|
||||
|
||||
void LadspaEffectsModule::DeleteInstance(IdentInterface *instance)
|
||||
{
|
||||
LadspaEffect *effect = dynamic_cast<LadspaEffect *>(instance);
|
||||
if (effect)
|
||||
{
|
||||
delete effect;
|
||||
}
|
||||
std::unique_ptr < LadspaEffect > {
|
||||
dynamic_cast<LadspaEffect *>(instance)
|
||||
};
|
||||
}
|
||||
|
||||
wxArrayString LadspaEffectsModule::GetSearchPaths()
|
||||
|
@ -266,22 +266,22 @@ bool LV2EffectsModule::IsPluginValid(const wxString & path)
|
||||
|
||||
IdentInterface *LV2EffectsModule::CreateInstance(const wxString & path)
|
||||
{
|
||||
// Acquires a resource for the application.
|
||||
const LilvPlugin *plug = GetPlugin(path);
|
||||
if (!plug)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return new LV2Effect(plug);
|
||||
// Safety of this depends on complementary calls to DeleteInstance on the module manager side.
|
||||
return safenew LV2Effect(plug);
|
||||
}
|
||||
|
||||
void LV2EffectsModule::DeleteInstance(IdentInterface *instance)
|
||||
{
|
||||
LV2Effect *effect = dynamic_cast<LV2Effect *>(instance);
|
||||
if (effect)
|
||||
{
|
||||
delete effect;
|
||||
}
|
||||
std::unique_ptr < LV2Effect > {
|
||||
dynamic_cast<LV2Effect *>(instance)
|
||||
};
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
@ -226,24 +226,22 @@ bool NyquistEffectsModule::IsPluginValid(const wxString & path)
|
||||
|
||||
IdentInterface *NyquistEffectsModule::CreateInstance(const wxString & path)
|
||||
{
|
||||
NyquistEffect *effect = new NyquistEffect(path);
|
||||
// Acquires a resource for the application.
|
||||
auto effect = std::make_unique<NyquistEffect>(path);
|
||||
if (effect->IsOk())
|
||||
{
|
||||
return effect;
|
||||
// Safety of this depends on complementary calls to DeleteInstance on the module manager side.
|
||||
return effect.release();
|
||||
}
|
||||
|
||||
delete effect;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void NyquistEffectsModule::DeleteInstance(IdentInterface *instance)
|
||||
{
|
||||
NyquistEffect *effect = dynamic_cast<NyquistEffect *>(instance);
|
||||
if (effect)
|
||||
{
|
||||
delete effect;
|
||||
}
|
||||
std::unique_ptr < NyquistEffect > {
|
||||
dynamic_cast<NyquistEffect *>(instance)
|
||||
};
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
@ -234,13 +234,15 @@ bool VampEffectsModule::IsPluginValid(const wxString & path)
|
||||
|
||||
IdentInterface *VampEffectsModule::CreateInstance(const wxString & path)
|
||||
{
|
||||
// Acquires a resource for the application.
|
||||
int output;
|
||||
bool hasParameters;
|
||||
|
||||
Plugin *vp = FindPlugin(path, output, hasParameters);
|
||||
if (vp)
|
||||
{
|
||||
return new VampEffect(vp, path, output, hasParameters);
|
||||
// Safety of this depends on complementary calls to DeleteInstance on the module manager side.
|
||||
return safenew VampEffect(vp, path, output, hasParameters);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -248,11 +250,9 @@ IdentInterface *VampEffectsModule::CreateInstance(const wxString & path)
|
||||
|
||||
void VampEffectsModule::DeleteInstance(IdentInterface *instance)
|
||||
{
|
||||
VampEffect *effect = dynamic_cast<VampEffect *>(instance);
|
||||
if (effect)
|
||||
{
|
||||
delete effect;
|
||||
}
|
||||
std::unique_ptr < VampEffect > {
|
||||
dynamic_cast<VampEffect *>(instance)
|
||||
};
|
||||
}
|
||||
|
||||
// VampEffectsModule implementation
|
||||
|
Loading…
x
Reference in New Issue
Block a user