clap

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

commit 0e352f612564092b385d489eb2a415e416f7c20e
parent 1865494172c3c6444357ccd2ddbec5d3de82c458
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date:   Tue,  3 Aug 2021 08:40:14 +0200

Begin some work on clap-gui

Diffstat:
Mexamples/gui/application.cc | 45+++++++++++++++++++++++++++++++++++++++++++++
Mexamples/gui/application.hh | 13++++++++++++-
Mexamples/io/remote-channel.cc | 5+++--
Mexamples/io/remote-channel.hh | 3+++
Aexamples/plugins/dc-offset/qml/main.qml | 6++++++
5 files changed, 69 insertions(+), 3 deletions(-)

diff --git a/examples/gui/application.cc b/examples/gui/application.cc @@ -1,6 +1,7 @@ #include <QCommandLineParser> #include <QQmlApplicationEngine> +#include "../io/messages.hh" #include "application.hh" Application::Application(int argc, char **argv) @@ -20,4 +21,48 @@ Application::Application(int argc, char **argv) qmlEngine_->load(parser.value(qmlOpt)); if (qmlEngine_->rootObjects().empty()) throw std::invalid_argument("bad qml file"); + + auto socket = parser.value(socketOpt).toULongLong(); + + socketReadNotifier_ = new QSocketNotifier(socket, QSocketNotifier::Read, this); + socketReadNotifier_->setEnabled(true); + connect( + socketReadNotifier_, + &QSocketNotifier::activated, + [this](QSocketDescriptor socket, QSocketNotifier::Type type) { remoteChannel_->onRead(); }); + + socketWriteNotifier_ = new QSocketNotifier(socket, QSocketNotifier::Write, this); + socketWriteNotifier_->setEnabled(false); + connect( + socketWriteNotifier_, + &QSocketNotifier::activated, + [this](QSocketDescriptor socket, QSocketNotifier::Type type) { remoteChannel_->onWrite(); }); + + socketErrorNotifier_ = new QSocketNotifier(socket, QSocketNotifier::Exception, this); + socketErrorNotifier_->setEnabled(false); + connect(socketErrorNotifier_, + &QSocketNotifier::activated, + [this](QSocketDescriptor socket, QSocketNotifier::Type type) { + remoteChannel_->onError(); + quit(); + }); + + remoteChannel_.reset(new clap::RemoteChannel( + [this](const clap::RemoteChannel::Message &msg) { onMessage(msg); }, *this, socket, false)); +} + +void Application::modifyFd(clap_fd_flags flags) { + socketReadNotifier_->setEnabled(flags & CLAP_FD_READ); + socketWriteNotifier_->setEnabled(flags & CLAP_FD_WRITE); + socketErrorNotifier_->setEnabled(flags & CLAP_FD_ERROR); +} + +void Application::onMessage(const clap::RemoteChannel::Message &msg) { + switch (msg.type) { + case clap::messages::kDefineParameterRequest: { + clap::messages::DefineParameterRequest rq; + msg.get(rq); + break; + } + } } diff --git a/examples/gui/application.hh b/examples/gui/application.hh @@ -1,15 +1,26 @@ #pragma once #include <QGuiApplication> +#include <QSocketNotifier> + +#include "../io/remote-channel.hh" class QQmlApplicationEngine; -class Application : public QGuiApplication { +class Application : public QGuiApplication, public clap::RemoteChannel::EventControl { Q_OBJECT; public: Application(int argc, char **argv); + void modifyFd(clap_fd_flags flags) override; + void onMessage(const clap::RemoteChannel::Message& msg); + private: QQmlApplicationEngine *qmlEngine_ = nullptr; + QSocketNotifier *socketReadNotifier_ = nullptr; + QSocketNotifier *socketWriteNotifier_ = nullptr; + QSocketNotifier *socketErrorNotifier_ = nullptr; + + std::unique_ptr<clap::RemoteChannel> remoteChannel_; }; \ No newline at end of file diff --git a/examples/io/remote-channel.cc b/examples/io/remote-channel.cc @@ -82,6 +82,8 @@ namespace clap { modifyFd(CLAP_FD_READ); } + void RemoteChannel::onError() { close(); } + void RemoteChannel::close() { if (socket_ == -1) return; @@ -150,8 +152,7 @@ namespace clap { return true; } - void RemoteChannel::modifyFd(clap_fd_flags flags) - { + void RemoteChannel::modifyFd(clap_fd_flags flags) { if (flags == ioFlags_) return; diff --git a/examples/io/remote-channel.hh b/examples/io/remote-channel.hh @@ -91,6 +91,9 @@ namespace clap { // Called when data can be written, non-blocking void onWrite(); + // Called on socket exception + void onError(); + void runOnce(); clap_fd fd() const { return socket_; } diff --git a/examples/plugins/dc-offset/qml/main.qml b/examples/plugins/dc-offset/qml/main.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +Text { + text: "Hello World!" +} +\ No newline at end of file