clap

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

commit 9e7b68dead09d830e54478bb1cb86da94be96c28
parent 8a28dc58aa077b6c517c62b6ba0e0a00660b7d85
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date:   Tue, 14 Sep 2021 21:36:53 +0200

Use the new param queue

Diffstat:
Mexamples/host/plugin-host.cc | 18++++++++++--------
Mexamples/plugins/core-plugin.cc | 14+++++++-------
Mexamples/plugins/core-plugin.hh | 6++++--
3 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/examples/host/plugin-host.cc b/examples/host/plugin-host.cc @@ -1,4 +1,4 @@ -#include <exception> +#include <exception> #include <iostream> #include <memory> #include <sstream> @@ -717,20 +717,22 @@ void PluginHost::process() { for (auto &ev : _evOut) { switch (ev.type) { case CLAP_EVENT_PARAM_VALUE: { + bool &isAdj = _isAdjusting[ev.param_value.param_id]; + if (ev.param_value.flags & CLAP_EVENT_PARAM_BEGIN_ADJUST) { - if (_isAdjusting[ev.param_value.param_id]) + if (isAdj) throw std::logic_error("The plugin sent BEGIN_ADJUST twice"); - _isAdjusting[ev.param_value.param_id] = true; + isAdj = true; } if (ev.param_value.flags & CLAP_EVENT_PARAM_END_ADJUST) { - if (!_isAdjusting[ev.param_value.param_id]) - throw std::logic_error("The plugin sent END_ADJUST without a preceding BEGIN_ADJUST"); - _isAdjusting[ev.param_value.param_id] = false; + if (!isAdj) + throw std::logic_error( + "The plugin sent END_ADJUST without a preceding BEGIN_ADJUST"); + isAdj = false; } - _engineToAppValueQueue.set(ev.param_value.param_id, - {ev.param_value.value, _isAdjusting[ev.param_value.param_id]}); + _engineToAppValueQueue.set(ev.param_value.param_id, {ev.param_value.value, isAdj}); break; } } diff --git a/examples/plugins/core-plugin.cc b/examples/plugins/core-plugin.cc @@ -171,13 +171,13 @@ namespace clap { } void CorePlugin::guiAdjust(clap_id paramId, double value, clap_event_param_flags flags) { - _guiToPluginQueue.set(paramId, {value, flags}); - _guiToPluginQueue.producerDone(); + _guiToPluginQueue.push({paramId, value, flags}); } void CorePlugin::processGuiEvents(const clap_process *process) { - _guiToPluginQueue.consume([this, process](clap_id paramId, const GuiToPluginValue &value) { - auto p = _parameters.getById(paramId); + GuiToPluginValue value; + while (_guiToPluginQueue.tryPop(value)) { + auto p = _parameters.getById(value.paramId); if (!p) return; p->setValueSmoothed(value.value, std::max<int>(process->frames_count, 128)); @@ -185,7 +185,7 @@ namespace clap { clap_event ev; ev.time = 0; ev.type = CLAP_EVENT_PARAM_VALUE; - ev.param_value.param_id = paramId; + ev.param_value.param_id = value.paramId; ev.param_value.value = value.value; ev.param_value.channel = -1; ev.param_value.key = -1; @@ -193,7 +193,7 @@ namespace clap { ev.param_value.cookie = p; process->out_events->push_back(process->out_events, &ev); - }); + } } uint32_t CorePlugin::processEvents(const clap_process *process, @@ -225,7 +225,7 @@ namespace clap { } p->setValueSmoothed(ev->param_value.value, _paramSmoothingDuration); - //p->setValueImmediately(ev->param_value.value); + // p->setValueImmediately(ev->param_value.value); _pluginToGuiQueue.set(p->info().id, {ev->param_value.value, p->modulation()}); } break; diff --git a/examples/plugins/core-plugin.hh b/examples/plugins/core-plugin.hh @@ -8,6 +8,7 @@ #include "path-provider.hh" #include "remote-gui.hh" +#include "../common/param-queue.hh" #include "../common/reducing-param-queue.hxx" namespace clap { @@ -156,9 +157,10 @@ namespace clap { void guiAdjust(clap_id paramId, double value, clap_event_param_flags flags); void processGuiEvents(const clap_process *process); uint32_t - processEvents(const clap_process *process, uint32_t& index, uint32_t count, uint32_t time); + processEvents(const clap_process *process, uint32_t &index, uint32_t count, uint32_t time); struct GuiToPluginValue { + clap_id paramId; double value; clap_event_param_flags flags; }; @@ -168,7 +170,7 @@ namespace clap { double mod; }; - ReducingParamQueue<GuiToPluginValue> _guiToPluginQueue; + ParamQueue<GuiToPluginValue, 32> _guiToPluginQueue; ReducingParamQueue<PluginToGuiValue> _pluginToGuiQueue; std::unique_ptr<PathProvider> _pathProvider;