Ensure all crates are formatted correctly, not just `cpal` itself.
This commit is contained in:
parent
ca255772fd
commit
7e846b47ad
|
@ -39,7 +39,7 @@ jobs:
|
|||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: fmt
|
||||
args: -- --check
|
||||
args: --all -- --check
|
||||
|
||||
cargo-publish:
|
||||
|
||||
|
|
2525
alsa-sys/src/lib.rs
2525
alsa-sys/src/lib.rs
File diff suppressed because it is too large
Load Diff
|
@ -64,8 +64,8 @@ fn create_lib(cpal_asio_dir: &PathBuf) {
|
|||
let entry = match entry {
|
||||
Err(e) => {
|
||||
println!("error: {}", e);
|
||||
continue
|
||||
},
|
||||
continue;
|
||||
}
|
||||
Ok(entry) => entry,
|
||||
};
|
||||
match entry.path().extension().and_then(|s| s.to_str()) {
|
||||
|
@ -127,8 +127,13 @@ fn create_bindings(cpal_asio_dir: &PathBuf) {
|
|||
($opt_header:expr, $FILE_NAME:expr) => {
|
||||
match $opt_header.as_ref() {
|
||||
None => {
|
||||
panic!("Could not find {} in {}: {}", $FILE_NAME, CPAL_ASIO_DIR, cpal_asio_dir.display());
|
||||
},
|
||||
panic!(
|
||||
"Could not find {} in {}: {}",
|
||||
$FILE_NAME,
|
||||
CPAL_ASIO_DIR,
|
||||
cpal_asio_dir.display()
|
||||
);
|
||||
}
|
||||
Some(path) => path.to_str().expect("Could not convert path to str"),
|
||||
}
|
||||
};
|
||||
|
|
|
@ -38,8 +38,12 @@ fn main() {
|
|||
for name in asio.driver_names() {
|
||||
println!("Driver: {:?}", name);
|
||||
let driver = asio.load_driver(&name).expect("failed to load driver");
|
||||
let channels = driver.channels().expect("failed to retrieve channel counts");
|
||||
let sample_rate = driver.sample_rate().expect("failed to retrieve sample rate");
|
||||
let channels = driver
|
||||
.channels()
|
||||
.expect("failed to retrieve channel counts");
|
||||
let sample_rate = driver
|
||||
.sample_rate()
|
||||
.expect("failed to retrieve sample rate");
|
||||
let in_fmt = Format {
|
||||
channels: channels.ins as _,
|
||||
sample_rate: SampleRate(sample_rate as _),
|
||||
|
|
|
@ -5,7 +5,13 @@ fn main() {
|
|||
for driver in asio.driver_names() {
|
||||
println!("Driver: {}", driver);
|
||||
let driver = asio.load_driver(&driver).expect("failed to load drivers");
|
||||
println!(" Channels: {:?}", driver.channels().expect("failed to get channels"));
|
||||
println!(" Sample rate: {:?}", driver.sample_rate().expect("failed to get sample rate"));
|
||||
println!(
|
||||
" Channels: {:?}",
|
||||
driver.channels().expect("failed to get channels")
|
||||
);
|
||||
println!(
|
||||
" Sample rate: {:?}",
|
||||
driver.sample_rate().expect("failed to get sample rate")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,7 +112,9 @@ macro_rules! asio_result {
|
|||
r if r == AsioErrorWrapper::ASE_OK as i32 => Ok(()),
|
||||
r if r == AsioErrorWrapper::ASE_SUCCESS as i32 => Ok(()),
|
||||
r if r == AsioErrorWrapper::ASE_NotPresent as i32 => Err(AsioError::NoDrivers),
|
||||
r if r == AsioErrorWrapper::ASE_HWMalfunction as i32 => Err(AsioError::HardwareMalfunction),
|
||||
r if r == AsioErrorWrapper::ASE_HWMalfunction as i32 => {
|
||||
Err(AsioError::HardwareMalfunction)
|
||||
}
|
||||
r if r == AsioErrorWrapper::ASE_InvalidParameter as i32 => Err(AsioError::InvalidInput),
|
||||
r if r == AsioErrorWrapper::ASE_InvalidMode as i32 => Err(AsioError::BadMode),
|
||||
r if r == AsioErrorWrapper::ASE_SPNotAdvancing as i32 => Err(AsioError::HardwareStuck),
|
||||
|
|
|
@ -2,8 +2,8 @@ pub mod asio_import;
|
|||
#[macro_use]
|
||||
pub mod errors;
|
||||
|
||||
use num_traits::FromPrimitive;
|
||||
use self::errors::{AsioError, AsioErrorWrapper, LoadDriverError};
|
||||
use num_traits::FromPrimitive;
|
||||
use std::ffi::CStr;
|
||||
use std::ffi::CString;
|
||||
use std::os::raw::{c_char, c_double, c_long, c_void};
|
||||
|
@ -165,9 +165,12 @@ pub struct AsioBufferInfo {
|
|||
struct AsioCallbacks {
|
||||
buffer_switch: extern "C" fn(double_buffer_index: c_long, direct_process: c_long) -> (),
|
||||
sample_rate_did_change: extern "C" fn(s_rate: c_double) -> (),
|
||||
asio_message:
|
||||
extern "C" fn(selector: c_long, value: c_long, message: *mut (), opt: *mut c_double)
|
||||
-> c_long,
|
||||
asio_message: extern "C" fn(
|
||||
selector: c_long,
|
||||
value: c_long,
|
||||
message: *mut (),
|
||||
opt: *mut c_double,
|
||||
) -> c_long,
|
||||
buffer_switch_time_info: extern "C" fn(
|
||||
params: *mut ai::ASIOTime,
|
||||
double_buffer_index: c_long,
|
||||
|
@ -276,7 +279,8 @@ impl Asio {
|
|||
}
|
||||
|
||||
unsafe {
|
||||
let num_drivers = ai::get_driver_names(driver_name_ptrs.as_mut_ptr(), MAX_DRIVERS as i32);
|
||||
let num_drivers =
|
||||
ai::get_driver_names(driver_name_ptrs.as_mut_ptr(), MAX_DRIVERS as i32);
|
||||
(0..num_drivers)
|
||||
.map(|i| driver_name_to_utf8(&driver_names[i as usize]).to_string())
|
||||
.collect()
|
||||
|
@ -317,8 +321,8 @@ impl Asio {
|
|||
}
|
||||
|
||||
// Make owned CString to send to load driver
|
||||
let driver_name_cstring = CString::new(driver_name)
|
||||
.expect("failed to create `CString` from driver name");
|
||||
let driver_name_cstring =
|
||||
CString::new(driver_name).expect("failed to create `CString` from driver name");
|
||||
let mut driver_info = std::mem::MaybeUninit::<ai::ASIODriverInfo>::uninit();
|
||||
|
||||
unsafe {
|
||||
|
@ -332,9 +336,15 @@ impl Asio {
|
|||
let state = Mutex::new(DriverState::Initialized);
|
||||
let name = driver_name.to_string();
|
||||
let destroyed = false;
|
||||
let inner = Arc::new(DriverInner { name, state, destroyed });
|
||||
*self.loaded_driver.lock().expect("failed to acquire loaded driver lock") =
|
||||
Arc::downgrade(&inner);
|
||||
let inner = Arc::new(DriverInner {
|
||||
name,
|
||||
state,
|
||||
destroyed,
|
||||
});
|
||||
*self
|
||||
.loaded_driver
|
||||
.lock()
|
||||
.expect("failed to acquire loaded driver lock") = Arc::downgrade(&inner);
|
||||
let driver = Driver { inner };
|
||||
Ok(driver)
|
||||
}
|
||||
|
@ -461,7 +471,10 @@ impl Driver {
|
|||
mut input_buffer_infos: Vec<AsioBufferInfo>,
|
||||
mut output_buffer_infos: Vec<AsioBufferInfo>,
|
||||
) -> Result<AsioStreams, AsioError> {
|
||||
let (input, output) = match (input_buffer_infos.is_empty(), output_buffer_infos.is_empty()) {
|
||||
let (input, output) = match (
|
||||
input_buffer_infos.is_empty(),
|
||||
output_buffer_infos.is_empty(),
|
||||
) {
|
||||
// Both stream exist.
|
||||
(false, false) => {
|
||||
// Create one continuous slice of buffers.
|
||||
|
@ -481,7 +494,7 @@ impl Driver {
|
|||
buffer_size,
|
||||
});
|
||||
(input, output)
|
||||
},
|
||||
}
|
||||
// Just input
|
||||
(false, true) => {
|
||||
let buffer_size = self.create_buffers(&mut input_buffer_infos)?;
|
||||
|
@ -491,7 +504,7 @@ impl Driver {
|
|||
});
|
||||
let output = None;
|
||||
(input, output)
|
||||
},
|
||||
}
|
||||
// Just output
|
||||
(true, false) => {
|
||||
let buffer_size = self.create_buffers(&mut output_buffer_infos)?;
|
||||
|
@ -501,7 +514,7 @@ impl Driver {
|
|||
buffer_size,
|
||||
});
|
||||
(input, output)
|
||||
},
|
||||
}
|
||||
// Impossible
|
||||
(true, true) => unreachable!("Trying to create streams without preparing"),
|
||||
};
|
||||
|
@ -729,7 +742,11 @@ fn prepare_buffer_infos(is_input: bool, n_channels: usize) -> Vec<AsioBufferInfo
|
|||
let channel_num = ch as c_long;
|
||||
// To be filled by ASIOCreateBuffers.
|
||||
let buffers = [std::ptr::null_mut(); 2];
|
||||
AsioBufferInfo { is_input, channel_num, buffers }
|
||||
AsioBufferInfo {
|
||||
is_input,
|
||||
channel_num,
|
||||
buffers,
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
@ -788,18 +805,14 @@ fn stream_data_type(is_input: bool) -> Result<AsioSampleType, AsioError> {
|
|||
///
|
||||
/// This converts to utf8.
|
||||
fn driver_name_to_utf8(bytes: &[c_char]) -> std::borrow::Cow<str> {
|
||||
unsafe {
|
||||
CStr::from_ptr(bytes.as_ptr()).to_string_lossy()
|
||||
}
|
||||
unsafe { CStr::from_ptr(bytes.as_ptr()).to_string_lossy() }
|
||||
}
|
||||
|
||||
/// ASIO uses null terminated c strings for channel names.
|
||||
///
|
||||
/// This converts to utf8.
|
||||
fn _channel_name_to_utf8(bytes: &[c_char]) -> std::borrow::Cow<str> {
|
||||
unsafe {
|
||||
CStr::from_ptr(bytes.as_ptr()).to_string_lossy()
|
||||
}
|
||||
unsafe { CStr::from_ptr(bytes.as_ptr()).to_string_lossy() }
|
||||
}
|
||||
|
||||
/// Indicates the stream sample rate has changed.
|
||||
|
@ -917,8 +930,9 @@ extern "C" fn buffer_switch(double_buffer_index: c_long, direct_process: c_long)
|
|||
&mut time.time_info.system_time,
|
||||
);
|
||||
if let Ok(()) = asio_result!(res) {
|
||||
time.time_info.flags =
|
||||
(ai::AsioTimeInfoFlags::kSystemTimeValid | ai::AsioTimeInfoFlags::kSamplePositionValid).0;
|
||||
time.time_info.flags = (ai::AsioTimeInfoFlags::kSystemTimeValid
|
||||
| ai::AsioTimeInfoFlags::kSamplePositionValid)
|
||||
.0;
|
||||
}
|
||||
time
|
||||
};
|
||||
|
@ -930,7 +944,16 @@ extern "C" fn buffer_switch(double_buffer_index: c_long, direct_process: c_long)
|
|||
|
||||
#[test]
|
||||
fn check_type_sizes() {
|
||||
assert_eq!(std::mem::size_of::<AsioSampleRate>(), std::mem::size_of::<ai::ASIOSampleRate>());
|
||||
assert_eq!(std::mem::size_of::<AsioTimeCode>(), std::mem::size_of::<ai::ASIOTimeCode>());
|
||||
assert_eq!(std::mem::size_of::<AsioTime>(), std::mem::size_of::<ai::ASIOTime>());
|
||||
assert_eq!(
|
||||
std::mem::size_of::<AsioSampleRate>(),
|
||||
std::mem::size_of::<ai::ASIOSampleRate>()
|
||||
);
|
||||
assert_eq!(
|
||||
std::mem::size_of::<AsioTimeCode>(),
|
||||
std::mem::size_of::<ai::ASIOTimeCode>()
|
||||
);
|
||||
assert_eq!(
|
||||
std::mem::size_of::<AsioTime>(),
|
||||
std::mem::size_of::<ai::ASIOTime>()
|
||||
);
|
||||
}
|
||||
|
|
|
@ -13,6 +13,6 @@ extern crate num_traits;
|
|||
#[cfg(asio)]
|
||||
pub mod bindings;
|
||||
#[cfg(asio)]
|
||||
pub use bindings::*;
|
||||
#[cfg(asio)]
|
||||
pub use bindings::errors::{AsioError, LoadDriverError};
|
||||
#[cfg(asio)]
|
||||
pub use bindings::*;
|
||||
|
|
Loading…
Reference in New Issue