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§

source§

impl CodeEngine

source

pub fn new_with_lib(lib: Rc<RefCell<DSPNodeTypeLibrary>>) -> Self

Constructor for your custom DSPNodeTypeLibrary.

source

pub fn set_debug(&mut self, debug: bool)

Enabled debug information collection:

source

pub fn get_debug_info(&self) -> String

Retrieves debug information:

source

pub fn new_stdlib() -> Self

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

source

pub fn get_lib(&self) -> Rc<RefCell<DSPNodeTypeLibrary>>

Returns the DSPNodeTypeLibrary that is used by this CodeEngine.

source

pub fn atom(&self, idx: usize) -> Option<Arc<AtomicFloat>>

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.

source

pub fn atom_get(&self, idx: usize) -> f32

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.

source

pub fn atom_set(&self, idx: usize, v: f32)

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.

source

pub fn upload(&mut self, ast: Box<ASTNode>) -> Result<(), JITCompileError>

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();
 // ..
source

pub fn send_buffer(&mut self, index: usize, buf: Vec<f64>)

source

pub fn send_table(&mut self, index: usize, buf: Arc<Vec<f32>>)

source

pub fn reset(&mut self)

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

source

pub fn query_returns(&mut self)

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

source

pub fn get_backend(&mut self) -> CodeEngineBackend

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§

source§

impl Clone for CodeEngine

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Drop for CodeEngine

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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> 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,

§

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>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.