clap

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

commit 267fa0f7b8871f0ec5a15b8f791a5ef7597fa727
parent 5c6c94f271aa8c88e313af7b96d0f17e07fdad89
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date:   Mon,  7 Jun 2021 22:15:05 +0200

More glue

Diffstat:
Mexamples/plugins/plugin.cc | 37+++++++++++++++++++++++++++++++++++++
Mexamples/plugins/plugin.hh | 43+++++++++++++++++++++++++++++++++----------
Minclude/clap/all.h | 2+-
Rinclude/clap/ext/draft/key-name.h -> include/clap/ext/draft/note-name.h | 0
4 files changed, 71 insertions(+), 11 deletions(-)

diff --git a/examples/plugins/plugin.cc b/examples/plugins/plugin.cc @@ -177,6 +177,10 @@ namespace clap { return &pluginParams_; if (!strcmp(id, CLAP_EXT_NOTE_NAME) && self.implementsNoteName()) return &pluginNoteName_; + if (!strcmp(id, CLAP_EXT_THREAD_POOL) && self.implementsThreadPool()) + return &pluginThreadPool_; + if (!strcmp(id, CLAP_EXT_EVENT_LOOP) && self.implementsEventLoop()) + return &pluginEventLoop_; return from(plugin).extension(id); } @@ -239,6 +243,15 @@ namespace clap { } } + //-------------------------// + // clap_plugin_thread_pool // + //-------------------------// + void Plugin::clapThreadPoolExec(const clap_plugin *plugin, uint32_t task_index) noexcept { + auto &self = from(plugin); + + self.threadPoolExec(task_index); + } + //-------------------// // clap_plugin_state // //-------------------// @@ -532,6 +545,30 @@ namespace clap { return self.noteNameGet(index, note_name); } + //------------------------// + // clap_plugin_event_loop // + //------------------------// + void Plugin::clapEventLoopOnTimer(const clap_plugin *plugin, clap_id timer_id) noexcept { + auto &self = from(plugin); + self.ensureMainThread("clap_plugin_event_loop.on_timer"); + + if (timer_id == CLAP_INVALID_ID) { + self.hostMisbehaving( + "Host called clap_plugin_event_loop.on_timer with an invalid timer_id"); + return; + } + + self.eventLoopOnTimer(timer_id); + } + + 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); + } + ///////////// // Logging // ///////////// diff --git a/examples/plugins/plugin.hh b/examples/plugins/plugin.hh @@ -56,6 +56,12 @@ namespace clap { virtual bool implementsRender() const noexcept { return false; } virtual void renderSetMode(clap_plugin_render_mode mode) noexcept {} + //-------------------------// + // clap_plugin_thread_pool // + //-------------------------// + virtual bool implementsThreadPool() const noexcept { return false; } + virtual void threadPoolExec(uint32_t task_index) noexcept; + //-------------------// // clap_plugin_state // //-------------------// @@ -132,6 +138,13 @@ namespace clap { virtual int noteNameCount() noexcept { return 0; } virtual bool noteNameGet(int index, clap_note_name *note_name) noexcept { return false; } + //------------------------// + // clap_plugin_event_loop // + //------------------------// + virtual bool implementsEventLoop() const noexcept { return false; } + virtual void eventLoopOnTimer(clap_id timer_id) noexcept {} + virtual void eventLoopOnFd(clap_fd fd, uint32_t flags) noexcept {} + ////////////////// // Invalidation // ////////////////// @@ -186,18 +199,11 @@ namespace clap { } protected: - clap_plugin_event_filter pluginEventFilter_; - clap_plugin_thread_pool pluginThreadPool_; - - /* state related */ - clap_plugin_file_reference pluginFileReference_; - /* GUI related */ clap_plugin_gui pluginGui_; clap_plugin_gui_win32 pluginGuiWin32_; clap_plugin_gui_cocoa pluginGuiCocoa_; clap_plugin_gui_x11 pluginGuiX11_; - clap_plugin_event_loop pluginEventLoop_; const clap_host *const host_ = nullptr; const clap_host_log *hostLog_ = nullptr; @@ -238,6 +244,9 @@ namespace clap { static void clapRenderSetMode(const clap_plugin *plugin, clap_plugin_render_mode mode) noexcept; + // clap_plugin_thread_pool + static void clapThreadPoolExec(const clap_plugin *plugin, uint32_t task_index) noexcept; + // clap_plugin_state static bool clapStateSave(const clap_plugin *plugin, clap_ostream *stream) noexcept; static bool clapStateLoad(const clap_plugin *plugin, clap_istream *stream) noexcept; @@ -287,16 +296,25 @@ namespace clap { const char *display, clap_param_value *value) noexcept; - // clap_note_name + // clap_plugin_note_name static uint32_t clapNoteNameCount(const clap_plugin *plugin) noexcept; - static bool - clapNoteNameGet(const clap_plugin *plugin, uint32_t index, clap_note_name *note_name) noexcept; + static bool clapNoteNameGet(const clap_plugin *plugin, + uint32_t index, + clap_note_name *note_name) noexcept; + + // clap_plugin_event_loop + 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; // interfaces static const constexpr clap_plugin_render pluginRender_ = { clapRenderSetMode, }; + static const constexpr clap_plugin_thread_pool pluginThreadPool_ = { + clapThreadPoolExec, + }; + static const constexpr clap_plugin_state pluginState_ = { clapStateSave, clapStateLoad, @@ -338,6 +356,11 @@ namespace clap { clapNoteNameGet, }; + static const constexpr clap_plugin_event_loop pluginEventLoop_ = { + clapEventLoopOnTimer, + clapEventLoopOnFd, + }; + // state bool isActive_ = false; bool isProcessing_ = false; diff --git a/include/clap/all.h b/include/clap/all.h @@ -17,7 +17,7 @@ #include "ext/event-loop.h" #include "ext/draft/event-filter.h" -#include "ext/draft/key-name.h" +#include "ext/draft/note-name.h" #include "ext/draft/preset-load.h" #include "ext/draft/quick-controls.h" #include "ext/draft/thread-pool.h" diff --git a/include/clap/ext/draft/key-name.h b/include/clap/ext/draft/note-name.h