minor fixes

This commit is contained in:
Tom Gowan 2018-11-07 14:59:38 +11:00 committed by mitchmindtree
parent 062205160c
commit 7950045240
3 changed files with 19 additions and 27 deletions

View File

@ -62,7 +62,7 @@ impl fmt::Display for AsioError {
match *self { match *self {
AsioError::NoDrivers => { AsioError::NoDrivers => {
write!(f, "hardware input or output is not present or available") write!(f, "hardware input or output is not present or available")
}, }
AsioError::HardwareMalfunction => write!( AsioError::HardwareMalfunction => write!(
f, f,
"hardware is malfunctioning (can be returned by any ASIO function)" "hardware is malfunctioning (can be returned by any ASIO function)"
@ -89,7 +89,7 @@ impl Error for AsioError {
AsioError::NoDrivers => "hardware input or output is not present or available", AsioError::NoDrivers => "hardware input or output is not present or available",
AsioError::HardwareMalfunction => { AsioError::HardwareMalfunction => {
"hardware is malfunctioning (can be returned by any ASIO function)" "hardware is malfunctioning (can be returned by any ASIO function)"
}, }
AsioError::InvalidInput => "input parameter invalid", AsioError::InvalidInput => "input parameter invalid",
AsioError::BadMode => "hardware is in a bad mode or used in a bad mode", AsioError::BadMode => "hardware is in a bad mode or used in a bad mode",
AsioError::HardwareStuck => "hardware is not running when sample position is inquired", AsioError::HardwareStuck => "hardware is not running when sample position is inquired",

View File

@ -15,14 +15,6 @@ use num;
// Bindings import // Bindings import
use self::asio_import as ai; use self::asio_import as ai;
// TODO I dont think this is needed anymore
/*
pub struct CbArgs<S, D> {
pub stream_id: S,
pub data: D,
}
*/
/// Holds the pointer to the callbacks that come from cpal /// Holds the pointer to the callbacks that come from cpal
struct BufferCallback(Box<FnMut(i32) + Send>); struct BufferCallback(Box<FnMut(i32) + Send>);
@ -231,16 +223,14 @@ impl Drivers {
pub fn load(driver_name: &str) -> Result<Self, AsioDriverError> { pub fn load(driver_name: &str) -> Result<Self, AsioDriverError> {
let mut drivers = get_drivers(); let mut drivers = get_drivers();
// Make owned CString to send to load driver // Make owned CString to send to load driver
let mut my_driver_name = CString::new(driver_name).expect("Can't go from str to CString"); let my_driver_name = CString::new(driver_name).expect("Can't go from str to CString");
let raw = my_driver_name.into_raw();
let mut driver_info = ai::ASIODriverInfo { let mut driver_info = ai::ASIODriverInfo {
_bindgen_opaque_blob: [0u32; 43], _bindgen_opaque_blob: [0u32; 43],
}; };
unsafe { unsafe {
// Destroy old drivers and load new drivers. // Destroy old drivers and load new drivers.
let load_result = drivers.load(raw); //let load_result = drivers.load(raw);
// Take back ownership let load_result = drivers.load(my_driver_name.as_ptr() as *mut i8);
my_driver_name = CString::from_raw(raw);
if load_result { if load_result {
// Initialize ASIO // Initialize ASIO
match drivers.asio_init(&mut driver_info) { match drivers.asio_init(&mut driver_info) {

View File

@ -14,6 +14,8 @@ use SampleFormat;
use StreamData; use StreamData;
use UnknownTypeInputBuffer; use UnknownTypeInputBuffer;
use UnknownTypeOutputBuffer; use UnknownTypeOutputBuffer;
use std::thread;
use std::time::Duration;
/// Controls all streams /// Controls all streams
pub struct EventLoop { pub struct EventLoop {
@ -812,9 +814,8 @@ impl EventLoop {
} }
let any_playing = streams let any_playing = streams
.iter() .iter()
.filter(|s| if let Some(s) = s { s.playing } else { false }) .any(|s| if let Some(s) = s { s.playing } else { false });
.next(); if any_playing {
if let None = any_playing {
sys::stop(); sys::stop();
} }
} }
@ -846,8 +847,9 @@ impl EventLoop {
.unwrap() .unwrap()
.push(unsafe { mem::transmute(callback) }); .push(unsafe { mem::transmute(callback) });
loop { loop {
// Might need a sleep here to prevent the loop being // A sleep here to prevent the loop being
// removed in --release // removed in --release
thread::sleep(Duration::new(1u64, 0u32));
} }
} }
} }