SpotlightKid / python-rtmidi

Python bindings for the cross-platform MIDI I/O library RtMidi
https://spotlightkid.github.io/python-rtmidi/
Other
356 stars 65 forks source link

get_ports() returns garbled text on multi-byte character port name. #180

Closed nai-kon closed 12 months ago

nai-kon commented 12 months ago

Hello. If midi port name contains multi-byte characters, Japanese in my case, get_ports() returns garbled text. Here is samples with multi-byte character "日本語" which means "Japanese".

On Windows 10, python-rtmidi 1.5.6, Python 3.11.5

original port name image

result

>>>  import rtmidi
>>> rtmidi.MidiOut().get_ports()
['Microsoft GS Wavetable Synth 0', 'loopMIDI Port 1', 'loopMIDI Port æ\x97¥æ\x9c¬èª\x9e 2']

On MacOS Sonoma on M1 Mac, python-rtmidi 1.5.6, Python 3.11.5

original port name image

result

>>>  import rtmidi
>>> rtmidi.MidiOut().get_ports()
['IACdriver port with english', 'IACdriver port with 日本語']

Thanks.

SpotlightKid commented 12 months ago

You probably need to pass the correct encoding name to the get_ports() method with the encoding keyword argument:

https://spotlightkid.github.io/python-rtmidi/rtmidi.html#rtmidi.MidiIn.get_ports

Or pass None as the encoding and get raw byte strings back.

nai-kon commented 12 months ago

get_ports("utf-8") returned a correct port name. Thank you!