diff --git a/examples/beep.rs b/examples/beep.rs index 68bfb3d..3a53263 100644 --- a/examples/beep.rs +++ b/examples/beep.rs @@ -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); diff --git a/examples/enumerate.rs b/examples/enumerate.rs index 1d467ab..5cd1414 100644 --- a/examples/enumerate.rs +++ b/examples/enumerate.rs @@ -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; } }; diff --git a/src/lib.rs b/src/lib.rs index fa1281d..621ef31 100644 --- a/src/lib.rs +++ b/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 { +pub fn default_endpoint() -> Option { cpal_impl::get_default_endpoint().map(Endpoint) } +/// Deprecated. Use `default_endpoint()` instead. +#[inline] +#[deprecated] +pub fn get_default_endpoint() -> Option { + 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 + pub fn supported_formats(&self) -> Result { Ok(SupportedFormatsIterator(try!(self.0.get_supported_formats_list()))) } + /// Deprecated. Use `supported_formats` instead. + #[inline] + #[deprecated] + pub fn get_supported_formats_list(&self) -> Result + { + 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. diff --git a/src/samples_formats.rs b/src/samples_formats.rs index ebf6525..33e3cc2 100644 --- a/src/samples_formats.rs +++ b/src/samples_formats.rs @@ -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::(), &SampleFormat::U16 => mem::size_of::(), &SampleFormat::F32 => mem::size_of::(), } } + + /// 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; }