Files
SonicForgeStudio/native_bridge/debug/probe_app4_live.py

133 lines
5.0 KiB
Python

# Live repro of the GUI-open bug in the RUNNING app: load 6 Nexus + EZkeys,
# transport PLAY, then OPEN_GUI ch=5 (Nexus) — exactly the frontend sequence.
# Usage: python probe_app4_live.py
import ctypes, ctypes.wintypes as w, struct, subprocess, sys, os, time, re
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
APP_PID = 22264 # sonicforge-daw.exe (SHM name is per-PID)
SHM_NAME = f"SonicForge_DAW_IPC_{APP_PID}".encode()
SHM_NAME_LEGACY = b"SonicForge_DAW_IPC" # installed build still uses legacy name
APP_LOG = os.path.join(os.environ.get('APPDATA', '.'), 'SonicForgeDAW', 'logs', 'bridge.log')
VST = r"C:\Program Files\Common Files\VST3"
NEXUS = os.path.join(VST, "Nexus.vst3")
EZKEYS = os.path.join(VST, "Toontrack", "EZkeys 2.vst3")
kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
kernel32.OpenFileMappingA.argtypes = [ctypes.wintypes.DWORD, w.BOOL, ctypes.c_char_p]
kernel32.OpenFileMappingA.restype = ctypes.c_void_p
kernel32.MapViewOfFile.argtypes = [ctypes.c_void_p, ctypes.wintypes.DWORD, ctypes.wintypes.DWORD, ctypes.wintypes.DWORD, ctypes.c_size_t]
kernel32.MapViewOfFile.restype = ctypes.c_void_p
FILE_MAP_ALL_ACCESS = 0xF001F
hMap = kernel32.OpenFileMappingA(FILE_MAP_ALL_ACCESS, False, SHM_NAME)
name_used = SHM_NAME
if not hMap:
print(f"OpenFileMapping({SHM_NAME}) failed err={ctypes.get_last_error()}, trying legacy...")
hMap = kernel32.OpenFileMappingA(FILE_MAP_ALL_ACCESS, False, SHM_NAME_LEGACY)
name_used = SHM_NAME_LEGACY
if not hMap:
print(f"OpenFileMapping({SHM_NAME_LEGACY}) failed err={ctypes.get_last_error()}")
sys.exit(1)
ptr = kernel32.MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0)
if not ptr:
print("MapViewOfFile failed", ctypes.get_last_error()); sys.exit(1)
print(f"SHM {name_used} mapped")
def w32(off, fmt, *args):
ctypes.memmove(ptr + off, struct.pack(fmt, *args), struct.calcsize(fmt))
def rd32(off):
return ctypes.c_uint32.from_address(ptr + off).value
def write_control(ctype, arg0, arg1, ch, path):
for i in range(8):
off = 2836 + i * 1040
if rd32(off) == 0:
w32(off, 'IIII', ctype, arg0, arg1, ch)
if path:
b = path.encode('utf-8')[:1023] + b'\x00'
ctypes.memmove(ptr + off + 16, b, len(b))
return i
raise RuntimeError("control queue full")
def push_controls(events):
for i in range(8):
w32(2836 + i * 1040, 'I', 0)
for (ctype, arg0, arg1, ch, path) in events:
write_control(ctype, arg0, arg1, ch, path)
w32(11156, 'I', len(events))
def log_lines():
try:
with open(APP_LOG, 'r', encoding='utf-8', errors='replace') as f:
return f.readlines()
except FileNotFoundError:
return []
def wait_log(pattern, timeout, since):
end = time.time() + timeout
while time.time() < end:
lines = log_lines()
for i in range(since, len(lines)):
if pattern in lines[i]:
return lines[i].strip()
time.sleep(0.2)
return None
def bridge_pid():
try:
out = subprocess.run(["tasklist", "/FI", "IMAGENAME eq daw_vst_bridge.exe", "/FO", "CSV"],
capture_output=True, text=True).stdout
for line in out.splitlines()[1:]:
if "daw_vst_bridge" in line:
return line.split(',')[1].strip('"')
except Exception:
pass
return None
# 1) LOAD 6 Nexus ch0-5 + EZkeys ch6 (restore session state after bridge restart)
since = len(log_lines())
evs = [(2, 0, 0, ch, NEXUS) for ch in range(6)] + [(2, 0, 0, 6, EZKEYS)]
push_controls(evs)
print("pushed LOAD x7; waiting for instruments...")
loaded = []
for ch in range(7):
r = wait_log(f"instrument loaded ch={ch}", 60, since)
loaded.append(r or "TIMEOUT")
print(f" ch={ch}: {('loaded' if r else 'TIMEOUT')}")
# 2) TRANSPORT PLAY
since = len(log_lines())
push_controls([(3, 1, 0, 0, "")])
r = wait_log("transport PLAY", 10, since)
print("transport:", r or "TIMEOUT")
# 3) OPEN_GUI ch=5 (Nexus) while playing — same args as frontend open_vst_gui
since = len(log_lines())
push_controls([(4, 0, 0, 5, "Nexus")])
print("pushed OPEN_GUI ch=5 plugin=Nexus; watching 40s...")
pid0 = bridge_pid()
t0 = time.time()
wi0 = rd32(4)
last_wi, last_t = wi0, t0
stall_started = None
events = []
while time.time() - t0 < 40:
wi = rd32(4)
if wi != last_wi:
last_wi, last_t = wi, time.time()
stall_started = None
elif stall_started is None and time.time() - last_t > 3.0:
stall_started = time.time() - last_t
print(f" [{time.time()-t0:.1f}s] bridge_write_index STALL {wi} since +{time.time()-last_t:.1f}s")
pid = bridge_pid()
if pid and pid != pid0:
print(f" [{time.time()-t0:.1f}s] BRIDGE RESTARTED pid {pid0} -> {pid}")
pid0 = pid
lines = log_lines()
for i in range(since, len(lines)):
l = lines[i].strip()
if any(k in l for k in ("EXCEPTION", "FAILED", "attached", "deferred", "restarted", "Starting DAW")):
print(f" [{time.time()-t0:.1f}s] LOG: {l}")
time.sleep(0.2)
print("done. write_index advanced:", last_wi, ">", wi0)