Files
SonicForgeStudio/native_bridge/debug/driver_once.py
T

79 lines
2.7 KiB
Python

# Driver: SF_ONCE test — bridge loads ch=5 itself BEFORE main loop.
# Driver only creates SHM + spawns bridge, waits for "GUI attached" (success)
# or hang (timeout while alive).
import ctypes, ctypes.wintypes as w, struct, subprocess, sys, os, time
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
SHM_NAME = "SonicForge_DAW_IPC_VERIFY"
SIZE = 32768
BRIDGE = r"C:\Users\locpham\SonicForgeStudio\native_bridge\build\Release\daw_vst_bridge.exe"
LOG = os.path.join(os.path.dirname(os.path.abspath(__file__)), "driver_once.log")
kernel32 = ctypes.windll.kernel32
kernel32.CreateFileMappingA.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.wintypes.DWORD, ctypes.wintypes.DWORD, ctypes.wintypes.DWORD, ctypes.c_char_p]
kernel32.CreateFileMappingA.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
INVALID_HANDLE_VALUE = ctypes.c_void_p(-1).value
PAGE_READWRITE = 0x04
FILE_MAP_ALL_ACCESS = 0xF001F
hMap = kernel32.CreateFileMappingA(INVALID_HANDLE_VALUE, None, PAGE_READWRITE, 0, SIZE, SHM_NAME.encode())
ptr = kernel32.MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0)
def wait_log(pattern, timeout):
end = time.time() + timeout
last = 0
while time.time() < end:
try:
with open(LOG, 'r', encoding='utf-8', errors='replace') as f:
lines = f.readlines()
except FileNotFoundError:
lines = []
for i in range(last, len(lines)):
if pattern in lines[i]:
return lines[i].strip()
last = max(0, len(lines))
time.sleep(0.2)
return None
extra = dict(os.environ)
for k in list(extra):
if k.startswith("SF_"):
del extra[k]
extra.update({
"SF_SHM_NAME": SHM_NAME,
# SF_PARENT_PID omitted: parent watchdog off (isolate)
"SF_SAMPLE_RATE": "48000",
"SF_BLOCK_SIZE": "256",
"SF_ONCE": "1",
"SF_AUTOGUI": "0", # ensure loop hook stays off
})
# Allow extra gates via argv[1]: e.g. "SF_NO_WD SF_NO_QTIMER SF_NO_AUDIO"
for gate in sys.argv[1:]:
k, v = gate.split("=", 1)
extra[k] = v
proc = subprocess.Popen(
[BRIDGE, "--shm", SHM_NAME],
env=extra,
stdout=open(LOG, 'wb'), stderr=subprocess.STDOUT,
)
print("bridge pid", proc.pid, "poll", proc.poll())
r = wait_log("SF_ONCE attach=", 90)
print("attach line:", r)
r2 = wait_log("GUI attached", 30)
print("gui line:", r2)
time.sleep(2)
print("FINAL alive:", proc.poll() is None)
print("--- last 30 log lines ---")
try:
with open(LOG, 'r', encoding='utf-8', errors='replace') as f:
lines = f.readlines()
for l in lines[-30:]:
print(l.rstrip())
except FileNotFoundError:
pass