Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
Fix VST plug-ins disappearing when resized
Browse files Browse the repository at this point in the history
Rather than resizing using the Windows API, perform resize on the Qt
wrapper window. This handles most situations of the plugin resizing.
  • Loading branch information
bluecataudio authored and WizardCM committed Jan 7, 2022
1 parent 2e90d23 commit 425935a
Showing 1 changed file with 8 additions and 29 deletions.
37 changes: 8 additions & 29 deletions win/EditorWidget-win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ void EditorWidget::buildEffectContainer(AEffect *effect)

QWidget *widget = QWidget::createWindowContainer(QWindow::fromWinId((WId)windowHandle), this);
widget->move(0, 0);
widget->resize(300, 300);

effect->dispatcher(effect, effEditOpen, 0, 0, windowHandle, 0);

VstRect *vstRect = nullptr;
effect->dispatcher(effect, effEditGetRect, 0, 0, &vstRect, 0);
if (vstRect) {
widget->resize(vstRect->right - vstRect->left, vstRect->bottom - vstRect->top);
resize(vstRect->right - vstRect->left, vstRect->bottom - vstRect->top);
} else {
widget->resize(300, 300);
}
}

Expand All @@ -53,36 +55,13 @@ void EditorWidget::handleResizeRequest(int, int)
// so we must resize window manually

// get pointer to vst effect from window long
LONG_PTR wndPtr = (LONG_PTR)GetWindowLongPtrW(windowHandle, -21 /*GWLP_USERDATA*/);
AEffect * effect = (AEffect *)(wndPtr);
VstRect * rec = nullptr;
static RECT PluginRc = {0};
RECT winRect = {0};
LONG_PTR wndPtr = (LONG_PTR)GetWindowLongPtrW(windowHandle, -21 /*GWLP_USERDATA*/);
AEffect *effect = (AEffect *)(wndPtr);
VstRect *rec = nullptr;

GetWindowRect(windowHandle, &winRect);
if (effect) {
effect->dispatcher(effect, effEditGetRect, 1, 0, &rec, 0);
}
effect->dispatcher(effect, effEditGetRect, 0, 0, &rec, 0);

// compare window rect with VST Rect
if (rec) {
if (PluginRc.bottom != rec->bottom || PluginRc.left != rec->left || PluginRc.right != rec->right ||
PluginRc.top != rec->top) {
PluginRc.bottom = rec->bottom;
PluginRc.left = rec->left;
PluginRc.right = rec->right;
PluginRc.top = rec->top;

// set rect to our window
AdjustWindowRectEx(&PluginRc, WS_CAPTION | WS_THICKFRAME | WS_OVERLAPPEDWINDOW, FALSE, 0);

// move window to apply pos
MoveWindow(windowHandle,
winRect.left,
winRect.top,
PluginRc.right - PluginRc.left,
PluginRc.bottom - PluginRc.top,
TRUE);
}
resize(rec->right - rec->left, rec->bottom - rec->top);
}
}

0 comments on commit 425935a

Please sign in to comment.