Working tag system

This commit is contained in:
2026-03-21 17:16:15 +01:00
parent 582d876abf
commit f468cb3c6d

View File

@ -20,58 +20,130 @@ use oxydsp_flowgraph::BlockIO;
use oxydsp_flowgraph::block::Block;
use oxydsp_flowgraph::block::BlockResult;
use oxydsp_flowgraph::block::SyncBlock;
use oxydsp_flowgraph::block::SyncBlockIO;
use oxydsp_flowgraph::flowgraph;
use oxydsp_flowgraph::graph::FlowGraph;
use oxydsp_flowgraph::io::In;
use oxydsp_flowgraph::io::Out;
use oxydsp_flowgraph::io::PopIterable;
use oxydsp_flowgraph::io::stream;
use oxydsp_flowgraph::sync_block;
use oxydsp_flowgraph::tag::Tag;
use oxydsp_flowgraph::tag::Tagged;
#[derive(BlockIO)]
#[sync_block(tagged)]
//#[sync_block(tagged)]
pub struct Printer<T: 'static + Display>
{
#[input]
input: In<T>,
n: usize,
}
impl<T: 'static + Display> Block for Printer<T>
{
fn work(&mut self) -> BlockResult
{
for x in self.input.pop_iter()
{
if self.n.is_multiple_of(100_000)
{
if x.has_tag()
{
let tag = x.1.unwrap();
let valuea: usize = *tag.retrieve("valuea").unwrap().downcast().unwrap();
let valueb: usize = *tag.retrieve("valueb").unwrap().downcast().unwrap();
println!(
"{} TAGGED {}, {} amoziefjmoazijfmoazeijfmoazeifjmozeijfmoizfmojzaemfojzaemofjzeamofimazoijefmzoaeijfmoazeifj",
x.0, valuea, valueb
);
}
else
{
println!("{} NO TAG", x.0);
}
}
self.n += 1
}
BlockResult::Ok
}
}
// impl<'view, T: 'static + Display> SyncBlock<'view> for Printer<T>
// {
// fn sync_work(state: Self::StateView, input: Self::Input) -> Option<Self::Output>
// {
// // if state.n.is_multiple_of(100_000)
// // {
// if input.has_tag()
// {
// println!("{} TAGGED", input.0);
// }
// else
// {
// println!("{} NO TAG", input.0);
// }
// //}
// *state.n += 1;
// Some(())
// }
// }
#[derive(BlockIO)]
//#[sync_block(tagged)]
pub struct SourceTag
{
#[output]
output: Out<T>,
output: Out<usize>,
tk: String,
n: usize,
}
// impl<T: 'static + Display> Block for Printer<T>
// where
// T: Display,
impl SourceTag
{
pub fn new(tk: String) -> (Self, In<usize>)
{
let (output, input) = stream();
(Self { output, tk, n: 0 }, input)
}
}
// impl<'view> SyncBlock<'view> for SourceTag
// {
// fn work(&mut self) -> oxydsp_flowgraph::block::BlockResult
// fn sync_work(state: Self::StateView, _input: Self::Input) -> Option<Self::Output>
// {
// for x in self.input.pop_iter()
// {
// if self.n.is_multiple_of(2usize.pow(20))
// {
// println!("{}", x.0);
// self.n = 0;
// }
// self.n += 1;
// }
// BlockResult::Ok
// *state.n += 1;
//
// let t = Tag::default();
// Some((*state.n, t).into())
// }
// }
impl<'view, T: 'static + Display> SyncBlock<'view> for Printer<T>
impl Block for SourceTag
{
fn sync_work(state: Self::StateView, input: Self::Input) -> Option<Self::Output>
fn work(&mut self) -> BlockResult
{
*state.n += 1;
if state.n.is_multiple_of(1_000_000)
{
println!("{}", input);
}
Some(())
self.output.push_iter((0usize..).map(|_| {
self.n += 1;
(
self.n - 1,
if (self.n - 1).is_multiple_of(1_000)
{
let tag = Tag::default();
tag.tag(&self.tk, self.n);
Some(tag)
}
else
{
None
},
)
.into()
}));
BlockResult::Ok
}
}
@ -98,18 +170,18 @@ impl<T: 'static + Display> Printer<T>
}
}
fn main()
fn main_tst()
{
let (iter_source_a, a) = IterSource::new(0..);
let (iter_source_b, b) = IterSource::new(0..);
let (sourcea, a) = SourceTag::new("valuea".to_string());
let (sourceb, b) = SourceTag::new("valueb".to_string());
let (adder, a) = Adder::new(a, b);
let printer = Printer::new(a);
let fg = flowgraph![iter_source_a, iter_source_b, adder, printer];
let fg = flowgraph![sourcea, sourceb, adder, printer];
let _ = fg.run().join();
}
fn main_fsk()
fn main()
{
let sample_rate = 48_000;
let sample_per_symbol = 96;