Skip to main content

SampleType

Enum SampleType 

Source
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:

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>

Source

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));
Source

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));
Source

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));
Source

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));
Source

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));
Source

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));
Source

pub fn map<TF32, TF64, Fn32, Fn64>( self, fn32: Fn32, fn64: Fn64, ) -> SampleType<TF32, TF64>
where Fn32: FnOnce(F32) -> TF32, Fn64: FnOnce(F64) -> 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)
);
Source

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>

Source§

fn clone(&self) -> SampleType<F32, F64>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F32: Copy, F64: Copy> Copy for SampleType<F32, F64>

Source§

impl<F32: Debug, F64: Debug> Debug for SampleType<F32, F64>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F32: Eq, F64: Eq> Eq for SampleType<F32, F64>

Source§

impl<F32: Ord, F64: Ord> Ord for SampleType<F32, F64>

Source§

fn cmp(&self, other: &SampleType<F32, F64>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl<F32: PartialEq, F64: PartialEq> PartialEq for SampleType<F32, F64>

Source§

fn eq(&self, other: &SampleType<F32, F64>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<F32: PartialOrd, F64: PartialOrd> PartialOrd for SampleType<F32, F64>

Source§

fn partial_cmp(&self, other: &SampleType<F32, F64>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<F32: PartialEq, F64: PartialEq> StructuralPartialEq for SampleType<F32, F64>

Auto Trait Implementations§

§

impl<F32, F64> Freeze for SampleType<F32, F64>
where F32: Freeze, F64: Freeze,

§

impl<F32, F64> RefUnwindSafe for SampleType<F32, F64>
where F32: RefUnwindSafe, F64: RefUnwindSafe,

§

impl<F32, F64> Send for SampleType<F32, F64>
where F32: Send, F64: Send,

§

impl<F32, F64> Sync for SampleType<F32, F64>
where F32: Sync, F64: Sync,

§

impl<F32, F64> Unpin for SampleType<F32, F64>
where F32: Unpin, F64: Unpin,

§

impl<F32, F64> UnsafeUnpin for SampleType<F32, F64>
where F32: UnsafeUnpin, F64: UnsafeUnpin,

§

impl<F32, F64> UnwindSafe for SampleType<F32, F64>
where F32: UnwindSafe, F64: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.