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
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
// 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.
@ -42,3 +42,5 @@ Integer parameters are declared as `ParamStepped`s. This is a similarly opaque
### 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 `.configureSTFX()` and `.processSTFX()` methods are wrapped into more typical

View File

@ -353,6 +353,12 @@ struct Plugin : public clap_plugin {
entry.steppedParam = &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() {
params.resize(0);
@ -514,7 +520,6 @@ struct Plugin : public clap_plugin {
void info(const char *, const char *) {}
int version(int v) {
LOG_EXPR(v);
(*this)("version", v);
return v;
}
@ -530,6 +535,12 @@ struct Plugin : public clap_plugin {
(*this)(key, v);
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> {
using StorageCborReader<true, StateReader>::StorageCborReader;
@ -553,6 +564,13 @@ struct Plugin : public clap_plugin {
param = v;
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;

View File

@ -313,7 +313,7 @@ namespace stfx {
auto v = current.load(std::memory_order_relaxed);
auto vPrev = 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()`
@ -384,12 +384,18 @@ namespace stfx {
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
static int version(int v) {return v;}
int version(int v) {return v;}
// Ignore the UI/synchronisation stuff
static bool extra() {return false;}
static bool extra(const char *, const char *) {return false;}
static void invalidate(const char *) {}
bool extra() {return false;}
bool extra(const char *, const char *) {return false;}
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
void operator()(const char *, bool) {}
@ -399,23 +405,18 @@ namespace stfx {
void operator()(const char *, float) {}
// And strings
void operator()(const char *, std::string &) {}
// Iterate through vectors
template<class Item>
void operator()(const char *label, std::vector<Item> &vector) {
for (auto &item : vector) (*this)(label, item);
}
// Assume all other arguments have a `.state()`, and recurse into it
template<class OtherObject>
void operator()(const char *, OtherObject &obj) {
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;
bool justHadReset = true;

View File

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