weirdnet_audio_plugin/lib.rs
1//! Audio plugins: a plugin takes a [`weirdnet_media::waveform::Waveform`] and typed parameters and returns a new waveform or an error.
2//!
3//! * [`Plugin`] and [`ParamSpec`]: what a plugin is and which parameters it takes (kind, range, default, unit).
4//! * [`ParamValues`]: the values for one use of a plugin. [`ParamSpec`]s validate and resolve them (defaults filled in, unknown names and
5//! out-of-range values rejected), so a plugin only ever sees complete, valid values.
6//! * [`Registry`]: plugins by id. [`Registry::with_builtins`] has `weirdnet.gain`, `weirdnet.levels`, `weirdnet.frequencies`, `weirdnet.duration` and `weirdnet.pitch`.
7//! * [`apply_chain`]: runs [`PluginInstance`]s in order; the error says which step failed. [`chain_cache_key`] is the BLAKE3 key a cache
8//! uses for the result: source content, plugin ids and versions, resolved parameter values; bypassed steps do not count.
9//!
10//! ```
11//! use weirdnet_audio_plugin::{ParamValues, PluginInstance, Registry, apply_chain, chain_cache_key, waveform_hash};
12//! use weirdnet_media::waveform::Waveform;
13//!
14//! let registry = Registry::with_builtins();
15//! let input = Waveform::tone(48_000, 440.0, 4_800, 0.5)?;
16//! let chain = [
17//! PluginInstance::new("weirdnet.frequencies", ParamValues::new().with_choice("type", "low").with_float("cutoff_hz", 800.0)),
18//! PluginInstance::new("weirdnet.gain", ParamValues::new().with_float("gain_db", -6.0)),
19//! ];
20//! let output = apply_chain(®istry, &input, &chain)?;
21//! let cache_key = chain_cache_key(®istry, &waveform_hash(&input), &chain)?;
22//! assert_eq!(output.frames(), input.frames());
23//! assert_eq!(cache_key.len(), 32);
24//! # Ok::<(), Box<dyn std::error::Error>>(())
25//! ```
26//!
27//! Every built-in's defaults are an identity, so a freshly added plugin changes nothing until a parameter moves. Hosting third-party plugin formats is out of scope.
28
29mod chain;
30mod error;
31mod params;
32mod plugin;
33
34pub mod builtin;
35
36pub use chain::{ChainError, PluginInstance, apply_chain, chain_cache_key, waveform_hash};
37pub use error::PluginError;
38pub use params::{ParamKind, ParamSpec, ParamValue, ParamValues};
39pub use plugin::{Plugin, Registry};