commit 162fa44fad3419a87d99b930cc409cb67672a59a
parent 7362b02cd373a63e72e0d27f3c700f568989038c
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date: Sun, 8 Aug 2021 22:00:28 +0200
Prepare the QML object binding
Diffstat:
9 files changed, 99 insertions(+), 3 deletions(-)
diff --git a/examples/gui/CMakeLists.txt b/examples/gui/CMakeLists.txt
@@ -8,6 +8,11 @@ add_executable(clap-gui
application.hh
application.cc
+
+ qml-parameter.hh
+ qml-parameter.cc
+ qml-plugin.hh
+ qml-plugin.cc
)
target_compile_options(clap-gui PRIVATE -fsanitize=address)
target_link_options(clap-gui PRIVATE -fsanitize=address)
diff --git a/examples/gui/application.cc b/examples/gui/application.cc
@@ -1,5 +1,7 @@
#include <QCommandLineParser>
#include <QQuickView>
+#include <QQmlEngine>
+#include <QQmlContext>
#include <QWindow>
#include "../io/messages.hh"
@@ -23,7 +25,11 @@ Application::Application(int argc, char **argv)
parser.process(*this);
+ plugin_ = new PluginProxy(this);
+
quickView_->setSource(parser.value(skinOpt) + "/main.qml");
+ auto qmlContext = quickView_->engine()->rootContext();
+ qmlContext->setContextProperty("plugin", plugin_);
auto socket = parser.value(socketOpt).toULongLong();
diff --git a/examples/gui/application.hh b/examples/gui/application.hh
@@ -5,6 +5,7 @@
#include <QWindow>
#include "../io/remote-channel.hh"
+#include "plugin-proxy.hh"
class QQuickView;
@@ -26,4 +27,5 @@ private:
std::unique_ptr<QWindow> hostWindow_ = nullptr;
std::unique_ptr<clap::RemoteChannel> remoteChannel_;
+ PluginProxy *plugin_ = nullptr;
};
\ No newline at end of file
diff --git a/examples/gui/parameter-proxy.cc b/examples/gui/parameter-proxy.cc
@@ -0,0 +1,11 @@
+#include "parameter-proxy.hh"
+
+void ParameterProxy::setValue(double value) {
+ // TODO: send notification
+ value_ = value;
+}
+
+void ParameterProxy::setModulation(double mod) {
+ // TODO send notification
+ modulation_ = mod;
+}
diff --git a/examples/gui/parameter-proxy.hh b/examples/gui/parameter-proxy.hh
@@ -0,0 +1,33 @@
+#pragma once
+
+#include <QObject>
+
+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 modulation READ getModulation NOTIFY modulationChanged)
+
+public:
+ 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);
+ double getModulation() const { return modulation_; }
+ void setModulation(double mod);
+
+signals:
+ void nameChanged();
+ void valueChanged();
+ void modulationChanged();
+
+private:
+ uint32_t id_;
+ QString name_;
+ QString module_;
+ double value_;
+ double modulation_;
+};
+\ No newline at end of file
diff --git a/examples/gui/plugin-proxy.cc b/examples/gui/plugin-proxy.cc
@@ -0,0 +1,10 @@
+#include "plugin-proxy.hh"
+
+PluginProxy::PluginProxy(QObject *parent) : QObject(parent) {}
+
+ParameterProxy *PluginProxy::param(clap_id paramId) const {
+ auto it = parameters_.find(paramId);
+ return it != parameters_.end() ? it->second : nullptr;
+}
+
+QString PluginProxy::toString() const { return "Plugin"; }
diff --git a/examples/gui/plugin-proxy.hh b/examples/gui/plugin-proxy.hh
@@ -0,0 +1,21 @@
+#pragma once
+
+#include <QHash>
+#include <QObject>
+
+#include <clap/clap.h>
+
+#include "parameter-proxy.hh"
+
+class PluginProxy : public QObject {
+ Q_OBJECT
+
+public:
+ PluginProxy(QObject *parent = nullptr);
+
+ Q_INVOKABLE ParameterProxy *param(clap_id paramId) const;
+ Q_INVOKABLE QString toString() const;
+
+private:
+ std::unordered_map<clap_id, ParameterProxy *> parameters_;
+};
+\ No newline at end of file
diff --git a/examples/plugins/dc-offset/skin/main.qml b/examples/plugins/dc-offset/skin/main.qml
@@ -1,5 +1,11 @@
import QtQuick 2.0
-Text {
- text: "Hello World!"
+Rectangle {
+ width: 300
+ height: 200
+ color: "#224477"
+
+ Text {
+ text: "Hello World!"
+ }
}
\ No newline at end of file
diff --git a/examples/plugins/remote-gui.cc b/examples/plugins/remote-gui.cc
@@ -49,7 +49,7 @@ namespace clap {
::snprintf(socketStr, sizeof(socketStr), "%d", sockets[1]);
auto path = pathProvider.getGuiExecutable();
auto skin = pathProvider.getSkinDirectory();
- ::execl(path.c_str(), path.c_str(), "--socket", socketStr, "--skin", skin.c_str(), nullptr);
+ ::execl(path.c_str(), path.c_str(), "--socket", socketStr, "--skin", skin.c_str(), (const char *)nullptr);
printf("Failed to start child process: %m\n");
std::terminate();
} else {