From 10bb0f96f49fdbd421a730b27cc7a4b114c32afd Mon Sep 17 00:00:00 2001 From: Weird Constructor Date: Sun, 24 Jul 2022 06:58:09 +0200 Subject: [PATCH] Added MatrixCellChain abstraction --- src/lib.rs | 1 + src/matrix.rs | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 7840467..ed6096d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -284,6 +284,7 @@ pub mod matrix_repr; pub mod monitor; pub mod nodes; pub mod sample_lib; +pub mod chain_builder; mod util; pub use cell_dir::CellDir; diff --git a/src/matrix.rs b/src/matrix.rs index 2591165..2e5925f 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -1,4 +1,4 @@ -// Copyright (c) 2021 Weird Constructor +// Copyright (c) 2021-2022 Weird Constructor // This file is a part of HexoDSP. Released under GPL-3.0-or-later. // See README.md and COPYING for details. @@ -149,6 +149,10 @@ impl Cell { self.out3 = None; } + pub fn set_node_id_keep_ios(&mut self, node_id: NodeId) { + self.node_id = node_id; + } + pub fn label<'a>(&self, buf: &'a mut [u8]) -> Option<&'a str> { use std::io::Write; let mut cur = std::io::Cursor::new(buf); @@ -261,6 +265,40 @@ impl Cell { } } + /// This is a helper function to quickly set an input by name and direction. + /// + ///``` + /// use hexodsp::*; + /// + /// let mut cell = Cell::empty(NodeId::Sin(0)); + /// cell.set_input_by_name("freq", CellDir::T).unwrap(); + ///``` + pub fn set_input_by_name(&mut self, name: &str, dir: CellDir) -> Result<(), ()> { + if let Some(idx) = self.node_id.inp(name) { + self.set_io_dir(dir, idx as usize); + Ok(()) + } else { + Err(()) + } + } + + /// This is a helper function to quickly set an output by name and direction. + /// + ///``` + /// use hexodsp::*; + /// + /// let mut cell = Cell::empty(NodeId::Sin(0)); + /// cell.set_output_by_name("sig", CellDir::B).unwrap(); + ///``` + pub fn set_output_by_name(&mut self, name: &str, dir: CellDir) -> Result<(), ()> { + if let Some(idx) = self.node_id.out(name) { + self.set_io_dir(dir, idx as usize); + Ok(()) + } else { + Err(()) + } + } + pub fn input(mut self, i1: Option, i2: Option, i3: Option) -> Self { self.in1 = i1; self.in2 = i2;