Skip to content

Commit

Permalink
VST3 Client: Avoid returning real editor size until onSize has been c…
Browse files Browse the repository at this point in the history
…alled
  • Loading branch information
reuk committed Oct 19, 2023
1 parent 384ddee commit 3edb072
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions modules/juce_audio_plugin_client/juce_audio_plugin_client_VST3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1844,6 +1844,7 @@ class JuceVST3EditController final : public Vst::EditController,
#endif

component = nullptr;
lastReportedSize.reset();
}

#if JUCE_LINUX || JUCE_BSD
Expand All @@ -1855,32 +1856,33 @@ class JuceVST3EditController final : public Vst::EditController,

tresult PLUGIN_API onSize (ViewRect* newSize) override
{
if (newSize != nullptr)
if (newSize == nullptr)
{
rect = convertFromHostBounds (*newSize);
jassertfalse;
return kResultFalse;
}

if (component != nullptr)
{
component->setSize (rect.getWidth(), rect.getHeight());

#if JUCE_MAC
if (cubase10Workaround != nullptr)
{
cubase10Workaround->triggerAsyncUpdate();
}
else
#endif
{
if (auto* peer = component->getPeer())
peer->updateBounds();
}
}
lastReportedSize.reset();
rect = convertFromHostBounds (*newSize);

if (component == nullptr)
return kResultTrue;

component->setSize (rect.getWidth(), rect.getHeight());

#if JUCE_MAC
if (cubase10Workaround != nullptr)
{
cubase10Workaround->triggerAsyncUpdate();
}
else
#endif
{
if (auto* peer = component->getPeer())
peer->updateBounds();
}

jassertfalse;
return kResultFalse;
return kResultTrue;
}

tresult PLUGIN_API getSize (ViewRect* size) override
Expand All @@ -1890,15 +1892,16 @@ class JuceVST3EditController final : public Vst::EditController,
return kResultFalse;
#endif

if (size != nullptr && component != nullptr)
{
auto editorBounds = component->getSizeToContainChild();
if (size == nullptr || component == nullptr)
return kResultFalse;

*size = convertToHostBounds ({ 0, 0, editorBounds.getWidth(), editorBounds.getHeight() });
return kResultTrue;
}
const auto editorBounds = component->getSizeToContainChild();
const auto sizeToReport = lastReportedSize.has_value()
? *lastReportedSize
: convertToHostBounds ({ 0, 0, editorBounds.getWidth(), editorBounds.getHeight() });

return kResultFalse;
lastReportedSize = *size = sizeToReport;
return kResultTrue;
}

tresult PLUGIN_API canResize() override
Expand Down Expand Up @@ -2275,6 +2278,7 @@ class JuceVST3EditController final : public Vst::EditController,

//==============================================================================
ScopedJuceInitialiser_GUI libraryInitialiser;
std::optional<ViewRect> lastReportedSize;

#if JUCE_LINUX || JUCE_BSD
SharedResourcePointer<detail::MessageThread> messageThread;
Expand Down

0 comments on commit 3edb072

Please sign in to comment.