clap

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

commit 60ab9397d04a22a4a42a40a1d4e099d3267908d6
parent 53f1ca8bfd31f5cecba529d8ef0d0905748dc759
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date:   Fri, 27 Aug 2021 16:37:21 +0200

Prepare the timer

Diffstat:
Mexamples/gui/application.cc | 11+++--------
Mexamples/io/messages.hh | 6------
Mexamples/plugins/core-plugin.cc | 24++++++++++++++++++++++--
Mexamples/plugins/core-plugin.hh | 12+++++++++---
Mexamples/plugins/dc-offset/dc-offset.cc | 35+++++++++++++----------------------
Mexamples/plugins/remote-gui.cc | 8++++++++
Mexamples/plugins/remote-gui.hh | 2++
7 files changed, 57 insertions(+), 41 deletions(-)

diff --git a/examples/gui/application.cc b/examples/gui/application.cc @@ -103,14 +103,9 @@ void Application::onMessage(const clap::RemoteChannel::Message &msg) { case clap::messages::kParameterValueRequest: { clap::messages::ParameterValueRequest rq; msg.get(rq); - pluginProxy_->param(rq.paramId)->setValueFromPlugin(rq.value); - break; - } - - case clap::messages::kParameterModulationRequest: { - clap::messages::ParameterModulationRequest rq; - msg.get(rq); - pluginProxy_->param(rq.paramId)->setModulationFromPlugin(rq.modulation); + auto p = pluginProxy_->param(rq.paramId); + p->setValueFromPlugin(rq.value); + p->setModulationFromPlugin(rq.modulation); break; } diff --git a/examples/io/messages.hh b/examples/io/messages.hh @@ -7,7 +7,6 @@ namespace clap::messages { enum Type : uint32_t { // DSP->GUI kDefineParameterRequest, - kParameterModulationRequest, kParameterValueRequest, // GUI->DSP @@ -54,11 +53,6 @@ namespace clap::messages { static const constexpr Type type = kParameterValueRequest; clap_id paramId; double value; - }; - - struct ParameterModulationRequest final { - static const constexpr Type type = kParameterModulationRequest; - clap_id paramId; double modulation; }; diff --git a/examples/plugins/core-plugin.cc b/examples/plugins/core-plugin.cc @@ -163,9 +163,29 @@ namespace clap { return false; } - void CorePlugin::guiAdjust(clap_id paramId, double value, clap_event_param_flags flags) - { + void CorePlugin::guiAdjust(clap_id paramId, double value, clap_event_param_flags flags) { guiToPluginQueue_.set(paramId, {value, flags}); guiToPluginQueue_.producerDone(); } + + void CorePlugin::processGuiEvents(const clap_process *process) { + guiToPluginQueue_.consume([this, process](clap_id paramId, const GuiToPluginValue &value) { + auto p = parameters_.getById(paramId); + if (!p) + return; + p->setValue(value.value); + + clap_event ev; + ev.time = 0; + ev.type = CLAP_EVENT_PARAM_VALUE; + ev.param_value.param_id = paramId; + ev.param_value.value = value.value; + ev.param_value.channel = -1; + ev.param_value.key = -1; + ev.param_value.flags = value.flags; + ev.param_value.cookie = p; + + process->out_events->push_back(process->out_events, &ev); + }); + } } // namespace clap \ No newline at end of file diff --git a/examples/plugins/core-plugin.hh b/examples/plugins/core-plugin.hh @@ -148,14 +148,20 @@ namespace clap { friend class RemoteGui; void guiAdjust(clap_id paramId, double value, clap_event_param_flags flags); + void processGuiEvents(const clap_process *process); - struct ParamQueueValue { + struct GuiToPluginValue { double value; clap_event_param_flags flags; }; - ParamQueue<ParamQueueValue> guiToPluginQueue_; - ParamQueue<ParamQueueValue> pluginToGuiQueue_; + struct PluginToGuiValue { + double value; + double mod; + }; + + ParamQueue<GuiToPluginValue> guiToPluginQueue_; + ParamQueue<PluginToGuiValue> pluginToGuiQueue_; std::unique_ptr<PathProvider> pathProvider_; diff --git a/examples/plugins/dc-offset/dc-offset.cc b/examples/plugins/dc-offset/dc-offset.cc @@ -78,24 +78,7 @@ namespace clap { const clap_event *ev = nullptr; uint32_t N = process->frames_count; - guiToPluginQueue_.consume([this, process] (clap_id paramId, const ParamQueueValue& value) { - auto p = parameters_.getById(paramId); - if (!p) - return; - p->setValue(value.value); - - clap_event ev; - ev.time = 0; - ev.type = CLAP_EVENT_PARAM_VALUE; - ev.param_value.param_id = paramId; - ev.param_value.value = value.value; - ev.param_value.channel = -1; - ev.param_value.key = -1; - ev.param_value.flags = value.flags; - ev.param_value.cookie = p; - - process->out_events->push_back(process->out_events, &ev); - }); + processGuiEvents(process); /* foreach frames */ for (uint32_t i = 0; i < process->frames_count; ++i) { @@ -117,16 +100,22 @@ namespace clap { switch (ev->type) { case CLAP_EVENT_PARAM_VALUE: { - auto p = parameters_.getById(ev->param_value.param_id); - if (p) + auto id = ev->param_value.param_id; + auto p = parameters_.getById(id); + if (p) { p->setValue(ev->param_value.value); + pluginToGuiQueue_.set(id, {ev->param_value.value, p->modulation()}); + } break; } case CLAP_EVENT_PARAM_MOD: { - auto p = parameters_.getById(ev->param_mod.param_id); - if (p) + auto id = ev->param_mod.param_id; + auto p = parameters_.getById(id); + if (p) { p->setModulation(ev->param_mod.amount); + pluginToGuiQueue_.set(id, {p->value(), ev->param_mod.amount}); + } break; } } @@ -141,6 +130,8 @@ namespace clap { } } + pluginToGuiQueue_.producerDone(); + return CLAP_PROCESS_CONTINUE_IF_NOT_QUIET; } } // namespace clap \ No newline at end of file diff --git a/examples/plugins/remote-gui.cc b/examples/plugins/remote-gui.cc @@ -190,4 +190,12 @@ namespace clap { return channel_->sendRequestSync(request, response); } + void RemoteGui::onTimer() { + plugin_.pluginToGuiQueue_.consume( + [this](clap_id paramId, const CorePlugin::PluginToGuiValue &value) { + messages::ParameterValueRequest rq{paramId, value.value, value.mod}; + channel_->sendRequestAsync(rq); + }); + } + } // namespace clap \ No newline at end of file diff --git a/examples/plugins/remote-gui.hh b/examples/plugins/remote-gui.hh @@ -38,6 +38,8 @@ namespace clap { clap_fd fd() const; void onFd(clap_fd_flags flags); + void onTimer(); + private: void onMessage(const RemoteChannel::Message& msg); void waitChild();