clap

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

commit f35949d0a2f7f80f4d7dc0763db4e29505655b73
parent ccfe150965564dab70285bd7290370b6fc3f7c2e
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date:   Tue, 17 Aug 2021 16:57:39 +0200

Lazily define parameter proxies

Diffstat:
Mexamples/gui/application.cc | 3++-
Mexamples/gui/parameter-proxy.cc | 26+++++++++++++++++++++++++-
Mexamples/gui/parameter-proxy.hh | 6+++++-
Mexamples/gui/plugin-proxy.cc | 15++++++++++++---
Mexamples/gui/plugin-proxy.hh | 2+-
Mexamples/plugins/dc-offset/skin/main.qml | 6+++---
6 files changed, 48 insertions(+), 10 deletions(-)

diff --git a/examples/gui/application.cc b/examples/gui/application.cc @@ -28,10 +28,11 @@ Application::Application(int& argc, char **argv) pluginProxy_ = new PluginProxy(this); - quickView_->setSource(parser.value(skinOpt) + "/main.qml"); auto qmlContext = quickView_->engine()->rootContext(); qmlContext->setContextProperty("plugin", pluginProxy_); + quickView_->setSource(parser.value(skinOpt) + "/main.qml"); + auto socket = parser.value(socketOpt).toULongLong(); socketReadNotifier_.reset(new QSocketNotifier(socket, QSocketNotifier::Read, this)); diff --git a/examples/gui/parameter-proxy.cc b/examples/gui/parameter-proxy.cc @@ -4,7 +4,31 @@ 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) {} + value_(info.default_value), minValue_(info.min_value), maxValue_(info.max_value), + defaultValue_(info.default_value) {} + +ParameterProxy::ParameterProxy(clap_id param_id, QObject *parent) + : QObject(parent), id_(param_id) {} + +void ParameterProxy::redefine(const clap_param_info &info) { + Q_ASSERT(id_ == info.id); + + if (name_ != info.name) { + name_ = info.name; + nameChanged(); + } + + if (module_ != info.module) { + module_ = info.module; + moduleChanged(); + } + + setMinValueFromPlugin(info.min_value); + setMaxValueFromPlugin(info.max_value); + setDefaultValueFromPlugin(info.default_value); + + setValueFromPlugin(std::min(maxValue_, std::max(minValue_, value_))); +} void ParameterProxy::setIsAdjusting(bool isAdjusting) { if (isAdjusting == isAdjusting_) diff --git a/examples/gui/parameter-proxy.hh b/examples/gui/parameter-proxy.hh @@ -8,7 +8,7 @@ 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(QString module READ getModule NOTIFY moduleChanged) Q_PROPERTY(double value READ getValue WRITE setValueFromUI NOTIFY valueChanged) Q_PROPERTY(double normalizedValue READ getNormalizedValue WRITE setNormalizedValueFromUI NOTIFY valueChanged) @@ -21,6 +21,9 @@ class ParameterProxy : public QObject { public: ParameterProxy(const clap_param_info &info, QObject *parent = nullptr); + ParameterProxy(clap_id param_id, QObject *parent = nullptr); + + void redefine(const clap_param_info &info); uint32_t getId() const { return id_; } const QString &getModule() const { return module_; } @@ -62,6 +65,7 @@ public: signals: void nameChanged(); + void moduleChanged(); void valueChanged(); void modulationChanged(); void minValueChanged(); diff --git a/examples/gui/plugin-proxy.cc b/examples/gui/plugin-proxy.cc @@ -2,14 +2,23 @@ PluginProxy::PluginProxy(QObject *parent) : QObject(parent) {} -ParameterProxy *PluginProxy::param(clap_id paramId) const { +ParameterProxy *PluginProxy::param(clap_id paramId) { auto it = parameters_.find(paramId); - return it != parameters_.end() ? it->second : nullptr; + if (it != parameters_.end()) + return it->second; + + auto *p = new ParameterProxy(paramId, this); + parameters_.emplace(paramId, p); + return p; } QString PluginProxy::toString() const { return "Plugin"; } void PluginProxy::defineParameter(const clap_param_info &info) { - parameters_.emplace(info.id, new ParameterProxy(info, this)); + auto it = parameters_.find(info.id); + if (it != parameters_.end()) + it->second->redefine(info); + else + parameters_.emplace(info.id, new ParameterProxy(info, this)); } \ No newline at end of file diff --git a/examples/gui/plugin-proxy.hh b/examples/gui/plugin-proxy.hh @@ -15,7 +15,7 @@ public: void defineParameter(const clap_param_info& info); - Q_INVOKABLE ParameterProxy *param(clap_id paramId) const; + Q_INVOKABLE ParameterProxy *param(clap_id paramId); Q_INVOKABLE QString toString() const; private: diff --git a/examples/plugins/dc-offset/skin/main.qml b/examples/plugins/dc-offset/skin/main.qml @@ -6,8 +6,8 @@ Rectangle { height: 200 color: "#224477" - /*Dial { - property QtObject param: plugin.getParam(0) + Dial { + property QtObject param: plugin.param(0) inputMode: Dial.Vertical - }*/ + } } \ No newline at end of file