diff --git a/distrho/DistrhoInfo.hpp b/distrho/DistrhoInfo.hpp index 5eaf6879..69f30fcb 100644 --- a/distrho/DistrhoInfo.hpp +++ b/distrho/DistrhoInfo.hpp @@ -618,6 +618,24 @@ START_NAMESPACE_DISTRHO */ #define DISTRHO_UI_CUSTOM_WIDGET_TYPE +/** + Default UI width to use when creating initial and temporary windows.@n + Setting this macro allows to skip a temporary UI from being created in certain VST2 and VST3 hosts. + (which would normally be done for knowing the UI size before host creates a window for it) + + When this macro is defined, the companion DISTRHO_UI_DEFAULT_HEIGHT macro must be defined as well. + */ +#define DISTRHO_UI_DEFAULT_WIDTH 300 + +/** + Default UI height to use when creating initial and temporary windows.@n + Setting this macro allows to skip a temporary UI from being created in certain VST2 and VST3 hosts. + (which would normally be done for knowing the UI size before host creates a window for it) + + When this macro is defined, the companion DISTRHO_UI_DEFAULT_WIDTH macro must be defined as well. + */ +#define DISTRHO_UI_DEFAULT_HEIGHT 300 + /** Whether the %UI uses NanoVG for drawing instead of the default raw OpenGL calls.@n When enabled your %UI instance will subclass @ref NanoWidget instead of @ref Widget. diff --git a/distrho/src/DistrhoPluginChecks.h b/distrho/src/DistrhoPluginChecks.h index dd838b96..21c98ff8 100644 --- a/distrho/src/DistrhoPluginChecks.h +++ b/distrho/src/DistrhoPluginChecks.h @@ -183,6 +183,17 @@ # define DISTRHO_PLUGIN_HAS_UI 0 #endif +// ----------------------------------------------------------------------- +// Make sure both default width and height are provided + +#if defined(DISTRHO_UI_DEFAULT_WIDTH) && !defined(DISTRHO_UI_DEFAULT_HEIGHT) +# error DISTRHO_UI_DEFAULT_WIDTH is defined but DISTRHO_UI_DEFAULT_HEIGHT is not +#endif + +#if defined(DISTRHO_UI_DEFAULT_HEIGHT) && !defined(DISTRHO_UI_DEFAULT_WIDTH) +# error DISTRHO_UI_DEFAULT_HEIGHT is defined but DISTRHO_UI_DEFAULT_WIDTH is not +#endif + // ----------------------------------------------------------------------- // Prevent users from messing about with DPF internals diff --git a/distrho/src/DistrhoPluginVST2.cpp b/distrho/src/DistrhoPluginVST2.cpp index 8f47a98a..c0b4a269 100644 --- a/distrho/src/DistrhoPluginVST2.cpp +++ b/distrho/src/DistrhoPluginVST2.cpp @@ -575,17 +575,25 @@ public: } else { + double scaleFactor = fLastScaleFactor; + #if defined(DISTRHO_UI_DEFAULT_WIDTH) && defined(DISTRHO_UI_DEFAULT_HEIGHT) + fVstRect.right = DISTRHO_UI_DEFAULT_WIDTH; + fVstRect.bottom = DISTRHO_UI_DEFAULT_HEIGHT; + if (d_isZero(scaleFactor)) + scaleFactor = 1.0; + #else UIExporter tmpUI(nullptr, 0, fPlugin.getSampleRate(), nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, d_nextBundlePath, - fPlugin.getInstancePointer(), fLastScaleFactor); - fVstRect.right = tmpUI.getWidth(); + fPlugin.getInstancePointer(), scaleFactor); + fVstRect.right = tmpUI.getWidth(); fVstRect.bottom = tmpUI.getHeight(); -# ifdef DISTRHO_OS_MAC - const double scaleFactor = tmpUI.getScaleFactor(); + scaleFactor = tmpUI.getScaleFactor(); + tmpUI.quit(); + #endif + #ifdef DISTRHO_OS_MAC fVstRect.right /= scaleFactor; fVstRect.bottom /= scaleFactor; -# endif - tmpUI.quit(); + #endif } *(ERect**)ptr = &fVstRect; return 1; diff --git a/distrho/src/DistrhoUI.cpp b/distrho/src/DistrhoUI.cpp index 3af6926f..69bcfa83 100644 --- a/distrho/src/DistrhoUI.cpp +++ b/distrho/src/DistrhoUI.cpp @@ -202,13 +202,23 @@ UI::PrivateData::createNextWindow(UI* const ui, const uint width, const uint hei * UI */ UI::UI(const uint width, const uint height, const bool automaticallyScaleAndSetAsMinimumSize) - : UIWidget(UI::PrivateData::createNextWindow(this, width, height)), + : UIWidget(UI::PrivateData::createNextWindow(this, + #ifdef DISTRHO_UI_DEFAULT_WIDTH + width == 0 ? DISTRHO_UI_DEFAULT_WIDTH : + #endif + width, + #ifdef DISTRHO_UI_DEFAULT_WIDTH + height == 0 ? DISTRHO_UI_DEFAULT_WIDTH : + #endif + height)), uiData(UI::PrivateData::s_nextPrivateData) { #if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI if (width != 0 && height != 0) { + #ifndef DISTRHO_UI_DEFAULT_WIDTH Widget::setSize(width, height); + #endif if (automaticallyScaleAndSetAsMinimumSize) setGeometryConstraints(width, height, true, true, true); diff --git a/distrho/src/DistrhoUIVST3.cpp b/distrho/src/DistrhoUIVST3.cpp index 3d824274..eba6ec6f 100644 --- a/distrho/src/DistrhoUIVST3.cpp +++ b/distrho/src/DistrhoUIVST3.cpp @@ -1473,19 +1473,26 @@ struct dpf_plugin_view : v3_plugin_view_cpp { view->sizeRequestedBeforeBeingAttached = true; - const float lastScaleFactor = view->scale != nullptr ? view->scale->scaleFactor : 0.0f; + double scaleFactor = view->scale != nullptr ? view->scale->scaleFactor : 0.0; + #if defined(DISTRHO_UI_DEFAULT_WIDTH) && defined(DISTRHO_UI_DEFAULT_HEIGHT) + rect->right = DISTRHO_UI_DEFAULT_WIDTH; + rect->bottom = DISTRHO_UI_DEFAULT_HEIGHT; + if (d_isZero(scaleFactor)) + scaleFactor = 1.0; + #else UIExporter tmpUI(nullptr, 0, view->sampleRate, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, d_nextBundlePath, - view->instancePointer, lastScaleFactor); - rect->left = rect->top = 0; - rect->right = tmpUI.getWidth(); + view->instancePointer, scaleFactor); + rect->right = tmpUI.getWidth(); rect->bottom = tmpUI.getHeight(); + scaleFactor = tmpUI.getScaleFactor(); + tmpUI.quit(); + #endif + rect->left = rect->top = 0; #ifdef DISTRHO_OS_MAC - const double scaleFactor = tmpUI.getScaleFactor(); rect->right /= scaleFactor; rect->bottom /= scaleFactor; #endif - tmpUI.quit(); return V3_OK; }