Browse Source

Give up on real external UIs, use pugl stub instead

Signed-off-by: falkTX <falktx@falktx.com>
pull/457/head
falkTX 1 year ago
parent
commit
3a3885e2bc
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
20 changed files with 92 additions and 608 deletions
  1. +1
    -4
      CMakeLists.txt
  2. +3
    -3
      Makefile
  3. +13
    -12
      Makefile.plugins.mk
  4. +2
    -1
      dgl/Makefile
  5. +2
    -0
      dgl/Widget.hpp
  6. +3
    -52
      distrho/DistrhoUI.hpp
  7. +1
    -1
      distrho/DistrhoUI_macOS.mm
  8. +2
    -2
      distrho/extra/WebViewImpl.hpp
  9. +3
    -3
      distrho/src/DistrhoPluginCLAP.cpp
  10. +18
    -36
      distrho/src/DistrhoPluginChecks.h
  11. +3
    -3
      distrho/src/DistrhoPluginLV2export.cpp
  12. +3
    -13
      distrho/src/DistrhoPluginVST.hpp
  13. +2
    -10
      distrho/src/DistrhoPluginVST2.cpp
  14. +8
    -74
      distrho/src/DistrhoUI.cpp
  15. +2
    -47
      distrho/src/DistrhoUIInternal.hpp
  16. +10
    -106
      distrho/src/DistrhoUIPrivateData.hpp
  17. +3
    -169
      distrho/src/DistrhoUIVST3.cpp
  18. +4
    -5
      examples/EmbedExternalUI/DistrhoPluginInfo.h
  19. +9
    -66
      examples/EmbedExternalUI/EmbedExternalExampleUI.cpp
  20. +0
    -1
      examples/SendNote/DistrhoPluginInfo.h

+ 1
- 4
CMakeLists.txt View File

@@ -48,10 +48,7 @@ if(DPF_EXAMPLES)
add_subdirectory("examples/CairoUI")
endif()
endif()
if((NOT WIN32) AND (NOT APPLE))
add_subdirectory("examples/ExternalUI")
endif()
add_subdirectory("examples/EmbedExternalUI")
#add_subdirectory("examples/EmbedExternalUI")
add_subdirectory("examples/FileHandling")
add_subdirectory("examples/Info")
add_subdirectory("examples/Latency")


+ 3
- 3
Makefile View File

@@ -35,9 +35,9 @@ examples: dgl
ifeq ($(HAVE_CAIRO),true)
$(MAKE) all -C examples/CairoUI
endif
ifeq ($(HAVE_DGL),true)
$(MAKE) all -C examples/EmbedExternalUI
endif
# ifeq ($(HAVE_DGL),true)
# $(MAKE) all -C examples/EmbedExternalUI
# endif

ifeq ($(CAN_GENERATE_TTL),true)
gen: examples utils/lv2_ttl_generator


+ 13
- 12
Makefile.plugins.mk View File

@@ -185,6 +185,9 @@ ifeq ($(HAVE_OPENGL),true)
UI_TYPE = opengl
else ifeq ($(HAVE_CAIRO),true)
UI_TYPE = cairo
else
HAVE_DGL = false
UI_TYPE = none
endif
endif

@@ -236,20 +239,11 @@ HAVE_DGL = false
endif
endif

ifeq ($(UI_TYPE),web)
DGL_FLAGS += -DDGL_WEB -DHAVE_DGL
DGL_LIB = $(DGL_BUILD_DIR)/libdgl-web.a
HAVE_DGL = true
USE_WEBVIEW = true
endif

ifeq ($(UI_TYPE),external)
DGL_FLAGS += -DDGL_EXTERNAL
HAVE_DGL = true
endif

ifeq ($(UI_TYPE),stub)
DGL_FLAGS += -DDGL_EXTERNAL -DHAVE_DGL
ifeq ($(HAVE_STUB),true)
DGL_FLAGS += $(STUB_FLAGS)
DGL_LIBS += $(STUB_LIBS)
DGL_LIB = $(DGL_BUILD_DIR)/libdgl-stub.a
HAVE_DGL = true
else
@@ -257,6 +251,13 @@ HAVE_DGL = false
endif
endif

ifeq ($(UI_TYPE),web)
DGL_FLAGS += -DDGL_WEB -DHAVE_DGL
DGL_LIB = $(DGL_BUILD_DIR)/libdgl-stub.a
HAVE_DGL = true
USE_WEBVIEW = true
endif

ifeq ($(HAVE_DGL)$(LINUX)$(USE_WEBVIEW),truetruetrue)
DGL_LIB_SHARED = $(shell $(CC) -print-file-name=Scrt1.o)
endif


+ 2
- 1
dgl/Makefile View File

@@ -91,7 +91,8 @@ endif

# ---------------------------------------------------------------------------------------------------------------------

OBJS_stub = $(OBJS_common)
OBJS_stub = $(OBJS_common) \
$(BUILD_DIR)/dgl/Stub.cpp.o

ifeq ($(MACOS),true)
OBJS_stub += $(BUILD_DIR)/dgl/pugl.mm.o


+ 2
- 0
dgl/Widget.hpp View File

@@ -404,10 +404,12 @@ public:
Window& getParentWindow() const noexcept { return getWindow(); }

protected:
#if defined(DGL_CAIRO) || defined(DGL_OPENGL) || defined(DGL_VULKAN)
/**
A function called to draw the widget contents.
*/
virtual void onDisplay() = 0;
#endif

/**
A function called when a key is pressed or released.


+ 3
- 52
distrho/DistrhoUI.hpp View File

@@ -31,11 +31,7 @@
# include "Vulkan.hpp"
#endif

#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
# include "../dgl/Base.hpp"
# include "extra/ExternalWindow.hpp"
typedef DISTRHO_NAMESPACE::ExternalWindow UIWidget;
#elif DISTRHO_UI_USE_CUSTOM
#if DISTRHO_UI_USE_CUSTOM
# include DISTRHO_UI_CUSTOM_INCLUDE_PATH
typedef DISTRHO_UI_CUSTOM_WIDGET_TYPE UIWidget;
#elif DISTRHO_UI_USE_CAIRO
@@ -44,9 +40,6 @@ typedef DGL_NAMESPACE::CairoTopLevelWidget UIWidget;
#elif DISTRHO_UI_USE_NANOVG
# include "../dgl/NanoVG.hpp"
typedef DGL_NAMESPACE::NanoTopLevelWidget UIWidget;
#elif DISTRHO_UI_USE_WEBVIEW
# include "../dgl/Web.hpp"
typedef DGL_NAMESPACE::WebViewWidget UIWidget;
#else
# include "../dgl/TopLevelWidget.hpp"
typedef DGL_NAMESPACE::TopLevelWidget UIWidget;
@@ -55,9 +48,8 @@ typedef DGL_NAMESPACE::TopLevelWidget UIWidget;
#if DISTRHO_UI_FILE_BROWSER
# include "extra/FileBrowserDialog.hpp"
#endif
#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
# include <vector>
#endif

#include <vector>

START_NAMESPACE_DISTRHO

@@ -217,34 +209,6 @@ public:
void* getPluginInstancePointer() const noexcept;
#endif

#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
/* --------------------------------------------------------------------------------------------------------
* External UI helpers */

