clap

CLAP Audio Plugin API
Log | Files | Refs | README | LICENSE

commit 74c01b879b7f14b83d8c097bc524734d86ca01d6
parent 79f342f4ce4196398a866f1a5ab4dfa1cbbfd96d
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date:   Mon,  7 Jun 2021 22:47:30 +0200

Add the glue for the GUI

Diffstat:
Mexamples/plugins/plugin.cc | 93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Mexamples/plugins/plugin.hh | 85+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
2 files changed, 170 insertions(+), 8 deletions(-)

diff --git a/examples/plugins/plugin.cc b/examples/plugins/plugin.cc @@ -181,6 +181,16 @@ namespace clap { return &pluginThreadPool_; if (!strcmp(id, CLAP_EXT_EVENT_LOOP) && self.implementsEventLoop()) return &pluginEventLoop_; + if (!strcmp(id, CLAP_EXT_GUI) && self.implementsGui()) + return &pluginGui_; + if (!strcmp(id, CLAP_EXT_GUI_X11) && self.implementsGuiX11()) + return &pluginGuiX11_; + if (!strcmp(id, CLAP_EXT_GUI_WIN32) && self.implementsGuiWin32()) + return &pluginGuiWin32_; + if (!strcmp(id, CLAP_EXT_GUI_COCOA) && self.implementsGuiCocoa()) + return &pluginGuiCocoa_; + if (!strcmp(id, CLAP_EXT_GUI_FREE_STANDING) && self.implementsGuiFreeStanding()) + return &pluginGuiFreeStanding_; return from(plugin).extension(id); } @@ -561,14 +571,93 @@ namespace clap { self.eventLoopOnTimer(timer_id); } - void Plugin::clapEventLoopOnFd(const clap_plugin *plugin, clap_fd fd, uint32_t flags) noexcept - { + void Plugin::clapEventLoopOnFd(const clap_plugin *plugin, clap_fd fd, uint32_t flags) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_event_loop.on_fd"); self.eventLoopOnFd(fd, flags); } + //-----------------// + // clap_plugin_gui // + //-----------------// + void Plugin::clapGuiSize(const clap_plugin *plugin, int32_t *width, int32_t *height) noexcept { + auto &self = from(plugin); + self.ensureMainThread("clap_plugin_gui.size"); + + self.guiSize(width, height); + } + + void Plugin::clapGuiSetScale(const clap_plugin *plugin, double scale) noexcept { + auto &self = from(plugin); + self.ensureMainThread("clap_plugin_gui.set_scale"); + + self.guiSetScale(scale); + } + + void Plugin::clapGuiShow(const clap_plugin *plugin) noexcept { + auto &self = from(plugin); + self.ensureMainThread("clap_plugin_gui.show"); + + self.guiShow(); + } + + void Plugin::clapGuiHide(const clap_plugin *plugin) noexcept { + auto &self = from(plugin); + self.ensureMainThread("clap_plugin_gui.hide"); + + self.guiHide(); + } + + void Plugin::clapGuiClose(const clap_plugin *plugin) noexcept { + auto &self = from(plugin); + self.ensureMainThread("clap_plugin_gui.close"); + + self.guiClose(); + } + + //---------------------// + // clap_plugin_gui_x11 // + //---------------------// + bool Plugin::clapGuiX11Attach(const clap_plugin *plugin, + const char *display_name, + unsigned long window) noexcept { + auto &self = from(plugin); + self.ensureMainThread("clap_plugin_gui_x11.attach"); + + return self.guiX11Attach(display_name, window); + } + + //-----------------------// + // clap_plugin_gui_win32 // + //-----------------------// + bool Plugin::clapGuiWin32Attach(const clap_plugin *plugin, clap_hwnd window) noexcept { + auto &self = from(plugin); + self.ensureMainThread("clap_plugin_gui_win32.attach"); + + return self.guiWin32Attach(window); + } + + //-----------------------// + // clap_plugin_gui_cocoa // + //-----------------------// + bool Plugin::clapGuiCocoaAttach(const clap_plugin *plugin, void *nsView) noexcept { + auto &self = from(plugin); + self.ensureMainThread("clap_plugin_gui_cocoa.attach"); + + return self.guiCocoaAttach(nsView); + } + + //-------------------------------// + // clap_plugin_gui_free_standing // + //-------------------------------// + bool Plugin::clapGuiFreeStandingOpen(const clap_plugin *plugin) noexcept { + auto &self = from(plugin); + self.ensureMainThread("clap_plugin_gui_win32.attach"); + + return self.guiFreeStandingOpen(); + } + ///////////// // Logging // ///////////// diff --git a/examples/plugins/plugin.hh b/examples/plugins/plugin.hh @@ -145,6 +145,40 @@ namespace clap { virtual void eventLoopOnTimer(clap_id timer_id) noexcept {} virtual void eventLoopOnFd(clap_fd fd, uint32_t flags) noexcept {} + //-----------------// + // clap_plugin_gui // + //-----------------// + virtual bool implementsGui() const noexcept { return false; } + virtual void guiSize(int32_t *width, int32_t *height) noexcept {} + virtual void guiSetScale(double scale) noexcept {} + virtual void guiShow() noexcept {} + virtual void guiHide() noexcept {} + virtual void guiClose() noexcept {} + + //---------------------// + // clap_plugin_gui_x11 // + //---------------------// + virtual bool implementsGuiX11() const noexcept { return false; } + virtual bool guiX11Attach(const char *display_name, unsigned long window) noexcept; + + //-----------------------// + // clap_plugin_gui_win32 // + //-----------------------// + virtual bool implementsGuiWin32() const noexcept { return false; } + virtual bool guiWin32Attach(clap_hwnd window) noexcept; + + //-----------------------// + // clap_plugin_gui_cocoa // + //-----------------------// + virtual bool implementsGuiCocoa() const noexcept { return false; } + virtual bool guiCocoaAttach(void *nsView) noexcept; + + //-------------------------------// + // clap_plugin_gui_free_standing // + //-------------------------------// + virtual bool implementsGuiFreeStanding() const noexcept { return false; } + virtual bool guiFreeStandingOpen() noexcept; + ////////////////// // Invalidation // ////////////////// @@ -199,12 +233,6 @@ namespace clap { } protected: - /* GUI related */ - clap_plugin_gui pluginGui_; - clap_plugin_gui_win32 pluginGuiWin32_; - clap_plugin_gui_cocoa pluginGuiCocoa_; - clap_plugin_gui_x11 pluginGuiX11_; - const clap_host *const host_ = nullptr; const clap_host_log *hostLog_ = nullptr; const clap_host_thread_check *hostThreadCheck_ = nullptr; @@ -306,6 +334,27 @@ namespace clap { static void clapEventLoopOnTimer(const clap_plugin *plugin, clap_id timer_id) noexcept; static void clapEventLoopOnFd(const clap_plugin *plugin, clap_fd fd, uint32_t flags) noexcept; + // clap_plugin_gui + static void clapGuiSize(const clap_plugin *plugin, int32_t *width, int32_t *height) noexcept; + static void clapGuiSetScale(const clap_plugin *plugin, double scale) noexcept; + static void clapGuiShow(const clap_plugin *plugin) noexcept; + static void clapGuiHide(const clap_plugin *plugin) noexcept; + static void clapGuiClose(const clap_plugin *plugin) noexcept; + + // clap_plugin_gui_x11 + static bool clapGuiX11Attach(const clap_plugin *plugin, + const char *display_name, + unsigned long window) noexcept; + + // clap_plugin_gui_win32 + static bool clapGuiWin32Attach(const clap_plugin *plugin, clap_hwnd window) noexcept; + + // clap_plugin_gui_cocoa + static bool clapGuiCocoaAttach(const clap_plugin *plugin, void *nsView) noexcept; + + // clap_plugin_gui_free_standing + static bool clapGuiFreeStandingOpen(const clap_plugin *plugin) noexcept; + // interfaces static const constexpr clap_plugin_render pluginRender_ = { clapRenderSetMode, @@ -361,6 +410,30 @@ namespace clap { clapEventLoopOnFd, }; + static const constexpr clap_plugin_gui pluginGui_ = { + clapGuiSize, + clapGuiSetScale, + clapGuiShow, + clapGuiHide, + clapGuiClose, + }; + + static const constexpr clap_plugin_gui_x11 pluginGuiX11_ = { + clapGuiX11Attach, + }; + + static const constexpr clap_plugin_gui_win32 pluginGuiWin32_ = { + clapGuiWin32Attach, + }; + + static const constexpr clap_plugin_gui_cocoa pluginGuiCocoa_ = { + clapGuiCocoaAttach, + }; + + static const constexpr clap_plugin_gui_free_standing pluginGuiFreeStanding_ = { + clapGuiFreeStandingOpen, + }; + // state bool isActive_ = false; bool isProcessing_ = false;