feat(ui): amp-head layout + Neural Amp model loader (S4)

- AmpPedal: double-width (widthUnits 2) amp-head card so the four tone knobs +
  Amp/Cab selectors + master aren't cramped. Uses the generic single-column
  content (no greedy Spacers → no flow-canvas height issue).
- Neural Amp model loader: PedalView renders, for a NeuralAmpPedal, a "Load
  Model…" picker (.fileImporter for .json) plus the loaded model's filename.
  Picking sets Pedal.resourcePath and asks the host to rebuild the board so the
  model applies live. Picker + AppKit stay in the UI layer (core imports none).
- New `pedalRebuildAction` environment value (@MainActor @Sendable), installed by
  ShoeGazeBuilderView; it resolves the pedal's board via a new branch-aware
  `ShoeGaze.board(containing:)` (finds pedals inside parallel / stereo-split
  branches, not just the main chain) and rebuilds it via the live-safe
  `rebuildBoard(_:from:)`.

Tests: AmpPedal widthUnits == 2; board(containing:) finds main + branch pedals
and returns nil for a stranger. Full suite 502. (SwiftUI loader flow needs
on-device visual QA.)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-08-01 22:17:53 -07:00
parent 40fa590196
commit 23d607b9fc
7 changed files with 127 additions and 0 deletions
@@ -5,6 +5,7 @@
// SPDX-License-Identifier: MIT
import SwiftUI
import UniformTypeIdentifiers
import LyrebirdUI
import LyrebirdShoeGaze
@@ -417,6 +418,10 @@ public struct PedalView: View {
/// Horizontal gap between the Level knob and the bypass control in the bottom row.
private static let bottomControlsSpacing: CGFloat = 18
private static let sectionSpacing: CGFloat = 14
/// Neural Amp model row: label/button spacing, caption size, and caption opacity.
private static let neuralRowSpacing: CGFloat = 6
private static let neuralRowFontSize: CGFloat = 11
private static let neuralRowLabelOpacity: Double = 0.85
private static let namePlateCornerRadius: CGFloat = 8
private static let namePlatePaddingH: CGFloat = 10
private static let namePlatePaddingV: CGFloat = 4
@@ -452,6 +457,13 @@ public struct PedalView: View {
/// Presentation flag for the pedal info panel (description + control ranges).
@State private var showInfo: Bool = false
/// Presentation flag for the Neural Amp model-file importer.
@State private var showModelImporter: Bool = false
/// Rebuilds this pedal's board after a non-`@UIParam` change (Neural Amp model file). Injected
/// by the builder; no-op elsewhere.
@Environment(\.pedalRebuildAction) private var pedalRebuildAction: @MainActor @Sendable (Pedal) -> Void
/// The rig's control map, injected by the builder so the pedal can draw a mapping strip. `nil`
/// when the rig has no bindings (or in contexts that don't set it) — the strip renders nothing.
@Environment(\.controlMappingMap) private var controlMappingMap: MIDIMap?
@@ -541,6 +553,7 @@ public struct PedalView: View {
VStack(spacing: PedalView.sectionSpacing) {
namePlate
knobGrid
neuralModelRow
selectorRow
switchRow
// Keyed on the pedal instance so the buttons' live captions (which poll the pedal
@@ -848,6 +861,42 @@ public struct PedalView: View {
/// Bottom control row: the `Level` knob, the bypass switch, and the `Mix` knob,
/// side-by-side and centred — a symmetric knob-switch-knob footer shared by all pedals.
/// Neural Amp only: shows the loaded model file name and a picker to load a `.json` capture.
/// Setting the model changes the graph, so after a pick it asks the host to rebuild the board.
@ViewBuilder
private var neuralModelRow: some View {
if let neural: NeuralAmpPedal = pedal as? NeuralAmpPedal {
VStack(spacing: PedalView.neuralRowSpacing) {
Text(neuralModelLabel(neural))
.font(.system(size: PedalView.neuralRowFontSize, weight: .medium))
.foregroundStyle(Color.white.opacity(PedalView.neuralRowLabelOpacity))
.lineLimit(1)
.truncationMode(.middle)
Button("Load Model…") { showModelImporter = true }
.buttonStyle(.bordered)
.controlSize(.small)
}
.frame(maxWidth: .infinity)
.fileImporter(
isPresented: $showModelImporter,
allowedContentTypes: [.json]
) { (result: Result<URL, Error>) in
guard case .success(let url) = result else { return }
// The app is unsandboxed, so a plain path read works; still bracket access defensively.
let accessed: Bool = url.startAccessingSecurityScopedResource()
neural.resourcePath = url.path
if accessed { url.stopAccessingSecurityScopedResource() }
pedalRebuildAction(neural)
}
}
}
/// Loaded-model caption for the Neural Amp row — the model file's base name, or a prompt.
private func neuralModelLabel(_ neural: NeuralAmpPedal) -> String {
guard let path: String = neural.resourcePath, !path.isEmpty else { return "No model loaded" }
return (path as NSString).lastPathComponent
}
private var bottomControls: some View {
HStack(alignment: .center, spacing: PedalView.bottomControlsSpacing) {
levelControl