/**
Get the bundle path that will be used for the next UI.
@note: This function is only valid during createUI(),
it will return null when called from anywhere else.
*/
static const char* getNextBundlePath() noexcept;

/**
Get the scale factor that will be used for the next UI.
@note: This function is only valid during createUI(),
it will return 1.0 when called from anywhere else.
*/
static double getNextScaleFactor() noexcept;

# if DISTRHO_PLUGIN_HAS_EMBED_UI
/**
Get the Window Id that will be used for the next created window.
@note: This function is only valid during createUI(),
it will return 0 when called from anywhere else.
*/
static uintptr_t getNextWindowId() noexcept;
# endif
#endif

protected:
/* --------------------------------------------------------------------------------------------------------
* DSP/Plugin Callbacks */
@@ -300,7 +264,6 @@ protected:
*/
virtual void uiScaleFactorChanged(double scaleFactor);

#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
/**
Get the types available for the data in a clipboard.
Must only be called within the context of uiClipboardDataOffer.
@@ -337,7 +300,6 @@ protected:
The most common exception is custom OpenGL setup, but only really needed for custom OpenGL drawing code.
*/
virtual void uiReshape(uint width, uint height);
#endif // !DISTRHO_PLUGIN_HAS_EXTERNAL_UI

#if DISTRHO_UI_FILE_BROWSER
/**
@@ -355,21 +317,12 @@ protected:
/* --------------------------------------------------------------------------------------------------------
* UI Resize Handling, internal */

#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
/**
External Window resize function, called when the window is resized.
This is overriden here so the host knows when the UI is resized by you.
@see ExternalWindow::sizeChanged(uint,uint)
*/
void sizeChanged(uint width, uint height) override;
#else
/**
Widget resize function, called when the widget is resized.
This is overriden here so the host knows when the UI is resized by you.
@see Widget::onResize(const ResizeEvent&)
*/
void onResize(const ResizeEvent& ev) override;
#endif

// -------------------------------------------------------------------------------------------------------

@@ -378,10 +331,8 @@ private:
PrivateData* const uiData;
friend class PluginWindow;
friend class UIExporter;
#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
/** @internal */
void requestSizeChange(uint width, uint height) override;
#endif

DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(UI)
};


+ 1
- 1
distrho/DistrhoUI_macOS.mm View File

@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2024 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


+ 2
- 2
distrho/extra/WebViewImpl.hpp View File

@@ -18,8 +18,8 @@
# error bad include
#endif

#if defined(DISTRHO_UI_USE_WEBVIEW) && DISTRHO_UI_USE_WEBVIEW == 0
# error To use WebViews in DPF plugins please set DISTRHO_UI_USE_WEBVIEW to 1
#if defined(DISTRHO_UI_WEB_VIEW) && DISTRHO_UI_WEB_VIEW == 0
# error To use WebViews in DPF plugins please set DISTRHO_UI_WEB_VIEW to 1
#endif

// --------------------------------------------------------------------------------------------------------------------


+ 3
- 3
distrho/src/DistrhoPluginCLAP.cpp View File

@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2023 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2024 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
@@ -29,7 +29,7 @@
# error DISTRHO_PLUGIN_CLAP_ID undefined!
#endif

#if DISTRHO_PLUGIN_HAS_UI && ! defined(HAVE_DGL) && ! DISTRHO_PLUGIN_HAS_EXTERNAL_UI
#if DISTRHO_PLUGIN_HAS_UI && ! defined(HAVE_DGL)
# undef DISTRHO_PLUGIN_HAS_UI
# define DISTRHO_PLUGIN_HAS_UI 0
#endif
@@ -57,7 +57,7 @@
#include "clap/ext/thread-check.h"
#include "clap/ext/timer-support.h"

#if (defined(DISTRHO_OS_MAC) || defined(DISTRHO_OS_WINDOWS)) && ! DISTRHO_PLUGIN_HAS_EXTERNAL_UI
#if defined(DISTRHO_OS_MAC) || defined(DISTRHO_OS_WINDOWS)
# define DPF_CLAP_USING_HOST_TIMER 0
#else
# define DPF_CLAP_USING_HOST_TIMER 1


+ 18
- 36
distrho/src/DistrhoPluginChecks.h View File

@@ -49,10 +49,6 @@
# define DISTRHO_PLUGIN_HAS_UI 0
#endif

#ifndef DISTRHO_PLUGIN_HAS_EXTERNAL_UI
# define DISTRHO_PLUGIN_HAS_EXTERNAL_UI 0
#endif

#ifndef DISTRHO_PLUGIN_IS_RT_SAFE
# define DISTRHO_PLUGIN_IS_RT_SAFE 0
#endif
@@ -110,6 +106,10 @@
# define DISTRHO_UI_USER_RESIZABLE 0
#endif

#ifndef DISTRHO_UI_USE_EXTERNAL
# define DISTRHO_UI_USE_EXTERNAL 0
#endif

#ifndef DISTRHO_UI_USE_NANOVG
# define DISTRHO_UI_USE_NANOVG 0
#endif
@@ -118,17 +118,6 @@
# define DISTRHO_UI_USE_WEBVIEW 0
#endif

// --------------------------------------------------------------------------------------------------------------------
// Define DISTRHO_PLUGIN_HAS_EMBED_UI if needed

#ifndef DISTRHO_PLUGIN_HAS_EMBED_UI
# if (defined(DGL_CAIRO) && defined(HAVE_CAIRO)) || (defined(DGL_OPENGL) && defined(HAVE_OPENGL)) || defined(DGL_WEB)
# define DISTRHO_PLUGIN_HAS_EMBED_UI 1
# else
# define DISTRHO_PLUGIN_HAS_EMBED_UI 0
# endif
#endif

// --------------------------------------------------------------------------------------------------------------------
// Define DISTRHO_UI_WEB_VIEW if needed

@@ -147,16 +136,20 @@
// --------------------------------------------------------------------------------------------------------------------
// Test for wrong compiler macros

#if defined(DGL_CAIRO) && defined(DGL_OPENGL)
# error invalid build config: trying to build for both cairo and opengl at the same time
#if defined(DISTRHO_PLUGIN_HAS_EXTERNAL_UI)
# error DISTRHO_PLUGIN_HAS_EXTERNAL_UI has been replaced by DISTRHO_UI_USE_EXTERNAL
#endif

