Skip to content

Commit

Permalink
Get rid of SignalDestination since that only applied to tick1, and re…
Browse files Browse the repository at this point in the history
…name ReusableSignalDestination to take its place
  • Loading branch information
ahicks92 committed Dec 19, 2024
1 parent 9435d96 commit b3b4f15
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 42 deletions.
4 changes: 2 additions & 2 deletions crates/synthizer/src/chain_mathops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ macro_rules! impl_mathop {
fn tick<
'a,
I: FnMut(usize) -> &'a Self::Input,
D: ReusableSignalDestination<Self::Output>,
D: SignalDestination<Self::Output>,
const N: usize,
>(
ctx: &'_ mut SignalExecutionContext<'_, '_, Self::State, Self::Parameters>,
Expand Down Expand Up @@ -84,7 +84,7 @@ macro_rules! impl_mathop {
left.into_iter().zip(right.into_iter()).for_each(|(l, r)| {
let l = unsafe { l.assume_init() };
let r = unsafe { r.assume_init() };
destination.send_reusable(l.$method(r));
destination.send(l.$method(r));
});
}

Expand Down
20 changes: 3 additions & 17 deletions crates/synthizer/src/core_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub(crate) mod sealed {
fn tick<
'a,
I: FnMut(usize) -> &'a Self::Input,
D: ReusableSignalDestination<Self::Output>,
D: SignalDestination<Self::Output>,
const N: usize,
>(
ctx: &'_ mut SignalExecutionContext<'_, '_, Self::State, Self::Parameters>,
Expand Down Expand Up @@ -76,11 +76,7 @@ pub(crate) mod sealed {
}

pub trait SignalDestination<Input: Sized> {
fn send(self, value: Input);
}

pub trait ReusableSignalDestination<Input: Sized>: SignalDestination<Input> {
fn send_reusable(&mut self, value: Input);
fn send(&mut self, value: Input);
}

/// A frame of audio data, which can be stored on the stack.
Expand Down Expand Up @@ -142,21 +138,11 @@ pub(crate) mod sealed {
pub(crate) use sealed::*;

impl<F, Input> SignalDestination<Input> for F
where
Input: Sized,
F: FnOnce(Input),
{
fn send(self, value: Input) {
self(value)
}
}

impl<F, Input> ReusableSignalDestination<Input> for F
where
Input: Sized,
F: FnMut(Input),
{
fn send_reusable(&mut self, value: Input) {
fn send(&mut self, value: Input) {
(*self)(value)
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/synthizer/src/signals/and_then.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ where
fn tick<
'a,
I: FnMut(usize) -> &'a Self::Input,
D: ReusableSignalDestination<Self::Output>,
D: SignalDestination<Self::Output>,
const N: usize,
>(
ctx: &'_ mut SignalExecutionContext<'_, '_, Self::State, Self::Parameters>,
Expand Down
4 changes: 2 additions & 2 deletions crates/synthizer/src/signals/audio_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ where
fn tick<
'a,
I: FnMut(usize) -> &'a Self::Input,
D: ReusableSignalDestination<Self::Output>,
D: SignalDestination<Self::Output>,
const N: usize,
>(
ctx: &'_ mut SignalExecutionContext<'_, '_, Self::State, Self::Parameters>,
Expand All @@ -50,7 +50,7 @@ where

// We do have to actually use the destination, as this drives computations elsewhere.
for _ in 0..config::BLOCK_SIZE {
destination.send_reusable(());
destination.send(());
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/synthizer/src/signals/consume_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ where
fn tick<
'a,
SigI: FnMut(usize) -> &'a Self::Input,
D: ReusableSignalDestination<Self::Output>,
D: SignalDestination<Self::Output>,
const N: usize,
>(
ctx: &'_ mut SignalExecutionContext<'_, '_, Self::State, Self::Parameters>,
Expand All @@ -53,7 +53,7 @@ where
ctx,
|_| &ni,
|v| {
destination.send_reusable(v);
destination.send(v);
},
);
}
Expand Down
6 changes: 2 additions & 4 deletions crates/synthizer/src/signals/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ where
fn tick<
'a,
I: FnMut(usize) -> &'a Self::Input,
D: ReusableSignalDestination<Self::Output>,
D: SignalDestination<Self::Output>,
const N: usize,
>(
ctx: &'_ mut SignalExecutionContext<'_, '_, Self::State, Self::Parameters>,
Expand All @@ -48,9 +48,7 @@ where
) where
Self::Input: 'a,
{
Sig::tick::<_, _, N>(ctx, input, |x: Sig::Output| {
destination.send_reusable(x.into())
});
Sig::tick::<_, _, N>(ctx, input, |x: Sig::Output| destination.send(x.into()));
}

fn trace_slots<
Expand Down
7 changes: 3 additions & 4 deletions crates/synthizer/src/signals/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ where
fn tick<
'a,
I: FnMut(usize) -> &'a Self::Input,
D: ReusableSignalDestination<Self::Output>,
D: SignalDestination<Self::Output>,
const N: usize,
>(
ctx: &'_ mut crate::context::SignalExecutionContext<'_, '_, Self::State, Self::Parameters>,
Expand All @@ -55,9 +55,8 @@ where
i += 1;
});

outs.iter().for_each(|i| {
destination.send_reusable((ctx.state.closure)(unsafe { i.assume_init_ref() }))
});
outs.iter()
.for_each(|i| destination.send((ctx.state.closure)(unsafe { i.assume_init_ref() })));

// The mapping closure gets references, so we must drop this ourselves.
unsafe {
Expand Down
4 changes: 2 additions & 2 deletions crates/synthizer/src/signals/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ unsafe impl Signal for NullSignal {
fn tick<
'a,
I: FnMut(usize) -> &'a Self::Input,
D: ReusableSignalDestination<Self::Output>,
D: SignalDestination<Self::Output>,
const N: usize,
>(
_ctx: &'_ mut SignalExecutionContext<'_, '_, Self::State, Self::Parameters>,
Expand All @@ -27,7 +27,7 @@ unsafe impl Signal for NullSignal {
{
for i in 0..N {
input(i);
destination.send_reusable(());
destination.send(());
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/synthizer/src/signals/periodic_f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ where
fn tick<
'a,
I: FnMut(usize) -> &'a Self::Input,
D: ReusableSignalDestination<Self::Output>,
D: SignalDestination<Self::Output>,
const N: usize,
>(
ctx: &'_ mut SignalExecutionContext<'_, '_, Self::State, Self::Parameters>,
Expand All @@ -72,7 +72,7 @@ where
);

increments.into_iter().for_each(|val| {
destination.send_reusable(inc1(ctx.state, ctx.parameters, val));
destination.send(inc1(ctx.state, ctx.parameters, val));
});
}

Expand Down
4 changes: 2 additions & 2 deletions crates/synthizer/src/signals/scalars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ macro_rules! impl_scalar {
fn tick<
'a,
I: FnMut(usize) -> &'a Self::Input,
D: ReusableSignalDestination<Self::Output>,
D: SignalDestination<Self::Output>,
const N: usize,
>(
ctx: &'_ mut SignalExecutionContext<'_, '_, Self::State, Self::Parameters>,
Expand All @@ -27,7 +27,7 @@ mut destination: D,
Self::Input: 'a {
for i in 0..N {
input(i);
destination.send_reusable(*ctx.parameters);
destination.send(*ctx.parameters);
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/synthizer/src/signals/slots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ where
fn tick<
'a,
I: FnMut(usize) -> &'a Self::Input,
D: ReusableSignalDestination<Self::Output>,
D: SignalDestination<Self::Output>,
const N: usize,
>(
ctx: &'_ mut crate::context::SignalExecutionContext<'_, '_, Self::State, Self::Parameters>,
Expand All @@ -168,7 +168,7 @@ where
};

for _ in 0..N {
destination.send_reusable(val.clone());
destination.send(val.clone());
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/synthizer/src/signals/trig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ where
fn tick<
'a,
I: FnMut(usize) -> &'a Self::Input,
D: ReusableSignalDestination<Self::Output>,
D: SignalDestination<Self::Output>,
const N: usize,
>(
ctx: &'_ mut SignalExecutionContext<'_, '_, Self::State, Self::Parameters>,
Expand All @@ -32,7 +32,7 @@ where
) where
Self::Input: 'a,
{
S::tick::<_, _, N>(ctx, input, |x: f64| destination.send_reusable(x.sin()));
S::tick::<_, _, N>(ctx, input, |x: f64| destination.send(x.sin()));
}

fn trace_slots<
Expand Down

0 comments on commit b3b4f15

Please sign in to comment.