Skip to content

Commit

Permalink
Merge pull request #109 from HEnquist/find_by_name_and_scope
Browse files Browse the repository at this point in the history
Add argument to search for device by name and scope
  • Loading branch information
simlay authored Apr 4, 2024
2 parents 3233a54 + 88f1ade commit 23c9754
Showing 1 changed file with 8 additions and 2 deletions.
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

0 comments on commit 23c9754

Please sign in to comment.