#if defined(DGL_CAIRO) && DISTRHO_PLUGIN_HAS_EXTERNAL_UI
# error invalid build config: trying to build cairo while using external UI
#if defined(DISTRHO_PLUGIN_HAS_EMBED_UI)
# warning DISTRHO_PLUGIN_HAS_EMBED_UI has been removed, it is now always on
#endif

#if defined(DGL_OPENGL) && DISTRHO_PLUGIN_HAS_EXTERNAL_UI
# error invalid build config: trying to build opengl while using external UI
#if defined(DGL_CAIRO) && defined(DGL_OPENGL)
# error invalid build config: trying to build for both cairo and opengl at the same time
#elif defined(DGL_EXTERNAL) && defined(DGL_CAIRO)
# error invalid build config: trying to build for both external and cairo at the same time
#elif defined(DGL_EXTERNAL) && defined(DGL_OPENGL)
# error invalid build config: trying to build for both external and opengl at the same time
#endif

#if DISTRHO_UI_FILE_BROWSER && defined(DGL_FILE_BROWSER_DISABLED)
@@ -205,25 +198,14 @@
#endif

// --------------------------------------------------------------------------------------------------------------------
// Disable file browser if using external UI

#if DISTRHO_UI_FILE_BROWSER && DISTRHO_PLUGIN_HAS_EXTERNAL_UI
# warning file browser APIs do not work for external UIs
# undef DISTRHO_UI_FILE_BROWSER 0
# define DISTRHO_UI_FILE_BROWSER 0
#endif

// --------------------------------------------------------------------------------------------------------------------
// Disable UI if DGL or external UI is not available
// Disable UI if DGL is not available

#if (defined(DGL_CAIRO) && ! defined(HAVE_CAIRO)) || (defined(DGL_OPENGL) && ! defined(HAVE_OPENGL))
# undef DISTRHO_PLUGIN_HAS_EMBED_UI
# define DISTRHO_PLUGIN_HAS_EMBED_UI 0
#endif

#if DISTRHO_PLUGIN_HAS_UI && ! DISTRHO_PLUGIN_HAS_EMBED_UI && ! DISTRHO_PLUGIN_HAS_EXTERNAL_UI
# undef DISTRHO_PLUGIN_HAS_UI
# define DISTRHO_PLUGIN_HAS_UI 0
# ifdef HAVE_DGL
# error HAVE_DGL is defined in a wrong configuration
# endif
#endif

// --------------------------------------------------------------------------------------------------------------------


+ 3
- 3
distrho/src/DistrhoPluginLV2export.cpp View File

@@ -74,7 +74,7 @@
# define DISTRHO_PLUGIN_USES_CUSTOM_MODGUI 0
#endif

#if DISTRHO_PLUGIN_HAS_EMBED_UI
#if DISTRHO_PLUGIN_HAS_UI
# if defined(DISTRHO_OS_HAIKU)
# define DISTRHO_LV2_UI_TYPE "BeUI"
# elif defined(DISTRHO_OS_MAC)
@@ -155,7 +155,7 @@ static constexpr const char* const lv2ManifestUiExtensionData[] = {
};

static constexpr const char* const lv2ManifestUiOptionalFeatures[] = {
#if DISTRHO_PLUGIN_HAS_EMBED_UI
#if DISTRHO_PLUGIN_HAS_UI
#if !DISTRHO_UI_USER_RESIZABLE
"ui:noUserResize",
#endif
@@ -1550,7 +1550,7 @@ void lv2_generate_ttl(const char* const basename)
stylesheetFile.close();
std::cout << " done!" << std::endl;
}
#endif // DISTRHO_PLUGIN_USES_MODGUI && DISTRHO_PLUGIN_HAS_EMBED_UI && !DISTRHO_PLUGIN_USES_CUSTOM_MODGUI
#endif // DISTRHO_PLUGIN_USES_MODGUI && !DISTRHO_PLUGIN_USES_CUSTOM_MODGUI

// ---------------------------------------------



+ 3
- 13
distrho/src/DistrhoPluginVST.hpp View File

@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2024 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
@@ -23,17 +23,7 @@
#include <algorithm>
#include <cmath>

#if DISTRHO_PLUGIN_HAS_UI && ! DISTRHO_PLUGIN_HAS_EMBED_UI
# undef DISTRHO_PLUGIN_HAS_UI
# define DISTRHO_PLUGIN_HAS_UI 0
#endif

#if DISTRHO_PLUGIN_HAS_UI && ! defined(HAVE_DGL) && ! DISTRHO_PLUGIN_HAS_EXTERNAL_UI
# undef DISTRHO_PLUGIN_HAS_UI
# define DISTRHO_PLUGIN_HAS_UI 0
#endif

#if DISTRHO_PLUGIN_HAS_UI && ! DISTRHO_PLUGIN_HAS_EXTERNAL_UI
#if DISTRHO_PLUGIN_HAS_UI
# include "Base.hpp"
#endif

@@ -224,7 +214,7 @@ void snprintf_u32_utf16(int16_t* const dst, const uint32_t value, const size_t s
return snprintf_utf16_t<uint32_t>(dst, value, "%u", size);
}

#if DISTRHO_PLUGIN_HAS_UI && ! DISTRHO_PLUGIN_HAS_EXTERNAL_UI
#if DISTRHO_PLUGIN_HAS_UI
// --------------------------------------------------------------------------------------------------------------------
// translate a vstgui-based key character and code to matching values used by DPF



+ 2
- 10
distrho/src/DistrhoPluginVST2.cpp View File

@@ -178,10 +178,8 @@ public:
nullptr, // TODO file request
d_nextBundlePath,
plugin->getInstancePointer(),
scaleFactor)
#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
, fKeyboardModifiers(0)
#endif
scaleFactor),
fKeyboardModifiers(0)
#if DISTRHO_PLUGIN_WANT_MIDI_INPUT
, fNotesRingBuffer()
#endif
@@ -242,7 +240,6 @@ public:
}
#endif

#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
int handlePluginKeyEvent(const bool down, const int32_t index, const intptr_t value)
{
d_stdout("handlePluginKeyEvent %i %i %li\n", down, index, (long int)value);
@@ -281,7 +278,6 @@ public:
value >= 0 ? static_cast<uint>(value) : 0,
fKeyboardModifiers) ? 1 : 0;
}
#endif // !DISTRHO_PLUGIN_HAS_EXTERNAL_UI

// ----------------------------------------------------------------------------------------------------------------

@@ -347,9 +343,7 @@ private:

