Ports should not be identified by index (for calls to port_name and connect), but rather by some backend-specific identifier that does not change when the order of devices changes.
These identifiers do not need to be persistent across sessions (e.g. to write them to a configuration file), because that would be quite a bit harder and can be added later.
The following identifiers could work for each platform:
| Backend |
Port Identifier |
| ALSA |
snd_seq_addr_t (numeric client + port IDs) |
| CoreMIDI |
MIDIEndpointRef, or maybe MIDIObjectFindByUniqueID |
| JACK |
Port name (string) |
| WinMM |
Maybe a combination of port name (as returned by GetDevCaps) and interface name (another string, see https://docs.microsoft.com/de-de/windows-hardware/drivers/audio/obtaining-a-device-interface-name). This requires a linear search when calling connect(), but I think that's not a problem. |
| WinRT |
DeviceInformation::Id (string) |
The platform-specific representation could be wrapped in a PortId struct.
Ports should not be identified by index (for calls to
port_nameandconnect), but rather by some backend-specific identifier that does not change when the order of devices changes.These identifiers do not need to be persistent across sessions (e.g. to write them to a configuration file), because that would be quite a bit harder and can be added later.
The following identifiers could work for each platform:
GetDevCaps) and interface name (another string, see https://docs.microsoft.com/de-de/windows-hardware/drivers/audio/obtaining-a-device-interface-name). This requires a linear search when callingconnect(), but I think that's not a problem.The platform-specific representation could be wrapped in a
PortIdstruct.