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:
@@ -34,8 +34,8 @@ public final class MIDIController {
|
||||
|
||||
/// A control armed for MIDI Learn: the next matching message captures a binding to it.
|
||||
public enum LearnTarget: Equatable, Sendable {
|
||||
/// A pedal knob awaiting a Control Change. Addressed positionally (see ``MIDIMap/CCTarget``).
|
||||
case cc(boardIndex: Int, pedalIndex: Int, knobIndex: Int)
|
||||
/// A continuous control awaiting a Control Change (address-only; hints are `nil`).
|
||||
case cc(MIDIMap.CCTarget)
|
||||
/// A toggle action awaiting a Program Change.
|
||||
case action(MIDIMap.Action)
|
||||
}
|
||||
@@ -131,14 +131,8 @@ public final class MIDIController {
|
||||
private func handle(_ message: MIDIMessage) {
|
||||
switch message {
|
||||
case .controlChange(let channel, let controller, let value):
|
||||
if case .cc(let boardIndex, let pedalIndex, let knobIndex) = learnTarget {
|
||||
captureCC(
|
||||
controller: controller,
|
||||
channel: channel,
|
||||
boardIndex: boardIndex,
|
||||
pedalIndex: pedalIndex,
|
||||
knobIndex: knobIndex
|
||||
)
|
||||
if case .cc(let target) = learnTarget {
|
||||
captureCC(controller: controller, channel: channel, target: target)
|
||||
} else {
|
||||
applyCC(controller: controller, channel: channel, value: value)
|
||||
}
|
||||
@@ -163,9 +157,13 @@ public final class MIDIController {
|
||||
|
||||
// MARK: - Learn API
|
||||
|
||||
/// Arms MIDI Learn for a pedal knob: the next incoming Control Change binds to it.
|
||||
public func armCCLearn(boardIndex: Int, pedalIndex: Int, knobIndex: Int) {
|
||||
learnTarget = .cc(boardIndex: boardIndex, pedalIndex: pedalIndex, knobIndex: knobIndex)
|
||||
/// Master-level range for a board fader, mirroring the UI slider.
|
||||
private let boardLevelRange: ClosedRange<Double> = 0.0 ... 1.0
|
||||
|
||||
/// Arms MIDI Learn for a continuous control: the next incoming Control Change binds to it. Pass
|
||||
/// an address-only target (hints `nil`); hints are captured from the live rig at bind time.
|
||||
public func armCCLearn(_ target: MIDIMap.CCTarget) {
|
||||
learnTarget = .cc(target)
|
||||
}
|
||||
|
||||
/// Cancels any in-progress Learn.
|
||||
@@ -173,20 +171,16 @@ public final class MIDIController {
|
||||
learnTarget = nil
|
||||
}
|
||||
|
||||
/// The CC binding currently assigned to a pedal knob, or `nil` if unbound.
|
||||
public func ccBinding(boardIndex: Int, pedalIndex: Int, knobIndex: Int) -> MIDIMap.CCBinding? {
|
||||
shoeGaze?.midiMap?.ccs.first { $0.target.boardIndex == boardIndex
|
||||
&& $0.target.pedalIndex == pedalIndex
|
||||
&& $0.target.knobIndex == knobIndex }
|
||||
/// The CC binding currently assigned to a control, or `nil` if unbound.
|
||||
public func ccBinding(for target: MIDIMap.CCTarget) -> MIDIMap.CCBinding? {
|
||||
shoeGaze?.midiMap?.ccs.first { $0.target.addresses(target) }
|
||||
}
|
||||
|
||||
/// Removes any CC binding assigned to a pedal knob.
|
||||
public func clearCCBinding(boardIndex: Int, pedalIndex: Int, knobIndex: Int) {
|
||||
/// Removes any CC binding assigned to a control.
|
||||
public func clearCCBinding(for target: MIDIMap.CCTarget) {
|
||||
guard let shoeGaze: ShoeGaze = shoeGaze, var map: MIDIMap = shoeGaze.midiMap else { return }
|
||||
let before: Int = map.ccs.count
|
||||
map.ccs.removeAll { $0.target.boardIndex == boardIndex
|
||||
&& $0.target.pedalIndex == pedalIndex
|
||||
&& $0.target.knobIndex == knobIndex }
|
||||
map.ccs.removeAll { $0.target.addresses(target) }
|
||||
guard map.ccs.count != before else { return }
|
||||
shoeGaze.midiMap = map
|
||||
onMapChanged?()
|
||||
@@ -194,66 +188,76 @@ public final class MIDIController {
|
||||
|
||||
// MARK: - CC handling
|
||||
|
||||
/// Captures a learned CC binding for the armed knob and clears the Learn state.
|
||||
private func captureCC(
|
||||
controller: UInt8,
|
||||
channel: UInt8,
|
||||
boardIndex: Int,
|
||||
pedalIndex: Int,
|
||||
knobIndex: Int
|
||||
) {
|
||||
/// Captures a learned CC binding for the armed control and clears the Learn state.
|
||||
private func captureCC(controller: UInt8, channel: UInt8, target: MIDIMap.CCTarget) {
|
||||
learnTarget = nil
|
||||
guard let shoeGaze: ShoeGaze = shoeGaze,
|
||||
let pedal: Pedal = pedal(boardIndex: boardIndex, pedalIndex: pedalIndex),
|
||||
knobIndex >= 0, knobIndex < pedal.ccMappableControls.count else { return }
|
||||
let resolved: ResolvedCC = resolveCC(target) else { return }
|
||||
|
||||
let target: MIDIMap.CCTarget = MIDIMap.CCTarget(
|
||||
boardIndex: boardIndex,
|
||||
pedalIndex: pedalIndex,
|
||||
knobIndex: knobIndex,
|
||||
pedalNameHint: pedal.displayName,
|
||||
knobLabelHint: pedal.ccMappableControls[knobIndex].label
|
||||
)
|
||||
let binding: MIDIMap.CCBinding = MIDIMap.CCBinding(
|
||||
controller: controller,
|
||||
channel: channel,
|
||||
target: target
|
||||
target: resolved.hinted
|
||||
)
|
||||
|
||||
var map: MIDIMap = shoeGaze.midiMap ?? MIDIMap.empty
|
||||
// One control → one CC, and reassigning a CC (same controller + channel) steals it from any
|
||||
// other control so a given expression pedal drives exactly one thing.
|
||||
map.ccs.removeAll { $0.target == target || ($0.controller == controller && $0.channel == channel) }
|
||||
map.ccs.removeAll {
|
||||
$0.target.addresses(resolved.hinted) || ($0.controller == controller && $0.channel == channel)
|
||||
}
|
||||
map.ccs.append(binding)
|
||||
shoeGaze.midiMap = map
|
||||
onMapChanged?()
|
||||
}
|
||||
|
||||
/// Applies an incoming CC to the pedal knob it is bound to, if any.
|
||||
/// Applies an incoming CC to the control it is bound to, if any (channel-filtered).
|
||||
private func applyCC(controller: UInt8, channel: UInt8, value: UInt8) {
|
||||
guard let shoeGaze: ShoeGaze = shoeGaze, let map: MIDIMap = shoeGaze.midiMap else { return }
|
||||
for binding: MIDIMap.CCBinding in map.ccs where binding.controller == controller {
|
||||
if let boundChannel: UInt8 = binding.channel, boundChannel != channel { continue }
|
||||
applyCCBinding(binding, value: value)
|
||||
guard let resolved: ResolvedCC = resolveCC(binding.target) else { continue }
|
||||
let ccMax: Double = 127.0
|
||||
var norm: Double = Double(value) / ccMax
|
||||
if binding.inverted { norm = 1.0 - norm }
|
||||
let mapped: Double = resolved.range.lowerBound
|
||||
+ norm * (resolved.range.upperBound - resolved.range.lowerBound)
|
||||
resolved.node.update(mapped)
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolves a CC binding's target knob (skipping stale bindings) and writes the mapped value.
|
||||
private func applyCCBinding(_ binding: MIDIMap.CCBinding, value: UInt8) {
|
||||
let target: MIDIMap.CCTarget = binding.target
|
||||
guard let pedal: Pedal = pedal(boardIndex: target.boardIndex, pedalIndex: target.pedalIndex),
|
||||
target.knobIndex >= 0, target.knobIndex < pedal.ccMappableControls.count else { return }
|
||||
let control: PedalControl = pedal.ccMappableControls[target.knobIndex]
|
||||
// Stale-binding guard: the chain may have been edited under the positional address.
|
||||
if let nameHint: String = target.pedalNameHint, nameHint != pedal.displayName { return }
|
||||
if let labelHint: String = target.knobLabelHint, labelHint != control.label { return }
|
||||
/// A resolved CC target: the live node + range to drive, plus the target re-stamped with the
|
||||
/// current display-name hints (for storing at capture time).
|
||||
private struct ResolvedCC {
|
||||
let node: UIParamNode
|
||||
let range: ClosedRange<Double>
|
||||
let hinted: MIDIMap.CCTarget
|
||||
}
|
||||
|
||||
let ccMax: Double = 127.0
|
||||
var norm: Double = Double(value) / ccMax
|
||||
if binding.inverted { norm = 1.0 - norm }
|
||||
let mapped: Double = control.range.lowerBound
|
||||
+ norm * (control.range.upperBound - control.range.lowerBound)
|
||||
control.node.update(mapped)
|
||||
/// Resolves a CC target to its live node + range, skipping it (returns `nil`) when the positional
|
||||
/// address is out of range or a captured display-name hint no longer matches (stale binding).
|
||||
private func resolveCC(_ target: MIDIMap.CCTarget) -> ResolvedCC? {
|
||||
switch target {
|
||||
case let .pedalControl(boardIndex, pedalIndex, controlIndex, nameHint, labelHint):
|
||||
guard let pedal: Pedal = pedal(boardIndex: boardIndex, pedalIndex: pedalIndex),
|
||||
controlIndex >= 0, controlIndex < pedal.ccMappableControls.count else { return nil }
|
||||
let control: PedalControl = pedal.ccMappableControls[controlIndex]
|
||||
if let nameHint: String = nameHint, nameHint != pedal.displayName { return nil }
|
||||
if let labelHint: String = labelHint, labelHint != control.label { return nil }
|
||||
let hinted: MIDIMap.CCTarget = .pedalControl(
|
||||
boardIndex: boardIndex,
|
||||
pedalIndex: pedalIndex,
|
||||
controlIndex: controlIndex,
|
||||
pedalNameHint: pedal.displayName,
|
||||
controlLabelHint: control.label
|
||||
)
|
||||
return ResolvedCC(node: control.node, range: control.range, hinted: hinted)
|
||||
case let .boardLevel(boardIndex, labelHint):
|
||||
guard let board: PedalBoard = board(at: boardIndex),
|
||||
let node: UIParamNode = board.masterGainNode else { return nil }
|
||||
if let labelHint: String = labelHint, labelHint != board.label { return nil }
|
||||
let hinted: MIDIMap.CCTarget = .boardLevel(boardIndex: boardIndex, boardLabelHint: board.label)
|
||||
return ResolvedCC(node: node, range: boardLevelRange, hinted: hinted)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Switch (Program Change) learn + apply
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,47 +78,109 @@ public struct MIDIMappingSheet: View {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Row models
|
||||
|
||||
/// A Program-Change switch row: a toggle action + its display label. `id` is globally unique so
|
||||
/// SwiftUI never reuses a row view across the two sections (which would leak the wrong Learn
|
||||
/// action into a row).
|
||||
private struct SwitchRowModel: Identifiable {
|
||||
let id: String
|
||||
let action: MIDIMap.Action
|
||||
let label: String
|
||||
}
|
||||
|
||||
/// A Control-Change row: a continuous target (address-only, hints `nil`) + its display label.
|
||||
private struct CCRowModel: Identifiable {
|
||||
let id: String
|
||||
let target: MIDIMap.CCTarget
|
||||
let label: String
|
||||
}
|
||||
|
||||
private var switchRowModels: [SwitchRowModel] {
|
||||
var rows: [SwitchRowModel] = [
|
||||
SwitchRowModel(id: "sw-rig", action: .rigBypass, label: "Rig Bypass"),
|
||||
]
|
||||
for boardPair in shoeGaze.boards.enumerated() {
|
||||
let boardIndex: Int = boardPair.offset
|
||||
let board: PedalBoard = boardPair.element
|
||||
rows.append(SwitchRowModel(id: "sw-solo-\(boardIndex)",
|
||||
action: .boardSolo(boardIndex: boardIndex),
|
||||
label: "\(board.label) · Solo"))
|
||||
rows.append(SwitchRowModel(id: "sw-aud-\(boardIndex)",
|
||||
action: .boardAudible(boardIndex: boardIndex),
|
||||
label: "\(board.label) · Audible"))
|
||||
rows.append(SwitchRowModel(id: "sw-byp-\(boardIndex)",
|
||||
action: .boardBypass(boardIndex: boardIndex),
|
||||
label: "\(board.label) · Bypass"))
|
||||
for pedalPair in board.pedals.enumerated() {
|
||||
rows.append(SwitchRowModel(
|
||||
id: "sw-pb-\(boardIndex)-\(pedalPair.offset)",
|
||||
action: .pedalBypass(boardIndex: boardIndex, pedalIndex: pedalPair.offset),
|
||||
label: "\(board.label) · \(pedalPair.element.displayName) · Bypass"))
|
||||
}
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
private var ccRowModels: [CCRowModel] {
|
||||
var rows: [CCRowModel] = []
|
||||
for boardPair in shoeGaze.boards.enumerated() {
|
||||
let boardIndex: Int = boardPair.offset
|
||||
let board: PedalBoard = boardPair.element
|
||||
// Board master level (the board fader).
|
||||
rows.append(CCRowModel(
|
||||
id: "cc-blvl-\(boardIndex)",
|
||||
target: .boardLevel(boardIndex: boardIndex, boardLabelHint: nil),
|
||||
label: "\(board.label) · Level"))
|
||||
for pedalPair in board.pedals.enumerated() {
|
||||
let pedalIndex: Int = pedalPair.offset
|
||||
let pedal: Pedal = pedalPair.element
|
||||
for controlPair in pedal.ccMappableControls.enumerated() {
|
||||
rows.append(CCRowModel(
|
||||
id: "cc-\(boardIndex)-\(pedalIndex)-\(controlPair.offset)",
|
||||
target: .pedalControl(
|
||||
boardIndex: boardIndex,
|
||||
pedalIndex: pedalIndex,
|
||||
controlIndex: controlPair.offset,
|
||||
pedalNameHint: nil,
|
||||
controlLabelHint: nil),
|
||||
label: "\(pedal.displayName) · \(controlPair.element.label)"))
|
||||
}
|
||||
}
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
// MARK: - Switches (Program Change)
|
||||
|
||||
private var switchesSection: some View {
|
||||
Section("Switches (Program Change)") {
|
||||
switchRow(action: .rigBypass, label: "Rig Bypass")
|
||||
ForEach(Array(shoeGaze.boards.enumerated()), id: \.offset) { boardPair in
|
||||
let boardIndex: Int = boardPair.offset
|
||||
let board: PedalBoard = boardPair.element
|
||||
switchRow(action: .boardSolo(boardIndex: boardIndex), label: "\(board.label) · Solo")
|
||||
switchRow(action: .boardAudible(boardIndex: boardIndex), label: "\(board.label) · Audible")
|
||||
switchRow(action: .boardBypass(boardIndex: boardIndex), label: "\(board.label) · Bypass")
|
||||
ForEach(Array(board.pedals.enumerated()), id: \.offset) { pedalPair in
|
||||
switchRow(
|
||||
action: .pedalBypass(boardIndex: boardIndex, pedalIndex: pedalPair.offset),
|
||||
label: "\(board.label) · \(pedalPair.element.displayName) · Bypass"
|
||||
)
|
||||
}
|
||||
ForEach(switchRowModels) { row in
|
||||
switchRow(row)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func switchRow(action: MIDIMap.Action, label: String) -> some View {
|
||||
let isArmed: Bool = controller.learnTarget == .action(action)
|
||||
let binding: MIDIMap.SwitchBinding? = controller.switchBinding(for: action)
|
||||
private func switchRow(_ row: SwitchRowModel) -> some View {
|
||||
let isArmed: Bool = controller.learnTarget == .action(row.action)
|
||||
let binding: MIDIMap.SwitchBinding? = controller.switchBinding(for: row.action)
|
||||
return HStack {
|
||||
VStack(alignment: .leading, spacing: 1) {
|
||||
Text(label)
|
||||
Text(row.label)
|
||||
Text(switchBindingLabel(isArmed: isArmed, binding: binding))
|
||||
.font(.caption)
|
||||
.foregroundStyle(isArmed ? Color.orange : .secondary)
|
||||
}
|
||||
Spacer()
|
||||
if binding != nil {
|
||||
Button("Clear") { controller.clearSwitchBinding(for: action) }
|
||||
Button("Clear") { controller.clearSwitchBinding(for: row.action) }
|
||||
.buttonStyle(.borderless)
|
||||
}
|
||||
Button(isArmed ? "Cancel" : "Learn") {
|
||||
if isArmed {
|
||||
controller.cancelLearn()
|
||||
} else {
|
||||
controller.armSwitchLearn(action)
|
||||
controller.armSwitchLearn(row.action)
|
||||
}
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
@@ -142,72 +204,32 @@ public struct MIDIMappingSheet: View {
|
||||
Text("Add a pedal to assign expression control.")
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
ForEach(Array(shoeGaze.boards.enumerated()), id: \.offset) { boardPair in
|
||||
let boardIndex: Int = boardPair.offset
|
||||
let board: PedalBoard = boardPair.element
|
||||
ForEach(Array(board.pedals.enumerated()), id: \.offset) { pedalPair in
|
||||
pedalRows(
|
||||
boardIndex: boardIndex,
|
||||
pedalIndex: pedalPair.offset,
|
||||
pedal: pedalPair.element,
|
||||
boardLabel: board.label
|
||||
)
|
||||
}
|
||||
ForEach(ccRowModels) { row in
|
||||
ccRow(row)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func pedalRows(boardIndex: Int, pedalIndex: Int, pedal: Pedal, boardLabel: String) -> some View {
|
||||
// Per-pedal header so each control row can show just its own name.
|
||||
Text("\(boardLabel) · \(pedal.displayName)")
|
||||
.font(.subheadline.weight(.semibold))
|
||||
.foregroundStyle(.secondary)
|
||||
ForEach(Array(pedal.ccMappableControls.enumerated()), id: \.offset) { controlPair in
|
||||
knobRow(
|
||||
boardIndex: boardIndex,
|
||||
pedalIndex: pedalIndex,
|
||||
knobIndex: controlPair.offset,
|
||||
controlLabel: controlPair.element.label
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private func knobRow(
|
||||
boardIndex: Int,
|
||||
pedalIndex: Int,
|
||||
knobIndex: Int,
|
||||
controlLabel: String
|
||||
) -> some View {
|
||||
let isArmed: Bool = controller.learnTarget == .cc(
|
||||
boardIndex: boardIndex, pedalIndex: pedalIndex, knobIndex: knobIndex
|
||||
)
|
||||
let binding: MIDIMap.CCBinding? = controller.ccBinding(
|
||||
boardIndex: boardIndex, pedalIndex: pedalIndex, knobIndex: knobIndex
|
||||
)
|
||||
private func ccRow(_ row: CCRowModel) -> some View {
|
||||
let isArmed: Bool = controller.learnTarget == .cc(row.target)
|
||||
let binding: MIDIMap.CCBinding? = controller.ccBinding(for: row.target)
|
||||
return HStack {
|
||||
VStack(alignment: .leading, spacing: 1) {
|
||||
Text(controlLabel)
|
||||
Text(bindingLabel(isArmed: isArmed, binding: binding))
|
||||
Text(row.label)
|
||||
Text(ccBindingLabel(isArmed: isArmed, binding: binding))
|
||||
.font(.caption)
|
||||
.foregroundStyle(isArmed ? Color.orange : .secondary)
|
||||
}
|
||||
Spacer()
|
||||
if binding != nil {
|
||||
Button("Clear") {
|
||||
controller.clearCCBinding(
|
||||
boardIndex: boardIndex, pedalIndex: pedalIndex, knobIndex: knobIndex
|
||||
)
|
||||
}
|
||||
.buttonStyle(.borderless)
|
||||
Button("Clear") { controller.clearCCBinding(for: row.target) }
|
||||
.buttonStyle(.borderless)
|
||||
}
|
||||
Button(isArmed ? "Cancel" : "Learn") {
|
||||
if isArmed {
|
||||
controller.cancelLearn()
|
||||
} else {
|
||||
controller.armCCLearn(
|
||||
boardIndex: boardIndex, pedalIndex: pedalIndex, knobIndex: knobIndex
|
||||
)
|
||||
controller.armCCLearn(row.target)
|
||||
}
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
@@ -216,7 +238,7 @@ public struct MIDIMappingSheet: View {
|
||||
.padding(.vertical, MIDIMappingSheet.rowVerticalPadding)
|
||||
}
|
||||
|
||||
private func bindingLabel(isArmed: Bool, binding: MIDIMap.CCBinding?) -> String {
|
||||
private func ccBindingLabel(isArmed: Bool, binding: MIDIMap.CCBinding?) -> String {
|
||||
if isArmed { return "Listening — move an expression pedal…" }
|
||||
guard let binding: MIDIMap.CCBinding = binding else { return "Unassigned" }
|
||||
let channelText: String = binding.channel.map { " · ch \($0 + 1)" } ?? ""
|
||||
|
||||
Reference in New Issue
Block a user