From 8f111732567b2c72bf4f50a56a510b74790c71ba Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Tue, 22 Sep 2015 14:43:30 +0200 Subject: [PATCH 1/2] Add an enumerate example --- examples/enumerate.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 examples/enumerate.rs diff --git a/examples/enumerate.rs b/examples/enumerate.rs new file mode 100644 index 0000000..d5921d9 --- /dev/null +++ b/examples/enumerate.rs @@ -0,0 +1,16 @@ +extern crate cpal; + +use cpal::*; + +fn main() { + let endpoints = cpal::get_endpoints_list(); + + println!("Endpoints: "); + for (endpoint_index, endpoint) in endpoints.enumerate() { + println!("{}. Endpoint \"{}\" Audio formats: ", endpoint_index + 1, endpoint.get_name()); + let formats = endpoint.get_supported_formats_list().unwrap(); + for (format_index, format) in formats.enumerate() { + println!("{}.{}. {:?}", endpoint_index+1, format_index+1, format); + } + } +} From ec48453b6f55760d85968a24bde203ab608cc4ab Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Tue, 22 Sep 2015 14:46:27 +0200 Subject: [PATCH 2/2] Add endpoint::get_name() and an enumerate example --- examples/enumerate.rs | 3 ++- src/alsa/mod.rs | 5 +++++ src/lib.rs | 6 ++++++ src/null/mod.rs | 5 +++++ src/wasapi/mod.rs | 5 +++++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/examples/enumerate.rs b/examples/enumerate.rs index d5921d9..03a0244 100644 --- a/examples/enumerate.rs +++ b/examples/enumerate.rs @@ -8,9 +8,10 @@ fn main() { println!("Endpoints: "); for (endpoint_index, endpoint) in endpoints.enumerate() { println!("{}. Endpoint \"{}\" Audio formats: ", endpoint_index + 1, endpoint.get_name()); + let formats = endpoint.get_supported_formats_list().unwrap(); for (format_index, format) in formats.enumerate() { - println!("{}.{}. {:?}", endpoint_index+1, format_index+1, format); + println!("{}.{}. {:?}", endpoint_index + 1, format_index + 1, format); } } } diff --git a/src/alsa/mod.rs b/src/alsa/mod.rs index e5922dc..0ad3634 100644 --- a/src/alsa/mod.rs +++ b/src/alsa/mod.rs @@ -33,6 +33,11 @@ impl Endpoint { Ok(Some(format).into_iter()) } + + #[inline] + pub fn get_name(&self) -> String { + "unknown".to_owned() // TODO: + } } pub struct Voice { diff --git a/src/lib.rs b/src/lib.rs index cc8a901..cf50a6f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -105,6 +105,12 @@ impl Endpoint { { Ok(SupportedFormatsIterator(try!(self.0.get_supported_formats_list()))) } + + /// Returns the name of the endpoint. + #[inline] + pub fn get_name(&self) -> String { + self.0.get_name() + } } /// Number of channels. diff --git a/src/null/mod.rs b/src/null/mod.rs index f5907af..ced23a8 100644 --- a/src/null/mod.rs +++ b/src/null/mod.rs @@ -33,6 +33,11 @@ impl Endpoint { { unreachable!() } + + #[inline] + pub fn get_name(&self) -> String { + "null".to_owned() + } } pub struct SupportedFormatsIterator; diff --git a/src/wasapi/mod.rs b/src/wasapi/mod.rs index f659d29..1212a67 100644 --- a/src/wasapi/mod.rs +++ b/src/wasapi/mod.rs @@ -51,6 +51,11 @@ unsafe impl Send for Endpoint {} unsafe impl Sync for Endpoint {} impl Endpoint { + #[inline] + pub fn get_name(&self) -> String { + "unknown".to_owned() // TODO: + } + #[inline] fn from_immdevice(device: *mut winapi::IMMDevice) -> Endpoint { Endpoint {