VST3: properly take references, ignore controll == component cases
This is mainly motivated by DPF's new VST3 implementation, but also takes a leaf out of JUCE's book, unconditionally initializing the VST::IEditController even if it is-a VST::IComponent. and likewise calling terminate().
This commit is contained in:
parent
28784a0da7
commit
789949ed8e
@ -108,7 +108,7 @@ public:
|
||||
FUID const& fuid () const { return _fuid; }
|
||||
|
||||
/* Ardour Preset Helpers */
|
||||
Vst::IUnitInfo* unit_info ();
|
||||
IPtr<Vst::IUnitInfo> unit_info ();
|
||||
Vst::ParameterInfo const& program_change_port () const { return _program_change_port; }
|
||||
|
||||
void set_n_factory_presets (size_t n) { _n_factory_presets = n; }
|
||||
|
@ -232,6 +232,7 @@ VST3PluginModule::factory ()
|
||||
GetFactoryProc fp = (GetFactoryProc)fn_ptr ("GetPluginFactory");
|
||||
if (fp) {
|
||||
_factory = fp ();
|
||||
_factory->addRef ();
|
||||
}
|
||||
}
|
||||
return _factory;
|
||||
|
@ -855,7 +855,7 @@ VST3Plugin::find_presets ()
|
||||
_preset_uri_map.clear ();
|
||||
|
||||
/* read vst3UnitPrograms */
|
||||
Vst::IUnitInfo* nfo = _plug->unit_info ();
|
||||
IPtr<Vst::IUnitInfo> nfo = _plug->unit_info ();
|
||||
if (nfo && _plug->program_change_port ().id != Vst::kNoParamId) {
|
||||
Vst::UnitID program_unit_id = _plug->program_change_port ().unitId;
|
||||
|
||||
@ -1053,14 +1053,16 @@ VST3PI::VST3PI (boost::shared_ptr<ARDOUR::VST3PluginModule> m, std::string uniqu
|
||||
#endif
|
||||
|
||||
if (factory->createInstance (_fuid.toTUID (), Vst::IComponent::iid, (void**)&_component) != kResultTrue) {
|
||||
DEBUG_TRACE (DEBUG::VST3Config, "VST3PI create instance failed\n");
|
||||
throw failed_constructor ();
|
||||
}
|
||||
|
||||
if (!_component || _component->initialize (HostApplication::getHostContext ()) != kResultOk) {
|
||||
DEBUG_TRACE (DEBUG::VST3Config, "VST3PI component initialize failed\n");
|
||||
throw failed_constructor ();
|
||||
}
|
||||
|
||||
_controller = FUnknownPtr<Vst::IEditController> (_component);
|
||||
_controller = FUnknownPtr<Vst::IEditController> (_component).take ();
|
||||
|
||||
if (!_controller) {
|
||||
TUID controllerCID;
|
||||
@ -1073,30 +1075,44 @@ VST3PI::VST3PI (boost::shared_ptr<ARDOUR::VST3PluginModule> m, std::string uniqu
|
||||
}
|
||||
}
|
||||
|
||||
if (_controller && (_controller->initialize (HostApplication::getHostContext ()) != kResultOk)) {
|
||||
if (!_controller) {
|
||||
DEBUG_TRACE (DEBUG::VST3Config, "VST3PI no controller was found\n");
|
||||
_component->terminate ();
|
||||
_component->release ();
|
||||
throw failed_constructor ();
|
||||
}
|
||||
|
||||
if (!_controller) {
|
||||
_component->terminate ();
|
||||
_component->release ();
|
||||
throw failed_constructor ();
|
||||
}
|
||||
/* The official Steinberg SDK's source/vst/hosting/plugprovider.cpp
|
||||
* only initializes the controller if it is separate of the component.
|
||||
*
|
||||
* However some plugins expect and unconditional call and other
|
||||
* hosts incl. JUCE based one initialize a controller separately because
|
||||
* FUnknownPtr<> cast may return a new obeject.
|
||||
*
|
||||
* So do not check for errors.
|
||||
* if Vst::IEditController is-a Vst::IComponent the Controller
|
||||
* may or may not already be initialized.
|
||||
*/
|
||||
_controller->initialize (HostApplication::getHostContext ());
|
||||
|
||||
if (_controller->setComponentHandler (this) != kResultOk) {
|
||||
_controller->terminate ();
|
||||
_controller->release ();
|
||||
_component->terminate ();
|
||||
_component->release ();
|
||||
throw failed_constructor ();
|
||||
}
|
||||
|
||||
if (!(_processor = FUnknownPtr<Vst::IAudioProcessor> (_component))) {
|
||||
if (!(_processor = FUnknownPtr<Vst::IAudioProcessor> (_component).take ())) {
|
||||
_controller->terminate ();
|
||||
_controller->release ();
|
||||
_component->terminate ();
|
||||
_component->release ();
|
||||
throw failed_constructor ();
|
||||
}
|
||||
|
||||
_processor->addRef ();
|
||||
|
||||
/* prepare process context */
|
||||
memset (&_context, 0, sizeof (Vst::ProcessContext));
|
||||
|
||||
@ -1195,10 +1211,10 @@ VST3PI::~VST3PI ()
|
||||
terminate ();
|
||||
}
|
||||
|
||||
Vst::IUnitInfo*
|
||||
IPtr<Vst::IUnitInfo>
|
||||
VST3PI::unit_info ()
|
||||
{
|
||||
Vst::IUnitInfo* nfo = FUnknownPtr<Vst::IUnitInfo> (_component);
|
||||
IPtr<Vst::IUnitInfo> nfo = FUnknownPtr<Vst::IUnitInfo> (_component);
|
||||
if (nfo) {
|
||||
return nfo;
|
||||
}
|
||||
@ -1206,7 +1222,7 @@ VST3PI::unit_info ()
|
||||
}
|
||||
|
||||
#if 0
|
||||
Vst::IUnitData*
|
||||
IPtr<Vst::IUnitData>
|
||||
VST3PI::unit_data ()
|
||||
{
|
||||
Vst::IUnitData* iud = FUnknownPtr<Vst::IUnitData> (_component);
|
||||
@ -1226,26 +1242,19 @@ VST3PI::terminate ()
|
||||
|
||||
deactivate ();
|
||||
|
||||
_processor->release ();
|
||||
_processor = 0;
|
||||
|
||||
disconnect_components ();
|
||||
|
||||
bool controller_is_component = false;
|
||||
if (_component) {
|
||||
controller_is_component = FUnknownPtr<Vst::IEditController> (_component) != 0;
|
||||
_component->terminate ();
|
||||
}
|
||||
|
||||
if (_controller) {
|
||||
_controller->setComponentHandler (0);
|
||||
}
|
||||
|
||||
if (_controller && controller_is_component == false) {
|
||||
_controller->terminate ();
|
||||
_controller->release ();
|
||||
}
|
||||
|
||||
if (_component) {
|
||||
_component->terminate ();
|
||||
_component->release ();
|
||||
}
|
||||
|
||||
@ -2934,7 +2943,7 @@ VST3PI::try_create_view () const
|
||||
view = _controller->createView (0);
|
||||
}
|
||||
if (!view) {
|
||||
view = FUnknownPtr<IPlugView> (_controller);
|
||||
view = FUnknownPtr<IPlugView> (_controller).take ();
|
||||
if (view) {
|
||||
view->addRef ();
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ discover_vst3 (boost::shared_ptr<ARDOUR::VST3PluginModule> m, std::vector<ARDOUR
|
||||
PBD::info << "FactoryInfo: '" << fi.vendor << "' '" << fi.url << "' '" << fi.email << "'" << endmsg;
|
||||
}
|
||||
|
||||
IPluginFactory2* factory2 = FUnknownPtr<IPluginFactory2> (factory);
|
||||
IPtr<IPluginFactory2> factory2 = FUnknownPtr<IPluginFactory2> (factory);
|
||||
|
||||
int32 class_cnt = factory->countClasses ();
|
||||
if (verbose) {
|
||||
@ -203,7 +203,7 @@ discover_vst3 (boost::shared_ptr<ARDOUR::VST3PluginModule> m, std::vector<ARDOUR
|
||||
continue;
|
||||
}
|
||||
|
||||
FUnknownPtr<Vst::IAudioProcessor> processor;
|
||||
IPtr<Vst::IAudioProcessor> processor;
|
||||
if (!(processor = FUnknownPtr<Vst::IAudioProcessor> (component))) {
|
||||
cerr << "VST3: No valid processor";
|
||||
component->terminate ();
|
||||
|
Loading…
Reference in New Issue
Block a user