// Plugin UI
UIExporter fUI;
#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
uint16_t fKeyboardModifiers;
#endif
#if DISTRHO_PLUGIN_WANT_MIDI_INPUT
RingBufferControl<SmallStackBuffer> fNotesRingBuffer;
#endif
@@ -678,7 +672,6 @@ public:
fVstUI->idle();
break;

#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
case VST_EFFECT_OPCODE_3B: // key down
if (fVstUI != nullptr)
return fVstUI->handlePluginKeyEvent(true, index, value);
@@ -688,7 +681,6 @@ public:
if (fVstUI != nullptr)
return fVstUI->handlePluginKeyEvent(false, index, value);
break;
#endif
#endif // DISTRHO_PLUGIN_HAS_UI

#if DISTRHO_PLUGIN_WANT_STATE


+ 8
- 74
distrho/src/DistrhoUI.cpp View File

@@ -60,7 +60,7 @@ END_NAMESPACE_DISTRHO
# include "../extra/FileBrowserDialogImpl.cpp"
#endif

#if DISTRHO_UI_USE_WEBVIEW && !defined(DISTRHO_OS_MAC)
#if DISTRHO_UI_WEB_VIEW && !defined(DISTRHO_OS_MAC)
# define DISTRHO_WEB_VIEW_HPP_INCLUDED
# define WEB_VIEW_NAMESPACE DISTRHO_NAMESPACE
# define WEB_VIEW_DISTRHO_NAMESPACE
@@ -70,11 +70,8 @@ END_NAMESPACE_DISTRHO
# include "../extra/WebViewImpl.cpp"
#endif

#if ! DISTRHO_PLUGIN_HAS_EXTERNAL_UI
# include "src/TopLevelWidgetPrivateData.hpp"
# include "src/WindowPrivateData.hpp"
#endif

#include "src/TopLevelWidgetPrivateData.hpp"
#include "src/WindowPrivateData.hpp"
#include "DistrhoUIPrivateData.hpp"

START_NAMESPACE_DISTRHO
@@ -82,11 +79,7 @@ START_NAMESPACE_DISTRHO
/* ------------------------------------------------------------------------------------------------------------
* Static data, see DistrhoUIInternal.hpp */

const char* g_nextBundlePath = nullptr;
#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
uintptr_t g_nextWindowId = 0;
double g_nextScaleFactor = 1.0;
#endif
const char* g_nextBundlePath = nullptr;

/* ------------------------------------------------------------------------------------------------------------
* get global scale factor */
@@ -177,12 +170,7 @@ static double getDesktopScaleFactor(const uintptr_t parentWindowHandle)

UI::PrivateData* UI::PrivateData::s_nextPrivateData = nullptr;

#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
ExternalWindow::PrivateData
#else
PluginWindow&
#endif
UI::PrivateData::createNextWindow(UI* const ui, uint width, uint height, const bool adjustForScaleFactor)
PluginWindow& UI::PrivateData::createNextWindow(UI* const ui, uint width, uint height, const bool adjustForScaleFactor)
{
UI::PrivateData* const pData = s_nextPrivateData;
const double scaleFactor = d_isNotZero(pData->scaleFactor) ? pData->scaleFactor : getDesktopScaleFactor(pData->winId);
@@ -193,17 +181,6 @@ UI::PrivateData::createNextWindow(UI* const ui, uint width, uint height, const b
height *= scaleFactor;
}

#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
pData->window = new PluginWindow(ui, pData->app);
ExternalWindow::PrivateData ewData;
ewData.parentWindowHandle = pData->winId;
ewData.width = width;
ewData.height = height;
ewData.scaleFactor = scaleFactor;
ewData.title = DISTRHO_PLUGIN_NAME;
ewData.isStandalone = DISTRHO_UI_IS_STANDALONE;
return ewData;
#else
d_stdout("createNextWindow %u %u %f %d", width, height, scaleFactor, adjustForScaleFactor);
pData->window = new PluginWindow(ui, pData->app, pData->winId, width, height, scaleFactor);

@@ -212,7 +189,6 @@ UI::PrivateData::createNextWindow(UI* const ui, uint width, uint height, const b
pData->window->setIgnoreIdleCallbacks();

return pData->window.getObject();
#endif
}

/* ------------------------------------------------------------------------------------------------------------
@@ -239,7 +215,6 @@ UI::UI(const uint width, const uint height, const bool automaticallyScaleAndSetA
)),
uiData(UI::PrivateData::s_nextPrivateData)
{
#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
if (width != 0 && height != 0)
{
Widget::setSize(width, height);
@@ -253,10 +228,6 @@ UI::UI(const uint width, const uint height, const bool automaticallyScaleAndSetA
Widget::setSize(DISTRHO_UI_DEFAULT_WIDTH, DISTRHO_UI_DEFAULT_HEIGHT);
}
#endif
#else
// unused
(void)automaticallyScaleAndSetAsMinimumSize;
#endif
}

UI::~UI()
@@ -268,15 +239,11 @@ UI::~UI()

bool UI::isResizable() const noexcept
{
#if DISTRHO_UI_USER_RESIZABLE
# if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
return true;
# else
#if DISTRHO_UI_USER_RESIZABLE
return uiData->window->isResizable();
# endif
#else
#else
return false;
#endif
#endif
}

uint UI::getBackgroundColor() const noexcept
@@ -347,28 +314,6 @@ void* UI::getPluginInstancePointer() const noexcept
}
#endif

#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
/* ------------------------------------------------------------------------------------------------------------
* External UI helpers (static calls) */

const char* UI::getNextBundlePath() noexcept
{
return g_nextBundlePath;
}

double UI::getNextScaleFactor() noexcept
{
return g_nextScaleFactor;
}

# if DISTRHO_PLUGIN_HAS_EMBED_UI
uintptr_t UI::getNextWindowId() noexcept
{
return g_nextWindowId;
}
# endif
#endif // DISTRHO_PLUGIN_HAS_EXTERNAL_UI

/* ------------------------------------------------------------------------------------------------------------
* DSP/Plugin Callbacks */

@@ -402,7 +347,6 @@ void UI::uiScaleFactorChanged(double)
{
}

#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
std::vector<DGL_NAMESPACE::ClipboardDataOffer> UI::getClipboardDataOfferTypes()
{
return uiData->window->getClipboardDataOfferTypes();
@@ -431,7 +375,6 @@ void UI::uiReshape(const uint width, const uint height)
// NOTE this must be the same as Window::onReshape
pData->fallbackOnResize(width, height);
}
#endif // !DISTRHO_PLUGIN_HAS_EXTERNAL_UI

#if DISTRHO_UI_FILE_BROWSER
void UI::uiFileBrowserSelected(const char*)
@@ -442,14 +385,6 @@ void UI::uiFileBrowserSelected(const char*)
/* ------------------------------------------------------------------------------------------------------------
* UI Resize Handling, internal */

#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
void UI::sizeChanged(const uint width, const uint height)
{
UIWidget::sizeChanged(width, height);

uiData->setSizeCallback(width, height);
}
#else
void UI::onResize(const ResizeEvent& ev)
{
UIWidget::onResize(ev);
@@ -478,7 +413,6 @@ void UI::requestSizeChange(const uint width, const uint height)
(void)height;
#endif
}
#endif

// -----------------------------------------------------------------------------------------------------------



+ 2
- 47
distrho/src/DistrhoUIInternal.hpp View File

@@ -25,10 +25,6 @@ START_NAMESPACE_DISTRHO
// Static data, see DistrhoUI.cpp

extern const char* g_nextBundlePath;
#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
extern uintptr_t g_nextWindowId;
extern double g_nextScaleFactor;
#endif

// -----------------------------------------------------------------------
// UI exporter class
@@ -79,41 +75,25 @@ public:
uiData->setSizeCallbackFunc = setSizeCall;
uiData->fileRequestCallbackFunc = fileRequestCall;

g_nextBundlePath = bundlePath;
#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
g_nextWindowId = winId;
g_nextScaleFactor = scaleFactor;
#endif
g_nextBundlePath = bundlePath;
UI::PrivateData::s_nextPrivateData = uiData;

UI* const uiPtr = createUI();

g_nextBundlePath = nullptr;
#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
g_nextWindowId = 0;
g_nextScaleFactor = 0.0;
#else
// enter context called in the PluginWindow constructor, see DistrhoUIPrivateData.hpp
uiData->window->leaveContext();
#endif
UI::PrivateData::s_nextPrivateData = nullptr;

DISTRHO_SAFE_ASSERT_RETURN(uiPtr != nullptr,);
ui = uiPtr;
uiData->initializing = false;

#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
// unused
(void)bundlePath;
#endif
}

