From a0f9667cc65f0f05e1ec0e8ee9ee764f26c3aa87 Mon Sep 17 00:00:00 2001 From: falkTX Date: Thu, 26 Aug 2021 12:42:05 +0100 Subject: [PATCH] Start tests with mpv Signed-off-by: falkTX --- distrho/extra/ExternalWindow.hpp | 2 - examples/ExternalUI/DistrhoPluginInfo.h | 2 +- examples/ExternalUI/ExternalExampleUI.cpp | 76 ++++++++++++++++++++--- examples/ExternalUI/Makefile | 1 + 4 files changed, 70 insertions(+), 11 deletions(-) diff --git a/distrho/extra/ExternalWindow.hpp b/distrho/extra/ExternalWindow.hpp index 05b40ede..5284ebaf 100644 --- a/distrho/extra/ExternalWindow.hpp +++ b/distrho/extra/ExternalWindow.hpp @@ -122,7 +122,6 @@ public: return ext.inUse ? ext.isQuitting : pData.isQuitting; } -#if DISTRHO_PLUGIN_HAS_EMBED_UI /** Get the "native" window handle. This can be reimplemented in order to pass the native window to hosts that can use such informaton. @@ -139,7 +138,6 @@ public: { return 0; } -#endif /** Grab the keyboard input focus. diff --git a/examples/ExternalUI/DistrhoPluginInfo.h b/examples/ExternalUI/DistrhoPluginInfo.h index 3163c2c3..e8892cb4 100644 --- a/examples/ExternalUI/DistrhoPluginInfo.h +++ b/examples/ExternalUI/DistrhoPluginInfo.h @@ -22,7 +22,7 @@ #define DISTRHO_PLUGIN_URI "http://distrho.sf.net/examples/ExternalUI" #define DISTRHO_PLUGIN_HAS_UI 1 -#define DISTRHO_PLUGIN_HAS_EMBED_UI 0 +#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 1 diff --git a/examples/ExternalUI/ExternalExampleUI.cpp b/examples/ExternalUI/ExternalExampleUI.cpp index 3ea0c608..8899a6e2 100644 --- a/examples/ExternalUI/ExternalExampleUI.cpp +++ b/examples/ExternalUI/ExternalExampleUI.cpp @@ -19,14 +19,20 @@ #include "DistrhoUI.hpp" +#define MPV_TEST +// #define KDE_FIFO_TEST + +#ifdef KDE_FIFO_TEST // Extra includes for current path and fifo stuff #include #include #include #include +#endif START_NAMESPACE_DISTRHO +#ifdef KDE_FIFO_TEST // TODO: generate a random, not-yet-existing, filename const char* const kFifoFilename = "/tmp/dpf-fifo-test"; @@ -58,6 +64,7 @@ writeRetry(int fd, const void* src, size_t size) return error; } +#endif // ----------------------------------------------------------------------------------------------------------- @@ -66,10 +73,13 @@ class ExternalExampleUI : public UI public: ExternalExampleUI() : UI(405, 256), +#ifdef KDE_FIFO_TEST fFifo(-1), - fValue(0.0f), - fExternalScript(getNextBundlePath()) + fExternalScript(getNextBundlePath()), +#endif + fValue(0.0f) { +#ifdef KDE_FIFO_TEST if (fExternalScript.isEmpty()) { fExternalScript = getCurrentPluginFilename(); @@ -78,6 +88,15 @@ public: fExternalScript += "/ExternalLauncher.sh"; d_stdout("External script = %s", fExternalScript.buffer()); +#endif + if (isVisible() || isEmbed()) + visibilityChanged(true); + } + + ~ExternalExampleUI() + { + if (isEmbed()) + terminateAndWaitForExternalProcess(); } protected: @@ -95,6 +114,7 @@ protected: fValue = value; +#ifdef KDE_FIFO_TEST if (fFifo == -1) return; @@ -104,6 +124,7 @@ protected: std::snprintf(valueStr, 23, "%i\n", static_cast(value + 0.5f)); DISTRHO_SAFE_ASSERT(writeRetry(fFifo, valueStr, 24) == sizeof(valueStr)); +#endif } /* -------------------------------------------------------------------------------------------------------- @@ -114,18 +135,21 @@ protected: */ void uiIdle() override { +#ifdef KDE_FIFO_TEST if (fFifo == -1) return; writeRetry(fFifo, "idle\n", 5); +#endif } /** Manage external process and IPC when UI is requested to be visible. */ - void setVisible(const bool yesNo) override + void visibilityChanged(const bool visible) override { - if (yesNo) +#ifdef KDE_FIFO_TEST + if (visible) { DISTRHO_SAFE_ASSERT_RETURN(fileExists(fExternalScript),); @@ -167,21 +191,57 @@ protected: unlink(kFifoFilename); terminateAndWaitForExternalProcess(); } +#endif +#ifdef MPV_TEST + if (visible) + { + const char* const file = "/home/falktx/Videos/HD/"; // TODO make this a state file? - UI::setVisible(yesNo); + if (isEmbed()) + { + char winIdStr[64]; + snprintf(winIdStr, sizeof(winIdStr), "--wid=%lu", getParentWindowHandle()); + const char* args[] = { + "mpv", + "--ao=jack", + winIdStr, + file, + nullptr + }; + unsetenv("LD_LIBRARY_PATH"); + startExternalProcess(args); + } + else + { + const char* args[] = { + "mpv", + "--ao=jack", + file, + nullptr + }; + startExternalProcess(args); + } + } + else + { + terminateAndWaitForExternalProcess(); + } +#endif } // ------------------------------------------------------------------------------------------------------- private: +#ifdef KDE_FIFO_TEST // IPC Stuff int fFifo; - // Current value, cached for when UI becomes visible - float fValue; - // Path to external ui script String fExternalScript; +#endif + + // Current value, cached for when UI becomes visible + float fValue; /** Set our UI class as non-copyable and add a leak detector just in case. diff --git a/examples/ExternalUI/Makefile b/examples/ExternalUI/Makefile index 58476a00..523e3257 100644 --- a/examples/ExternalUI/Makefile +++ b/examples/ExternalUI/Makefile @@ -34,6 +34,7 @@ endif TARGETS += jack TARGETS += dssi TARGETS += lv2_sep +TARGETS += vst2 all: $(TARGETS)