Starting fsk demod
This commit is contained in:
@ -8,6 +8,7 @@ use zyn::ext::TypeExt;
|
||||
use zyn::quote::quote;
|
||||
use zyn::syn::Field;
|
||||
use zyn::syn::GenericParam;
|
||||
use zyn::syn::Lifetime;
|
||||
use zyn::syn::parse_quote;
|
||||
|
||||
use crate::SyncBlockConfig;
|
||||
@ -23,28 +24,41 @@ pub fn sync_block_impl(item: zyn::syn::ItemStruct, config: SyncBlockConfig) -> z
|
||||
// module to keep everything clean
|
||||
mod {{ item.ident | snake | ident: "{}_synchronous_block" }}
|
||||
{
|
||||
use super::*;
|
||||
|
||||
@sync_block_view_struct(item = item.clone())
|
||||
}
|
||||
|
||||
@sync_block_syncio_impl(item = item.clone(), config = *config)
|
||||
@sync_block_impl_block(item = item.clone())
|
||||
@sync_block_impl_block(item = item.clone(), tagged = config.tagged)
|
||||
)
|
||||
}
|
||||
|
||||
// Block implementation for sync block
|
||||
#[zyn::element]
|
||||
fn sync_block_syncio_impl(item: zyn::syn::ItemStruct, config: SyncBlockConfig) -> zyn::TokenStream
|
||||
{
|
||||
let view_lifetime: GenericParam = parse_quote!('view);
|
||||
let mut view_generics = item.generics.clone();
|
||||
view_generics.params.iter_mut().for_each(|x| match x
|
||||
{
|
||||
GenericParam::Lifetime(_) =>
|
||||
{}
|
||||
GenericParam::Type(type_param) => type_param
|
||||
.bounds
|
||||
.push(zyn::syn::TypeParamBound::Lifetime(parse_quote!('view))),
|
||||
GenericParam::Const(_) =>
|
||||
{}
|
||||
});
|
||||
view_generics.params.insert(0, view_lifetime);
|
||||
|
||||
let (view_impl_generics, view_type_generics, _view_where_clause) =
|
||||
let (view_impl_generics, view_type_generics, view_where_clause) =
|
||||
view_generics.split_for_impl();
|
||||
let (_impl_generics, type_generics, where_clause) = item.generics.split_for_impl();
|
||||
let (_impl_generics, type_generics, _where_clause) = item.generics.split_for_impl();
|
||||
|
||||
zyn::zyn!(
|
||||
impl {{ view_impl_generics }} oxydsp_flowgraph::block::SyncBlockIO<'view> for {{ item.ident }} {{ type_generics }}
|
||||
{{ where_clause }}
|
||||
{{ view_where_clause }}
|
||||
{
|
||||
// Path within module
|
||||
type StateView = {{ item.ident | snake | ident: "{}_synchronous_block" }}::{{ item.ident | ident:"{}View" }} {{ view_type_generics }};
|
||||
@ -54,6 +68,7 @@ fn sync_block_syncio_impl(item: zyn::syn::ItemStruct, config: SyncBlockConfig) -
|
||||
)
|
||||
}
|
||||
|
||||
// Input/Output types for block
|
||||
fn sync_block_io_types(
|
||||
item: zyn::syn::ItemStruct,
|
||||
io: &'static str,
|
||||
@ -116,15 +131,26 @@ fn sync_block_io_types(
|
||||
.into_token_stream()
|
||||
}
|
||||
|
||||
// View struct for sync block
|
||||
#[zyn::element]
|
||||
fn sync_block_view_struct(item: zyn::syn::ItemStruct) -> zyn::TokenStream
|
||||
{
|
||||
// Create view liftime to add to struct definition
|
||||
let lifetime: GenericParam = parse_quote!('view);
|
||||
let mut generics = item.generics.clone();
|
||||
generics.params.iter_mut().for_each(|x| match x
|
||||
{
|
||||
GenericParam::Lifetime(_) =>
|
||||
{}
|
||||
GenericParam::Type(type_param) => type_param
|
||||
.bounds
|
||||
.push(zyn::syn::TypeParamBound::Lifetime(parse_quote!('view))),
|
||||
GenericParam::Const(_) =>
|
||||
{}
|
||||
});
|
||||
generics.params.insert(0, lifetime);
|
||||
|
||||
let (_impl_generics, type_generics, where_clause) = generics.split_for_impl();
|
||||
let (impl_generics, _type_generics, where_clause) = generics.split_for_impl();
|
||||
let fields = &item.fields.as_named().unwrap().named;
|
||||
|
||||
let mut state_fields = vec![];
|
||||
@ -169,7 +195,8 @@ fn sync_block_view_struct(item: zyn::syn::ItemStruct) -> zyn::TokenStream
|
||||
.filter(|tokens| !tokens.is_empty());
|
||||
|
||||
zyn::zyn!(
|
||||
pub struct {{ item.ident | ident:"{}View" }} {{ type_generics }}
|
||||
pub struct {{ item.ident | ident:"{}View" }} {{ impl_generics }}
|
||||
{{ where_clause }}
|
||||
{
|
||||
@for (field in state_fields.iter())
|
||||
{
|
||||
@ -185,187 +212,7 @@ fn sync_block_view_struct(item: zyn::syn::ItemStruct) -> zyn::TokenStream
|
||||
)
|
||||
}
|
||||
|
||||
#[zyn::element]
|
||||
fn sync_block_impl_block(item: zyn::syn::ItemStruct) -> zyn::TokenStream
|
||||
{
|
||||
let item2 = item.clone();
|
||||
let (impl_generics, type_generics, where_clause) = item2.generics.split_for_impl();
|
||||
let fields = &item.fields.as_named().unwrap().named;
|
||||
|
||||
// Retrieve fields
|
||||
let input_fields = fields
|
||||
.iter()
|
||||
.filter(|f| f.attrs.iter().any(|attr| attr.is("input")))
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
let output_fields = fields
|
||||
.iter()
|
||||
.filter(|f| f.attrs.iter().any(|attr| attr.is("output")))
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
zyn::zyn!(
|
||||
impl {{ impl_generics }} oxydsp_flowgraph::block::Block for {{ item.ident }} {{ type_generics }}
|
||||
{{ where_clause }}
|
||||
{
|
||||
fn work(&mut self) -> oxydsp_flowgraph::block::BlockResult
|
||||
{
|
||||
|
||||
// Get writers from outputs
|
||||
let mut max_len = usize::MAX;
|
||||
@for (out_field in output_fields.iter())
|
||||
{
|
||||
let {{ out_field.ident.clone().unwrap() | ident: "{}_writer"}} = self.{{ out_field.ident }}.write();
|
||||
}
|
||||
|
||||
// Compute max_len
|
||||
let max_len = [
|
||||
usize::MAX,
|
||||
@for (out_field in output_fields.iter())
|
||||
{
|
||||
{{ out_field.ident.clone().unwrap() | ident: "{}_writer"}}.len(),
|
||||
}
|
||||
].iter().min().unwrap();
|
||||
|
||||
|
||||
@if (!input_fields.is_empty())
|
||||
{
|
||||
@sync_block_block_impl_with_inputs(item = item.clone(), input_fields = input_fields.clone(), output_fields = output_fields.clone())
|
||||
}
|
||||
@else
|
||||
{
|
||||
@sync_block_block_impl_without_inputs(item = item.clone(), output_fields = output_fields.clone())
|
||||
}
|
||||
|
||||
oxydsp_flowgraph::block::BlockResult::Ok
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
#[zyn::element]
|
||||
fn sync_block_block_impl_without_inputs(
|
||||
item: zyn::syn::ItemStruct,
|
||||
output_fields: Vec<Field>,
|
||||
) -> zyn::TokenStream
|
||||
{
|
||||
zyn::zyn!(
|
||||
for _ in 0..max_len
|
||||
{
|
||||
// Get outputs
|
||||
@if (output_fields.len() == 1)
|
||||
{
|
||||
let {{output_fields[0].ident.clone().unwrap() | ident:"{}_element"}}
|
||||
}
|
||||
@else
|
||||
{
|
||||
let state = {{ sync_block_make_view_struct(item.clone()) }};
|
||||
let (@for (out_field in output_fields.iter())
|
||||
{
|
||||
{{out_field.ident.clone().unwrap() | ident:"{}_element"}},
|
||||
}
|
||||
)
|
||||
}
|
||||
= <Self as oxydsp_flowgraph::block::SyncBlock>::sync_work(state, ()).unwrap();
|
||||
|
||||
// Now the output samples must be sent to their resepective outputs
|
||||
@for (out_field in output_fields.iter())
|
||||
{
|
||||
{{ out_field.ident.clone().unwrap() | ident: "{}_writer"}}.push(
|
||||
(
|
||||
{{ out_field.ident.clone().unwrap() | ident: "{}_element"}}, None
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
#[zyn::element]
|
||||
fn sync_block_block_impl_with_inputs(
|
||||
item: zyn::syn::ItemStruct,
|
||||
input_fields: Vec<Field>,
|
||||
output_fields: Vec<Field>,
|
||||
) -> zyn::TokenStream
|
||||
{
|
||||
zyn::zyn!(
|
||||
|
||||
// Iterate on inputs
|
||||
(
|
||||
@for (in_field in input_fields.iter())
|
||||
{
|
||||
&mut self.{{ in_field.ident }},
|
||||
}
|
||||
).pop_iter()
|
||||
.take(max_len)
|
||||
.for_each(
|
||||
// Deconstruct foreach arguments
|
||||
|
|
||||
(@for (in_field in input_fields.iter())
|
||||
{
|
||||
oxydsp_flowgraph::tag::Tagged({{in_field.ident.clone().unwrap() | ident:"{}_element"}},
|
||||
{{in_field.ident.clone().unwrap() | ident:"{}_tag_opt"}}),
|
||||
})
|
||||
|
|
||||
{
|
||||
// Create output tag
|
||||
let common_tag = oxydsp_flowgraph::tag::Tag::merge_tag_opts([
|
||||
@for (in_field in input_fields.iter())
|
||||
{
|
||||
{{in_field.ident.clone().unwrap() | ident:"{}_tag_opt"}}.clone(),
|
||||
}
|
||||
]);
|
||||
|
||||
let state = {{ sync_block_make_view_struct(item.clone()) }};
|
||||
// Compute output sample
|
||||
@if (output_fields.is_empty())
|
||||
{
|
||||
let _
|
||||
}
|
||||
@else if (output_fields.len() == 1)
|
||||
{
|
||||
let oxydsp_flowgraph::tag::Tagged({{output_fields[0].ident.clone().unwrap() | ident:"{}_element"}}, {{output_fields[0].ident.clone().unwrap() | ident:"{}_tag_opt"}})
|
||||
}
|
||||
@else
|
||||
{
|
||||
let (@for (out_field in output_fields.iter())
|
||||
{
|
||||
oxydsp_flowgraph::tag::Tagged({{out_field.ident.clone().unwrap() | ident:"{}_element"}}, {{out_field.ident.clone().unwrap() | ident:"{}_tag_opt"}}),
|
||||
}
|
||||
)
|
||||
}
|
||||
= <Self as oxydsp_flowgraph::block::SyncBlock>::sync_work(state,
|
||||
@if (input_fields.len() == 1)
|
||||
{
|
||||
oxydsp_flowgraph::tag::Tagged({{input_fields[0].ident.clone().unwrap() | ident:"{}_element"}}, {{input_fields[0].ident.clone().unwrap() | ident:"{}_tag_opt"}}.clone())
|
||||
}
|
||||
@else
|
||||
{
|
||||
(@for (in_field in input_fields.iter())
|
||||
{
|
||||
oxydsp_flowgraph::tag::Tagged({{in_field.ident.clone().unwrap() | ident:"{}_element"}}, {{in_field.ident.clone().unwrap() | ident:"{}_tag_opt"}}.clone()),
|
||||
}
|
||||
)
|
||||
}
|
||||
).unwrap();
|
||||
|
||||
// Now the output samples must be sent to their resepective outputs
|
||||
@for (out_field in output_fields.iter())
|
||||
{
|
||||
{{ out_field.ident.clone().unwrap() | ident: "{}_writer"}}.push(
|
||||
oxydsp_flowgraph::tag::Tagged(
|
||||
{{ out_field.ident.clone().unwrap() | ident: "{}_element"}},
|
||||
{{ out_field.ident.clone().unwrap() | ident: "{}_tag_opt"}}.merge(common_tag),
|
||||
)
|
||||
);
|
||||
}
|
||||
//
|
||||
|
||||
}
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
// Instantiates the view struct
|
||||
fn sync_block_make_view_struct(item: zyn::syn::ItemStruct) -> zyn::TokenStream
|
||||
{
|
||||
let fields = &item.fields.as_named().unwrap().named;
|
||||
@ -395,3 +242,282 @@ fn sync_block_make_view_struct(item: zyn::syn::ItemStruct) -> zyn::TokenStream
|
||||
)
|
||||
.into_token_stream()
|
||||
}
|
||||
|
||||
// Impl Block for syncio
|
||||
#[zyn::element]
|
||||
fn sync_block_impl_block(item: zyn::syn::ItemStruct, tagged: bool) -> zyn::TokenStream
|
||||
{
|
||||
let item2 = item.clone();
|
||||
let (impl_generics, type_generics, where_clause) = item2.generics.split_for_impl();
|
||||
let fields = &item.fields.as_named().unwrap().named;
|
||||
|
||||
// Retrieve fields
|
||||
let input_fields = fields
|
||||
.iter()
|
||||
.filter(|f| f.attrs.iter().any(|attr| attr.is("input")))
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
let output_fields = fields
|
||||
.iter()
|
||||
.filter(|f| f.attrs.iter().any(|attr| attr.is("output")))
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
zyn::zyn!(
|
||||
impl {{ impl_generics }} oxydsp_flowgraph::block::Block for {{ item.ident }} {{ type_generics }}
|
||||
{{ where_clause }}
|
||||
{
|
||||
fn work(&mut self) -> oxydsp_flowgraph::block::BlockResult
|
||||
{
|
||||
use oxydsp_flowgraph::tag::TagMergable;
|
||||
// Get writers from outputs
|
||||
let mut max_len = usize::MAX;
|
||||
@for (out_field in output_fields.iter())
|
||||
{
|
||||
let {{ out_field.ident.clone().unwrap() | ident: "{}_writer"}} = self.{{ out_field.ident }}.write();
|
||||
}
|
||||
|
||||
// Compute max_len
|
||||
let max_len = *([
|
||||
usize::MAX,
|
||||
@for (out_field in output_fields.iter())
|
||||
{
|
||||
{{ out_field.ident.clone().unwrap() | ident: "{}_writer"}}.len(),
|
||||
}
|
||||
].iter().min().unwrap());
|
||||
|
||||
|
||||
@if (!input_fields.is_empty())
|
||||
{
|
||||
@sync_block_block_impl_with_inputs(item = item.clone(), input_fields = input_fields.clone(), output_fields = output_fields.clone(), tagged = *tagged)
|
||||
}
|
||||
@else
|
||||
{
|
||||
@sync_block_block_impl_without_inputs(item = item.clone(), output_fields = output_fields.clone(), tagged = *tagged)
|
||||
}
|
||||
|
||||
oxydsp_flowgraph::block::BlockResult::Ok
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// Impl Block for syncio (no inputs)
|
||||
#[zyn::element]
|
||||
fn sync_block_block_impl_without_inputs(
|
||||
item: zyn::syn::ItemStruct,
|
||||
output_fields: Vec<Field>,
|
||||
tagged: bool,
|
||||
) -> zyn::TokenStream
|
||||
{
|
||||
zyn::zyn!(
|
||||
for _ in 0..max_len
|
||||
{
|
||||
// Get outputs
|
||||
let state = {{ sync_block_make_view_struct(item.clone()) }};
|
||||
let @sync_block_output_descons(output_fields = output_fields.clone(), tagged = *tagged) =
|
||||
<Self as oxydsp_flowgraph::block::SyncBlock>::sync_work(state, ()).unwrap();
|
||||
|
||||
// Now the output samples must be sent to their resepective outputs
|
||||
@for (out_field in output_fields.iter())
|
||||
{
|
||||
@if (*tagged)
|
||||
{
|
||||
let _ = {{ out_field.ident.clone().unwrap() | ident: "{}_writer"}}.push(
|
||||
oxydsp_flowgraph::tag::Tagged(
|
||||
{{ out_field.ident.clone().unwrap() | ident: "{}_element"}},
|
||||
{{ out_field.ident.clone().unwrap() | ident: "{}_tag_opt"}},
|
||||
)
|
||||
);
|
||||
} @else
|
||||
{
|
||||
let _ = {{ out_field.ident.clone().unwrap() | ident: "{}_writer"}}.push(
|
||||
oxydsp_flowgraph::tag::Tagged(
|
||||
{{ out_field.ident.clone().unwrap() | ident: "{}_element"}},
|
||||
None,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// Impl Block for syncio (with inputs)
|
||||
#[zyn::element]
|
||||
fn sync_block_block_impl_with_inputs(
|
||||
item: zyn::syn::ItemStruct,
|
||||
input_fields: Vec<Field>,
|
||||
output_fields: Vec<Field>,
|
||||
tagged: bool,
|
||||
) -> zyn::TokenStream
|
||||
{
|
||||
zyn::zyn!(
|
||||
|
||||
use oxydsp_flowgraph::io::PopIterable;
|
||||
// Iterate on inputs
|
||||
(
|
||||
@for (in_field in input_fields.iter())
|
||||
{
|
||||
&mut self.{{ in_field.ident }},
|
||||
}
|
||||
).pop_iter()
|
||||
.take(max_len)
|
||||
.for_each(
|
||||
// Deconstruct foreach arguments
|
||||
|
|
||||
(@for (in_field in input_fields.iter())
|
||||
{
|
||||
oxydsp_flowgraph::tag::Tagged({{in_field.ident.clone().unwrap() | ident:"{}_element"}},
|
||||
{{in_field.ident.clone().unwrap() | ident:"{}_tag_opt"}}),
|
||||
})
|
||||
|
|
||||
{
|
||||
// Create output tag
|
||||
let common_tag = oxydsp_flowgraph::tag::Tag::merge_tag_opts([
|
||||
@for (in_field in input_fields.iter())
|
||||
{
|
||||
{{in_field.ident.clone().unwrap() | ident:"{}_tag_opt"}}.clone(),
|
||||
}
|
||||
]);
|
||||
|
||||
let state = {{ sync_block_make_view_struct(item.clone()) }};
|
||||
// Compute output sample
|
||||
let @sync_block_output_descons(output_fields = output_fields.clone(), tagged = *tagged)
|
||||
= <Self as oxydsp_flowgraph::block::SyncBlock>::sync_work(state, @sync_block_input_cons(input_fields = input_fields.clone(), tagged = *tagged)).unwrap();
|
||||
|
||||
// Now the output samples must be sent to their resepective outputs
|
||||
@for (out_field in output_fields.iter())
|
||||
{
|
||||
@if (*tagged)
|
||||
{
|
||||
let _ = {{ out_field.ident.clone().unwrap() | ident: "{}_writer"}}.push(
|
||||
oxydsp_flowgraph::tag::Tagged(
|
||||
{{ out_field.ident.clone().unwrap() | ident: "{}_element"}},
|
||||
{{ out_field.ident.clone().unwrap() | ident: "{}_tag_opt"}}.merge(&common_tag),
|
||||
)
|
||||
);
|
||||
} @else
|
||||
{
|
||||
let _ = {{ out_field.ident.clone().unwrap() | ident: "{}_writer"}}.push(
|
||||
oxydsp_flowgraph::tag::Tagged(
|
||||
{{ out_field.ident.clone().unwrap() | ident: "{}_element"}},
|
||||
common_tag,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
//
|
||||
|
||||
}
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
#[zyn::element]
|
||||
fn sync_block_output_descons(output_fields: Vec<Field>, tagged: bool) -> zyn::TokenStream
|
||||
{
|
||||
#[allow(clippy::collapsible_else_if)]
|
||||
if *tagged
|
||||
{
|
||||
// If tagged : deconstruct tags
|
||||
if output_fields.is_empty()
|
||||
{
|
||||
zyn::zyn!(_)
|
||||
}
|
||||
else if output_fields.len() == 1
|
||||
{
|
||||
zyn::zyn!(
|
||||
oxydsp_flowgraph::tag::Tagged({{output_fields[0].ident.clone().unwrap() | ident:"{}_element"}}, {{output_fields[0].ident.clone().unwrap() | ident:"{}_tag_opt"}})
|
||||
)
|
||||
}
|
||||
else
|
||||
{
|
||||
zyn::zyn!(
|
||||
(@for (in_field in output_fields.iter())
|
||||
{
|
||||
oxydsp_flowgraph::tag::Tagged({{in_field.ident.clone().unwrap() | ident:"{}_element"}}, {{in_field.ident.clone().unwrap() | ident:"{}_tag_opt"}}.clone()),
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise just get the output element
|
||||
if output_fields.is_empty()
|
||||
{
|
||||
zyn::zyn!(_)
|
||||
}
|
||||
else if output_fields.len() == 1
|
||||
{
|
||||
zyn::zyn!(
|
||||
{{output_fields[0].ident.clone().unwrap() | ident:"{}_element"}}
|
||||
)
|
||||
}
|
||||
else
|
||||
{
|
||||
zyn::zyn!(
|
||||
(@for (in_field in output_fields.iter())
|
||||
{
|
||||
{{in_field.ident.clone().unwrap() | ident:"{}_element"}},
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[zyn::element]
|
||||
fn sync_block_input_cons(input_fields: Vec<Field>, tagged: bool) -> zyn::TokenStream
|
||||
{
|
||||
#[allow(clippy::collapsible_else_if)]
|
||||
if *tagged
|
||||
{
|
||||
// If tagged : deconstruct tags
|
||||
if input_fields.is_empty()
|
||||
{
|
||||
zyn::zyn!(())
|
||||
}
|
||||
else if input_fields.len() == 1
|
||||
{
|
||||
zyn::zyn!(
|
||||
oxydsp_flowgraph::tag::Tagged({{input_fields[0].ident.clone().unwrap() | ident:"{}_element"}}, {{input_fields[0].ident.clone().unwrap() | ident:"{}_tag_opt"}})
|
||||
)
|
||||
}
|
||||
else
|
||||
{
|
||||
zyn::zyn!(
|
||||
(@for (in_field in input_fields.iter())
|
||||
{
|
||||
oxydsp_flowgraph::tag::Tagged({{in_field.ident.clone().unwrap() | ident:"{}_element"}}, {{in_field.ident.clone().unwrap() | ident:"{}_tag_opt"}}.clone()),
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise just get the output element
|
||||
if input_fields.is_empty()
|
||||
{
|
||||
zyn::zyn!(_)
|
||||
}
|
||||
else if input_fields.len() == 1
|
||||
{
|
||||
zyn::zyn!(
|
||||
{{input_fields[0].ident.clone().unwrap() | ident:"{}_element"}}
|
||||
)
|
||||
}
|
||||
else
|
||||
{
|
||||
zyn::zyn!(
|
||||
(@for (in_field in input_fields.iter())
|
||||
{
|
||||
{{in_field.ident.clone().unwrap() | ident:"{}_element"}},
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,8 +9,10 @@ pub enum BlockResult
|
||||
|
||||
// Signifies that the block finished its work
|
||||
// Running it again would be useless
|
||||
// This triggers the graph shutdown
|
||||
Terminated,
|
||||
|
||||
// Kill graph
|
||||
Exit,
|
||||
}
|
||||
|
||||
pub trait BlockIO
|
||||
|
||||
5
oxydsp-flowgraph/src/event.rs
Normal file
5
oxydsp-flowgraph/src/event.rs
Normal file
@ -0,0 +1,5 @@
|
||||
// Represents a FlowGrahWide, simultaneous event
|
||||
pub enum FlowGraphEvent
|
||||
{
|
||||
Kill(String),
|
||||
}
|
||||
@ -49,20 +49,15 @@ impl FlowGraph
|
||||
crate::block::BlockResult::Ok =>
|
||||
{}
|
||||
crate::block::BlockResult::Terminated =>
|
||||
{ //break 'outer;
|
||||
}
|
||||
crate::block::BlockResult::Exit =>
|
||||
{
|
||||
break 'outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _ in 0..10_000
|
||||
{
|
||||
for x in self.blocks.iter_mut()
|
||||
{
|
||||
x.work();
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -131,7 +131,7 @@ impl<T: 'static> Out<T>
|
||||
}
|
||||
}
|
||||
|
||||
pub fn push_iter<I: Iterator<Item = (T, Option<Tag>)>>(&mut self, mut iter: I) -> bool
|
||||
pub fn push_iter<I: Iterator<Item = Tagged<T>>>(&mut self, mut iter: I) -> bool
|
||||
{
|
||||
let writer = self.write();
|
||||
let len = writer.len();
|
||||
@ -140,17 +140,7 @@ impl<T: 'static> Out<T>
|
||||
{
|
||||
if let Some(elt) = iter.next()
|
||||
{
|
||||
match elt.1
|
||||
{
|
||||
Some(tag) =>
|
||||
{
|
||||
let _ = writer.push(Tagged(elt.0, Some(tag)));
|
||||
}
|
||||
None =>
|
||||
{
|
||||
let _ = writer.push_no_tag(elt.0);
|
||||
}
|
||||
}
|
||||
let _ = writer.push(elt);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -220,7 +210,13 @@ impl<T> OutWriter<'_, T>
|
||||
|
||||
pub fn push(&self, data: Tagged<T>) -> Result<(), Tagged<T>>
|
||||
{
|
||||
let (data, tag) = data.into();
|
||||
let (data, mut tag) = data.into();
|
||||
let position = self.data_writer.next_index();
|
||||
if let Some(tag) = &mut tag
|
||||
{
|
||||
tag.position = position
|
||||
}
|
||||
|
||||
match self.data_writer.push(data)
|
||||
{
|
||||
Ok(_) if tag.is_some() =>
|
||||
|
||||
@ -3,8 +3,10 @@
|
||||
|
||||
pub mod block;
|
||||
pub mod edge;
|
||||
pub mod event;
|
||||
pub mod graph;
|
||||
pub mod io;
|
||||
pub mod stream;
|
||||
pub mod tag;
|
||||
pub use oxydsp_flowgraph_macros::{BlockIO, sync_block};
|
||||
pub use oxydsp_flowgraph_macros::BlockIO;
|
||||
pub use oxydsp_flowgraph_macros::sync_block;
|
||||
|
||||
@ -22,6 +22,14 @@ pub struct Tag
|
||||
|
||||
impl Tag
|
||||
{
|
||||
pub fn new() -> Self
|
||||
{
|
||||
Self {
|
||||
position: 0,
|
||||
data: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn merge_tag_opts<const N: usize>(tag_opts: [Option<Tag>; N]) -> Option<Tag>
|
||||
{
|
||||
let mut out_tag = None;
|
||||
@ -31,6 +39,27 @@ impl Tag
|
||||
}
|
||||
out_tag
|
||||
}
|
||||
|
||||
pub fn tag<T: 'static + Send + Sync>(&self, key: impl AsRef<str>, value: T)
|
||||
{
|
||||
self.data
|
||||
.lock()
|
||||
.unwrap()
|
||||
.insert(key.as_ref().to_owned(), Arc::new(value));
|
||||
}
|
||||
|
||||
pub fn retrieve(&self, key: impl AsRef<str>) -> Option<Arc<dyn Any + Send + Sync>>
|
||||
{
|
||||
self.data.lock().unwrap().get(key.as_ref()).cloned()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Tag
|
||||
{
|
||||
fn default() -> Self
|
||||
{
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TagValue: Clone {}
|
||||
@ -93,6 +122,10 @@ impl<T> Tagged<T>
|
||||
{
|
||||
pub fn new(inner: T, tag: Option<Tag>) -> Self
|
||||
{
|
||||
if tag.is_none()
|
||||
{
|
||||
//println!("data has no tag");
|
||||
}
|
||||
Self(inner, tag)
|
||||
}
|
||||
|
||||
@ -156,11 +189,11 @@ impl<T> From<(T, Option<Tag>)> for Tagged<T>
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Into<(T, Option<Tag>)> for Tagged<T>
|
||||
impl<T> From<Tagged<T>> for (T, Option<Tag>)
|
||||
{
|
||||
fn into(self) -> (T, Option<Tag>)
|
||||
fn from(val: Tagged<T>) -> Self
|
||||
{
|
||||
(self.0, self.1)
|
||||
(val.0, val.1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user