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()
|
PluginDescriptor::~PluginDescriptor()
|
||||||
|
{
|
||||||
|
DeleteInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PluginDescriptor::DeleteInstance()
|
||||||
{
|
{
|
||||||
if (mInstance)
|
if (mInstance)
|
||||||
{
|
{
|
||||||
ModuleManager::Get().DeleteInstance(GetProviderID(), mInstance);
|
ModuleManager::Get().DeleteInstance(GetProviderID(), mInstance);
|
||||||
|
mInstance = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PluginDescriptor::IsInstantiated() const
|
bool PluginDescriptor::IsInstantiated() const
|
||||||
@ -1086,6 +1090,12 @@ IdentInterface *PluginDescriptor::GetInstance()
|
|||||||
|
|
||||||
void PluginDescriptor::SetInstance(IdentInterface *instance)
|
void PluginDescriptor::SetInstance(IdentInterface *instance)
|
||||||
{
|
{
|
||||||
|
if (mInstance && mInstance != instance)
|
||||||
|
{
|
||||||
|
// Be sure not to leak resources!!
|
||||||
|
DeleteInstance();
|
||||||
|
}
|
||||||
|
|
||||||
mInstance = instance;
|
mInstance = instance;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -117,8 +117,13 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void DeleteInstance();
|
||||||
|
|
||||||
// Common
|
// 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;
|
IdentInterface *mInstance;
|
||||||
|
|
||||||
PluginType mPluginType;
|
PluginType mPluginType;
|
||||||
|
@ -327,16 +327,17 @@ bool BuiltinEffectsModule::IsPluginValid(const wxString & path)
|
|||||||
|
|
||||||
IdentInterface *BuiltinEffectsModule::CreateInstance(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);
|
return Instantiate(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuiltinEffectsModule::DeleteInstance(IdentInterface *instance)
|
void BuiltinEffectsModule::DeleteInstance(IdentInterface *instance)
|
||||||
{
|
{
|
||||||
Effect *effect = dynamic_cast<Effect *>(instance);
|
// Releases the resource.
|
||||||
if (effect)
|
std::unique_ptr < Effect > {
|
||||||
{
|
dynamic_cast<Effect *>(instance)
|
||||||
delete effect;
|
};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
@ -623,17 +623,17 @@ bool VSTEffectsModule::IsPluginValid(const wxString & path)
|
|||||||
|
|
||||||
IdentInterface *VSTEffectsModule::CreateInstance(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
|
// 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)
|
void VSTEffectsModule::DeleteInstance(IdentInterface *instance)
|
||||||
{
|
{
|
||||||
VSTEffect *effect = dynamic_cast<VSTEffect *>(instance);
|
std::unique_ptr < VSTEffect > {
|
||||||
if (effect)
|
dynamic_cast<VSTEffect *>(instance)
|
||||||
{
|
};
|
||||||
delete effect;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
@ -176,6 +176,7 @@ bool AudioUnitEffectsModule::IsPluginValid(const wxString & path)
|
|||||||
|
|
||||||
IdentInterface *AudioUnitEffectsModule::CreateInstance(const wxString & path)
|
IdentInterface *AudioUnitEffectsModule::CreateInstance(const wxString & path)
|
||||||
{
|
{
|
||||||
|
// Acquires a resource for the application.
|
||||||
wxString name;
|
wxString name;
|
||||||
AudioComponent component = FindAudioUnit(path, name);
|
AudioComponent component = FindAudioUnit(path, name);
|
||||||
if (component == NULL)
|
if (component == NULL)
|
||||||
@ -183,16 +184,15 @@ IdentInterface *AudioUnitEffectsModule::CreateInstance(const wxString & path)
|
|||||||
return NULL;
|
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)
|
void AudioUnitEffectsModule::DeleteInstance(IdentInterface *instance)
|
||||||
{
|
{
|
||||||
AudioUnitEffect *effect = dynamic_cast<AudioUnitEffect *>(instance);
|
std::unique_ptr < AudioUnitEffect > {
|
||||||
if (effect)
|
dynamic_cast<AudioUnitEffect *>(instance)
|
||||||
{
|
};
|
||||||
delete effect;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
@ -261,6 +261,7 @@ bool LadspaEffectsModule::IsPluginValid(const wxString & path)
|
|||||||
|
|
||||||
IdentInterface *LadspaEffectsModule::CreateInstance(const wxString & path)
|
IdentInterface *LadspaEffectsModule::CreateInstance(const wxString & path)
|
||||||
{
|
{
|
||||||
|
// Acquires a resource for the application.
|
||||||
// For us, the path is two words.
|
// For us, the path is two words.
|
||||||
// 1) The library's path
|
// 1) The library's path
|
||||||
// 2) The LADSPA descriptor index
|
// 2) The LADSPA descriptor index
|
||||||
@ -268,16 +269,15 @@ IdentInterface *LadspaEffectsModule::CreateInstance(const wxString & path)
|
|||||||
wxString realPath = path.BeforeFirst(wxT(';'));
|
wxString realPath = path.BeforeFirst(wxT(';'));
|
||||||
path.AfterFirst(wxT(';')).ToLong(&index);
|
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)
|
void LadspaEffectsModule::DeleteInstance(IdentInterface *instance)
|
||||||
{
|
{
|
||||||
LadspaEffect *effect = dynamic_cast<LadspaEffect *>(instance);
|
std::unique_ptr < LadspaEffect > {
|
||||||
if (effect)
|
dynamic_cast<LadspaEffect *>(instance)
|
||||||
{
|
};
|
||||||
delete effect;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxArrayString LadspaEffectsModule::GetSearchPaths()
|
wxArrayString LadspaEffectsModule::GetSearchPaths()
|
||||||
|
@ -266,22 +266,22 @@ bool LV2EffectsModule::IsPluginValid(const wxString & path)
|
|||||||
|
|
||||||
IdentInterface *LV2EffectsModule::CreateInstance(const wxString & path)
|
IdentInterface *LV2EffectsModule::CreateInstance(const wxString & path)
|
||||||
{
|
{
|
||||||
|
// Acquires a resource for the application.
|
||||||
const LilvPlugin *plug = GetPlugin(path);
|
const LilvPlugin *plug = GetPlugin(path);
|
||||||
if (!plug)
|
if (!plug)
|
||||||
{
|
{
|
||||||
return NULL;
|
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)
|
void LV2EffectsModule::DeleteInstance(IdentInterface *instance)
|
||||||
{
|
{
|
||||||
LV2Effect *effect = dynamic_cast<LV2Effect *>(instance);
|
std::unique_ptr < LV2Effect > {
|
||||||
if (effect)
|
dynamic_cast<LV2Effect *>(instance)
|
||||||
{
|
};
|
||||||
delete effect;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
@ -226,24 +226,22 @@ bool NyquistEffectsModule::IsPluginValid(const wxString & path)
|
|||||||
|
|
||||||
IdentInterface *NyquistEffectsModule::CreateInstance(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())
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NyquistEffectsModule::DeleteInstance(IdentInterface *instance)
|
void NyquistEffectsModule::DeleteInstance(IdentInterface *instance)
|
||||||
{
|
{
|
||||||
NyquistEffect *effect = dynamic_cast<NyquistEffect *>(instance);
|
std::unique_ptr < NyquistEffect > {
|
||||||
if (effect)
|
dynamic_cast<NyquistEffect *>(instance)
|
||||||
{
|
};
|
||||||
delete effect;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
@ -234,13 +234,15 @@ bool VampEffectsModule::IsPluginValid(const wxString & path)
|
|||||||
|
|
||||||
IdentInterface *VampEffectsModule::CreateInstance(const wxString & path)
|
IdentInterface *VampEffectsModule::CreateInstance(const wxString & path)
|
||||||
{
|
{
|
||||||
|
// Acquires a resource for the application.
|
||||||
int output;
|
int output;
|
||||||
bool hasParameters;
|
bool hasParameters;
|
||||||
|
|
||||||
Plugin *vp = FindPlugin(path, output, hasParameters);
|
Plugin *vp = FindPlugin(path, output, hasParameters);
|
||||||
if (vp)
|
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;
|
return NULL;
|
||||||
@ -248,11 +250,9 @@ IdentInterface *VampEffectsModule::CreateInstance(const wxString & path)
|
|||||||
|
|
||||||
void VampEffectsModule::DeleteInstance(IdentInterface *instance)
|
void VampEffectsModule::DeleteInstance(IdentInterface *instance)
|
||||||
{
|
{
|
||||||
VampEffect *effect = dynamic_cast<VampEffect *>(instance);
|
std::unique_ptr < VampEffect > {
|
||||||
if (effect)
|
dynamic_cast<VampEffect *>(instance)
|
||||||
{
|
};
|
||||||
delete effect;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// VampEffectsModule implementation
|
// VampEffectsModule implementation
|
||||||
|
Loading…
x
Reference in New Issue
Block a user