Merge pull request #304 from ishitatsuyuki/host-name
Add name to HostId
This commit is contained in:
commit
68bccdb325
|
@ -9,7 +9,7 @@ fn main() -> Result<(), failure::Error> {
|
||||||
println!("Available hosts:\n {:?}", available_hosts);
|
println!("Available hosts:\n {:?}", available_hosts);
|
||||||
|
|
||||||
for host_id in available_hosts {
|
for host_id in available_hosts {
|
||||||
println!("{:?}", host_id);
|
println!("{}", host_id.name());
|
||||||
let host = cpal::host_from_id(host_id)?;
|
let host = cpal::host_from_id(host_id)?;
|
||||||
let default_in = host.default_input_device().map(|e| e.name().unwrap());
|
let default_in = host.default_input_device().map(|e| e.name().unwrap());
|
||||||
let default_out = host.default_output_device().map(|e| e.name().unwrap());
|
let default_out = host.default_output_device().map(|e| e.name().unwrap());
|
||||||
|
|
|
@ -12,8 +12,8 @@ pub use self::platform_impl::*;
|
||||||
// These dynamically dispatched types are necessary to allow for users to switch between hosts at
|
// These dynamically dispatched types are necessary to allow for users to switch between hosts at
|
||||||
// runtime.
|
// runtime.
|
||||||
//
|
//
|
||||||
// For example the invocation `impl_platform_host(Wasapi wasapi, Asio asio)`, this macro should
|
// For example the invocation `impl_platform_host(Wasapi wasapi "WASAPI", Asio asio "ASIO")`,
|
||||||
// expand to:
|
// this macro should expand to:
|
||||||
//
|
//
|
||||||
// ```
|
// ```
|
||||||
// pub enum HostId {
|
// pub enum HostId {
|
||||||
|
@ -31,7 +31,7 @@ pub use self::platform_impl::*;
|
||||||
// SupportedOutputFormats and all their necessary trait implementations.
|
// SupportedOutputFormats and all their necessary trait implementations.
|
||||||
// ```
|
// ```
|
||||||
macro_rules! impl_platform_host {
|
macro_rules! impl_platform_host {
|
||||||
($($HostVariant:ident $host_mod:ident),*) => {
|
($($HostVariant:ident $host_mod:ident $host_name:literal),*) => {
|
||||||
/// All hosts supported by CPAL on this platform.
|
/// All hosts supported by CPAL on this platform.
|
||||||
pub const ALL_HOSTS: &'static [HostId] = &[
|
pub const ALL_HOSTS: &'static [HostId] = &[
|
||||||
$(
|
$(
|
||||||
|
@ -126,6 +126,16 @@ macro_rules! impl_platform_host {
|
||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HostId {
|
||||||
|
pub fn name(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
$(
|
||||||
|
HostId::$HostVariant => $host_name,
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Host {
|
impl Host {
|
||||||
/// The unique identifier associated with this host.
|
/// The unique identifier associated with this host.
|
||||||
pub fn id(&self) -> HostId {
|
pub fn id(&self) -> HostId {
|
||||||
|
@ -468,7 +478,7 @@ mod platform_impl {
|
||||||
SupportedOutputFormats as AlsaSupportedOutputFormats,
|
SupportedOutputFormats as AlsaSupportedOutputFormats,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl_platform_host!(Alsa alsa);
|
impl_platform_host!(Alsa alsa "ALSA");
|
||||||
|
|
||||||
/// The default host for the current compilation target platform.
|
/// The default host for the current compilation target platform.
|
||||||
pub fn default_host() -> Host {
|
pub fn default_host() -> Host {
|
||||||
|
@ -491,7 +501,7 @@ mod platform_impl {
|
||||||
SupportedOutputFormats as CoreAudioSupportedOutputFormats,
|
SupportedOutputFormats as CoreAudioSupportedOutputFormats,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl_platform_host!(CoreAudio coreaudio);
|
impl_platform_host!(CoreAudio coreaudio "CoreAudio");
|
||||||
|
|
||||||
/// The default host for the current compilation target platform.
|
/// The default host for the current compilation target platform.
|
||||||
pub fn default_host() -> Host {
|
pub fn default_host() -> Host {
|
||||||
|
@ -513,7 +523,7 @@ mod platform_impl {
|
||||||
SupportedOutputFormats as EmscriptenSupportedOutputFormats,
|
SupportedOutputFormats as EmscriptenSupportedOutputFormats,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl_platform_host!(Emscripten emscripten);
|
impl_platform_host!(Emscripten emscripten "Emscripten");
|
||||||
|
|
||||||
/// The default host for the current compilation target platform.
|
/// The default host for the current compilation target platform.
|
||||||
pub fn default_host() -> Host {
|
pub fn default_host() -> Host {
|
||||||
|
@ -546,10 +556,10 @@ mod platform_impl {
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "asio")]
|
#[cfg(feature = "asio")]
|
||||||
impl_platform_host!(Asio asio, Wasapi wasapi);
|
impl_platform_host!(Asio asio "ASIO", Wasapi wasapi "WASAPI");
|
||||||
|
|
||||||
#[cfg(not(feature = "asio"))]
|
#[cfg(not(feature = "asio"))]
|
||||||
impl_platform_host!(Wasapi wasapi);
|
impl_platform_host!(Wasapi wasapi "WASAPI");
|
||||||
|
|
||||||
/// The default host for the current compilation target platform.
|
/// The default host for the current compilation target platform.
|
||||||
pub fn default_host() -> Host {
|
pub fn default_host() -> Host {
|
||||||
|
@ -572,7 +582,7 @@ mod platform_impl {
|
||||||
SupportedOutputFormats as NullSupportedOutputFormats,
|
SupportedOutputFormats as NullSupportedOutputFormats,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl_platform_host!(Null null);
|
impl_platform_host!(Null null "Null");
|
||||||
|
|
||||||
/// The default host for the current compilation target platform.
|
/// The default host for the current compilation target platform.
|
||||||
pub fn default_host() -> Host {
|
pub fn default_host() -> Host {
|
||||||
|
|
Loading…
Reference in New Issue