~UIExporter()
{
quit();
#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
uiData->window->enterContextForDeletion();
#endif
delete ui;
delete uiData;
}
@@ -137,13 +117,9 @@ public:

bool getGeometryConstraints(uint& minimumWidth, uint& minimumHeight, bool& keepAspectRatio) const noexcept
{
#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
uiData->window->getGeometryConstraints(minimumWidth, minimumHeight, keepAspectRatio);
#else
const DGL_NAMESPACE::Size<uint> size(uiData->window->getGeometryConstraints(keepAspectRatio));
minimumWidth = size.getWidth();
minimumHeight = size.getHeight();
#endif
return true;
}

@@ -263,16 +239,14 @@ public:
uiData->app.quit();
}

#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
void repaint()
{
uiData->window->repaint();
}
#endif

// -------------------------------------------------------------------

#if defined(DISTRHO_OS_MAC) || defined(DISTRHO_OS_WINDOWS)
#if defined(DISTRHO_OS_MAC) || defined(DISTRHO_OS_WINDOWS)
void idleFromNativeIdle()
{
DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr,);
@@ -282,7 +256,6 @@ public:
uiData->app.repaintIfNeeeded();
}

#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
void addIdleCallbackForNativeIdle(IdleCallback* const cb, const uint timerFrequencyInMs)
{
uiData->window->addIdleCallback(cb, timerFrequencyInMs);
@@ -293,28 +266,18 @@ public:
uiData->window->removeIdleCallback(cb);
}
#endif
#endif

// -------------------------------------------------------------------

void setWindowOffset(const int x, const int y)
{
#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
// TODO
(void)x; (void)y;
#else
uiData->window->setOffset(x, y);
#endif
}

#if DISTRHO_UI_USES_SIZE_REQUEST
void setWindowSizeFromHost(const uint width, const uint height)
{
#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
ui->setSize(width, height);
#else
uiData->window->setSizeFromHost(width, height);
#endif
}
#endif

@@ -325,11 +288,7 @@ public:

void setWindowTransientWinId(const uintptr_t transientParentWindowHandle)
{
#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
ui->setTransientWindowId(transientParentWindowHandle);
#else
uiData->window->setTransientParent(transientParentWindowHandle);
#endif
}

bool setWindowVisible(const bool yesNo)
@@ -339,7 +298,6 @@ public:
return ! uiData->app.isQuitting();
}

#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
bool handlePluginKeyboardVST(const bool press, const bool special, const uint keychar, const uint keycode, const uint16_t mods)
{
using namespace DGL_NAMESPACE;
@@ -372,7 +330,6 @@ public:

return ret;
}
#endif

// -------------------------------------------------------------------

@@ -383,14 +340,12 @@ public:
ui->uiScaleFactorChanged(scaleFactor);
}

#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
void notifyFocusChanged(const bool focus)
{
DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr,);

ui->uiFocus(focus, DGL_NAMESPACE::kCrossingNormal);
}
#endif

void setSampleRate(const double sampleRate, const bool doCallback = false)
{


+ 10
- 106
distrho/src/DistrhoUIPrivateData.hpp View File

@@ -23,16 +23,11 @@
# include "DistrhoPluginVST.hpp"
#endif

#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
# include "../extra/Sleep.hpp"
// TODO import and use file browser here
#else
# include "../../dgl/src/ApplicationPrivateData.hpp"
# include "../../dgl/src/WindowPrivateData.hpp"
# include "../../dgl/src/pugl.hpp"
#endif
#include "../../dgl/src/ApplicationPrivateData.hpp"
#include "../../dgl/src/WindowPrivateData.hpp"
#include "../../dgl/src/pugl.hpp"

#if DISTRHO_PLUGIN_WANT_STATE && DISTRHO_UI_FILE_BROWSER && !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
#if DISTRHO_PLUGIN_WANT_STATE && DISTRHO_UI_FILE_BROWSER
# include <map>
# include <string>
#endif
@@ -65,55 +60,6 @@ START_NAMESPACE_DISTRHO
// -----------------------------------------------------------------------
// Plugin Application, will set class name based on plugin details

#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
struct PluginApplication
{
DGL_NAMESPACE::IdleCallback* idleCallback;
UI* ui;

explicit PluginApplication(const char*)
: idleCallback(nullptr),
ui(nullptr) {}

void addIdleCallback(DGL_NAMESPACE::IdleCallback* const cb)
{
DISTRHO_SAFE_ASSERT_RETURN(cb != nullptr,);
DISTRHO_SAFE_ASSERT_RETURN(idleCallback == nullptr,);

idleCallback = cb;
}

bool isQuitting() const noexcept
{
return ui->isQuitting();
}

bool isStandalone() const noexcept
{
return DISTRHO_UI_IS_STANDALONE;
}

void exec()
{
while (ui->isRunning())
{
d_msleep(30);
idleCallback->idleCallback();
}

if (! ui->isQuitting())
ui->close();
}

// these are not needed
void idle() {}
void quit() {}
void triggerIdleCallbacks() {}
void repaintIfNeeeded() {}

DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PluginApplication)
};
#else
class PluginApplication : public DGL_NAMESPACE::Application
{
public:
@@ -151,47 +97,10 @@ public:

DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PluginApplication)
};
#endif

