diff --git a/include/mostly_harmless/core/mostlyharmless_ISharedState.h b/include/mostly_harmless/core/mostlyharmless_ISharedState.h index 6707986..c6ef838 100644 --- a/include/mostly_harmless/core/mostlyharmless_ISharedState.h +++ b/include/mostly_harmless/core/mostlyharmless_ISharedState.h @@ -111,6 +111,16 @@ namespace mostly_harmless::core { */ void rescanParams() const; + /** + * Asks the host to resize your gui to the specified dimensions. + * Doesn't block, and is thread safe, more of a "please do this when you get a chance" than a "do this now". + * That said - if you call this from the audio thread it's kinda against the spirit of the framework, and this is my answer to JUCE's "tut tut tut..." comment.. + * @param width The requested width. + * @param height The requested height. + * @return true if the host acknowledged the resize request, false otherwise. + */ + bool requestGuiResize(std::uint32_t width, std::uint32_t height) const; + private: SharedStateContext m_context; std::vector> m_params; diff --git a/include/mostly_harmless/core/mostlyharmless_SharedStateContext.h b/include/mostly_harmless/core/mostlyharmless_SharedStateContext.h index 1c5059a..461e672 100644 --- a/include/mostly_harmless/core/mostlyharmless_SharedStateContext.h +++ b/include/mostly_harmless/core/mostlyharmless_SharedStateContext.h @@ -25,6 +25,14 @@ namespace mostly_harmless::core { * Call this to request that the host rescans the param values, to keep them up to date. */ std::function requestParamRescan{ nullptr }; + + /** + * Call this to ask the host to resize your editor to the specified dimensions. + * It's up to the host *when* it does this, and doesn't block. + * It's *technically* fine to call this from any thread, but obviously it doesn't really make sense to do from the audio thread... + * Args are width and height, and return value is whether the host acknowledged your resize request. + */ + std::function requestGuiResize{ nullptr }; }; } // namespace mostly_harmless::core #endif // MOSTLYHARMLESS_MOSTLYHARMLESS_SHAREDSTATECONTEXT_H diff --git a/source/core/mostlyharmless_ISharedState.cpp b/source/core/mostlyharmless_ISharedState.cpp index a160c22..8d62a9e 100644 --- a/source/core/mostlyharmless_ISharedState.cpp +++ b/source/core/mostlyharmless_ISharedState.cpp @@ -58,5 +58,9 @@ namespace mostly_harmless::core { m_context.requestParamRescan(); } + bool ISharedState::requestGuiResize(std::uint32_t width, std::uint32_t height) const { + return m_context.requestGuiResize(width, height); + } + } // namespace mostly_harmless::core \ No newline at end of file diff --git a/source/mostlyharmless_PluginBase.cpp b/source/mostlyharmless_PluginBase.cpp index e21a1c9..a47bccc 100644 --- a/source/mostlyharmless_PluginBase.cpp +++ b/source/mostlyharmless_PluginBase.cpp @@ -23,6 +23,9 @@ namespace mostly_harmless::internal { } }, .requestParamRescan = [this]() -> void { _host.paramsRescan(CLAP_PARAM_RESCAN_VALUES); + }, + .requestGuiResize = [this](std::uint32_t width, std::uint32_t height) -> bool { + return _host.guiRequestResize(width, height); } }; m_state = m_pluginEntry->createState(std::move(context));