Signed-off-by: falkTX <falktx@falktx.com>pull/272/head
| @@ -9,7 +9,7 @@ include ../Makefile.base.mk | |||
| # --------------------------------------------------------------------------------------------------------------------- | |||
| BUILD_C_FLAGS += $(DGL_FLAGS) -I. -Isrc | |||
| BUILD_CXX_FLAGS += $(DGL_FLAGS) -I. -Isrc -Isrc/pugl-upstream -DDONT_SET_USING_DGL_NAMESPACE -Wno-unused-parameter | |||
| BUILD_CXX_FLAGS += $(DGL_FLAGS) -I. -Isrc -Isrc/pugl-upstream/include -DDONT_SET_USING_DGL_NAMESPACE -Wno-unused-parameter | |||
| LINK_FLAGS += $(DGL_LIBS) | |||
| # TODO fix these after pugl-upstream is done | |||
| @@ -21,6 +21,7 @@ | |||
| #ifdef DISTRHO_DEFINES_H_INCLUDED | |||
| START_NAMESPACE_DISTRHO | |||
| class UI; | |||
| class UIExporter; | |||
| END_NAMESPACE_DISTRHO | |||
| #endif | |||
| @@ -145,6 +146,7 @@ private: | |||
| friend class Widget; | |||
| friend class StandaloneWindow; | |||
| #ifdef DISTRHO_DEFINES_H_INCLUDED | |||
| friend class DISTRHO_NAMESPACE::UI; | |||
| friend class DISTRHO_NAMESPACE::UIExporter; | |||
| #endif | |||
| @@ -1,6 +1,6 @@ | |||
| /* | |||
| * DISTRHO Plugin Framework (DPF) | |||
| * Copyright (C) 2012-2020 Filipe Coelho <falktx@falktx.com> | |||
| * Copyright (C) 2012-2021 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 | |||
| @@ -20,7 +20,7 @@ | |||
| #include "../Application.hpp" | |||
| #include "../Window.hpp" | |||
| #include "pugl-upstream/pugl/pugl.h" | |||
| #include "pugl-upstream/include/pugl/pugl.h" | |||
| #include <list> | |||
| @@ -26,25 +26,25 @@ | |||
| #endif | |||
| extern "C" { | |||
| #include "pugl-upstream/pugl/detail/implementation.c" | |||
| #include "pugl-upstream/src/implementation.c" | |||
| } | |||
| #if defined(DISTRHO_OS_HAIKU) | |||
| # define DGL_DEBUG_EVENTS | |||
| # include "pugl-upstream/pugl/detail/haiku.cpp" | |||
| # include "pugl-upstream/src/haiku.cpp" | |||
| #elif defined(DISTRHO_OS_MAC) | |||
| # define PuglWindow DISTRHO_JOIN_MACRO(PuglWindow, DGL_NAMESPACE) | |||
| # define PuglOpenGLView DISTRHO_JOIN_MACRO(PuglOpenGLView, DGL_NAMESPACE) | |||
| # include "pugl-upstream/pugl/detail/mac.m" | |||
| # include "pugl-upstream/src/mac.m" | |||
| #elif defined(DISTRHO_OS_WINDOWS) | |||
| # include "ppugl-upstream/pugl/detail/win.c" | |||
| # include "ppugl-upstream/src/win.c" | |||
| # undef max | |||
| # undef min | |||
| #else | |||
| # include <sys/types.h> | |||
| # include <unistd.h> | |||
| extern "C" { | |||
| # include "pugl-upstream/pugl/detail/x11.c" | |||
| # include "pugl-upstream/src/x11.c" | |||
| } | |||
| #endif | |||
| @@ -75,6 +75,10 @@ void DGL::Window::PrivateData::Fallback::onReshape(const uint width, const uint | |||
| glViewport(0, 0, static_cast<GLsizei>(width), static_cast<GLsizei>(height)); | |||
| glMatrixMode(GL_MODELVIEW); | |||
| glLoadIdentity(); | |||
| #else | |||
| // unused | |||
| (void)width; | |||
| (void)height; | |||
| #endif | |||
| } | |||
| @@ -20,7 +20,7 @@ | |||
| #include "../Window.hpp" | |||
| #include "ApplicationPrivateData.hpp" | |||
| #include "pugl-upstream/pugl/pugl.h" | |||
| #include "pugl-upstream/include/pugl/pugl.h" | |||
| #include <vector> | |||
| @@ -77,6 +77,10 @@ struct Window::PrivateData { | |||
| { | |||
| } | |||
| #ifdef DISTRHO_DEFINES_H_INCLUDED | |||
| friend class DISTRHO_NAMESPACE::UI; | |||
| #endif | |||
| DISTRHO_DECLARE_NON_COPY_STRUCT(PrivateData) | |||
| }; | |||
| @@ -161,6 +161,14 @@ | |||
| # define DISTRHO_PLUGIN_HAS_UI 0 | |||
| #endif | |||
| // ----------------------------------------------------------------------- | |||
| // Prevent users from messing about with DPF internals | |||
| #ifdef DISTRHO_UI_IS_STANDALONE | |||
| # error DISTRHO_UI_IS_STANDALONE must not be defined | |||
| #endif | |||
| // ----------------------------------------------------------------------- | |||
| #endif // DISTRHO_PLUGIN_CHECKS_H_INCLUDED | |||
| @@ -17,6 +17,7 @@ | |||
| #include "DistrhoPluginInternal.hpp" | |||
| #if DISTRHO_PLUGIN_HAS_UI | |||
| # define DISTRHO_UI_IS_STANDALONE true | |||
| # include "DistrhoUIInternal.hpp" | |||
| #else | |||
| # include "../extra/Sleep.hpp" | |||
| @@ -14,7 +14,8 @@ | |||
| * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |||
| */ | |||
| #include "DistrhoUIInternal.hpp" | |||
| #include "DistrhoUIPrivateData.hpp" | |||
| #include "src/WindowPrivateData.hpp" | |||
| #if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI | |||
| # include "src/WidgetPrivateData.hpp" | |||
| #endif | |||
| @@ -22,7 +23,7 @@ | |||
| START_NAMESPACE_DISTRHO | |||
| /* ------------------------------------------------------------------------------------------------------------ | |||
| * Static data, see DistrhoUIInternal.hpp */ | |||
| * Static data, see DistrhoUIInternal.hpp and DistrhoUIPrivateData.hpp */ | |||
| double d_lastUiSampleRate = 0.0; | |||
| void* d_lastUiDspPtr = nullptr; | |||
| @@ -34,6 +35,36 @@ uintptr_t g_nextWindowId = 0; | |||
| Window* d_lastUiWindow = nullptr; | |||
| #endif | |||
| // ----------------------------------------------------------------------------------------------------------- | |||
| #if DISTRHO_PLUGIN_HAS_EXTERNAL_UI | |||
| static inline | |||
| UI* createUiWrapper(void* const dspPtr, const uintptr_t winId, const double scaleFactor, const char* const bundlePath) | |||
| { | |||
| d_lastUiDspPtr = dspPtr; | |||
| g_nextWindowId = winId; | |||
| g_nextScaleFactor = scaleFactor; | |||
| g_nextBundlePath = bundlePath; | |||
| UI* const ret = createUI(); | |||
| d_lastUiDspPtr = nullptr; | |||
| g_nextWindowId = 0; | |||
| g_nextScaleFactor = 1.0; | |||
| g_nextBundlePath = nullptr; | |||
| return ret; | |||
| } | |||
| #else | |||
| 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; | |||
| } | |||
| #endif // DISTRHO_PLUGIN_HAS_EXTERNAL_UI | |||
| /* ------------------------------------------------------------------------------------------------------------ | |||
| * UI */ | |||
| @@ -157,7 +188,7 @@ uintptr_t UI::getNextWindowId() noexcept | |||
| return g_nextWindowId; | |||
| } | |||
| # endif | |||
| #endif | |||
| #endif // DISTRHO_PLUGIN_HAS_EXTERNAL_UI | |||
| /* ------------------------------------------------------------------------------------------------------------ | |||
| * DSP/Plugin Callbacks (optional) */ | |||
| @@ -176,20 +207,7 @@ void UI::uiFileBrowserSelected(const char*) | |||
| void UI::uiReshape(uint width, uint height) | |||
| { | |||
| #ifdef DGL_OPENGL | |||
| glEnable(GL_BLEND); | |||
| glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |||
| glMatrixMode(GL_PROJECTION); | |||
| glLoadIdentity(); | |||
| glOrtho(0.0, static_cast<GLdouble>(width), static_cast<GLdouble>(height), 0.0, 0.0, 1.0); | |||
| glViewport(0, 0, static_cast<GLsizei>(width), static_cast<GLsizei>(height)); | |||
| glMatrixMode(GL_MODELVIEW); | |||
| glLoadIdentity(); | |||
| #else | |||
| // unused | |||
| (void)width; | |||
| (void)height; | |||
| #endif | |||
| Window::PrivateData::Fallback::onReshape(width, height); | |||
| } | |||
| /* ------------------------------------------------------------------------------------------------------------ | |||
| @@ -17,7 +17,7 @@ | |||
| #ifndef DISTRHO_UI_INTERNAL_HPP_INCLUDED | |||
| #define DISTRHO_UI_INTERNAL_HPP_INCLUDED | |||
| #include "../DistrhoUI.hpp" | |||
| #include "DistrhoUIPrivateData.hpp" | |||
| #if DISTRHO_PLUGIN_HAS_EXTERNAL_UI | |||
| # include "../extra/Sleep.hpp" | |||
| @@ -46,153 +46,17 @@ extern Window* d_lastUiWindow; | |||
| #endif | |||
| // ----------------------------------------------------------------------- | |||
| // UI callbacks | |||
| 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 (*setSizeFunc) (void* ptr, uint width, uint height); | |||
| typedef bool (*fileRequestFunc) (void* ptr, const char* key); | |||
| // ----------------------------------------------------------------------- | |||
| // UI private data | |||
| struct UI::PrivateData { | |||
| // DSP | |||
| double sampleRate; | |||
| uint32_t parameterOffset; | |||
| #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS | |||
| void* dspPtr; | |||
| #endif | |||
| // UI | |||
| bool automaticallyScale; | |||
| bool resizeInProgress; | |||
| uint minWidth; | |||
| uint minHeight; | |||
| uint bgColor; | |||
| uint fgColor; | |||
| // Callbacks | |||
| void* callbacksPtr; | |||
| editParamFunc editParamCallbackFunc; | |||
| setParamFunc setParamCallbackFunc; | |||
| setStateFunc setStateCallbackFunc; | |||
| sendNoteFunc sendNoteCallbackFunc; | |||
| setSizeFunc setSizeCallbackFunc; | |||
| fileRequestFunc fileRequestCallbackFunc; | |||
| PrivateData() noexcept | |||
| : sampleRate(d_lastUiSampleRate), | |||
| parameterOffset(0), | |||
| #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS | |||
| dspPtr(d_lastUiDspPtr), | |||
| #endif | |||
| automaticallyScale(false), | |||
| resizeInProgress(false), | |||
| minWidth(0), | |||
| minHeight(0), | |||
| bgColor(0), | |||
| fgColor(0), | |||
| callbacksPtr(nullptr), | |||
| editParamCallbackFunc(nullptr), | |||
| setParamCallbackFunc(nullptr), | |||
| setStateCallbackFunc(nullptr), | |||
| sendNoteCallbackFunc(nullptr), | |||
| setSizeCallbackFunc(nullptr), | |||
| fileRequestCallbackFunc(nullptr) | |||
| { | |||
| DISTRHO_SAFE_ASSERT(d_isNotZero(sampleRate)); | |||
| #if defined(DISTRHO_PLUGIN_TARGET_DSSI) || defined(DISTRHO_PLUGIN_TARGET_LV2) | |||
| parameterOffset += DISTRHO_PLUGIN_NUM_INPUTS + DISTRHO_PLUGIN_NUM_OUTPUTS; | |||
| # if DISTRHO_PLUGIN_WANT_LATENCY | |||
| parameterOffset += 1; | |||
| # endif | |||
| #endif | |||
| #ifdef DISTRHO_PLUGIN_TARGET_LV2 | |||
| # if (DISTRHO_PLUGIN_IS_SYNTH || DISTRHO_PLUGIN_WANT_TIMEPOS || DISTRHO_PLUGIN_WANT_STATE) | |||
| parameterOffset += 1; | |||
| # if DISTRHO_PLUGIN_WANT_STATE | |||
| parameterOffset += 1; | |||
| # endif | |||
| # endif | |||
| #if DISTRHO_PLUGIN_HAS_EXTERNAL_UI | |||
| UI* createUiWrapper(void* dspPtr, uintptr_t winId, double scaleFactor, const char* bundlePath); | |||
| #else // DISTRHO_PLUGIN_HAS_EXTERNAL_UI | |||
| UI* createUiWrapper(void* dspPtr, Window* window); | |||
| #endif | |||
| } | |||
| void editParamCallback(const uint32_t rindex, const bool started) | |||
| { | |||
| if (editParamCallbackFunc != nullptr) | |||
| editParamCallbackFunc(callbacksPtr, rindex, started); | |||
| } | |||
| void setParamCallback(const uint32_t rindex, const float value) | |||
| { | |||
| if (setParamCallbackFunc != nullptr) | |||
| setParamCallbackFunc(callbacksPtr, rindex, value); | |||
| } | |||
| void setStateCallback(const char* const key, const char* const value) | |||
| { | |||
| if (setStateCallbackFunc != nullptr) | |||
| setStateCallbackFunc(callbacksPtr, key, value); | |||
| } | |||
| void sendNoteCallback(const uint8_t channel, const uint8_t note, const uint8_t velocity) | |||
| { | |||
| if (sendNoteCallbackFunc != nullptr) | |||
| sendNoteCallbackFunc(callbacksPtr, channel, note, velocity); | |||
| } | |||
| void setSizeCallback(const uint width, const uint height) | |||
| { | |||
| if (setSizeCallbackFunc != nullptr) | |||
| setSizeCallbackFunc(callbacksPtr, width, height); | |||
| } | |||
| bool fileRequestCallback(const char* key) | |||
| { | |||
| if (fileRequestCallbackFunc != nullptr) | |||
| return fileRequestCallbackFunc(callbacksPtr, key); | |||
| // TODO use old style DPF dialog here | |||
| return false; | |||
| } | |||
| }; | |||
| // ----------------------------------------------------------------------- | |||
| // Plugin Window, needed to take care of resize properly | |||
| #if DISTRHO_PLUGIN_HAS_EXTERNAL_UI | |||
| static inline | |||
| UI* createUiWrapper(void* const dspPtr, const uintptr_t winId, const double scaleFactor, const char* const bundlePath) | |||
| { | |||
| d_lastUiDspPtr = dspPtr; | |||
| g_nextWindowId = winId; | |||
| g_nextScaleFactor = scaleFactor; | |||
| g_nextBundlePath = bundlePath; | |||
| UI* const ret = createUI(); | |||
| d_lastUiDspPtr = nullptr; | |||
| g_nextWindowId = 0; | |||
| g_nextScaleFactor = 1.0; | |||
| g_nextBundlePath = nullptr; | |||
| return ret; | |||
| } | |||
| #else // DISTRHO_PLUGIN_HAS_EXTERNAL_UI | |||
| 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; | |||
| } | |||
| #if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI | |||
| class UIExporterWindow : public Window | |||
| { | |||
| public: | |||
| @@ -284,7 +148,7 @@ public: | |||
| #if DISTRHO_PLUGIN_HAS_EXTERNAL_UI | |||
| : fUI(createUiWrapper(dspPtr, winId, scaleFactor, bundlePath)), | |||
| #else | |||
| : glApp(), | |||
| : glApp(DISTRHO_UI_IS_STANDALONE), | |||
| glWindow(glApp, winId, scaleFactor, dspPtr), | |||
| fChangingSize(false), | |||
| fUI(glWindow.getUI()), | |||
| @@ -0,0 +1,152 @@ | |||
| /* | |||
| * DISTRHO Plugin Framework (DPF) | |||
| * Copyright (C) 2012-2020 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 | |||
| * permission notice appear in all copies. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD | |||
| * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN | |||
| * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | |||
| * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER | |||
| * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | |||
| * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |||
| */ | |||
| #ifndef DISTRHO_UI_PRIVATE_DATA_HPP_INCLUDED | |||
| #define DISTRHO_UI_PRIVATE_DATA_HPP_INCLUDED | |||
| #include "../DistrhoUI.hpp" | |||
| START_NAMESPACE_DISTRHO | |||
| // ----------------------------------------------------------------------- | |||
| // Static data, see DistrhoUI.cpp | |||
| extern double d_lastUiSampleRate; | |||
| extern void* d_lastUiDspPtr; | |||
| // ----------------------------------------------------------------------- | |||
| // UI callbacks | |||
| 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 (*setSizeFunc) (void* ptr, uint width, uint height); | |||
| typedef bool (*fileRequestFunc) (void* ptr, const char* key); | |||
| // ----------------------------------------------------------------------- | |||
| // UI private data | |||
| struct UI::PrivateData { | |||
| // DSP | |||
| double sampleRate; | |||
| uint32_t parameterOffset; | |||
| #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS | |||
| void* dspPtr; | |||
| #endif | |||
| // UI | |||
| bool automaticallyScale; | |||
| bool resizeInProgress; | |||
| uint minWidth; | |||
| uint minHeight; | |||
| uint bgColor; | |||
| uint fgColor; | |||
| // Callbacks | |||
| void* callbacksPtr; | |||
| editParamFunc editParamCallbackFunc; | |||
| setParamFunc setParamCallbackFunc; | |||
| setStateFunc setStateCallbackFunc; | |||
| sendNoteFunc sendNoteCallbackFunc; | |||
| setSizeFunc setSizeCallbackFunc; | |||
| fileRequestFunc fileRequestCallbackFunc; | |||
| PrivateData() noexcept | |||
| : sampleRate(d_lastUiSampleRate), | |||
| parameterOffset(0), | |||
| #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS | |||
| dspPtr(d_lastUiDspPtr), | |||
| #endif | |||
| automaticallyScale(false), | |||
| resizeInProgress(false), | |||
| minWidth(0), | |||
| minHeight(0), | |||
| bgColor(0), | |||
| fgColor(0), | |||
| callbacksPtr(nullptr), | |||
| editParamCallbackFunc(nullptr), | |||
| setParamCallbackFunc(nullptr), | |||
| setStateCallbackFunc(nullptr), | |||
| sendNoteCallbackFunc(nullptr), | |||
| setSizeCallbackFunc(nullptr), | |||
| fileRequestCallbackFunc(nullptr) | |||
| { | |||
| DISTRHO_SAFE_ASSERT(d_isNotZero(sampleRate)); | |||
| #if defined(DISTRHO_PLUGIN_TARGET_DSSI) || defined(DISTRHO_PLUGIN_TARGET_LV2) | |||
| parameterOffset += DISTRHO_PLUGIN_NUM_INPUTS + DISTRHO_PLUGIN_NUM_OUTPUTS; | |||
| # if DISTRHO_PLUGIN_WANT_LATENCY | |||
| parameterOffset += 1; | |||
| # endif | |||
| #endif | |||
| #ifdef DISTRHO_PLUGIN_TARGET_LV2 | |||
| # if (DISTRHO_PLUGIN_IS_SYNTH || DISTRHO_PLUGIN_WANT_TIMEPOS || DISTRHO_PLUGIN_WANT_STATE) | |||
| parameterOffset += 1; | |||
| # if DISTRHO_PLUGIN_WANT_STATE | |||
| parameterOffset += 1; | |||
| # endif | |||
| # endif | |||
| #endif | |||
| } | |||
| void editParamCallback(const uint32_t rindex, const bool started) | |||
| { | |||
| if (editParamCallbackFunc != nullptr) | |||
| editParamCallbackFunc(callbacksPtr, rindex, started); | |||
| } | |||
| void setParamCallback(const uint32_t rindex, const float value) | |||
| { | |||
| if (setParamCallbackFunc != nullptr) | |||
| setParamCallbackFunc(callbacksPtr, rindex, value); | |||
| } | |||
| void setStateCallback(const char* const key, const char* const value) | |||
| { | |||
| if (setStateCallbackFunc != nullptr) | |||
| setStateCallbackFunc(callbacksPtr, key, value); | |||
| } | |||
| void sendNoteCallback(const uint8_t channel, const uint8_t note, const uint8_t velocity) | |||
| { | |||
| if (sendNoteCallbackFunc != nullptr) | |||
| sendNoteCallbackFunc(callbacksPtr, channel, note, velocity); | |||
| } | |||
| void setSizeCallback(const uint width, const uint height) | |||
| { | |||
| if (setSizeCallbackFunc != nullptr) | |||
| setSizeCallbackFunc(callbacksPtr, width, height); | |||
| } | |||
| bool fileRequestCallback(const char* key) | |||
| { | |||
| if (fileRequestCallbackFunc != nullptr) | |||
| return fileRequestCallbackFunc(callbacksPtr, key); | |||
| // TODO use old style DPF dialog here | |||
| return false; | |||
| } | |||
| }; | |||
| // ----------------------------------------------------------------------- | |||
| END_NAMESPACE_DISTRHO | |||
| #endif // DISTRHO_UI_PRIVATE_DATA_HPP_INCLUDED | |||