FEAT: cài đặt các thư viện để chuẩn bị build exe trên window

This commit is contained in:
2026-08-08 08:46:15 +07:00
parent 9ef622f29a
commit 029ed1c456
24 changed files with 575 additions and 13 deletions
+3 -1
View File
@@ -105,6 +105,7 @@ class PythonRenderEngine:
# Parse synth_engine struct (Task C) — fall back to flat fields
se = track.get("synth_engine", {}) or {}
instrument_id = se.get("plugin_id") or track.get("instrument_id", "") or track.get("instrument", "")
vst_path = se.get("plugin_path") or "" # spec desktop: load VST3 từ plugin_path
instrument_source = se.get("type") or track.get("instrument_source", "soundfont")
soundfont_bank = se.get("soundfont_bank") if se.get("soundfont_bank") is not None else track.get("soundfont_bank", 0)
soundfont_program = se.get("soundfont_program") if se.get("soundfont_program") is not None else track.get("soundfont_program", 0)
@@ -189,7 +190,8 @@ class PythonRenderEngine:
if midi_events:
try:
plugin_mgr = PluginManager()
vst = plugin_mgr.load_vst(instrument_id) if instrument_id else None
# Ưu tiên plugin_path (spec desktop) — fallback plugin_id theo tên
vst = plugin_mgr.load_vst(vst_path or instrument_id) if (vst_path or instrument_id) else None
if instrument_source == "pianobook":
dspreset_path = track.get("dspreset_path", "")
+16 -2
View File
@@ -216,6 +216,19 @@ class PluginManager:
def load_vst(self, plugin_name: str, preset_data: dict = None):
if not HAS_PEDALBOARD:
return None
# Ưu tiên PATH trực tiếp (spec desktop 2026-08-08: synth_engine.plugin_path)
if plugin_name and (plugin_name.endswith(".vst3") or plugin_name.endswith(".so")
or plugin_name.endswith(".component") or "/" in plugin_name or "\\" in plugin_name):
if os.path.exists(plugin_name):
vst = VST3Plugin(plugin_name)
if preset_data:
for k, v in preset_data.items():
try:
setattr(vst, k, v)
except Exception:
pass
return vst
return None
plugins = self._scan_plugins()
if plugin_name not in plugins:
return None
@@ -305,8 +318,9 @@ class PluginManager:
def list_available(self) -> dict:
return {
"vst_instruments": [
{"id": k, "name": k, "type": "VST3", "has_native_support": HAS_PEDALBOARD}
for k in self._scan_plugins().keys()
{"id": "vst3_" + k.lower().replace(" ", "_"), "name": k, "type": "VST3",
"path": p, "has_native_support": HAS_PEDALBOARD}
for k, p in self._scan_plugins().items()
],
"soundfonts": self._scan_soundfonts()
}
+86
View File
@@ -0,0 +1,86 @@
import os
import platform
import logging
from typing import List, Dict, Any
logger = logging.getLogger(__name__)
class NativePluginScanner:
"""Quét thư mục custom chứa VST3 (.vst3) / Audio Unit (.component trên macOS)
— spec DESKTOP VST (2026-08-08): POST /api/v1/desktop/plugins/scan."""
def __init__(self):
self.os_type = platform.system() # 'Linux', 'Windows', 'Darwin'
def scan_directories(self, target_paths: List[str]) -> List[Dict[str, Any]]:
found_plugins = []
seen = set()
for base_path in target_paths:
if not base_path:
continue
if not os.path.exists(base_path):
logger.warning(f"Scan path does not exist: {base_path}")
continue
for root, dirs, files in os.walk(base_path):
for dir_name in dirs:
full_path = os.path.join(root, dir_name)
# VST3 = bundle directory *.vst3
if dir_name.endswith('.vst3'):
plugin_name = dir_name[:-5]
pid = f"vst3_{plugin_name.lower().replace(' ', '_')}"
if pid in seen:
continue
seen.add(pid)
found_plugins.append({
"id": pid,
"name": plugin_name,
"type": "VST3",
"format": "VST3",
"category": "Instrument",
"vendor": self._read_vendor(full_path) or None,
"path": full_path,
"is_instrument": True,
"has_native_gui": True
})
# Audio Unit = bundle *.component (macOS only)
elif dir_name.endswith('.component') and self.os_type == 'Darwin':
plugin_name = dir_name[:-10]
pid = f"au_{plugin_name.lower().replace(' ', '_')}"
if pid in seen:
continue
seen.add(pid)
found_plugins.append({
"id": pid,
"name": plugin_name,
"type": "AU",
"format": "AudioUnit",
"category": "Instrument",
"vendor": self._read_vendor(full_path) or None,
"path": full_path,
"is_instrument": True,
"has_native_gui": True
})
return found_plugins
@staticmethod
def _read_vendor(bundle_path: str) -> str:
"""Đọc vendor từ Info.plist nếu có (macOS) — best-effort."""
try:
plist = os.path.join(bundle_path, "Contents", "Info.plist")
if os.path.exists(plist):
with open(plist, "rb") as f:
raw = f.read(65536)
import plistlib
try:
data = plistlib.loads(raw)
return data.get("CFBundleManufacturer") or data.get("NSHumanReadableCopyright")
except Exception:
return None
except Exception:
return None
return None