diff --git a/Makefile.plugins.mk b/Makefile.plugins.mk index aa69a91c..026a4d52 100644 --- a/Makefile.plugins.mk +++ b/Makefile.plugins.mk @@ -76,6 +76,11 @@ all: # --------------------------------------------------------------------------------------------------------------------- # Common +$(BUILD_DIR)/%.S.o: %.S + -@mkdir -p "$(shell dirname $(BUILD_DIR)/$<)" + @echo "Compiling $<" + @$(CC) $< $(BUILD_C_FLAGS) -c -o $@ + $(BUILD_DIR)/%.c.o: %.c -@mkdir -p "$(shell dirname $(BUILD_DIR)/$<)" @echo "Compiling $<" diff --git a/dgl/Makefile b/dgl/Makefile index b0b4f419..f328da78 100644 --- a/dgl/Makefile +++ b/dgl/Makefile @@ -27,7 +27,8 @@ OBJS = \ ../build/dgl/ImageWidgets.cpp.o \ ../build/dgl/NanoVG.cpp.o \ ../build/dgl/Resources.cpp.o \ - ../build/dgl/Widget.cpp.o + ../build/dgl/Widget.cpp.o \ + ../build/dgl/VstGui.cpp.o ifeq ($(MACOS),true) OBJS += ../build/dgl/Window.mm.o @@ -71,6 +72,11 @@ all: $(TARGET) @echo "Compiling $<" @$(CXX) $< $(BUILD_CXX_FLAGS) -ObjC++ -c -o $@ +../build/dgl/VstGui.cpp.o: src/VstGui.cpp + -@mkdir -p ../build/dgl + @echo "Compiling $<" + @$(CXX) $< $(BUILD_CXX_FLAGS) $(shell pkg-config --cflags cairo freetype2) -w -DDebugPrint={} -c -o $@ + # --------------------------------------------------------------------------------------------------------------------- clean: diff --git a/dgl/VstGuiWidget.hpp b/dgl/VstGuiWidget.hpp new file mode 100644 index 00000000..e2749382 --- /dev/null +++ b/dgl/VstGuiWidget.hpp @@ -0,0 +1,110 @@ +/* + * DISTRHO Plugin Framework (DPF) + * Copyright (C) 2012-2019 Filipe Coelho + * + * 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_VSTGUI_HPP_INCLUDED +#define DISTRHO_VSTGUI_HPP_INCLUDED + +#include "Base.hpp" +#include "../distrho/extra/String.hpp" + +START_NAMESPACE_DGL + +// ----------------------------------------------------------------------- + +class VstGuiWidget +{ +public: + VstGuiWidget(const uint w = 1, const uint h = 1, const char* const t = "") + : width(w), + height(h), + title(t), + transientWinId(0), + visible(false) {} + + virtual ~VstGuiWidget() + { + } + + uint getWidth() const noexcept + { + return width; + } + + uint getHeight() const noexcept + { + return height; + } + + const char* getTitle() const noexcept + { + return title; + } + + uintptr_t getTransientWinId() const noexcept + { + return transientWinId; + } + + bool isVisible() const noexcept + { + return visible; + } + + bool isRunning() noexcept + { + return visible; + } + + virtual void idle() {} + + virtual void setSize(uint w, uint h) + { + width = w; + height = h; + } + + virtual void setTitle(const char* const t) + { + title = t; + } + + virtual void setTransientWinId(const uintptr_t winId) + { + transientWinId = winId; + } + + virtual void setVisible(const bool yesNo) + { + visible = yesNo; + } + + void terminateAndWaitForProcess() + { + } + +private: + uint width; + uint height; + DISTRHO_NAMESPACE::String title; + uintptr_t transientWinId; + bool visible; +}; + +// ----------------------------------------------------------------------- + +END_NAMESPACE_DGL + +#endif // DISTRHO_VSTGUI_HPP_INCLUDED diff --git a/dgl/src/VstGui.cpp b/dgl/src/VstGui.cpp new file mode 100644 index 00000000..0bea1fd0 --- /dev/null +++ b/dgl/src/VstGui.cpp @@ -0,0 +1,239 @@ +/* + * DISTRHO Plugin Framework (DPF) + * Copyright (C) 2012-2019 Filipe Coelho + * + * 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. + */ + +// #include "../../vstgui/vstgui/standalone/source/platform/gdk/gdkrunloop.h" +#include "../../vstgui/vstgui/vstgui_linux.cpp" +#include "../../vstgui/vstgui/plugin-bindings/plugguieditor.h" + +namespace VSTGUI { + void* soHandle = nullptr; +}; + +//------------------------------------------------------------------------ +class RunLoop : public VSTGUI::X11::IRunLoop +{ +public: + using IEventHandler = VSTGUI::X11::IEventHandler; + using ITimerHandler = VSTGUI::X11::ITimerHandler; + + static RunLoop& instance (); + + RunLoop (); + ~RunLoop () noexcept; + + bool registerEventHandler (int fd, IEventHandler* handler) override; + bool unregisterEventHandler (IEventHandler* handler) override; + + bool registerTimer (uint64_t interval, ITimerHandler* handler) override; + bool unregisterTimer (ITimerHandler* handler) override; + + void forget () override {} + void remember () override {} + +private: + struct Impl; + std::unique_ptr impl; +}; + +static VSTGUI::X11::ITimerHandler* timer1 = nullptr; +static VSTGUI::X11::ITimerHandler* timer2 = nullptr; +static VSTGUI::X11::ITimerHandler* timer3 = nullptr; +static VSTGUI::X11::IEventHandler* event1 = nullptr; +static VSTGUI::X11::IEventHandler* event2 = nullptr; + +//------------------------------------------------------------------------ +RunLoop& RunLoop::instance () +{ + static RunLoop instance; + return instance; +} + +//------------------------------------------------------------------------ +struct ExternalEventHandler +{ + VSTGUI::X11::IEventHandler* eventHandler{nullptr}; +// GSource* source{nullptr}; +// GIOChannel* ioChannel{nullptr}; +}; + +//------------------------------------------------------------------------ +struct ExternalTimerHandler +{ + VSTGUI::X11::ITimerHandler* timerHandler{nullptr}; +// GSource* source{nullptr}; +}; + +//------------------------------------------------------------------------ +struct RunLoop::Impl +{ + using EventHandlerVector = std::vector>; + using TimerHandlerVector = std::vector>; + +// GMainContext * mainContext{nullptr}; + EventHandlerVector eventHandlers; + TimerHandlerVector timerHandlers; +}; + +//------------------------------------------------------------------------ +RunLoop::RunLoop () +{ + impl = std::unique_ptr (new Impl); +// impl->mainContext = g_main_context_ref (g_main_context_default ()); +} + +//------------------------------------------------------------------------ +RunLoop::~RunLoop () noexcept +{ + printf("%s\n", __func__); +} + +//------------------------------------------------------------------------ +bool RunLoop::registerEventHandler (int fd, IEventHandler* handler) +{ + printf("%s\n", __func__); + if (event1 == nullptr) + { + event1 = handler; + return true; + } + if (event2 == nullptr) + { + event2 = handler; + return true; + } + return true; +} + +//------------------------------------------------------------------------ +bool RunLoop::unregisterEventHandler (IEventHandler* handler) +{ + printf("%s\n", __func__); + return false; +} + +//------------------------------------------------------------------------ +bool RunLoop::registerTimer (uint64_t interval, ITimerHandler* handler) +{ + printf("%s\n", __func__); + if (timer1 == nullptr) + { + timer1 = handler; + return true; + } + if (timer2 == nullptr) + { + timer2 = handler; + return true; + } + if (timer3 == nullptr) + { + timer3 = handler; + return true; + } + return false; +} + +//------------------------------------------------------------------------ +bool RunLoop::unregisterTimer (ITimerHandler* handler) +{ + printf("%s\n", __func__); + return false; +} + +PluginGUIEditor::PluginGUIEditor (void *pEffect) + : effect (pEffect) +{ + systemWindow = 0; + lLastTicks = getTicks (); +} + +//----------------------------------------------------------------------------- +PluginGUIEditor::~PluginGUIEditor () +{ +} + +//----------------------------------------------------------------------------- +void PluginGUIEditor::draw (ERect *ppErect) +{ +} + +//----------------------------------------------------------------------------- +bool PluginGUIEditor::open (void *ptr) +{ + frame = new CFrame (CRect (0, 0, 0, 0), this); + getFrame ()->setTransparency (true); + + IPlatformFrameConfig* config = nullptr; + X11::FrameConfig x11config; + x11config.runLoop = owned (new RunLoop ()); + config = &x11config; + + printf("%s %p %p\n", __func__, frame, ptr); + getFrame ()->open (ptr, kDefaultNative, config); + + systemWindow = ptr; + return true; +} + +//----------------------------------------------------------------------------- +void PluginGUIEditor::idle () +{ + if (frame) + frame->idle (); + if (timer1 != nullptr) + timer1->onTimer(); + if (timer2 != nullptr) + timer2->onTimer(); + if (timer3 != nullptr) + timer3->onTimer(); + if (event1 != nullptr) + event1->onEvent(); + if (event2 != nullptr) + event2->onEvent(); +} + +//----------------------------------------------------------------------------- +int32_t PluginGUIEditor::knobMode = kCircularMode; + +//----------------------------------------------------------------------------- +int32_t PluginGUIEditor::setKnobMode (int32_t val) +{ + PluginGUIEditor::knobMode = val; + return 1; +} + +//----------------------------------------------------------------------------- +void PluginGUIEditor::wait (uint32_t ms) +{ +} + +//----------------------------------------------------------------------------- +uint32_t PluginGUIEditor::getTicks () +{ + return 0; +} + +//----------------------------------------------------------------------------- +void PluginGUIEditor::doIdleStuff () +{ +} + +//----------------------------------------------------------------------------- +bool PluginGUIEditor::getRect (ERect **ppErect) +{ + *ppErect = ▭ + return true; +} diff --git a/distrho/DistrhoUI.hpp b/distrho/DistrhoUI.hpp index 244b25bc..0337ea75 100644 --- a/distrho/DistrhoUI.hpp +++ b/distrho/DistrhoUI.hpp @@ -20,7 +20,10 @@ #include "extra/LeakDetector.hpp" #include "src/DistrhoPluginChecks.h" -#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI +#if DISTRHO_UI_USE_VSTGUI +# include "../dgl/VstGuiWidget.hpp" +typedef DGL_NAMESPACE::VstGuiWidget UIWidget; +#elif DISTRHO_PLUGIN_HAS_EXTERNAL_UI # include "../dgl/Base.hpp" # include "extra/ExternalWindow.hpp" typedef DISTRHO_NAMESPACE::ExternalWindow UIWidget;