pub enum SampleType<F32, F64> {
F32(F32),
F64(F64),
Both(F32, F64),
}Expand description
A generic enum to discriminate between buffers containing f32 and f64 sample types.
This enum is actually just a generic container for two different types, called F32 and F64,
representing a buffer that’s holding either f32 or f64 sample data.
This type is used by methods that detect which types of sample buffers are available:
InputPort::channelsreturns aSampleTypeofInputChannels;OutputPort::channelsreturns aSampleTypeofOutputChannels;PortPair::channelsreturns aSampleTypeofPairedChannels;
Variants§
F32(F32)
Only f32 sample buffers are available.
F64(F64)
Only f64 sample buffers are available.
Both(F32, F64)
Both f32 and f64 sample buffers are available.
The host isn’t actually allowed to send both buffer types for a given port to the plugin, but this is still technically a possibility due to how the CLAP API is designed.
This variant is there to let plugins decide what to do with the buffers and whether to simply ignore the extra one, instead of throwing a hard error if this were to happen.
Implementations§
Source§impl<F32, F64> SampleType<F32, F64>
impl<F32, F64> SampleType<F32, F64>
Sourcepub fn as_f32(&self) -> Option<&F32>
pub fn as_f32(&self) -> Option<&F32>
Returns a reference to the F32 sample buffer type if it is available,
or None otherwise.
If both buffer types are available, the F64 buffer type is ignored.
§Example
use clack_plugin::process::audio::SampleType;
assert_eq!(SampleType::<f32, f64>::F32(1.0).as_f32(), Some(&1.0f32));
assert_eq!(SampleType::<f32, f64>::F64(1.0).as_f32(), None);
assert_eq!(SampleType::<f32, f64>::Both(1.0, 1.0).as_f32(), Some(&1.0f32));Sourcepub fn as_f32_mut(&mut self) -> Option<&mut F32>
pub fn as_f32_mut(&mut self) -> Option<&mut F32>
Returns a mutable reference to the F32 sample buffer type if it is available,
or None otherwise.
If both buffer types are available, the F64 buffer type is ignored.
§Example
use clack_plugin::process::audio::SampleType;
assert_eq!(SampleType::<f32, f64>::F32(1.0).as_f32_mut(), Some(&mut 1.0f32));
assert_eq!(SampleType::<f32, f64>::F64(1.0).as_f32_mut(), None);
assert_eq!(SampleType::<f32, f64>::Both(1.0, 1.0).as_f32_mut(), Some(&mut 1.0f32));Sourcepub fn into_f32(self) -> Option<F32>
pub fn into_f32(self) -> Option<F32>
Returns the F32 sample buffer type if it is available, or None otherwise.
If both buffer types are available, the F64 buffer type is discarded.
This method consumes the enum. For a non-consuming operation, see the
as_f32 and as_f32_mut methods.
§Example
use clack_plugin::process::audio::SampleType;
assert_eq!(SampleType::<f32, f64>::F32(1.0).into_f32(), Some(1.0f32));
assert_eq!(SampleType::<f32, f64>::F64(1.0).into_f32(), None);
assert_eq!(SampleType::<f32, f64>::Both(1.0, 1.0).into_f32(), Some(1.0f32));Sourcepub fn as_f64(&self) -> Option<&F64>
pub fn as_f64(&self) -> Option<&F64>
Returns a reference to the F64 sample buffer type if it is available,
or None otherwise.
If both buffer types are available, the F32 buffer type is ignored.
§Example
use clack_plugin::process::audio::SampleType;
assert_eq!(SampleType::<f32, f64>::F32(1.0).as_f64(), None);
assert_eq!(SampleType::<f32, f64>::F64(1.0).as_f64(), Some(&1.0f64));
assert_eq!(SampleType::<f32, f64>::Both(1.0, 1.0).as_f64(), Some(&1.0f64));Sourcepub fn as_f64_mut(&mut self) -> Option<&mut F64>
pub fn as_f64_mut(&mut self) -> Option<&mut F64>
Returns a mutable reference to the F64 sample buffer type if it is available,
or None otherwise.
If both buffer types are available, the F32 buffer type is ignored.
§Example
use clack_plugin::process::audio::SampleType;
assert_eq!(SampleType::<f32, f64>::F32(1.0).as_f64_mut(), None);
assert_eq!(SampleType::<f32, f64>::F64(1.0).as_f64_mut(), Some(&mut 1.0f64));
assert_eq!(SampleType::<f32, f64>::Both(1.0, 1.0).as_f64_mut(), Some(&mut 1.0f64));Sourcepub fn into_f64(self) -> Option<F64>
pub fn into_f64(self) -> Option<F64>
Returns the F64 sample buffer type if it is available, or None otherwise.
If both buffer types are available, the F32 buffer type is discarded.
This method consumes the enum. For a non-consuming operation, see the
as_f32 and as_f64_mut methods.
§Example
use clack_plugin::process::audio::SampleType;
assert_eq!(SampleType::<f32, f64>::F32(1.0).into_f64(), None);
assert_eq!(SampleType::<f32, f64>::F64(1.0).into_f64(), Some(1.0f64));
assert_eq!(SampleType::<f32, f64>::Both(1.0, 1.0).into_f64(), Some(1.0f64));Sourcepub fn map<TF32, TF64, Fn32, Fn64>(
self,
fn32: Fn32,
fn64: Fn64,
) -> SampleType<TF32, TF64>
pub fn map<TF32, TF64, Fn32, Fn64>( self, fn32: Fn32, fn64: Fn64, ) -> SampleType<TF32, TF64>
Maps a SampleType<F32, F64> to SampleType<TF32, TF64> by applying functions to the
contained values.
The fn32 function parameter is applied to the F32 buffer type if it is present, and the
fn64 function parameter is applied to the F64 buffer type if it is present. If both
buffer types are present, both functions are applied to each matching value type.
§Example
use clack_plugin::process::audio::SampleType;
assert_eq!(
SampleType::<f32, f64>::F32(1.0).map(|f| f * 2.0, |f| f * 3.0),
SampleType::F32(2f32)
);
assert_eq!(
SampleType::<f32, f64>::F64(1.0).map(|f| f * 2.0, |f| f * 3.0),
SampleType::F64(3f64)
);
assert_eq!(
SampleType::<f32, f64>::Both(1.0, 1.0).map(|f| f * 2.0, |f| f * 3.0),
SampleType::Both(2f32, 3f64)
);Sourcepub fn try_match_with<TF32, TF64>(
self,
other: SampleType<TF32, TF64>,
) -> Result<SampleType<(F32, TF32), (F64, TF64)>, BufferError>
pub fn try_match_with<TF32, TF64>( self, other: SampleType<TF32, TF64>, ) -> Result<SampleType<(F32, TF32), (F64, TF64)>, BufferError>
Tries to match two SampleTypes possibly containing different buffer types.
This returns a SampleType containing a tuple of the matched buffer types (i.e.
(F32, TF32) if both 32-bit buffer types were present, or (F64, TF64) if both 32-bit
buffer types were present).
If any of the two SampleTypes actually contain Both, then the extra
buffer type is discarded. Unless both SampleTypes contain both buffers, in which case
Both is also returned.
This method consumes the SampleType.
§Errors
This method returns a BufferError::MismatchedBufferPair if no match could be found, i.e.
oneSampleType contains only a F32 and the other contains only a F64.
§Examples
use clack_plugin::process::audio::{BufferError, SampleType};
assert_eq!(
SampleType::<f32, f64>::F32(1.0)
.try_match_with(SampleType::<f32, f64>::F32(2.0)),
Ok(SampleType::F32((1.0, 2.0)))
);
assert_eq!(
SampleType::<f32, f64>::F64(1.0)
.try_match_with(SampleType::<f32, f64>::F64(2.0)),
Ok(SampleType::F64((1.0, 2.0)))
);
assert_eq!(
SampleType::<f32, f64>::F32(1.0)
.try_match_with(SampleType::<f32, f64>::F64(2.0)),
Err(BufferError::MismatchedBufferPair)
);Trait Implementations§
Source§impl<F32: Clone, F64: Clone> Clone for SampleType<F32, F64>
impl<F32: Clone, F64: Clone> Clone for SampleType<F32, F64>
Source§fn clone(&self) -> SampleType<F32, F64>
fn clone(&self) -> SampleType<F32, F64>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more