pub struct CodeEngine { /* private fields */ }
Expand description

This is the frontend handle for the DSP code execution engine.

You create it with either CodeEngine::new_with_lib or CodeEngine::new_stdlib. Afterwards you split off the backend/real time thread handle with CodeEngine::get_backend. In the backend you must make sure to call CodeEngineBackend::set_sample_rate at least once and CodeEngineBackend::process_updates regularily.

Once the audio thread runs, you can call CodeEngine::upload with an ASTNode tree. The tree can be built for instance with the helper functions in crate::build. To process feedback and unused old DSPFunction instances, you must call CodeEngine::query_returns regularily. In a GUI for instance each frame, or in the idle callback of the event loop.

This is the rough way to use this API:

 use synfx_dsp_jit::engine::CodeEngine;
 use synfx_dsp_jit::build::*;

 let mut engine = CodeEngine::new_stdlib();

 let mut backend = engine.get_backend();
 std::thread::spawn(move || {
     backend.set_sample_rate(44100.0);

     loop {
         backend.process_updates();

         for frame in 0..64 {
             let (s1, s2, ret) = backend.process(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
         }
     }
 });

 // Upload a new piece of code:
 engine.upload(call("sin", 1, &[literal(1.0)])).unwrap();

 // Call this regularily!!!!
 engine.query_returns();

A more elaborate example can be found at the top level: crate

Implementations

Constructor for your custom DSPNodeTypeLibrary.

Enabled debug information collection:

Retrieves debug information:

Constructor with the default standard library that comes with synfx-dsp-jit.

Returns the DSPNodeTypeLibrary that is used by this CodeEngine.

Returns you a reference to the specified atom connected with the DSP backend. These atoms can be read and written in the DSPFunction using the atomr and atomw nodes.

A shortcut to access a specific atom that was written with the atomw node. An alternative is the CodeEngine::atom method to directly access the AtomicFloat.

A shortcut to access a specific atom that can be read with the atomr (or atomr~) node. An alternative is the CodeEngine::atom method to directly access the AtomicFloat.

Compiles and uploads a new piece of DSP code to the backend thread.

 use synfx_dsp_jit::engine::CodeEngine;
 use synfx_dsp_jit::build::*;

 let mut engine = CodeEngine::new_stdlib();
 // ..
 engine.upload(call("sin", 1, &[literal(1.0)])).unwrap();
 // ..

Emits a message to the backend to cause a reset of the DSPFunction. All non persistent state is resetted in this case.

Call this regularily in the frontend/worker thread for cleanup purposes.

Use this function to split off a CodeEngineBackend handle. If you call this multiple times, the previously generated CodeEngineBackend instances will not receive any updates anymore (for now).

 use synfx_dsp_jit::engine::CodeEngine;
 use synfx_dsp_jit::build::*;

 let mut engine = CodeEngine::new_stdlib();

 let mut backend = engine.get_backend();
 std::thread::spawn(move || {
     backend.set_sample_rate(44100.0);
     loop {
         backend.process_updates();
         // ...
     }
 });

See also the module description for a more complete example crate::engine

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Executes the destructor for this type. Read more

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 resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
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.