Working base

This commit is contained in:
2026-03-13 21:57:10 +01:00
parent 092fb0191f
commit 866a5dd501
23 changed files with 1050 additions and 321 deletions

View File

@ -1,4 +1,61 @@
use std::{fmt::Display, fs::File, io::Write};
use oxydsp_dsp::blocks::{math::basic::Adder, utilities::iter::IterSource};
use oxydsp_flowgraph::{
BlockIO,
block::{Block, BlockResult},
edge::{In, PopIterable},
flowgraph,
graph::FlowGraph,
};
#[derive(BlockIO)]
pub struct Printer<T: 'static>
{
#[input]
input: In<T>,
n: usize,
}
impl<T: 'static> Printer<T>
{
pub fn new(input: In<T>) -> Self
{
Self { input, n: 0 }
}
}
impl<T: 'static> Block for Printer<T>
where
T: Display,
{
fn work(&mut self) -> oxydsp_flowgraph::block::BlockResult
{
for x in self.input.pop_iter()
{
if self.n.is_multiple_of(2usize.pow(20))
{
println!("{}", x);
self.n = 0;
}
self.n += 1;
}
BlockResult::Ok
}
}
fn main()
{
println!("Hello, world!");
let (iter_a, a) = IterSource::new(0usize..);
let (iter_b, b) = IterSource::new(0usize..);
let (adder, added) = Adder::new(a, b);
let printer = Printer::new(added);
let graph = flowgraph![iter_a, iter_b, adder, printer];
File::create("out.dot")
.unwrap()
.write_all(graph.get_dot().as_bytes())
.unwrap();
graph.run();
}