From 2ce6dda9dac830608f9bc53591f506d6c0242873 Mon Sep 17 00:00:00 2001 From: Joshua Parmenter Date: Fri, 3 Jul 2026 22:17:40 -0700 Subject: [PATCH] Looper UI: re-subscribe polls when the pedal instance changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The looper timeline and the transport buttons' live captions poll the pedal via SwiftUI `.task`, which captures the pedal at task-start and never re-subscribes. When a rig load swaps in a new LooperPedal instance, the buttons/LEDs (read live in `body`) tracked the new pedal while the polled state text and captions stayed frozen on the old one — the state indicator and "Record/Set End/…" captions never updated even though transport worked. Key the timeline poll on ObjectIdentifier(pedal) (`.task(id:)`) and tag the transport button row with `.id(ObjectIdentifier(pedal))`, so both re-subscribe to the current instance. Board edits reuse the same instance (identity stable), so this only refreshes on an actual instance swap — no per-render churn. Co-Authored-By: Claude Opus 4.8 --- Sources/LyrebirdShoeGazeUI/LooperTimelineView.swift | 4 +++- Sources/LyrebirdShoeGazeUI/PedalView.swift | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/LyrebirdShoeGazeUI/LooperTimelineView.swift b/Sources/LyrebirdShoeGazeUI/LooperTimelineView.swift index 7935089..b90bc06 100644 --- a/Sources/LyrebirdShoeGazeUI/LooperTimelineView.swift +++ b/Sources/LyrebirdShoeGazeUI/LooperTimelineView.swift @@ -78,7 +78,9 @@ struct LooperTimelineView: View { track stateIndicator } - .task { + // Key the poll on the pedal instance: if a rig load / rebuild swaps in a new LooperPedal, + // `.task` alone would keep polling the old (captured) instance and freeze. Restart on change. + .task(id: ObjectIdentifier(pedal)) { while !Task.isCancelled { position = pedal.playbackPosition01() state = pedal.transportState diff --git a/Sources/LyrebirdShoeGazeUI/PedalView.swift b/Sources/LyrebirdShoeGazeUI/PedalView.swift index 0f69aa4..972dc69 100644 --- a/Sources/LyrebirdShoeGazeUI/PedalView.swift +++ b/Sources/LyrebirdShoeGazeUI/PedalView.swift @@ -309,7 +309,10 @@ public struct PedalView: View { knobGrid selectorRow switchRow + // Keyed on the pedal instance so the buttons' live captions (which poll the pedal + // via `.task`) re-subscribe when a rig load / rebuild swaps in a new pedal instance. transportButtonRow + .id(ObjectIdentifier(pedal)) buttonRow sliderBank(sliders) Spacer(minLength: 0)