From b3b4f156a8219feda4f1c639f53b232832eda97a Mon Sep 17 00:00:00 2001 From: Austin Hicks Date: Thu, 19 Dec 2024 12:26:37 -0800 Subject: [PATCH] Get rid of SignalDestination since that only applied to tick1, and rename ReusableSignalDestination to take its place --- crates/synthizer/src/chain_mathops.rs | 4 ++-- crates/synthizer/src/core_traits.rs | 20 +++---------------- crates/synthizer/src/signals/and_then.rs | 2 +- crates/synthizer/src/signals/audio_io.rs | 4 ++-- crates/synthizer/src/signals/consume_input.rs | 4 ++-- crates/synthizer/src/signals/conversion.rs | 6 ++---- crates/synthizer/src/signals/map.rs | 7 +++---- crates/synthizer/src/signals/null.rs | 4 ++-- crates/synthizer/src/signals/periodic_f64.rs | 4 ++-- crates/synthizer/src/signals/scalars.rs | 4 ++-- crates/synthizer/src/signals/slots.rs | 4 ++-- crates/synthizer/src/signals/trig.rs | 4 ++-- 12 files changed, 25 insertions(+), 42 deletions(-) diff --git a/crates/synthizer/src/chain_mathops.rs b/crates/synthizer/src/chain_mathops.rs index 6bbbd92..ea70619 100644 --- a/crates/synthizer/src/chain_mathops.rs +++ b/crates/synthizer/src/chain_mathops.rs @@ -51,7 +51,7 @@ macro_rules! impl_mathop { fn tick< 'a, I: FnMut(usize) -> &'a Self::Input, - D: ReusableSignalDestination, + D: SignalDestination, const N: usize, >( ctx: &'_ mut SignalExecutionContext<'_, '_, Self::State, Self::Parameters>, @@ -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)); }); } diff --git a/crates/synthizer/src/core_traits.rs b/crates/synthizer/src/core_traits.rs index 1f91177..8391a50 100644 --- a/crates/synthizer/src/core_traits.rs +++ b/crates/synthizer/src/core_traits.rs @@ -36,7 +36,7 @@ pub(crate) mod sealed { fn tick< 'a, I: FnMut(usize) -> &'a Self::Input, - D: ReusableSignalDestination, + D: SignalDestination, const N: usize, >( ctx: &'_ mut SignalExecutionContext<'_, '_, Self::State, Self::Parameters>, @@ -76,11 +76,7 @@ pub(crate) mod sealed { } pub trait SignalDestination { - fn send(self, value: Input); - } - - pub trait ReusableSignalDestination: SignalDestination { - 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. @@ -142,21 +138,11 @@ pub(crate) mod sealed { pub(crate) use sealed::*; impl SignalDestination for F -where - Input: Sized, - F: FnOnce(Input), -{ - fn send(self, value: Input) { - self(value) - } -} - -impl ReusableSignalDestination for F where Input: Sized, F: FnMut(Input), { - fn send_reusable(&mut self, value: Input) { + fn send(&mut self, value: Input) { (*self)(value) } } diff --git a/crates/synthizer/src/signals/and_then.rs b/crates/synthizer/src/signals/and_then.rs index 7020e42..345ae80 100644 --- a/crates/synthizer/src/signals/and_then.rs +++ b/crates/synthizer/src/signals/and_then.rs @@ -29,7 +29,7 @@ where fn tick< 'a, I: FnMut(usize) -> &'a Self::Input, - D: ReusableSignalDestination, + D: SignalDestination, const N: usize, >( ctx: &'_ mut SignalExecutionContext<'_, '_, Self::State, Self::Parameters>, diff --git a/crates/synthizer/src/signals/audio_io.rs b/crates/synthizer/src/signals/audio_io.rs index a88cc0e..dc7ade2 100644 --- a/crates/synthizer/src/signals/audio_io.rs +++ b/crates/synthizer/src/signals/audio_io.rs @@ -25,7 +25,7 @@ where fn tick< 'a, I: FnMut(usize) -> &'a Self::Input, - D: ReusableSignalDestination, + D: SignalDestination, const N: usize, >( ctx: &'_ mut SignalExecutionContext<'_, '_, Self::State, Self::Parameters>, @@ -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(()); } } diff --git a/crates/synthizer/src/signals/consume_input.rs b/crates/synthizer/src/signals/consume_input.rs index 22425e4..0fb0d2a 100644 --- a/crates/synthizer/src/signals/consume_input.rs +++ b/crates/synthizer/src/signals/consume_input.rs @@ -39,7 +39,7 @@ where fn tick< 'a, SigI: FnMut(usize) -> &'a Self::Input, - D: ReusableSignalDestination, + D: SignalDestination, const N: usize, >( ctx: &'_ mut SignalExecutionContext<'_, '_, Self::State, Self::Parameters>, @@ -53,7 +53,7 @@ where ctx, |_| &ni, |v| { - destination.send_reusable(v); + destination.send(v); }, ); } diff --git a/crates/synthizer/src/signals/conversion.rs b/crates/synthizer/src/signals/conversion.rs index 552ea54..029cdb7 100644 --- a/crates/synthizer/src/signals/conversion.rs +++ b/crates/synthizer/src/signals/conversion.rs @@ -39,7 +39,7 @@ where fn tick< 'a, I: FnMut(usize) -> &'a Self::Input, - D: ReusableSignalDestination, + D: SignalDestination, const N: usize, >( ctx: &'_ mut SignalExecutionContext<'_, '_, Self::State, Self::Parameters>, @@ -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< diff --git a/crates/synthizer/src/signals/map.rs b/crates/synthizer/src/signals/map.rs index 63ab9cb..1627c54 100644 --- a/crates/synthizer/src/signals/map.rs +++ b/crates/synthizer/src/signals/map.rs @@ -39,7 +39,7 @@ where fn tick< 'a, I: FnMut(usize) -> &'a Self::Input, - D: ReusableSignalDestination, + D: SignalDestination, const N: usize, >( ctx: &'_ mut crate::context::SignalExecutionContext<'_, '_, Self::State, Self::Parameters>, @@ -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 { diff --git a/crates/synthizer/src/signals/null.rs b/crates/synthizer/src/signals/null.rs index 6cfa148..b5127d3 100644 --- a/crates/synthizer/src/signals/null.rs +++ b/crates/synthizer/src/signals/null.rs @@ -16,7 +16,7 @@ unsafe impl Signal for NullSignal { fn tick< 'a, I: FnMut(usize) -> &'a Self::Input, - D: ReusableSignalDestination, + D: SignalDestination, const N: usize, >( _ctx: &'_ mut SignalExecutionContext<'_, '_, Self::State, Self::Parameters>, @@ -27,7 +27,7 @@ unsafe impl Signal for NullSignal { { for i in 0..N { input(i); - destination.send_reusable(()); + destination.send(()); } } diff --git a/crates/synthizer/src/signals/periodic_f64.rs b/crates/synthizer/src/signals/periodic_f64.rs index 9ffcd65..85d3948 100644 --- a/crates/synthizer/src/signals/periodic_f64.rs +++ b/crates/synthizer/src/signals/periodic_f64.rs @@ -51,7 +51,7 @@ where fn tick< 'a, I: FnMut(usize) -> &'a Self::Input, - D: ReusableSignalDestination, + D: SignalDestination, const N: usize, >( ctx: &'_ mut SignalExecutionContext<'_, '_, Self::State, Self::Parameters>, @@ -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)); }); } diff --git a/crates/synthizer/src/signals/scalars.rs b/crates/synthizer/src/signals/scalars.rs index fa4a0a1..e1abb93 100644 --- a/crates/synthizer/src/signals/scalars.rs +++ b/crates/synthizer/src/signals/scalars.rs @@ -17,7 +17,7 @@ macro_rules! impl_scalar { fn tick< 'a, I: FnMut(usize) -> &'a Self::Input, - D: ReusableSignalDestination, + D: SignalDestination, const N: usize, >( ctx: &'_ mut SignalExecutionContext<'_, '_, Self::State, Self::Parameters>, @@ -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); } } diff --git a/crates/synthizer/src/signals/slots.rs b/crates/synthizer/src/signals/slots.rs index f86728a..a4a4de2 100644 --- a/crates/synthizer/src/signals/slots.rs +++ b/crates/synthizer/src/signals/slots.rs @@ -153,7 +153,7 @@ where fn tick< 'a, I: FnMut(usize) -> &'a Self::Input, - D: ReusableSignalDestination, + D: SignalDestination, const N: usize, >( ctx: &'_ mut crate::context::SignalExecutionContext<'_, '_, Self::State, Self::Parameters>, @@ -168,7 +168,7 @@ where }; for _ in 0..N { - destination.send_reusable(val.clone()); + destination.send(val.clone()); } } diff --git a/crates/synthizer/src/signals/trig.rs b/crates/synthizer/src/signals/trig.rs index 624a981..c38017e 100644 --- a/crates/synthizer/src/signals/trig.rs +++ b/crates/synthizer/src/signals/trig.rs @@ -23,7 +23,7 @@ where fn tick< 'a, I: FnMut(usize) -> &'a Self::Input, - D: ReusableSignalDestination, + D: SignalDestination, const N: usize, >( ctx: &'_ mut SignalExecutionContext<'_, '_, Self::State, Self::Parameters>, @@ -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<