You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm writing a GUI program where the user is offered a choice of input devices and can pick one. The program should "remember" the user choice across launch, so it must serialise some identifying data about the device such that it can be retrieved again at next launch (assuming it still exists).
As far as I understand, the only piece of identifying data available for a Device is its name().
Problem
Device names are not unique, at least on macOS if you have two identical (e.g.) monitors, both equipped with mics and/or speakers. I happen to be in this situation and this code returns the following result:
let devices:Vec<_> = cpal::default_host().input_devices().unwrap().collect();for device in devices {println!("Input device: {}", device.name().unwrap());}
Result:
Input device: <iphone name> Microphone
Input device: Studio Display Microphone
Input device: Studio Display Microphone
Input device: MacBook Pro Microphone
Input device: Microsoft Teams Audio
Input device: iPad audio
Input device: ZoomAudioDevice
Solution
Ideally, Devices should have some kind of id that can be stored and checked against when trying to retrieve the same device at a later stage.
I'll probably have to do something like that, though I might save the (name, n), to refer to the nth device named name.
edit: this workaround precludes using the system-defined default input/output device, because if the default is one of the duplicated name, it's currently impossible to know which one it corresponds to.
Motivating use case
I'm writing a GUI program where the user is offered a choice of input devices and can pick one. The program should "remember" the user choice across launch, so it must serialise some identifying data about the device such that it can be retrieved again at next launch (assuming it still exists).
As far as I understand, the only piece of identifying data available for a
Device
is itsname()
.Problem
Device names are not unique, at least on macOS if you have two identical (e.g.) monitors, both equipped with mics and/or speakers. I happen to be in this situation and this code returns the following result:
Result:
Solution
Ideally,
Device
s should have some kind of id that can be stored and checked against when trying to retrieve the same device at a later stage.Related
Device::id()
: Add Device::id() #537The text was updated successfully, but these errors were encountered: