VST3: common factory instantiating and release

This may address some issues with multiple references
(and incremental releases) of a plugin's factory.
This commit is contained in:
Robin Gareus 2020-10-02 15:01:01 +02:00
parent e2639a1a58
commit 3c4801bc96
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
5 changed files with 42 additions and 26 deletions

View File

@ -23,23 +23,34 @@
#include "ardour/libardour_visibility.h"
namespace Steinberg {
class IPluginFactory;
}
namespace ARDOUR {
class LIBARDOUR_API VST3PluginModule
{
public:
static boost::shared_ptr<VST3PluginModule> load (std::string const& path);
VST3PluginModule () {}
VST3PluginModule () : _factory (0) {}
virtual ~VST3PluginModule () {}
virtual void* fn_ptr (const char* name) const = 0;
Steinberg::IPluginFactory* factory ();
protected:
void release_factory ();
virtual bool init () = 0;
virtual bool exit () = 0;
virtual void* fn_ptr (const char* name) const = 0;
private:
/* prevent copy construction */
VST3PluginModule (VST3PluginModule const&);
Steinberg::IPluginFactory* _factory;
};
} // namespace ARDOUR

View File

@ -176,7 +176,6 @@ private:
std::vector <Vst::IConnectionPoint*> _connections;
FUID _fuid;
IPluginFactory* _factory;
Vst::IComponent* _component;
Vst::IEditController* _controller;
IPlugView* _view;

View File

@ -31,6 +31,7 @@
#include "pbd/error.h"
#include "pbd/failed_constructor.h"
#include "vst3/pluginterfaces/base/ipluginbase.h"
#include "ardour/vst3_module.h"
#include "pbd/i18n.h"
@ -72,6 +73,7 @@ public:
~VST3MacModule ()
{
release_factory ();
if (_bundle) {
exit ();
CFRelease (_bundle);
@ -126,6 +128,7 @@ public:
~VST3WindowsModule ()
{
release_factory ();
if (_handle) {
exit ();
FreeLibrary (_handle);
@ -186,6 +189,7 @@ public:
~VST3LinuxModule ()
{
release_factory ();
if (_dll) {
exit ();
dlclose (_dll);
@ -217,6 +221,26 @@ private:
#endif
Steinberg::IPluginFactory*
VST3PluginModule::factory ()
{
if (!_factory) {
GetFactoryProc fp = (GetFactoryProc)fn_ptr ("GetPluginFactory");
if (fp) {
_factory = fp ();
}
}
return _factory;
}
void
VST3PluginModule::release_factory ()
{
if (_factory) {
_factory->release ();
}
}
boost::shared_ptr<VST3PluginModule>
VST3PluginModule::load (std::string const& path)
{

View File

@ -941,7 +941,6 @@ VST3PluginInfo::is_instrument () const
VST3PI::VST3PI (boost::shared_ptr<ARDOUR::VST3PluginModule> m, std::string unique_id)
: _module (m)
, _factory (0)
, _component (0)
, _controller (0)
, _view (0)
@ -954,13 +953,9 @@ VST3PI::VST3PI (boost::shared_ptr<ARDOUR::VST3PluginModule> m, std::string uniqu
, _n_factory_presets (0)
{
using namespace std;
IPluginFactory* factory = m->factory ();
GetFactoryProc fp = (GetFactoryProc)m->fn_ptr ("GetPluginFactory");
if (!fp) {
throw failed_constructor ();
}
if (!(_factory = fp ())) {
if (!factory) {
throw failed_constructor ();
}
@ -968,7 +963,7 @@ VST3PI::VST3PI (boost::shared_ptr<ARDOUR::VST3PluginModule> m, std::string uniqu
throw failed_constructor ();
}
if (_factory->createInstance (_fuid.toTUID (), Vst::IComponent::iid, (void**)&_component) != kResultTrue) {
if (factory->createInstance (_fuid.toTUID (), Vst::IComponent::iid, (void**)&_component) != kResultTrue) {
throw failed_constructor ();
}
@ -980,7 +975,7 @@ VST3PI::VST3PI (boost::shared_ptr<ARDOUR::VST3PluginModule> m, std::string uniqu
if (!_controller) {
TUID controllerCID;
if (_component->getControllerClassId (controllerCID) == kResultTrue) {
if (_factory->createInstance (controllerCID, Vst::IEditController::iid, (void**)&_controller) != kResultTrue) {
if (factory->createInstance (controllerCID, Vst::IEditController::iid, (void**)&_controller) != kResultTrue) {
throw failed_constructor ();
}
if (_controller && (_controller->initialize (HostApplication::getHostContext ()) != kResultOk)) {
@ -1137,13 +1132,8 @@ VST3PI::terminate ()
_component->release ();
if (_factory) {
_factory->release ();
}
_controller = 0;
_component = 0;
_factory = 0;
}
bool

View File

@ -90,14 +90,7 @@ ARDOUR::discover_vst3 (boost::shared_ptr<VST3PluginModule> m, std::vector<VST3In
{
using namespace std;
GetFactoryProc fp = (GetFactoryProc)m->fn_ptr ("GetPluginFactory");
if (!fp) {
cerr << "Failed to find 'GetPluginFactory' function\n";
return false;
}
IPluginFactory* factory = fp ();
IPluginFactory* factory = m->factory ();
if (!factory) {
cerr << "Failed to get VST3 plug-in factory\n";
@ -199,7 +192,6 @@ ARDOUR::discover_vst3 (boost::shared_ptr<VST3PluginModule> m, std::vector<VST3In
}
}
factory->release ();
return true;
}