DPF

DISTRHO Plugin Framework
Log | Files | Refs | Submodules | README | LICENSE

commit 05384270a88a734439db13aba8eb4714b7a78f80
parent 58f2cc61a99a5ba837097b9420b317eb79fb95eb
Author: falkTX <falktx@gmail.com>
Date:   Sun, 18 May 2014 02:42:43 +0100

Clear up UI size stuff

Diffstat:
Mdistrho/DistrhoUI.hpp | 3++-
Mdistrho/src/DistrhoPluginCarla.cpp | 8++++----
Mdistrho/src/DistrhoPluginJack.cpp | 8++++----
Mdistrho/src/DistrhoPluginVST.cpp | 8++++----
Mdistrho/src/DistrhoUI.cpp | 4++--
Mdistrho/src/DistrhoUIDSSI.cpp | 8++++----
Mdistrho/src/DistrhoUIInternal.hpp | 55++++++++++++++++++++++++++++++++++---------------------
Mdistrho/src/DistrhoUILV2.cpp | 8++++----
8 files changed, 58 insertions(+), 44 deletions(-)

diff --git a/distrho/DistrhoUI.hpp b/distrho/DistrhoUI.hpp @@ -49,7 +49,7 @@ public: // ------------------------------------------------------------------- // Host UI State - void d_uiResize(uint width, uint height); + void d_setSize(uint width, uint height); #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS // ------------------------------------------------------------------- @@ -89,6 +89,7 @@ private: struct PrivateData; PrivateData* const pData; friend class UIExporter; + friend class UIExporterWindow; DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(UI) }; diff --git a/distrho/src/DistrhoPluginCarla.cpp b/distrho/src/DistrhoPluginCarla.cpp @@ -43,7 +43,7 @@ public: UICarla(const NativeHostDescriptor* const host, PluginExporter* const plugin) : fHost(host), fPlugin(plugin), - fUI(this, 0, editParameterCallback, setParameterCallback, setStateCallback, sendNoteCallback, uiResizeCallback, plugin->getInstancePointer()) + fUI(this, 0, editParameterCallback, setParameterCallback, setStateCallback, sendNoteCallback, setSizeCallback, plugin->getInstancePointer()) { fUI.setTitle(host->uiName); @@ -110,7 +110,7 @@ protected: // TODO } - void handleUiResize(const uint width, const uint height) + void handleSetSize(const uint width, const uint height) { fUI.setSize(width, height); } @@ -154,9 +154,9 @@ private: } #endif - static void uiResizeCallback(void* ptr, uint width, uint height) + static void setSizeCallback(void* ptr, uint width, uint height) { - handlePtr->handleUiResize(width, height); + handlePtr->handleSetSize(width, height); } #undef handlePtr diff --git a/distrho/src/DistrhoPluginJack.cpp b/distrho/src/DistrhoPluginJack.cpp @@ -37,7 +37,7 @@ class PluginJack public: PluginJack(jack_client_t* const client) : fPlugin(), - fUI(this, 0, nullptr, nullptr, nullptr, nullptr, uiResizeCallback, fPlugin.getInstancePointer()), + fUI(this, 0, nullptr, nullptr, nullptr, nullptr, setSizeCallback, fPlugin.getInstancePointer()), fClient(client) { char strBuf[0xff+1]; @@ -217,7 +217,7 @@ protected: fUI.quit(); } - void uiResize(const uint width, const uint height) + void setSize(const uint width, const uint height) { fUI.setSize(width, height); } @@ -271,9 +271,9 @@ private: uiPtr->jackShutdown(); } - static void uiResizeCallback(void* ptr, uint width, uint height) + static void setSizeCallback(void* ptr, uint width, uint height) { - uiPtr->uiResize(width, height); + uiPtr->setSize(width, height); } #undef uiPtr diff --git a/distrho/src/DistrhoPluginVST.cpp b/distrho/src/DistrhoPluginVST.cpp @@ -119,7 +119,7 @@ public: fEffect(effect), fUiHelper(uiHelper), fPlugin(plugin), - fUI(this, winId, editParameterCallback, setParameterCallback, setStateCallback, sendNoteCallback, uiResizeCallback, plugin->getInstancePointer()) + fUI(this, winId, editParameterCallback, setParameterCallback, setStateCallback, sendNoteCallback, setSizeCallback, plugin->getInstancePointer()) { } @@ -215,7 +215,7 @@ protected: #endif } - void uiResize(const uint width, const uint height) + void setSize(const uint width, const uint height) { fUI.setSize(width, height); hostCallback(audioMasterSizeWindow, width, height, nullptr, 0.0f); @@ -256,9 +256,9 @@ private: handlePtr->sendNote(channel, note, velocity); } - static void uiResizeCallback(void* ptr, uint width, uint height) + static void setSizeCallback(void* ptr, uint width, uint height) { - handlePtr->uiResize(width, height); + handlePtr->setSize(width, height); } #undef handlePtr diff --git a/distrho/src/DistrhoUI.cpp b/distrho/src/DistrhoUI.cpp @@ -79,9 +79,9 @@ void UI::d_sendNote(uint8_t channel, uint8_t note, uint8_t velocity) // ----------------------------------------------------------------------- // Host UI State -void UI::d_uiResize(uint width, uint height) +void UI::d_setSize(uint width, uint height) { - pData->uiResizeCallback(width, height); + pData->setSizeCallback(width, height); } #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS diff --git a/distrho/src/DistrhoUIDSSI.cpp b/distrho/src/DistrhoUIDSSI.cpp @@ -93,7 +93,7 @@ class UIDssi { public: UIDssi(const OscData& oscData, const char* const uiTitle) - : fUI(this, 0, nullptr, setParameterCallback, setStateCallback, sendNoteCallback, uiResizeCallback), + : fUI(this, 0, nullptr, setParameterCallback, setStateCallback, sendNoteCallback, setSizeCallback), fHostClosed(false), fOscData(oscData) { @@ -188,7 +188,7 @@ protected: fOscData.send_midi(mdata); } - void uiResize(const uint width, const uint height) + void setSize(const uint width, const uint height) { fUI.setSize(width, height); } @@ -219,9 +219,9 @@ private: uiPtr->sendNote(channel, note, velocity); } - static void uiResizeCallback(void* ptr, uint width, uint height) + static void setSizeCallback(void* ptr, uint width, uint height) { - uiPtr->uiResize(width, height); + uiPtr->setSize(width, height); } #undef uiPtr diff --git a/distrho/src/DistrhoUIInternal.hpp b/distrho/src/DistrhoUIInternal.hpp @@ -40,7 +40,7 @@ typedef void (*editParamFunc) (void* ptr, uint32_t rindex, bool started); typedef void (*setParamFunc) (void* ptr, uint32_t rindex, float value); typedef void (*setStateFunc) (void* ptr, const char* key, const char* value); typedef void (*sendNoteFunc) (void* ptr, uint8_t channel, uint8_t note, uint8_t velo); -typedef void (*uiResizeFunc) (void* ptr, uint width, uint height); +typedef void (*setSizeFunc) (void* ptr, uint width, uint height); // ----------------------------------------------------------------------- // UI private data @@ -58,7 +58,7 @@ struct UI::PrivateData { setParamFunc setParamCallbackFunc; setStateFunc setStateCallbackFunc; sendNoteFunc sendNoteCallbackFunc; - uiResizeFunc uiResizeCallbackFunc; + setSizeFunc setSizeCallbackFunc; void* ptr; PrivateData() noexcept @@ -71,7 +71,7 @@ struct UI::PrivateData { setParamCallbackFunc(nullptr), setStateCallbackFunc(nullptr), sendNoteCallbackFunc(nullptr), - uiResizeCallbackFunc(nullptr), + setSizeCallbackFunc(nullptr), ptr(nullptr) { DISTRHO_SAFE_ASSERT(sampleRate != 0.0); @@ -117,26 +117,31 @@ struct UI::PrivateData { sendNoteCallbackFunc(ptr, channel, note, velocity); } - void uiResizeCallback(const uint width, const uint height) + void setSizeCallback(const uint width, const uint height) { - if (uiResizeCallbackFunc != nullptr) - uiResizeCallbackFunc(ptr, width, height); + if (setSizeCallbackFunc != nullptr) + setSizeCallbackFunc(ptr, width, height); } }; // ----------------------------------------------------------------------- // Plugin Window, needed to take care of resize properly -class PluginWindow : public Window +class UIExporterWindow : public Window { public: - PluginWindow(App& app, const intptr_t winId) + UIExporterWindow(App& app, const intptr_t winId) : Window(app, winId), - fUi(createUI()) + fUi(createUI()), + fIsReady(false) { + DISTRHO_SAFE_ASSERT_RETURN(fUi != nullptr,); + + setResizable(false); + setSize(fUi->d_getWidth(), fUi->d_getHeight()); } - ~PluginWindow() + ~UIExporterWindow() { delete fUi; } @@ -146,17 +151,25 @@ public: return fUi; } + bool isReady() const noexcept + { + return fIsReady; + } + protected: - void onReshape(const int width, const int height) override + void onReshape(int width, int height) override { DISTRHO_SAFE_ASSERT_RETURN(fUi != nullptr,); + fIsReady = true; + fUi->setSize(width, height); - fUi->d_uiResize(width, height); + fUi->d_uiReshape(width, height); } private: UI* const fUi; + bool fIsReady; }; // ----------------------------------------------------------------------- @@ -166,7 +179,7 @@ class UIExporter : public IdleCallback { public: UIExporter(void* const ptr, const intptr_t winId, - const editParamFunc editParamCall, const setParamFunc setParamCall, const setStateFunc setStateCall, const sendNoteFunc sendNoteCall, const uiResizeFunc uiResizeCall, + const editParamFunc editParamCall, const setParamFunc setParamCall, const setStateFunc setStateCall, const sendNoteFunc sendNoteCall, const setSizeFunc setSizeCall, void* const dspPtr = nullptr) : glApp(), glWindow(glApp, winId), @@ -181,10 +194,7 @@ public: fData->setParamCallbackFunc = setParamCall; fData->setStateCallbackFunc = setStateCall; fData->sendNoteCallbackFunc = sendNoteCall; - fData->uiResizeCallbackFunc = uiResizeCall; - - glWindow.setResizable(false); - glWindow.setSize(fUi->d_getWidth(), fUi->d_getHeight()); + fData->setSizeCallbackFunc = setSizeCall; #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS fData->dspPtr = dspPtr; @@ -270,7 +280,9 @@ public: { DISTRHO_SAFE_ASSERT_RETURN(fUi != nullptr, false); - fUi->d_uiIdle(); + if (glWindow.isReady()) + fUi->d_uiIdle(); + glApp.idle(); return ! glApp.isQuiting(); @@ -312,15 +324,16 @@ public: protected: void idleCallback() override { - fUi->d_uiIdle(); + if (glWindow.isReady()) + fUi->d_uiIdle(); } private: // ------------------------------------------------------------------- // DGL Application and Window for this widget - App glApp; - PluginWindow glWindow; + App glApp; + UIExporterWindow glWindow; // ------------------------------------------------------------------- // Widget and DistrhoUI data diff --git a/distrho/src/DistrhoUILV2.cpp b/distrho/src/DistrhoUILV2.cpp @@ -37,7 +37,7 @@ public: UiLv2(const intptr_t winId, const LV2_Options_Option* options, const LV2_URID_Map* const uridMap, const LV2UI_Resize* const uiResz, const LV2UI_Touch* uiTouch, const LV2UI_Controller controller, const LV2UI_Write_Function writeFunc, void* const dspPtr) - : fUI(this, winId, editParameterCallback, setParameterCallback, setStateCallback, sendNoteCallback, uiResizeCallback, dspPtr), + : fUI(this, winId, editParameterCallback, setParameterCallback, setStateCallback, sendNoteCallback, setSizeCallback, dspPtr), fUridMap(uridMap), fUiResize(uiResz), fUiTouch(uiTouch), @@ -193,7 +193,7 @@ protected: { } - void uiResize(const uint width, const uint height) + void setSize(const uint width, const uint height) { fUI.setSize(width, height); @@ -245,9 +245,9 @@ private: uiPtr->sendNote(channel, note, velocity); } - static void uiResizeCallback(void* ptr, uint width, uint height) + static void setSizeCallback(void* ptr, uint width, uint height) { - uiPtr->uiResize(width, height); + uiPtr->setSize(width, height); } #undef uiPtr