Add board mixer bar UI + independent per-board audibility API

Multi-board playback was all-or-one: selectBoard soloed exclusively,
selectAllBoards summed. There was no way to play an arbitrary subset, and
the builder only exposed a dropdown that picked which board to *edit*.

ShoeGaze API:
- setBoard(_:audible:crossfadeSeconds:) toggles one board's select-gain in
  place without disturbing the others (Blend mixing); clears activeBoardIndex.
- soloBoard(_:crossfadeSeconds:) — the "Solo" verb (wraps selectBoard).
- isBoardAudible(_:) reports a board's live select-gain target.

UI — BoardBarView (shared macOS/iOS):
- Horizontal board-mixer strip. Each board is a channel cell: audible LED,
  Solo button, and a master-gain fader. Tapping a cell name sets the edit
  target (independent of what's audible); context menu silences/deletes.
- Solo | Blend mode switch + an All button + a crossfade slider.
- Replaces the builder's board dropdown and Add Board button; the cell's +
  adds a board.

Tests: solo/blend/all audibility transitions and activeBoardIndex tracking;
setBoard no-op for a board owned by another manager.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-23 16:51:17 -07:00
parent cdac587454
commit c0605d295d
4 changed files with 440 additions and 17 deletions
+46
View File
@@ -261,6 +261,52 @@ public final class ShoeGaze {
activeBoardIndex = nil
}
/// Solos `board` exclusively — identical to ``selectBoard(_:crossfadeSeconds:)``.
///
/// Provided as the "Solo" verb alongside ``setBoard(_:audible:crossfadeSeconds:)`` so
/// callers can express *make only this board audible* without conflating it with the
/// independent per-board enable used by Blend-style mixing.
///
/// - Parameters:
/// - board: The board to solo. No-op if not managed by this instance.
/// - crossfadeSeconds: Crossfade duration in seconds (`0` = instant).
public func soloBoard(_ board: PedalBoard, crossfadeSeconds: Double) {
selectBoard(board, crossfadeSeconds: crossfadeSeconds)
}
/// Sets a single board audible or silent **without** disturbing the others.
///
/// Unlike ``selectBoard(_:crossfadeSeconds:)`` (which is exclusive), this toggles one
/// board's select-gain in place, so arbitrary subsets of boards can play at once — the
/// "Blend" mixing model. Because the audible set is no longer a single soloed board,
/// ``activeBoardIndex`` is cleared to `nil`.
///
/// - Parameters:
/// - board: The board to enable or silence. No-op if not managed by this instance.
/// - audible: `true` to fade the board in, `false` to fade it out.
/// - crossfadeSeconds: Crossfade duration in seconds (`0` = instant).
public func setBoard(_ board: PedalBoard, audible: Bool, crossfadeSeconds: Double) {
guard boards.contains(where: { $0 === board }) else { return }
board.crossfadeTimeNode?.update(crossfadeSeconds)
board.selectGainNode?.update(audible ? 1.0 : 0.0)
activeBoardIndex = nil
}
/// Whether `board`'s output is currently audible (its select-gain target is on).
///
/// Reads the live select-gain target, so it reflects the latest
/// ``selectBoard(_:crossfadeSeconds:)`` / ``setBoard(_:audible:crossfadeSeconds:)`` /
/// ``selectAllBoards(crossfadeSeconds:)`` call (the value the crossfade is ramping
/// toward), independent of where the crossfade currently sits.
///
/// - Parameter board: A board managed by this instance.
/// - Returns: `true` when the board's select-gain target is on; `false` when silenced
/// or when the board has no output master yet.
public func isBoardAudible(_ board: PedalBoard) -> Bool {
let selectGainOnThreshold: Double = 0.5
return (board.selectGainNode?.value ?? 0.0) > selectGainOnThreshold
}
/// Removes a single board and its associated input source and output master from
/// the engine, then releases the board's buses. The other boards are unaffected.
///
@@ -0,0 +1,304 @@
// BoardBarView.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import SwiftUI
import LyrebirdUI
import LyrebirdShoeGaze
/// A horizontal board-mixer strip for switching between, or blending, multiple `PedalBoard`s.
///
/// Each board is a channel cell with an audible LED, a Solo button, and a level fader (the
/// board's master gain). A leading **Solo / Blend** mode switch chooses the interaction:
///
/// - **Solo** — tapping a cell's LED makes that board the only audible one
/// (``ShoeGaze/soloBoard(_:crossfadeSeconds:)``); the **All** button returns to the
/// summed state (``ShoeGaze/selectAllBoards(crossfadeSeconds:)``). Amp-channel feel.
/// - **Blend** — tapping a cell's LED toggles that board in or out of the mix
/// independently (``ShoeGaze/setBoard(_:audible:crossfadeSeconds:)``), so any subset can
/// play at once — the default summed behaviour, now controllable per board.
///
/// Tapping a cell's **name** selects it as the edit target (`editingBoardIndex`), which is
/// independent of what is audible — you can audition one board while editing another. A
/// cell's context menu deletes the board.
///
/// The same view serves macOS and iOS; on iOS the cell row scrolls horizontally and the
/// context-menu delete is reached by long-press.
public struct BoardBarView: View {
// MARK: - Play mode
/// How a cell's LED tap maps to board audibility.
private enum PlayMode: Hashable {
/// Tapping a board solos it exclusively.
case solo
/// Tapping a board toggles it independently in/out of the mix.
case blend
}
// MARK: - Layout constants
private static let barSpacing: CGFloat = 12
private static let cellSpacing: CGFloat = 8
private static let cellWidth: CGFloat = 116
private static let cellInnerSpacing: CGFloat = 6
private static let cellPadding: CGFloat = 8
private static let cellCornerRadius: CGFloat = 8
private static let controlColumnWidth: CGFloat = 150
private static let ledDiameter: CGFloat = 12
private static let ledGlowRadius: CGFloat = 6
private static let ledGlowOpacity: Double = 0.75
private static let ledDimBrightness: Double = 0.16
private static let ledRimOpacity: Double = 0.30
private static let soloButtonSize: CGFloat = 22
private static let editingBorderWidth: CGFloat = 2
private static let idleBorderOpacity: Double = 0.18
private static let cellBackgroundBrightness: Double = 0.14
private static let labelOpacity: Double = 0.65
private static let nameFontSize: CGFloat = 12
private static let maxCrossfadeSeconds: Double = 10.0
private static let crossfadeStep: Double = 0.1
private static let addButtonSize: CGFloat = 30
// MARK: - Properties
private let shoeGaze: ShoeGaze
@Binding private var editingBoardIndex: Int
@Binding private var crossfadeSeconds: Double
private let onAddBoard: () -> Void
@State private var mode: PlayMode = .solo
// MARK: - Init
/// Creates a board-mixer bar.
///
/// - Parameters:
/// - shoeGaze: The manager whose `boards` are switched / blended.
/// - editingBoardIndex: The index of the board currently being edited (a cell's name
/// tap writes this).
/// - crossfadeSeconds: Crossfade duration applied to every board switch / toggle.
/// - onAddBoard: Called when the trailing **+** button is tapped.
public init(
shoeGaze: ShoeGaze,
editingBoardIndex: Binding<Int>,
crossfadeSeconds: Binding<Double>,
onAddBoard: @escaping () -> Void
) {
self.shoeGaze = shoeGaze
self._editingBoardIndex = editingBoardIndex
self._crossfadeSeconds = crossfadeSeconds
self.onAddBoard = onAddBoard
}
// MARK: - Body
public var body: some View {
HStack(alignment: .center, spacing: BoardBarView.barSpacing) {
controlColumn
Divider().overlay(Color.white.opacity(BoardBarView.idleBorderOpacity))
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: BoardBarView.cellSpacing) {
ForEach(Array(shoeGaze.boards.enumerated()), id: \.offset) { pair in
boardCell(index: pair.offset, board: pair.element)
}
addButton
}
}
}
}
// MARK: - Control column
private var controlColumn: some View {
VStack(alignment: .leading, spacing: BoardBarView.cellInnerSpacing) {
Picker("Mode", selection: $mode) {
Text("Solo").tag(PlayMode.solo)
Text("Blend").tag(PlayMode.blend)
}
.pickerStyle(.segmented)
.labelsHidden()
HStack(spacing: BoardBarView.cellInnerSpacing) {
Button("All") {
shoeGaze.selectAllBoards(crossfadeSeconds: clampedCrossfade)
}
.buttonStyle(.bordered)
.tint(.orange)
.help("Play all boards (summed)")
Text("XFade")
.font(.caption2)
.foregroundStyle(Color.white.opacity(BoardBarView.labelOpacity))
}
HStack(spacing: BoardBarView.cellInnerSpacing) {
Slider(
value: $crossfadeSeconds,
in: 0 ... BoardBarView.maxCrossfadeSeconds,
step: BoardBarView.crossfadeStep
)
Text(String(format: "%.1fs", clampedCrossfade))
.font(.caption2)
.monospacedDigit()
.foregroundStyle(Color.white.opacity(BoardBarView.labelOpacity))
}
}
.frame(width: BoardBarView.controlColumnWidth)
}
// MARK: - Board cell
@ViewBuilder
private func boardCell(index: Int, board: PedalBoard) -> some View {
let isEditing: Bool = index == editingBoardIndex
let isAudible: Bool = shoeGaze.isBoardAudible(board)
let isSoloed: Bool = shoeGaze.activeBoardIndex == index
VStack(spacing: BoardBarView.cellInnerSpacing) {
Text(boardLabel(index: index, board: board))
.font(.system(size: BoardBarView.nameFontSize, weight: .semibold))
.foregroundStyle(Color.white)
.lineLimit(1)
.frame(maxWidth: .infinity)
.contentShape(Rectangle())
.onTapGesture { editingBoardIndex = index }
HStack(spacing: BoardBarView.cellSpacing) {
ledButton(board: board, isAudible: isAudible)
soloButton(board: board, isSoloed: isSoloed)
}
levelFader(board: board)
}
.padding(BoardBarView.cellPadding)
.frame(width: BoardBarView.cellWidth)
.background(
RoundedRectangle(cornerRadius: BoardBarView.cellCornerRadius)
.fill(Color(white: BoardBarView.cellBackgroundBrightness))
)
.overlay(
RoundedRectangle(cornerRadius: BoardBarView.cellCornerRadius)
.stroke(
isEditing ? Color.orange : Color.white.opacity(BoardBarView.idleBorderOpacity),
lineWidth: isEditing ? BoardBarView.editingBorderWidth : 1
)
)
.contextMenu {
Button("Edit This Board") { editingBoardIndex = index }
Button(isAudible ? "Silence" : "Enable") {
shoeGaze.setBoard(board, audible: !isAudible, crossfadeSeconds: clampedCrossfade)
}
Divider()
Button("Delete Board", role: .destructive) {
shoeGaze.removeBoard(board)
clampEditingIndex()
}
}
}
/// The audible LED — tap behaviour depends on the current ``PlayMode``.
private func ledButton(board: PedalBoard, isAudible: Bool) -> some View {
Button {
switch mode {
case .solo:
shoeGaze.soloBoard(board, crossfadeSeconds: clampedCrossfade)
case .blend:
shoeGaze.setBoard(board, audible: !isAudible, crossfadeSeconds: clampedCrossfade)
}
} label: {
ZStack {
if isAudible {
Circle()
.fill(Color.green.opacity(BoardBarView.ledGlowOpacity))
.frame(
width: BoardBarView.ledDiameter + BoardBarView.ledGlowRadius,
height: BoardBarView.ledDiameter + BoardBarView.ledGlowRadius
)
.blur(radius: BoardBarView.ledGlowRadius / 2)
}
Circle()
.fill(isAudible ? Color.green : Color(white: BoardBarView.ledDimBrightness))
.frame(width: BoardBarView.ledDiameter, height: BoardBarView.ledDiameter)
.overlay(
Circle().stroke(Color.white.opacity(BoardBarView.ledRimOpacity), lineWidth: 0.5)
)
}
.frame(width: BoardBarView.ledDiameter + BoardBarView.ledGlowRadius,
height: BoardBarView.ledDiameter + BoardBarView.ledGlowRadius)
}
.buttonStyle(.plain)
.help(mode == .solo ? "Solo this board" : (isAudible ? "Silence this board" : "Add this board to the mix"))
}
/// Exclusive solo button — lit when this board is the soloed one.
private func soloButton(board: PedalBoard, isSoloed: Bool) -> some View {
Button {
shoeGaze.soloBoard(board, crossfadeSeconds: clampedCrossfade)
} label: {
Text("S")
.font(.system(size: BoardBarView.nameFontSize, weight: .bold))
.foregroundStyle(isSoloed ? Color.black : Color.white)
.frame(width: BoardBarView.soloButtonSize, height: BoardBarView.soloButtonSize)
.background(
RoundedRectangle(cornerRadius: 4)
.fill(isSoloed ? Color.yellow : Color(white: BoardBarView.ledDimBrightness))
)
}
.buttonStyle(.plain)
.help("Solo this board (exclusive)")
}
/// Board master-gain fader. Hidden until the board's output master is connected.
@ViewBuilder
private func levelFader(board: PedalBoard) -> some View {
if let gainNode: UIParamNode = board.masterGainNode {
Slider(
value: Binding(
get: { gainNode.value },
set: { gainNode.update($0) }
),
in: 0.0 ... 1.0
)
.controlSize(.mini)
}
}
// MARK: - Add button
private var addButton: some View {
Button(action: onAddBoard) {
Image(systemName: "plus")
.font(.system(size: BoardBarView.nameFontSize, weight: .bold))
.foregroundStyle(Color.white)
.frame(width: BoardBarView.addButtonSize, height: BoardBarView.addButtonSize)
.background(
RoundedRectangle(cornerRadius: BoardBarView.cellCornerRadius)
.stroke(Color.white.opacity(BoardBarView.idleBorderOpacity), lineWidth: 1)
)
}
.buttonStyle(.plain)
.help("Add a board")
}
// MARK: - Helpers
/// Display label for a board, falling back to a 1-based position when unnamed.
private func boardLabel(index: Int, board: PedalBoard) -> String {
board.label.isEmpty ? "Board \(index + 1)" : board.label
}
/// `crossfadeSeconds` clamped to the supported range.
private var clampedCrossfade: Double {
min(max(crossfadeSeconds, 0.0), BoardBarView.maxCrossfadeSeconds)
}
/// Keeps the edit target valid after a delete.
private func clampEditingIndex() {
let count: Int = shoeGaze.boards.count
guard count > 0 else { editingBoardIndex = 0; return }
editingBoardIndex = min(editingBoardIndex, count - 1)
}
}
@@ -60,6 +60,9 @@ public struct ShoeGazeBuilderView: View {
/// Index of the board currently being edited.
@State private var selectedBoardIndex: Int = 0
/// Crossfade duration (seconds) applied to board switches in the board bar.
@State private var crossfadeSeconds: Double = 0.3
/// Bumped on transport/edit actions to force a re-read of `engine.isRunning`.
@State private var transportTick: Bool = false
@@ -102,6 +105,13 @@ public struct ShoeGazeBuilderView: View {
recordingRow
#endif
Divider().overlay(Color.white.opacity(ShoeGazeBuilderView.dividerOpacity))
BoardBarView(
shoeGaze: shoeGaze,
editingBoardIndex: $selectedBoardIndex,
crossfadeSeconds: $crossfadeSeconds,
onAddBoard: { addBoard() }
)
Divider().overlay(Color.white.opacity(ShoeGazeBuilderView.dividerOpacity))
HStack(alignment: .top, spacing: ShoeGazeBuilderView.columnSpacing) {
paletteSidebar
Divider().overlay(Color.white.opacity(ShoeGazeBuilderView.dividerOpacity))
@@ -191,23 +201,6 @@ public struct ShoeGazeBuilderView: View {
.pickerStyle(.menu)
.foregroundStyle(Color.white)
Text("Board:")
.font(.subheadline)
.foregroundStyle(Color.white.opacity(ShoeGazeBuilderView.labelOpacity))
Picker("Board", selection: $selectedBoardIndex) {
ForEach(Array(shoeGaze.boards.enumerated()), id: \.offset) { pair in
let label: String = pair.element.label.isEmpty
? "Board \(pair.offset + 1)"
: pair.element.label
Text(label).tag(pair.offset)
}
}
.pickerStyle(.menu)
.foregroundStyle(Color.white)
Button("Add Board") { addBoard() }
.buttonStyle(.bordered).tint(.orange)
Spacer()
// On macOS, Save/Load live in the app's File menu (see the app shell's AppDelegate);