"""Native ringside overlay and small, original synthesized reaction sounds.""" import math from pathlib import Path import struct import wave from PyQt6.QtCore import Qt, QTimer, QPropertyAnimation, QVariantAnimation, QPoint, QEasingCurve, QEvent from PyQt6.QtGui import QPainter, QPainterPath, QFont, QColor, QPen, QLinearGradient, QTransform from PyQt6.QtWidgets import QApplication, QWidget, QFrame, QLabel, QHBoxLayout, QVBoxLayout REACTIONS = { "ko": ("K.O.", "That's a wrap.", "#ff5676"), "bell": ("DING!", "Back to your corners.", "#f5c86c"), "tap": ("TAP!", "Someone's had enough.", "#e1e1e1"), "robbery": ("ROBBERY?", "Judges, explain yourselves.", "#f5c86c"), } def write_reaction_sound(directory, kind): """Generate mono PCM once per cache directory, with no downloaded samples.""" if kind not in REACTIONS: raise ValueError("Unknown reaction") path = Path(directory) / f"{kind}.wav" if path.exists(): return path path.parent.mkdir(parents=True, exist_ok=True) rate = 22050 duration = .85 if kind == "bell" else .4 samples = bytearray() for i in range(int(rate * duration)): t = i / rate attack = min(1, t / .008) if kind == "ko": value = math.sin(2 * math.pi * (130 * t - 100 * t * t)) * math.exp(-13 * t) elif kind == "bell": value = sum(math.sin(2 * math.pi * f * t) * a for f, a in ((880, .55), (1765, .25), (2410, .12))) * math.exp(-5 * t) elif kind == "tap": pulse = t if t < .16 else t - .16 value = math.sin(2 * math.pi * 420 * pulse) * math.exp(-45 * pulse) else: value = math.sin(2 * math.pi * 145 * t) * math.sin(2 * math.pi * 22 * t) * math.exp(-8 * t) release = min(1, (duration - t) / .02) samples.extend(struct.pack("