diff options
| author | Ryan McCampbell <rmccampbell7@gmail.com> | 2024-08-11 04:51:44 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-11 13:51:44 +0200 |
| commit | 990af534a9f75e78928dc4aea5c60d7d66e5091b (patch) | |
| tree | 19a8fea385fa738bce5192bd83fbed464962fac7 | |
| parent | a316b2b2f909f1f2c506693c798612d1d26e616c (diff) | |
Change DeviceList repr to use correct indices (#548)
The index from enumerate won't match the actual device index if the list is filtered/reordered for whatever reason (i.e. to restrict to inputs/outputs or a specific API). This also means the default mark would be wrong. This fix uses the index in the dictionary instead.
| -rw-r--r-- | sounddevice.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/sounddevice.py b/sounddevice.py index e59244b..0784726 100644 --- a/sounddevice.py +++ b/sounddevice.py @@ -1832,16 +1832,20 @@ class DeviceList(tuple): odev = _get_device_id(default.device['output'], 'output') digits = len(str(_lib.Pa_GetDeviceCount() - 1)) hostapi_names = [hostapi['name'] for hostapi in query_hostapis()] + + def get_mark(idx): + return (' ', '>', '<', '*')[(idx == idev) + 2 * (idx == odev)] + text = '\n'.join( '{mark} {idx:{dig}} {name}, {ha} ({ins} in, {outs} out)'.format( - mark=(' ', '>', '<', '*')[(idx == idev) + 2 * (idx == odev)], - idx=idx, + mark=get_mark(info['index']), + idx=info['index'], dig=digits, name=info['name'], ha=hostapi_names[info['hostapi']], ins=info['max_input_channels'], outs=info['max_output_channels']) - for idx, info in enumerate(self)) + for info in self) return text |
