Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add argument to search for device by name and scope #109

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/audio_unit/macos_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,23 @@ pub fn get_default_device_id(input: bool) -> Option<AudioDeviceID> {
}

/// Find the device id for a device name.
pub fn get_device_id_from_name(name: &str) -> Option<AudioDeviceID> {
/// Set `input` to `true` to find a playback device, or `false` for a capture device.
pub fn get_device_id_from_name(name: &str, input: bool) -> Option<AudioDeviceID> {
let scope = match input {
false => Scope::Output,
true => Scope::Input,
};
if let Ok(all_ids) = get_audio_device_ids() {
return all_ids
.iter()
.find(|id| get_device_name(**id).unwrap_or_else(|_| "".to_string()) == name)
.find(|id| get_device_name(**id).unwrap_or_default() == name && get_audio_device_supports_scope(**id, scope).unwrap_or_default())
.copied();
}
None
}

/// Create an AudioUnit instance from a device id.
/// Set `input` to `true` to create a playback device, or `false` for a capture device.
pub fn audio_unit_from_device_id(
device_id: AudioDeviceID,
input: bool,
Expand Down
Loading