use crate::{
compiler::IoChannelInfo,
utils::{error::ReportableError, metadata::Location},
};
use thiserror::Error;
pub mod ffi;
pub mod ffi_serde;
pub mod primitives;
pub mod vm;
pub mod vm_ffi;
#[cfg(not(target_arch = "wasm32"))]
pub mod wasm;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct Time(pub u64);
pub type ReturnCode = i64;
pub enum ProgramPayload {
VmProgram(vm::Program),
#[cfg(not(target_arch = "wasm32"))]
WasmModule {
bytes: Vec<u8>,
prepared_engine: Box<crate::runtime::wasm::engine::WasmEngine>,
dsp_state_skeleton: Option<state_tree::tree::StateTreeSkeleton<crate::mir::StateType>>,
state_patch_plan: state_tree::StateStoragePatchPlan,
prewarmed_global_state: Vec<u64>,
},
}
pub trait DspRuntime {
fn run_dsp(&mut self, time: Time) -> ReturnCode;
fn get_output(&self, n_channels: usize) -> &[f64];
fn set_input(&mut self, input: &[f64]);
fn io_channels(&self) -> Option<IoChannelInfo>;
fn set_sample_rate(&mut self, _sample_rate: f64) {}
fn try_hot_swap(&mut self, new_program: ProgramPayload) -> bool {
let _ = new_program;
false
}
fn as_any(&self) -> &dyn std::any::Any;
fn as_any_mut(&mut self) -> &mut dyn std::any::Any;
}
#[derive(Debug, Error)]
pub enum ErrorKind {
#[error("Unknown Error")]
Unknown,
}
#[derive(Debug, Error)]
#[error("Runtime Error: {0}")]
pub struct RuntimeError(pub ErrorKind, pub Location);
impl ReportableError for RuntimeError {
fn get_labels(&self) -> Vec<(crate::utils::metadata::Location, String)> {
vec![(self.1.clone(), self.0.to_string())]
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn ensure_payload_is_send() {
fn assert_send<T: Send>() {}
assert_send::<ProgramPayload>();
}
}