// -----------------------------------------------------------------------
// Plugin Window, will pass some Window events to UI

#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
class PluginWindow
{
UI* const ui;

public:
explicit PluginWindow(UI* const uiPtr, PluginApplication& app)
: ui(uiPtr)
{
app.ui = ui;
}

// fetch cached data
uint getWidth() const noexcept { return ui->pData.width; }
uint getHeight() const noexcept { return ui->pData.height; }
double getScaleFactor() const noexcept { return ui->pData.scaleFactor; }

// direct mappings
void close() { ui->close(); }
void focus() { ui->focus(); }
void show() { ui->show(); }
bool isResizable() const noexcept { return ui->isResizable(); }
bool isVisible() const noexcept { return ui->isVisible(); }
void setTitle(const char* const title) { ui->setTitle(title); }
void setVisible(const bool visible) { ui->setVisible(visible); }
uintptr_t getNativeWindowHandle() const noexcept { return ui->getNativeWindowHandle(); }
void getGeometryConstraints(uint& minimumWidth, uint& minimumHeight, bool& keepAspectRatio) const noexcept
{
minimumWidth = ui->pData.minWidth;
minimumHeight = ui->pData.minHeight;
keepAspectRatio = ui->pData.keepAspectRatio;
}

DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PluginWindow)
};
#else // DISTRHO_PLUGIN_HAS_EXTERNAL_UI
class PluginWindow : public DGL_NAMESPACE::Window
{
UI* const ui;
@@ -320,7 +229,6 @@ protected:

DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PluginWindow)
};
#endif // DISTRHO_PLUGIN_HAS_EXTERNAL_UI

