//! Signal routing — connects module outputs to inputs. //! //! A `Patch` is a fixed-size connection graph. Each cable routes //! the output buffer of one slot into the CV or audio input of another. //! Const generics keep everything on the stack. /// A single cable: from slot `src` output to slot `dst` input. #[derive(Clone, Copy, Debug, PartialEq)] pub struct Cable { pub src: usize, pub dst: usize, } /// A fixed-capacity patch with up to `MAX_CABLES` connections. pub struct Patch { cables: heapless::Vec, } impl Patch { pub fn new() -> Self { Self { cables: heapless::Vec::new() } } /// Add a cable; returns `Err(cable)` if the patch is full. pub fn connect(&mut self, src: usize, dst: usize) -> Result<(), Cable> { self.cables.push(Cable { src, dst }).map_err(|_| Cable { src, dst }) } pub fn disconnect(&mut self, src: usize, dst: usize) { self.cables.retain(|c| !(c.src == src && c.dst == dst)); } pub fn cables(&self) -> &[Cable] { &self.cables } } impl Default for Patch { fn default() -> Self { Self::new() } }