From 5f3a3bd05e05a0d00955565122f246634fc8277f Mon Sep 17 00:00:00 2001 From: Adrien Prokopowicz Date: Sat, 26 Oct 2024 17:05:21 +0200 Subject: [PATCH] Better lifetimes in PortPair, add missing Copy/Clone implementations for Port pairs and related types --- plugin/src/process.rs | 4 ++-- plugin/src/process/audio/pair.rs | 24 +++++++++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/plugin/src/process.rs b/plugin/src/process.rs index a532a7e..4d30e01 100644 --- a/plugin/src/process.rs +++ b/plugin/src/process.rs @@ -237,8 +237,8 @@ impl<'a> Audio<'a> { /// channel buffers pointed to by `buffers`. #[inline] pub unsafe fn from_raw_buffers( - inputs: *const [clap_audio_buffer], - outputs: *const [clap_audio_buffer], + inputs: *mut [clap_audio_buffer], + outputs: *mut [clap_audio_buffer], frames_count: u32, ) -> Self { Self { diff --git a/plugin/src/process/audio/pair.rs b/plugin/src/process/audio/pair.rs index a1b6e5e..ebc8043 100644 --- a/plugin/src/process/audio/pair.rs +++ b/plugin/src/process/audio/pair.rs @@ -43,7 +43,7 @@ impl<'a> PortPair<'a> { /// /// If the port layout is asymmetric and there is no input port, this returns [`None`]. #[inline] - pub fn input(&self) -> Option { + pub fn input(&self) -> Option> { self.input // SAFETY: this type ensures the buffer is valid and matches frame_count .map(|i| unsafe { Port::from_raw(i, self.frames_count) }) @@ -53,7 +53,7 @@ impl<'a> PortPair<'a> { /// /// If the port layout is asymmetric and there is no output port, this returns [`None`]. #[inline] - pub fn output(&self) -> Option { + pub fn output(&self) -> Option> { self.output // SAFETY: this type ensures the buffer is valid and matches frame_count .map(|i| unsafe { Port::from_raw(i, self.frames_count) }) @@ -150,7 +150,6 @@ impl<'a> PortPair<'a> { /// /// The sample type `S` is always going to be either [`f32`] or [`f64`], as returned by /// [`PortPair::channels`]. -#[derive(Copy, Clone)] pub struct PairedChannels<'a, S> { input_data: &'a [*mut S], output_data: &'a [*mut S], @@ -223,6 +222,13 @@ impl<'a, S> PairedChannels<'a, S> { } } +impl<'a, S> Copy for PairedChannels<'a, S> {} +impl<'a, S> Clone for PairedChannels<'a, S> { + fn clone(&self) -> Self { + *self + } +} + impl<'a, S> IntoIterator for PairedChannels<'a, S> { type Item = ChannelPair<'a, S>; type IntoIter = PairedChannelsIter<'a, S>; @@ -282,7 +288,19 @@ impl ExactSizeIterator for PairedChannelsIter<'_, S> { } } +impl<'a, S> Clone for PairedChannelsIter<'a, S> { + #[inline] + fn clone(&self) -> Self { + Self { + input_iter: self.input_iter.clone(), + output_iter: self.output_iter.clone(), + frames_count: self.frames_count, + } + } +} + /// An iterator of all of the available [`PortPair`]s from an [`Audio`] struct. +#[derive(Clone)] pub struct PortPairsIter<'a> { inputs: Iter<'a, CelledClapAudioBuffer>, outputs: Iter<'a, CelledClapAudioBuffer>,