pub struct SynthConstructor {
    config: NodeConfigurator,
    exec: Option<NodeExecutor>,
    nodes: HashMap<NodeId, Box<NodeConfig>>,
    graph_ordering: NodeGraphOrdering,
}
Expand description

A convenient highlevel API to HexoDSP for building custom synthesizers from HexoDSP nodes.

This API combines with the crate::build API for defining compile time checked HexoDSP graphs in Rust.

You also have the possibility of providing your own DSP nodes using the SynthConstructor::set_dynamic_node1x1 function and the crate::DynamicNode1x1 trait.

Fields

config: NodeConfiguratorexec: Option<NodeExecutor>nodes: HashMap<NodeId, Box<NodeConfig>>graph_ordering: NodeGraphOrdering

Implementations

Clears the DSP graph.

Retrieves the NodeExecutor for handing to your audio thread.

Try to update only DSP node parameters. If you did any graph changes, a new DSP graph will be uploaded on the fly though. Call this if you only want to update specific parameters. The function returns a boolean flag, that is true if the DSP graph was reuploaded. It returns an error if something is wrong with the input graph to this function.

 use hexodsp::SynthConstructor;
 use hexodsp::build::*;
 let mut sc = SynthConstructor::new();

 // Set the `freq` parameter of the BOsc(0) node to 400Hz:
 let uploaded_new_graph = sc.update_params(&bosc(0).set().freq(400.0)).unwrap();

Updates the dynamic node for the Rust1x1 nodes. The index refers to the instance NodeId::Rust1x1(index). The new DSP code is preserved for the first use of that node, and can also be swapped out at runtime anytime while the DSP graph is working.

 use hexodsp::{SynthConstructor, DynamicNode1x1, DynNode1x1Context};
 use hexodsp::build::*;

 let mut sc = SynthConstructor::new();

 // Setup the input of the Rust1x1 node to receive an 880Hz sine.
 let sine_gen_out = &sin(0).set().freq(880.0).output().sig();
 let r1x1 = rust1x1(0).input().inp(sine_gen_out);

 // you can provide up to 4 extra parameters (alpha, beta, gamma, delta):
 let r1x1 = r1x1.set().alpha(0.75);

 // You may replace this function anytime at runtime:
 sc.set_dynamic_node1x1(0, Box::new(|inp: &[f32], out: &mut [f32], ctx: &DynNode1x1Context| {
     let alpha = ctx.alpha_slice();

     for (i, in_sample) in inp.iter().enumerate() {
         out[i] = in_sample * alpha[i];
     }

     // This sets an atomic float that can be read out using SynthConstructor::led_value()!
     ctx.led_value().set(out[0]);
 }));

 sc.upload(&out(0).input().ch1(&r1x1.output().sig()));

Returns the atomic phase value for NodeId.

Returns the atomic LED value for NodeId.

Updates internal states. For instance for providing feedback values for SynthConstructor::output_feedback and SynthConstructor::output_feedback_minmax.

Retrieves the output port feedback for a specific output of the given NodeId.

Make sure to call SynthConstructor::poll regularily to update the feedback values.

See also NodeConfigurator::out_fb_for.

 use hexodsp::{NodeId, SynthConstructor};

 let mut sc = SynthConstructor::new();

 // Setup stuff with sc here..

 // In a loop call eg.:
 sc.poll();
 let node_id = NodeId::BOsc(0);
 let out_idx = NodeId::BOsc(0).out("sig").unwrap();
 if let Some(value) = sc.output_feedback(&node_id, out_idx) {
     println!("Current min/max output of BOsc(0).sig={}", value);
 }

Retrieves the output port feedback for a specific output of the given NodeId. The output is slightly filtered and provides the min and max values over a few of the most recent calls to SynthConstructor::poll.

Make sure to call SynthConstructor::poll regularily to update the feedback values.

See also NodeConfigurator::out_fb_for.

 use hexodsp::{NodeId, SynthConstructor};

 let mut sc = SynthConstructor::new();

 // Setup stuff with sc here..

 // In a loop call eg.:
 sc.poll();
 let node_id = NodeId::BOsc(0);
 let out_idx = NodeId::BOsc(0).out("sig").unwrap();
 let (min, max) = sc.output_feedback_minmax(&node_id, out_idx);
 println!("Current min/max output of BOsc(0).sig={}/{}", min, max);

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.