pub struct Registry { /* private fields */ }Expand description
Plugins by id.
Implementations§
Source§impl Registry
impl Registry
pub fn new() -> Self
Sourcepub fn with_builtins() -> Self
pub fn with_builtins() -> Self
A registry with every built-in.
Examples found in repository?
examples/apply_chain.rs (line 55)
50fn run() -> Result<(), String> {
51 let args: Vec<String> = std::env::args().skip(1).collect();
52 if args.len() < 2 {
53 return Err("usage: apply_chain IN.wav|--demo OUT.wav [STEP...] (see the file's docs)".into());
54 }
55 let registry = Registry::with_builtins();
56 let input = if args[0] == "--demo" {
57 demo()
58 } else {
59 let bytes = std::fs::read(&args[0]).map_err(|e| format!("{}: {e}", args[0]))?;
60 Waveform::from_wav(&bytes).map_err(|e| format!("{}: {e}", args[0]))?
61 };
62 let chain = args[2..].iter().map(|s| parse_step(®istry, s)).collect::<Result<Vec<_>, _>>()?;
63 let output = apply_chain(®istry, &input, &chain).map_err(|e| e.to_string())?;
64 std::fs::write(&args[1], output.to_wav(WavFormat::Pcm24)).map_err(|e| format!("{}: {e}", args[1]))?;
65 println!(
66 "{} steps; {} Hz, {} ch, {} frames; peak {:.1} dBFS -> {:.1} dBFS; rms {:.1} dBFS -> {:.1} dBFS; wrote {}",
67 chain.len(),
68 output.sample_rate(),
69 output.channels(),
70 output.frames(),
71 input.peak_db(),
72 output.peak_db(),
73 input.rms_db(),
74 output.rms_db(),
75 args[1]
76 );
77 Ok(())
78}Sourcepub fn register(&mut self, plugin: Arc<dyn Plugin>)
pub fn register(&mut self, plugin: Arc<dyn Plugin>)
Adds a plugin, replacing one with the same id.
Sourcepub fn get(&self, id: &str) -> Option<&Arc<dyn Plugin>>
pub fn get(&self, id: &str) -> Option<&Arc<dyn Plugin>>
Examples found in repository?
examples/apply_chain.rs (line 36)
32fn parse_step(registry: &Registry, text: &str) -> Result<PluginInstance, String> {
33 let (bypass, text) = text.strip_prefix('!').map_or((false, text), |t| (true, t));
34 let (name, args) = text.split_once(':').unwrap_or((text, ""));
35 let id = if name.contains('.') { name.to_string() } else { format!("weirdnet.{name}") };
36 let plugin = registry.get(&id).ok_or_else(|| format!("no plugin {id:?}; have {}", registry.ids().collect::<Vec<_>>().join(", ")))?;
37 let mut values = ParamValues::new();
38 for pair in args.split(',').filter(|p| !p.is_empty()) {
39 let (key, raw) = pair.split_once('=').ok_or_else(|| format!("{pair:?} is not name=value"))?;
40 let spec = plugin.params().iter().find(|s| s.name == key).ok_or_else(|| format!("{id} has no parameter {key:?}"))?;
41 values = match &spec.kind {
42 ParamKind::Float => values.with_float(key, raw.parse().map_err(|_| format!("{key}: {raw:?} is not a number"))?),
43 ParamKind::Bool => values.with_bool(key, raw.parse().map_err(|_| format!("{key}: {raw:?} is not true or false"))?),
44 ParamKind::Choice(_) => values.with_choice(key, raw),
45 };
46 }
47 Ok(PluginInstance { plugin: id, values, bypass })
48}Sourcepub fn ids(&self) -> impl Iterator<Item = &'static str> + '_
pub fn ids(&self) -> impl Iterator<Item = &'static str> + '_
Ids in order.
Examples found in repository?
examples/apply_chain.rs (line 36)
32fn parse_step(registry: &Registry, text: &str) -> Result<PluginInstance, String> {
33 let (bypass, text) = text.strip_prefix('!').map_or((false, text), |t| (true, t));
34 let (name, args) = text.split_once(':').unwrap_or((text, ""));
35 let id = if name.contains('.') { name.to_string() } else { format!("weirdnet.{name}") };
36 let plugin = registry.get(&id).ok_or_else(|| format!("no plugin {id:?}; have {}", registry.ids().collect::<Vec<_>>().join(", ")))?;
37 let mut values = ParamValues::new();
38 for pair in args.split(',').filter(|p| !p.is_empty()) {
39 let (key, raw) = pair.split_once('=').ok_or_else(|| format!("{pair:?} is not name=value"))?;
40 let spec = plugin.params().iter().find(|s| s.name == key).ok_or_else(|| format!("{id} has no parameter {key:?}"))?;
41 values = match &spec.kind {
42 ParamKind::Float => values.with_float(key, raw.parse().map_err(|_| format!("{key}: {raw:?} is not a number"))?),
43 ParamKind::Bool => values.with_bool(key, raw.parse().map_err(|_| format!("{key}: {raw:?} is not true or false"))?),
44 ParamKind::Choice(_) => values.with_choice(key, raw),
45 };
46 }
47 Ok(PluginInstance { plugin: id, values, bypass })
48}pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn process(
&self,
id: &str,
input: &Waveform,
values: &ParamValues,
) -> Result<Waveform, PluginError>
pub fn process( &self, id: &str, input: &Waveform, values: &ParamValues, ) -> Result<Waveform, PluginError>
Resolves values against the plugin’s parameters and runs it.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Registry
impl !UnwindSafe for Registry
impl Forget for Registry
impl Freeze for Registry
impl Move for Registry
impl Send for Registry
impl Sync for Registry
impl Unpin for Registry
impl UnsafeUnpin for Registrywhere
*const LeafNode<&'static str, Arc<dyn Plugin>> is !null: UnsafeUnpin,
PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin,
PhantomData<Box<(&'static str, Arc<dyn Plugin>)>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more