import io p = r"C:/Users/locpham/SonicForgeStudio/native_bridge/src/NativeInstrumentEngine.cpp" with io.open(p, "r", encoding="utf-8-sig", newline="") as f: s = f.read() old = """ const float kCeilingPeak = 0.7071f; // -3 dBFS const float kAttack = 0.9f; // chặt: sample dau keo ve tran ~90% (tran 0.4 de lo qua -3 dBFS) const float kRelease = 0.0006f;""" new = """ const float kCeilingPeak = 0.7071f; // -3 dBFS // Attack 0.9 (near-instant) caused zipper crackle: nhieu track sum ~2.0, // target 0.35 -> gain 1.0->0.42 trong 1 sample = step -7.6 dB moi transient. // 0.1 = ~10 samples (0.2ms @48k) ve tran: smooth, van giu ceiling -3 dBFS. const float kAttack = 0.1f; const float kRelease = 0.0006f;""" assert s.count(old) == 1, "pattern not found: %d" % s.count(old) s = s.replace(old, new) with io.open(p, "w", encoding="utf-8-sig", newline="") as f: f.write(s) print("patched OK")