clap

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

commit aa9b8906a4f85f8ff7895513d7f233e587d28a36
parent 028aa252b6e53bdd7de4d449bb678883331658f1
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date:   Mon, 12 Jul 2021 17:33:53 +0200

Update the plugin host


Diffstat:
Mexamples/host/param-queue.cc | 8+++++---
Mexamples/host/param-queue.hh | 11++++++++---
Mexamples/host/plugin-host.cc | 25+++++++++++--------------
3 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/examples/host/param-queue.cc b/examples/host/param-queue.cc @@ -18,7 +18,9 @@ void ParamQueue::setCapacity(size_t capacity) { q.reserve(2 * capacity); } -void ParamQueue::set(clap_id id, double value) { producer_.load()->emplace(id, value); } +void ParamQueue::set(clap_id id, void *cookie, double value) { + producer_.load()->emplace(id, value_type{cookie, value}); +} void ParamQueue::producerDone() { if (consumer_) @@ -31,14 +33,14 @@ void ParamQueue::producerDone() { Q_ASSERT(producer_); } -void ParamQueue::consume(const std::function<void(clap_id, double)> consumer) { +void ParamQueue::consume(const std::function<void(clap_id, void *, double)> consumer) { Q_ASSERT(consumer); if (!consumer_) return; for (auto &x : *consumer_) - consumer(x.first, x.second); + consumer(x.first, x.second.cookie, x.second.value); consumer_.load()->clear(); if (free_) diff --git a/examples/host/param-queue.hh b/examples/host/param-queue.hh @@ -8,16 +8,21 @@ class ParamQueue { public: - using queue_type = std::unordered_map<clap_id, double>; + using value_type = struct { + void *cookie; + double value; + }; + + using queue_type = std::unordered_map<clap_id, value_type>; ParamQueue(); void setCapacity(size_t capacity); - void set(clap_id id, double value); + void set(clap_id id, void *cookie, double value); void producerDone(); - void consume(const std::function<void(clap_id id, double value)> consumer); + void consume(const std::function<void(clap_id id, void *cookie, double value)> consumer); void reset(); diff --git a/examples/host/plugin-host.cc b/examples/host/plugin-host.cc @@ -603,18 +603,15 @@ void PluginHost::process() { process_.audio_outputs_count = 1; evOut_.clear(); - appToEngineQueue_.consume([this](clap_id param_id, double value) { + appToEngineQueue_.consume([this](clap_id param_id, void *cookie, double value) { clap_event ev; ev.time = 0; - ev.type = CLAP_EVENT_PARAM_SET; - ev.param.param_id = param_id; - ev.param.key = -1; - ev.param.channel = -1; - ev.param.val0 = value; - ev.param.val1 = value; - ev.param.mod0 = 0; - ev.param.mod1 = 0; - ev.param.distance = process_.frames_count; + ev.type = CLAP_EVENT_PARAM_VALUE; + ev.param_value.param_id = param_id; + ev.param_value.cookie = cookie; + ev.param_value.key = -1; + ev.param_value.channel = -1; + ev.param_value.value = value; evIn_.push_back(ev); }); @@ -631,8 +628,8 @@ void PluginHost::process() { for (auto &ev : evOut_) { switch (ev.type) { - case CLAP_EVENT_PARAM_SET: - engineToAppQueue_.set(ev.param.param_id, ev.param.val0); + case CLAP_EVENT_PARAM_VALUE: + engineToAppQueue_.set(ev.param_value.param_id, ev.param_value.cookie, ev.param_value.value); break; } } @@ -653,7 +650,7 @@ void PluginHost::idle() { // Try to send events to the audio engine appToEngineQueue_.producerDone(); - engineToAppQueue_.consume([this](clap_id param_id, double value) { + engineToAppQueue_.consume([this](clap_id param_id, void *cookie, double value) { auto it = params_.find(param_id); if (it == params_.end()) { std::ostringstream msg; @@ -706,7 +703,7 @@ void PluginHost::setParamValueByHost(PluginParam &param, double value) { param.setValue(value); - appToEngineQueue_.set(param.info().id, value); + appToEngineQueue_.set(param.info().id, param.info().cookie, value); appToEngineQueue_.producerDone(); }