weresocool_portaudio/
error.rs

1//!
2//! A module for implementing the Portaudio Error type and
3//! implementing the std Error trait.
4//!
5
6use ffi;
7
8enum_from_primitive! {
9/// Error codes returned by PortAudio functions.
10#[repr(i32)]
11#[derive(Copy, Clone, PartialEq, PartialOrd, Debug, Eq)]
12pub enum Error {
13    /// No Error
14    NoError =
15        ffi::PaErrorCode_paNoError,
16    /// No audio devices
17    NoDevice =
18        ffi::PA_NO_DEVICE,
19    /// Portaudio not initialized
20    NotInitialized =
21        ffi::PaErrorCode_paNotInitialized,
22    /// Unanticipated error from the host
23    UnanticipatedHostError =
24        ffi::PaErrorCode_paUnanticipatedHostError,
25    /// Invalid channel count
26    InvalidChannelCount =
27        ffi::PaErrorCode_paInvalidChannelCount,
28    /// Invalid sample rate
29    InvalidSampleRate =
30        ffi::PaErrorCode_paInvalidSampleRate,
31    /// Invalid Device
32    InvalidDevice =
33        ffi::PaErrorCode_paInvalidDevice,
34    /// Invalid Flag
35    InvalidFlag =
36        ffi::PaErrorCode_paInvalidFlag,
37    /// The Sample format is not supported
38    SampleFormatNotSupported =
39        ffi::PaErrorCode_paSampleFormatNotSupported,
40    /// Input device not compatible with output device
41    BadIODeviceCombination =
42        ffi::PaErrorCode_paBadIODeviceCombination,
43    /// Memory insufficient
44    InsufficientMemory =
45        ffi::PaErrorCode_paInsufficientMemory,
46    /// The buffer is too big
47    BufferTooBig =
48        ffi::PaErrorCode_paBufferTooBig,
49    /// The buffer is too small
50    BufferTooSmall =
51        ffi::PaErrorCode_paBufferTooSmall,
52    /// Invalid callback
53    NullCallback =
54        ffi::PaErrorCode_paNullCallback,
55    /// Invalid Stream
56    BadStreamPtr =
57        ffi::PaErrorCode_paBadStreamPtr,
58    /// Time out
59    TimedOut =
60        ffi::PaErrorCode_paTimedOut,
61    /// Portaudio internal error
62    InternalError =
63        ffi::PaErrorCode_paInternalError,
64    /// Device unavailable
65    DeviceUnavailable =
66        ffi::PaErrorCode_paDeviceUnavailable,
67    /// Stream info not compatible with the host
68    IncompatibleHostApiSpecificStreamInfo =
69        ffi::PaErrorCode_paIncompatibleHostApiSpecificStreamInfo,
70    /// The stream is stopped
71    StreamIsStopped =
72        ffi::PaErrorCode_paStreamIsStopped,
73    /// The stream is not stopped
74    StreamIsNotStopped =
75        ffi::PaErrorCode_paStreamIsNotStopped,
76    /// The input stream has overflowed
77    InputOverflowed =
78        ffi::PaErrorCode_paInputOverflowed,
79    /// The output has underflowed
80    OutputUnderflowed =
81        ffi::PaErrorCode_paOutputUnderflowed,
82    /// The host API is not found by Portaudio
83    HostApiNotFound =
84        ffi::PaErrorCode_paHostApiNotFound,
85    /// The host API is invalid
86    InvalidHostApi =
87        ffi::PaErrorCode_paInvalidHostApi,
88    /// Portaudio cannot read from the callback stream
89    CanNotReadFromACallbackStream =
90        ffi::PaErrorCode_paCanNotReadFromACallbackStream,
91    /// Portaudio cannot write to the callback stream
92    CanNotWriteToACallbackStream =
93        ffi::PaErrorCode_paCanNotWriteToACallbackStream,
94    /// Portaudio cannot read from an output only stream
95    CanNotReadFromAnOutputOnlyStream =
96        ffi::PaErrorCode_paCanNotReadFromAnOutputOnlyStream,
97    /// Portaudio cannot write to an input only stream
98    CanNotWriteToAnInputOnlyStream =
99        ffi::PaErrorCode_paCanNotWriteToAnInputOnlyStream,
100    /// The stream is not compatible with the host API
101    IncompatibleStreamHostApi =
102        ffi::PaErrorCode_paIncompatibleStreamHostApi,
103    /// Invalid buffer
104    BadBufferPtr =
105        ffi::PaErrorCode_paBadBufferPtr,
106}
107}
108
109impl ::std::fmt::Display for Error {
110    fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
111        write!(f, "{:?}", self)
112    }
113}
114
115impl ::std::error::Error for Error {
116    fn description(&self) -> &str {
117        match *self {
118            Error::NoError => "No Error",
119            Error::NoDevice => "No Device",
120            Error::NotInitialized => "PortAudio not initialized",
121            Error::UnanticipatedHostError => "Unanticipated error from the host",
122            Error::InvalidChannelCount => "Invalid number of channels",
123            Error::InvalidSampleRate => "Invalid sample rate",
124            Error::InvalidDevice => "Invalid device",
125            Error::InvalidFlag => "Invalid flag",
126            Error::SampleFormatNotSupported => "Sample format is not supported",
127            Error::BadIODeviceCombination => "Input device not compatible with output device",
128            Error::InsufficientMemory => "Memory insufficient",
129            Error::BufferTooBig => "The buffer is too big",
130            Error::BufferTooSmall => "The buffer is too small",
131            Error::NullCallback => "Invalid callback",
132            Error::BadStreamPtr => "Invalid stream",
133            Error::TimedOut => "Time out",
134            Error::InternalError => "Portaudio internal error",
135            Error::DeviceUnavailable => "Device unavailable",
136            Error::IncompatibleHostApiSpecificStreamInfo => {
137                "Stream info not compatible with the host"
138            }
139            Error::StreamIsStopped => "The stream is stopped",
140            Error::StreamIsNotStopped => "The stream is not stopped",
141            Error::InputOverflowed => "The input stream has overflowed",
142            Error::OutputUnderflowed => "The output stream has underflowed",
143            Error::HostApiNotFound => "The host api is not found by Portaudio",
144            Error::InvalidHostApi => "The host API is invalid",
145            Error::CanNotReadFromACallbackStream => {
146                "Portaudio cannot read from the callback stream"
147            }
148            Error::CanNotWriteToACallbackStream => "Portaudio cannot write to the callback stream",
149            Error::CanNotReadFromAnOutputOnlyStream => {
150                "Portaudio cannot read from an output only stream"
151            }
152            Error::CanNotWriteToAnInputOnlyStream => {
153                "Portaudio cannot write to an input only stream"
154            }
155            Error::IncompatibleStreamHostApi => "The stream is not compatible with the host API",
156            Error::BadBufferPtr => "Invalid buffer",
157        }
158    }
159}