zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

commit 13c17bece8a5f6ad7fb9cdf9ec72363646ddd844
parent 349772abc260920aec0183ff8d368f84de255ca1
Author: falkTX <falktx@gmail.com>
Date:   Sun, 14 Feb 2016 20:07:54 +0100

Continue sync with dpf external-ui, almost there...

Diffstat:
Msrc/Plugin/ZynAddSubFX/DistrhoPluginInfo.h | 2+-
Msrc/Plugin/ZynAddSubFX/DistrhoUI.cpp | 11++++++++---
Msrc/Plugin/ZynAddSubFX/DistrhoUI.hpp | 13++++++++++++-
Msrc/Plugin/ZynAddSubFX/DistrhoUIInternal.hpp | 219++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
4 files changed, 216 insertions(+), 29 deletions(-)

diff --git a/src/Plugin/ZynAddSubFX/DistrhoPluginInfo.h b/src/Plugin/ZynAddSubFX/DistrhoPluginInfo.h @@ -2,7 +2,7 @@ ZynAddSubFX - a software synthesizer DistrhoPluginInfo.h - DPF information header - Copyright (C) 2015 Filipe Coelho + Copyright (C) 2015-2016 Filipe Coelho Author: Filipe Coelho This program is free software; you can redistribute it and/or modify diff --git a/src/Plugin/ZynAddSubFX/DistrhoUI.cpp b/src/Plugin/ZynAddSubFX/DistrhoUI.cpp @@ -35,16 +35,21 @@ uintptr_t g_nextWindowId = 0; /* ------------------------------------------------------------------------------------------------------------ * UI */ +#ifdef HAVE_DGL UI::UI(uint width, uint height) - : pData(new PrivateData()) + : UIWidget(*d_lastUiWindow), + pData(new PrivateData()) { -#ifdef HAVE_DGL ((UIWidget*)this)->pData->needsFullViewport = false; if (width > 0 && height > 0) setSize(width, height); -#endif } +#else +UI::UI(uint width, uint height) + : UIWidget(width, height), + pData(new PrivateData()) {} +#endif UI::~UI() { diff --git a/src/Plugin/ZynAddSubFX/DistrhoUI.hpp b/src/Plugin/ZynAddSubFX/DistrhoUI.hpp @@ -39,6 +39,17 @@ #define DISTRHO_PLUGIN_WANT_STATE 1 #define DISTRHO_PLUGIN_WANT_FULL_STATE 1 +#ifndef HAVE_DGL +# include "extra/ExternalWindow.hpp" +typedef DISTRHO_NAMESPACE::ExternalWindow UIWidget; +#elif DISTRHO_UI_USE_NANOVG +# include "../dgl/NanoVG.hpp" +typedef DGL::NanoWidget UIWidget; +#else +# include "../dgl/Widget.hpp" +typedef DGL::Widget UIWidget; +#endif + START_NAMESPACE_DISTRHO /* ------------------------------------------------------------------------------------------------------------ @@ -55,7 +66,7 @@ START_NAMESPACE_DISTRHO @note You must call setSize during construction, @TODO Detailed information about this class. */ -class UI +class UI : public UIWidget { public: /** diff --git a/src/Plugin/ZynAddSubFX/DistrhoUIInternal.hpp b/src/Plugin/ZynAddSubFX/DistrhoUIInternal.hpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com> + * Copyright (C) 2012-2016 Filipe Coelho <falktx@falktx.com> * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -19,6 +19,14 @@ #include "DistrhoUI.hpp" +#ifdef HAVE_DGL +# include "../../dgl/Application.hpp" +# include "../../dgl/Window.hpp" +using DGL::Application; +using DGL::IdleCallback; +using DGL::Window; +#endif + START_NAMESPACE_DISTRHO // ----------------------------------------------------------------------- @@ -123,15 +131,87 @@ struct UI::PrivateData { }; // ----------------------------------------------------------------------- -// UI exporter class +// Plugin Window, needed to take care of resize properly + +#ifdef HAVE_DGL +static inline +UI* createUiWrapper(void* const dspPtr, Window* const window) +{ + d_lastUiDspPtr = dspPtr; + d_lastUiWindow = window; + UI* const ret = createUI(); + d_lastUiDspPtr = nullptr; + d_lastUiWindow = nullptr; + return ret; +} -static UI* createWindowIdUI(const intptr_t winId) +class UIExporterWindow : public Window { +public: + UIExporterWindow(Application& app, const intptr_t winId, void* const dspPtr) + : Window(app, winId), + fUI(createUiWrapper(dspPtr, this)), + fIsReady(false) + { + DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,); + + // set window size + setResizable(false); + setSize(fUI->getWidth(), fUI->getHeight()); + } + + ~UIExporterWindow() + { + delete fUI; + } + + UI* getUI() const noexcept + { + return fUI; + } + + bool isReady() const noexcept + { + return fIsReady; + } + +protected: + // custom window reshape + void onReshape(uint width, uint height) override + { + DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,); + + fUI->uiReshape(width, height); + fIsReady = true; + } + + // custom file-browser selected + void fileBrowserSelected(const char* filename) override + { + DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,); + + fUI->uiFileBrowserSelected(filename); + } + +private: + UI* const fUI; + bool fIsReady; +}; +#else +static inline +UI* createUiWrapper(void* const dspPtr, const uintptr_t winId) +{ + d_lastUiDspPtr = dspPtr; g_nextWindowId = winId; - UI* const ui(createUI()); + UI* const ret = createUI(); + d_lastUiDspPtr = nullptr; g_nextWindowId = 0; - return ui; + return ret; } +#endif + +// ----------------------------------------------------------------------- +// UI exporter class class UIExporter { @@ -139,7 +219,14 @@ public: UIExporter(void* const ptr, const intptr_t winId, const editParamFunc editParamCall, const setParamFunc setParamCall, const setStateFunc setStateCall, const sendNoteFunc sendNoteCall, const setSizeFunc setSizeCall, void* const dspPtr = nullptr) - : fUI(createWindowIdUI(winId)), +#ifdef HAVE_DGL + : glApp(), + glWindow(glApp, winId, dspPtr), + fChangingSize(false), + fUI(glWindow.getUI()), +#else + : fUI(createUiWrapper(dspPtr, winId)), +#endif fData((fUI != nullptr) ? fUI->pData : nullptr) { DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,); @@ -155,6 +242,48 @@ public: // ------------------------------------------------------------------- + uint getWidth() const noexcept + { +#ifdef HAVE_DGL + return glWindow.getWidth(); +#else + DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr, 1); + return fUI->getWidth(); +#endif + } + + uint getHeight() const noexcept + { +#ifdef HAVE_DGL + return glWindow.getHeight(); +#else + DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr, 1); + return fUI->getHeight(); +#endif + } + + bool isVisible() const noexcept + { +#ifdef HAVE_DGL + return glWindow.isVisible(); +#else + return true; +#endif + } + + // ------------------------------------------------------------------- + + intptr_t getWindowId() const noexcept + { +#ifdef HAVE_DGL + return glWindow.getWindowId(); +#else + return 0; +#endif + } + + // ------------------------------------------------------------------- + uint32_t getParameterOffset() const noexcept { DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr, 0); @@ -192,53 +321,83 @@ public: #endif // ------------------------------------------------------------------- - // compatibility calls, used for regular OpenGL windows - uint getWidth() const noexcept +#ifdef HAVE_DGL + void exec(IdleCallback* const cb) { - return 390; + DISTRHO_SAFE_ASSERT_RETURN(cb != nullptr,); + DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,); + + glWindow.addIdleCallback(cb); + glWindow.setVisible(true); + glApp.exec(); } - uint getHeight() const noexcept + void exec_idle() { - return 525; + if (glWindow.isReady()) + fUI->uiIdle(); } - intptr_t getWindowId() const noexcept + bool idle() { - return 0; + DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr, false); + + glApp.idle(); + + if (glWindow.isReady()) + fUI->uiIdle(); + + return ! glApp.isQuiting(); } - bool isVisible() const noexcept + void quit() { - return true; + glWindow.close(); + glApp.quit(); } + // ------------------------------------------------------------------- + void setWindowSize(const uint width, const uint height, const bool updateUI = false) { + DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,); + DISTRHO_SAFE_ASSERT_RETURN(! fChangingSize,); + + fChangingSize = true; + + if (updateUI) + fUI->setSize(width, height); + + glWindow.setSize(width, height); + + fChangingSize = false; } void setWindowTitle(const char* const uiTitle) { + glWindow.setTitle(uiTitle); } void setWindowTransientWinId(const uintptr_t winId) { + glWindow.setTransientWinId(winId); } bool setWindowVisible(const bool yesNo) { - return true; - } + glWindow.setVisible(yesNo); - bool idle() - { - return true; - } - - void quit() - { + return ! glApp.isQuiting(); } +#else + bool idle() { return true; } + void quit() {} + void setWindowSize(const uint width, const uint height, const bool updateUI = false) {} + void setWindowTitle(const char* const uiTitle) {} + void setWindowTransientWinId(const uintptr_t winId) {} + bool setWindowVisible(const bool yesNo) { return true; } +#endif // ------------------------------------------------------------------- @@ -258,7 +417,19 @@ public: } private: +#ifdef HAVE_DGL + // ------------------------------------------------------------------- + // DGL Application and Window for this widget + + Application glApp; + UIExporterWindow glWindow; + + // prevent recursion + bool fChangingSize; +#endif + // ------------------------------------------------------------------- + // Widget and DistrhoUI data UI* const fUI; UI::PrivateData* const fData;