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