83b8fff74b
Phase-lock: reset the overdub recorder write heads (requestReset) and the player play-heads (playTrigger rising edge) synchronously in startPlayback so both re-anchor on the same audio block, instead of deferring the trigger an extra run-loop turn; playTrigger is zeroed on every stop for a clean 0→1 edge. This also makes overdub actually record under NRT. Reverse vs overdub: overdub records forward-in-time and can't follow a reversed play-head. Block engaging overdub while reversed, and make Reverse a toggleReverse() action that ends any active overdub when engaging reverse (the footswitch keeps its LED via indicator: $reverse). resetLoop: gate isPlaying off before clear() so the buffer-clear overlaps at most one in-flight RT block; corrected the rationale comment. Docs: fix stale $overdubOn / .empty / .recording references. Tests: overdubbingTrackAAddsEnergyToTheLoop (NRT overdub records), overdubBlockedWhileReversed, engagingReverseWhileOverdubbingEndsOverdub. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
96 lines
4.0 KiB
Swift
96 lines
4.0 KiB
Swift
// PedalButton.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import LyrebirdUI
|
|
|
|
/// A UI-agnostic description of one pedal button — a momentary action trigger or a
|
|
/// node-bound toggle, rendered as a stomp-style button.
|
|
///
|
|
/// Where ``PedalSwitch`` describes a multi-position segmented control, `PedalButton`
|
|
/// describes a single button in one of two styles:
|
|
/// - `.momentary`: runs a closure on each press (e.g. "Record / Stop", "Reset"). Use this
|
|
/// whenever pressing the button must also perform a non-RT side effect (clearing a
|
|
/// buffer, requesting a recorder reset) beyond writing a single parameter value.
|
|
/// - `.toggle`: flips a bound ``UIParamNode`` between `0` and `1` on each press, with no
|
|
/// side effect required — appropriate only when the live audio graph itself reads the
|
|
/// node continuously (so toggling the raw value is sufficient).
|
|
///
|
|
/// A `Pedal` publishes an array of these via ``Pedal/effectButtons`` so a generic
|
|
/// pedalboard UI can render a footswitch-style button per action without knowing the
|
|
/// concrete pedal type.
|
|
public struct PedalButton {
|
|
|
|
/// Style of button behavior, mirroring `ParameterButton.Style` in `LyrebirdUI`.
|
|
public enum Style: Equatable {
|
|
/// Executes `action` on each press.
|
|
case momentary
|
|
/// Flips `node` between `0` and `1` on each press.
|
|
case toggle
|
|
}
|
|
|
|
/// Short label shown on the button (e.g. "Record", "Reset").
|
|
public let label: String
|
|
|
|
/// Button behavior style.
|
|
public let style: Style
|
|
|
|
/// The live parameter node this button toggles. Non-`nil` only for `.toggle` style.
|
|
public let node: UIParamNode?
|
|
|
|
/// The action run on each press. Non-`nil` only for `.momentary` style.
|
|
public let action: (() -> Void)?
|
|
|
|
/// Optional LED-indicator node for a `.momentary` button. When non-`nil`, the button is
|
|
/// drawn in the same LED + footswitch style as a `.toggle` button, with the LED lit while
|
|
/// this node reads `≥ 0.5` — letting a momentary action reflect a persistent state (e.g. a
|
|
/// looper's Stop lit while stopped, Cue Stop lit while armed). `nil` renders a plain button.
|
|
public let indicator: UIParamNode?
|
|
|
|
/// Optional live caption describing what the *next* press does, polled by the UI. When set,
|
|
/// the button shows this instead of the static `label` — letting a state-driven control (the
|
|
/// looper's Loop footswitch) read "Record" → "Set End" → "Overdub" → "Play" as the state
|
|
/// changes. `nil` shows the static `label`.
|
|
public let dynamicLabel: (() -> String)?
|
|
|
|
/// Creates a momentary action button.
|
|
///
|
|
/// - Parameters:
|
|
/// - label: Short label shown on the button.
|
|
/// - indicator: Optional state node driving an LED (see ``indicator``). Defaults to `nil`
|
|
/// for a plain button.
|
|
/// - dynamicLabel: Optional live caption describing the next press (see ``dynamicLabel``).
|
|
/// - action: Closure run on each press.
|
|
public init(
|
|
label: String,
|
|
indicator: UIParamNode? = nil,
|
|
dynamicLabel: (() -> String)? = nil,
|
|
action: @escaping () -> Void
|
|
) {
|
|
self.label = label
|
|
self.style = .momentary
|
|
self.node = nil
|
|
self.action = action
|
|
self.indicator = indicator
|
|
self.dynamicLabel = dynamicLabel
|
|
}
|
|
|
|
/// Creates a toggle button bound to a `UIParamNode`.
|
|
///
|
|
/// - Parameters:
|
|
/// - label: Short label shown on the button.
|
|
/// - node: The `UIParamNode` projected value of an `@UIParam` property
|
|
/// (`pedal.$loopOn`, `pedal.$reverse`, …).
|
|
/// - dynamicLabel: Optional live caption describing the next press (see ``dynamicLabel``).
|
|
public init(label: String, node: UIParamNode, dynamicLabel: (() -> String)? = nil) {
|
|
self.label = label
|
|
self.style = .toggle
|
|
self.node = node
|
|
self.action = nil
|
|
self.indicator = nil
|
|
self.dynamicLabel = dynamicLabel
|
|
}
|
|
}
|