1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-02-05 03:50:07 +00:00

VST3 Host: Avoid calling initialize twice on objects that implement both IComponent and IEditController

This commit is contained in:
reuk 2022-02-09 13:06:20 +00:00
parent a3c55a967f
commit 1bf9ebb4b1
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11

View file

@ -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();
}
@ -1598,11 +1596,24 @@ private:
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;
@ -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)
{
@ -1702,9 +1730,6 @@ struct VST3ComponentHolder
}
}
if (editController == nullptr)
editController.loadFrom (component);
return (editController != nullptr);
}
@ -2220,7 +2245,7 @@ public:
editController->setComponentHandler (nullptr);
if (isControllerInitialised)
if (isControllerInitialised && ! holder->isIComponentAlsoIEditController())
editController->terminate();
holder->terminate();
@ -2252,8 +2277,10 @@ public:
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);