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:
@@ -42,6 +42,8 @@ public enum PedalRegistry {
|
||||
"Compressor": { CompressorPedal() },
|
||||
"Mutant": { MutantPedal() },
|
||||
"Auto-Wah": { AutoWahPedal() },
|
||||
"Wah": { WahPedal() },
|
||||
"Volume": { VolumePedal() },
|
||||
"Feedback Delay": { FeedbackDelayPedal() },
|
||||
"Multi-Tap Delay": { MultiTapDelayPedal() },
|
||||
"Octave Splitter": { OctaveUpSplitterPedal() },
|
||||
|
||||
@@ -59,6 +59,65 @@ extension ShoeGaze {
|
||||
return try rebuildBoard(board, from: BoardState(label: board.label, segments: segments))
|
||||
}
|
||||
|
||||
/// Inserts a pedal of the given type at `index` within a lane, shifting later pedals along.
|
||||
///
|
||||
/// `index` addresses the lane's own pedal order (`board.pedals` for ``PedalLane/main``; the
|
||||
/// branch's pedal list for a branch lane) and follows insert-before semantics: the new pedal
|
||||
/// lands immediately before the pedal currently at `index`. An `index` equal to the lane's pedal
|
||||
/// count appends to the end (same placement as ``appendPedal(_:to:lane:)``). The pedal is created
|
||||
/// at its constructor defaults and the board is rebuilt via ``rebuildBoard(_:from:)``.
|
||||
///
|
||||
/// - Important: Editing rebuilds the board through the same path as preset load; safe on a
|
||||
/// running engine with at most one block of glitch (see ``rebuildBoard(_:from:)``).
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - kind: The pedal type. Its `rawValue` must be a key in `PedalRegistry.builtIn`.
|
||||
/// - index: Insert-before position in the lane's pedal order. Valid range `0...laneCount`.
|
||||
/// - board: The board to edit. Must have been returned by `addBoard()` on this instance.
|
||||
/// - lane: Which lane to insert into. Defaults to ``PedalLane/main``.
|
||||
/// - Returns: The rebuilt board occupying the same slot in `boards`.
|
||||
/// - Throws: `ShoeGazeError.unknownPedalType`, `.pedalIndexOutOfRange`, `.notABranchRegion`, or
|
||||
/// any error from ``rebuildBoard(_:from:)``.
|
||||
@discardableResult
|
||||
public func insertPedal(
|
||||
_ kind: PedalType,
|
||||
at index: Int,
|
||||
to board: PedalBoard,
|
||||
lane: PedalLane = .main
|
||||
) throws -> PedalBoard {
|
||||
let type: String = kind.rawValue
|
||||
guard PedalRegistry.builtIn[type] != nil else {
|
||||
throw ShoeGazeError.unknownPedalType(type)
|
||||
}
|
||||
let newState: PedalState = PedalState(type: type, knobValues: [], switchValues: [], bypass: 0.0)
|
||||
|
||||
var segments: [BoardSegmentState] = board.captureState().segments
|
||||
switch lane {
|
||||
case .main:
|
||||
let pedalPositions: [Int] = linearPedalSegmentIndices(segments)
|
||||
guard index >= 0 && index <= pedalPositions.count else {
|
||||
throw ShoeGazeError.pedalIndexOutOfRange(index: index, count: pedalPositions.count)
|
||||
}
|
||||
if index < pedalPositions.count {
|
||||
segments.insert(.pedal(newState), at: pedalPositions[index])
|
||||
} else if let lastPedalIndex: Int = pedalPositions.last {
|
||||
// Inserting at the end: land right after the last linear pedal, before any trailing
|
||||
// routing node — mirrors `appendPedal`'s placement rule.
|
||||
segments.insert(.pedal(newState), at: lastPedalIndex + 1)
|
||||
} else {
|
||||
segments.append(.pedal(newState))
|
||||
}
|
||||
case .left, .right:
|
||||
try mutateBranch(&segments, lane: lane) { branch in
|
||||
guard index >= 0 && index <= branch.count else {
|
||||
throw ShoeGazeError.pedalIndexOutOfRange(index: index, count: branch.count)
|
||||
}
|
||||
branch.insert(newState, at: index)
|
||||
}
|
||||
}
|
||||
return try rebuildBoard(board, from: BoardState(label: board.label, segments: segments))
|
||||
}
|
||||
|
||||
/// Removes the pedal at `index` within a lane.
|
||||
///
|
||||
/// `index` addresses the lane's own pedal order (`board.pedals` for ``PedalLane/main``; the
|
||||
|
||||
@@ -18,7 +18,7 @@ extension ShoeGaze {
|
||||
/// - Returns: A `ShoeGazeState` reflecting the current rig.
|
||||
public func captureState() -> ShoeGazeState {
|
||||
let boardStates: [BoardState] = boards.map { $0.captureState() }
|
||||
return ShoeGazeState(boards: boardStates)
|
||||
return ShoeGazeState(boards: boardStates, midiMap: midiMap)
|
||||
}
|
||||
|
||||
/// Captures the current rig as a named ``RigEntry`` suitable for the rig library.
|
||||
@@ -95,6 +95,9 @@ extension ShoeGaze {
|
||||
|
||||
teardown()
|
||||
try rebuildAllBoards(from: state)
|
||||
// Restore the rig's MIDI bindings after the boards exist, so a MIDIController re-reading the
|
||||
// map resolves against the freshly rebuilt boards.
|
||||
midiMap = state.midiMap
|
||||
}
|
||||
|
||||
/// Rebuilds every board from a snapshot with all-or-nothing semantics.
|
||||
|
||||
@@ -27,16 +27,26 @@ public struct ShoeGazeState: Codable, Equatable {
|
||||
/// All board snapshots in the order they were created.
|
||||
public let boards: [BoardState]
|
||||
|
||||
/// The rig's MIDI foot-controller bindings, or `nil` for a rig saved without any.
|
||||
///
|
||||
/// Optional so rigs written before MIDI mapping existed decode cleanly (the synthesized
|
||||
/// `init(from:)` uses `decodeIfPresent`, yielding `nil` for the missing key) — no format
|
||||
/// version bump is required for this additive field.
|
||||
public let midiMap: MIDIMap?
|
||||
|
||||
/// Creates a rig state snapshot.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - version: Preset format version. Defaults to `presetFormatVersion`.
|
||||
/// - boards: Ordered list of board state snapshots.
|
||||
/// - midiMap: The rig's MIDI bindings, or `nil` when there are none. Defaults to `nil`.
|
||||
public init(
|
||||
version: Int = presetFormatVersion,
|
||||
boards: [BoardState]
|
||||
boards: [BoardState],
|
||||
midiMap: MIDIMap? = nil
|
||||
) {
|
||||
self.version = version
|
||||
self.boards = boards
|
||||
self.midiMap = midiMap
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user