Skip to main content

Registry

Struct Registry 

Source
pub struct Registry { /* private fields */ }
Expand description

Plugins by id.

Implementations§

Source§

impl Registry

Source

pub fn new() -> Self

Source

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(&registry, s)).collect::<Result<Vec<_>, _>>()?;
63    let output = apply_chain(&registry, &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}
Source

pub fn register(&mut self, plugin: Arc<dyn Plugin>)

Adds a plugin, replacing one with the same id.

Source

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}
Source

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}
Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

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§

Source§

impl Clone for Registry

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Registry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Registry

§

impl !UnwindSafe for Registry

§

impl Forget for Registry

§

impl Freeze for Registry
where *const LeafNode<&'static str, Arc<dyn Plugin>> is !null: Freeze, PhantomData<(Owned, LeafOrInternal)>: Freeze, PhantomData<Box<(&'static str, Arc<dyn Plugin>)>>: Freeze,

§

impl Move for Registry

§

impl Send for Registry
where NodeRef<Owned, &'static str, Arc<dyn Plugin>, LeafOrInternal>: Send, BoxRaw<(&'static str, Arc<dyn Plugin>)>: Send,

§

impl Sync for Registry
where NodeRef<Owned, &'static str, Arc<dyn Plugin>, LeafOrInternal>: Sync, BoxRaw<(&'static str, Arc<dyn Plugin>)>: Sync,

§

impl Unpin for Registry
where *const LeafNode<&'static str, Arc<dyn Plugin>> is !null: Unpin, Box<(&'static str, Arc<dyn Plugin>)>: Unpin,

§

impl UnsafeUnpin for Registry
where *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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.