Skip to content

Commit 990af53

Browse files
authored
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.
1 parent a316b2b commit 990af53

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

sounddevice.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,16 +1832,20 @@ def __repr__(self):
18321832
odev = _get_device_id(default.device['output'], 'output')
18331833
digits = len(str(_lib.Pa_GetDeviceCount() - 1))
18341834
hostapi_names = [hostapi['name'] for hostapi in query_hostapis()]
1835+
1836+
def get_mark(idx):
1837+
return (' ', '>', '<', '*')[(idx == idev) + 2 * (idx == odev)]
1838+
18351839
text = '\n'.join(
18361840
'{mark} {idx:{dig}} {name}, {ha} ({ins} in, {outs} out)'.format(
1837-
mark=(' ', '>', '<', '*')[(idx == idev) + 2 * (idx == odev)],
1838-
idx=idx,
1841+
mark=get_mark(info['index']),
1842+
idx=info['index'],
18391843
dig=digits,
18401844
name=info['name'],
18411845
ha=hostapi_names[info['hostapi']],
18421846
ins=info['max_input_channels'],
18431847
outs=info['max_output_channels'])
1844-
for idx, info in enumerate(self))
1848+
for info in self)
18451849
return text
18461850

18471851

0 commit comments

Comments
 (0)