M5: capture editor state -> preset_b64 khi đóng GUI native (JuceFxLoop ghi <job>.preset.json + /fx-gui/close poll)
This commit is contained in:
@@ -834,8 +834,13 @@ async def close_fx_gui(req: FxGuiCloseRequest, current_user: dict = Depends(get_
|
||||
fx_realtime.editor_unregister(plugin_path)
|
||||
_sess = fx_realtime.get_session(_sid)
|
||||
if _sess is not None and _sess.alive():
|
||||
# M5: capture state editor TRƯỚC khi đóng (preset user chỉnh trong
|
||||
# GUI → lưu về project như WM_FXGUI_CAPTURE cũ; preset_b64 dùng để
|
||||
# mở lại GUI / nạp chain với đúng cài đặt). Không lỗi nếu rỗng.
|
||||
_preset = _sess.capture_editor_preset(_slot)
|
||||
_sess.send_editor_cmd("close", slot=_slot)
|
||||
return {"success": True, "closed": True, "native": True}
|
||||
return {"success": True, "closed": True, "native": True,
|
||||
"preset_b64": _preset}
|
||||
# session đã chết — rơi xuống spawn fallback (đóng bridge fx-gui cũ nếu có)
|
||||
for proc in _FX_GUI_PROCESSES:
|
||||
if proc is not None and proc.poll() is None and getattr(proc, "_sf_plugin_path", None) == plugin_path:
|
||||
|
||||
@@ -484,6 +484,39 @@ class FxRealtimeSession:
|
||||
return i
|
||||
return None
|
||||
|
||||
def capture_editor_preset(self, slot, timeout=3.0):
|
||||
"""M5: capture state editor của CHÍNH instance DSP (ed.capture) → C++
|
||||
ghi file JSON cạnh job: <jobPath>.preset.json {slot, preset_b64} (xem
|
||||
JuceFxLoop.cpp) → đọc + xoá file → trả preset_b64 ("" nếu plugin không
|
||||
có state / bridge chết / timeout). Không cần editor đang mở — state
|
||||
đọc từ processor sống trong graph; gọi TRƯỚC ed.close khi đóng GUI."""
|
||||
cap_path = (self._job_path or "") + ".preset.json"
|
||||
if cap_path and os.path.exists(cap_path):
|
||||
try:
|
||||
os.remove(cap_path)
|
||||
except Exception:
|
||||
pass
|
||||
if not self.send_editor_cmd("capture", slot=slot):
|
||||
return ""
|
||||
deadline = time.time() + timeout
|
||||
while time.time() < deadline:
|
||||
if not self.alive():
|
||||
return ""
|
||||
if cap_path and os.path.exists(cap_path):
|
||||
try:
|
||||
with open(cap_path, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
os.remove(cap_path)
|
||||
return data.get("preset_b64", "")
|
||||
except Exception:
|
||||
try:
|
||||
os.remove(cap_path)
|
||||
except Exception:
|
||||
pass
|
||||
return ""
|
||||
time.sleep(0.05)
|
||||
return ""
|
||||
|
||||
def _watch_loop(self):
|
||||
"""M4.5 watchdog — thread riêng (ngoài audio). Proc chết ngoài ý muốn
|
||||
(crash view/plugin/loop) → AUTO restart tối đa FXRT_MAX_RESTARTS lần,
|
||||
|
||||
Reference in New Issue
Block a user