clap

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

commit 56bb6cef2a2d4bbb7ea996bc342ebe30636310ad
parent 1c2f9406b253b29a88bb0152cd86697169cca97a
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date:   Sat, 17 Jul 2021 14:10:19 +0200

Format & add modulation queue

Diffstat:
Mexamples/host/plugin-host.cc | 29++++++++++++++++++++++-------
Mexamples/host/plugin-host.hh | 91+++++++++++++++++++++++++++++++++++++++++--------------------------------------
2 files changed, 69 insertions(+), 51 deletions(-)

diff --git a/examples/host/plugin-host.cc b/examples/host/plugin-host.cc @@ -602,7 +602,7 @@ void PluginHost::process() { process_.audio_outputs_count = 1; evOut_.clear(); - appToEngineQueue_.consume([this](clap_id param_id, void *cookie, double value) { + appToEngineValueQueue_.consume([this](clap_id param_id, void *cookie, double value) { clap_event ev; ev.time = 0; ev.type = CLAP_EVENT_PARAM_VALUE; @@ -611,6 +611,19 @@ void PluginHost::process() { ev.param_value.key = -1; ev.param_value.channel = -1; ev.param_value.value = value; + ev.param_value.flags = 0; + evIn_.push_back(ev); + }); + + appToEngineModQueue_.consume([this](clap_id param_id, void *cookie, double value) { + clap_event ev; + ev.time = 0; + ev.type = CLAP_EVENT_PARAM_MOD; + ev.param_mod.param_id = param_id; + ev.param_mod.cookie = cookie; + ev.param_mod.key = -1; + ev.param_mod.channel = -1; + ev.param_mod.amount = value; evIn_.push_back(ev); }); @@ -628,7 +641,7 @@ void PluginHost::process() { for (auto &ev : evOut_) { switch (ev.type) { case CLAP_EVENT_PARAM_VALUE: - engineToAppQueue_.set( + engineToAppValueQueue_.set( ev.param_value.param_id, ev.param_value.cookie, ev.param_value.value); break; } @@ -641,7 +654,7 @@ void PluginHost::process() { setPluginState(ActiveAndReadyToDeactivate); } - engineToAppQueue_.producerDone(); + engineToAppValueQueue_.producerDone(); g_thread_type = Unknown; } @@ -649,8 +662,10 @@ void PluginHost::idle() { checkForMainThread(); // Try to send events to the audio engine - appToEngineQueue_.producerDone(); - engineToAppQueue_.consume([this](clap_id param_id, void *cookie, double value) { + appToEngineValueQueue_.producerDone(); + appToEngineModQueue_.producerDone(); + + engineToAppValueQueue_.consume([this](clap_id param_id, void *cookie, double value) { auto it = params_.find(param_id); if (it == params_.end()) { std::ostringstream msg; @@ -703,8 +718,8 @@ void PluginHost::setParamValueByHost(PluginParam &param, double value) { param.setValue(value); - appToEngineQueue_.set(param.info().id, param.info().cookie, value); - appToEngineQueue_.producerDone(); + appToEngineValueQueue_.set(param.info().id, param.info().cookie, value); + appToEngineValueQueue_.producerDone(); } void PluginHost::scanParams() { clapParamsRescan(&host_, CLAP_PARAM_RESCAN_ALL); } diff --git a/examples/host/plugin-host.hh b/examples/host/plugin-host.hh @@ -59,9 +59,9 @@ public: auto quickControlsSelectedPage() const { return quickControlsSelectedPage_; } void setQuickControlsSelectedPageByHost(clap_id page_id); - bool loadNativePluginPreset(const std::string& path); - bool loadStateFromFile(const std::string& path); - bool saveStateToFile(const std::string& path); + bool loadNativePluginPreset(const std::string &path); + bool loadStateFromFile(const std::string &path); + bool saveStateToFile(const std::string &path); static void checkForMainThread(); static void checkForAudioThread(); @@ -82,16 +82,16 @@ private: static bool clapIsMainThread(const clap_host *host); static bool clapIsAudioThread(const clap_host *host); - static void clapParamsRescan(const clap_host *host, uint32_t flags); - static void clapParamsClear(const clap_host *host, uint32_t flags); - void scanParams(); - void scanParam(int32_t index); + static void clapParamsRescan(const clap_host *host, uint32_t flags); + static void clapParamsClear(const clap_host *host, uint32_t flags); + void scanParams(); + void scanParam(int32_t index); PluginParam &checkValidParamId(const std::string_view &function, const std::string_view &param_name, - clap_id param_id); - void checkValidParamValue(const PluginParam &param, double value); + clap_id param_id); + void checkValidParamValue(const PluginParam &param, double value); double getParamValue(const clap_param_info &info); - static bool clapParamsRescanMayValueChange(uint32_t flags) { + static bool clapParamsRescanMayValueChange(uint32_t flags) { return flags & (CLAP_PARAM_RESCAN_ALL | CLAP_PARAM_RESCAN_VALUES); } static bool clapParamsRescanMayInfoChange(uint32_t flags) { @@ -103,12 +103,13 @@ private: static void clapQuickControlsPagesChanged(const clap_host *host); static void clapQuickControlsSelectedPageChanged(const clap_host *host, clap_id page_id); - static bool clapEventLoopRegisterTimer(const clap_host *host, uint32_t period_ms, clap_id *timer_id); + static bool + clapEventLoopRegisterTimer(const clap_host *host, uint32_t period_ms, clap_id *timer_id); static bool clapEventLoopUnregisterTimer(const clap_host *host, clap_id timer_id); static bool clapEventLoopRegisterFd(const clap_host *host, clap_fd fd, uint32_t flags); static bool clapEventLoopModifyFd(const clap_host *host, clap_fd fd, uint32_t flags); static bool clapEventLoopUnregisterFd(const clap_host *host, clap_fd fd); - void eventLoopSetFdNotifierFlags(clap_fd fd, uint32_t flags); + void eventLoopSetFdNotifierFlags(clap_fd fd, uint32_t flags); static bool clapThreadPoolRequestExec(const clap_host *host, uint32_t num_tasks); @@ -124,36 +125,36 @@ private: QLibrary library_; - clap_host host_; - clap_host_log hostLog_; - clap_host_gui hostGui_; - clap_host_audio_ports hostAudioPorts_; - clap_host_params hostParams_; + clap_host host_; + clap_host_log hostLog_; + clap_host_gui hostGui_; + clap_host_audio_ports hostAudioPorts_; + clap_host_params hostParams_; clap_host_quick_controls hostQuickControls_; - clap_host_event_loop hostEventLoop_; - clap_host_thread_check hostThreadCheck_; - clap_host_thread_pool hostThreadPool_; + clap_host_event_loop hostEventLoop_; + clap_host_thread_check hostThreadCheck_; + clap_host_thread_pool hostThreadPool_; clap_host_state hostState_; - const struct clap_plugin_entry * pluginEntry_ = nullptr; - const clap_plugin * plugin_ = nullptr; - const clap_plugin_params * pluginParams_ = nullptr; - const clap_plugin_quick_controls * pluginQuickControls_ = nullptr; - const clap_plugin_audio_ports * pluginAudioPorts_ = nullptr; - const clap_plugin_gui * pluginGui_ = nullptr; - const clap_plugin_gui_x11 * pluginGuiX11_ = nullptr; - const clap_plugin_gui_win32 * pluginGuiWin32_ = nullptr; - const clap_plugin_gui_cocoa * pluginGuiCocoa_ = nullptr; + const struct clap_plugin_entry *pluginEntry_ = nullptr; + const clap_plugin *plugin_ = nullptr; + const clap_plugin_params *pluginParams_ = nullptr; + const clap_plugin_quick_controls *pluginQuickControls_ = nullptr; + const clap_plugin_audio_ports *pluginAudioPorts_ = nullptr; + const clap_plugin_gui *pluginGui_ = nullptr; + const clap_plugin_gui_x11 *pluginGuiX11_ = nullptr; + const clap_plugin_gui_win32 *pluginGuiWin32_ = nullptr; + const clap_plugin_gui_cocoa *pluginGuiCocoa_ = nullptr; const clap_plugin_gui_free_standing *pluginGuiFreeStanding_ = nullptr; - const clap_plugin_event_loop * pluginEventLoop_ = nullptr; - const clap_plugin_thread_pool * pluginThreadPool_ = nullptr; - const clap_plugin_preset_load * pluginPresetLoad_ = nullptr; - const clap_plugin_state * pluginState_ = nullptr; + const clap_plugin_event_loop *pluginEventLoop_ = nullptr; + const clap_plugin_thread_pool *pluginThreadPool_ = nullptr; + const clap_plugin_preset_load *pluginPresetLoad_ = nullptr; + const clap_plugin_state *pluginState_ = nullptr; bool pluginExtensionsAreInitialized_ = false; /* timers */ - clap_id nextTimerId_ = 0; + clap_id nextTimerId_ = 0; std::unordered_map<clap_id, std::unique_ptr<QTimer>> timers_; /* fd events */ @@ -166,22 +167,24 @@ private: /* thread pool */ std::vector<std::unique_ptr<QThread>> threadPool_; - std::atomic<bool> threadPoolStop_ = {false}; - std::atomic<int> threadPoolTaskIndex_ = {0}; - QSemaphore threadPoolSemaphoreProd_; - QSemaphore threadPoolSemaphoreDone_; + std::atomic<bool> threadPoolStop_ = {false}; + std::atomic<int> threadPoolTaskIndex_ = {0}; + QSemaphore threadPoolSemaphoreProd_; + QSemaphore threadPoolSemaphoreDone_; /* process stuff */ - clap_audio_buffer audioIn_ = {}; - clap_audio_buffer audioOut_ = {}; + clap_audio_buffer audioIn_ = {}; + clap_audio_buffer audioOut_ = {}; std::vector<clap_event> evIn_; std::vector<clap_event> evOut_; - clap_process process_; + clap_process process_; /* param update queues */ std::unordered_map<clap_id, std::unique_ptr<PluginParam>> params_; - ParamQueue appToEngineQueue_; - ParamQueue engineToAppQueue_; + + ParamQueue appToEngineValueQueue_; + ParamQueue appToEngineModQueue_; + ParamQueue engineToAppValueQueue_; std::unordered_map<clap_id, std::unique_ptr<clap_quick_controls_page>> quickControlsPages_; clap_id quickControlsSelectedPage_ = CLAP_INVALID_ID; @@ -213,7 +216,7 @@ private: void setPluginState(PluginState state); PluginState state_ = Inactive; - bool stateIsDirty_ = false; + bool stateIsDirty_ = false; bool scheduleRestart_ = false; };