Skip to content

Commit 23c9754

Browse files
authored
Merge pull request #109 from HEnquist/find_by_name_and_scope
Add argument to search for device by name and scope
2 parents 3233a54 + 88f1ade commit 23c9754

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/audio_unit/macos_helpers.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,23 @@ pub fn get_default_device_id(input: bool) -> Option<AudioDeviceID> {
7070
}
7171

7272
/// Find the device id for a device name.
73-
pub fn get_device_id_from_name(name: &str) -> Option<AudioDeviceID> {
73+
/// Set `input` to `true` to find a playback device, or `false` for a capture device.
74+
pub fn get_device_id_from_name(name: &str, input: bool) -> Option<AudioDeviceID> {
75+
let scope = match input {
76+
false => Scope::Output,
77+
true => Scope::Input,
78+
};
7479
if let Ok(all_ids) = get_audio_device_ids() {
7580
return all_ids
7681
.iter()
77-
.find(|id| get_device_name(**id).unwrap_or_else(|_| "".to_string()) == name)
82+
.find(|id| get_device_name(**id).unwrap_or_default() == name && get_audio_device_supports_scope(**id, scope).unwrap_or_default())
7883
.copied();
7984
}
8085
None
8186
}
8287

8388
/// Create an AudioUnit instance from a device id.
89+
/// Set `input` to `true` to create a playback device, or `false` for a capture device.
8490
pub fn audio_unit_from_device_id(
8591
device_id: AudioDeviceID,
8692
input: bool,

0 commit comments

Comments
 (0)