Skip to main content

clack_plugin/process/audio/
error.rs

1use std::error::Error;
2use std::fmt::{Display, Formatter};
3
4/// Errors that can occur when accessing [`Audio`](crate::process::Audio) buffers.
5#[derive(Copy, Clone, Eq, PartialEq, Debug)]
6pub enum BufferError {
7    /// A port's channel buffers are invalid.
8    ///
9    /// This happens when both the [`f32`] and [`f64`] buffer pointers provided by the host are null.
10    ///
11    /// This error can be returned by the [`InputPort::channels`](super::InputPort::channels),
12    /// [`OutputPort::channels`](super::OutputPort::channels), or
13    /// [`PortPair::channels`](super::PortPair::channels) methods.
14    InvalidChannelBuffer,
15    /// A pair of mismatched buffer types (i.e. one [`f32`] and the other [`f64`]) were tried to
16    /// be accessed together.
17    ///
18    /// This error is returned by the [`PortPair::channels`](super::PortPair::channels) method if
19    /// the two ports in the pair have mismatched types.
20    ///
21    /// This error is also used by the [`SampleType::try_match_with`](super::SampleType::try_match_with) method.
22    MismatchedBufferPair,
23}
24
25impl Display for BufferError {
26    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
27        match self {
28            BufferError::InvalidChannelBuffer => {
29                f.write_str("Invalid port channels buffers: both the data32 and data64 pointers were null")
30            },
31            BufferError::MismatchedBufferPair => f.write_str("Invalid channel buffer pairing: attempted to read/write a 32-bit buffer and a 64-bit buffer together")
32        }
33    }
34}
35
36impl Error for BufferError {}