Closed Yao-Lirong closed 1 year ago
A pr was created to fix the described issue #221.
Hello!
I think this issue was based on a quite old version of pyfluidsynth and PR #221 crashes with the newer versions. In the first message it's said that the definition of sfload
in fluidsynth.py
is:
fluid_synth_sfload = cfunc('fluid_synth_sfload', c_int,
('synth', c_void_p, 1),
('filename', c_char_p, 1),
('update_midi_presets', c_int, 1))
def sfload(self, filename, update_midi_preset=0):
"""Load SoundFont and return its ID"""
return fluid_synth_sfload(self.synth, filename, update_midi_preset)
But since https://github.com/nwhitehead/pyfluidsynth/commit/8c9bbaabe1688160f6be201170b26335746cc66e in 2017, the definition of 'sfload' includes a call to .encode()
so filename
should be a str
and not a c_char_p
:
def sfload(self, filename, update_midi_preset=0):
"""Load SoundFont and return its ID"""
return fluid_synth_sfload(self.synth, filename.encode(), update_midi_preset)
Which fixes the issue reported at the beginning of this threat and crashes with PR #221: AttributeError: 'c_char_p' object has no attribute 'encode'
.
I think PR #221 should be reverted and, in any case, indicate the minimum version of pyfluidsynth compatible with pretty-midi in the documentation.
In
fluidsynth
ofinstrument.py
(attached as the bottom last cell), there is this following function call tofluidsynth.py
(attached as the bottom second cell). The last line callssfload
, which should take in an argument ofc_char_p
type. However,sf2_path
, according to spec of this function, is a pythonstr
. This causes the error:A simple fix would be to add the following line before calling
sfload
: (A pull request will be opened soon to provide this simple fix)The following is the definition of
sfload
influidsynth.py
:The following is the original definition of
fluidsynth
ininstrument.py
.