clap

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

commit e8b4aa2eb392514e1a9096479b1872ce7dc9265e
parent 63f8872c991cf7f5220317b151277e35fcb93e0f
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date:   Tue, 14 Sep 2021 18:35:26 +0200

Refactoring

Diffstat:
Mexamples/common/CMakeLists.txt | 6+++---
Dexamples/common/param-queue.hh | 32--------------------------------
Dexamples/common/param-queue.hxx | 59-----------------------------------------------------------
Aexamples/common/reducing-param-queue.hh | 32++++++++++++++++++++++++++++++++
Aexamples/common/reducing-param-queue.hxx | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mexamples/host/plugin-host.cc | 2+-
Mexamples/host/plugin-host.hh | 8++++----
Mexamples/plugins/core-plugin.hh | 6+++---
Mexamples/plugins/gui/parameter-proxy.cc | 1+
Mexamples/plugins/qml/clap/Knob.qml | 20++++++++++++++++----
10 files changed, 119 insertions(+), 106 deletions(-)

diff --git a/examples/common/CMakeLists.txt b/examples/common/CMakeLists.txt @@ -1,3 +1,3 @@ # add_library(clap-common EXCLUDE_FROM_ALL -# param-queue.hxx -# param-queue.hh) -\ No newline at end of file +# reducing-param-queue.hxx +# reducing-param-queue.hh) +\ No newline at end of file diff --git a/examples/common/param-queue.hh b/examples/common/param-queue.hh @@ -1,31 +0,0 @@ -#pragma once - -#include <atomic> -#include <functional> -#include <unordered_map> - -#include <clap/all.h> - -template <typename T> -class ParamQueue { -public: - using value_type = T; - using queue_type = std::unordered_map<clap_id, value_type>; - - ParamQueue(); - - void setCapacity(size_t capacity); - - void set(clap_id id, const value_type &value); - void producerDone(); - - void consume(const std::function<void(clap_id id, const value_type &value)> consumer); - - void reset(); - -private: - queue_type _queues[2]; - std::atomic<queue_type *> _free = nullptr; - std::atomic<queue_type *> _producer = nullptr; - std::atomic<queue_type *> _consumer = nullptr; -}; -\ No newline at end of file diff --git a/examples/common/param-queue.hxx b/examples/common/param-queue.hxx @@ -1,59 +0,0 @@ -#pragma once - -#include <cassert> - -#include "param-queue.hh" - -template<typename T> -ParamQueue<T>::ParamQueue() { reset(); } - -template<typename T> -void ParamQueue<T>::reset() { - for (auto &q : _queues) - q.clear(); - - _free = &_queues[0]; - _producer = &_queues[1]; - _consumer = nullptr; -} - -template<typename T> -void ParamQueue<T>::setCapacity(size_t capacity) { - for (auto &q : _queues) - q.reserve(2 * capacity); -} - -template<typename T> -void ParamQueue<T>::set(clap_id id, const value_type& value) { - _producer.load()->emplace(id, value); -} - -template<typename T> -void ParamQueue<T>::producerDone() { - if (_consumer) - return; - - _consumer.store(_producer.load()); - _producer.store(_free.load()); - _free.store(nullptr); - - assert(_producer); -} - -template<typename T> -void ParamQueue<T>::consume(const std::function<void(clap_id, const value_type& value)> consumer) { - assert(consumer); - - if (!_consumer) - return; - - for (auto &x : *_consumer) - consumer(x.first, x.second); - - _consumer.load()->clear(); - if (_free) - return; - - _free = _consumer.load(); - _consumer = nullptr; -} diff --git a/examples/common/reducing-param-queue.hh b/examples/common/reducing-param-queue.hh @@ -0,0 +1,31 @@ +#pragma once + +#include <atomic> +#include <functional> +#include <unordered_map> + +#include <clap/all.h> + +template <typename T> +class ReducingParamQueue { +public: + using value_type = T; + using queue_type = std::unordered_map<clap_id, value_type>; + + ReducingParamQueue(); + + void setCapacity(size_t capacity); + + void set(clap_id id, const value_type &value); + void producerDone(); + + void consume(const std::function<void(clap_id id, const value_type &value)> consumer); + + void reset(); + +private: + queue_type _queues[2]; + std::atomic<queue_type *> _free = nullptr; + std::atomic<queue_type *> _producer = nullptr; + std::atomic<queue_type *> _consumer = nullptr; +}; +\ No newline at end of file diff --git a/examples/common/reducing-param-queue.hxx b/examples/common/reducing-param-queue.hxx @@ -0,0 +1,59 @@ +#pragma once + +#include <cassert> + +#include "reducing-param-queue.hh" + +template<typename T> +ReducingParamQueue<T>::ReducingParamQueue() { reset(); } + +template<typename T> +void ReducingParamQueue<T>::reset() { + for (auto &q : _queues) + q.clear(); + + _free = &_queues[0]; + _producer = &_queues[1]; + _consumer = nullptr; +} + +template<typename T> +void ReducingParamQueue<T>::setCapacity(size_t capacity) { + for (auto &q : _queues) + q.reserve(2 * capacity); +} + +template<typename T> +void ReducingParamQueue<T>::set(clap_id id, const value_type& value) { + _producer.load()->emplace(id, value); +} + +template<typename T> +void ReducingParamQueue<T>::producerDone() { + if (_consumer) + return; + + _consumer.store(_producer.load()); + _producer.store(_free.load()); + _free.store(nullptr); + + assert(_producer); +} + +template<typename T> +void ReducingParamQueue<T>::consume(const std::function<void(clap_id, const value_type& value)> consumer) { + assert(consumer); + + if (!_consumer) + return; + + for (auto &x : *_consumer) + consumer(x.first, x.second); + + _consumer.load()->clear(); + if (_free) + return; + + _free = _consumer.load(); + _consumer = nullptr; +} diff --git a/examples/host/plugin-host.cc b/examples/host/plugin-host.cc @@ -13,7 +13,7 @@ #include "main-window.hh" #include "plugin-host.hh" -#include "../common/param-queue.hxx" +#include "../common/reducing-param-queue.hxx" enum ThreadType { Unknown, diff --git a/examples/host/plugin-host.hh b/examples/host/plugin-host.hh @@ -15,7 +15,7 @@ #include <clap/all.h> -#include "../common/param-queue.hh" +#include "../common/reducing-param-queue.hh" #include "engine.hh" #include "plugin-param.hh" @@ -225,9 +225,9 @@ PluginHost::clapParamsRescan, bool isAdjusting; }; - ParamQueue<AppToEngineParamQueueValue> _appToEngineValueQueue; - ParamQueue<AppToEngineParamQueueValue> _appToEngineModQueue; - ParamQueue<EngineToAppParamQueueValue> _engineToAppValueQueue; + ReducingParamQueue<AppToEngineParamQueueValue> _appToEngineValueQueue; + ReducingParamQueue<AppToEngineParamQueueValue> _appToEngineModQueue; + ReducingParamQueue<EngineToAppParamQueueValue> _engineToAppValueQueue; std::unordered_map<clap_id, bool> _isAdjusting; diff --git a/examples/plugins/core-plugin.hh b/examples/plugins/core-plugin.hh @@ -8,7 +8,7 @@ #include "path-provider.hh" #include "remote-gui.hh" -#include "../common/param-queue.hxx" +#include "../common/reducing-param-queue.hxx" namespace clap { class CorePlugin : public Plugin { @@ -168,8 +168,8 @@ namespace clap { double mod; }; - ParamQueue<GuiToPluginValue> _guiToPluginQueue; - ParamQueue<PluginToGuiValue> _pluginToGuiQueue; + ReducingParamQueue<GuiToPluginValue> _guiToPluginQueue; + ReducingParamQueue<PluginToGuiValue> _pluginToGuiQueue; std::unique_ptr<PathProvider> _pathProvider; diff --git a/examples/plugins/gui/parameter-proxy.cc b/examples/plugins/gui/parameter-proxy.cc @@ -34,6 +34,7 @@ void ParameterProxy::setIsAdjusting(bool isAdjusting) { if (isAdjusting == _isAdjusting) return; + qDebug() << "C++ isAdjusting: " << isAdjusting << ", " << "_isAdjusting: " << _isAdjusting; _isAdjusting = isAdjusting; clap_event_param_flags flags = CLAP_EVENT_PARAM_SHOULD_RECORD; flags |= isAdjusting ? CLAP_EVENT_PARAM_BEGIN_ADJUST : CLAP_EVENT_PARAM_END_ADJUST; diff --git a/examples/plugins/qml/clap/Knob.qml b/examples/plugins/qml/clap/Knob.qml @@ -38,25 +38,36 @@ Canvas { hoverEnabled: true acceptedButtons: Qt.LeftButton | Qt.RightButton + function myDump(name, mouse) { + console.log(name + ": " + mouse.button + "; " + mouse.buttons) + } + onPressed: (mouse) => { + myDump("onPressed", mouse) if (mouse.button === Qt.LeftButton) { lastY = mouse.y; knob.param.isAdjusting = true; + console.log("begin adjust") knob.requestPaint(); mouse.accepted = true; } } onReleased: (mouse) => { - if (mouse.button === Qt.LeftButton || !(mouse.buttons & Qt.LeftButton)) { + myDump("onReleased", mouse) + if (mouse.button === Qt.LeftButton) { knob.param.isAdjusting = false; + console.log("end adjust") knob.requestPaint(); } } onPositionChanged: (mouse) => { - if (!(mouse.buttons & Qt.LeftButton)) + // myDump("onPositionChanged", mouse) + if (!(mouse.buttons & Qt.LeftButton)) { + //knob.param.isAdjusting = false; return; + } knob.param.normalizedValue += ((mouse.modifiers & Qt.ShiftModifier) ? 0.001 : 0.01) * (lastY - mouse.y); lastY = mouse.y; mouse.accepted = true; @@ -72,16 +83,17 @@ Canvas { } onCanceled: (mouse) => { + myDump("onCanceled", mouse) knob.param.isAdjusting = false; knob.requestPaint(); } - onEntered: (mouse) => { + onEntered: () => { knob.param.isHovered = true; knob.requestPaint(); } - onExited: (mouse) => { + onExited: () => { knob.param.isHovered = false; knob.requestPaint(); }