extern crate libsoundio_sys as raw;
use super::util::*;
use std::fmt;
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum Backend {
None,
Jack,
PulseAudio,
Alsa,
CoreAudio,
Wasapi,
Dummy,
}
impl From<raw::SoundIoBackend> for Backend {
fn from(backend: raw::SoundIoBackend) -> Backend {
match backend {
raw::SoundIoBackend::SoundIoBackendJack => Backend::Jack,
raw::SoundIoBackend::SoundIoBackendPulseAudio => Backend::PulseAudio,
raw::SoundIoBackend::SoundIoBackendAlsa => Backend::Alsa,
raw::SoundIoBackend::SoundIoBackendCoreAudio => Backend::CoreAudio,
raw::SoundIoBackend::SoundIoBackendWasapi => Backend::Wasapi,
raw::SoundIoBackend::SoundIoBackendDummy => Backend::Dummy,
_ => Backend::None,
}
}
}
impl From<Backend> for raw::SoundIoBackend {
fn from(backend: Backend) -> raw::SoundIoBackend {
match backend {
Backend::Jack => raw::SoundIoBackend::SoundIoBackendJack,
Backend::PulseAudio => raw::SoundIoBackend::SoundIoBackendPulseAudio,
Backend::Alsa => raw::SoundIoBackend::SoundIoBackendAlsa,
Backend::CoreAudio => raw::SoundIoBackend::SoundIoBackendCoreAudio,
Backend::Wasapi => raw::SoundIoBackend::SoundIoBackendWasapi,
Backend::Dummy => raw::SoundIoBackend::SoundIoBackendDummy,
_ => raw::SoundIoBackend::SoundIoBackendNone,
}
}
}
impl fmt::Display for Backend {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s = latin1_to_string(unsafe { raw::soundio_backend_name((*self).into()) });
f.write_str(&s)
}
}