Remove DefaultHost type in favour of determining at runtime
Re-exports host-specific types so that they are available within the platform module if necessary (e.g. host::asla::Host as AlsaHost). Allows for converting platform-specific host types (e.g. AlsaHost) into the dynamically dispatched type generated for the target platform (`Host`).
This commit is contained in:
parent
283a73054e
commit
51eba20c44
|
@ -148,7 +148,7 @@ extern crate lazy_static;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate stdweb;
|
extern crate stdweb;
|
||||||
|
|
||||||
pub use platform::{ALL_HOSTS, DefaultHost, HostId, available_hosts, default_host, host_from_id};
|
pub use platform::{ALL_HOSTS, HostId, available_hosts, default_host, host_from_id};
|
||||||
pub use samples_formats::{Sample, SampleFormat};
|
pub use samples_formats::{Sample, SampleFormat};
|
||||||
|
|
||||||
use failure::Fail;
|
use failure::Fail;
|
||||||
|
|
|
@ -387,6 +387,38 @@ macro_rules! impl_platform_host {
|
||||||
|
|
||||||
impl crate::StreamId for StreamId {}
|
impl crate::StreamId for StreamId {}
|
||||||
|
|
||||||
|
$(
|
||||||
|
impl From<crate::host::$host_mod::Device> for Device {
|
||||||
|
fn from(h: crate::host::$host_mod::Device) -> Self {
|
||||||
|
Device(DeviceInner::$HostVariant(h))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<crate::host::$host_mod::Devices> for Devices {
|
||||||
|
fn from(h: crate::host::$host_mod::Devices) -> Self {
|
||||||
|
Devices(DevicesInner::$HostVariant(h))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<crate::host::$host_mod::EventLoop> for EventLoop {
|
||||||
|
fn from(h: crate::host::$host_mod::EventLoop) -> Self {
|
||||||
|
EventLoop(EventLoopInner::$HostVariant(h))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<crate::host::$host_mod::Host> for Host {
|
||||||
|
fn from(h: crate::host::$host_mod::Host) -> Self {
|
||||||
|
Host(HostInner::$HostVariant(h))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<crate::host::$host_mod::StreamId> for StreamId {
|
||||||
|
fn from(h: crate::host::$host_mod::StreamId) -> Self {
|
||||||
|
StreamId(StreamIdInner::$HostVariant(h))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)*
|
||||||
|
|
||||||
/// Produces a list of hosts that are currently available on the system.
|
/// Produces a list of hosts that are currently available on the system.
|
||||||
pub fn available_hosts() -> Vec<HostId> {
|
pub fn available_hosts() -> Vec<HostId> {
|
||||||
let mut host_ids = vec![];
|
let mut host_ids = vec![];
|
||||||
|
@ -416,61 +448,113 @@ macro_rules! impl_platform_host {
|
||||||
// TODO: Add pulseaudio and jack here eventually.
|
// TODO: Add pulseaudio and jack here eventually.
|
||||||
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
|
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
|
||||||
mod platform_impl {
|
mod platform_impl {
|
||||||
pub use crate::host::alsa::Host as AlsaHost;
|
pub use crate::host::alsa::{
|
||||||
|
Device as AlsaDevice,
|
||||||
/// The default host for the current compilation target platform.
|
Devices as AlsaDevices,
|
||||||
pub type DefaultHost = crate::host::alsa::Host;
|
EventLoop as AlsaEventLoop,
|
||||||
|
Host as AlsaHost,
|
||||||
|
StreamId as AlsaStreamId,
|
||||||
|
SupportedInputFormats as AlsaSupportedInputFormats,
|
||||||
|
SupportedOutputFormats as AlsaSupportedOutputFormats,
|
||||||
|
};
|
||||||
|
|
||||||
impl_platform_host!(Alsa alsa);
|
impl_platform_host!(Alsa alsa);
|
||||||
|
|
||||||
|
/// The default host for the current compilation target platform.
|
||||||
|
pub fn default_host() -> Host {
|
||||||
|
AlsaHost::new()
|
||||||
|
.expect("the default host should always be available")
|
||||||
|
.into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||||
mod platform_impl {
|
mod platform_impl {
|
||||||
pub use crate::host::coreaudio::Host as CoreAudioHost;
|
pub use crate::host::coreaudio::{
|
||||||
|
Device as CoreAudioDevice,
|
||||||
/// The default host for the current compilation target platform.
|
Devices as CoreAudioDevices,
|
||||||
pub type DefaultHost = crate::host::coreaudio::Host;
|
EventLoop as CoreAudioEventLoop,
|
||||||
|
Host as CoreAudioHost,
|
||||||
|
StreamId as CoreAudioStreamId,
|
||||||
|
SupportedInputFormats as CoreAudioSupportedInputFormats,
|
||||||
|
SupportedOutputFormats as CoreAudioSupportedOutputFormats,
|
||||||
|
};
|
||||||
|
|
||||||
impl_platform_host!(CoreAudio coreaudio);
|
impl_platform_host!(CoreAudio coreaudio);
|
||||||
|
|
||||||
|
/// The default host for the current compilation target platform.
|
||||||
|
pub fn default_host() -> Host {
|
||||||
|
CoreAudioHost::new()
|
||||||
|
.expect("the default host should always be available")
|
||||||
|
.into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "emscripten")]
|
#[cfg(target_os = "emscripten")]
|
||||||
mod platform_impl {
|
mod platform_impl {
|
||||||
pub use crate::host::emscripten::Host as EmscriptenHost;
|
pub use crate::host::emscripten::{
|
||||||
|
Device as EmscriptenDevice,
|
||||||
/// The default host for the current compilation target platform.
|
Devices as EmscriptenDevices,
|
||||||
pub type DefaultHost = crate::host::emscripten::Host;
|
EventLoop as EmscriptenEventLoop,
|
||||||
|
Host as EmscriptenHost,
|
||||||
|
StreamId as EmscriptenStreamId,
|
||||||
|
SupportedInputFormats as EmscriptenSupportedInputFormats,
|
||||||
|
SupportedOutputFormats as EmscriptenSupportedOutputFormats,
|
||||||
|
};
|
||||||
|
|
||||||
impl_platform_host!(Emscripten emscripten);
|
impl_platform_host!(Emscripten emscripten);
|
||||||
|
|
||||||
|
/// The default host for the current compilation target platform.
|
||||||
|
pub fn default_host() -> Host {
|
||||||
|
EmscriptenHost::new()
|
||||||
|
.expect("the default host should always be available")
|
||||||
|
.into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add `Asio asio` once #221 lands.
|
// TODO: Add `Asio asio` once #221 lands.
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
mod platform_impl {
|
mod platform_impl {
|
||||||
pub use crate::host::wasapi::Host as WasapiHost;
|
pub use crate::host::wasapi::{
|
||||||
|
Device as WasapiDevice,
|
||||||
/// The default host for the current compilation target platform.
|
Devices as WasapiDevices,
|
||||||
pub type DefaultHost = crate::host::wasapi::Host;
|
EventLoop as WasapiEventLoop,
|
||||||
|
Host as WasapiHost,
|
||||||
|
StreamId as WasapiStreamId,
|
||||||
|
SupportedInputFormats as WasapiSupportedInputFormats,
|
||||||
|
SupportedOutputFormats as WasapiSupportedOutputFormats,
|
||||||
|
};
|
||||||
|
|
||||||
impl_platform_host!(Wasapi wasapi);
|
impl_platform_host!(Wasapi wasapi);
|
||||||
|
|
||||||
|
/// The default host for the current compilation target platform.
|
||||||
|
pub fn default_host() -> Host {
|
||||||
|
WasapiHost::new()
|
||||||
|
.expect("the default host should always be available")
|
||||||
|
.into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(windows, target_os = "linux", target_os = "freebsd", target_os = "macos",
|
#[cfg(not(any(windows, target_os = "linux", target_os = "freebsd", target_os = "macos",
|
||||||
target_os = "ios", target_os = "emscripten")))]
|
target_os = "ios", target_os = "emscripten")))]
|
||||||
mod platform_impl {
|
mod platform_impl {
|
||||||
pub use crate::host::null::Host as NullHost;
|
pub use crate::host::null::{
|
||||||
|
Device as NullDevice,
|
||||||
/// The default host for the current compilation target platform.
|
Devices as NullDevices,
|
||||||
pub type DefaultHost = crate::host::null::Host;
|
EventLoop as NullEventLoop,
|
||||||
|
Host as NullHost,
|
||||||
|
StreamId as NullStreamId,
|
||||||
|
SupportedInputFormats as NullSupportedInputFormats,
|
||||||
|
SupportedOutputFormats as NullSupportedOutputFormats,
|
||||||
|
};
|
||||||
|
|
||||||
impl_platform_host!(Null null);
|
impl_platform_host!(Null null);
|
||||||
}
|
|
||||||
|
|
||||||
/// Retrieve the default host for the system.
|
/// The default host for the current compilation target platform.
|
||||||
///
|
pub fn default_host() -> Host {
|
||||||
/// There should *always* be a default host for each of the supported target platforms, regardless
|
NullHost::new()
|
||||||
/// of whether or not there are any available audio devices.
|
.expect("the default host should always be available")
|
||||||
pub fn default_host() -> DefaultHost {
|
.into()
|
||||||
DefaultHost::new().expect("the default host should always be available")
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue