Struct synfx_dsp_jit::engine::CodeEngine
source · [−]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
sourceimpl CodeEngine
impl CodeEngine
sourcepub fn new_with_lib(lib: Rc<RefCell<DSPNodeTypeLibrary>>) -> Self
pub fn new_with_lib(lib: Rc<RefCell<DSPNodeTypeLibrary>>) -> Self
Constructor for your custom DSPNodeTypeLibrary.
sourcepub fn get_debug_info(&self) -> String
pub fn get_debug_info(&self) -> String
Retrieves debug information:
sourcepub fn new_stdlib() -> Self
pub fn new_stdlib() -> Self
Constructor with the default standard library that comes with synfx-dsp-jit
.
sourcepub fn get_lib(&self) -> Rc<RefCell<DSPNodeTypeLibrary>>
pub fn get_lib(&self) -> Rc<RefCell<DSPNodeTypeLibrary>>
Returns the DSPNodeTypeLibrary that is used by this CodeEngine.
sourcepub fn atom(&self, idx: usize) -> Option<Arc<AtomicFloat>>
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.
sourcepub fn atom_get(&self, idx: usize) -> f32
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.
sourcepub fn atom_set(&self, idx: usize, v: f32)
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.
sourcepub fn upload(&mut self, ast: Box<ASTNode>) -> Result<(), JITCompileError>
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();
// ..
pub fn send_buffer(&mut self, index: usize, buf: Vec<f64>)
pub fn send_table(&mut self, index: usize, buf: Arc<Vec<f32>>)
sourcepub fn reset(&mut self)
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.
sourcepub fn query_returns(&mut self)
pub fn query_returns(&mut self)
Call this regularily in the frontend/worker thread for cleanup purposes.
sourcepub fn get_backend(&mut self) -> CodeEngineBackend
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