Remove old .rustfmt.toml config. Run default cargo fmt on repo.
Seeing as a few large refactors have landed recently, I thought I'd take this opportunity to do a `cargo fmt` run and standardise on the default rustfmt settings.
This commit is contained in:
parent
95cda0dbe8
commit
aab0d90add
20 changed files with 458 additions and 530 deletions
|
|
@ -2,8 +2,10 @@ use std;
|
|||
pub type SupportedInputFormats = std::vec::IntoIter<SupportedFormat>;
|
||||
pub type SupportedOutputFormats = std::vec::IntoIter<SupportedFormat>;
|
||||
|
||||
use super::parking_lot::Mutex;
|
||||
use super::sys;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::sync::{Arc};
|
||||
use std::sync::Arc;
|
||||
use BackendSpecificError;
|
||||
use DefaultFormatError;
|
||||
use DeviceNameError;
|
||||
|
|
@ -13,8 +15,6 @@ use SampleFormat;
|
|||
use SampleRate;
|
||||
use SupportedFormat;
|
||||
use SupportedFormatsError;
|
||||
use super::sys;
|
||||
use super::parking_lot::Mutex;
|
||||
|
||||
/// A ASIO Device
|
||||
pub struct Device {
|
||||
|
|
@ -55,9 +55,7 @@ impl Device {
|
|||
/// Gets the supported input formats.
|
||||
/// TODO currently only supports the default.
|
||||
/// Need to find all possible formats.
|
||||
pub fn supported_input_formats(
|
||||
&self,
|
||||
) -> Result<SupportedInputFormats, SupportedFormatsError> {
|
||||
pub fn supported_input_formats(&self) -> Result<SupportedInputFormats, SupportedFormatsError> {
|
||||
// Retrieve the default format for the total supported channels and supported sample
|
||||
// format.
|
||||
let mut f = match self.default_input_format() {
|
||||
|
|
@ -68,7 +66,12 @@ impl Device {
|
|||
// Collect a format for every combination of supported sample rate and number of channels.
|
||||
let mut supported_formats = vec![];
|
||||
for &rate in ::COMMON_SAMPLE_RATES {
|
||||
if !self.driver.can_sample_rate(rate.0.into()).ok().unwrap_or(false) {
|
||||
if !self
|
||||
.driver
|
||||
.can_sample_rate(rate.0.into())
|
||||
.ok()
|
||||
.unwrap_or(false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for channels in 1..f.channels + 1 {
|
||||
|
|
@ -96,7 +99,12 @@ impl Device {
|
|||
// Collect a format for every combination of supported sample rate and number of channels.
|
||||
let mut supported_formats = vec![];
|
||||
for &rate in ::COMMON_SAMPLE_RATES {
|
||||
if !self.driver.can_sample_rate(rate.0.into()).ok().unwrap_or(false) {
|
||||
if !self
|
||||
.driver
|
||||
.can_sample_rate(rate.0.into())
|
||||
.ok()
|
||||
.unwrap_or(false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for channels in 1..f.channels + 1 {
|
||||
|
|
@ -114,8 +122,8 @@ impl Device {
|
|||
let sample_rate = SampleRate(self.driver.sample_rate().map_err(default_format_err)? as _);
|
||||
// Map th ASIO sample type to a CPAL sample type
|
||||
let data_type = self.driver.input_data_type().map_err(default_format_err)?;
|
||||
let data_type = convert_data_type(&data_type)
|
||||
.ok_or(DefaultFormatError::StreamTypeNotSupported)?;
|
||||
let data_type =
|
||||
convert_data_type(&data_type).ok_or(DefaultFormatError::StreamTypeNotSupported)?;
|
||||
Ok(Format {
|
||||
channels,
|
||||
sample_rate,
|
||||
|
|
@ -128,8 +136,8 @@ impl Device {
|
|||
let channels = self.driver.channels().map_err(default_format_err)?.outs as u16;
|
||||
let sample_rate = SampleRate(self.driver.sample_rate().map_err(default_format_err)? as _);
|
||||
let data_type = self.driver.output_data_type().map_err(default_format_err)?;
|
||||
let data_type = convert_data_type(&data_type)
|
||||
.ok_or(DefaultFormatError::StreamTypeNotSupported)?;
|
||||
let data_type =
|
||||
convert_data_type(&data_type).ok_or(DefaultFormatError::StreamTypeNotSupported)?;
|
||||
Ok(Format {
|
||||
channels,
|
||||
sample_rate,
|
||||
|
|
@ -159,10 +167,13 @@ impl Iterator for Devices {
|
|||
input: None,
|
||||
output: None,
|
||||
}));
|
||||
return Some(Device { driver, asio_streams });
|
||||
return Some(Device {
|
||||
driver,
|
||||
asio_streams,
|
||||
});
|
||||
}
|
||||
Err(_) => continue,
|
||||
}
|
||||
},
|
||||
None => return None,
|
||||
}
|
||||
}
|
||||
|
|
@ -193,8 +204,9 @@ pub(crate) fn convert_data_type(ty: &sys::AsioSampleType) -> Option<SampleFormat
|
|||
|
||||
fn default_format_err(e: sys::AsioError) -> DefaultFormatError {
|
||||
match e {
|
||||
sys::AsioError::NoDrivers |
|
||||
sys::AsioError::HardwareMalfunction => DefaultFormatError::DeviceNotAvailable,
|
||||
sys::AsioError::NoDrivers | sys::AsioError::HardwareMalfunction => {
|
||||
DefaultFormatError::DeviceNotAvailable
|
||||
}
|
||||
sys::AsioError::NoRate => DefaultFormatError::StreamTypeNotSupported,
|
||||
err => {
|
||||
let description = format!("{}", err);
|
||||
|
|
|
|||
|
|
@ -2,22 +2,10 @@ extern crate asio_sys as sys;
|
|||
extern crate parking_lot;
|
||||
|
||||
use crate::{
|
||||
BuildStreamError,
|
||||
Data,
|
||||
DefaultFormatError,
|
||||
DeviceNameError,
|
||||
DevicesError,
|
||||
Format,
|
||||
PauseStreamError,
|
||||
PlayStreamError,
|
||||
StreamError,
|
||||
SupportedFormatsError,
|
||||
};
|
||||
use traits::{
|
||||
DeviceTrait,
|
||||
HostTrait,
|
||||
StreamTrait,
|
||||
BuildStreamError, Data, DefaultFormatError, DeviceNameError, DevicesError, Format,
|
||||
PauseStreamError, PlayStreamError, StreamError, SupportedFormatsError,
|
||||
};
|
||||
use traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||
|
||||
pub use self::device::{Device, Devices, SupportedInputFormats, SupportedOutputFormats};
|
||||
pub use self::stream::Stream;
|
||||
|
|
@ -73,11 +61,15 @@ impl DeviceTrait for Device {
|
|||
Device::name(self)
|
||||
}
|
||||
|
||||
fn supported_input_formats(&self) -> Result<Self::SupportedInputFormats, SupportedFormatsError> {
|
||||
fn supported_input_formats(
|
||||
&self,
|
||||
) -> Result<Self::SupportedInputFormats, SupportedFormatsError> {
|
||||
Device::supported_input_formats(self)
|
||||
}
|
||||
|
||||
fn supported_output_formats(&self) -> Result<Self::SupportedOutputFormats, SupportedFormatsError> {
|
||||
fn supported_output_formats(
|
||||
&self,
|
||||
) -> Result<Self::SupportedOutputFormats, SupportedFormatsError> {
|
||||
Device::supported_output_formats(self)
|
||||
}
|
||||
|
||||
|
|
@ -97,7 +89,7 @@ impl DeviceTrait for Device {
|
|||
) -> Result<Self::Stream, BuildStreamError>
|
||||
where
|
||||
D: FnMut(&Data) + Send + 'static,
|
||||
E: FnMut(StreamError) + Send + 'static
|
||||
E: FnMut(StreamError) + Send + 'static,
|
||||
{
|
||||
Device::build_input_stream(self, format, data_callback, error_callback)
|
||||
}
|
||||
|
|
@ -110,7 +102,7 @@ impl DeviceTrait for Device {
|
|||
) -> Result<Self::Stream, BuildStreamError>
|
||||
where
|
||||
D: FnMut(&mut Data) + Send + 'static,
|
||||
E: FnMut(StreamError) + Send + 'static
|
||||
E: FnMut(StreamError) + Send + 'static,
|
||||
{
|
||||
Device::build_output_stream(self, format, data_callback, error_callback)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@ extern crate asio_sys as sys;
|
|||
extern crate num_traits;
|
||||
|
||||
use self::num_traits::PrimInt;
|
||||
use super::parking_lot::Mutex;
|
||||
use super::Device;
|
||||
use std;
|
||||
use std::sync::atomic::{Ordering, AtomicBool};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
use super::parking_lot::Mutex;
|
||||
use BackendSpecificError;
|
||||
use BuildStreamError;
|
||||
use Data;
|
||||
|
|
@ -93,7 +93,7 @@ impl Device {
|
|||
let callback_id = self.driver.add_callback(move |buffer_index| unsafe {
|
||||
// If not playing return early.
|
||||
if !playing.load(Ordering::SeqCst) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
// There is 0% chance of lock contention the host only locks when recreating streams.
|
||||
|
|
@ -111,8 +111,7 @@ impl Device {
|
|||
asio_stream: &sys::AsioStream,
|
||||
buffer_index: usize,
|
||||
from_endianness: F,
|
||||
)
|
||||
where
|
||||
) where
|
||||
A: AsioSample,
|
||||
B: Sample,
|
||||
D: FnMut(&Data) + Send + 'static,
|
||||
|
|
@ -157,8 +156,8 @@ impl Device {
|
|||
|
||||
// TODO: Handle endianness conversion for floats? We currently use the `PrimInt`
|
||||
// trait for the `to_le` and `to_be` methods, but this does not support floats.
|
||||
(&sys::AsioSampleType::ASIOSTFloat32LSB, SampleFormat::F32) |
|
||||
(&sys::AsioSampleType::ASIOSTFloat32MSB, SampleFormat::F32) => {
|
||||
(&sys::AsioSampleType::ASIOSTFloat32LSB, SampleFormat::F32)
|
||||
| (&sys::AsioSampleType::ASIOSTFloat32MSB, SampleFormat::F32) => {
|
||||
process_input_callback::<f32, f32, _, _>(
|
||||
&mut data_callback,
|
||||
&mut interleaved,
|
||||
|
|
@ -191,8 +190,8 @@ impl Device {
|
|||
}
|
||||
// TODO: Handle endianness conversion for floats? We currently use the `PrimInt`
|
||||
// trait for the `to_le` and `to_be` methods, but this does not support floats.
|
||||
(&sys::AsioSampleType::ASIOSTFloat64LSB, SampleFormat::F32) |
|
||||
(&sys::AsioSampleType::ASIOSTFloat64MSB, SampleFormat::F32) => {
|
||||
(&sys::AsioSampleType::ASIOSTFloat64LSB, SampleFormat::F32)
|
||||
| (&sys::AsioSampleType::ASIOSTFloat64MSB, SampleFormat::F32) => {
|
||||
process_input_callback::<f64, f32, _, _>(
|
||||
&mut data_callback,
|
||||
&mut interleaved,
|
||||
|
|
@ -202,10 +201,11 @@ impl Device {
|
|||
);
|
||||
}
|
||||
|
||||
unsupported_format_pair => {
|
||||
unreachable!("`build_input_stream` should have returned with unsupported \
|
||||
format {:?}", unsupported_format_pair)
|
||||
}
|
||||
unsupported_format_pair => unreachable!(
|
||||
"`build_input_stream` should have returned with unsupported \
|
||||
format {:?}",
|
||||
unsupported_format_pair
|
||||
),
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -258,7 +258,7 @@ impl Device {
|
|||
let callback_id = self.driver.add_callback(move |buffer_index| unsafe {
|
||||
// If not playing, return early.
|
||||
if !playing.load(Ordering::SeqCst) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
// There is 0% chance of lock contention the host only locks when recreating streams.
|
||||
|
|
@ -301,8 +301,7 @@ impl Device {
|
|||
asio_stream: &sys::AsioStream,
|
||||
buffer_index: usize,
|
||||
to_endianness: F,
|
||||
)
|
||||
where
|
||||
) where
|
||||
A: Sample,
|
||||
B: AsioSample,
|
||||
D: FnMut(&mut Data) + Send + 'static,
|
||||
|
|
@ -321,7 +320,9 @@ impl Device {
|
|||
for ch_ix in 0..n_channels {
|
||||
let asio_channel =
|
||||
asio_channel_slice_mut::<B>(asio_stream, buffer_index, ch_ix);
|
||||
asio_channel.iter_mut().for_each(|s| *s = to_endianness(B::SILENCE));
|
||||
asio_channel
|
||||
.iter_mut()
|
||||
.for_each(|s| *s = to_endianness(B::SILENCE));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -359,8 +360,8 @@ impl Device {
|
|||
|
||||
// TODO: Handle endianness conversion for floats? We currently use the `PrimInt`
|
||||
// trait for the `to_le` and `to_be` methods, but this does not support floats.
|
||||
(SampleFormat::F32, &sys::AsioSampleType::ASIOSTFloat32LSB) |
|
||||
(SampleFormat::F32, &sys::AsioSampleType::ASIOSTFloat32MSB) => {
|
||||
(SampleFormat::F32, &sys::AsioSampleType::ASIOSTFloat32LSB)
|
||||
| (SampleFormat::F32, &sys::AsioSampleType::ASIOSTFloat32MSB) => {
|
||||
process_output_callback::<f32, f32, _, _>(
|
||||
&mut data_callback,
|
||||
&mut interleaved,
|
||||
|
|
@ -396,8 +397,8 @@ impl Device {
|
|||
}
|
||||
// TODO: Handle endianness conversion for floats? We currently use the `PrimInt`
|
||||
// trait for the `to_le` and `to_be` methods, but this does not support floats.
|
||||
(SampleFormat::F32, &sys::AsioSampleType::ASIOSTFloat64LSB) |
|
||||
(SampleFormat::F32, &sys::AsioSampleType::ASIOSTFloat64MSB) => {
|
||||
(SampleFormat::F32, &sys::AsioSampleType::ASIOSTFloat64LSB)
|
||||
| (SampleFormat::F32, &sys::AsioSampleType::ASIOSTFloat64MSB) => {
|
||||
process_output_callback::<f32, f64, _, _>(
|
||||
&mut data_callback,
|
||||
&mut interleaved,
|
||||
|
|
@ -408,10 +409,11 @@ impl Device {
|
|||
);
|
||||
}
|
||||
|
||||
unsupported_format_pair => {
|
||||
unreachable!("`build_output_stream` should have returned with unsupported \
|
||||
format {:?}", unsupported_format_pair)
|
||||
}
|
||||
unsupported_format_pair => unreachable!(
|
||||
"`build_output_stream` should have returned with unsupported \
|
||||
format {:?}",
|
||||
unsupported_format_pair
|
||||
),
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -434,15 +436,12 @@ impl Device {
|
|||
/// If there is no existing ASIO Input Stream it will be created.
|
||||
///
|
||||
/// On success, the buffer size of the stream is returned.
|
||||
fn get_or_create_input_stream(
|
||||
&self,
|
||||
format: &Format,
|
||||
) -> Result<usize, BuildStreamError> {
|
||||
fn get_or_create_input_stream(&self, format: &Format) -> Result<usize, BuildStreamError> {
|
||||
match self.default_input_format() {
|
||||
Ok(f) => {
|
||||
let num_asio_channels = f.channels;
|
||||
check_format(&self.driver, format, num_asio_channels)
|
||||
},
|
||||
}
|
||||
Err(_) => Err(BuildStreamError::FormatNotSupported),
|
||||
}?;
|
||||
let num_channels = format.channels as usize;
|
||||
|
|
@ -462,7 +461,8 @@ impl Device {
|
|||
};
|
||||
*streams = new_streams;
|
||||
bs
|
||||
}).map_err(|ref e| {
|
||||
})
|
||||
.map_err(|ref e| {
|
||||
println!("Error preparing stream: {}", e);
|
||||
BuildStreamError::DeviceNotAvailable
|
||||
})
|
||||
|
|
@ -473,15 +473,12 @@ impl Device {
|
|||
/// Create a new CPAL Output Stream.
|
||||
///
|
||||
/// If there is no existing ASIO Output Stream it will be created.
|
||||
fn get_or_create_output_stream(
|
||||
&self,
|
||||
format: &Format,
|
||||
) -> Result<usize, BuildStreamError> {
|
||||
fn get_or_create_output_stream(&self, format: &Format) -> Result<usize, BuildStreamError> {
|
||||
match self.default_output_format() {
|
||||
Ok(f) => {
|
||||
let num_asio_channels = f.channels;
|
||||
check_format(&self.driver, format, num_asio_channels)
|
||||
},
|
||||
}
|
||||
Err(_) => Err(BuildStreamError::FormatNotSupported),
|
||||
}?;
|
||||
let num_channels = format.channels as usize;
|
||||
|
|
@ -501,7 +498,8 @@ impl Device {
|
|||
};
|
||||
*streams = new_streams;
|
||||
bs
|
||||
}).map_err(|ref e| {
|
||||
})
|
||||
.map_err(|ref e| {
|
||||
println!("Error preparing stream: {}", e);
|
||||
BuildStreamError::DeviceNotAvailable
|
||||
})
|
||||
|
|
@ -588,7 +586,10 @@ fn check_format(
|
|||
// Try and set the sample rate to what the user selected.
|
||||
let sample_rate = sample_rate.0.into();
|
||||
if sample_rate != driver.sample_rate().map_err(build_stream_err)? {
|
||||
if driver.can_sample_rate(sample_rate).map_err(build_stream_err)? {
|
||||
if driver
|
||||
.can_sample_rate(sample_rate)
|
||||
.map_err(build_stream_err)?
|
||||
{
|
||||
driver
|
||||
.set_sample_rate(sample_rate)
|
||||
.map_err(build_stream_err)?;
|
||||
|
|
@ -656,19 +657,17 @@ unsafe fn asio_channel_slice_mut<T>(
|
|||
buffer_index: usize,
|
||||
channel_index: usize,
|
||||
) -> &mut [T] {
|
||||
let buff_ptr: *mut T = asio_stream
|
||||
.buffer_infos[channel_index]
|
||||
.buffers[buffer_index as usize]
|
||||
as *mut _;
|
||||
let buff_ptr: *mut T =
|
||||
asio_stream.buffer_infos[channel_index].buffers[buffer_index as usize] as *mut _;
|
||||
std::slice::from_raw_parts_mut(buff_ptr, asio_stream.buffer_size as usize)
|
||||
}
|
||||
|
||||
fn build_stream_err(e: sys::AsioError) -> BuildStreamError {
|
||||
match e {
|
||||
sys::AsioError::NoDrivers |
|
||||
sys::AsioError::HardwareMalfunction => BuildStreamError::DeviceNotAvailable,
|
||||
sys::AsioError::InvalidInput |
|
||||
sys::AsioError::BadMode => BuildStreamError::InvalidArgument,
|
||||
sys::AsioError::NoDrivers | sys::AsioError::HardwareMalfunction => {
|
||||
BuildStreamError::DeviceNotAvailable
|
||||
}
|
||||
sys::AsioError::InvalidInput | sys::AsioError::BadMode => BuildStreamError::InvalidArgument,
|
||||
err => {
|
||||
let description = format!("{}", err);
|
||||
BackendSpecificError { description }.into()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue