Added MatrixCellChain abstraction

This commit is contained in:
Weird Constructor 2022-07-24 06:58:09 +02:00
parent 1a4be5421d
commit 10bb0f96f4
2 changed files with 40 additions and 1 deletions

View file

@ -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;

View file

@ -1,4 +1,4 @@
// Copyright (c) 2021 Weird Constructor <weirdconstructor@gmail.com>
// Copyright (c) 2021-2022 Weird Constructor <weirdconstructor@gmail.com>
// 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<u8>, i2: Option<u8>, i3: Option<u8>) -> Self {
self.in1 = i1;
self.in2 = i2;