|
| 1 | +//! Implementations for ASIO-specific device functionality. |
| 2 | +
|
| 3 | +use crate::BackendSpecificError; |
| 4 | +use crate::Device; |
| 5 | + |
| 6 | +/// Extension trait for ASIO-specific device functionality. |
| 7 | +pub trait AsioDeviceExt { |
| 8 | + /// Returns `true` if this device is an ASIO device. |
| 9 | + fn is_asio_device(&self) -> bool; |
| 10 | + |
| 11 | + /// Opens the ASIO driver's control panel window. |
| 12 | + /// |
| 13 | + /// This provides access to device-specific settings like buffer size, |
| 14 | + /// sample rate, input/output routing, and hardware-specific features. |
| 15 | + /// |
| 16 | + /// # Blocking Behavior |
| 17 | + /// |
| 18 | + /// **WARNING**: This call may block until the user closes the control panel. |
| 19 | + /// Consider spawning a thread to avoid blocking the main thread. |
| 20 | + /// |
| 21 | + /// # Errors |
| 22 | + /// |
| 23 | + /// Returns an error if this device is not an ASIO device. |
| 24 | + fn asio_open_control_panel(&self) -> Result<(), BackendSpecificError>; |
| 25 | +} |
| 26 | + |
| 27 | +#[cfg(all(target_os = "windows", feature = "asio"))] |
| 28 | +impl AsioDeviceExt for Device { |
| 29 | + fn is_asio_device(&self) -> bool { |
| 30 | + matches!(self.as_inner(), crate::platform::DeviceInner::Asio(_)) |
| 31 | + } |
| 32 | + |
| 33 | + fn asio_open_control_panel(&self) -> Result<(), BackendSpecificError> { |
| 34 | + use crate::platform::DeviceInner; |
| 35 | + |
| 36 | + if let DeviceInner::Asio(ref asio_device) = self.as_inner() { |
| 37 | + asio_device |
| 38 | + .driver |
| 39 | + .open_control_panel() |
| 40 | + .map_err(|e| BackendSpecificError { |
| 41 | + description: format!("Failed to open control panel: {:?}", e), |
| 42 | + }) |
| 43 | + } else { |
| 44 | + Err(BackendSpecificError { |
| 45 | + description: "Not an ASIO device".to_string(), |
| 46 | + }) |
| 47 | + } |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +#[cfg(not(all(target_os = "windows", feature = "asio")))] |
| 52 | +impl AsioDeviceExt for Device { |
| 53 | + fn is_asio_device(&self) -> bool { |
| 54 | + false |
| 55 | + } |
| 56 | + |
| 57 | + fn asio_open_control_panel(&self) -> Result<(), BackendSpecificError> { |
| 58 | + Err(not_available()) |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +#[cfg(not(all(target_os = "windows", feature = "asio")))] |
| 63 | +fn not_available() -> BackendSpecificError { |
| 64 | + BackendSpecificError { |
| 65 | + description: "ASIO is not available on this platform".to_string(), |
| 66 | + } |
| 67 | +} |
0 commit comments