Files
ShoeGaze/Sources/LyrebirdShoeGazeUI/ChainRouterView.swift
T
josh 0ddf350f1f Migrate to Lyrebird 2.0.0; app version bump
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>
2026-09-23 21:17:30 -07:00

166 lines
6.4 KiB
Swift

// ChainRouterView.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import SwiftUI
import LyrebirdUI
import LyrebirdShoeGaze
import LyrebirdSynth
/// Renders a ``ChainRouter`` as a vertical stack with transport controls, two labelled
/// board rows, and a merger + optional master-gain output stage.
///
/// Layout (top → bottom):
/// 1. **Header row** — ``SplitterView`` on the left; if `router.masterGainNode` is
/// non-nil, a "Master" ``ParameterKnob`` on the right.
/// 2. **Board A row** — label "A" followed by ``PedalBoardView`` for `router.boardA`.
/// 3. **Board B row** — label "B" followed by ``PedalBoardView`` for `router.boardB`.
/// 4. **Footer row** — ``MergerView`` for `router.merger` (shown only once finalize
/// has been called and `router.merger` is non-nil).
///
/// `merger` is optional on `ChainRouter` (nil before `finalize()`) — the footer is
/// conditionally shown so the view is usable at any lifecycle stage.
///
/// ## Usage
///
/// ```swift
/// ChainRouterView(router: chainRouter)
/// ```
public struct ChainRouterView: View {
// MARK: - Layout constants
private static let outerSpacing: CGFloat = 16
private static let headerSpacing: CGFloat = 14
private static let boardRowSpacing: CGFloat = 8
private static let boardLabelFontSize: CGFloat = 11
private static let boardLabelOpacity: Double = 0.55
private static let masterLabelFontSize: CGFloat = 11
private static let masterLabelOpacity: Double = 0.45
private static let masterKnobSpacing: CGFloat = 6
private static let footerSpacing: CGFloat = 14
private static let outerPaddingH: CGFloat = 12
private static let outerPaddingV: CGFloat = 12
private static let sectionDividerOpacity: Double = 0.12
private static let sectionDividerHeight: CGFloat = 1
/// Master gain range: 0 = silence, 1 = unity output.
private static let masterGainRange: ClosedRange<Double> = 0.0...1.0
/// Background colour for the router enclosure (darker than stage floor).
private static let backgroundRed: Double = 0.11
private static let backgroundGreen: Double = 0.10
private static let backgroundBlue: Double = 0.13
private static let backgroundCornerRadius: CGFloat = 10
private static let backgroundBorderOpacity: Double = 0.30
private static let backgroundBorderLineWidth: CGFloat = 1.0
// MARK: - Properties
private let router: ChainRouter
// MARK: - Init
/// Creates a chain router view for the given ``ChainRouter``.
///
/// - Parameter router: The `ChainRouter` to display. Board A/B pedal views, the
/// splitter mode picker, the merger mix knobs, and the optional master gain knob
/// are all derived from this instance. The view correctly handles the pre-`finalize()`
/// state where `router.merger` and `router.masterGainNode` are `nil`.
public init(router: ChainRouter) {
self.router = router
}
// MARK: - Body
public var body: some View {
VStack(alignment: .leading, spacing: ChainRouterView.outerSpacing) {
headerRow
sectionDivider
boardRow(label: "A", board: router.boardA)
sectionDivider
boardRow(label: "B", board: router.boardB)
if let builtMerger: Merger = router.merger {
sectionDivider
footerRow(merger: builtMerger)
}
}
.padding(.horizontal, ChainRouterView.outerPaddingH)
.padding(.vertical, ChainRouterView.outerPaddingV)
.background(
RoundedRectangle(cornerRadius: ChainRouterView.backgroundCornerRadius)
.fill(Color(
red: ChainRouterView.backgroundRed,
green: ChainRouterView.backgroundGreen,
blue: ChainRouterView.backgroundBlue
))
.overlay(
RoundedRectangle(cornerRadius: ChainRouterView.backgroundCornerRadius)
.stroke(
Color.white.opacity(ChainRouterView.backgroundBorderOpacity),
lineWidth: ChainRouterView.backgroundBorderLineWidth
)
)
)
}
// MARK: - Subviews
/// Top row: splitter mode selector + optional master gain knob.
private var headerRow: some View {
HStack(alignment: .top, spacing: ChainRouterView.headerSpacing) {
SplitterView(splitter: router.splitter)
Spacer()
if let masterNode: UIParamNode = router.masterGainNode {
masterKnob(node: masterNode)
}
}
}
/// Master gain knob with a small label above.
private func masterKnob(node: UIParamNode) -> some View {
VStack(spacing: ChainRouterView.masterKnobSpacing) {
Text("MASTER")
.font(.system(
size: ChainRouterView.masterLabelFontSize,
weight: .medium,
design: .monospaced
))
.foregroundStyle(Color.white.opacity(ChainRouterView.masterLabelOpacity))
ParameterKnob("Gain", node: node, range: ChainRouterView.masterGainRange)
.foregroundStyle(Color.white)
}
}
/// A labelled board row.
private func boardRow(label: String, board: PedalBoard) -> some View {
HStack(alignment: .top, spacing: ChainRouterView.boardRowSpacing) {
Text(label)
.font(.system(
size: ChainRouterView.boardLabelFontSize,
weight: .semibold,
design: .monospaced
))
.foregroundStyle(Color.white.opacity(ChainRouterView.boardLabelOpacity))
.frame(width: 14, alignment: .leading)
.padding(.top, 4) // optically align with board content
PedalBoardView(board: board)
}
}
/// Footer row with merger mix knobs.
private func footerRow(merger: Merger) -> some View {
HStack(spacing: ChainRouterView.footerSpacing) {
MergerView(merger: merger)
Spacer()
}
}
/// A thin horizontal rule between sections.
private var sectionDivider: some View {
Rectangle()
.fill(Color.white.opacity(ChainRouterView.sectionDividerOpacity))
.frame(height: ChainRouterView.sectionDividerHeight)
}
}