Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0bfc25ace6 | |||
| 426a288002 | |||
| 12e83bd172 | |||
| bf1e09ede3 | |||
| cd3aeb771b | |||
| e75b50b157 | |||
| 6a3c4fdca9 | |||
| 22ae022143 | |||
| 722c8d9069 | |||
| 1c9979af52 | |||
| 36202a5e95 | |||
| 19feb03fe8 | |||
| f97ba90ea6 | |||
| 67744ec89d | |||
| ba80573213 | |||
| efa193ea37 | |||
| 45b18b5ea8 | |||
| 5b343a2cce | |||
| d07247e40e | |||
| bdfbe04713 | |||
| 5090a9255f |
@@ -2,6 +2,21 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDocumentTypes</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>CFBundleTypeName</key>
|
||||
<string>ShoeGaze Document</string>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>Editor</string>
|
||||
<key>LSHandlerRank</key>
|
||||
<string>Owner</string>
|
||||
<key>LSItemContentTypes</key>
|
||||
<array>
|
||||
<string>net.realizedsound.shoegaze</string>
|
||||
</array>
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
@@ -22,6 +37,18 @@
|
||||
<string>Copyright © 2026 realizedsound. All rights reserved.</string>
|
||||
<key>NSMicrophoneUsageDescription</key>
|
||||
<string>ShoeGaze Builder can route a hardware input channel through your pedalboard. Enable microphone access to use Live Input mode.</string>
|
||||
<key>NSUbiquitousContainers</key>
|
||||
<dict>
|
||||
<key>iCloud.net.realizedsound.ShoeGazeData</key>
|
||||
<dict>
|
||||
<key>NSUbiquitousContainerIsDocumentScopePublic</key>
|
||||
<true/>
|
||||
<key>NSUbiquitousContainerName</key>
|
||||
<string>ShoeGaze</string>
|
||||
<key>NSUbiquitousContainerSupportedFolderLevels</key>
|
||||
<string>Any</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>UIApplicationSceneManifest</key>
|
||||
<dict>
|
||||
<key>UIApplicationSupportsMultipleScenes</key>
|
||||
@@ -40,45 +67,19 @@
|
||||
<array>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>NSUbiquitousContainers</key>
|
||||
<dict>
|
||||
<key>iCloud.net.realizedsound.ShoeGazeData</key>
|
||||
<dict>
|
||||
<key>NSUbiquitousContainerIsDocumentScopePublic</key>
|
||||
<true/>
|
||||
<key>NSUbiquitousContainerName</key>
|
||||
<string>ShoeGaze</string>
|
||||
<key>NSUbiquitousContainerSupportedFolderLevels</key>
|
||||
<string>Any</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>CFBundleDocumentTypes</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>CFBundleTypeName</key>
|
||||
<string>ShoeGaze Document</string>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>Editor</string>
|
||||
<key>LSHandlerRank</key>
|
||||
<string>Owner</string>
|
||||
<key>LSItemContentTypes</key>
|
||||
<array>
|
||||
<string>net.realizedsound.shoegaze</string>
|
||||
</array>
|
||||
</dict>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
</array>
|
||||
<key>UTExportedTypeDeclarations</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>UTTypeIdentifier</key>
|
||||
<string>net.realizedsound.shoegaze</string>
|
||||
<key>UTTypeDescription</key>
|
||||
<string>ShoeGaze Document</string>
|
||||
<key>UTTypeConformsTo</key>
|
||||
<array>
|
||||
<string>public.json</string>
|
||||
</array>
|
||||
<key>UTTypeDescription</key>
|
||||
<string>ShoeGaze Document</string>
|
||||
<key>UTTypeIdentifier</key>
|
||||
<string>net.realizedsound.shoegaze</string>
|
||||
<key>UTTypeTagSpecification</key>
|
||||
<dict>
|
||||
<key>public.filename-extension</key>
|
||||
|
||||
@@ -13,8 +13,9 @@ import LyrebirdShoeGazeUI
|
||||
/// lifetime of the app. The audio engine is **not** started automatically — the user presses
|
||||
/// Start in ``ShoeGazeBuilderView``. The engine is stopped when the view disappears.
|
||||
///
|
||||
/// ``ShoeGazeBuilderView`` manages its own scroll regions (palette + builder), so it is hosted
|
||||
/// directly rather than wrapped in an outer `ScrollView`.
|
||||
/// ``ShoeGazeBuilderView`` draws its own header/title and manages its own scroll regions (palette
|
||||
/// + board canvas), so it is hosted directly — no `NavigationStack`, title, or outer `ScrollView`.
|
||||
/// A fill frame keeps it pinned to the full window so portrait isn't vertically centered.
|
||||
@main
|
||||
struct ShoeGazeBuilderiOSApp: App {
|
||||
|
||||
@@ -23,7 +24,6 @@ struct ShoeGazeBuilderiOSApp: App {
|
||||
|
||||
var body: some Scene {
|
||||
WindowGroup {
|
||||
NavigationStack {
|
||||
ShoeGazeBuilderView(
|
||||
shoeGaze: model.shoeGaze,
|
||||
library: model.library,
|
||||
@@ -31,10 +31,8 @@ struct ShoeGazeBuilderiOSApp: App {
|
||||
onEnableLiveInput: { model.enableLiveInput() },
|
||||
midi: model.midi
|
||||
)
|
||||
.navigationTitle("ShoeGaze Builder")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
|
||||
.task { await model.startLibrary() }
|
||||
}
|
||||
.onDisappear { model.stop() }
|
||||
.onOpenURL { url in model.importDocument(at: url) }
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
<key>UILaunchScreen</key>
|
||||
<dict/>
|
||||
<key>UIRequiresFullScreen</key>
|
||||
<true/>
|
||||
<false/>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
@@ -40,6 +40,8 @@
|
||||
<array>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -49,6 +49,11 @@ public struct PedalSwitch {
|
||||
/// three-state switch. Must contain at least two options.
|
||||
public let options: [Option]
|
||||
|
||||
/// `true` when this switch controls a tempo-synced behaviour (e.g. the looper's
|
||||
/// Sync-to-Tempo mode). A generic UI can disable such switches — and the host can force them
|
||||
/// to their first (off) option — while the tempo indicator is turned off. Defaults to `false`.
|
||||
public let tempoDependent: Bool
|
||||
|
||||
/// Creates a switch descriptor.
|
||||
///
|
||||
/// - Parameters:
|
||||
@@ -56,15 +61,18 @@ public struct PedalSwitch {
|
||||
/// - node: The `UIParamNode` projected value of an `@UIParam` property
|
||||
/// (`pedal.$mode`, `pedal.$direction`, …).
|
||||
/// - options: Ordered switch positions, left to right. At least two.
|
||||
/// - tempoDependent: `true` if the switch depends on the tempo/clock. Defaults to `false`.
|
||||
public init(
|
||||
label: String,
|
||||
node: UIParamNode,
|
||||
options: [Option]
|
||||
options: [Option],
|
||||
tempoDependent: Bool = false
|
||||
) {
|
||||
precondition(options.count >= 2, "PedalSwitch requires at least two options")
|
||||
self.label = label
|
||||
self.node = node
|
||||
self.options = options
|
||||
self.tempoDependent = tempoDependent
|
||||
}
|
||||
|
||||
/// The value of the next option after the one nearest `current`, wrapping to the first — so a
|
||||
|
||||
@@ -40,8 +40,9 @@ public final class LooperPedal: Pedal {
|
||||
"Multitrack looper: record track A, then layer synced overdubs on tracks B–D."
|
||||
}
|
||||
|
||||
/// Double-width card: the looper carries a full transport plus a track strip and timeline.
|
||||
public override var widthUnits: Int { 2 }
|
||||
/// Triple-width card: the looper spreads its timeline, knobs, and transport grid across three
|
||||
/// columns so the tall pedal fits the canvas without scrolling.
|
||||
public override var widthUnits: Int { 3 }
|
||||
|
||||
/// The looper always passes the clean signal through and adds the loop on top (see `effect`),
|
||||
/// so the wet/dry Mix knob is meaningless — hide it and keep `mix` fully wet.
|
||||
@@ -167,8 +168,22 @@ public final class LooperPedal: Pedal {
|
||||
private var recordStartSample: SampleTime = 0
|
||||
private var playStartSample: SampleTime = 0
|
||||
|
||||
/// Play-head position tracking that survives direction changes. `playHeadAnchor01` is the
|
||||
/// normalised play-head fraction at the last anchor event (playback start or a reverse flip);
|
||||
/// `playHeadAnchorSample` is the engine sample at that event. Between events the position is
|
||||
/// `anchor01 + direction · (elapsed / masterLength)`, wrapped into `[0, 1)`. This mirrors the
|
||||
/// actual `PlayBuffer` play-head — which reverses smoothly from its live phase — instead of the
|
||||
/// old `1 − forward` reflection that jumped the read-out to the mirror point on every reverse.
|
||||
private var playHeadAnchor01: Double = 0.0
|
||||
private var playHeadAnchorSample: SampleTime = 0
|
||||
|
||||
private var transportRoutine: LyrebirdRoutine?
|
||||
private var stopRoutine: LyrebirdRoutine?
|
||||
private var reverseRoutine: LyrebirdRoutine?
|
||||
|
||||
/// Generation guard for a beat-deferred reverse. Separate from `transportGeneration` so
|
||||
/// scheduling a reverse never invalidates a pending record/close (and vice versa).
|
||||
private(set) var reverseGeneration: Int = 0
|
||||
|
||||
/// Transient notice shown in place of the state description for `noticeDuration` seconds.
|
||||
private var noticeText: String?
|
||||
@@ -205,12 +220,13 @@ public final class LooperPedal: Pedal {
|
||||
public override var effectSwitches: [PedalSwitch] {
|
||||
[
|
||||
PedalSwitch(
|
||||
label: "Sync",
|
||||
label: "Sync to Tempo",
|
||||
node: $syncToBeat,
|
||||
options: [
|
||||
PedalSwitch.Option(title: "Free", value: 0.0),
|
||||
PedalSwitch.Option(title: "Sync", value: 1.0),
|
||||
]
|
||||
],
|
||||
tempoDependent: true
|
||||
),
|
||||
]
|
||||
}
|
||||
@@ -278,11 +294,20 @@ public final class LooperPedal: Pedal {
|
||||
guard phase == .playing, masterLength > 0, let engine: SynthesisEngine = hostEngine else {
|
||||
return nil
|
||||
}
|
||||
let elapsed: SampleTime = engine.currentTime - playStartSample
|
||||
guard elapsed >= 0 else { return 0.0 }
|
||||
let framesInto: Int = Int(elapsed % SampleTime(masterLength))
|
||||
let forward: Double = Double(framesInto) / Double(masterLength)
|
||||
return reverse >= 0.5 ? (1.0 - forward) : forward
|
||||
return playHeadFraction(at: engine.currentTime)
|
||||
}
|
||||
|
||||
/// The normalised play-head fraction in `[0, 1)` at engine sample `sample`, integrating the
|
||||
/// signed distance travelled since the last anchor (playback start or reverse flip). Reversal
|
||||
/// simply changes the sign of the accumulation from the current position — no jump.
|
||||
func playHeadFraction(at sample: SampleTime) -> Double {
|
||||
guard masterLength > 0 else { return 0.0 }
|
||||
let direction: Double = reverse >= 0.5 ? -1.0 : 1.0
|
||||
let elapsed: Double = Double(sample - playHeadAnchorSample)
|
||||
let raw: Double = playHeadAnchor01 + direction * elapsed / Double(masterLength)
|
||||
var frac: Double = raw.truncatingRemainder(dividingBy: 1.0)
|
||||
if frac < 0 { frac += 1.0 }
|
||||
return frac
|
||||
}
|
||||
|
||||
/// Caption for the Loop footswitch describing what the *next* press does.
|
||||
@@ -480,10 +505,55 @@ public final class LooperPedal: Pedal {
|
||||
syncToBeat = sync.nextValue(after: syncToBeat)
|
||||
}
|
||||
|
||||
/// Flips playback direction. Engaging reverse ends any active overdub, since overdub records
|
||||
/// Flips playback direction from the current play-head position. In Sync mode the flip is
|
||||
/// deferred to the next beat; in Free mode (or with no clock/engine, or when not playing) it
|
||||
/// applies immediately. Engaging reverse ends any active overdub, since overdub records
|
||||
/// forward-in-time and can't follow a backward-reading play-head (see the class doc).
|
||||
public func toggleReverse() {
|
||||
reverseRoutine?.stop()
|
||||
reverseRoutine = nil
|
||||
|
||||
// Not playing: no live play-head to reverse — just flip the direction for the next start.
|
||||
guard phase == .playing else {
|
||||
applyReverse(at: hostEngine?.currentTime ?? playHeadAnchorSample)
|
||||
return
|
||||
}
|
||||
|
||||
reverseGeneration += 1
|
||||
let generation: Int = reverseGeneration
|
||||
|
||||
// Free mode, or no clock/engine to schedule against → reverse immediately from here.
|
||||
guard syncToBeat >= 0.5, let clock: LyrebirdClock = clock, let engine: SynthesisEngine = hostEngine else {
|
||||
applyReverse(at: hostEngine?.currentTime ?? playHeadAnchorSample)
|
||||
return
|
||||
}
|
||||
|
||||
// Sync mode: reverse on the next beat, from wherever the play-head is at that beat.
|
||||
let target: SampleTime = clock.nextBeat()
|
||||
let routine: LyrebirdRoutine = LyrebirdRoutine { [weak self] ctx in
|
||||
try ctx.waitUntil(sampleTime: target)
|
||||
DispatchQueue.main.async { self?.applyDeferredReverse(generation: generation, at: target) }
|
||||
}
|
||||
reverseRoutine = routine
|
||||
routine.start(engine: engine)
|
||||
}
|
||||
|
||||
/// Applies a beat-deferred reverse once its target beat is reached, unless superseded by a
|
||||
/// newer reverse press or a transport change.
|
||||
func applyDeferredReverse(generation: Int, at beatSample: SampleTime) {
|
||||
guard generation == reverseGeneration, phase == .playing else { return }
|
||||
reverseRoutine = nil
|
||||
applyReverse(at: beatSample)
|
||||
}
|
||||
|
||||
/// Flips the playback direction, re-anchoring the position read-out to the current play-head so
|
||||
/// it continues smoothly in the new direction. `sample` is the point the flip takes effect.
|
||||
func applyReverse(at sample: SampleTime) {
|
||||
let engagingReverse: Bool = reverse < 0.5
|
||||
// Re-anchor at the current play-head fraction *before* flipping, so the new-direction
|
||||
// accumulation starts from where we actually are.
|
||||
playHeadAnchor01 = playHeadFraction(at: sample)
|
||||
playHeadAnchorSample = sample
|
||||
reverse = engagingReverse ? 1.0 : 0.0
|
||||
if engagingReverse, overdubbingTrack != nil {
|
||||
overdubbingTrack = nil
|
||||
@@ -497,6 +567,8 @@ public final class LooperPedal: Pedal {
|
||||
transportGeneration += 1
|
||||
stopRoutine?.stop()
|
||||
stopRoutine = nil
|
||||
reverseRoutine?.stop()
|
||||
reverseRoutine = nil
|
||||
cueStopArmed = 0.0
|
||||
overdubbingTrack = nil
|
||||
updateOverdubGates()
|
||||
@@ -579,6 +651,8 @@ public final class LooperPedal: Pedal {
|
||||
transportRoutine = nil
|
||||
stopRoutine?.stop()
|
||||
stopRoutine = nil
|
||||
reverseRoutine?.stop()
|
||||
reverseRoutine = nil
|
||||
transportGeneration += 1
|
||||
|
||||
// Gate the recorders off (they run off `$isPlaying`) and stop the master BEFORE clearing,
|
||||
@@ -634,6 +708,8 @@ public final class LooperPedal: Pedal {
|
||||
transportRoutine = nil
|
||||
stopRoutine?.stop()
|
||||
stopRoutine = nil
|
||||
reverseRoutine?.stop()
|
||||
reverseRoutine = nil
|
||||
buffers.removeAll()
|
||||
players.removeAll()
|
||||
overdubRecorders.removeAll()
|
||||
@@ -689,6 +765,10 @@ public final class LooperPedal: Pedal {
|
||||
recorder.requestReset() // realign every write head to the top
|
||||
}
|
||||
playStartSample = sample
|
||||
// Play head resets to the top (frame 0) via the playTrigger edge below; anchor the
|
||||
// position read-out there so direction changes accumulate from a known origin.
|
||||
playHeadAnchor01 = 0.0
|
||||
playHeadAnchorSample = sample
|
||||
isPlaying = 1.0
|
||||
stoppedIndicator = 0.0
|
||||
overdubbingTrack = overdubTrack
|
||||
|
||||
@@ -125,10 +125,30 @@ public final class ShoeGaze {
|
||||
|
||||
// MARK: - Tempo state
|
||||
|
||||
/// `true` when the tempo indicator (BPM readout / TAP / beat LED) is shown and tempo-synced
|
||||
/// features are available. Toggle with ``setTempoEnabled(_:)``; when turned off, every
|
||||
/// tempo-dependent pedal switch (e.g. the looper's Sync-to-Tempo mode) is forced to its
|
||||
/// first (off) position so nothing keeps quantizing to a hidden clock.
|
||||
public private(set) var tempoEnabled: Bool = true
|
||||
|
||||
/// Timestamps of recent `tapTempo()` calls, oldest first. `internal` so
|
||||
/// `ShoeGaze+Tempo.swift` (same module, different file) can mutate it.
|
||||
internal var tapTimestamps: [Date] = []
|
||||
|
||||
/// Shows or hides the tempo indicator and, when hiding, deactivates every tempo-synced
|
||||
/// control by forcing each ``PedalSwitch/tempoDependent`` switch to its first option.
|
||||
public func setTempoEnabled(_ enabled: Bool) {
|
||||
tempoEnabled = enabled
|
||||
guard !enabled else { return }
|
||||
for pedal: Pedal in allPedals() {
|
||||
for pedalSwitch: PedalSwitch in pedal.effectSwitches where pedalSwitch.tempoDependent {
|
||||
if let off: PedalSwitch.Option = pedalSwitch.options.first {
|
||||
pedalSwitch.node.update(off.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Scope state
|
||||
|
||||
/// Scope tap over the hardware input + output buses, feeding the debug scope view.
|
||||
|
||||
@@ -41,7 +41,9 @@ public struct BoardBarView: View {
|
||||
// MARK: - Layout constants
|
||||
|
||||
private static let barSpacing: CGFloat = 10
|
||||
private static let barHeight: CGFloat = 92
|
||||
// Tall enough for the control column's three rows of (iOS-chunky) segmented picker + sliders +
|
||||
// bordered mute button, so it doesn't overflow into the CPU meters below.
|
||||
private static let barHeight: CGFloat = 110
|
||||
private static let cellSpacing: CGFloat = 8
|
||||
private static let cellWidth: CGFloat = 104
|
||||
private static let cellInnerSpacing: CGFloat = 5
|
||||
@@ -56,6 +58,9 @@ public struct BoardBarView: View {
|
||||
private static let ledDimBrightness: Double = 0.16
|
||||
private static let ledRimOpacity: Double = 0.30
|
||||
private static let soloButtonSize: CGFloat = 22
|
||||
/// Fixed size for the rig mute glyph so the slash / wave states don't shift the volume row.
|
||||
private static let muteIconWidth: CGFloat = 16
|
||||
private static let muteIconHeight: CGFloat = 16
|
||||
private static let editingBorderWidth: CGFloat = 2
|
||||
private static let idleBorderOpacity: Double = 0.18
|
||||
private static let cellBackgroundBrightness: Double = 0.14
|
||||
@@ -71,6 +76,7 @@ public struct BoardBarView: View {
|
||||
@Binding private var editingBoardIndex: Int
|
||||
@Binding private var crossfadeSeconds: Double
|
||||
private let onAddBoard: () -> Void
|
||||
private let onClearBoards: (() -> Void)?
|
||||
|
||||
@State private var mode: PlayMode = .solo
|
||||
|
||||
@@ -84,16 +90,20 @@ public struct BoardBarView: View {
|
||||
/// tap writes this).
|
||||
/// - crossfadeSeconds: Crossfade duration applied to every board switch / toggle.
|
||||
/// - onAddBoard: Called when the trailing **+** button is tapped.
|
||||
/// - onClearBoards: Called when the trailing **Clear** button is tapped. When `nil`
|
||||
/// (the default) no Clear button is shown.
|
||||
public init(
|
||||
shoeGaze: ShoeGaze,
|
||||
editingBoardIndex: Binding<Int>,
|
||||
crossfadeSeconds: Binding<Double>,
|
||||
onAddBoard: @escaping () -> Void
|
||||
onAddBoard: @escaping () -> Void,
|
||||
onClearBoards: (() -> Void)? = nil
|
||||
) {
|
||||
self.shoeGaze = shoeGaze
|
||||
self._editingBoardIndex = editingBoardIndex
|
||||
self._crossfadeSeconds = crossfadeSeconds
|
||||
self.onAddBoard = onAddBoard
|
||||
self.onClearBoards = onClearBoards
|
||||
}
|
||||
|
||||
// MARK: - Body
|
||||
@@ -109,6 +119,11 @@ public struct BoardBarView: View {
|
||||
boardCell(index: pair.offset, board: pair.element)
|
||||
}
|
||||
addButton
|
||||
if let onClearBoards: () -> Void = onClearBoards {
|
||||
Button("Clear") { onClearBoards() }
|
||||
.buttonStyle(.bordered).tint(.red)
|
||||
.help("Remove all boards in the current rig (with the option to save first)")
|
||||
}
|
||||
}
|
||||
.frame(height: BoardBarView.barHeight)
|
||||
}
|
||||
@@ -175,7 +190,10 @@ public struct BoardBarView: View {
|
||||
Button {
|
||||
shoeGaze.toggleRigMuted()
|
||||
} label: {
|
||||
// Fixed width: the slash / wave glyphs differ in width, which would otherwise
|
||||
// shift the whole volume row a few pixels when toggling mute.
|
||||
Image(systemName: shoeGaze.rigMuted ? "speaker.slash.fill" : "speaker.wave.2.fill")
|
||||
.frame(width: BoardBarView.muteIconWidth, height: BoardBarView.muteIconHeight)
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
.tint(shoeGaze.rigMuted ? .red : .orange)
|
||||
|
||||
@@ -42,6 +42,10 @@ public struct EngineConfigView: View {
|
||||
private let hardwareSampleRate: () -> Double?
|
||||
private let applyConfig: ((Double, Int, Int) throws -> Void)?
|
||||
private let onConfigApplied: () -> Void
|
||||
/// When `true`, renders only the Start/Stop transport button (the sample-rate / channel-count
|
||||
/// controls are hidden). Used by the compact (iPhone / narrow iPad) layout, which keeps the
|
||||
/// transport on screen and moves the config controls into a Settings sheet.
|
||||
private let transportOnly: Bool
|
||||
|
||||
@State private var pendingSampleRate: Double
|
||||
@State private var pendingInputs: Int
|
||||
@@ -63,12 +67,14 @@ public struct EngineConfigView: View {
|
||||
shoeGaze: ShoeGaze,
|
||||
hardwareSampleRate: @escaping () -> Double? = { nil },
|
||||
applyConfig: ((Double, Int, Int) throws -> Void)? = nil,
|
||||
onConfigApplied: @escaping () -> Void = { }
|
||||
onConfigApplied: @escaping () -> Void = { },
|
||||
transportOnly: Bool = false
|
||||
) {
|
||||
self.shoeGaze = shoeGaze
|
||||
self.hardwareSampleRate = hardwareSampleRate
|
||||
self.applyConfig = applyConfig
|
||||
self.onConfigApplied = onConfigApplied
|
||||
self.transportOnly = transportOnly
|
||||
_pendingSampleRate = State(initialValue: shoeGaze.engine.sampleRate)
|
||||
_pendingInputs = State(initialValue: shoeGaze.engine.numInputChannels)
|
||||
_pendingOutputs = State(initialValue: shoeGaze.engine.numOutputChannels)
|
||||
@@ -78,8 +84,11 @@ public struct EngineConfigView: View {
|
||||
|
||||
public var body: some View {
|
||||
_ = transportTick
|
||||
let isRunning: Bool = shoeGaze.engine.isRunning
|
||||
return HStack(spacing: EngineConfigView.rowSpacing) {
|
||||
return Group {
|
||||
if transportOnly {
|
||||
transportButton
|
||||
} else {
|
||||
HStack(spacing: EngineConfigView.rowSpacing) {
|
||||
label("Rate")
|
||||
Picker("Rate", selection: $pendingSampleRate) {
|
||||
ForEach(EngineConfigView.standardRates, id: \.self) { rate in
|
||||
@@ -88,25 +97,23 @@ public struct EngineConfigView: View {
|
||||
}
|
||||
.labelsHidden()
|
||||
.pickerStyle(.menu)
|
||||
.disabled(isRunning)
|
||||
.disabled(shoeGaze.engine.isRunning)
|
||||
|
||||
Stepper(value: $pendingInputs, in: 0...EngineConfigView.maxInputs) {
|
||||
Text("In: \(pendingInputs)").foregroundStyle(Color.white)
|
||||
}
|
||||
.disabled(isRunning)
|
||||
.disabled(shoeGaze.engine.isRunning)
|
||||
.fixedSize()
|
||||
|
||||
Stepper(value: $pendingOutputs, in: 1...EngineConfigView.maxOutputs) {
|
||||
Text("Out: \(pendingOutputs)").foregroundStyle(Color.white)
|
||||
}
|
||||
.disabled(isRunning)
|
||||
.disabled(shoeGaze.engine.isRunning)
|
||||
.fixedSize()
|
||||
|
||||
Button(isRunning ? "Stop" : "Start") {
|
||||
if isRunning { stopEngine() } else { startEngine() }
|
||||
transportButton
|
||||
}
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
.tint(isRunning ? .red : .green)
|
||||
}
|
||||
.alert(alertTitle, isPresented: $showAlert) {
|
||||
Button("OK", role: .cancel) { }
|
||||
@@ -131,6 +138,16 @@ public struct EngineConfigView: View {
|
||||
.onChange(of: pendingSampleRate) { applyConfigWhileStopped() }
|
||||
}
|
||||
|
||||
/// The Start / Stop transport button, shared by the full and transport-only layouts.
|
||||
private var transportButton: some View {
|
||||
let isRunning: Bool = shoeGaze.engine.isRunning
|
||||
return Button(isRunning ? "Stop" : "Start") {
|
||||
if isRunning { stopEngine() } else { startEngine() }
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
.tint(isRunning ? .red : .green)
|
||||
}
|
||||
|
||||
/// Reconfigures the stopped engine with the pending values and notifies the host so views that
|
||||
/// read non-observable engine state refresh. No-op while the engine is running.
|
||||
private func applyConfigWhileStopped() {
|
||||
@@ -161,6 +178,11 @@ public struct EngineConfigView: View {
|
||||
|
||||
private func startEngine() {
|
||||
do {
|
||||
// Transport-only mode does not own the config controls — the engine is already
|
||||
// configured (via the full instance's live apply, or the init defaults). Re-applying
|
||||
// this instance's cached pending state here would revert edits made in the Settings
|
||||
// sheet, so skip the reconfigure and just start.
|
||||
if !transportOnly {
|
||||
if let applyConfig: (Double, Int, Int) throws -> Void = applyConfig {
|
||||
try applyConfig(pendingSampleRate, pendingInputs, pendingOutputs)
|
||||
} else {
|
||||
@@ -170,6 +192,7 @@ public struct EngineConfigView: View {
|
||||
outputChannels: pendingOutputs
|
||||
)
|
||||
}
|
||||
}
|
||||
try shoeGaze.engine.start()
|
||||
} catch {
|
||||
handleStartError(error)
|
||||
|
||||
@@ -66,6 +66,33 @@ public struct HelpView: View {
|
||||
+ "Delete, and Erase All.",
|
||||
]
|
||||
)
|
||||
topicSection(
|
||||
icon: "repeat",
|
||||
title: "The Looper Pedal",
|
||||
intro: "The Looper records a phrase and plays it back in a loop, with up to four "
|
||||
+ "overdub tracks (A–D). The big Record button is a smart footswitch whose job "
|
||||
+ "changes with the looper's state.",
|
||||
steps: [
|
||||
"Record (smart footswitch): first press records track A; press again to set the "
|
||||
+ "loop end and start playback (auto-overdubbing A); while playing it toggles "
|
||||
+ "overdub on the selected track.",
|
||||
"Free vs Sync to Tempo: Free loops are whatever length you play, captured instantly. "
|
||||
+ "Sync quantizes record-start and loop-close to the beat clock — so every loop is "
|
||||
+ "a whole number of beats. Sync needs the Tempo indicator On; it is disabled while "
|
||||
+ "tempo is off.",
|
||||
"Knobs: Playback sets loop level against your live signal; Overdub sets the record "
|
||||
+ "level of new overdubs; Feedback sets how much existing audio survives each pass "
|
||||
+ "(1.0 = keep forever); Crossfade smooths loop mute/unmute so it doesn't click.",
|
||||
"Reverse flips playback direction from the current position (in Sync it waits for the "
|
||||
+ "next beat). Stop halts now; Cue Stop arms a stop at the next loop end (press again "
|
||||
+ "to cancel); Reset clears every track back to empty.",
|
||||
"Tracks A–D: tap a dot to select the track Record overdubs into; tap a selected, "
|
||||
+ "recorded track again to mute or unmute it.",
|
||||
"MIDI: Record, Stop, Cue Stop, Reverse, Sync, Reset, and each Track A–D map as "
|
||||
+ "footswitch (Program Change) actions in MIDI Mapping; the Crossfade / Playback / "
|
||||
+ "Overdub / Feedback knobs sweep from an expression pedal like any pedal knob.",
|
||||
]
|
||||
)
|
||||
topicSection(
|
||||
icon: "square.and.arrow.down",
|
||||
title: "Saving & Autosave",
|
||||
|
||||
@@ -9,7 +9,7 @@ import SwiftUI
|
||||
/// A presentation grouping for pedals in the palette — used to colour-code the picker cards and to
|
||||
/// drive the "filter by type" menu. Purely a UI concern: the mapping from a pedal's `displayName`
|
||||
/// to its category lives here, keyed by name like ``PedalPaletteView``'s preferred order.
|
||||
enum PedalCategory: String, CaseIterable, Identifiable {
|
||||
public enum PedalCategory: String, CaseIterable, Identifiable, Sendable {
|
||||
case gain = "Gain"
|
||||
case dynamics = "Dynamics"
|
||||
case filter = "EQ & Filter"
|
||||
@@ -19,7 +19,7 @@ enum PedalCategory: String, CaseIterable, Identifiable {
|
||||
case reverb = "Reverb"
|
||||
case texture = "Texture"
|
||||
|
||||
var id: String { rawValue }
|
||||
public var id: String { rawValue }
|
||||
|
||||
/// Accent colour used to tint the palette card and the filter chip.
|
||||
var color: Color {
|
||||
|
||||
@@ -83,9 +83,25 @@ public struct PedalPaletteView: View {
|
||||
private let onAdd: (String) -> Void
|
||||
private let onRouting: (RoutingAction) -> Void
|
||||
private let axis: Axis
|
||||
private let showsFilterMenu: Bool
|
||||
|
||||
/// Active type filter; `nil` shows all pedals.
|
||||
@State private var filter: PedalCategory?
|
||||
/// Active type filter when the palette owns it; `nil` shows all pedals. Ignored when an
|
||||
/// `externalFilter` binding is supplied (the host hoists the filter into its own header).
|
||||
@State private var internalFilter: PedalCategory?
|
||||
private let externalFilter: Binding<PedalCategory?>?
|
||||
|
||||
/// The live filter, from the host binding if provided, else the palette's own state.
|
||||
private var activeFilter: PedalCategory? {
|
||||
externalFilter?.wrappedValue ?? internalFilter
|
||||
}
|
||||
|
||||
private func setFilter(_ category: PedalCategory?) {
|
||||
if let externalFilter: Binding<PedalCategory?> = externalFilter {
|
||||
externalFilter.wrappedValue = category
|
||||
} else {
|
||||
internalFilter = category
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
@@ -95,15 +111,23 @@ public struct PedalPaletteView: View {
|
||||
/// - axis: `.vertical` (default) lays the catalog out as a full-width column for a sidebar;
|
||||
/// `.horizontal` lays it out as a fixed-width-card row for a horizontal scroller. The host
|
||||
/// wraps the view in a `ScrollView` of the matching axis.
|
||||
/// - filter: Optional external binding for the type filter, so a host (e.g. a sheet) can put
|
||||
/// the filter control in its own fixed header. When `nil` the palette manages its own filter.
|
||||
/// - showsFilterMenu: Whether to draw the built-in filter menu inline. Pass `false` when the
|
||||
/// host renders its own filter control. Defaults to `true`.
|
||||
/// - onAdd: Invoked with a pedal's `displayName` when its row is tapped (append to main chain).
|
||||
/// Rows are also `.draggable` carrying `"add:<displayName>"` for drop-onto-lane targeting.
|
||||
/// - onRouting: Invoked when a routing row is tapped. Defaults to a no-op.
|
||||
public init(
|
||||
axis: Axis = .vertical,
|
||||
filter: Binding<PedalCategory?>? = nil,
|
||||
showsFilterMenu: Bool = true,
|
||||
onAdd: @escaping (String) -> Void,
|
||||
onRouting: @escaping (RoutingAction) -> Void = { _ in }
|
||||
) {
|
||||
self.axis = axis
|
||||
self.externalFilter = filter
|
||||
self.showsFilterMenu = showsFilterMenu
|
||||
self.onAdd = onAdd
|
||||
self.onRouting = onRouting
|
||||
}
|
||||
@@ -120,7 +144,7 @@ public struct PedalPaletteView: View {
|
||||
|
||||
/// Pedal names after applying the active type filter.
|
||||
private var visiblePedalNames: [String] {
|
||||
guard let filter: PedalCategory = filter else { return orderedPedalNames }
|
||||
guard let filter: PedalCategory = activeFilter else { return orderedPedalNames }
|
||||
return orderedPedalNames.filter { PedalCategory.category(for: $0) == filter }
|
||||
}
|
||||
|
||||
@@ -151,7 +175,7 @@ public struct PedalPaletteView: View {
|
||||
HStack {
|
||||
sectionTitle("PEDALS")
|
||||
Spacer(minLength: 0)
|
||||
filterMenu
|
||||
if showsFilterMenu { filterMenu }
|
||||
}
|
||||
ForEach(visiblePedalNames, id: \.self) { name in
|
||||
pedalRow(name)
|
||||
@@ -174,7 +198,7 @@ public struct PedalPaletteView: View {
|
||||
HStack(alignment: .top, spacing: PedalPaletteView.sectionSpacing) {
|
||||
VStack(alignment: .leading, spacing: PedalPaletteView.rowSpacing) {
|
||||
sectionTitle("PEDALS")
|
||||
filterMenu
|
||||
if showsFilterMenu { filterMenu }
|
||||
}
|
||||
ForEach(groupedVisiblePedals, id: \.category) { group in
|
||||
VStack(alignment: .leading, spacing: PedalPaletteView.rowSpacing) {
|
||||
@@ -215,18 +239,18 @@ public struct PedalPaletteView: View {
|
||||
/// "Filter by type" menu — defaults to **All** (no filtering).
|
||||
private var filterMenu: some View {
|
||||
Menu {
|
||||
Button("All Types") { filter = nil }
|
||||
Button("All Types") { setFilter(nil) }
|
||||
Divider()
|
||||
ForEach(PedalCategory.allCases) { category in
|
||||
Button(category.rawValue) { filter = category }
|
||||
Button(category.rawValue) { setFilter(category) }
|
||||
}
|
||||
} label: {
|
||||
HStack(spacing: 3) {
|
||||
Image(systemName: "line.3.horizontal.decrease.circle")
|
||||
Text(filter?.rawValue ?? "All").lineLimit(1)
|
||||
Text(activeFilter?.rawValue ?? "All").lineLimit(1)
|
||||
}
|
||||
.font(.system(size: PedalPaletteView.titleFontSize))
|
||||
.foregroundStyle((filter?.color ?? Color.white).opacity(0.9))
|
||||
.foregroundStyle((activeFilter?.color ?? Color.white).opacity(0.9))
|
||||
}
|
||||
#if os(macOS)
|
||||
.menuStyle(.borderlessButton)
|
||||
|
||||
@@ -43,10 +43,15 @@ public struct PedalSwitchView: View {
|
||||
private static let borderLineWidth: CGFloat = 1
|
||||
private static let activeTextBrightness: Double = 0.12
|
||||
|
||||
/// Opacity applied to a tempo-dependent switch while the tempo indicator is turned off.
|
||||
private static let tempoDisabledOpacity: Double = 0.4
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
private let pedalSwitch: PedalSwitch
|
||||
|
||||
@Environment(\.shoeGazeTempoEnabled) private var tempoEnabled: Bool
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
/// Creates a segmented switch view.
|
||||
@@ -62,6 +67,8 @@ public struct PedalSwitchView: View {
|
||||
// Reading `node.value` registers this view for @Observable re-render on change.
|
||||
let current: Double = pedalSwitch.node.value
|
||||
let selectedIndex: Int = nearestIndex(to: current)
|
||||
// A tempo-synced switch is inert while the tempo indicator is turned off.
|
||||
let inert: Bool = pedalSwitch.tempoDependent && !tempoEnabled
|
||||
|
||||
VStack(spacing: PedalSwitchView.labelSpacing) {
|
||||
HStack(spacing: PedalSwitchView.segmentSpacing) {
|
||||
@@ -77,10 +84,12 @@ public struct PedalSwitchView: View {
|
||||
lineWidth: PedalSwitchView.borderLineWidth)
|
||||
)
|
||||
|
||||
Text(pedalSwitch.label)
|
||||
Text(inert ? "\(pedalSwitch.label) (tempo off)" : pedalSwitch.label)
|
||||
.font(.system(size: PedalSwitchView.captionFontSize))
|
||||
.foregroundStyle(Color.white)
|
||||
}
|
||||
.disabled(inert)
|
||||
.opacity(inert ? PedalSwitchView.tempoDisabledOpacity : 1.0)
|
||||
}
|
||||
|
||||
// MARK: - Subviews
|
||||
|
||||
@@ -241,6 +241,10 @@ public struct PedalView: View {
|
||||
private static let shadowOpacity: Double = 0.60
|
||||
private static let enclosureGradientDarkFraction: Double = 0.30
|
||||
private static let bypassSectionSpacing: CGFloat = 6
|
||||
/// Gap between the looper's three content columns.
|
||||
private static let looperColumnSpacing: CGFloat = 18
|
||||
/// Fixed width of the looper's left (timeline) column.
|
||||
private static let looperTimelineColumnWidth: CGFloat = 200
|
||||
/// Half the screw-dot size — used to centre screws on the corner position.
|
||||
private static let screwHalfSize: CGFloat = 4
|
||||
private static let namePlateBackgroundOpacity: Double = 0.35
|
||||
@@ -302,21 +306,14 @@ public struct PedalView: View {
|
||||
lineWidth: PedalView.innerHighlightLineWidth)
|
||||
.padding(PedalView.innerHighlightPadding)
|
||||
|
||||
// Content stack
|
||||
VStack(spacing: PedalView.sectionSpacing) {
|
||||
namePlate
|
||||
looperTimeline
|
||||
knobGrid
|
||||
selectorRow
|
||||
switchRow
|
||||
// Keyed on the pedal instance so the buttons' live captions (which poll the pedal
|
||||
// via `.task`) re-subscribe when a rig load / rebuild swaps in a new pedal instance.
|
||||
transportButtonRow
|
||||
.id(ObjectIdentifier(pedal))
|
||||
buttonRow
|
||||
sliderBank(sliders)
|
||||
Spacer(minLength: 0)
|
||||
bottomControls
|
||||
// Content stack — the looper uses a wide, columnar layout to stay short; every other
|
||||
// pedal uses the default single-column section stack.
|
||||
Group {
|
||||
if let looper: LooperPedal = pedal as? LooperPedal {
|
||||
looperColumnarContent(looper)
|
||||
} else {
|
||||
defaultContent(sliders: sliders)
|
||||
}
|
||||
}
|
||||
.padding(PedalView.enclosurePadding)
|
||||
|
||||
@@ -341,6 +338,136 @@ public struct PedalView: View {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Content layouts
|
||||
|
||||
/// The default single-column section stack used by every pedal except the looper.
|
||||
private func defaultContent(sliders: [PedalSlider]) -> some View {
|
||||
VStack(spacing: PedalView.sectionSpacing) {
|
||||
namePlate
|
||||
knobGrid
|
||||
selectorRow
|
||||
switchRow
|
||||
// Keyed on the pedal instance so the buttons' live captions (which poll the pedal
|
||||
// via `.task`) re-subscribe when a rig load / rebuild swaps in a new pedal instance.
|
||||
transportButtonRow
|
||||
.id(ObjectIdentifier(pedal))
|
||||
buttonRow
|
||||
sliderBank(sliders)
|
||||
Spacer(minLength: 0)
|
||||
bottomControls
|
||||
}
|
||||
}
|
||||
|
||||
/// Wide, three-column layout for the looper: the loop timeline on the left, the effect knobs
|
||||
/// over the Free/Sync switch in the centre, and the transport footswitch grid (with bypass) on
|
||||
/// the right. Laying the sections side-by-side keeps the tall pedal short enough to fit the
|
||||
/// canvas without scrolling. Requires the looper's `widthUnits` to be wide enough (3×).
|
||||
private func looperColumnarContent(_ looper: LooperPedal) -> some View {
|
||||
VStack(spacing: PedalView.sectionSpacing) {
|
||||
namePlate
|
||||
HStack(alignment: .top, spacing: PedalView.looperColumnSpacing) {
|
||||
// Left column: timeline, then the Free/Sync switch, then the Reset footswitch.
|
||||
VStack(spacing: PedalView.sectionSpacing) {
|
||||
LooperTimelineView(pedal: looper)
|
||||
switchRow
|
||||
looperResetCell
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
.frame(width: PedalView.looperTimelineColumnWidth)
|
||||
|
||||
// Centre column: the four effect knobs (2×2), with the Level + Bypass footer at the
|
||||
// bottom. The Mix slot is reserved (empty) so Bypass stays horizontally centred,
|
||||
// matching a normal pedal's footer.
|
||||
VStack(spacing: PedalView.sectionSpacing) {
|
||||
looperEffectKnobs(columns: 2)
|
||||
Spacer(minLength: 0)
|
||||
looperFooter
|
||||
}
|
||||
|
||||
// Right column: the transport footswitches (minus Reset) in a 2×2 grid.
|
||||
looperTransportGrid(columns: 2)
|
||||
.id(ObjectIdentifier(pedal))
|
||||
}
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
}
|
||||
|
||||
/// The looper's effect knobs (everything except the trailing `Mix` / `Level`) laid out in
|
||||
/// rows of `columns`.
|
||||
private func looperEffectKnobs(columns: Int) -> some View {
|
||||
let knobs: [PedalKnob] = Array(pedal.knobs.dropLast(2))
|
||||
let rows: [[PedalKnob]] = stride(from: 0, to: knobs.count, by: columns).map { start in
|
||||
Array(knobs[start ..< min(start + columns, knobs.count)])
|
||||
}
|
||||
return VStack(spacing: PedalView.knobSpacing) {
|
||||
ForEach(Array(rows.enumerated()), id: \.offset) { rowPair in
|
||||
HStack(spacing: PedalView.knobRowItemSpacing) {
|
||||
Spacer(minLength: 0)
|
||||
ForEach(Array(rowPair.element.enumerated()), id: \.offset) { knobPair in
|
||||
let knob: PedalKnob = knobPair.element
|
||||
ParameterKnob(knob.label, node: knob.node, range: knob.range)
|
||||
.foregroundStyle(Color.white)
|
||||
}
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Preferred grid order for the looper's transport footswitches (row-major), so the 2×2 grid
|
||||
/// reads Record / Reverse over Stop / Cue Stop. Buttons not listed keep their original order
|
||||
/// and follow. Matched by label to stay robust if the descriptor order changes.
|
||||
private static let looperTransportOrder: [String] = ["Loop", "Reverse", "Stop", "Cue Stop"]
|
||||
|
||||
/// The looper's transport footswitches — everything except the trailing Reset (which sits in
|
||||
/// the left column) — laid out in rows of `columns` in ``looperTransportOrder``.
|
||||
private func looperTransportGrid(columns: Int) -> some View {
|
||||
let buttons: [PedalButton] = Array(pedal.effectTransportButtons.dropLast())
|
||||
let ordered: [PedalButton] =
|
||||
PedalView.looperTransportOrder.compactMap { label in buttons.first { $0.label == label } }
|
||||
+ buttons.filter { !PedalView.looperTransportOrder.contains($0.label) }
|
||||
let rows: [[PedalButton]] = stride(from: 0, to: ordered.count, by: columns).map { start in
|
||||
Array(ordered[start ..< min(start + columns, ordered.count)])
|
||||
}
|
||||
return VStack(spacing: PedalView.knobSpacing) {
|
||||
ForEach(Array(rows.enumerated()), id: \.offset) { rowPair in
|
||||
HStack(alignment: .top, spacing: PedalView.knobRowItemSpacing) {
|
||||
Spacer(minLength: 0)
|
||||
ForEach(Array(rowPair.element.enumerated()), id: \.offset) { pair in
|
||||
PedalButtonView(pair.element)
|
||||
}
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The looper's footer: Level on the left, Bypass in the centre, and an empty third where a
|
||||
/// normal pedal's Mix knob would sit — so Bypass stays horizontally centred in the column.
|
||||
private var looperFooter: some View {
|
||||
HStack(spacing: 0) {
|
||||
levelControl
|
||||
.frame(maxWidth: .infinity)
|
||||
bypassControl
|
||||
.frame(maxWidth: .infinity)
|
||||
Color.clear
|
||||
.frame(maxWidth: .infinity, maxHeight: 0) // reserved Mix slot
|
||||
}
|
||||
}
|
||||
|
||||
/// The Reset footswitch (the trailing transport button), centred — sits at the bottom of the
|
||||
/// looper's left (timeline) column.
|
||||
@ViewBuilder
|
||||
private var looperResetCell: some View {
|
||||
if let reset: PedalButton = pedal.effectTransportButtons.last {
|
||||
HStack(spacing: 0) {
|
||||
Spacer(minLength: 0)
|
||||
PedalButtonView(reset)
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Subviews
|
||||
|
||||
/// Capsule name plate near the top of the enclosure.
|
||||
@@ -354,15 +481,6 @@ public struct PedalView: View {
|
||||
.clipShape(RoundedRectangle(cornerRadius: PedalView.namePlateCornerRadius))
|
||||
}
|
||||
|
||||
/// Loop timeline strip — rendered only for the double-width `LooperPedal`, between the
|
||||
/// name plate and the knob grid. Other pedals render nothing here.
|
||||
@ViewBuilder
|
||||
private var looperTimeline: some View {
|
||||
if let looper: LooperPedal = pedal as? LooperPedal {
|
||||
LooperTimelineView(pedal: looper)
|
||||
}
|
||||
}
|
||||
|
||||
/// Info button tucked just under the top-left corner screw.
|
||||
private var infoButton: some View {
|
||||
Button {
|
||||
|
||||
@@ -49,6 +49,11 @@ public struct ShoeGazeBuilderView: View {
|
||||
/// Width of the scope/CPU block in the bottom strip — matches `BoardBarView`'s Solo/Blend/All
|
||||
/// control column so the scope aligns under it.
|
||||
private static let scopeWidth: CGFloat = 188
|
||||
/// Narrow scope shown in the compact (iPad) header, tucked left of the transport buttons.
|
||||
private static let compactHeaderScopeWidth: CGFloat = 340
|
||||
private static let compactHeaderScopeHeight: CGFloat = 76
|
||||
/// Stable height (fraction of the screen) for the Add-Pedal sheet — a single, non-resizable detent.
|
||||
private static let paletteSheetHeightFraction: CGFloat = 0.82
|
||||
private static let columnSpacing: CGFloat = 14
|
||||
private static let backgroundRed: Double = 0.08
|
||||
private static let backgroundGreen: Double = 0.07
|
||||
@@ -157,6 +162,21 @@ public struct ShoeGazeBuilderView: View {
|
||||
/// Help sheet presentation flag (iOS button; macOS uses the Help menu).
|
||||
@State private var showHelpSheet: Bool = false
|
||||
|
||||
/// Compact-layout sheet flags — the composition panels docked in the regular layout become
|
||||
/// bottom sheets so the board canvas gets the full screen.
|
||||
@State private var showRigsSheet: Bool = false
|
||||
@State private var showPaletteSheet: Bool = false
|
||||
@State private var showSettingsSheet: Bool = false
|
||||
|
||||
/// Type filter for the compact Add-Pedal sheet, hoisted so it sits in the sheet's fixed header.
|
||||
@State private var pedalFilter: PedalCategory?
|
||||
|
||||
/// `true` when the window is taller than it is wide (portrait). iPad is `.regular` in both
|
||||
/// orientations, so this is derived from the actual size, not the size class. In portrait the
|
||||
/// header scope moves to a full-width strip below the controls (it would otherwise overlay /
|
||||
/// clip the header on narrower iPads); landscape keeps it inline beside the transport.
|
||||
@State private var isPortrait: Bool = false
|
||||
|
||||
#if !os(macOS)
|
||||
/// iOS recording-folder picker presentation flag. (macOS uses the Record menu.)
|
||||
@State private var showRecordingFolderImporter: Bool = false
|
||||
@@ -197,16 +217,30 @@ public struct ShoeGazeBuilderView: View {
|
||||
|
||||
// MARK: - Body
|
||||
|
||||
public var body: some View {
|
||||
HStack(alignment: .top, spacing: ShoeGazeBuilderView.columnSpacing) {
|
||||
rigSidebar
|
||||
Divider().overlay(Color.white.opacity(ShoeGazeBuilderView.dividerOpacity))
|
||||
builderColumn
|
||||
/// `true` on iPad (any size) — the canvas-first layout with composition panels in sheets. The
|
||||
/// docked desktop layout is macOS-only; on iPad it overflowed and clipped even at iPad-Pro
|
||||
/// width, so every iPad size uses the sheet-based layout. macOS always uses the docked layout.
|
||||
private var isCompact: Bool {
|
||||
#if os(iOS)
|
||||
return true
|
||||
#else
|
||||
return false
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
public var body: some View {
|
||||
rootContent
|
||||
.padding(ShoeGazeBuilderView.outerPadding)
|
||||
// A large min width is a macOS window sizing hint; on iPad it would force content wider than
|
||||
// the screen and clip it, so the sheet-based iPad layout imposes no minimum width. Fill the
|
||||
// whole window and pin to the top-leading corner so portrait isn't vertically centered.
|
||||
.frame(
|
||||
minWidth: ShoeGazeBuilderView.minWidth + ShoeGazeBuilderView.librarySidebarReserve,
|
||||
minHeight: ShoeGazeBuilderView.minHeight
|
||||
minWidth: isCompact ? nil : ShoeGazeBuilderView.minWidth + ShoeGazeBuilderView.librarySidebarReserve,
|
||||
maxWidth: isCompact ? .infinity : nil,
|
||||
minHeight: isCompact ? nil : ShoeGazeBuilderView.minHeight,
|
||||
maxHeight: isCompact ? .infinity : nil,
|
||||
alignment: .topLeading
|
||||
)
|
||||
.background(
|
||||
Color(
|
||||
@@ -215,6 +249,14 @@ public struct ShoeGazeBuilderView: View {
|
||||
blue: ShoeGazeBuilderView.backgroundBlue
|
||||
)
|
||||
)
|
||||
// Track portrait vs landscape by actual size (iPad is `.regular` in both orientations).
|
||||
.background(
|
||||
GeometryReader { proxy in
|
||||
Color.clear.task(id: proxy.size) {
|
||||
isPortrait = proxy.size.height > proxy.size.width
|
||||
}
|
||||
}
|
||||
)
|
||||
// The builder is always dark-themed; force the dark scheme so system controls (nav title,
|
||||
// steppers, the Record button) use light text instead of black-on-dark in light mode.
|
||||
.preferredColorScheme(.dark)
|
||||
@@ -309,9 +351,57 @@ public struct ShoeGazeBuilderView: View {
|
||||
.sheet(isPresented: $showHelpSheet) {
|
||||
HelpView()
|
||||
}
|
||||
// Each compact composition sheet lives on its own anchor node — SwiftUI presents at most one
|
||||
// sheet per node, so stacking them on the main node would silently swallow all but one.
|
||||
.background(rigsSheetAnchor)
|
||||
.background(paletteSheetAnchor)
|
||||
.background(settingsSheetAnchor)
|
||||
.overlay(alignment: .top) { midiLearnBanner }
|
||||
}
|
||||
|
||||
/// Hosts the compact rig-library sheet on its own node.
|
||||
private var rigsSheetAnchor: some View {
|
||||
Color.clear
|
||||
.sheet(isPresented: $showRigsSheet) {
|
||||
rigSidebar
|
||||
.padding(.top, ShoeGazeBuilderView.outerPadding)
|
||||
.presentationDetents([.large])
|
||||
.preferredColorScheme(.dark)
|
||||
}
|
||||
}
|
||||
|
||||
/// Hosts the compact Add-pedal palette sheet on its own node.
|
||||
private var paletteSheetAnchor: some View {
|
||||
Color.clear
|
||||
.sheet(isPresented: $showPaletteSheet) {
|
||||
paletteSheet
|
||||
}
|
||||
}
|
||||
|
||||
/// Hosts the compact engine-settings sheet on its own node.
|
||||
private var settingsSheetAnchor: some View {
|
||||
Color.clear
|
||||
.sheet(isPresented: $showSettingsSheet) {
|
||||
settingsSheet
|
||||
.presentationDetents([.medium, .large])
|
||||
}
|
||||
}
|
||||
|
||||
/// The whole-view layout: docked desktop layout on regular widths, canvas-first on compact.
|
||||
@ViewBuilder
|
||||
private var rootContent: some View {
|
||||
if isCompact {
|
||||
// No docked sidebar — the rig library is a sheet reached from the header.
|
||||
builderColumn
|
||||
} else {
|
||||
HStack(alignment: .top, spacing: ShoeGazeBuilderView.columnSpacing) {
|
||||
rigSidebar
|
||||
Divider().overlay(Color.white.opacity(ShoeGazeBuilderView.dividerOpacity))
|
||||
builderColumn
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A banner shown while a control is armed for MIDI Learn, prompting the user to move it.
|
||||
@ViewBuilder
|
||||
private var midiLearnBanner: some View {
|
||||
@@ -384,17 +474,297 @@ public struct ShoeGazeBuilderView: View {
|
||||
/// board canvas.
|
||||
private var builderColumn: some View {
|
||||
VStack(alignment: .leading, spacing: ShoeGazeBuilderView.sectionSpacing) {
|
||||
transportRow
|
||||
ioRow
|
||||
if isCompact {
|
||||
compactHeader
|
||||
Divider().overlay(Color.white.opacity(ShoeGazeBuilderView.dividerOpacity))
|
||||
compactTopSection
|
||||
} else {
|
||||
headerSection
|
||||
#if !os(macOS)
|
||||
recordingRow
|
||||
#endif
|
||||
Divider().overlay(Color.white.opacity(ShoeGazeBuilderView.dividerOpacity))
|
||||
topSection
|
||||
}
|
||||
Divider().overlay(Color.white.opacity(ShoeGazeBuilderView.dividerOpacity))
|
||||
boardArea
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
|
||||
.environment(\.shoeGazeTempoEnabled, shoeGaze.tempoEnabled)
|
||||
}
|
||||
|
||||
// MARK: - Compact layout (iPhone / narrow iPad)
|
||||
|
||||
/// The compact header: a performance row (title, transport, mute) always visible, plus a
|
||||
/// horizontally scrollable row of panel toggles that open the composition sheets.
|
||||
private var compactHeader: some View {
|
||||
_ = transportTick
|
||||
// The three control rows stack tight on the left; the transport sits top-right. The scope
|
||||
// is inline (right, spanning the rows) in landscape, but on narrower portrait widths it
|
||||
// would overlay/clip the header — so there it drops to a full-width strip below the rows.
|
||||
// Row 1: title · [Bypass · Mute · Help · MIDI] Row 2: Tempo · Tuner Row 3: Rigs/Pedals/Settings
|
||||
return VStack(alignment: .leading, spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||
HStack(alignment: .top, spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||
headerControlRows
|
||||
|
||||
if !isPortrait {
|
||||
// Inline: clamped to the compact header height (a short strip beside transport).
|
||||
headerScope
|
||||
.frame(
|
||||
width: ShoeGazeBuilderView.compactHeaderScopeWidth,
|
||||
height: ShoeGazeBuilderView.compactHeaderScopeHeight
|
||||
)
|
||||
}
|
||||
|
||||
headerTransport
|
||||
}
|
||||
|
||||
if isPortrait {
|
||||
// Full-width strip at the scope's natural height (legend + lanes), so the legend
|
||||
// doesn't overflow up into the panel row.
|
||||
headerScope
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The three stacked control rows shared by both orientations.
|
||||
private var headerControlRows: some View {
|
||||
VStack(alignment: .leading, spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||
HStack(spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||
VStack(alignment: .leading, spacing: 1) {
|
||||
Text("ShoeGaze").font(.headline).bold()
|
||||
.foregroundStyle(Color.white)
|
||||
currentRigLabel
|
||||
}
|
||||
if shoeGaze.isRecording { recordingBadge }
|
||||
compactRigControlsRow
|
||||
}
|
||||
|
||||
HStack(spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||
TempoView(shoeGaze: shoeGaze)
|
||||
TunerView(shoeGaze: shoeGaze)
|
||||
}
|
||||
.environment(\.shoeGazeTempoEnabled, shoeGaze.tempoEnabled)
|
||||
|
||||
compactPanelRow
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
|
||||
/// The oscilloscope. The caller sizes it: a fixed short strip inline (landscape) or a
|
||||
/// full-width strip at natural height (portrait).
|
||||
private var headerScope: some View {
|
||||
ShoeGazeScopeView(shoeGaze: shoeGaze)
|
||||
}
|
||||
|
||||
/// The Start / Stop over Record transport cluster (top-right in both orientations).
|
||||
private var headerTransport: some View {
|
||||
VStack(alignment: .trailing, spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||
EngineConfigView(
|
||||
shoeGaze: shoeGaze,
|
||||
hardwareSampleRate: hardwareSampleRate,
|
||||
onConfigApplied: { transportTick.toggle() },
|
||||
transportOnly: true
|
||||
)
|
||||
#if !os(macOS)
|
||||
recordButton
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// The rig-wide controls shown inline on the title row: Bypass / Mute / Help / MIDI.
|
||||
private var compactRigControlsRow: some View {
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
HStack(spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||
rigBypassButton
|
||||
// fixedSize stops the switch Toggle from expanding to fill the row (which pushed
|
||||
// the following controls far to the right, under the scope).
|
||||
Toggle("Mute rig", isOn: Binding(
|
||||
get: { shoeGaze.tunerMutesRig },
|
||||
set: { shoeGaze.tunerMutesRig = $0 }
|
||||
))
|
||||
.toggleStyle(.switch)
|
||||
.fixedSize()
|
||||
helpButton
|
||||
if let midi: MIDIController = midi {
|
||||
MIDIIndicatorView(controller: midi) { showMIDISheet = true }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The composition-panel row: buttons that open the Rigs / Pedals / Settings sheets.
|
||||
private var compactPanelRow: some View {
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
HStack(spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||
compactPanelButton("Rigs", systemImage: "tray.full") { showRigsSheet = true }
|
||||
compactPanelButton("Pedals", systemImage: "plus.app") { showPaletteSheet = true }
|
||||
compactPanelButton("Settings", systemImage: "gearshape") { showSettingsSheet = true }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The recording indicator badge (extracted so both header variants can show it).
|
||||
private var recordingBadge: some View {
|
||||
HStack(spacing: 4) {
|
||||
Circle()
|
||||
.fill(Color.red)
|
||||
.frame(width: ShoeGazeBuilderView.recordDotSize, height: ShoeGazeBuilderView.recordDotSize)
|
||||
Text("REC")
|
||||
.font(.caption.monospaced())
|
||||
.foregroundStyle(Color.red)
|
||||
}
|
||||
}
|
||||
|
||||
/// A labelled icon button that opens one of the compact composition sheets.
|
||||
private func compactPanelButton(
|
||||
_ title: String,
|
||||
systemImage: String,
|
||||
action: @escaping () -> Void
|
||||
) -> some View {
|
||||
Button(action: action) {
|
||||
Label(title, systemImage: systemImage)
|
||||
.font(.subheadline)
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
.tint(.gray)
|
||||
}
|
||||
|
||||
/// Compact top strip: performance monitoring kept on screen — the board switch/mixer bar, the
|
||||
/// scope, and the CPU meters. Tempo / Tuner sit below so they don't crowd the transport row.
|
||||
private var compactTopSection: some View {
|
||||
VStack(alignment: .leading, spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||
BoardBarView(
|
||||
shoeGaze: shoeGaze,
|
||||
editingBoardIndex: $selectedBoardIndex,
|
||||
crossfadeSeconds: $crossfadeSeconds,
|
||||
onAddBoard: { addBoard() },
|
||||
onClearBoards: { showClearDialog = true }
|
||||
)
|
||||
|
||||
Divider().overlay(Color.white.opacity(ShoeGazeBuilderView.dividerOpacity))
|
||||
|
||||
// Scope + Tempo/Tuner moved to the header; the CPU meters stay here.
|
||||
LyrebirdStatusView(engine: shoeGaze.engine)
|
||||
}
|
||||
}
|
||||
|
||||
/// The Add-a-pedal palette + routing options, presented as a compact sheet.
|
||||
private var paletteSheet: some View {
|
||||
// A fixed header (title, type filter, Done) over a scrolling list. Not a NavigationStack —
|
||||
// its transparent bar let the list scroll under the title. The palette does not self-wrap in
|
||||
// a ScrollView (the host must), so it is wrapped here.
|
||||
VStack(spacing: 0) {
|
||||
HStack(spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||
Text("Add Pedal")
|
||||
.font(.headline)
|
||||
.foregroundStyle(Color.white)
|
||||
Spacer()
|
||||
pedalFilterMenu
|
||||
Button("Done") { showPaletteSheet = false }
|
||||
.fontWeight(.semibold)
|
||||
}
|
||||
.padding()
|
||||
|
||||
Divider().overlay(Color.white.opacity(ShoeGazeBuilderView.dividerOpacity))
|
||||
|
||||
ScrollView {
|
||||
PedalPaletteView(
|
||||
axis: .vertical,
|
||||
filter: $pedalFilter,
|
||||
showsFilterMenu: false,
|
||||
onAdd: { type in addPedal(type: type); showPaletteSheet = false },
|
||||
onRouting: { action in performRouting(action); showPaletteSheet = false }
|
||||
)
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
|
||||
.preferredColorScheme(.dark)
|
||||
// One fixed detent (no resize-drag) and drags scroll the list instead of the sheet.
|
||||
.presentationDetents([.fraction(ShoeGazeBuilderView.paletteSheetHeightFraction)])
|
||||
.presentationContentInteraction(.scrolls)
|
||||
}
|
||||
|
||||
/// The type-filter menu shown in the Add-Pedal sheet header, bound to `pedalFilter`.
|
||||
private var pedalFilterMenu: some View {
|
||||
Menu {
|
||||
Button("All Types") { pedalFilter = nil }
|
||||
Divider()
|
||||
ForEach(PedalCategory.allCases) { category in
|
||||
Button(category.rawValue) { pedalFilter = category }
|
||||
}
|
||||
} label: {
|
||||
HStack(spacing: 3) {
|
||||
Image(systemName: "line.3.horizontal.decrease.circle")
|
||||
Text(pedalFilter?.rawValue ?? "All").lineLimit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Engine configuration (sample rate, input/output channel counts, input source), presented as
|
||||
/// a compact sheet — the set-and-forget composition controls.
|
||||
private var settingsSheet: some View {
|
||||
NavigationStack {
|
||||
// A plain scroll (not a Form) so the engine controls' horizontal row has the full sheet
|
||||
// width — a Form row compresses it and clips the Start button to "S…".
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: ShoeGazeBuilderView.sectionSpacing) {
|
||||
Text("Engine")
|
||||
.font(.headline)
|
||||
.foregroundStyle(Color.white)
|
||||
EngineConfigView(
|
||||
shoeGaze: shoeGaze,
|
||||
hardwareSampleRate: hardwareSampleRate,
|
||||
onConfigApplied: { transportTick.toggle() }
|
||||
)
|
||||
|
||||
Divider().overlay(Color.white.opacity(ShoeGazeBuilderView.dividerOpacity))
|
||||
|
||||
HStack {
|
||||
Text("Input")
|
||||
.font(.headline)
|
||||
.foregroundStyle(Color.white)
|
||||
Spacer()
|
||||
Picker("Input", selection: inputBinding) {
|
||||
Text("Test Loop").tag(ShoeGazeBuilderView.testLoopTag)
|
||||
if shoeGaze.engine.numInputChannels > 0 {
|
||||
ForEach(Array(0..<shoeGaze.engine.numInputChannels), id: \.self) { channel in
|
||||
Text("In \(channel)").tag(channel)
|
||||
}
|
||||
} else if onEnableLiveInput != nil {
|
||||
Text("Live Input").tag(0)
|
||||
}
|
||||
}
|
||||
.labelsHidden()
|
||||
.pickerStyle(.menu)
|
||||
}
|
||||
|
||||
#if !os(macOS)
|
||||
Divider().overlay(Color.white.opacity(ShoeGazeBuilderView.dividerOpacity))
|
||||
Text("Recording")
|
||||
.font(.headline)
|
||||
.foregroundStyle(Color.white)
|
||||
recordingFolderPicker
|
||||
#endif
|
||||
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
.padding()
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
.navigationTitle("Settings")
|
||||
#if os(iOS)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
#endif
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .confirmationAction) {
|
||||
Button("Done") { showSettingsSheet = false }
|
||||
}
|
||||
}
|
||||
}
|
||||
.preferredColorScheme(.dark)
|
||||
}
|
||||
|
||||
/// Top section: the scope + CPU meters on the left (sized to align with the mixer's
|
||||
@@ -415,7 +785,8 @@ public struct ShoeGazeBuilderView: View {
|
||||
shoeGaze: shoeGaze,
|
||||
editingBoardIndex: $selectedBoardIndex,
|
||||
crossfadeSeconds: $crossfadeSeconds,
|
||||
onAddBoard: { addBoard() }
|
||||
onAddBoard: { addBoard() },
|
||||
onClearBoards: { showClearDialog = true }
|
||||
)
|
||||
Divider().overlay(Color.white.opacity(ShoeGazeBuilderView.dividerOpacity))
|
||||
pedalPickerRow
|
||||
@@ -530,11 +901,14 @@ public struct ShoeGazeBuilderView: View {
|
||||
|
||||
// MARK: - Transport row
|
||||
|
||||
private var transportRow: some View {
|
||||
/// Two-row header. Left: the title with the Tempo / Tuner toggles stacked and left-aligned
|
||||
/// beside it. Right: the engine options (row 1) over the input controls (row 2), trailing-
|
||||
/// aligned so both right edges line up. Keeping it two rows tall frees canvas for the pedals.
|
||||
private var headerSection: some View {
|
||||
_ = transportTick
|
||||
return HStack(spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||
return HStack(alignment: .top, spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||
VStack(alignment: .leading, spacing: 1) {
|
||||
Text("ShoeGaze Builder")
|
||||
Text("ShoeGaze")
|
||||
.font(.title2).bold()
|
||||
.foregroundStyle(Color.white)
|
||||
currentRigLabel
|
||||
@@ -551,9 +925,18 @@ public struct ShoeGazeBuilderView: View {
|
||||
.foregroundStyle(Color.red)
|
||||
}
|
||||
}
|
||||
Spacer()
|
||||
|
||||
// Tempo over Tuner, left-aligned to each other.
|
||||
VStack(alignment: .leading, spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||
TempoView(shoeGaze: shoeGaze)
|
||||
TunerView(shoeGaze: shoeGaze)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
// Right column: engine options over input controls, both right-aligned.
|
||||
VStack(alignment: .trailing, spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||
HStack(spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||
if let midi: MIDIController = midi {
|
||||
MIDIIndicatorView(controller: midi) { showMIDISheet = true }
|
||||
}
|
||||
@@ -565,6 +948,38 @@ public struct ShoeGazeBuilderView: View {
|
||||
onConfigApplied: { transportTick.toggle() }
|
||||
)
|
||||
}
|
||||
.frame(height: TempoView.enabledHeight)
|
||||
|
||||
HStack(spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||
// Mute-rig-while-tuning toggle sits to the left of the input selector.
|
||||
Toggle("Mute rig", isOn: Binding(
|
||||
get: { shoeGaze.tunerMutesRig },
|
||||
set: { shoeGaze.tunerMutesRig = $0 }
|
||||
))
|
||||
.toggleStyle(.switch)
|
||||
|
||||
Text("Input:")
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(Color.white.opacity(ShoeGazeBuilderView.labelOpacity))
|
||||
Picker("Input", selection: inputBinding) {
|
||||
Text("Test Loop").tag(ShoeGazeBuilderView.testLoopTag)
|
||||
if shoeGaze.engine.numInputChannels > 0 {
|
||||
ForEach(Array(0..<shoeGaze.engine.numInputChannels), id: \.self) { channel in
|
||||
Text("In \(channel)").tag(channel)
|
||||
}
|
||||
} else if onEnableLiveInput != nil {
|
||||
// No input channel yet: offer live input; selecting it asks the host to
|
||||
// request mic access and rebuild the engine with one (channel 0).
|
||||
Text("Live Input").tag(0)
|
||||
}
|
||||
}
|
||||
.labelsHidden()
|
||||
.pickerStyle(.menu)
|
||||
.foregroundStyle(Color.white)
|
||||
}
|
||||
.frame(height: TempoView.enabledHeight)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens the in-app help. Shown on both platforms; macOS also has a Help menu item.
|
||||
@@ -595,40 +1010,6 @@ public struct ShoeGazeBuilderView: View {
|
||||
.help("Bypass the entire rig — every board passes your dry input straight through")
|
||||
}
|
||||
|
||||
// MARK: - Input + board + save/load row
|
||||
|
||||
private var ioRow: some View {
|
||||
HStack(spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||
Text("Input:")
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(Color.white.opacity(ShoeGazeBuilderView.labelOpacity))
|
||||
Picker("Input", selection: inputBinding) {
|
||||
Text("Test Loop").tag(ShoeGazeBuilderView.testLoopTag)
|
||||
if shoeGaze.engine.numInputChannels > 0 {
|
||||
ForEach(Array(0..<shoeGaze.engine.numInputChannels), id: \.self) { channel in
|
||||
Text("In \(channel)").tag(channel)
|
||||
}
|
||||
} else if onEnableLiveInput != nil {
|
||||
// No input channel yet: offer live input; selecting it asks the host to
|
||||
// request mic access and rebuild the engine with one (channel 0).
|
||||
Text("Live Input").tag(0)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.menu)
|
||||
.foregroundStyle(Color.white)
|
||||
|
||||
Button("Boards…") { showBoardsSheet = true }
|
||||
.buttonStyle(.bordered).tint(.orange)
|
||||
.help("Rename, reorder, or delete boards")
|
||||
|
||||
Button("Clear") { showClearDialog = true }
|
||||
.buttonStyle(.bordered).tint(.red)
|
||||
.help("Remove all boards in the current rig (with the option to save first)")
|
||||
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Board area
|
||||
|
||||
private var boardArea: some View {
|
||||
@@ -859,6 +1240,26 @@ public struct ShoeGazeBuilderView: View {
|
||||
#if !os(macOS)
|
||||
/// iOS recording controls: choose an output folder, then start/stop recording.
|
||||
private var recordingRow: some View {
|
||||
HStack(spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||
recordingFolderPicker
|
||||
Spacer()
|
||||
recordButton
|
||||
}
|
||||
}
|
||||
|
||||
/// The Record / Stop-Recording button (performance control; lives in the compact header).
|
||||
private var recordButton: some View {
|
||||
Button(shoeGaze.isRecording ? "Stop Recording" : "Record") {
|
||||
toggleRecording()
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
.tint(shoeGaze.isRecording ? .red : .accentColor)
|
||||
.disabled(shoeGaze.recordingFolder == nil && !shoeGaze.isRecording)
|
||||
}
|
||||
|
||||
/// The recording-folder chooser + current folder name (a set-and-forget control; shown in the
|
||||
/// compact Settings sheet).
|
||||
private var recordingFolderPicker: some View {
|
||||
HStack(spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||
Button("Recording Folder…") { showRecordingFolderImporter = true }
|
||||
.buttonStyle(.bordered).tint(.blue)
|
||||
@@ -867,13 +1268,6 @@ public struct ShoeGazeBuilderView: View {
|
||||
.foregroundStyle(Color.white.opacity(ShoeGazeBuilderView.folderLabelOpacity))
|
||||
.lineLimit(1)
|
||||
.truncationMode(.middle)
|
||||
Spacer()
|
||||
Button(shoeGaze.isRecording ? "Stop Recording" : "Record") {
|
||||
toggleRecording()
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
.tint(shoeGaze.isRecording ? .red : .accentColor)
|
||||
.disabled(shoeGaze.recordingFolder == nil && !shoeGaze.isRecording)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// TempoEnabledEnvironment.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import SwiftUI
|
||||
|
||||
/// Environment flag mirroring ``ShoeGaze/tempoEnabled`` so leaf views (e.g. ``PedalSwitchView``)
|
||||
/// can disable tempo-synced controls without each needing a reference to the session. Set once
|
||||
/// near the builder root; defaults to `true`.
|
||||
private struct TempoEnabledKey: EnvironmentKey {
|
||||
static let defaultValue: Bool = true
|
||||
}
|
||||
|
||||
extension EnvironmentValues {
|
||||
/// `true` when the tempo indicator is shown and tempo-synced features are active.
|
||||
var shoeGazeTempoEnabled: Bool {
|
||||
get { self[TempoEnabledKey.self] }
|
||||
set { self[TempoEnabledKey.self] = newValue }
|
||||
}
|
||||
}
|
||||
@@ -24,10 +24,10 @@ public struct TempoView: View {
|
||||
private static let minBpm: Double = 30.0
|
||||
private static let maxBpm: Double = 300.0
|
||||
private static let bpmStep: Double = 1.0
|
||||
private static let ledDiameter: CGFloat = 16
|
||||
private static let panelSpacing: CGFloat = 10
|
||||
private static let rowSpacing: CGFloat = 14
|
||||
private static let tapAreaSize: CGFloat = 64
|
||||
private static let ledDiameter: CGFloat = 14
|
||||
private static let rowSpacing: CGFloat = 10
|
||||
/// Fixed row height = the enabled (BPM/TAP-visible) height, so toggling doesn't shift layout.
|
||||
static let enabledHeight: CGFloat = 34
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
@@ -47,8 +47,16 @@ public struct TempoView: View {
|
||||
// MARK: - Body
|
||||
|
||||
public var body: some View {
|
||||
VStack(spacing: TempoView.panelSpacing) {
|
||||
HStack(spacing: TempoView.rowSpacing) {
|
||||
Button(shoeGaze.tempoEnabled ? "Tempo: On" : "Tempo: Off") {
|
||||
shoeGaze.setTempoEnabled(!shoeGaze.tempoEnabled)
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
.tint(shoeGaze.tempoEnabled ? .green : .gray)
|
||||
.fixedSize()
|
||||
.help("Show the tempo indicator and enable tempo-synced controls")
|
||||
|
||||
if shoeGaze.tempoEnabled {
|
||||
led
|
||||
Text("\(Int(displayedBpm.rounded())) BPM")
|
||||
.font(.system(size: 18, weight: .semibold, design: .rounded))
|
||||
@@ -67,12 +75,15 @@ public struct TempoView: View {
|
||||
step: TempoView.bpmStep
|
||||
)
|
||||
.labelsHidden()
|
||||
}
|
||||
|
||||
tapArea
|
||||
}
|
||||
.task {
|
||||
while !Task.isCancelled {
|
||||
}
|
||||
// Pin to the enabled height (BPM / stepper / TAP visible) so toggling tempo on/off never
|
||||
// shifts the surrounding layout.
|
||||
.frame(height: TempoView.enabledHeight)
|
||||
.task(id: shoeGaze.tempoEnabled) {
|
||||
while shoeGaze.tempoEnabled && !Task.isCancelled {
|
||||
let beat: Double = shoeGaze.clock.currentBeat
|
||||
let phase: Double = beat - beat.rounded(.down)
|
||||
ledOn = phase < TempoView.flashDutyCycle
|
||||
@@ -91,17 +102,17 @@ public struct TempoView: View {
|
||||
}
|
||||
|
||||
private var tapArea: some View {
|
||||
// A standard-height bordered button (not a tall circle) so the tempo row matches the
|
||||
// height of the title and the engine-option buttons and top-aligns cleanly with them.
|
||||
Button {
|
||||
shoeGaze.tapTempo()
|
||||
displayedBpm = shoeGaze.clock.bpm
|
||||
} label: {
|
||||
Text("TAP")
|
||||
.font(.system(size: 14, weight: .bold, design: .rounded))
|
||||
.frame(width: TempoView.tapAreaSize, height: TempoView.tapAreaSize)
|
||||
.background(Color.white.opacity(0.08))
|
||||
.clipShape(Circle())
|
||||
.font(.system(size: 13, weight: .bold, design: .rounded))
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.buttonStyle(.bordered)
|
||||
.tint(.gray)
|
||||
.foregroundStyle(Color.white)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,10 +26,12 @@ public struct TunerView: View {
|
||||
private static let trackingConfidenceThreshold: Double = 0.8
|
||||
/// Opacity applied to the latched readout while not actively tracking.
|
||||
private static let untrackedOpacity: Double = 0.35
|
||||
private static let panelSpacing: CGFloat = 10
|
||||
private static let rowSpacing: CGFloat = 14
|
||||
private static let noteFontSize: CGFloat = 34
|
||||
private static let readoutSpacing: CGFloat = 10
|
||||
private static let noteFontSize: CGFloat = 24
|
||||
private static let statusFontSize: CGFloat = 10
|
||||
/// Fixed row height = the engaged (readout-visible) height, so toggling doesn't shift layout.
|
||||
static let engagedHeight: CGFloat = 34
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
@@ -50,25 +52,23 @@ public struct TunerView: View {
|
||||
// MARK: - Body
|
||||
|
||||
public var body: some View {
|
||||
VStack(spacing: TunerView.panelSpacing) {
|
||||
// Single horizontal row so engaging the tuner grows it sideways, not downward — the
|
||||
// transport row keeps its height and the pedals below don't jump.
|
||||
HStack(spacing: TunerView.rowSpacing) {
|
||||
Button(shoeGaze.tunerEngaged ? "Tuner: On" : "Tuner: Off") {
|
||||
shoeGaze.toggleTunerEngaged()
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
.tint(shoeGaze.tunerEngaged ? .green : .gray)
|
||||
|
||||
Toggle("Mute rig", isOn: Binding(
|
||||
get: { shoeGaze.tunerMutesRig },
|
||||
set: { shoeGaze.tunerMutesRig = $0 }
|
||||
))
|
||||
.toggleStyle(.switch)
|
||||
}
|
||||
.fixedSize()
|
||||
|
||||
if shoeGaze.tunerEngaged {
|
||||
readout
|
||||
}
|
||||
}
|
||||
// Pin to the engaged height (the taller readout state) so toggling the tuner on/off never
|
||||
// shifts the surrounding layout by a few pixels.
|
||||
.frame(height: TunerView.engagedHeight)
|
||||
.task(id: shoeGaze.tunerEngaged) {
|
||||
while shoeGaze.tunerEngaged && !Task.isCancelled {
|
||||
updateReading()
|
||||
@@ -100,7 +100,7 @@ public struct TunerView: View {
|
||||
@ViewBuilder
|
||||
private var readout: some View {
|
||||
if let pitch: TunerPitchReading = latchedPitch {
|
||||
VStack(spacing: 6) {
|
||||
HStack(spacing: TunerView.readoutSpacing) {
|
||||
Text(pitch.noteName)
|
||||
.font(.system(size: TunerView.noteFontSize, weight: .bold, design: .rounded))
|
||||
.foregroundStyle(TunerView.color(forCents: pitch.cents))
|
||||
@@ -111,7 +111,7 @@ public struct TunerView: View {
|
||||
}
|
||||
.opacity(isTracking ? 1.0 : TunerView.untrackedOpacity)
|
||||
} else {
|
||||
VStack(spacing: 6) {
|
||||
HStack(spacing: TunerView.readoutSpacing) {
|
||||
Text("—")
|
||||
.font(.system(size: TunerView.noteFontSize, weight: .bold, design: .rounded))
|
||||
.foregroundStyle(Color.white.opacity(0.4))
|
||||
|
||||
@@ -163,13 +163,13 @@ struct LooperPedalTests {
|
||||
@Test func exposesLooperControls() throws {
|
||||
let pedal: LooperPedal = LooperPedal()
|
||||
#expect(pedal.effectKnobs.map { $0.label } == ["Crossfade", "Playback", "Overdub", "Feedback"])
|
||||
#expect(pedal.effectSwitches.map { $0.label } == ["Sync"])
|
||||
#expect(pedal.effectSwitches.map { $0.label } == ["Sync to Tempo"])
|
||||
#expect(pedal.effectButtons.isEmpty)
|
||||
#expect(pedal.effectTransportButtons.map { $0.label } == ["Loop", "Stop", "Cue Stop", "Reverse", "Reset"])
|
||||
}
|
||||
|
||||
@Test func looperIsDoubleWidth() throws {
|
||||
#expect(LooperPedal().widthUnits == 2)
|
||||
@Test func looperIsTripleWidth() throws {
|
||||
#expect(LooperPedal().widthUnits == 3)
|
||||
#expect(LooperPedal.trackCount == 4)
|
||||
}
|
||||
|
||||
@@ -420,6 +420,75 @@ struct LooperPedalTests {
|
||||
} }
|
||||
}
|
||||
|
||||
@Test func reverseDoesNotJumpPlayHeadPosition() throws {
|
||||
let sampleRate: Double = 44100.0
|
||||
let (engine, clock, pedal): (SynthesisEngine, LyrebirdClock, LooperPedal) =
|
||||
try makeQuantizedFixture(bpm: 120.0, sampleRate: sampleRate)
|
||||
withExtendedLifetime(engine) { withExtendedLifetime(clock) {
|
||||
// Record a 1-second master (record start at 0, close at 44100) → masterLength = 44100.
|
||||
pedal.pressLoop()
|
||||
pedal.applyQuantizedTransport(.beginMaster, generation: pedal.transportGeneration, at: SampleTime(0))
|
||||
let closeSample: SampleTime = SampleTime(sampleRate)
|
||||
pedal.pressLoop()
|
||||
pedal.applyQuantizedTransport(.closeMaster, generation: pedal.transportGeneration, at: closeSample)
|
||||
#expect(pedal.transportState == .playing)
|
||||
|
||||
// A quarter of the way in, moving forward.
|
||||
let quarter: SampleTime = closeSample + SampleTime(sampleRate * 0.25)
|
||||
#expect(abs(pedal.playHeadFraction(at: quarter) - 0.25) < 0.001)
|
||||
|
||||
// Reversing here must NOT jump the read-out to the mirror point (0.75) — it stays at 0.25.
|
||||
pedal.applyReverse(at: quarter)
|
||||
#expect(abs(pedal.playHeadFraction(at: quarter) - 0.25) < 0.001,
|
||||
"reverse must continue from the current position, not jump to duration − position")
|
||||
|
||||
// Advancing time now walks the position backward from 0.25.
|
||||
let laterBy: SampleTime = SampleTime(sampleRate * 0.10)
|
||||
#expect(abs(pedal.playHeadFraction(at: quarter + laterBy) - 0.15) < 0.001,
|
||||
"reversed play head moves backward from the reverse point")
|
||||
} }
|
||||
}
|
||||
|
||||
@Test func reverseDefersToNextBeatInSyncMode() throws {
|
||||
let sampleRate: Double = 44100.0
|
||||
let (engine, clock, pedal): (SynthesisEngine, LyrebirdClock, LooperPedal) =
|
||||
try makeQuantizedFixture(bpm: 120.0, sampleRate: sampleRate)
|
||||
withExtendedLifetime(engine) { withExtendedLifetime(clock) {
|
||||
pedal.pressLoop()
|
||||
pedal.applyQuantizedTransport(.beginMaster, generation: pedal.transportGeneration, at: SampleTime(0))
|
||||
pedal.pressLoop()
|
||||
pedal.applyQuantizedTransport(.closeMaster, generation: pedal.transportGeneration, at: SampleTime(sampleRate))
|
||||
#expect(pedal.transportState == .playing)
|
||||
#expect(pedal.overdubbingTrackIndex == 0)
|
||||
|
||||
// Sync mode (default): the press is deferred — direction and overdub are untouched.
|
||||
pedal.toggleReverse()
|
||||
#expect(pedal.reverse == 0.0, "sync-mode reverse waits for the next beat")
|
||||
#expect(pedal.overdubbingTrackIndex == 0, "overdub survives until the deferred reverse fires")
|
||||
|
||||
// The beat arrives: direction flips and the overdub ends.
|
||||
pedal.applyDeferredReverse(generation: pedal.reverseGeneration, at: SampleTime(sampleRate * 2))
|
||||
#expect(pedal.reverse == 1.0)
|
||||
#expect(pedal.overdubbingTrackIndex == nil, "engaging reverse ends the overdub")
|
||||
} }
|
||||
}
|
||||
|
||||
@Test func reverseIsImmediateInFreeMode() throws {
|
||||
let (engine, clock, pedal): (SynthesisEngine, LyrebirdClock, LooperPedal) =
|
||||
try makeQuantizedFixture(bpm: 120.0, sampleRate: 44100.0)
|
||||
withExtendedLifetime(engine) { withExtendedLifetime(clock) {
|
||||
pedal.syncToBeat = 0.0
|
||||
pedal.pressLoop() // record A (immediate)
|
||||
pedal.pressLoop() // play + overdub A (immediate)
|
||||
#expect(pedal.transportState == .playing)
|
||||
|
||||
// Free mode: reverse applies right away, even with a clock present.
|
||||
pedal.toggleReverse()
|
||||
#expect(pedal.reverse == 1.0, "free-mode reverse is immediate")
|
||||
#expect(pedal.overdubbingTrackIndex == nil, "engaging reverse ends the overdub")
|
||||
} }
|
||||
}
|
||||
|
||||
@Test func engineStopResetsLooperAndPostsNotice() throws {
|
||||
let (engine, clock, pedal): (SynthesisEngine, LyrebirdClock, LooperPedal) =
|
||||
try makeQuantizedFixture(bpm: 120.0, sampleRate: 44100.0)
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
// TempoEnableTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Testing
|
||||
import Foundation
|
||||
import LyrebirdSynth
|
||||
@testable import LyrebirdShoeGaze
|
||||
|
||||
@MainActor
|
||||
@Suite("Tempo enable")
|
||||
struct TempoEnableTests {
|
||||
|
||||
private func makeRigWithLooper() throws -> (ShoeGaze, SynthesisEngine, URL, LooperPedal) {
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.1)
|
||||
let sg: ShoeGaze = ShoeGaze(engine: engine)
|
||||
let board: PedalBoard = try sg.addBoard()
|
||||
guard let looper: LooperPedal = PedalRegistry.makePedal(type: "Looper") as? LooperPedal else {
|
||||
fatalError("Looper pedal must be registered")
|
||||
}
|
||||
try board.add(looper)
|
||||
try sg.finalizeBoard(board)
|
||||
return (sg, engine, url, looper)
|
||||
}
|
||||
|
||||
@Test func tempoEnabledDefaultsOn() throws {
|
||||
let (sg, _, url, _): (ShoeGaze, SynthesisEngine, URL, LooperPedal) = try makeRigWithLooper()
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
#expect(sg.tempoEnabled, "tempo indicator is on by default")
|
||||
}
|
||||
|
||||
@Test func looperSyncSwitchIsTempoDependent() throws {
|
||||
let (_, _, url, looper): (ShoeGaze, SynthesisEngine, URL, LooperPedal) = try makeRigWithLooper()
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
let syncSwitch: PedalSwitch? = looper.effectSwitches.first { $0.tempoDependent }
|
||||
#expect(syncSwitch != nil, "the looper Sync-to-Tempo switch must be marked tempo-dependent")
|
||||
}
|
||||
|
||||
@Test func disablingTempoForcesSyncSwitchesOff() throws {
|
||||
let (sg, _, url, looper): (ShoeGaze, SynthesisEngine, URL, LooperPedal) = try makeRigWithLooper()
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
looper.syncToBeat = 1.0 // engage Sync
|
||||
sg.setTempoEnabled(false)
|
||||
#expect(!sg.tempoEnabled)
|
||||
#expect(looper.syncToBeat == 0.0, "disabling tempo forces the looper back to Free")
|
||||
|
||||
// Re-enabling leaves it Free — the user re-selects Sync if wanted.
|
||||
sg.setTempoEnabled(true)
|
||||
#expect(sg.tempoEnabled)
|
||||
#expect(looper.syncToBeat == 0.0)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user