Skip to content

Commit 902e85a

Browse files
committed
Make more variants of the plugin undo testing
1 parent 02933b2 commit 902e85a

File tree

3 files changed

+84
-39
lines changed

3 files changed

+84
-39
lines changed

plugins/clap-entry.cc

+12-10
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22

33
#include <cstring>
44
#include <functional>
5-
#include <vector>
6-
#include <mutex>
75
#include <iostream>
6+
#include <mutex>
7+
#include <vector>
88

99
#include "plugs/adsr/adsr-plug.hh"
10+
#include "plugs/char-check/char-check.hh"
1011
#include "plugs/dc-offset/dc-offset.hh"
1112
#include "plugs/gain/gain.hh"
12-
#include "plugs/transport/transport-info.hh"
13-
#include "plugs/char-check/char-check.hh"
14-
#include "plugs/synth/synth.hh"
15-
#include "plugs/svf/svf-plug.hh"
1613
#include "plugs/latency/latency.hh"
1714
#include "plugs/offline-latency/offline-latency.hh"
1815
#include "plugs/realtime-requirement/realtime-requirement.hh"
16+
#include "plugs/svf/svf-plug.hh"
17+
#include "plugs/synth/synth.hh"
1918
#include "plugs/track-info/track-info.hh"
19+
#include "plugs/transport/transport-info.hh"
2020
#include "plugs/undo-test/undo-test.hh"
2121

