Browse Source

Internally scale VST2 UI size if host doesnt inform of scale factor

pull/309/head
falkTX 3 years ago
parent
commit
87c74fb39a
2 changed files with 57 additions and 5 deletions
  1. +44
    -4
      distrho/src/DistrhoPluginVST2.cpp
  2. +13
    -1
      distrho/src/DistrhoUIInternal.hpp

+ 44
- 4
distrho/src/DistrhoPluginVST2.cpp View File

@@ -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;



+ 13
- 1
distrho/src/DistrhoUIInternal.hpp View File

@@ -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,);


Loading…
Cancel
Save