use ffi;
enum_from_primitive! {
#[repr(i32)]
#[derive(Copy, Clone, PartialEq, PartialOrd, Debug, Eq)]
pub enum Error {
NoError =
ffi::PaErrorCode_paNoError,
NoDevice =
ffi::PA_NO_DEVICE,
NotInitialized =
ffi::PaErrorCode_paNotInitialized,
UnanticipatedHostError =
ffi::PaErrorCode_paUnanticipatedHostError,
InvalidChannelCount =
ffi::PaErrorCode_paInvalidChannelCount,
InvalidSampleRate =
ffi::PaErrorCode_paInvalidSampleRate,
InvalidDevice =
ffi::PaErrorCode_paInvalidDevice,
InvalidFlag =
ffi::PaErrorCode_paInvalidFlag,
SampleFormatNotSupported =
ffi::PaErrorCode_paSampleFormatNotSupported,
BadIODeviceCombination =
ffi::PaErrorCode_paBadIODeviceCombination,
InsufficientMemory =
ffi::PaErrorCode_paInsufficientMemory,
BufferTooBig =
ffi::PaErrorCode_paBufferTooBig,
BufferTooSmall =
ffi::PaErrorCode_paBufferTooSmall,
NullCallback =
ffi::PaErrorCode_paNullCallback,
BadStreamPtr =
ffi::PaErrorCode_paBadStreamPtr,
TimedOut =
ffi::PaErrorCode_paTimedOut,
InternalError =
ffi::PaErrorCode_paInternalError,
DeviceUnavailable =
ffi::PaErrorCode_paDeviceUnavailable,
IncompatibleHostApiSpecificStreamInfo =
ffi::PaErrorCode_paIncompatibleHostApiSpecificStreamInfo,
StreamIsStopped =
ffi::PaErrorCode_paStreamIsStopped,
StreamIsNotStopped =
ffi::PaErrorCode_paStreamIsNotStopped,
InputOverflowed =
ffi::PaErrorCode_paInputOverflowed,
OutputUnderflowed =
ffi::PaErrorCode_paOutputUnderflowed,
HostApiNotFound =
ffi::PaErrorCode_paHostApiNotFound,
InvalidHostApi =
ffi::PaErrorCode_paInvalidHostApi,
CanNotReadFromACallbackStream =
ffi::PaErrorCode_paCanNotReadFromACallbackStream,
CanNotWriteToACallbackStream =
ffi::PaErrorCode_paCanNotWriteToACallbackStream,
CanNotReadFromAnOutputOnlyStream =
ffi::PaErrorCode_paCanNotReadFromAnOutputOnlyStream,
CanNotWriteToAnInputOnlyStream =
ffi::PaErrorCode_paCanNotWriteToAnInputOnlyStream,
IncompatibleStreamHostApi =
ffi::PaErrorCode_paIncompatibleStreamHostApi,
BadBufferPtr =
ffi::PaErrorCode_paBadBufferPtr,
}
}
impl ::std::fmt::Display for Error {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
write!(f, "{:?}", self)
}
}
impl ::std::error::Error for Error {
fn description(&self) -> &str {
match *self {
Error::NoError => "No Error",
Error::NoDevice => "No Device",
Error::NotInitialized => "PortAudio not initialized",
Error::UnanticipatedHostError => "Unanticipated error from the host",
Error::InvalidChannelCount => "Invalid number of channels",
Error::InvalidSampleRate => "Invalid sample rate",
Error::InvalidDevice => "Invalid device",
Error::InvalidFlag => "Invalid flag",
Error::SampleFormatNotSupported => "Sample format is not supported",
Error::BadIODeviceCombination => "Input device not compatible with output device",
Error::InsufficientMemory => "Memory insufficient",
Error::BufferTooBig => "The buffer is too big",
Error::BufferTooSmall => "The buffer is too small",
Error::NullCallback => "Invalid callback",
Error::BadStreamPtr => "Invalid stream",
Error::TimedOut => "Time out",
Error::InternalError => "Portaudio internal error",
Error::DeviceUnavailable => "Device unavailable",
Error::IncompatibleHostApiSpecificStreamInfo => {
"Stream info not compatible with the host"
}
Error::StreamIsStopped => "The stream is stopped",
Error::StreamIsNotStopped => "The stream is not stopped",
Error::InputOverflowed => "The input stream has overflowed",
Error::OutputUnderflowed => "The output stream has underflowed",
Error::HostApiNotFound => "The host api is not found by Portaudio",
Error::InvalidHostApi => "The host API is invalid",
Error::CanNotReadFromACallbackStream => {
"Portaudio cannot read from the callback stream"
}
Error::CanNotWriteToACallbackStream => "Portaudio cannot write to the callback stream",
Error::CanNotReadFromAnOutputOnlyStream => {
"Portaudio cannot read from an output only stream"
}
Error::CanNotWriteToAnInputOnlyStream => {
"Portaudio cannot write to an input only stream"
}
Error::IncompatibleStreamHostApi => "The stream is not compatible with the host API",
Error::BadBufferPtr => "Invalid buffer",
}
}
}