1
0

Add dummy .changed()/.invalidate() methods to Storage impls.

This commit is contained in:
Geraint 2025-06-23 20:08:46 +01:00
parent 767906a31e
commit 7e02cfd77b
4 changed files with 38 additions and 17 deletions

View File

@ -8,11 +8,11 @@ A collection of basic effects, available as plugins and re-usable open-source (M
## How to use ## How to use
Each effect can be used just by including the corresponding header (e.g. `limiter.h`). This defines two classes `LimiterFloat` and `LimiterDouble`. Some of these have initialisation arguments (e.g. maximum lookahead) but these are always optional. Each effect can be used just by including the corresponding header (e.g. `limiter.h`). This defines two classes `...Float` and `...Double`. Some of these have initialisation arguments (e.g. maximum lookahead) but these are always optional.
```cpp ```cpp
// Limiter with maximum attack/lookahead of 100ms // Limiter with maximum attack/lookahead of 100ms
signalsmith::basics::Limiter effect(100); signalsmith::basics::LimiterFloat effect(100);
``` ```
Before use, these classes must be configured. The `.configure()` method returns `true` if the config was accepted. They can be configured multiple times, but (obviously) not while actively processing audio. Before use, these classes must be configured. The `.configure()` method returns `true` if the config was accepted. They can be configured multiple times, but (obviously) not while actively processing audio.
@ -42,3 +42,5 @@ Integer parameters are declared as `ParamStepped`s. This is a similarly opaque
### Implementation ### Implementation
The `.state()` method of these templates contain a lot of detail, almost all of which is ignored (and optimised away) when using the `...Float`/`...Double` classes. The `.state()` method of these templates contain a lot of detail, almost all of which is ignored (and optimised away) when using the `...Float`/`...Double` classes.
The `.configureSTFX()` and `.processSTFX()` methods are wrapped into more typical

View File

@ -353,6 +353,12 @@ struct Plugin : public clap_plugin {
entry.steppedParam = &param; entry.steppedParam = &param;
return entry.steppedInfo.emplace(param); return entry.steppedInfo.emplace(param);
} }
template<class V>
bool changed(const char *key, V &v) {
(*this)(key, v);
return false;
}
void invalidate(const char *) {}
}; };
void scanParams() { void scanParams() {
params.resize(0); params.resize(0);
@ -514,7 +520,6 @@ struct Plugin : public clap_plugin {
void info(const char *, const char *) {} void info(const char *, const char *) {}
int version(int v) { int version(int v) {
LOG_EXPR(v);
(*this)("version", v); (*this)("version", v);
return v; return v;
} }
@ -530,6 +535,12 @@ struct Plugin : public clap_plugin {
(*this)(key, v); (*this)(key, v);
return {}; return {};
} }
template<class V>
bool changed(const char *key, V &v) {
(*this)(key, v);
return false;
}
void invalidate(const char *) {}
}; };
struct StateReader : public StorageCborReader<true, StateReader> { struct StateReader : public StorageCborReader<true, StateReader> {
using StorageCborReader<true, StateReader>::StorageCborReader; using StorageCborReader<true, StateReader>::StorageCborReader;
@ -553,6 +564,13 @@ struct Plugin : public clap_plugin {
param = v; param = v;
return {}; return {};
} }
template<class V>
bool changed(const char *key, V &v) {
V prev = v;
(*this)(key, v);
return v == prev;
}
void invalidate(const char *) {}
}; };
std::vector<unsigned char> stateBuffer; std::vector<unsigned char> stateBuffer;

View File

@ -313,7 +313,7 @@ namespace stfx {
auto v = current.load(std::memory_order_relaxed); auto v = current.load(std::memory_order_relaxed);
auto vPrev = v; auto vPrev = v;
storage("value", v); storage("value", v);
if (v != vPrev) current.store(v); if (v != vPrev) current.store(v, std::memory_order_relaxed);
} }
// The following are only called from `.process()` // The following are only called from `.process()`
@ -384,12 +384,18 @@ namespace stfx {
return {}; return {};
} }
// Drop any name/description we're given
template<class ...Args>
void info(Args...) {}
// The effect might ask us to store/fetch the serialisation version, we just echo it back // The effect might ask us to store/fetch the serialisation version, we just echo it back
static int version(int v) {return v;} int version(int v) {return v;}
// Ignore the UI/synchronisation stuff // Ignore the UI/synchronisation stuff
static bool extra() {return false;} bool extra() {return false;}
static bool extra(const char *, const char *) {return false;} bool extra(const char *, const char *) {return false;}
static void invalidate(const char *) {} void invalidate(const char *) {}
// This storage only reads values, never changes them
template<class T>
bool changed(const char *, T &v) {return false;}
// We ignore any basic type // We ignore any basic type
void operator()(const char *, bool) {} void operator()(const char *, bool) {}
@ -399,23 +405,18 @@ namespace stfx {
void operator()(const char *, float) {} void operator()(const char *, float) {}
// And strings // And strings
void operator()(const char *, std::string &) {} void operator()(const char *, std::string &) {}
// Iterate through vectors // Iterate through vectors
template<class Item> template<class Item>
void operator()(const char *label, std::vector<Item> &vector) { void operator()(const char *label, std::vector<Item> &vector) {
for (auto &item : vector) (*this)(label, item); for (auto &item : vector) (*this)(label, item);
} }
// Assume all other arguments have a `.state()`, and recurse into it // Assume all other arguments have a `.state()`, and recurse into it
template<class OtherObject> template<class OtherObject>
void operator()(const char *, OtherObject &obj) { void operator()(const char *, OtherObject &obj) {
obj.state(*this); obj.state(*this);
} }
template<class Fn>
void group(const char *, Fn fn) {
fn(*this);
}
// Drop any name/description we're given
template<class ...Args>
void info(Args...) {}
} params; } params;
bool justHadReset = true; bool justHadReset = true;

View File

@ -163,7 +163,8 @@ struct StorageCborReader {
} }
readValue(v); readValue(v);
} }
private:
template<class Obj> template<class Obj>
void readValue(Obj &obj) { void readValue(Obj &obj) {
if (compact) { if (compact) {
@ -224,7 +225,6 @@ struct StorageCborReader {
}); });
array.resize(length); array.resize(length);
} }
private:
protected: protected:
Cbor cbor; Cbor cbor;