choose backend

This commit is contained in:
Tom Gowan 2018-10-31 13:22:10 +11:00 committed by mitchmindtree
parent 91f2edb277
commit 6a71f0a801
2 changed files with 28 additions and 26 deletions

View File

@ -1,12 +1,30 @@
pub enum Backend { use std::sync::Mutex;
#[derive(Clone)]
pub enum BackEnd {
Wasapi, Wasapi,
Asio, Asio,
} }
// TODO This needs to be set once at run time //static BACKEND: BackEnd = BackEnd::Asio;
// by the cpal user
static backend: Backend = Backend::Asio;
pub fn which_backend() -> &'static Backend { lazy_static! {
&backend static ref BACK_END: Mutex<BackEnd> = Mutex::new(BackEnd::Wasapi);
} }
pub fn which_backend() -> BackEnd {
(*BACK_END.lock().unwrap()).clone()
}
pub fn use_asio_backend() -> Result<(), BackEndError> {
*BACK_END.lock().unwrap() = BackEnd::Asio;
Ok(())
}
pub fn use_wasapi_backend() -> Result<(), BackEndError> {
*BACK_END.lock().unwrap() = BackEnd::Wasapi;
Ok(())
}
#[derive(Debug)]
pub struct BackEndError;

View File

@ -127,16 +127,8 @@ impl Iterator for Devices {
// Asio doesn't have a concept of default // Asio doesn't have a concept of default
// so returning first in list as default // so returning first in list as default
pub fn default_input_device() -> Option<Device> { pub fn default_input_device() -> Option<Device> {
let driver_list = sys::get_driver_list(); let mut driver_list = sys::get_driver_list();
// Remove match driver_list.pop() {
let d_name = driver_list.into_iter()
.filter(|d| d == "ASIO4ALL v2")
//.filter(|d| d.name() == "Dante Via (x64)")
//.filter(|d| d.name() == "Dante Virtual Soundcard (x64)")
.next();
//match driver_list.pop() {
match d_name {
// end remove
Some(name) => { Some(name) => {
sys::Drivers::load(&name) sys::Drivers::load(&name)
.or_else(|e| { .or_else(|e| {
@ -151,16 +143,8 @@ pub fn default_input_device() -> Option<Device> {
} }
pub fn default_output_device() -> Option<Device> { pub fn default_output_device() -> Option<Device> {
let driver_list = sys::get_driver_list(); let mut driver_list = sys::get_driver_list();
// Remove match driver_list.pop() {
let d_name = driver_list.into_iter()
.filter(|d| d == "ASIO4ALL v2")
//.filter(|d| d.name() == "Dante Via (x64)")
//.filter(|d| d.name() == "Dante Virtual Soundcard (x64)")
.next();
//match driver_list.pop() {
match d_name {
// end remove
Some(name) => { Some(name) => {
sys::Drivers::load(&name) sys::Drivers::load(&name)
.or_else(|e| { .or_else(|e| {