Skip to content

Commit

Permalink
Change DeviceList repr to use correct indices (#548)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rmccampbell authored Aug 11, 2024
1 parent a316b2b commit 990af53
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions sounddevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -1832,16 +1832,20 @@ def __repr__(self):
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


Expand Down

0 comments on commit 990af53

Please sign in to comment.