diff --git a/plugins/clap-entry.cc b/plugins/clap-entry.cc index a1acf57..09d6aea 100644 --- a/plugins/clap-entry.cc +++ b/plugins/clap-entry.cc @@ -17,6 +17,7 @@ #include "plugs/offline-latency/offline-latency.hh" #include "plugs/realtime-requirement/realtime-requirement.hh" #include "plugs/track-info/track-info.hh" +#include "plugs/undo-test/undo-test.hh" struct PluginEntry { using create_func = std::function; @@ -53,6 +54,7 @@ static bool clap_init(const char *plugin_path) { addPlugin(); addPlugin(); addPlugin(); + addPlugin(); return true; } diff --git a/plugins/core-plugin.cc b/plugins/core-plugin.cc index 1cfc60c..30bbe92 100644 --- a/plugins/core-plugin.cc +++ b/plugins/core-plugin.cc @@ -20,12 +20,8 @@ #include "gui/abstract-gui.hh" #ifndef CLAP_PLUGINS_HEADLESS -# ifdef CLAP_REMOTE_GUI -# include "gui/remote-gui-factory-proxy.hh" -# else -# include "gui/local-gui-factory.hh" -# include "gui/threaded-gui-factory.hh" -# endif +# include "gui/local-gui-factory.hh" +# include "gui/threaded-gui-factory.hh" #endif namespace clap { @@ -151,23 +147,12 @@ namespace clap { #ifndef CLAP_PLUGINS_HEADLESS bool CorePlugin::implementsGui() const noexcept { return true; } - bool CorePlugin::guiIsApiSupported(const char *api, bool isFloating) noexcept { -# if defined(__APPLE__) && defined(CLAP_REMOTE_GUI) - return isFloating; -# else - return true; -# endif - } + bool CorePlugin::guiIsApiSupported(const char *api, bool isFloating) noexcept { return true; } bool CorePlugin::guiCreate(const char *api, bool isFloating) noexcept { -# ifdef CLAP_REMOTE_GUI - auto guiPath = _pathProvider->getGuiExecutable(); - _guiFactory = RemoteGuiFactoryProxy::getInstance(guiPath); -# else _guiFactory = LocalGuiFactory::getInstance(); if (!_guiFactory) _guiFactory = ThreadedGuiFactory::getInstance(); -# endif _guiHandle = _guiFactory->createGui(*this); @@ -176,6 +161,7 @@ namespace clap { guiDefineParameters(); guiDefineTrackInfo(); + guiSubscribeUndo(); auto skinPath = _pathProvider->getQmlSkinPath(); _guiHandle->gui().addImportPath(_pathProvider->getQmlLibraryPath()); @@ -234,7 +220,10 @@ namespace clap { } } - void CorePlugin::guiDestroy() noexcept { _guiHandle.reset(); } + void CorePlugin::guiDestroy() noexcept { + guiUnsubscribeUndo(); + _guiHandle.reset(); + } bool CorePlugin::guiGetSize(uint32_t *width, uint32_t *height) noexcept { if (!_guiHandle) @@ -263,13 +252,31 @@ namespace clap { bool CorePlugin::guiShow() noexcept { if (!_guiHandle) return false; - return _guiHandle->gui().show(); + if (!_guiHandle->gui().show()) + return false; + + guiSubscribeUndo(); + return true; } bool CorePlugin::guiHide() noexcept { if (!_guiHandle) return false; - return _guiHandle->gui().hide(); + if (!_guiHandle->gui().hide()) + return false; + + guiUnsubscribeUndo(); + return true; + } + + void CorePlugin::guiSubscribeUndo() { + if (implementsUndo() && _host.canUseUndo()) + _host.undoSetWantsContextUpdates(true); + } + + void CorePlugin::guiUnsubscribeUndo() { + if (implementsUndo() && _host.canUseUndo()) + _host.undoSetWantsContextUpdates(false); } //---------------------// @@ -344,14 +351,14 @@ namespace clap { void CorePlugin::onGuiUndo() { runOnMainThread([this] { - if (_host.canUseUndo()) + if (_canUndo && _host.canUseUndo()) _host.undoUndo(); }); } void CorePlugin::onGuiRedo() { runOnMainThread([this] { - if (_host.canUseUndo()) + if (_canRedo && _host.canUseUndo()) _host.undoRedo(); }); } @@ -911,4 +918,55 @@ namespace clap { return true; } + void CorePlugin::undoSetCanUndo(bool can_undo) noexcept { + _canUndo = can_undo; + +#ifndef CLAP_PLUGINS_HEADLESS + if (_guiHandle) + _guiHandle->gui().setCanUndo(can_undo); +#endif + + if (!can_undo) + undoSetUndoName(nullptr); + } + + void CorePlugin::undoSetCanRedo(bool can_redo) noexcept { + _canRedo = can_redo; + +#ifndef CLAP_PLUGINS_HEADLESS + if (_guiHandle) + _guiHandle->gui().setCanRedo(can_redo); +#endif + + if (!can_redo) + undoSetRedoName(nullptr); + } + + void CorePlugin::undoSetUndoName(const char *name) noexcept { + if (name && *name) { + if (!_canUndo) + hostMisbehaving("set undo name while it isn't possible to undo"); + _undoName = name; + } else + _undoName.reset(); + +#ifndef CLAP_PLUGINS_HEADLESS + if (_guiHandle) + _guiHandle->gui().setUndoName(_undoName.value_or("(none)")); +#endif + } + + void CorePlugin::undoSetRedoName(const char *name) noexcept { + if (name && *name) { + if (!_canRedo) + hostMisbehaving("set undo name while it isn't possible to redo"); + _redoName = name; + } else + _redoName.reset(); + +#ifndef CLAP_PLUGINS_HEADLESS + if (_guiHandle) + _guiHandle->gui().setRedoName(_undoName.value_or("(none)")); +#endif + } } // namespace clap \ No newline at end of file diff --git a/plugins/core-plugin.hh b/plugins/core-plugin.hh index 92c577d..c926fee 100644 --- a/plugins/core-plugin.hh +++ b/plugins/core-plugin.hh @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -164,6 +165,8 @@ namespace clap { bool guiShow() noexcept override; bool guiHide() noexcept override; void guiDefineParameters(); + void guiSubscribeUndo(); + void guiUnsubscribeUndo(); //---------------------// // AbstractGuiListener // @@ -199,6 +202,14 @@ namespace clap { bool implementsLatency() const noexcept override { return true; } uint32_t latencyGet() const noexcept override { return _rootModule->latency(); } + //------------------// + // clap_plugin_undo // + //------------------// + void undoSetCanUndo(bool can_undo) noexcept override; + void undoSetCanRedo(bool can_redo) noexcept override; + void undoSetUndoName(const char *name) noexcept override; + void undoSetRedoName(const char *name) noexcept override; + ////////////////////// // Cached Host Info // ////////////////////// @@ -295,5 +306,10 @@ namespace clap { std::unique_ptr _rootModule; TuningProvider _tuningProvider; + + bool _canUndo{false}; + bool _canRedo{false}; + std::optional _undoName; + std::optional _redoName; }; } // namespace clap \ No newline at end of file diff --git a/plugins/gui/qml/clap/skins/CMakeLists.txt b/plugins/gui/qml/clap/skins/CMakeLists.txt index e8b6a57..c4c493d 100644 --- a/plugins/gui/qml/clap/skins/CMakeLists.txt +++ b/plugins/gui/qml/clap/skins/CMakeLists.txt @@ -10,4 +10,5 @@ qt6_add_qml_module(clap-qml-skins char-check/main.qml synth/main.qml track-info/main.qml + undo-test/main.qml ) diff --git a/plugins/gui/qml/clap/skins/char-check/main.qml b/plugins/gui/qml/clap/skins/char-check/main.qml index 2692ce8..0686f59 100644 --- a/plugins/gui/qml/clap/skins/char-check/main.qml +++ b/plugins/gui/qml/clap/skins/char-check/main.qml @@ -1,5 +1,5 @@ -import QtQuick 2.1 -import QtQuick.Controls 2.1 +import QtQuick 6.0 +import QtQuick.Controls 6.0 Rectangle { width: 250 diff --git a/plugins/gui/qml/clap/skins/dc-offset/main.qml b/plugins/gui/qml/clap/skins/dc-offset/main.qml index b9252cc..6ab31ca 100644 --- a/plugins/gui/qml/clap/skins/dc-offset/main.qml +++ b/plugins/gui/qml/clap/skins/dc-offset/main.qml @@ -1,5 +1,5 @@ -import QtQuick 2.1 -import QtQuick.Controls 2.1 +import QtQuick 6.0 +import QtQuick.Controls 6.0 import clap.lib Rectangle { diff --git a/plugins/gui/qml/clap/skins/gain/main.qml b/plugins/gui/qml/clap/skins/gain/main.qml index 1f8e444..f13302f 100644 --- a/plugins/gui/qml/clap/skins/gain/main.qml +++ b/plugins/gui/qml/clap/skins/gain/main.qml @@ -1,5 +1,5 @@ -import QtQuick 2.1 -import QtQuick.Controls 2.1 +import QtQuick 6.0 +import QtQuick.Controls 6.0 import clap.lib Rectangle { diff --git a/plugins/gui/qml/clap/skins/synth/main.qml b/plugins/gui/qml/clap/skins/synth/main.qml index 3ac823f..50c1edf 100644 --- a/plugins/gui/qml/clap/skins/synth/main.qml +++ b/plugins/gui/qml/clap/skins/synth/main.qml @@ -1,5 +1,5 @@ -import QtQuick 2.1 -import QtQuick.Controls 2.1 +import QtQuick 6.0 +import QtQuick.Controls 6.0 import QtQuick.Layouts import clap.lib diff --git a/plugins/gui/qml/clap/skins/track-info/main.qml b/plugins/gui/qml/clap/skins/track-info/main.qml index d9508e7..c286178 100644 --- a/plugins/gui/qml/clap/skins/track-info/main.qml +++ b/plugins/gui/qml/clap/skins/track-info/main.qml @@ -1,5 +1,5 @@ -import QtQuick 2.1 -import QtQuick.Controls 2.1 +import QtQuick 6.0 +import QtQuick.Controls 6.0 Rectangle { width: 450 diff --git a/plugins/gui/qml/clap/skins/transport-info/main.qml b/plugins/gui/qml/clap/skins/transport-info/main.qml index 5e08c69..b05af9d 100644 --- a/plugins/gui/qml/clap/skins/transport-info/main.qml +++ b/plugins/gui/qml/clap/skins/transport-info/main.qml @@ -1,5 +1,5 @@ -import QtQuick 2.1 -import QtQuick.Controls 2.1 +import QtQuick 6.0 +import QtQuick.Controls 6.0 Rectangle { width: 450 diff --git a/plugins/gui/qml/clap/skins/undo-test/main.qml b/plugins/gui/qml/clap/skins/undo-test/main.qml new file mode 100644 index 0000000..1990fd1 --- /dev/null +++ b/plugins/gui/qml/clap/skins/undo-test/main.qml @@ -0,0 +1,35 @@ +import QtQuick 6.7 +import QtQuick.Controls 6.7 +import QtQuick.Layouts + +Rectangle { + width: 450 + height: 300 + color: "#f8f8f8" + + ColumnLayout { + Text { + text: "# Undo Test" + } + RowLayout { + Button { + text: "Undo" + onClicked: undo.undo() + enabled: undo.canUndo + } + Text { + text: undo.undoName + } + } + RowLayout { + Button { + text: "Redo" + onClicked: undo.redo() + enabled: undo.canRedo + } + Text { + text: undo.redoName + } + } + } +} diff --git a/plugins/plugs/undo-test/undo-test.cc b/plugins/plugs/undo-test/undo-test.cc index efd28d0..b1a5dab 100644 --- a/plugins/plugs/undo-test/undo-test.cc +++ b/plugins/plugs/undo-test/undo-test.cc @@ -16,7 +16,7 @@ namespace clap { UndoTestModule(UndoTest &plugin) : Module(plugin, "", 0) {} clap_process_status process(const Context &c, uint32_t numFrames) noexcept override { - return CLAP_PROCESS_CONTINUE; + return CLAP_PROCESS_SLEEP; } }; @@ -38,10 +38,6 @@ namespace clap { return &desc; } - enum { - kParamIdOffset = 0, - }; - UndoTest::UndoTest(const std::string &pluginPath, const clap_host &host) : CorePlugin(PathProvider::create(pluginPath, "undo-test"), descriptor(), host) { _rootModule = std::make_unique(*this); @@ -87,36 +83,6 @@ namespace clap { return false; } - void UndoTest::undoSetCanUndo(bool can_undo) noexcept { - _canUndo = can_undo; - if (!can_undo) - _undoName.reset(); - } - - void UndoTest::undoSetCanRedo(bool can_redo) noexcept { - _canRedo = can_redo; - if (!can_redo) - _redoName.reset(); - } - - void UndoTest::undoSetUndoName(const char *name) noexcept { - if (name && *name) { - if (!_canUndo) - hostMisbehaving("set undo name while it isn't possible to undo"); - _undoName = name; - } else - _undoName.reset(); - } - - void UndoTest::undoSetRedoName(const char *name) noexcept { - if (name && *name) { - if (!_canRedo) - hostMisbehaving("set undo name while it isn't possible to redo"); - _redoName = name; - } else - _redoName.reset(); - } - void UndoTest::incrementState() { if (!_host.canUseUndo()) return; @@ -126,14 +92,13 @@ namespace clap { delta.new_value = ++_state; _host.undoChangeMade("inc", &delta, sizeof(delta), true); } + bool UndoTest::init() noexcept { + if (!super::init()) + return false; - void UndoTest::requestHostUndo() { - if (_canUndo && _host.canUseUndo()) - _host.undoUndo(); - } - - void UndoTest::requestHostRedo() { - if (_canRedo && _host.canUseUndo()) - _host.undoRedo(); + if (_host.canUseUndo()) { + _host.undoSetWantsContextUpdates(true); + } + return true; } } // namespace clap diff --git a/plugins/plugs/undo-test/undo-test.hh b/plugins/plugs/undo-test/undo-test.hh index 4512596..b7076c0 100644 --- a/plugins/plugs/undo-test/undo-test.hh +++ b/plugins/plugs/undo-test/undo-test.hh @@ -15,26 +15,17 @@ namespace clap { static const clap_plugin_descriptor *descriptor(); - bool implementsUndo() const noexcept; - void undoGetDeltaProperties(clap_undo_delta_properties_t *properties) noexcept; - bool undoCanUseDeltaFormatVersion(clap_id format_version) noexcept; - bool undoUndo(clap_id format_version, const void *delta, size_t delta_size) noexcept; - bool undoRedo(clap_id format_version, const void *delta, size_t delta_size) noexcept; - void undoSetCanUndo(bool can_undo) noexcept; - void undoSetCanRedo(bool can_redo) noexcept; - void undoSetUndoName(const char *name) noexcept; - void undoSetRedoName(const char *name) noexcept; + bool init() noexcept override; + + bool implementsUndo() const noexcept override; + void undoGetDeltaProperties(clap_undo_delta_properties_t *properties) noexcept override; + bool undoCanUseDeltaFormatVersion(clap_id format_version) noexcept override; + bool undoUndo(clap_id format_version, const void *delta, size_t delta_size) noexcept override; + bool undoRedo(clap_id format_version, const void *delta, size_t delta_size) noexcept override; void incrementState(); - void requestHostUndo(); - void requestHostRedo(); private: uint32_t _state{0}; - - bool _canUndo{false}; - bool _canRedo{false}; - std::optional _undoName; - std::optional _redoName; }; } // namespace clap \ No newline at end of file