Skip to content

Commit fc2232c

Browse files
authored
Merge pull request #81 from SLM-Audio/syl/request-resize
ISharedState::requestGuiResize()
2 parents 51016b4 + 9f66238 commit fc2232c

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

include/mostly_harmless/core/mostlyharmless_ISharedState.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ namespace mostly_harmless::core {
111111
*/
112112
void rescanParams() const;
113113

114+
/**
115+
* Asks the host to resize your gui to the specified dimensions.
116+
* Doesn't block, and is thread safe, more of a "please do this when you get a chance" than a "do this now".
117+
* 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..
118+
* @param width The requested width.
119+
* @param height The requested height.
120+
* @return true if the host acknowledged the resize request, false otherwise.
121+
*/
122+
bool requestGuiResize(std::uint32_t width, std::uint32_t height) const;
123+
114124
private:
115125
SharedStateContext m_context;
116126
std::vector<Parameter<float>> m_params;

include/mostly_harmless/core/mostlyharmless_SharedStateContext.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ namespace mostly_harmless::core {
2525
* Call this to request that the host rescans the param values, to keep them up to date.
2626
*/
2727
std::function<void(void)> requestParamRescan{ nullptr };
28+
29+
/**
30+
* Call this to ask the host to resize your editor to the specified dimensions.
31+
* It's up to the host *when* it does this, and doesn't block.
32+
* It's *technically* fine to call this from any thread, but obviously it doesn't really make sense to do from the audio thread...
33+
* Args are width and height, and return value is whether the host acknowledged your resize request.
34+
*/
35+
std::function<bool(std::uint32_t, std::uint32_t)> requestGuiResize{ nullptr };
2836
};
2937
} // namespace mostly_harmless::core
3038
#endif // MOSTLYHARMLESS_MOSTLYHARMLESS_SHAREDSTATECONTEXT_H

source/core/mostlyharmless_ISharedState.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,9 @@ namespace mostly_harmless::core {
5858
m_context.requestParamRescan();
5959
}
6060

61+
bool ISharedState::requestGuiResize(std::uint32_t width, std::uint32_t height) const {
62+
return m_context.requestGuiResize(width, height);
63+
}
64+
6165

6266
} // namespace mostly_harmless::core

source/mostlyharmless_PluginBase.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ namespace mostly_harmless::internal {
2323
} },
2424
.requestParamRescan = [this]() -> void {
2525
_host.paramsRescan(CLAP_PARAM_RESCAN_VALUES);
26+
},
27+
.requestGuiResize = [this](std::uint32_t width, std::uint32_t height) -> bool {
28+
return _host.guiRequestResize(width, height);
2629
}
2730
};
2831
m_state = m_pluginEntry->createState(std::move(context));

0 commit comments

Comments
 (0)