Looper: stomp-style Reset button; reset on engine stop
Reset now renders as an LED + footswitch like the other transport buttons — its LED lights whenever there's something to reset (any non-clear state), driven off a phase didSet. Add a Pedal.engineDidStop() hook, invoked for every pedal by a new ShoeGaze.stopEngine() that the user-facing Stop control now calls (transient stop-around-rebuild sequences still call engine.stop() directly, so pedals keep state across a restart). LooperPedal overrides it to return to the clear state, post to LyrebirdMessageCenter, and briefly show "Looper reset — engine stopped." on its own card via the state indicator. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -85,6 +85,10 @@ public final class LooperPedal: Pedal {
|
||||
/// LED state for the Loop footswitch: `1` while overdubbing a track.
|
||||
@UIParam public var overdubIndicator: Double = 0.0
|
||||
|
||||
/// LED state for the Reset footswitch: `1` whenever there is something to reset (any state
|
||||
/// other than clear). Kept in sync by `phase`'s `didSet`.
|
||||
@UIParam public var resetIndicator: Double = 0.0
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
/// Number of loop tracks (A–D).
|
||||
@@ -124,7 +128,9 @@ public final class LooperPedal: Pedal {
|
||||
case stopped
|
||||
}
|
||||
|
||||
private var phase: Phase = .clear
|
||||
private var phase: Phase = .clear {
|
||||
didSet { resetIndicator = phase == .clear ? 0.0 : 1.0 }
|
||||
}
|
||||
|
||||
/// The track the Loop footswitch records / overdubs into (`0` = A).
|
||||
private var selectedTrack: Int = 0
|
||||
@@ -148,6 +154,11 @@ public final class LooperPedal: Pedal {
|
||||
private var transportRoutine: LyrebirdRoutine?
|
||||
private var stopRoutine: LyrebirdRoutine?
|
||||
|
||||
/// Transient notice shown in place of the state description for `noticeDuration` seconds.
|
||||
private var noticeText: String?
|
||||
private var noticeExpiry: Date?
|
||||
private static let noticeDuration: TimeInterval = 4.0
|
||||
|
||||
/// Monotonic action generation guarding deferred beat/stop callbacks (see the single-track
|
||||
/// history — `LyrebirdRoutine.stop()` cannot recall an already-enqueued main-thread hop).
|
||||
private(set) var transportGeneration: Int = 0
|
||||
@@ -185,7 +196,7 @@ public final class LooperPedal: Pedal {
|
||||
dynamicLabel: { [weak self] in self?.cueStopButtonCaption ?? "Cue Stop" }) { [weak self] in self?.toggleStopAtLoopEnd() },
|
||||
PedalButton(label: "Reverse", indicator: $reverse,
|
||||
dynamicLabel: { [weak self] in self?.reverseButtonCaption ?? "Reverse" }) { [weak self] in self?.toggleReverse() },
|
||||
PedalButton(label: "Reset") { [weak self] in self?.resetLoop() },
|
||||
PedalButton(label: "Reset", indicator: $resetIndicator) { [weak self] in self?.resetLoop() },
|
||||
]
|
||||
}
|
||||
|
||||
@@ -261,8 +272,12 @@ public final class LooperPedal: Pedal {
|
||||
/// Caption for the Reverse footswitch (the direction the next press switches to).
|
||||
public var reverseButtonCaption: String { reverse >= 0.5 ? "Forward" : "Reverse" }
|
||||
|
||||
/// One-line description of what the pedal is doing now, for the state indicator.
|
||||
/// One-line description of what the pedal is doing now, for the state indicator. A transient
|
||||
/// notice (e.g. the engine-stop reset) takes precedence for a few seconds.
|
||||
public var stateDescription: String {
|
||||
if let notice: String = noticeText, let expiry: Date = noticeExpiry, Date() < expiry {
|
||||
return notice
|
||||
}
|
||||
let armedSuffix: String = isStopAtLoopEndArmed ? " · stop at end" : ""
|
||||
switch phase {
|
||||
case .clear: return "Empty — record track A"
|
||||
@@ -451,6 +466,18 @@ public final class LooperPedal: Pedal {
|
||||
phase = .stopped
|
||||
}
|
||||
|
||||
/// When the engine is stopped by the user, drop any recorded loop and return to the clear
|
||||
/// state — a stopped engine can't keep a loop running, and resuming into a half-recorded take
|
||||
/// is confusing. Posts a notice to the message log and briefly on the pedal's own card.
|
||||
public override func engineDidStop() {
|
||||
guard phase != .clear else { return }
|
||||
resetLoop()
|
||||
let message: String = "Looper reset — engine stopped."
|
||||
noticeText = message
|
||||
noticeExpiry = Date().addingTimeInterval(LooperPedal.noticeDuration)
|
||||
LyrebirdMessageCenter.shared.info(message, source: displayName)
|
||||
}
|
||||
|
||||
/// Returns the pedal to the clear state: all tracks cleared, track A selected, length reset.
|
||||
/// If sound is playing it acts as an immediate stop-and-clear.
|
||||
public func resetLoop() {
|
||||
|
||||
Reference in New Issue
Block a user