From b716bf6155c2573be4bb37e61a36a6ba52c489d8 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 27 Oct 2012 05:21:32 +0100 Subject: [PATCH] Carla: Fix initial plugin-bridge window size --- c++/carla-backend/vst.cpp | 26 +++++++++++++++++++++--- c++/carla-bridge/carla_bridge_plugin.cpp | 24 +++++++++++++++++----- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/c++/carla-backend/vst.cpp b/c++/carla-backend/vst.cpp index 71d4fd7..cac81f1 100644 --- a/c++/carla-backend/vst.cpp +++ b/c++/carla-backend/vst.cpp @@ -341,14 +341,34 @@ public: int32_t value = 0; void* const ptr = (void*)container->winId(); + ERect* vstRect = nullptr; #ifdef Q_WS_X11 value = (intptr_t)QX11Info::display(); #endif + // get UI size before opening UI, plugin may refuse this + effect->dispatcher(effect, effEditGetRect, 0, 0, &vstRect, 0.0f); + + if (vstRect) + { + int width = vstRect->right - vstRect->left; + int height = vstRect->bottom - vstRect->top; + + if (width > 0 || height > 0) + { + container->setFixedSize(width, height); +#ifdef BUILD_BRIDGE + x_engine->callback(CALLBACK_RESIZE_GUI, m_id, width, height, 1.0); +#endif + } + } + + // open UI if (effect->dispatcher(effect, effEditOpen, 0, value, ptr, 0.0f) == 1) { - ERect* vstRect = nullptr; + // get UI size again, can't fail now + vstRect = nullptr; effect->dispatcher(effect, effEditGetRect, 0, 0, &vstRect, 0.0f); if (vstRect) @@ -358,7 +378,7 @@ public: if (width <= 0 || height <= 0) { - qCritical("VstPlugin::setGuiContainer(%p) - failed to get proper window size", container); + qCritical("VstPlugin::setGuiContainer(%p) - failed to get proper editor size", container); return; } @@ -369,7 +389,7 @@ public: qDebug("VstPlugin::setGuiContainer(%p) -> setFixedSize(%i, %i)", container, width, height); } else - qCritical("VstPlugin::setGuiContainer(%p) - failed to get plugin window size", container); + qCritical("VstPlugin::setGuiContainer(%p) - failed to get plugin editor size", container); } else { diff --git a/c++/carla-bridge/carla_bridge_plugin.cpp b/c++/carla-bridge/carla_bridge_plugin.cpp index 9efaa41..be856f0 100644 --- a/c++/carla-bridge/carla_bridge_plugin.cpp +++ b/c++/carla-bridge/carla_bridge_plugin.cpp @@ -226,7 +226,7 @@ public: engine = nullptr; plugin = nullptr; - pluginGui = new BridgePluginGUI(nullptr, this); + pluginGui = nullptr; m_client = this; } @@ -254,6 +254,9 @@ public: void init() { qDebug("BridgePluginClient::init()"); + + pluginGui = new BridgePluginGUI(nullptr, this); + pluginGui->hide(); } void exec(CarlaClient* const, const bool showGui) @@ -552,8 +555,17 @@ public: case CarlaBackend::CALLBACK_RESIZE_GUI: CARLA_ASSERT(value1 > 0 && value2 > 0); - nextWidth = value1; - nextHeight = value2; + if (value3 == 1.0) + { + nextWidth = 0; + nextHeight = 0; + pluginGui->setFixedSize(value1, value2); + } + else if (nextWidth != value1 && nextHeight != value2) + { + nextWidth = value1; + nextHeight = value2; + } break; case CarlaBackend::CALLBACK_RELOAD_PARAMETERS: @@ -674,7 +686,6 @@ int main(int argc, char* argv[]) qargc = argc; qargv = argv; - initSignalHandler(); const char* const oscUrl = argv[1]; const char* const stype = argv[2]; @@ -715,6 +726,9 @@ int main(int argc, char* argv[]) return -1; } + // Listen for ctrl+c or sigint/sigterm events + initSignalHandler(); + // Init backend engine CarlaBackend::CarlaEngine* engine = CarlaBackend::CarlaEngine::newDriverByName("JACK"); engine->setCallback(client.callback, &client); @@ -737,7 +751,7 @@ int main(int argc, char* argv[]) return 2; } - /// Init plugin + // Init plugin short id = engine->addPlugin(itype, filename, name, label); int ret;