Expand description
Parametric patches — the in-engine runtime.
A Patch is a SoundDoc template plus named parameters, each bound to
one or more JSON paths in the graph. Instantiating it with runtime values
produces a concrete document the deterministic renderer turns into audio — so
a game ships ONE patch and renders endless per-instance variations (an impact
that scales with force, a footstep that varies by surface) with zero baked
files. Pure and deterministic like the rest of the core: the same patch and
the same values always render byte-identically, and it compiles native, to
WASM, and into a game engine.
use std::collections::BTreeMap;
use tono_core::patch::Patch;
let patch: Patch = serde_json::from_str(r#"{
"doc": { "name": "zap", "duration": 0.2, "engine": 4,
"root": { "type": "sine", "freq": 880 } },
"params": [ { "name": "pitch", "paths": ["root.freq"],
"min": 100.0, "max": 2000.0, "default": 880.0 } ]
}"#).unwrap();
// One patch, endless per-instance variations — deterministic each time.
let low = patch.render(&BTreeMap::from([("pitch".into(), 220.0)])).unwrap();
let high = patch.render(&BTreeMap::from([("pitch".into(), 1760.0)])).unwrap();
assert_ne!(low, high);
assert_eq!(low, patch.render(&BTreeMap::from([("pitch".into(), 220.0)])).unwrap());