clap

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

commit 85397a670cb5f79b7f90ff8e7029779243821dc2
parent 7ffbf5150078b90031cd8dc617cadcd8f37e4bf8
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date:   Mon,  9 Aug 2021 00:07:43 +0200

More work on ParameterProxy

Diffstat:
Mexamples/gui/application.hh | 6+++++-
Mexamples/gui/parameter-proxy.cc | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
Mexamples/gui/parameter-proxy.hh | 40++++++++++++++++++++++++++++++++++------
Mexamples/gui/plugin-proxy.cc | 6++++++
Mexamples/gui/plugin-proxy.hh | 4+++-
Mexamples/io/messages.hh | 19+++++++++++++++++++
6 files changed, 129 insertions(+), 12 deletions(-)

diff --git a/examples/gui/application.hh b/examples/gui/application.hh @@ -15,10 +15,14 @@ class Application : public QGuiApplication, public clap::RemoteChannel::EventCon public: Application(int argc, char **argv); + clap::RemoteChannel& remoteChannel() const { return *remoteChannel_; } void modifyFd(clap_fd_flags flags) override; - void onMessage(const clap::RemoteChannel::Message& msg); + + static Application& instance() { return *dynamic_cast<Application *>(QCoreApplication::instance()); } private: + void onMessage(const clap::RemoteChannel::Message& msg); + QQuickView *quickView_ = nullptr; QSocketNotifier *socketReadNotifier_ = nullptr; QSocketNotifier *socketWriteNotifier_ = nullptr; diff --git a/examples/gui/parameter-proxy.cc b/examples/gui/parameter-proxy.cc @@ -1,11 +1,68 @@ #include "parameter-proxy.hh" +#include "../io/messages.hh" +#include "application.hh" + +ParameterProxy::ParameterProxy(const clap_param_info &info, QObject *parent) + : QObject(parent), id_(info.id), name_(info.name), module_(info.module), + minValue_(info.min_value), maxValue_(info.max_value), defaultValue_(info.default_value) {} + +void ParameterProxy::setIsAdjusting(bool isAdjusting) { + if (isAdjusting == isAdjusting_) + return; + + isAdjusting_ = isAdjusting; + if (isAdjusting) { + clap::messages::BeginAdjustRequest rq{id_}; + Application::instance().remoteChannel().sendRequestAsync(rq); + } else { + clap::messages::EndAdjustRequest rq{id_}; + Application::instance().remoteChannel().sendRequestAsync(rq); + } +} + +void ParameterProxy::setValueFromUI(double value) { + value_ = value; + + clap::messages::AdjustRequest rq{id_, value_}; + Application::instance().remoteChannel().sendRequestAsync(rq); +} + +void ParameterProxy::setValueFromPlugin(double value) { + if (value == value_) + return; -void ParameterProxy::setValue(double value) { - // TODO: send notification value_ = value; + valueChanged(); } -void ParameterProxy::setModulation(double mod) { - // TODO send notification +void ParameterProxy::setModulationFromPlugin(double mod) { + if (mod == modulation_) + return; + modulation_ = mod; + modulationChanged(); } + +void ParameterProxy::setMinValueFromPlugin(double minValue) { + if (minValue == minValue_) + return; + + minValue_ = minValue; + minValueChanged(); +} + +void ParameterProxy::setMaxValueFromPlugin(double maxValue) { + if (maxValue == maxValue_) + return; + + maxValue_ = maxValue; + maxValueChanged(); +} + +void ParameterProxy::setDefaultValueFromPlugin(double defaultValue) { + if (defaultValue == defaultValue_) + return; + + defaultValue_ = defaultValue; + defaultValueChanged(); +} +\ No newline at end of file diff --git a/examples/gui/parameter-proxy.hh b/examples/gui/parameter-proxy.hh @@ -2,32 +2,60 @@ #include <QObject> +#include <clap/all.h> + class ParameterProxy : public QObject { Q_OBJECT Q_PROPERTY(uint32_t id READ getId) Q_PROPERTY(QString name READ getName NOTIFY nameChanged) Q_PROPERTY(QString module READ getModule) - Q_PROPERTY(double value READ getValue WRITE setValue NOTIFY valueChanged) + Q_PROPERTY(double value READ getValue WRITE setValueFromUI NOTIFY valueChanged) Q_PROPERTY(double modulation READ getModulation NOTIFY modulationChanged) + Q_PROPERTY(double minValue READ getMinValue NOTIFY minValueChanged) + Q_PROPERTY(double maxValue READ getMaxValue NOTIFY maxValueChanged) + Q_PROPERTY(double defaultValue READ getDefaultValue NOTIFY defaultValueChanged) + Q_PROPERTY(bool isAdjusting READ isAdjusting WRITE setIsAdjusting) public: + ParameterProxy(const clap_param_info &info, QObject *parent = nullptr); + uint32_t getId() const { return id_; } const QString &getModule() const { return module_; } const QString &getName() const { return name_; } + double getValue() const { return value_; } - void setValue(double value); + void setValueFromUI(double value); + void setValueFromPlugin(double value); + double getModulation() const { return modulation_; } - void setModulation(double mod); + void setModulationFromPlugin(double mod); + + bool isAdjusting() const { return isAdjusting_; } + void setIsAdjusting(bool isAdjusting); + + double getMinValue() const { return minValue_; } + void setMinValueFromPlugin(double minValue); + double getMaxValue() const { return maxValue_; } + void setMaxValueFromPlugin(double maxValue); + double getDefaultValue() const { return defaultValue_; } + void setDefaultValueFromPlugin(double defaultValue); signals: void nameChanged(); void valueChanged(); void modulationChanged(); + void minValueChanged(); + void maxValueChanged(); + void defaultValueChanged(); private: - uint32_t id_; + const uint32_t id_; QString name_; QString module_; - double value_; - double modulation_; + double value_ = 0; + double modulation_ = 0; + double minValue_ = 0; + double maxValue_ = 0; + double defaultValue_ = 0; + bool isAdjusting_ = false; }; \ No newline at end of file diff --git a/examples/gui/plugin-proxy.cc b/examples/gui/plugin-proxy.cc @@ -8,3 +8,8 @@ ParameterProxy *PluginProxy::param(clap_id paramId) const { } QString PluginProxy::toString() const { return "Plugin"; } + +void PluginProxy::defineParameter(const clap_param_info &info) +{ + +} +\ No newline at end of file diff --git a/examples/gui/plugin-proxy.hh b/examples/gui/plugin-proxy.hh @@ -3,7 +3,7 @@ #include <QHash> #include <QObject> -#include <clap/clap.h> +#include <clap/all.h> #include "parameter-proxy.hh" @@ -13,6 +13,8 @@ class PluginProxy : public QObject { public: PluginProxy(QObject *parent = nullptr); + void defineParameter(const clap_param_info& info); + Q_INVOKABLE ParameterProxy *param(clap_id paramId) const; Q_INVOKABLE QString toString() const; diff --git a/examples/io/messages.hh b/examples/io/messages.hh @@ -37,6 +37,25 @@ namespace clap::messages { kResizeResponse, }; + struct BeginAdjustRequest final { + static const constexpr Type type = clap::messages::kBeginAdjustRequest; + + clap_id paramId; + }; + + struct AdjustRequest final { + static const constexpr Type type = clap::messages::kAdjustRequest; + + clap_id paramId; + double value; + }; + + struct EndAdjustRequest final { + static const constexpr Type type = clap::messages::kEndAdjustRequest; + + clap_id paramId; + }; + struct DefineParameterRequest final { static const constexpr Type type = kDefineParameterRequest; clap_param_info info;