0ddf350f1f
Lyrebird 2.0 moved `@UIParam` / `UIParamNode` out of `LyrebirdUI` into the core `LyrebirdSynth` module (the `Lyrebird` product); `LyrebirdUI` no longer re-exports them. Migrate: - add `import LyrebirdSynth` to every file that uses `@UIParam`/`UIParamNode` (the pedal controls, tempo-syncable params, and the SwiftUI views). - Package.swift: the `LyrebirdShoeGazeUI` target now also depends on the `Lyrebird` product (previously only `LyrebirdUI`), so `import LyrebirdSynth` resolves there under explicit module maps. - Package.resolved (SwiftPM + both Xcode projects) pinned to Lyrebird 2.0.0. Also: app marketing/project version bumps, Xcode upgrade-check, and a CHANGELOG wording tweak carried in the same working tree. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
108 lines
3.8 KiB
Swift
108 lines
3.8 KiB
Swift
// PedalButtonView.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import SwiftUI
|
|
import LyrebirdUI
|
|
import LyrebirdShoeGaze
|
|
import LyrebirdSynth
|
|
|
|
// MARK: - PedalButtonView
|
|
|
|
/// A stomp-style action button rendered from a ``PedalButton`` descriptor.
|
|
///
|
|
/// `.momentary` renders a plain `ParameterButton`. `.toggle` renders the same LED +
|
|
/// footswitch look as the pedal's own bypass control (`PedalView`'s `LEDIndicator` /
|
|
/// `FootswitchButton`), with a caption label beneath — so a looper's Overdub/Loop toggles
|
|
/// read as stomp switches with state, not a segmented picker.
|
|
///
|
|
/// ## Usage
|
|
/// ```swift
|
|
/// PedalButtonView(pedalButton)
|
|
/// ```
|
|
public struct PedalButtonView: View {
|
|
|
|
private static let toggleOnThreshold: Double = 0.5
|
|
private static let sectionSpacing: CGFloat = 6
|
|
private static let captionFontSize: CGFloat = 11
|
|
|
|
private let pedalButton: PedalButton
|
|
|
|
/// Creates a button view from a descriptor.
|
|
///
|
|
/// - Parameter pedalButton: The button to render.
|
|
public init(_ pedalButton: PedalButton) {
|
|
self.pedalButton = pedalButton
|
|
}
|
|
|
|
public var body: some View {
|
|
switch pedalButton.style {
|
|
case .momentary:
|
|
if let indicator: UIParamNode = pedalButton.indicator {
|
|
// LED + footswitch, same look as a toggle, but the press runs an action and the
|
|
// LED reflects a separate state node (e.g. Stop lit while stopped). Reading
|
|
// `indicator.value` registers this view for @Observable re-render.
|
|
let isOn: Bool = indicator.value >= PedalButtonView.toggleOnThreshold
|
|
VStack(spacing: PedalButtonView.sectionSpacing) {
|
|
LEDIndicator(isOn: isOn)
|
|
FootswitchButton(action: pedalButton.action ?? {})
|
|
caption
|
|
}
|
|
} else {
|
|
ParameterButton(pedalButton.label, action: pedalButton.action ?? {})
|
|
}
|
|
case .toggle:
|
|
if let node: UIParamNode = pedalButton.node {
|
|
// Reading `node.value` registers this view for @Observable re-render.
|
|
let isOn: Bool = node.value >= PedalButtonView.toggleOnThreshold
|
|
VStack(spacing: PedalButtonView.sectionSpacing) {
|
|
LEDIndicator(isOn: isOn)
|
|
FootswitchButton(node: node)
|
|
caption
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// The button caption — a live "what the next press does" label when the descriptor supplies
|
|
/// a `dynamicLabel`, otherwise the static label.
|
|
@ViewBuilder
|
|
private var caption: some View {
|
|
if let provider: () -> String = pedalButton.dynamicLabel {
|
|
DynamicCaption(provider: provider, fallback: pedalButton.label)
|
|
.font(.system(size: PedalButtonView.captionFontSize))
|
|
.foregroundStyle(Color.white)
|
|
} else {
|
|
Text(pedalButton.label)
|
|
.font(.system(size: PedalButtonView.captionFontSize))
|
|
.foregroundStyle(Color.white)
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - DynamicCaption
|
|
|
|
/// A caption that polls a text provider (RT-adjacent pedal state that isn't `@Observable`), on
|
|
/// the same `.task` cadence as the looper timeline, so a state-driven button label stays current.
|
|
private struct DynamicCaption: View {
|
|
|
|
private static let pollIntervalNanoseconds: UInt64 = 33_000_000 // ~30 Hz
|
|
|
|
let provider: () -> String
|
|
let fallback: String
|
|
|
|
@State private var text: String = ""
|
|
|
|
var body: some View {
|
|
Text(text.isEmpty ? fallback : text)
|
|
.task {
|
|
while !Task.isCancelled {
|
|
text = provider()
|
|
try? await Task.sleep(nanoseconds: DynamicCaption.pollIntervalNanoseconds)
|
|
}
|
|
}
|
|
}
|
|
}
|