add scope for debugging
This commit is contained in:
@@ -53,5 +53,56 @@ extension ShoeGaze {
|
||||
}
|
||||
|
||||
try rebuildAllBoards(from: snapshot)
|
||||
|
||||
// The tapped bus indices depend on the channel layout (input buses follow the output
|
||||
// buses), so rebuild the scope tap for the new configuration.
|
||||
installScopeTap()
|
||||
}
|
||||
|
||||
/// Default samples-per-frame captured by the scope tap.
|
||||
public static let defaultScopeBufferSize: Int = 2_048
|
||||
|
||||
/// (Re)builds the ``scopeTap`` over the current hardware input + output buses and assigns it
|
||||
/// to the engine, so the debug scope view can visualise both the live input signal and the
|
||||
/// board output.
|
||||
///
|
||||
/// Lane order is **inputs first** (`In 0`, `In 1`, …) then **outputs** (`Out L`, `Out R`, …),
|
||||
/// so the input waveform sits at the top of the scope. Must be called while the engine is
|
||||
/// stopped — `SynthesisEngine` caches its scope tap at `start()`. Rebuilt automatically by
|
||||
/// ``reconfigureEngine(sampleRate:inputChannels:outputChannels:)`` and at init.
|
||||
///
|
||||
/// - Parameter bufferSize: Samples per channel per display frame. Defaults to 2048.
|
||||
public func installScopeTap(bufferSize: Int = ShoeGaze.defaultScopeBufferSize) {
|
||||
let numOut: Int = engine.numOutputChannels
|
||||
let numIn: Int = engine.numInputChannels
|
||||
|
||||
var buses: [Int] = []
|
||||
for ch: Int in 0..<numIn { buses.append(numOut + ch) } // hardware inputs (top lanes)
|
||||
for ch: Int in 0..<numOut { buses.append(ch) } // outputs (lower lanes)
|
||||
|
||||
guard !buses.isEmpty else {
|
||||
engine.scopeTap = nil
|
||||
scopeTap = nil
|
||||
return
|
||||
}
|
||||
|
||||
let capture: ScopeCapture = ScopeCapture(buses: buses, bufferSize: bufferSize)
|
||||
engine.scopeTap = capture
|
||||
scopeTap = capture
|
||||
}
|
||||
|
||||
/// Human-readable label for a tapped audio-bus index under the current engine layout.
|
||||
///
|
||||
/// Output buses (`bus < numOutputChannels`) are `Out L` / `Out R` / `Out N`; the remaining
|
||||
/// buses are hardware inputs `In 0`, `In 1`, … Used by the scope view to label each lane.
|
||||
///
|
||||
/// - Parameter bus: An audio-bus index, typically one of ``scopeTap``'s `buses`.
|
||||
public func scopeLaneLabel(forBus bus: Int) -> String {
|
||||
let numOut: Int = engine.numOutputChannels
|
||||
guard bus >= numOut else {
|
||||
let stereoNames: [String] = ["Out L", "Out R"]
|
||||
return bus < stereoNames.count ? stereoNames[bus] : "Out \(bus)"
|
||||
}
|
||||
return "In \(bus - numOut)"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +84,16 @@ public final class ShoeGaze {
|
||||
/// (same module, different file) can mutate it.
|
||||
internal var recordTaps: [RecordTap] = []
|
||||
|
||||
// MARK: - Scope state
|
||||
|
||||
/// Scope tap over the hardware input + output buses, feeding the debug scope view.
|
||||
///
|
||||
/// Rebuilt by ``installScopeTap(bufferSize:)`` whenever the engine layout changes (so the
|
||||
/// tapped bus indices follow the current input/output channel counts). `nil` until first
|
||||
/// installed. The setter is `internal` so ``installScopeTap(bufferSize:)`` (same module,
|
||||
/// different file) can assign it; external callers observe it through this `public` getter.
|
||||
public internal(set) var scopeTap: ScopeCapture?
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private var testLoopSources: [TestLoopSource] = []
|
||||
@@ -110,6 +120,7 @@ public final class ShoeGaze {
|
||||
) {
|
||||
self.engine = engine
|
||||
self.inputSource = inputSource
|
||||
installScopeTap()
|
||||
}
|
||||
|
||||
// MARK: - Board management
|
||||
|
||||
@@ -105,6 +105,7 @@ public struct ShoeGazeBuilderView: View {
|
||||
boardArea
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
|
||||
ShoeGazeScopeView(shoeGaze: shoeGaze)
|
||||
LyrebirdStatusView(engine: shoeGaze.engine)
|
||||
}
|
||||
.padding(ShoeGazeBuilderView.outerPadding)
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
// ShoeGazeScopeView.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import SwiftUI
|
||||
import LyrebirdSynth
|
||||
import LyrebirdUI
|
||||
import LyrebirdShoeGaze
|
||||
|
||||
/// Oscilloscope panel showing the live input and board-output waveforms.
|
||||
///
|
||||
/// Wraps Lyrebird's `LyrebirdScopeView` bound to ``ShoeGaze/scopeTap`` and adds a labelled
|
||||
/// legend so each lane is identifiable (`In 0`, `Out L`, `Out R`, …) — input lanes on top,
|
||||
/// outputs below. Use it to confirm signal flow: a flat input lane with audible test-tone
|
||||
/// output means the live input never reaches the board head bus; a live input lane with a flat
|
||||
/// output lane points downstream.
|
||||
///
|
||||
/// The lane colours match `LyrebirdScopeView` (cyan, orange, green, yellow, cycling). The view
|
||||
/// keys itself on the tap's object identity so a reconfigure that rebuilds the tap recreates the
|
||||
/// underlying scope.
|
||||
public struct ShoeGazeScopeView: View {
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
/// Colours used by `LyrebirdScopeView`, mirrored here for the legend swatches.
|
||||
private static let laneColors: [Color] = [.cyan, .orange, .green, .yellow]
|
||||
private static let scopeHeight: CGFloat = 120
|
||||
private static let legendSpacing: CGFloat = 14
|
||||
private static let swatchSize: CGFloat = 9
|
||||
private static let panelSpacing: CGFloat = 6
|
||||
private static let labelOpacity: Double = 0.75
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
private let shoeGaze: ShoeGaze
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
/// - Parameter shoeGaze: The session whose ``ShoeGaze/scopeTap`` is visualised.
|
||||
public init(shoeGaze: ShoeGaze) {
|
||||
self.shoeGaze = shoeGaze
|
||||
}
|
||||
|
||||
// MARK: - Body
|
||||
|
||||
public var body: some View {
|
||||
VStack(alignment: .leading, spacing: ShoeGazeScopeView.panelSpacing) {
|
||||
if let capture: ScopeCapture = shoeGaze.scopeTap {
|
||||
legend(for: capture)
|
||||
LyrebirdScopeView(capture: capture)
|
||||
.frame(height: ShoeGazeScopeView.scopeHeight)
|
||||
.id(ObjectIdentifier(capture))
|
||||
} else {
|
||||
Text("Scope unavailable")
|
||||
.font(.caption)
|
||||
.foregroundStyle(Color.white.opacity(ShoeGazeScopeView.labelOpacity))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Legend
|
||||
|
||||
/// A horizontal legend mapping each lane colour to its bus label.
|
||||
private func legend(for capture: ScopeCapture) -> some View {
|
||||
HStack(spacing: ShoeGazeScopeView.legendSpacing) {
|
||||
ForEach(Array(capture.buses.enumerated()), id: \.offset) { index, bus in
|
||||
HStack(spacing: 4) {
|
||||
Circle()
|
||||
.fill(ShoeGazeScopeView.laneColors[index % ShoeGazeScopeView.laneColors.count])
|
||||
.frame(
|
||||
width: ShoeGazeScopeView.swatchSize,
|
||||
height: ShoeGazeScopeView.swatchSize
|
||||
)
|
||||
Text(shoeGaze.scopeLaneLabel(forBus: bus))
|
||||
.font(.caption2)
|
||||
.foregroundStyle(Color.white.opacity(ShoeGazeScopeView.labelOpacity))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,6 +112,9 @@ public struct ShoeGazeView: View {
|
||||
Divider()
|
||||
.overlay(Color.white.opacity(ShoeGazeView.dividerOpacity))
|
||||
boardList
|
||||
Divider()
|
||||
.overlay(Color.white.opacity(ShoeGazeView.dividerOpacity))
|
||||
ShoeGazeScopeView(shoeGaze: shoeGaze)
|
||||
Divider()
|
||||
.overlay(Color.white.opacity(ShoeGazeView.dividerOpacity))
|
||||
LyrebirdStatusView(engine: shoeGaze.engine)
|
||||
|
||||
Reference in New Issue
Block a user