Add MIDI foot-controller control; board/rig bypass; iOS fixes
Headline: MIDI control for a Behringer FCB1010 (four phases). - MIDIController (Lyrebird MIDI client): connection indicator via source polling, background-queue->main-actor hop, MIDI Learn. - Volume and Wah pedals (Wah reuses the SVF bandpass sweep, driven by pedal position instead of an envelope follower). - CC -> any pedal knob (0-127 mapped across the knob range). - Program Change -> pedal/board/rig toggles: software latch for booleans, exclusive radio for board solo. Positional addressing with display-name hints; stale/out-of-range bindings are skipped, not fired. - Per-rig MIDIMap embedded in ShoeGazeState as an optional field (old rigs decode to nil; no preset version bump). Central MIDI Mapping sheet with Learn/Clear per control. Also included (same working branch): - Full board bypass and rig bypass (dry passthrough via cascaded crossfades in BoardOutputMaster), with UI toggles. - Horizontal pedal picker grouped by category in filter order. - Drag a palette pedal onto a chain card to insert before it (ShoeGaze.insertPedal); tap still appends. - iOS: guard macOS-only .menuStyle(.borderlessButton) to silence the _UIReparentingView warning; iCloud-unavailable alert; keep the device awake while audio runs. Tests: 24 added (Volume/Wah, MIDIMap Codable incl. legacy decode, CC and PC controller behavior, insert/bypass API). Full suite green; macOS and iOS app targets build. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,9 @@
|
||||
#if canImport(AppKit)
|
||||
import AppKit
|
||||
#endif
|
||||
#if canImport(UIKit)
|
||||
import UIKit
|
||||
#endif
|
||||
import SwiftUI
|
||||
import UniformTypeIdentifiers
|
||||
import LyrebirdSynth
|
||||
@@ -73,6 +76,10 @@ public struct ShoeGazeBuilderView: View {
|
||||
private let library: RigLibraryStore
|
||||
private let hardwareSampleRate: () -> Double?
|
||||
|
||||
/// The MIDI controller for foot-controller input, or `nil` when MIDI is unavailable/disabled.
|
||||
/// When present, the transport row shows a connection indicator.
|
||||
private let midi: MIDIController?
|
||||
|
||||
/// Host hook to enable live input when the current engine has no input channel (iOS).
|
||||
/// The host requests microphone access and rebuilds the engine with one input channel,
|
||||
/// preserving the rig, then swaps in a new `ShoeGaze`. `nil` on platforms (macOS) whose
|
||||
@@ -91,6 +98,13 @@ public struct ShoeGazeBuilderView: View {
|
||||
/// Shown when live input is selected but microphone access is denied/restricted.
|
||||
@State private var showMicDeniedAlert: Bool = false
|
||||
|
||||
/// Presents the "iCloud unavailable" guidance alert (rigs saved locally only).
|
||||
@State private var showICloudUnavailableAlert: Bool = false
|
||||
|
||||
/// Guards the automatic one-shot iCloud-unavailable alert so it fires at most once per launch
|
||||
/// (the tappable status icon can still re-present it on demand).
|
||||
@State private var didCheckICloudStatus: Bool = false
|
||||
|
||||
/// Guards the one-time input-source restore in `.onAppear`.
|
||||
@State private var didRestoreInput: Bool = false
|
||||
|
||||
@@ -136,6 +150,9 @@ public struct ShoeGazeBuilderView: View {
|
||||
/// Archive import state (cross-platform).
|
||||
@State private var showImporter: Bool = false
|
||||
|
||||
/// MIDI mapping sheet presentation flag.
|
||||
@State private var showMIDISheet: Bool = false
|
||||
|
||||
#if !os(macOS)
|
||||
/// iOS recording-folder picker presentation flag. (macOS uses the Record menu.)
|
||||
@State private var showRecordingFolderImporter: Bool = false
|
||||
@@ -158,16 +175,20 @@ public struct ShoeGazeBuilderView: View {
|
||||
/// - library: The rig library store. The host should `start()` it (e.g. via
|
||||
/// `RigLibraryBootstrap`); the view shows a loading state until then and highlights the
|
||||
/// persisted current rig once the library has loaded.
|
||||
/// - midi: The MIDI controller for foot-controller input. When non-`nil`, the transport row
|
||||
/// shows a connection indicator. Defaults to `nil`.
|
||||
public init(
|
||||
shoeGaze: ShoeGaze,
|
||||
library: RigLibraryStore,
|
||||
hardwareSampleRate: @escaping () -> Double? = { nil },
|
||||
onEnableLiveInput: (() -> Void)? = nil
|
||||
onEnableLiveInput: (() -> Void)? = nil,
|
||||
midi: MIDIController? = nil
|
||||
) {
|
||||
self.shoeGaze = shoeGaze
|
||||
self.library = library
|
||||
self.hardwareSampleRate = hardwareSampleRate
|
||||
self.onEnableLiveInput = onEnableLiveInput
|
||||
self.midi = midi
|
||||
}
|
||||
|
||||
// MARK: - Body
|
||||
@@ -197,8 +218,15 @@ public struct ShoeGazeBuilderView: View {
|
||||
.onAppear {
|
||||
restoreInputSelection()
|
||||
restoreCurrentRig()
|
||||
syncIdleTimer()
|
||||
maybeWarnICloudUnavailable()
|
||||
}
|
||||
.onDisappear { releaseIdleTimer() }
|
||||
.onChange(of: transportTick) { syncIdleTimer() }
|
||||
.onChange(of: library.isLoaded) {
|
||||
restoreCurrentRig()
|
||||
maybeWarnICloudUnavailable()
|
||||
}
|
||||
.onChange(of: library.isLoaded) { restoreCurrentRig() }
|
||||
.onChange(of: currentRigID) { persistCurrentRigID() }
|
||||
.background(boardsSheetAnchor)
|
||||
.background(rigExportAnchor)
|
||||
@@ -261,9 +289,37 @@ public struct ShoeGazeBuilderView: View {
|
||||
Text("Live input needs microphone access. Enable it in System Settings › Privacy & "
|
||||
+ "Security › Microphone, then select the input again.")
|
||||
}
|
||||
.alert("iCloud Unavailable", isPresented: $showICloudUnavailableAlert) {
|
||||
Button("OK", role: .cancel) { }
|
||||
} message: {
|
||||
Text("Your rigs are saved on this device only. To sync them across your devices, "
|
||||
+ "sign in to iCloud and turn on iCloud Drive in "
|
||||
+ ShoeGazeBuilderView.settingsAppName
|
||||
+ ", then reopen ShoeGaze.")
|
||||
}
|
||||
#if !os(macOS)
|
||||
.background(recordingFolderImportAnchor)
|
||||
#endif
|
||||
.sheet(isPresented: $showMIDISheet) {
|
||||
if let midi: MIDIController = midi {
|
||||
MIDIMappingSheet(controller: midi, shoeGaze: shoeGaze)
|
||||
}
|
||||
}
|
||||
.overlay(alignment: .top) { midiLearnBanner }
|
||||
}
|
||||
|
||||
/// A banner shown while a control is armed for MIDI Learn, prompting the user to move it.
|
||||
@ViewBuilder
|
||||
private var midiLearnBanner: some View {
|
||||
if let midi: MIDIController = midi, midi.learnTarget != nil {
|
||||
Text("MIDI Learn — press a footswitch or move an expression pedal to assign it")
|
||||
.font(.callout.weight(.semibold))
|
||||
.foregroundStyle(Color.black)
|
||||
.padding(.horizontal, 14)
|
||||
.padding(.vertical, 8)
|
||||
.background(Capsule().fill(Color.orange))
|
||||
.padding(.top, 6)
|
||||
}
|
||||
}
|
||||
|
||||
/// The rig library listing on the far left: every saved rig plus new/save/duplicate/rename/
|
||||
@@ -281,10 +337,45 @@ public struct ShoeGazeBuilderView: View {
|
||||
onDelete: { entry in deleteEntry(entry) },
|
||||
onEraseAll: { showEraseAllDialog = true },
|
||||
onImportArchive: { showImporter = true },
|
||||
onExportArchive: { exportArchiveAction() }
|
||||
onExportArchive: { exportArchiveAction() },
|
||||
onShowCloudStatus: { showICloudUnavailableAlert = true }
|
||||
)
|
||||
}
|
||||
|
||||
// MARK: - Sleep / iCloud status
|
||||
|
||||
/// Platform name for the settings app, used in the iCloud guidance alert.
|
||||
private static let settingsAppName: String = {
|
||||
#if os(macOS)
|
||||
return "System Settings"
|
||||
#else
|
||||
return "Settings"
|
||||
#endif
|
||||
}()
|
||||
|
||||
/// Keeps the device awake while audio is running so a live pedalboard session isn't cut off by
|
||||
/// auto-lock; the assertion is released as soon as the engine stops. iOS/iPadOS only.
|
||||
private func syncIdleTimer() {
|
||||
#if os(iOS)
|
||||
UIApplication.shared.isIdleTimerDisabled = shoeGaze.engine.isRunning
|
||||
#endif
|
||||
}
|
||||
|
||||
/// Clears the keep-awake assertion (view left the screen / app backgrounded).
|
||||
private func releaseIdleTimer() {
|
||||
#if os(iOS)
|
||||
UIApplication.shared.isIdleTimerDisabled = false
|
||||
#endif
|
||||
}
|
||||
|
||||
/// Once the library has resolved, warn the user a single time if it fell back to local-only
|
||||
/// storage (iCloud Drive signed out or disabled). The status icon can re-present on demand.
|
||||
private func maybeWarnICloudUnavailable() {
|
||||
guard library.isLoaded, !library.isICloud, !didCheckICloudStatus else { return }
|
||||
didCheckICloudStatus = true
|
||||
showICloudUnavailableAlert = true
|
||||
}
|
||||
|
||||
/// The main builder column: transport, IO, the scope-plus-mixer/picker top section, then the
|
||||
/// board canvas.
|
||||
private var builderColumn: some View {
|
||||
@@ -454,6 +545,10 @@ public struct ShoeGazeBuilderView: View {
|
||||
}
|
||||
}
|
||||
Spacer()
|
||||
if let midi: MIDIController = midi {
|
||||
MIDIIndicatorView(controller: midi) { showMIDISheet = true }
|
||||
}
|
||||
rigBypassButton
|
||||
EngineConfigView(
|
||||
shoeGaze: shoeGaze,
|
||||
hardwareSampleRate: hardwareSampleRate,
|
||||
@@ -462,6 +557,21 @@ public struct ShoeGazeBuilderView: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// Global rig bypass — routes every board to its dry input at once (pedals skipped). Lit when
|
||||
/// engaged. A live performance panic/compare control.
|
||||
private var rigBypassButton: some View {
|
||||
let bypassed: Bool = shoeGaze.rigBypassed
|
||||
return Button {
|
||||
shoeGaze.toggleRigBypassed()
|
||||
} label: {
|
||||
Label(bypassed ? "Rig Bypassed" : "Bypass Rig", systemImage: "power")
|
||||
.font(.subheadline)
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
.tint(bypassed ? .orange : .gray)
|
||||
.help("Bypass the entire rig — every board passes your dry input straight through")
|
||||
}
|
||||
|
||||
// MARK: - Input + board + save/load row
|
||||
|
||||
private var ioRow: some View {
|
||||
|
||||
Reference in New Issue
Block a user