// StereoSplitSectionView.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import SwiftUI import LyrebirdUI import LyrebirdShoeGaze /// Renders a ``StereoSplitSection`` as a horizontal stereo rack. /// /// Layout (left → right): /// 1. ``StereoRouteControlView`` — the 4-way ``StereoRoute`` selector and source LEDs. /// 2. A central panel with two labelled branch rows that become the stereo channels: /// - **L** row: one ``PedalView`` per pedal in `section.left`. /// - **R** row: one ``PedalView`` per pedal in `section.right`. /// Empty branches show a placeholder (the split signal passes straight through). /// /// The route collector and dry tap are owned by `PedalBoard`, not the section, so only /// the route control and the two branch rows are rendered here. The central panel is /// wrapped in a horizontal `ScrollView` so wide branch chains do not overflow. /// /// ## Usage /// /// ```swift /// StereoSplitSectionView(section: stereoSplitSection) /// ``` public struct StereoSplitSectionView: View { // MARK: - Layout constants private static let outerSpacing: CGFloat = 16 private static let branchStackSpacing: CGFloat = 12 private static let pedalSpacing: CGFloat = 16 private static let branchLabelFontSize: CGFloat = 11 private static let branchLabelOpacity: Double = 0.55 private static let emptyBranchOpacity: Double = 0.30 private static let emptyBranchFontSize: CGFloat = 11 private static let scrollPaddingH: CGFloat = 12 private static let scrollPaddingV: CGFloat = 8 private static let branchSeparatorOpacity: Double = 0.15 private static let branchSeparatorHeight: CGFloat = 1 private static let branchLabelWidth: CGFloat = 18 // MARK: - Properties private let section: StereoSplitSection // MARK: - Init /// Creates a stereo split section view. /// /// - Parameter section: The `StereoSplitSection` to render. Both branch pedal arrays /// and the route are read from this instance. public init(section: StereoSplitSection) { self.section = section } // MARK: - Body public var body: some View { HStack(alignment: .top, spacing: StereoSplitSectionView.outerSpacing) { StereoRouteControlView(section: section) ScrollView(.horizontal, showsIndicators: false) { VStack(alignment: .leading, spacing: StereoSplitSectionView.branchStackSpacing) { branchRow(label: "L", pedals: section.left.pedals) Rectangle() .fill(Color.white.opacity(StereoSplitSectionView.branchSeparatorOpacity)) .frame(height: StereoSplitSectionView.branchSeparatorHeight) branchRow(label: "R", pedals: section.right.pedals) } .padding(.horizontal, StereoSplitSectionView.scrollPaddingH) .padding(.vertical, StereoSplitSectionView.scrollPaddingV) } } } // MARK: - Subviews /// A labelled row of pedal cards for one stereo channel. private func branchRow(label: String, pedals: [Pedal]) -> some View { HStack(alignment: .bottom, spacing: StereoSplitSectionView.pedalSpacing) { Text(label) .font(.system( size: StereoSplitSectionView.branchLabelFontSize, weight: .semibold, design: .monospaced )) .foregroundStyle(Color.white.opacity(StereoSplitSectionView.branchLabelOpacity)) .frame(width: StereoSplitSectionView.branchLabelWidth, alignment: .leading) if pedals.isEmpty { Text("(empty)") .font(.system(size: StereoSplitSectionView.emptyBranchFontSize)) .foregroundStyle(Color.white.opacity(StereoSplitSectionView.emptyBranchOpacity)) } else { ForEach(Array(pedals.enumerated()), id: \.offset) { pair in let pedal: Pedal = pair.element PedalView(pedal: pedal) } } } } }