diff --git a/app/core/vst_engine.py b/app/core/vst_engine.py index 702abaf..54089f0 100644 --- a/app/core/vst_engine.py +++ b/app/core/vst_engine.py @@ -5,6 +5,22 @@ import numpy as np import functools from ctypes import c_char_p + +def _ensure_fluidsynth_dll_on_path(): + """Frozen (PyInstaller): pyfluidsynth tim dll qua ctypes.util.find_library + (chi quet PATH). Dat libfluidsynth-3.dll ke exe roi them exe_dir vao PATH + truoc khi import fluidsynth - nguoc lai: 'Couldn't find the FluidSynth + library' -> /soundfont-render tra 501.""" + import sys + if getattr(sys, 'frozen', False): + exe_dir = os.path.dirname(os.path.abspath(sys.executable)) + if exe_dir and exe_dir not in os.environ.get('PATH', '').split(os.pathsep): + os.environ['PATH'] = exe_dir + os.pathsep + os.environ.get('PATH', '') + + +_ensure_fluidsynth_dll_on_path() + + def midi_note_to_freq(note_number: int) -> float: return 440.0 * (2.0 ** ((note_number - 69) / 12.0)) diff --git a/engine.spec b/engine.spec index 1215c88..40bd61b 100644 --- a/engine.spec +++ b/engine.spec @@ -90,8 +90,16 @@ _hidden = [ 'uvicorn.protocols.websockets', 'uvicorn.protocols.websockets.auto', 'pedalboard', + # C++ ExternalPlugin.h import pedalboard.midi_utils khi tao VST3Plugin + # (py::module_::import) - PyInstaller khong thay duoc import tu C++, phai + # khai bao hiddenimport thu cong (thieu -> "No module named + # 'pedalboard.midi_utils'" khi /midi-render). + 'pedalboard.midi_utils', 'soundfile', 'sf2utils', + # pyfluidsynth (fluidsynth.py cffi) - render soundfont native cho + # /soundfont-render (browser client). Can libfluidsynth-3.dll ke exe. + 'fluidsynth', 'mido.backends.rtmidi', ] + _scipy_signal_hidden