diff --git a/app/core/vst_engine.py b/app/core/vst_engine.py index d8adb6b..2bb0420 100644 --- a/app/core/vst_engine.py +++ b/app/core/vst_engine.py @@ -49,27 +49,29 @@ def render_midi_events_to_audio(midi_events: list, sr: int = 44100, bpm: float = out_r /= max_peak return np.vstack([out_l, out_r]) -def check_pedalboard_safe(): - import subprocess, sys +def _module_available(name: str) -> bool: + """Kiem tra module co san khong — KHONG spawn subprocess. + + Truoc day dung subprocess.run([sys.executable, '-c', 'import X']) — + khi app dong goi (PyInstaller frozen), sys.executable = daw_engine.exe + -> subprocess chay CA ENGINE (bootloader bo qua '-c', chay desktop_engine) + -> moi lan check lai sinh ra engine moi -> de quy spawn vo han + (Task Manager day daw_engine, port 8000-8005 leo thang, load rat cham). + find_spec() nhanh (micro-giay) va hoat dong ca source lan frozen. + """ + import importlib.util try: - res = subprocess.run( - [sys.executable, "-c", "import pedalboard"], - stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=2.0 - ) - return res.returncode == 0 - except Exception: + return importlib.util.find_spec(name) is not None + except (ImportError, AttributeError, ValueError): return False + +def check_pedalboard_safe(): + return _module_available("pedalboard") + + def check_pyfluidsynth_safe(): - import subprocess, sys - try: - res = subprocess.run( - [sys.executable, "-c", "import fluidsynth"], - stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=2.0 - ) - return res.returncode == 0 - except Exception: - return False + return _module_available("fluidsynth") HAS_PEDALBOARD = check_pedalboard_safe() HAS_PYFLUIDSYNTH = check_pyfluidsynth_safe() diff --git a/desktop_engine.py b/desktop_engine.py index 5b010b3..67938c4 100644 --- a/desktop_engine.py +++ b/desktop_engine.py @@ -52,6 +52,13 @@ def _parent_alive(pid): def main(): + # PHONG THU (fix ban 1.1.2): neu exe bi goi nhu 'python -c ...' — vd code + # cu kiem tra thu vien bang subprocess.run([sys.executable, '-c', 'import X']) + # thi frozen sys.executable = daw_engine.exe -> se chay CA ENGINE o day. + # Thoat ngay, KHONG khoi dong server, tranh de quy spawn vo han. + if len(sys.argv) > 1 and sys.argv[1] == "-c": + return + os.environ.setdefault("SF_DESKTOP", "1") # Log dir tao SOM de stderr co the tro vao file (xem duoi).