// -----------------------------------------------------------------------
// UI callbacks
@@ -350,7 +258,7 @@ struct UI::PrivateData {
uint fgColor;
double scaleFactor;
uintptr_t winId;
#if DISTRHO_PLUGIN_WANT_STATE && DISTRHO_UI_FILE_BROWSER && !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
#if DISTRHO_PLUGIN_WANT_STATE && DISTRHO_UI_FILE_BROWSER
char* uiStateFileKeyRequest;
std::map<std::string,std::string> lastUsedDirnames;
#endif
@@ -378,7 +286,7 @@ struct UI::PrivateData {
fgColor(0xffffffff),
scaleFactor(1.0),
winId(0),
#if DISTRHO_PLUGIN_WANT_STATE && DISTRHO_UI_FILE_BROWSER && !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
#if DISTRHO_PLUGIN_WANT_STATE && DISTRHO_UI_FILE_BROWSER
uiStateFileKeyRequest(nullptr),
#endif
bundlePath(nullptr),
@@ -414,7 +322,7 @@ struct UI::PrivateData {

~PrivateData() noexcept
{
#if DISTRHO_PLUGIN_WANT_STATE && DISTRHO_UI_FILE_BROWSER && !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
#if DISTRHO_PLUGIN_WANT_STATE && DISTRHO_UI_FILE_BROWSER
std::free(uiStateFileKeyRequest);
#endif
std::free(bundlePath);
@@ -454,11 +362,7 @@ struct UI::PrivateData {
bool fileRequestCallback(const char* const key);

static UI::PrivateData* s_nextPrivateData;
#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
static ExternalWindow::PrivateData createNextWindow(UI* ui, uint width, uint height, bool adjustForScaleFactor);
#else
static PluginWindow& createNextWindow(UI* ui, uint width, uint height, bool adjustForScaleFactor);
#endif
};

// -----------------------------------------------------------------------
@@ -469,7 +373,7 @@ inline bool UI::PrivateData::fileRequestCallback(const char* const key)
if (fileRequestCallbackFunc != nullptr)
return fileRequestCallbackFunc(callbacksPtr, key);

#if DISTRHO_PLUGIN_WANT_STATE && DISTRHO_UI_FILE_BROWSER && !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
#if DISTRHO_PLUGIN_WANT_STATE && DISTRHO_UI_FILE_BROWSER
std::free(uiStateFileKeyRequest);
uiStateFileKeyRequest = strdup(key);
DISTRHO_SAFE_ASSERT_RETURN(uiStateFileKeyRequest != nullptr, false);
@@ -491,7 +395,7 @@ inline bool UI::PrivateData::fileRequestCallback(const char* const key)
// -----------------------------------------------------------------------
// PluginWindow onFileSelected that require UI::PrivateData definitions

#if DISTRHO_UI_FILE_BROWSER && !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
#if DISTRHO_UI_FILE_BROWSER
inline void PluginWindow::onFileSelected(const char* const filename)
{
DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr,);
@@ -499,7 +403,7 @@ inline void PluginWindow::onFileSelected(const char* const filename)
if (initializing)
return;

#if DISTRHO_PLUGIN_WANT_STATE && DISTRHO_UI_FILE_BROWSER && !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
#if DISTRHO_PLUGIN_WANT_STATE
if (char* const key = ui->uiData->uiStateFileKeyRequest)
{
ui->uiData->uiStateFileKeyRequest = nullptr;


+ 3
- 169
distrho/src/DistrhoUIVST3.cpp View File

@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2024 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
@@ -21,15 +21,6 @@
#include "travesty/host.h"
#include "travesty/view.h"

#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
# if defined(DISTRHO_OS_MAC)
# include <CoreFoundation/CoreFoundation.h>
# elif defined(DISTRHO_OS_WINDOWS)
# include <winuser.h>
# define DPF_VST3_WIN32_TIMER_ID 1
# endif
#endif

/* TODO items:
* - mousewheel event
* - file request?
@@ -110,7 +101,6 @@ static void applyGeometryConstraints(const uint minimumWidth,

// --------------------------------------------------------------------------------------------------------------------

#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
static uint translateVST3Modifiers(const int64_t modifiers) noexcept
{
using namespace DGL_NAMESPACE;
@@ -134,115 +124,9 @@ static uint translateVST3Modifiers(const int64_t modifiers) noexcept

return dglmods;
}
#endif

// --------------------------------------------------------------------------------------------------------------------

#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI && !DPF_VST3_USING_HOST_RUN_LOOP
/**
* Helper class for getting a native idle timer via native APIs.
*/
class NativeIdleHelper
{
public:
NativeIdleHelper(IdleCallback* const callback)
: fCallback(callback),
#ifdef DISTRHO_OS_MAC
fTimerRef(nullptr)
#else
fTimerWindow(nullptr),
fTimerWindowClassName()
#endif
{
}

void registerNativeIdleCallback()
{
#ifdef DISTRHO_OS_MAC
constexpr const CFTimeInterval interval = DPF_VST3_TIMER_INTERVAL * 0.0001;

CFRunLoopTimerContext context = {};
context.info = this;
fTimerRef = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + interval, interval, 0, 0,
platformIdleTimerCallback, &context);
DISTRHO_SAFE_ASSERT_RETURN(fTimerRef != nullptr,);

CFRunLoopAddTimer(CFRunLoopGetCurrent(), fTimerRef, kCFRunLoopCommonModes);
#else
/*
* Create an invisible window to handle a timer.
* There is no need for implementing a window proc because DefWindowProc already calls the
* callback function when processing WM_TIMER messages.
*/
fTimerWindowClassName = (
#ifdef DISTRHO_PLUGIN_BRAND
DISTRHO_PLUGIN_BRAND
#else
DISTRHO_MACRO_AS_STRING(DISTRHO_NAMESPACE)
#endif
"-" DISTRHO_PLUGIN_NAME "-"
);

char suffix[9];
std::snprintf(suffix, sizeof(suffix), "%08x", std::rand());
suffix[sizeof(suffix)-1] = '\0';
fTimerWindowClassName += suffix;

WNDCLASSEX cls;
ZeroMemory(&cls, sizeof(cls));
cls.cbSize = sizeof(WNDCLASSEX);
cls.cbWndExtra = sizeof(LONG_PTR);
cls.lpszClassName = fTimerWindowClassName.buffer();
cls.lpfnWndProc = DefWindowProc;
RegisterClassEx(&cls);

fTimerWindow = CreateWindowEx(0, cls.lpszClassName, "DPF Timer Helper",
0, 0, 0, 0, 0, HWND_MESSAGE, nullptr, nullptr, nullptr);
DISTRHO_SAFE_ASSERT_RETURN(fTimerWindow != nullptr,);

SetWindowLongPtr(fTimerWindow, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(static_cast<void*>(this)));
SetTimer(fTimerWindow, DPF_VST3_WIN32_TIMER_ID, DPF_VST3_TIMER_INTERVAL,
static_cast<TIMERPROC>(platformIdleTimerCallback));
#endif
}

void unregisterNativeIdleCallback()
{
#ifdef DISTRHO_OS_MAC
CFRunLoopRemoveTimer(CFRunLoopGetCurrent(), fTimerRef, kCFRunLoopCommonModes);
CFRelease(fTimerRef);
#else
DISTRHO_SAFE_ASSERT_RETURN(fTimerWindow != nullptr,);
KillTimer(fTimerWindow, DPF_VST3_WIN32_TIMER_ID);
DestroyWindow(fTimerWindow);
UnregisterClass(fTimerWindowClassName, nullptr);
#endif
}

private:
IdleCallback* const fCallback;

#ifdef DISTRHO_OS_MAC
CFRunLoopTimerRef fTimerRef;

static void platformIdleTimerCallback(CFRunLoopTimerRef, void* const info)
{
static_cast<NativeIdleHelper*>(info)->fCallback->idleCallback();
}
#else
HWND fTimerWindow;
String fTimerWindowClassName;

static void WINAPI platformIdleTimerCallback(const HWND hwnd, UINT, UINT_PTR, DWORD)
{
reinterpret_cast<NativeIdleHelper*>(GetWindowLongPtr(hwnd, GWLP_USERDATA))->fCallback->idleCallback();
}
#endif
};
#endif

/**
* Helper class for getting a native idle timer, either through pugl or via native APIs.
* Helper class for getting a native idle timer.
*/
#if !DPF_VST3_USING_HOST_RUN_LOOP
class NativeIdleCallback : public IdleCallback
@@ -250,49 +134,25 @@ class NativeIdleCallback : public IdleCallback
public:
NativeIdleCallback(UIExporter& ui)
: fCallbackRegistered(false),
#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
fIdleHelper(this)
#else
fUI(ui)
#endif
{
#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
// unused
(void)ui;
#endif
}
fUI(ui) {}

void registerNativeIdleCallback()
{
DISTRHO_SAFE_ASSERT_RETURN(!fCallbackRegistered,);
fCallbackRegistered = true;

#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
fIdleHelper.registerNativeIdleCallback();
#else
fUI.addIdleCallbackForNativeIdle(this, DPF_VST3_TIMER_INTERVAL);
#endif
}

void unregisterNativeIdleCallback()
{
DISTRHO_SAFE_ASSERT_RETURN(fCallbackRegistered,);
fCallbackRegistered = false;

#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
fIdleHelper.unregisterNativeIdleCallback();
#else
fUI.removeIdleCallbackForNativeIdle(this);
#endif
}

private:
bool fCallbackRegistered;
#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
NativeIdleHelper fIdleHelper;
#else
UIExporter& fUI;
#endif
};
#endif

@@ -392,7 +252,6 @@ public:
// ----------------------------------------------------------------------------------------------------------------
// v3_plugin_view interface calls

#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
v3_result onWheel(float /*distance*/)
{
// TODO
@@ -432,7 +291,6 @@ public:
fUI.notifyFocusChanged(state);
return V3_OK;
}
#endif

v3_result getSize(v3_view_rect* const rect) const noexcept
{
@@ -1464,7 +1322,6 @@ struct dpf_plugin_view : v3_plugin_view_cpp {

static v3_result V3_API on_wheel(void* const self, const float distance)
{
#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
d_debug("dpf_plugin_view::on_wheel => %p %f", self, distance);
dpf_plugin_view* const view = *static_cast<dpf_plugin_view**>(self);

@@ -1472,16 +1329,10 @@ struct dpf_plugin_view : v3_plugin_view_cpp {
DISTRHO_SAFE_ASSERT_RETURN(uivst3 != nullptr, V3_NOT_INITIALIZED);

return uivst3->onWheel(distance);
#else
return V3_NOT_IMPLEMENTED;
// unused
(void)self; (void)distance;
#endif
}

static v3_result V3_API on_key_down(void* const self, const int16_t key_char, const int16_t key_code, const int16_t modifiers)
{
#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
d_debug("dpf_plugin_view::on_key_down => %p %i %i %i", self, key_char, key_code, modifiers);
dpf_plugin_view* const view = *static_cast<dpf_plugin_view**>(self);

@@ -1489,16 +1340,10 @@ struct dpf_plugin_view : v3_plugin_view_cpp {
DISTRHO_SAFE_ASSERT_RETURN(uivst3 != nullptr, V3_NOT_INITIALIZED);

return uivst3->onKeyDown(key_char, key_code, modifiers);
#else
return V3_NOT_IMPLEMENTED;
// unused
(void)self; (void)key_char; (void)key_code; (void)modifiers;
#endif
}

static v3_result V3_API on_key_up(void* const self, const int16_t key_char, const int16_t key_code, const int16_t modifiers)
{
#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
d_debug("dpf_plugin_view::on_key_up => %p %i %i %i", self, key_char, key_code, modifiers);
dpf_plugin_view* const view = *static_cast<dpf_plugin_view**>(self);

@@ -1506,11 +1351,6 @@ struct dpf_plugin_view : v3_plugin_view_cpp {
DISTRHO_SAFE_ASSERT_RETURN(uivst3 != nullptr, V3_NOT_INITIALIZED);

return uivst3->onKeyUp(key_char, key_code, modifiers);
#else
return V3_NOT_IMPLEMENTED;
// unused
(void)self; (void)key_char; (void)key_code; (void)modifiers;
#endif
}

static v3_result V3_API get_size(void* const self, v3_view_rect* const rect)
@@ -1569,7 +1409,6 @@ struct dpf_plugin_view : v3_plugin_view_cpp {

static v3_result V3_API on_focus(void* const self, const v3_bool state)
{
#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
d_debug("dpf_plugin_view::on_focus => %p %u", self, state);
dpf_plugin_view* const view = *static_cast<dpf_plugin_view**>(self);

@@ -1577,11 +1416,6 @@ struct dpf_plugin_view : v3_plugin_view_cpp {
DISTRHO_SAFE_ASSERT_RETURN(uivst3 != nullptr, V3_NOT_INITIALIZED);

return uivst3->onFocus(state);
#else
return V3_NOT_IMPLEMENTED;
// unused
(void)self; (void)state;
#endif
}

static v3_result V3_API set_frame(void* const self, v3_plugin_frame** const frame)


+ 4
- 5
examples/EmbedExternalUI/DistrhoPluginInfo.h View File

@@ -23,16 +23,15 @@
#define DISTRHO_PLUGIN_CLAP_ID "studio.kx.distrho.examples.embed-external-ui"

#define DISTRHO_PLUGIN_HAS_UI 1
#define DISTRHO_PLUGIN_HAS_EMBED_UI 1
#define DISTRHO_PLUGIN_HAS_EXTERNAL_UI 1
#define DISTRHO_PLUGIN_IS_RT_SAFE 1
#define DISTRHO_PLUGIN_NUM_INPUTS 2
#define DISTRHO_PLUGIN_NUM_OUTPUTS 2
#define DISTRHO_UI_FILE_BROWSER 0
#define DISTRHO_UI_USE_WEBVIEW 1
#define DISTRHO_UI_WEB_VIEW 1
#define DISTRHO_UI_USE_EXTERNAL 1
#define DISTRHO_UI_USER_RESIZABLE 1
#define DISTRHO_UI_DEFAULT_WIDTH 1184
#define DISTRHO_UI_DEFAULT_HEIGHT 768
#define DISTRHO_UI_DEFAULT_WIDTH 768
#define DISTRHO_UI_DEFAULT_HEIGHT 512

// #ifdef _WIN32
// #define WEB_VIEW_USING_CHOC 1


+ 9
- 66
examples/EmbedExternalUI/EmbedExternalExampleUI.cpp View File

@@ -15,17 +15,15 @@
*/

#include "DistrhoUI.hpp"
#include "NativeWindow.hpp"
#include "Window.hpp"
#include "extra/WebView.hpp"

START_NAMESPACE_DISTRHO

// --------------------------------------------------------------------------------------------------------------------

class EmbedExternalExampleUI : public UI,
public NativeWindow::Callbacks
class EmbedExternalExampleUI : public UI
{
ScopedPointer<NativeWindow> window;
WebViewHandle webview;

public:
@@ -33,24 +31,19 @@ public:
: UI(),
webview(nullptr)
{
const bool standalone = isStandalone();
const double scaleFactor = getScaleFactor();
d_stdout("isStandalone %d", (int)standalone);

const uint width = DISTRHO_UI_DEFAULT_WIDTH * scaleFactor;
const uint height = DISTRHO_UI_DEFAULT_HEIGHT * scaleFactor;

window = new NativeWindow(this, getTitle(), getParentWindowHandle(), width, height, standalone);
webview = webViewCreate("https://distrho.github.io/DPF/",
window->getNativeWindowHandle(),
width, height, scaleFactor);

setGeometryConstraints(width, height);

if (d_isNotEqual(scaleFactor, 1.0))
setSize(width, height);

d_stdout("created external window with size %u %u", getWidth(), getHeight());
webview = webViewCreate("https://distrho.github.io/DPF/",
getWindow().getNativeWindowHandle(),
width, height, scaleFactor);
}

~EmbedExternalExampleUI()
@@ -83,68 +76,18 @@ protected:
}

/* --------------------------------------------------------------------------------------------------------
* External Window callbacks */

void nativeHide() override
{
d_stdout("nativeHide");
UI::hide();
}

void nativeResize(const uint width, const uint height) override
{
d_stdout("nativeResize");
setSize(width, height);
}

/* --------------------------------------------------------------------------------------------------------
* External Window overrides */

void focus() override
{
d_stdout("focus");
window->focus();
}

uintptr_t getNativeWindowHandle() const noexcept override
{
return window->getNativeWindowHandle();
}
* UI overrides */

void sizeChanged(const uint width, const uint height) override
void onResize(const ResizeEvent& ev) override
{
d_stdout("sizeChanged %u %u", width, height);
UI::sizeChanged(width, height);

window->setSize(width, height);
UI::onResize(ev);

if (webview != nullptr)
webViewResize(webview, width, height, getScaleFactor());
}

void titleChanged(const char* const title) override
{
d_stdout("titleChanged %s", title);
window->setTitle(title);
}

void transientParentWindowChanged(const uintptr_t winId) override
{
d_stdout("transientParentWindowChanged %lu", winId);
window->setTransientParentWindow(winId);
}

void visibilityChanged(const bool visible) override
{
d_stdout("visibilityChanged %d", visible);
window->setVisible(visible);
webViewResize(webview, ev.size.getWidth(), ev.size.getHeight(), getScaleFactor());
}

void uiIdle() override
{
// d_stdout("uiIdle");
window->idle();

if (webview != nullptr)
webViewIdle(webview);
}


+ 0
- 1
examples/SendNote/DistrhoPluginInfo.h View File

@@ -26,7 +26,6 @@
#define DISTRHO_PLUGIN_UNIQUE_ID dSNo

#define DISTRHO_PLUGIN_HAS_UI 1
#define DISTRHO_PLUGIN_HAS_EMBED_UI 1
#define DISTRHO_PLUGIN_IS_RT_SAFE 1
#define DISTRHO_PLUGIN_IS_SYNTH 1
#define DISTRHO_PLUGIN_NUM_INPUTS 0


Loading…
Cancel
Save