Skip to content

Commit

Permalink
VST3 Host: Avoid calling initialize twice on objects that implement b…
Browse files Browse the repository at this point in the history
…oth IComponent and IEditController
  • Loading branch information
reuk committed Feb 18, 2022
1 parent a3c55a9 commit 1bf9ebb
Showing 1 changed file with 38 additions and 11 deletions.
Expand Up @@ -1348,9 +1348,7 @@ struct VST3PluginWindow : public AudioProcessorEditor,
warnOnFailure (view->setFrame (this));
view->queryInterface (Steinberg::IPlugViewContentScaleSupport::iid, (void**) &scaleInterface);

if (scaleInterface != nullptr)
warnOnFailure (scaleInterface->setContentScaleFactor ((Steinberg::IPlugViewContentScaleSupport::ScaleFactor) nativeScaleFactor));

setContentScaleFactor();
resizeToFit();
}

Expand Down Expand Up @@ -1598,11 +1596,24 @@ struct VST3PluginWindow : public AudioProcessorEditor,
void updatePluginScale()
{
if (scaleInterface != nullptr)
warnOnFailure (scaleInterface->setContentScaleFactor ((Steinberg::IPlugViewContentScaleSupport::ScaleFactor) nativeScaleFactor));
setContentScaleFactor();
else
resizeToFit();
}

void setContentScaleFactor()
{
if (scaleInterface != nullptr)
{
const auto result = scaleInterface->setContentScaleFactor ((Steinberg::IPlugViewContentScaleSupport::ScaleFactor) nativeScaleFactor);
ignoreUnused (result);

#if ! JUCE_MAC
ignoreUnused (warnOnFailure (result));
#endif
}
}

//==============================================================================
Atomic<int> refCount { 1 };
VSTComSmartPtr<IPlugView> view;
Expand Down Expand Up @@ -1676,16 +1687,33 @@ struct VST3ComponentHolder
// transfers ownership to the plugin instance!
AudioPluginInstance* createPluginInstance();

bool isIComponentAlsoIEditController() const
{
if (component == nullptr)
{
jassertfalse;
return false;
}

return VSTComSmartPtr<Vst::IEditController>().loadFrom (component);
}

bool fetchController (VSTComSmartPtr<Vst::IEditController>& editController)
{
if (! isComponentInitialised && ! initialise())
return false;

editController.loadFrom (component);

// Get the IEditController:
TUID controllerCID = { 0 };

if (component->getControllerClassId (controllerCID) == kResultTrue && FUID (controllerCID).isValid())
if (editController == nullptr
&& component->getControllerClassId (controllerCID) == kResultTrue
&& FUID (controllerCID).isValid())
{
editController.loadFrom (factory, controllerCID);
}

if (editController == nullptr)
{
Expand All @@ -1702,9 +1730,6 @@ struct VST3ComponentHolder
}
}

if (editController == nullptr)
editController.loadFrom (component);

return (editController != nullptr);
}

Expand Down Expand Up @@ -2220,7 +2245,7 @@ class VST3PluginInstance final : public AudioPluginInstance

editController->setComponentHandler (nullptr);

if (isControllerInitialised)
if (isControllerInitialised && ! holder->isIComponentAlsoIEditController())
editController->terminate();

holder->terminate();
Expand Down Expand Up @@ -2252,8 +2277,10 @@ class VST3PluginInstance final : public AudioPluginInstance
if (! (isControllerInitialised || holder->fetchController (editController)))
return false;

// (May return an error if the plugin combines the IComponent and IEditController implementations)
editController->initialize (holder->host->getFUnknown());
// If the IComponent and IEditController are the same, we will have
// already initialized the object at this point and should avoid doing so again.
if (! holder->isIComponentAlsoIEditController())
editController->initialize (holder->host->getFUnknown());

isControllerInitialised = true;
editController->setComponentHandler (holder->host);
Expand Down

0 comments on commit 1bf9ebb

Please sign in to comment.