Starts synchronous block interface

This commit is contained in:
2026-03-19 15:28:31 +01:00
parent f727c119b8
commit 2baee8d28b
11 changed files with 348 additions and 260 deletions

View File

@ -3,7 +3,8 @@ use std::ops::{Add, Mul};
use oxydsp_flowgraph::{
BlockIO,
block::{Block, BlockResult},
edge::{In, Out, PopIterable, stream},
io::{In, Out, PopIterable},
tag::TagMergable,
};
#[derive(BlockIO)]
@ -31,7 +32,7 @@ where
{
pub fn new(input_a: In<Ia>, input_b: In<Ib>) -> (Self, In<O>)
{
let (output, added) = stream();
let (output, added) = oxydsp_flowgraph::io::stream();
(
Self {
input_a,
@ -54,7 +55,7 @@ where
self.output.push_iter(
(&mut self.input_a, &mut self.input_b)
.pop_iter()
.map(|(a, b)| a + b),
.map(|(a, b)| (a.0 + b.0, a.1.merge(&b.1))),
);
BlockResult::Ok
}
@ -85,7 +86,7 @@ where
{
pub fn new(input_a: In<Ia>, input_b: In<Ib>) -> (Self, In<O>)
{
let (output, added) = stream();
let (output, added) = oxydsp_flowgraph::io::stream();
(
Self {
input_a,
@ -108,7 +109,7 @@ where
self.output.push_iter(
(&mut self.input_a, &mut self.input_b)
.pop_iter()
.map(|(a, b)| a * b),
.map(|(a, b)| (a.0 * b.0, a.1.merge(&b.1))),
);
BlockResult::Ok
}

View File

@ -4,10 +4,10 @@ use num::Float;
use oxydsp_flowgraph::BlockIO;
use oxydsp_flowgraph::block::Block;
use oxydsp_flowgraph::block::BlockResult;
use oxydsp_flowgraph::edge::In;
use oxydsp_flowgraph::edge::Out;
use oxydsp_flowgraph::edge::PopIterable;
use oxydsp_flowgraph::edge::stream;
use oxydsp_flowgraph::io::In;
use oxydsp_flowgraph::io::Out;
use oxydsp_flowgraph::io::PopIterable;
use oxydsp_flowgraph::io::stream;
#[derive(BlockIO)]
pub struct OscillatorSource<T: Float + From<f32> + 'static>
@ -31,7 +31,7 @@ impl<T: Float + From<f32> + 'static> Block for OscillatorSource<T>
{
fn work(&mut self) -> oxydsp_flowgraph::block::BlockResult
{
self.output.push_iter(&mut self.nco);
self.output.push_iter((&mut self.nco).map(|x| (x, None)));
BlockResult::Ok
}
}
@ -81,8 +81,8 @@ impl<T: Float + From<f32> + 'static> Block for Nco<T>
{
self.output
.push_iter(&mut self.frequency.pop_iter().map(|f| {
self.nco.set_frequency(f);
self.nco.next().unwrap()
self.nco.set_frequency(f.0);
(self.nco.next().unwrap(), f.1)
}));
BlockResult::Ok
}

View File

@ -1,7 +1,8 @@
use oxydsp_flowgraph::{
BlockIO,
block::{Block, BlockResult},
edge::{In, Out, PopIterable, stream},
io::{In, Out, PopIterable, stream},
tag::Tag,
};
#[derive(BlockIO)]
@ -33,7 +34,8 @@ where
{
fn work(&mut self) -> oxydsp_flowgraph::block::BlockResult
{
self.output.push_iter(self.input.pop_iter().map(&self.map));
self.output
.push_iter(self.input.pop_iter().map(|x| ((&self.map)(x.0), x.1)));
BlockResult::Ok
}
}
@ -46,7 +48,7 @@ pub struct Repeat<T: 'static>
repetitions: usize,
remaining: usize,
current: Option<T>,
current: Option<(T, Option<Tag>)>,
#[output]
output: Out<T>,
@ -82,13 +84,24 @@ impl<T: Clone + 'static> Block for Repeat<T>
{
if self.remaining == 0 || self.current.is_none()
{
self.current = Some(reader.pop().unwrap());
self.current = Some(reader.pop_tagged().unwrap());
self.remaining = self.repetitions;
}
writer
.push(self.current.clone().unwrap())
.unwrap_or_else(|_| panic!());
match &mut self.current
{
Some((_, tag)) =>
{
*tag = None;
}
None =>
{}
}
self.remaining -= 1;
}

View File

@ -3,7 +3,7 @@ use std::sync::mpsc::{Receiver, Sender, SyncSender};
use oxydsp_flowgraph::{
BlockIO,
block::{Block, BlockResult},
edge::{In, Out, PopIterable, stream},
io::{In, Out, PopIterable, stream},
};
#[derive(BlockIO)]
@ -45,7 +45,7 @@ impl<I: 'static> Block for RxSource<Receiver<I>, I>
{
fn work(&mut self) -> oxydsp_flowgraph::block::BlockResult
{
if self.output.push_iter(self.input.iter())
if self.output.push_iter(self.input.iter().map(|x| (x, None)))
{
BlockResult::Ok
}
@ -63,7 +63,7 @@ impl<I: 'static> Block for TxSink<Sender<I>, I>
if self
.input
.pop_iter()
.map(|x| self.output.send(x))
.map(|x| self.output.send(x.0))
.any(|res| res.is_err())
{
BlockResult::Terminated
@ -82,7 +82,7 @@ impl<I: 'static> Block for TxSink<SyncSender<I>, I>
if self
.input
.pop_iter()
.map(|x| self.output.send(x))
.map(|x| self.output.send(x.0))
.any(|res| res.is_err())
{
BlockResult::Terminated

View File

@ -1,7 +1,7 @@
use oxydsp_flowgraph::{
BlockIO,
block::{Block, BlockResult},
edge::{In, Out, stream},
io::{In, Out, stream},
};
#[derive(BlockIO)]
@ -34,7 +34,7 @@ where
{
fn work(&mut self) -> oxydsp_flowgraph::block::BlockResult
{
if self.output.push_iter(&mut self.iter)
if self.output.push_iter((&mut self.iter).map(|x| (x, None)))
{
BlockResult::Ok
}