# G0.3 diagnosis: track attach_in_flight flag + writeIndex over LOAD->PLAY->OPEN_GUI->STOP. # Determines whether watchdog killed at 3s (flag not seen) or attach hung >15s (flag set). import ctypes, ctypes.wintypes as w, struct, subprocess, sys, os, time sys.stdout.reconfigure(encoding='utf-8', errors='replace') APP_PID = 9692 SHM_NAME = f"SonicForge_DAW_IPC_{APP_PID}".encode() SHM_NAME_LEGACY = b"SonicForge_DAW_IPC" 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: hMap = kernel32.OpenFileMappingA(FILE_MAP_ALL_ACCESS, False, SHM_NAME_LEGACY) name_used = SHM_NAME_LEGACY if not hMap: print(f"OpenFileMapping 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, verbose=True): end = time.time() + timeout while time.time() < end: lines = log_lines() for i in range(since, len(lines)): if pattern in lines[i]: if verbose: print(f" LOG: {lines[i].strip()}") return lines[i].strip() time.sleep(0.2) return None def bridge_pid(): try: out = subprocess.run(["cmd", "/c", "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 OFF_ATTACH = 11160 # attach_in_flight (u32, appended after control_queue_count @11156) OFF_WRITE = 4 # bridge_write_index since = len(log_lines()) push_controls([(2, 0, 0, ch, NEXUS) for ch in range(6)] + [(2, 0, 0, 6, EZKEYS)]) print("pushed LOAD x7; waiting...") for ch in range(7): r = wait_log(f"instrument loaded ch={ch}", 60, since) print(f" ch={ch}: {'loaded' if r else 'TIMEOUT'}") since = len(log_lines()) push_controls([(3, 1, 0, 0, "")]) wait_log("transport PLAY", 10, since) since = len(log_lines()) push_controls([(4, 0, 0, 5, "Nexus")]) wait_log("GUI deferred ch=5", 10, since) pid0 = bridge_pid() print(f"bridge pid before STOP: {pid0}") # STOP then track writeIndex + attach flag every 100ms for 40s since = len(log_lines()) push_controls([(3, 0, 0, 0, "")]) wait_log("transport STOP", 10, since) print(f"{'t(s)':>5} {'wIdx':>8} {'attach':>6} events") t0 = time.time() last_w = rd32(OFF_WRITE) stall_t = None attached_seen = False end = time.time() + 40 while time.time() < end: w = rd32(OFF_WRITE) a = rd32(OFF_ATTACH) t = time.time() - t0 if w != last_w: if stall_t is not None: print(f"{t:5.1f} {w:8d} {a:6d} writeIndex resumed after {t - stall_t:.1f}s stall") stall_t = None last_w = w else: if stall_t is None: stall_t = t print(f"{t:5.1f} {w:8d} {a:6d} WRITEINDEX STALL START") if a == 1 and (not hasattr(sys, '_a_was')): print(f"{t:5.1f} {w:8d} {a:6d} attach_in_flight SET") if a == 0 and stall_t is not None and not attached_seen: pass # log check for l in log_lines()[since:]: if "GUI attached hwnd=" in l and not attached_seen: attached_seen = True print(f"{t:5.1f} --- GUI ATTACHED: {l.strip()}") if "bridge restarted" in l: print(f"{t:5.1f} --- BRIDGE RESTARTED IN LOG") pid = bridge_pid() if pid != pid0: print(f"{t:5.1f} --- BRIDGE PID CHANGED {pid0}->{pid}") break time.sleep(0.1) print("done. final attach_in_flight =", rd32(OFF_ATTACH), " writeIndex =", rd32(OFF_WRITE))