Fix CC section: stop switch actions leaking in; add board-level target
The MIDI Mapping sheet's two sections both keyed their ForEach rows on the enumeration offset (0,1,2…) and the Expression section mixed a bare header Text with a ForEach. SwiftUI's List reused structurally identical row views across the sections, so Program-Change switch rows (e.g. "Board 1 · Solo", "Board 1 · Overdrive · Bypass") leaked into the Expression (CC) section and their Learn button armed a Program Change instead of a Control Change. - Rebuild both sections from precomputed row models with globally-unique, section-namespaced string ids and a single ForEach each; no bare headers. - CC target is now an enum: `.pedalControl` (a knob/slider) or `.boardLevel` (the board fader). Board master level is now CC-assignable, shown as "<Board> · Level". - CC rows are labelled "<Pedal> · <Control>" (e.g. "Overdrive · Drive"). - Stale-binding + steal-on-reassign now key off an address matcher on the target enum. Tests updated for the enum target; added a board-level CC test. 319 green; both app targets build. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -86,45 +86,35 @@ public struct MIDIMap: Codable, Equatable, Sendable {
|
||||
|
||||
// MARK: - CC target
|
||||
|
||||
/// Addresses a single pedal knob to be driven by an expression pedal. `knobIndex` indexes into
|
||||
/// the pedal's `knobs` list (effect knobs, then Mix and Level).
|
||||
public struct CCTarget: Codable, Equatable, Sendable {
|
||||
/// A continuous control an expression pedal can drive — either a specific pedal control (a knob
|
||||
/// or slider, addressed by index into the pedal's ``Pedal/ccMappableControls``) or a board's
|
||||
/// master level. The `*Hint` payloads capture the resolved display name at learn time so a
|
||||
/// binding that no longer matches (chain edited) can be detected and skipped.
|
||||
public enum CCTarget: Codable, Equatable, Sendable {
|
||||
|
||||
/// Index of the board in `ShoeGaze.boards`.
|
||||
public var boardIndex: Int
|
||||
|
||||
/// Index of the pedal in `board.pedals`.
|
||||
public var pedalIndex: Int
|
||||
|
||||
/// Index of the knob in `pedal.knobs`.
|
||||
public var knobIndex: Int
|
||||
|
||||
/// The pedal's `displayName` at learn time, for stale-binding detection.
|
||||
public var pedalNameHint: String?
|
||||
|
||||
/// The knob's label at learn time, for stale-binding detection.
|
||||
public var knobLabelHint: String?
|
||||
|
||||
/// Creates a CC target.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - boardIndex: Index of the board in `ShoeGaze.boards`.
|
||||
/// - pedalIndex: Index of the pedal in `board.pedals`.
|
||||
/// - knobIndex: Index of the knob in `pedal.knobs`.
|
||||
/// - pedalNameHint: Pedal display name at learn time. Defaults to `nil`.
|
||||
/// - knobLabelHint: Knob label at learn time. Defaults to `nil`.
|
||||
public init(
|
||||
/// A knob or slider on a pedal, indexed into `pedal.ccMappableControls`.
|
||||
case pedalControl(
|
||||
boardIndex: Int,
|
||||
pedalIndex: Int,
|
||||
knobIndex: Int,
|
||||
pedalNameHint: String? = nil,
|
||||
knobLabelHint: String? = nil
|
||||
) {
|
||||
self.boardIndex = boardIndex
|
||||
self.pedalIndex = pedalIndex
|
||||
self.knobIndex = knobIndex
|
||||
self.pedalNameHint = pedalNameHint
|
||||
self.knobLabelHint = knobLabelHint
|
||||
controlIndex: Int,
|
||||
pedalNameHint: String?,
|
||||
controlLabelHint: String?
|
||||
)
|
||||
|
||||
/// A board's master output level (the board fader).
|
||||
case boardLevel(boardIndex: Int, boardLabelHint: String?)
|
||||
|
||||
/// Whether two targets address the same control, ignoring the display-name hints (used to
|
||||
/// find and replace a binding regardless of the name captured at learn time).
|
||||
public func addresses(_ other: CCTarget) -> Bool {
|
||||
switch (self, other) {
|
||||
case let (.pedalControl(b1, p1, c1, _, _), .pedalControl(b2, p2, c2, _, _)):
|
||||
return b1 == b2 && p1 == p2 && c1 == c2
|
||||
case let (.boardLevel(b1, _), .boardLevel(b2, _)):
|
||||
return b1 == b2
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user