From 979e89e3052bba554d199752cb528084883f608e Mon Sep 17 00:00:00 2001 From: David Gwilliam Date: Wed, 24 Jun 2026 04:07:17 -0700 Subject: [PATCH] fix indentation and debug: add pipeline counters --- scripts/led-matrix-viz.py | 56 +++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/scripts/led-matrix-viz.py b/scripts/led-matrix-viz.py index a67deca..df08159 100644 --- a/scripts/led-matrix-viz.py +++ b/scripts/led-matrix-viz.py @@ -82,6 +82,9 @@ def main(): fps_sample_frames = 0 events_processed = 0 raw_packets = 0 + semicolon_hits = 0 + midi_matched = 0 + changed_true = 0 while True: now = time.monotonic() @@ -104,37 +107,41 @@ def main(): pass while b";" in buf: + semicolon_hits += 1 raw_msg, buf = buf.split(b";", 1) msg = raw_msg.decode().strip() parts = msg.split() if not parts: + print(f"[viz] empty parts: {msg!r}", flush=True) continue if parts[0] != "midi": - print(f"[viz] skipping: {msg!r}", flush=True) + print(f"[viz] not midi: {msg!r}", flush=True) continue if len(parts) < 3: print(f"[viz] too short: {parts}", flush=True) continue - status = int(parts[1]) - note = int(parts[2]) - vel = int(parts[3]) if len(parts) >= 4 else 0 - msg_type = status & 0xF0 - changed = False - if msg_type == 0x90 and vel > 0: - if note not in active_notes: - active_notes.add(note) - changed = True - elif msg_type == 0x80 or (msg_type == 0x90 and vel == 0): - if note in active_notes: - active_notes.discard(note) - changed = True - if changed: - events_processed += 1 - params = render(active_notes) - if params != last_sent_params: - msg_id = (msg_id + 1) % 65535 - pending_bytes = packer.pack([0, msg_id, "draw_frame", params]) - last_sent_params = params + midi_matched += 1 + status = int(parts[1]) + note = int(parts[2]) + vel = int(parts[3]) if len(parts) >= 4 else 0 + msg_type = status & 0xF0 + changed = False + if msg_type == 0x90 and vel > 0: + if note not in active_notes: + active_notes.add(note) + changed = True + elif msg_type == 0x80 or (msg_type == 0x90 and vel == 0): + if note in active_notes: + active_notes.discard(note) + changed = True + if changed: + changed_true += 1 + events_processed += 1 + params = render(active_notes) + if params != last_sent_params: + msg_id = (msg_id + 1) % 65535 + pending_bytes = packer.pack([0, msg_id, "draw_frame", params]) + last_sent_params = params # Try to send pending frame — no POLLOUT dependency if pending_bytes is not None: @@ -160,14 +167,14 @@ def main(): if now - stats_last_write >= 2.0: fps = fps_sample_frames / (now - fps_sample_start) if (now - fps_sample_start) > 0 else 0 - _write_stats(frames_sent, frames_dropped, fps, len(active_notes), events_processed, bytes_received, raw_packets) + _write_stats(frames_sent, frames_dropped, fps, len(active_notes), events_processed, bytes_received, raw_packets, semicolon_hits, midi_matched, changed_true) stats_last_write = now fps_sample_start = now fps_sample_frames = 0 events_processed = 0 -def _write_stats(sent, dropped, fps, active_count, events, bytes_rcv, packets): +def _write_stats(sent, dropped, fps, active_count, events, bytes_rcv, packets, semi, matched, changed): import json try: with open(STATS_FILE, "w") as f: @@ -179,6 +186,9 @@ def _write_stats(sent, dropped, fps, active_count, events, bytes_rcv, packets): "midi_events": events, "bytes_received": bytes_rcv, "raw_packets": packets, + "semicolon_hits": semi, + "midi_matched": matched, + "changed_true": changed, "ts": time.time() }, f) except OSError: