diff --git a/example/src/main.rs b/example/src/main.rs index bcc5507..d7ffa97 100644 --- a/example/src/main.rs +++ b/example/src/main.rs @@ -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 { #[input] input: In, + n: usize, +} + +impl Block for Printer +{ + 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 +// { +// fn sync_work(state: Self::StateView, input: Self::Input) -> Option +// { +// // 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, + output: Out, + + tk: String, n: usize, } -// impl Block for Printer -// where -// T: Display, +impl SourceTag +{ + pub fn new(tk: String) -> (Self, In) + { + 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 // { -// 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 +impl Block for SourceTag { - fn sync_work(state: Self::StateView, input: Self::Input) -> Option + 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 Printer } } -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;