commit 87c74fb39ad9a3c3f6c01d66a2ccc37d277a67a5
parent d2c8d93044d3834930522a6ac2683971855e7376
Author: falkTX <falktx@falktx.com>
Date: Sat, 14 Aug 2021 01:08:39 +0100
Internally scale VST2 UI size if host doesnt inform of scale factor
Diffstat:
2 files changed, 57 insertions(+), 5 deletions(-)
diff --git a/distrho/src/DistrhoPluginVST2.cpp b/distrho/src/DistrhoPluginVST2.cpp
@@ -189,7 +189,8 @@ public:
nullptr, // TODO file request
nullptr,
plugin->getInstancePointer(),
- scaleFactor)
+ scaleFactor),
+ fHasScaleFactor(d_isNotZero(scaleFactor))
# if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
, fKeyboardModifiers(0)
# endif
@@ -228,11 +229,21 @@ public:
return fUI.getHeight();
}
+ double getScaleFactor() const
+ {
+ return fUI.getScaleFactor();
+ }
+
void setSampleRate(const double newSampleRate)
{
fUI.setSampleRate(newSampleRate, true);
}
+ void notifyScaleFactorChanged(const double scaleFactor)
+ {
+ fUI.notifyScaleFactorChanged(scaleFactor);
+ }
+
// -------------------------------------------------------------------
// functions called from the plugin side, may block
@@ -387,9 +398,15 @@ protected:
hostCallback(audioMasterAutomate, index, 0, nullptr, perValue);
}
- void setSize(const uint width, const uint height)
+ void setSize(uint width, uint height)
{
- // fUI.setWindowSize(width, height);
+ // figure out scale factor ourselves if the host doesn't support it
+ if (! fHasScaleFactor)
+ {
+ const double scaleFactor = fUI.getScaleFactor();
+ width /= scaleFactor;
+ height /= scaleFactor;
+ }
hostCallback(audioMasterSizeWindow, width, height);
}
@@ -421,6 +438,7 @@ private:
// Plugin UI
UIExporter fUI;
+ const bool fHasScaleFactor;
# if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
uint16_t fKeyboardModifiers;
# endif
@@ -499,7 +517,7 @@ public:
fVstRect.left = 0;
fVstRect.bottom = 0;
fVstRect.right = 0;
- fLastScaleFactor = 1.0f;
+ fLastScaleFactor = 0.0f;
if (parameterCount != 0)
{
@@ -670,6 +688,13 @@ public:
{
fVstRect.right = fVstUI->getWidth();
fVstRect.bottom = fVstUI->getHeight();
+ // figure out scale factor ourselves if the host doesn't support it
+ if (fLastScaleFactor == 0.0f)
+ {
+ const double scaleFactor = fVstUI->getScaleFactor();
+ fVstRect.right /= scaleFactor;
+ fVstRect.bottom /= scaleFactor;
+ }
}
else
{
@@ -678,6 +703,13 @@ public:
fPlugin.getInstancePointer(), fLastScaleFactor);
fVstRect.right = tmpUI.getWidth();
fVstRect.bottom = tmpUI.getHeight();
+ // figure out scale factor ourselves if the host doesn't support it
+ if (fLastScaleFactor == 0.0f)
+ {
+ const double scaleFactor = tmpUI.getScaleFactor();
+ fVstRect.right /= scaleFactor;
+ fVstRect.bottom /= scaleFactor;
+ }
tmpUI.quit();
}
*(ERect**)ptr = &fVstRect;
@@ -998,7 +1030,15 @@ public:
case effVendorSpecific:
#if DISTRHO_PLUGIN_HAS_UI
if (index == CCONST('P', 'r', 'e', 'S') && value == CCONST('A', 'e', 'C', 's'))
+ {
+ if (d_isEqual(fLastScaleFactor, opt))
+ break;
+
fLastScaleFactor = opt;
+
+ if (fVstUI != nullptr)
+ fVstUI->notifyScaleFactorChanged(opt);
+ }
#endif
break;
diff --git a/distrho/src/DistrhoUIInternal.hpp b/distrho/src/DistrhoUIInternal.hpp
@@ -59,7 +59,7 @@ public:
const fileRequestFunc fileRequestCall,
const char* const bundlePath = nullptr,
void* const dspPtr = nullptr,
- const double scaleFactor = 1.0,
+ const double scaleFactor = 0.0,
const uint32_t bgColor = 0,
const uint32_t fgColor = 0xffffffff)
: ui(nullptr),
@@ -128,6 +128,11 @@ public:
return uiData->window->getHeight();
}
+ double getScaleFactor() const noexcept
+ {
+ return uiData->window->getScaleFactor();
+ }
+
bool isVisible() const noexcept
{
return uiData->window->isVisible();
@@ -340,6 +345,13 @@ public:
// -------------------------------------------------------------------
+ void notifyScaleFactorChanged(const double scaleFactor)
+ {
+ DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr,);
+
+ ui->uiScaleFactorChanged(scaleFactor);
+ }
+
void setSampleRate(const double sampleRate, const bool doCallback = false)
{
DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr,);