diff --git a/src/os/windows/mod.rs b/src/os/windows/mod.rs index ad447d8..17f029f 100644 --- a/src/os/windows/mod.rs +++ b/src/os/windows/mod.rs @@ -1,12 +1,30 @@ -pub enum Backend { +use std::sync::Mutex; + +#[derive(Clone)] +pub enum BackEnd { Wasapi, Asio, } -// TODO This needs to be set once at run time -// by the cpal user -static backend: Backend = Backend::Asio; +//static BACKEND: BackEnd = BackEnd::Asio; -pub fn which_backend() -> &'static Backend { - &backend +lazy_static! { + static ref BACK_END: Mutex = 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; \ No newline at end of file diff --git a/src/platform/windows/asio/device.rs b/src/platform/windows/asio/device.rs index 67fff78..815e1f5 100644 --- a/src/platform/windows/asio/device.rs +++ b/src/platform/windows/asio/device.rs @@ -127,16 +127,8 @@ impl Iterator for Devices { // Asio doesn't have a concept of default // so returning first in list as default pub fn default_input_device() -> Option { - let driver_list = sys::get_driver_list(); - // Remove - 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 + let mut driver_list = sys::get_driver_list(); + match driver_list.pop() { Some(name) => { sys::Drivers::load(&name) .or_else(|e| { @@ -151,16 +143,8 @@ pub fn default_input_device() -> Option { } pub fn default_output_device() -> Option { - let driver_list = sys::get_driver_list(); - // Remove - 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 + let mut driver_list = sys::get_driver_list(); + match driver_list.pop() { Some(name) => { sys::Drivers::load(&name) .or_else(|e| {