M5: capture editor state -> preset_b64 khi đóng GUI native (JuceFxLoop ghi <job>.preset.json + /fx-gui/close poll)

This commit is contained in:
2026-09-04 11:49:42 +07:00
parent 14fd794e6d
commit 014b9ac460
3 changed files with 88 additions and 1 deletions
+33
View File
@@ -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,