2222
struct PluginEntry {
@@ -54,7 +54,9 @@ static bool clap_init(const char *plugin_path) {
5454
addPlugin<clap::OfflineLatency>();
5555
addPlugin<clap::RealtimeRequirement>();
5656
addPlugin<clap::TrackInfo>();
57-
addPlugin<clap::UndoTest>();
57+
addPlugin<clap::UndoTest<true, true>>();
58+
addPlugin<clap::UndoTest<true, false>>();
59+
addPlugin<clap::UndoTest<false, false>>();
5860
return true;
5961
}
6062

@@ -89,7 +91,8 @@ static uint32_t clap_get_plugin_count(const clap_plugin_factory *) { return g_pl
8991
static const clap_plugin_descriptor *clap_get_plugin_descriptor(const clap_plugin_factory *,
9092
uint32_t index) {
9193
if (index < 0 || index >= g_plugins.size()) {
92-
std::cerr << "index out of bounds: " << index << " not in 0.." << g_plugins.size() << std::endl;
94+
std::cerr << "index out of bounds: " << index << " not in 0.." << g_plugins.size()
95+
<< std::endl;
9396
std::terminate();
9497
}
9598

@@ -110,8 +113,7 @@ static const clap_plugin_factory g_clap_plugin_factory = {
110113
clap_create_plugin,
111114
};
112115

113-
const void *clap_get_factory(const char *factory_id)
114-
{
116+
const void *clap_get_factory(const char *factory_id) {
115117
if (!::strcmp(factory_id, CLAP_PLUGIN_FACTORY_ID))
116118
return &g_clap_plugin_factory;
117119
return nullptr;

plugins/plugs/undo-test/undo-test.cc

+71-28
Original file line numberDiff line numberDiff line change
@@ -11,51 +11,79 @@ namespace clap {
1111
};
1212
} // namespace
1313

14+
template <bool hasDelta, bool areDeltasPersistant>
1415
class UndoTestModule final : public Module {
1516
public:
16-
UndoTestModule(UndoTest &plugin) : Module(plugin, "", 0) {}
17+
UndoTestModule(UndoTest<hasDelta, areDeltasPersistant> &plugin) : Module(plugin, "", 0) {}
1718

1819
clap_process_status process(const Context &c, uint32_t numFrames) noexcept override {
1920
return CLAP_PROCESS_SLEEP;
2021
}
2122
};
2223

23-
const clap_plugin_descriptor *UndoTest::descriptor() {
24+
template <bool hasDelta, bool areDeltasPersistant>
25+
const clap_plugin_descriptor *UndoTest<hasDelta, areDeltasPersistant>::descriptor() {
2426
static const char *features[] = {
2527
CLAP_PLUGIN_FEATURE_UTILITY, CLAP_PLUGIN_FEATURE_ANALYZER, nullptr};
2628

27-
static const clap_plugin_descriptor desc = {CLAP_VERSION,
28-
"com.github.free-audio.clap.undo-test",
29-
"Undo Test",
30-
"clap",
31-
"https://github.com/free-audio/clap",
32-
nullptr,
33-
nullptr,
34-
"0.1",
35-
"Help testing the undo extension",
36-
features};
29+
static const clap_plugin_descriptor desc = {
30+
CLAP_VERSION,
31+
areDeltasPersistant ? "com.github.free-audio.clap.undo-test"
32+
: hasDelta ? "com.github.free-audio.clap.undo-test-not-persistent"
33+
: "com.github.free-audio.clap.undo-test-no-deltas",
34+
areDeltasPersistant ? "Undo Test"
35+
: hasDelta ? "UndoTest (deltas not persistent)"
36+
: "UndoTest (no deltas)",
37+
"clap",
38+
"https://github.com/free-audio/clap",
39+
nullptr,
40+
nullptr,
41+
"0.1",
42+
"Help testing the undo extension",
43+
features};
3744

3845
return &desc;
3946
}
4047

41-
UndoTest::UndoTest(const std::string &pluginPath, const clap_host &host)
42-
: CorePlugin(PathProvider::create(pluginPath, "undo-test"), descriptor(), host) {
48+
template <bool hasDelta, bool areDeltasPersistant>
49+
UndoTest<hasDelta, areDeltasPersistant>::UndoTest(const std::string &pluginPath,
50+
const clap_host &host)
51+
: CorePlugin(PathProvider::create(
52+
pluginPath, UndoTest<hasDelta, areDeltasPersistant>::descriptor()->name),
53+
descriptor(),
54+
host) {
4355
_rootModule = std::make_unique<UndoTestModule>(*this);
4456
}
4557

46-
bool UndoTest::implementsUndo() const noexcept { return true; }
58+
template <bool hasDelta, bool areDeltasPersistant>
59+
bool UndoTest<hasDelta, areDeltasPersistant>::implementsUndo() const noexcept {
60+
return true;
61+
}
4762

48-
void UndoTest::undoGetDeltaProperties(clap_undo_delta_properties_t *properties) noexcept {
49-
properties->has_delta = true;
50-
properties->are_deltas_persistent = true;
51-
properties->format_version = UNDO_FORMAT_VERSION;
63+
template <bool hasDelta, bool areDeltasPersistant>
64+
void UndoTest<hasDelta, areDeltasPersistant>::undoGetDeltaProperties(
65+
clap_undo_delta_properties_t *properties) noexcept {
66+
properties->has_delta = hasDelta;
67+
properties->are_deltas_persistent = areDeltasPersistant;
68+
properties->format_version = hasDelta ? UNDO_FORMAT_VERSION : CLAP_INVALID_ID;
5269
}
5370

54-
bool UndoTest::undoCanUseDeltaFormatVersion(clap_id format_version) noexcept {
71+
template <bool hasDelta, bool areDeltasPersistant>
72+
bool UndoTest<hasDelta, areDeltasPersistant>::undoCanUseDeltaFormatVersion(
73+
clap_id format_version) noexcept {
74+
if constexpr (!hasDelta)
75+
return false;
76+
5577
return format_version == UNDO_FORMAT_VERSION;
5678
}
5779

58-
bool UndoTest::undoUndo(clap_id format_version, const void *delta, size_t delta_size) noexcept {
80+
template <bool hasDelta, bool areDeltasPersistant>
81+
bool UndoTest<hasDelta, areDeltasPersistant>::undoUndo(clap_id format_version,
82+
const void *delta,
83+
size_t delta_size) noexcept {
84+
if constexpr (!hasDelta)
85+
return false;
86+
5987
if (format_version != UNDO_FORMAT_VERSION) {
6088
hostMisbehaving("invalid undo delta format version");
6189
return false;
@@ -76,7 +104,13 @@ namespace clap {
76104
return true;
77105
}
78106

79-
bool UndoTest::undoRedo(clap_id format_version, const void *delta, size_t delta_size) noexcept {
107+
template <bool hasDelta, bool areDeltasPersistant>
108+
bool UndoTest<hasDelta, areDeltasPersistant>::undoRedo(clap_id format_version,
109+
const void *delta,
110+
size_t delta_size) noexcept {
111+
if constexpr (!hasDelta)
112+
return false;
113+
80114
if (format_version != UNDO_FORMAT_VERSION) {
81115
hostMisbehaving("invalid undo delta format version");
82116
return false;
@@ -97,7 +131,8 @@ namespace clap {
97131
return true;
98132
}
99133

100-
void UndoTest::incrementState() {
134+
template <bool hasDelta, bool areDeltasPersistant>
135+
void UndoTest<hasDelta, areDeltasPersistant>::incrementState() {
101136
if (!_host.canUseUndo())
102137
return;
103138

@@ -109,10 +144,14 @@ namespace clap {
109144
snprintf(buffer, sizeof(buffer), "UNDO increment %d -> %d", delta.old_value, delta.new_value);
110145
_host.log(CLAP_LOG_INFO, buffer);
111146

112-
_host.undoChangeMade(buffer, &delta, sizeof(delta), true);
147+
if constexpr (hasDelta)
148+
_host.undoChangeMade(buffer, &delta, sizeof(delta), true);
149+
else
150+
_host.undoChangeMade(buffer, nullptr, 0, 0);
113151
}
114152

115-
bool UndoTest::init() noexcept {
153+
template <bool hasDelta, bool areDeltasPersistant>
154+
bool UndoTest<hasDelta, areDeltasPersistant>::init() noexcept {
116155
if (!super::init())
117156
return false;
118157

@@ -123,7 +162,8 @@ namespace clap {
123162
}
124163

125164
#ifndef CLAP_PLUGINS_HEADLESS
126-
void UndoTest::onGuiInvoke(
165+
template <bool hasDelta, bool areDeltasPersistant>
166+
void UndoTest<hasDelta, areDeltasPersistant>::onGuiInvoke(
127167
const std::string &method,
128168
const std::vector<std::variant<bool, int64_t, double, std::string>> &args) {
129169
if (method == "incrementState")
@@ -133,11 +173,14 @@ namespace clap {
133173
}
134174
#endif
135175

136-
std::vector<uint8_t> UndoTest::stateSaveExtra() noexcept {
176+
template <bool hasDelta, bool areDeltasPersistant>
177+
std::vector<uint8_t> UndoTest<hasDelta, areDeltasPersistant>::stateSaveExtra() noexcept {
137178
return std::vector<uint8_t>((const uint8_t *)&_state, (const uint8_t *)(&_state + 1));
138179
}
139180

140-
bool UndoTest::stateLoadExtra(const std::vector<uint8_t> &data) noexcept {
181+
template <bool hasDelta, bool areDeltasPersistant>
182+
bool UndoTest<hasDelta, areDeltasPersistant>::stateLoadExtra(
183+
const std::vector<uint8_t> &data) noexcept {
141184
if (data.size() != sizeof(_state))
142185
return false;
143186
_state = *(const uint32_t *)data.data();

plugins/plugs/undo-test/undo-test.hh

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#include "../../core-plugin.hh"
77

88
namespace clap {
9+
template <bool hasDelta, bool areDeltasPersistant>
910
class UndoTest final : public CorePlugin {
10-
private:
1111
using super = CorePlugin;
1212

1313
public:

0 commit comments

Comments
 (0)