Remove the `get_` prefix of methods (#151)
* Remove the `get_` prefix of methods * Fix overlooks
This commit is contained in:
parent
35d9201b85
commit
cdcef96279
|
@ -19,8 +19,8 @@ impl Executor for MyExecutor {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let endpoint = cpal::get_default_endpoint().expect("Failed to get default endpoint");
|
||||
let format = endpoint.get_supported_formats_list().unwrap().next().expect("Failed to get endpoint format");
|
||||
let endpoint = cpal::default_endpoint().expect("Failed to get default endpoint");
|
||||
let format = endpoint.supported_formats().unwrap().next().expect("Failed to get endpoint format");
|
||||
|
||||
let event_loop = cpal::EventLoop::new();
|
||||
let executor = Arc::new(MyExecutor);
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
extern crate cpal;
|
||||
|
||||
fn main() {
|
||||
let endpoints = cpal::get_endpoints_list();
|
||||
let endpoints = cpal::endpoints();
|
||||
|
||||
println!("Endpoints: ");
|
||||
for (endpoint_index, endpoint) in endpoints.enumerate() {
|
||||
println!("{}. Endpoint \"{}\" Audio formats: ", endpoint_index + 1, endpoint.get_name());
|
||||
println!("{}. Endpoint \"{}\" Audio formats: ", endpoint_index + 1, endpoint.name());
|
||||
|
||||
let formats = match endpoint.get_supported_formats_list() {
|
||||
let formats = match endpoint.supported_formats() {
|
||||
Ok(f) => f,
|
||||
Err(e) => { println!("Error: {:?}", e); continue; }
|
||||
};
|
||||
|
|
36
src/lib.rs
36
src/lib.rs
|
@ -120,16 +120,30 @@ impl Iterator for EndpointsIterator {
|
|||
|
||||
/// Return an iterator to the list of formats that are supported by the system.
|
||||
#[inline]
|
||||
pub fn endpoints() -> EndpointsIterator {
|
||||
EndpointsIterator(Default::default())
|
||||
}
|
||||
|
||||
/// Deprecated. Use `endpoints()` instead.
|
||||
#[inline]
|
||||
#[deprecated]
|
||||
pub fn get_endpoints_list() -> EndpointsIterator {
|
||||
EndpointsIterator(Default::default())
|
||||
}
|
||||
|
||||
/// Return the default endpoint, or `None` if no device is available.
|
||||
#[inline]
|
||||
pub fn get_default_endpoint() -> Option<Endpoint> {
|
||||
pub fn default_endpoint() -> Option<Endpoint> {
|
||||
cpal_impl::get_default_endpoint().map(Endpoint)
|
||||
}
|
||||
|
||||
/// Deprecated. Use `default_endpoint()` instead.
|
||||
#[inline]
|
||||
#[deprecated]
|
||||
pub fn get_default_endpoint() -> Option<Endpoint> {
|
||||
default_endpoint()
|
||||
}
|
||||
|
||||
/// An opaque type that identifies an end point.
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct Endpoint(cpal_impl::Endpoint);
|
||||
|
@ -137,17 +151,33 @@ pub struct Endpoint(cpal_impl::Endpoint);
|
|||
impl Endpoint {
|
||||
/// Returns an iterator that produces the list of formats that are supported by the backend.
|
||||
#[inline]
|
||||
pub fn get_supported_formats_list(&self) -> Result<SupportedFormatsIterator,
|
||||
pub fn supported_formats(&self) -> Result<SupportedFormatsIterator,
|
||||
FormatsEnumerationError>
|
||||
{
|
||||
Ok(SupportedFormatsIterator(try!(self.0.get_supported_formats_list())))
|
||||
}
|
||||
|
||||
/// Deprecated. Use `supported_formats` instead.
|
||||
#[inline]
|
||||
#[deprecated]
|
||||
pub fn get_supported_formats_list(&self) -> Result<SupportedFormatsIterator,
|
||||
FormatsEnumerationError>
|
||||
{
|
||||
self.supported_formats()
|
||||
}
|
||||
|
||||
/// Returns the name of the endpoint.
|
||||
#[inline]
|
||||
pub fn get_name(&self) -> String {
|
||||
pub fn name(&self) -> String {
|
||||
self.0.get_name()
|
||||
}
|
||||
|
||||
/// Deprecated. Use `name()` instead.
|
||||
#[deprecated]
|
||||
#[inline]
|
||||
pub fn get_name(&self) -> String {
|
||||
self.name()
|
||||
}
|
||||
}
|
||||
|
||||
/// Number of channels.
|
||||
|
|
|
@ -14,18 +14,26 @@ pub enum SampleFormat {
|
|||
impl SampleFormat {
|
||||
/// Returns the size in bytes of a sample of this format.
|
||||
#[inline]
|
||||
pub fn get_sample_size(&self) -> usize {
|
||||
pub fn sample_size(&self) -> usize {
|
||||
match self {
|
||||
&SampleFormat::I16 => mem::size_of::<i16>(),
|
||||
&SampleFormat::U16 => mem::size_of::<u16>(),
|
||||
&SampleFormat::F32 => mem::size_of::<f32>(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Deprecated. Use `sample_size` instead.
|
||||
#[inline]
|
||||
#[deprecated]
|
||||
pub fn get_sample_size(&self) -> usize {
|
||||
self.sample_size()
|
||||
}
|
||||
}
|
||||
|
||||
/// Trait for containers that contain PCM data.
|
||||
pub unsafe trait Sample: Copy + Clone {
|
||||
/// Returns the `SampleFormat` corresponding to this data type.
|
||||
// TODO: rename to `format()`. Requires a breaking change.
|
||||
fn get_format() -> SampleFormat;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue