Presets, Effect and Layered
Preset and Registry
Preset: id, name, description, category, behavior (OneShot, Evolving, Sustained), tags, params (ParamSpec list), default_seed, reversed, and a build function void(Recipe&, const BuildCtx&). find_param(name), default_duration(), default_tail().
Registry: add(Preset), all(), size(), find(id), by_category(c), search(text) (ids, names, tags, descriptions). builtin_registry() returns the shared catalog. Free functions: all_presets(), find(id), presets_in(category), search(text), make(id). Category = Risers, Impacts, Glitch, Textures, Bass, EarCandy, Vocal, Rhythmic, Percussion, Experimental, Tonal, Reverses, with all_categories(), category_id(), category_name(), parse_category().
BuildCtx — what a preset sees
Passed to build: the resolved params, duration, bpm, seed, plus helpers p(name), beats(b) (beats → seconds), beat_hz(beats_per_cycle), rng(tag), lerp01(name, a, b), static lg(t, a, b) (log interpolation), evenly(n, a, b), scattered(n, tag, a, b), chord_notes(), scale_walk(n, from, stride).
Effect — the tunable handle
Effect e = sfx::make("id"); copies a preset's parameters.
| Method | Meaning |
|---|---|
set(name, value) | Validated against the parameter range; throws sfx::Error for unknown names or out-of-range values. Setting duration cancels beat-based duration |
get, has, params() | Inspect parameters |
seed(s) / seed() | Seed for all randomness (default: the preset’s default_seed) |
tempo(bpm) / tempo() | 20–400 BPM, default 120 |
duration_beats(b) | Duration in beats at the effect tempo; duration() reports seconds |
recipe(), render(settings) | Build the Recipe, or render it directly |
Layered — composites
Layered mixes several sources of audio: tempo(bpm), seed(s), add(preset_id | Effect | Rendered, LayerOpts), size(), render(settings). Each layer’s randomness uses its explicit seed or one derived from the composite seed and layer index.
LayerOpts (chainable)
| Method | Field | Meaning |
|---|---|---|
gain(db) | gain_db | Relative level. Effect layers render at 0 dBFS peak first; rendered audio is used as-is |
at(sec), at_beats(b) | offset, offset_beats | Start time; beats override seconds using the composite tempo |
dur(sec) | duration | Sets the layer effect’s duration parameter |
transpose(semis) | pitch | Presets with a pitch parameter are re-pitched through it (clamped); others and audio are resampled, which also changes length |
place(pan) | pan | −1 … +1, equal power |
with_seed(s) | seed | Layer-specific seed |
flip() | reverse | Reverse this layer |
set(name, value) | params | Parameter override for the layer effect |
Defining your own presets
Copy the built-in registry (sfx::Registry mine = sfx::builtin_registry();), fill a Preset (use params_from({"duration=2", "brightness=0.6"}) to pull specs from the dictionary), set build, and mine.add(p). See example 07. Built-in presets are defined with the Def helper in the category files under wauvio/sfx/presets/.
Full API listing
wauvio/sfx/presets/registry.hpp
wauvio::sfx::enum class Category
enum class Category { Risers, Impacts, Glitch, Textures, Bass, EarCandy, Vocal, Rhythmic, Percussion, Experimental, Tonal, Reverses };
inline const std::vector<Category>& all_categories()
inline const char* category_id(Category c)
inline const char* category_name(Category c)
inline bool parse_category(std::string_view text, Category& out)
wauvio::sfx::enum class Behavior
enum class Behavior { OneShot, Evolving, Sustained };
inline const char* behavior_name(Behavior b) { return b == Behavior::OneShot ? "one-shot" : b == Behavior::Evolving ? "evolving" : "sustained"; }
inline std::string make_id(const std::string& name)
wauvio::sfx::struct BuildCtx
struct BuildCtx
const ParamSet& params; double duration; double bpm; uint64_t seed;
double p(const char* name) const { return params.get(name); }
double beats(double b) const { return b * 60.0 / bpm; }
double beat_hz(double beats_per_cycle) const { return bpm / 60.0 / beats_per_cycle; }
Rng rng(uint64_t tag) const { return Rng(mix_seed(seed, tag)); }
double lerp01(const char* name, double a, double b) const { return a + (b - a) * p(name); }
static double lg(double t, double a, double b) { return a * std::pow(b / a, clampd(t, 0.0, 1.0)); }
std::vector<double> evenly(int n, double a = 0.0, double b = 1.0) const { std::vector<double> t; for (int i = 0; i < n; ++i) t.push_back(n == 1 ? a : a + (b - a) * i / n); return t; }
std::vector<double> scattered(int n, uint64_t tag, double a = 0.0, double b = 1.0) const { Rng r = rng(tag); std::vector<double> t; for (int i = 0; i < n; ++i) t.push_back(r.range(a, b)); std::sort(t.begin(), t.end()); return t; }
std::vector<double> chord_notes() const { return chord_intervals(static_cast<int>(p("chord"))); }
std::vector<double> scale_walk(int n, int from = 0, int stride = 1) const
using BuildFn = std::function<void(Recipe&, const BuildCtx&)>;
wauvio::sfx::struct Preset
struct Preset
std::string id;
std::string name;
std::string description;
Category category = Category::Risers;
Behavior behavior = Behavior::OneShot;
std::vector<std::string> tags;
std::vector<ParamSpec> params;
uint64_t default_seed = 1;
bool reversed = false;
BuildFn build;
const ParamSpec* find_param(const std::string& n) const { for (auto& p : params) if (p.name == n) return &p; return nullptr; }
double default_duration() const { const ParamSpec* d = find_param("duration"); return d ? d->def : 0.0; }
double default_tail() const { const ParamSpec* d = find_param("tail"); return d ? d->def : 0.0; }
inline std::vector<ParamSpec> params_from(std::initializer_list<const char*> items)
wauvio::sfx::class Registry
class Registry
public:
void add(Preset p)
const std::vector<Preset>& all() const noexcept { return presets_; }
size_t size() const noexcept { return presets_.size(); }
const Preset* find(std::string_view id) const { for (auto& p : presets_) if (p.id == id) return &p; return nullptr; }
std::vector<const Preset*> by_category(Category c) const { std::vector<const Preset*> v; for (auto& p : presets_) if (p.category == c) v.push_back(&p); return v; }
std::vector<const Preset*> search(std::string_view text) const
const Registry& builtin_registry();
wauvio::sfx::class Effect
class Effect
public:
explicit Effect(const Preset& p) : preset_(p), params_(p.params), seed_(p.default_seed) {}
Effect& set(const std::string& name, double value) { if (name == "duration") beats_ = 0.0; params_.set(name, value); return *this; }
double get(const std::string& name) const { return params_.get(name); }
bool has(const std::string& name) const { return params_.has(name); }
Effect& seed(uint64_t s) { seed_ = s; return *this; }
uint64_t seed() const noexcept { return seed_; }
Effect& tempo(double bpm) { if (!(bpm >= 20.0 && bpm <= 400.0)) throw Error("tempo must be within 20..400 bpm"); bpm_ = bpm; return *this; }
double tempo() const noexcept { return bpm_; }
Effect& duration_beats(double beats) { if (!(beats > 0.0) || !std::isfinite(beats)) throw Error("duration_beats must be positive"); beats_ = beats; return *this; }
double duration() const { return beats_ > 0.0 ? beats_ * 60.0 / bpm_ : params_.get("duration"); }
const Preset& preset() const noexcept { return preset_; }
const ParamSet& params() const noexcept { return params_; }
Recipe recipe() const
Rendered render(const RenderSettings& st = RenderSettings()) const
inline Effect make(std::string_view id)
inline Effect make(const Preset& p) { return Effect(p); }
inline const std::vector<Preset>& all_presets() { return builtin_registry().all(); }
inline const Preset* find(std::string_view id) { return builtin_registry().find(id); }
inline std::vector<const Preset*> presets_in(Category c) { return builtin_registry().by_category(c); }
inline std::vector<const Preset*> search(std::string_view text) { return builtin_registry().search(text); }
wauvio::sfx::struct Def
struct Def
Registry& reg; Category cat;
void operator()(const char* name, Behavior b, const char* desc, std::initializer_list<const char*> tags, std::initializer_list<const char*> params, BuildFn fn, bool reversed = false) const
wauvio/sfx/layers/layered.hpp
wauvio::sfx::struct LayerOpts
/// Per-layer controls of a Layered composite.
struct LayerOpts
double gain_db = 0.0; ///< relative level. Effect layers are first rendered at a peak of 0 dBFS; rendered audio is used as it is
double offset = 0.0; ///< start time in seconds
double offset_beats = -1.0; ///< if >= 0: start time in beats (overrides offset; uses the Layered tempo)
double duration = -1.0; ///< if > 0: sets the layer effect's "duration" parameter (seconds)
double pitch = 0.0; ///< semitones. Presets with a "pitch" parameter are re-pitched through it (clamped to its range);
///< others (and rendered audio) are resampled, which also changes their length.
double pan = 0.0; ///< -1 left .. +1 right (equal power)
bool has_seed = false; uint64_t seed = 0; ///< layer-specific seed; otherwise derived from the composite seed and the layer index
bool reverse = false; ///< reverse this layer (offline)
std::vector<std::pair<std::string, double>> params; ///< parameter overrides applied to the layer effect
LayerOpts& gain(double db) { gain_db = db; return *this; }
LayerOpts& at(double sec) { offset = sec; return *this; }
LayerOpts& at_beats(double b) { offset_beats = b; return *this; }
LayerOpts& dur(double sec) { duration = sec; return *this; }
LayerOpts& transpose(double semis) { pitch = semis; return *this; }
LayerOpts& place(double p) { pan = p; return *this; }
LayerOpts& with_seed(uint64_t s) { has_seed = true; seed = s; return *this; }
LayerOpts& flip() { reverse = true; return *this; }
LayerOpts& set(const std::string& n, double v) { params.emplace_back(n, v); return *this; }
/// Cubic-interpolated resampling by `ratio` (> 1 = higher pitch and shorter).
inline Buffer resample(const Buffer& in, double ratio)
wauvio::sfx::class Layered
class Layered
public:
Layered& tempo(double bpm) { if (!(bpm >= 20.0 && bpm <= 400.0)) throw Error("tempo must be within 20..400 bpm"); bpm_ = bpm; return *this; }
Layered& seed(uint64_t s) { seed_ = s; return *this; }
size_t size() const noexcept { return layers_.size(); }
/// Add a built-in preset by id.
Layered& add(std::string_view preset_id, const LayerOpts& o = LayerOpts()) { return add(make(preset_id), o); }
/// Add a configured Effect (its own parameters, seed and tempo-independent settings are kept; per-layer options are applied on top).
Layered& add(const Effect& e, const LayerOpts& o = LayerOpts()) { check(o); Item it; it.effect = std::make_shared<Effect>(e); it.opts = o; layers_.push_back(std::move(it)); return *this; }
/// Add audio you already rendered (it must have the sample rate you will render the composite at).
Layered& add(const Rendered& audio, const LayerOpts& o = LayerOpts()) { check(o); Item it; it.audio = std::make_shared<Rendered>(audio); it.opts = o; layers_.push_back(std::move(it)); return *this; }
/// Render and mix all layers, then normalise the composite according to `st`. Each layer's randomness comes from its own seed:
/// the explicit LayerOpts seed if given, otherwise a seed derived from the composite seed and the layer's position.
Rendered render(const RenderSettings& st = RenderSettings()) const
wauvio/sfx/presets/builtin.hpp
wauvio::sfx::Free functions, constants and aliases
inline void register_builtin_presets(Registry& R)
inline const Registry& builtin_registry()
wauvio/sfx/presets/preset_helpers.hpp
wauvio::sfx::presets::Free functions, constants and aliases
using Rc = Recipe&;
using Cc = const BuildCtx&;
inline Behavior OneShot() { return Behavior::OneShot; }
inline Behavior Evolving() { return Behavior::Evolving; }
inline Behavior Sustained() { return Behavior::Sustained; }