@@ -11,51 +11,79 @@ namespace clap {
11
11
};
12
12
} // namespace
13
13
14
+ template <bool hasDelta, bool areDeltasPersistant>
14
15
class UndoTestModule final : public Module {
15
16
public:
16
- UndoTestModule (UndoTest &plugin) : Module(plugin, " " , 0 ) {}
17
+ UndoTestModule (UndoTest<hasDelta, areDeltasPersistant> &plugin) : Module(plugin, " " , 0 ) {}
17
18
18
19
clap_process_status process (const Context &c, uint32_t numFrames) noexcept override {
19
20
return CLAP_PROCESS_SLEEP;
20
21
}
21
22
};
22
23
23
- const clap_plugin_descriptor *UndoTest::descriptor () {
24
+ template <bool hasDelta, bool areDeltasPersistant>
25
+ const clap_plugin_descriptor *UndoTest<hasDelta, areDeltasPersistant>::descriptor() {
24
26
static const char *features[] = {
25
27
CLAP_PLUGIN_FEATURE_UTILITY, CLAP_PLUGIN_FEATURE_ANALYZER, nullptr };
26
28
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};
37
44
38
45
return &desc;
39
46
}
40
47
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) {
43
55
_rootModule = std::make_unique<UndoTestModule>(*this );
44
56
}
45
57
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
+ }
47
62
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;
52
69
}
53
70
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
+
55
77
return format_version == UNDO_FORMAT_VERSION;
56
78
}
57
79
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
+
59
87
if (format_version != UNDO_FORMAT_VERSION) {
60
88
hostMisbehaving (" invalid undo delta format version" );
61
89
return false ;
@@ -76,7 +104,13 @@ namespace clap {
76
104
return true ;
77
105
}
78
106
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
+
80
114
if (format_version != UNDO_FORMAT_VERSION) {
81
115
hostMisbehaving (" invalid undo delta format version" );
82
116
return false ;
@@ -97,7 +131,8 @@ namespace clap {
97
131
return true ;
98
132
}
99
133
100
- void UndoTest::incrementState () {
134
+ template <bool hasDelta, bool areDeltasPersistant>
135
+ void UndoTest<hasDelta, areDeltasPersistant>::incrementState() {
101
136
if (!_host.canUseUndo ())
102
137
return ;
103
138
@@ -109,10 +144,14 @@ namespace clap {
109
144
snprintf (buffer, sizeof (buffer), " UNDO increment %d -> %d" , delta.old_value , delta.new_value );
110
145
_host.log (CLAP_LOG_INFO, buffer);
111
146
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 );
113
151
}
114
152
115
- bool UndoTest::init () noexcept {
153
+ template <bool hasDelta, bool areDeltasPersistant>
154
+ bool UndoTest<hasDelta, areDeltasPersistant>::init() noexcept {
116
155
if (!super::init ())
117
156
return false ;
118
157
@@ -123,7 +162,8 @@ namespace clap {
123
162
}
124
163
125
164
#ifndef CLAP_PLUGINS_HEADLESS
126
- void UndoTest::onGuiInvoke (
165
+ template <bool hasDelta, bool areDeltasPersistant>
166
+ void UndoTest<hasDelta, areDeltasPersistant>::onGuiInvoke(
127
167
const std::string &method,
128
168
const std::vector<std::variant<bool , int64_t , double , std::string>> &args) {
129
169
if (method == " incrementState" )
@@ -133,11 +173,14 @@ namespace clap {
133
173
}
134
174
#endif
135
175
136
- std::vector<uint8_t > UndoTest::stateSaveExtra () noexcept {
176
+ template <bool hasDelta, bool areDeltasPersistant>
177
+ std::vector<uint8_t > UndoTest<hasDelta, areDeltasPersistant>::stateSaveExtra() noexcept {
137
178
return std::vector<uint8_t >((const uint8_t *)&_state, (const uint8_t *)(&_state + 1 ));
138
179
}
139
180
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 {
141
184
if (data.size () != sizeof (_state))
142
185
return false ;
143
186
_state = *(const uint32_t *)data.data ();
0 commit comments