phase4: Linux native_bridge build (Docker) — sfizz from source, --render SF2/SFZ

- Dockerfile: build sfizz tu native_bridge/sfizz-src (hoac git clone v1.2.3),
  sed fix sfizz.pc (-llibsfizz -> -lsfizz), cmake bridge voi 3 flag SMTG OFF
  (VSTGUI/plugin/hosting examples) — bridge headless chi can --render.
- CMakeLists: nhanh non-WIN32 build daw_vst_bridge tu main_linux.cpp +
  RenderJob.cpp + NativeInstrumentEngine.cpp (SF2/SF3 + SFZ; VST3/VST2
  hosting Windows-only, guard #ifdef _WIN32). gui_probe/plugin_host/
  seh_channel_test chi build tren Windows.
- RenderJob.cpp: JSON parser (sheredom json.h) khong con phu thuoc
  HAVE_VST3SDK — render SF2/SFZ chay duoc khong can VST3 SDK.
- NativeInstrumentEngine.cpp: guard windows.h/VST3/VST2/Sandbox/SEH.
- main.cpp: g_engine unconditional + guard disable_ime_contexts (_WIN32).
- engine.spec: bo pedalboard collect_dynamic_libs + hidden imports.
- vst_engine/render_engine: DecentSampler -> NotImplementedError + huong
  dan convert .dspreset -> .vstpreset; pianobook fallback synth.
- Verified: WSL Ubuntu 24.04 build OK, bridge Linux --render SF2 ra WAV
  44100 stereo peak 1575; Python tests 115 passed 1 skipped.
- Dockerfile build chua test duoc (may khong co Docker).
This commit is contained in:
2026-08-17 11:46:24 +07:00
parent efe26e3277
commit e79dae5d5c
10 changed files with 135 additions and 71 deletions
+9 -29
View File
@@ -7,7 +7,6 @@ from app.config import settings
from app.core.vst_engine import (
render_midi_events_to_audio,
PluginManager,
DecentSamplerManager,
HAS_PEDALBOARD,
HAS_PYFLUIDSYNTH,
apply_preset_to_plugin,
@@ -204,35 +203,16 @@ class PythonRenderEngine:
vst = plugin_mgr.load_vst(instrument_id) if instrument_id else None
if instrument_source == "pianobook":
# Phase 4 (§3.4): .dspreset không hỗ trợ nữa (pedalboard
# GPL-3.0 gỡ; spike load .dspreset fail). Chặn + fallback synth.
dspreset_path = track.get("dspreset_path", "")
if dspreset_path and os.path.exists(dspreset_path) and HAS_PEDALBOARD:
from pedalboard import Pedalboard
ds_manager = DecentSamplerManager()
try:
vst = ds_manager.create_decent_sampler_instance(dspreset_path)
midi_messages = PluginManager.midi_events_to_messages(
midi_events, bpm, self.sample_rate
)
total_needed = 0
for ev in midi_events:
end_sec = (ev.get("start_beat", 0) + ev.get("duration_beats", 1)) * (60.0 / bpm)
dur_samples = int(end_sec * self.sample_rate)
if dur_samples > total_needed:
total_needed = dur_samples
total_needed = max(total_needed, 1024)
silent = np.zeros((2, total_needed), dtype=np.float32)
# pedalboard >= 0.9: instrument KHÔNG vào Pedalboard container
synth_buffer = vst(midi_messages, sample_rate=self.sample_rate,
duration=total_needed / float(self.sample_rate), num_channels=2)
except Exception as e:
logger.warning(f"[RenderEngine] DecentSampler/Pianobook error: {e}")
synth_buffer = render_midi_events_to_audio(
midi_events=midi_events, sr=self.sample_rate, bpm=bpm, instrument='synth'
)
else:
synth_buffer = render_midi_events_to_audio(
midi_events=midi_events, sr=self.sample_rate, bpm=bpm, instrument='synth'
)
logger.warning(
"[RenderEngine] Pianobook track bỏ qua: .dspreset không còn hỗ trợ. "
"Convert sang .vstpreset (DecentSampler → Save preset) rồi gán lại track."
)
synth_buffer = render_midi_events_to_audio(
midi_events=midi_events, sr=self.sample_rate, bpm=bpm, instrument='synth'
)
elif instrument_id and not instrument_id.startswith("sf_"):
# VSTi track: native_bridge --render (SF_RENDER_ENGINE=bridge)
# thay pedalboard; ngược lại giữ pedalboard path cũ.
+9 -19
View File
@@ -521,25 +521,15 @@ class DecentSamplerManager:
self.vst_path = vst_path
def create_decent_sampler_instance(self, dspreset_path: str):
if not HAS_PEDALBOARD:
raise RuntimeError("pedalboard not available")
if not os.path.exists(self.vst_path):
raise FileNotFoundError(f"DecentSampler VST3 not found at {self.vst_path}")
if not os.path.exists(dspreset_path):
raise FileNotFoundError(f"Preset file not found at {dspreset_path}")
plugin = VST3Plugin(self.vst_path)
abs_preset = os.path.abspath(dspreset_path)
preset_dir = os.path.dirname(abs_preset)
cwd_before = os.getcwd()
try:
os.chdir(preset_dir)
plugin.load_preset(abs_preset)
finally:
os.chdir(cwd_before)
return plugin
# Phase 4 (PLAN_REPLACE_PEDALBOARD_NATIVE_BRIDGE.md §3.4): .dspreset là
# format riêng của DecentSampler (không phải VST3 state) — spike đã fail
# cả trên pedalboard (container: "failed to load data from preset file").
# pedalboard GPL-3.0 bị gỡ → chặn Pianobook + hướng dẫn convert.
raise NotImplementedError(
"Pianobook .dspreset không còn được hỗ trợ (pedalboard GPL-3.0 đã gỡ). "
"Chuyển đổi: mở preset trong DecentSampler → save .vstpreset (VST3 state) "
"rồi upload .vstpreset qua web UI — native_bridge đọc được."
)
# ── Preset bridge (Carla ↔ pedalboard) ─────────────────────────────────────