nwhitehead / pyfluidsynth

Python bindings for FluidSynth
GNU Lesser General Public License v2.1
197 stars 56 forks source link

"NoneType object not callable” error when calling sfpreset_name() #35

Closed erixoff closed 2 years ago

erixoff commented 2 years ago

Hello, First of all, thanx very much for bringing PyFluidSynth.

I recently installed PyFluidSynth in a 32bit Windows environment, and managed to find a 32bit version of FluidSynth (wich is not so easy to find, unless I rebuild it) in a form of libfluidsynth-1.dll I execute the first test listed on PyFluidSynth GitHub homepage and it works well. Then I tried to call the following services and they fail with “NoneType object not callable” error :

Same issue with the example with the FluidSynth sequencer.

_File "C:\Users\xxx\MyApp\Python3.7_32bits\lib\site-packages\fluidsynth.py", line 607, in channel_info presetname = self.sfpreset_name(sfontid, banknum, prognum) File "C:\Users\xxx\MyApp\Python3.7_32bits\lib\site-packages\fluidsynth.py", line 624, in sfpreset_name preset=fluid_sfont_getpreset(sfont, bank, prog) TypeError: 'NoneType' object is not callable

Did I miss something ?

Thanx in advance

Regards

albedozero commented 2 years ago

You can grab a 32bit version of FluidSynth from their latest release on github - it's in fluidsynth-X.X.X-winXP-x86.zip.

The FluidSynth API has changed in some significant ways since its original version, and PyFluidSynth tries to figure out what's available and work around these changes in a way that's invisible to you the user. If you're compiling libfluidsynth-1.dll it sounds like you're using a pretty old version, which maybe just doesn't make _fluid_sfont_getpreset available.

Could you try the version in the latest release, or if you're locked to this older version for some reason, let us know what the version number is and maybe we can provide a workaround.

erixoff commented 2 years ago

Thanx for your answer and explanations :-) Yes, the link you provide gives access to either WindowsXP 32bit DLL ... or Windows10 64bit; but I use a 32bit Python under Windows10 for now. I think I should figure out how to install a 64 bit Python environment instead; because I don't know how to retrieve the version info from my old DLL; and I don't want to take your time for useless things. Anyway, thanx very much for your help.

albedozero commented 2 years ago

I can confirm that the DLLs in fluidsynth-2.2.3-winXP-x86.zip do actually work fine on Windows 10. I think the 32bit version was first developed on XP and the name just hasn't changed.

erixoff commented 2 years ago

Thank you. I tested with fluidsynth-2.2.3-winXP-x86.zip you mention, and I get another error: _Traceback (most recent call last): File "c:\Users\S0101534\MyApp\pySMG\main.py", line 7, in import fluidsynth File "C:\Users\S0101534\MyApp\Python3.7_32bits\lib\site-packages\fluidsynth.py", line 47, in _fl = CDLL(lib) File "C:\Users\S0101534\MyApp\Python3.7_32bits\lib\ctypes__init.py", line 364, in init__ self._handle = _dlopen(self.name, mode) OSError: [WinError 126] Le module spécifié est introuvable (in english: "the specified module is not found")

-> Wich leads to the following line in fluidsynth.py": _fl = CDLL(lib)

albedozero commented 2 years ago

Oops - I think that's a problem on this end. We needed to add the newest DLL name to the libraries searched. If you grab the latest version of pyfluidsynth it should work.

erixoff commented 2 years ago

Thanx. I updated my install with the last version (4 days ago) of PyFluidSynth, and I have the issue on "_fl = CDLL(lib)" line. Actually, I put the 32bit libfluidsynth-3.dll in the root of my project because it seems after debugging that it was needed to put there.

albedozero commented 2 years ago

Sorry I forgot to come back to this for a couple weeks. Did you copy all the DLL's from the 32bit release into your project root? They're all needed for fluidsynth to work.

erixoff commented 2 years ago

No problemo, you're back; that matters 👍 I copied all the DLLs and now, it works; I have sound and just the following error messages, but it runs: fluidsynth: error: not enough MIDI in devices found. Expected:1 found:0 fluidsynth: error: Device "default" does not exists fluidsynth: warning: sequencer: Usage of the system timer has been deprecated! Thanx very much !

albedozero commented 2 years ago

fluidsynth: error: not enough MIDI in devices found. Expected:1 found:0 fluidsynth: error: Device "default" does not exists

This is because midi.autoconnect is set to 1 and you didn't have a MIDI controller connected or it wasn't detected because it's being used by something else. midi.autoconnect should be 0 by default - if you're not planning to play notes from a keyboard you don't need it.

fluidsynth: warning: sequencer: Usage of the system timer has been deprecated!

Either player.timing-source is set to system, or maybe your script is rendering MIDI files to WAV files? If the latter, system timing is your only option and it's fine anyway. If you want fluidsynth to output audio to speakers, sample timing is probably better.

TLDR if your script is doing what you want, no worries! 😀

erixoff commented 2 years ago

Thanx very much for your answers (yes, I don't have MIDI keyboard connected, and script runs fine), for your support, and for having taken your time for my request. Good day