// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown // SPDX-License-Identifier: GPL-3.0-or-later import SwiftUI /// Android's MidiLearnPopup: every parameter of the slot with its MIDI CC. LEARN, /// then move a knob or fader on a MIDI controller; ✕ removes the binding. The /// bindings are saved in the song (`midicc@` slot values), as on Android. struct MidiLearnSheet: View { let slot: Int let type: String @ObservedObject private var input = InputController.shared @ObservedObject private var watch = MixSongWatch.shared @Environment(\.dismiss) private var dismiss var body: some View { let session = SizzleSession.shared VStack(alignment: .leading, spacing: 8) { HStack { Text("MIDI LEARN — \(session.name(ofSlot: slot))").font(Theme.mono(14)).foregroundColor(Theme.accent) Spacer() Text("DONE").font(Theme.mono(13)).foregroundColor(Theme.dim) .contentShape(Rectangle()).onTapGesture { dismiss() } } Text("Tap LEARN, then move a knob/fader on your MIDI controller.").font(Theme.mono(10)).foregroundColor(Theme.dim) SnapScroll { VStack(spacing: 6) { ForEach(SizzleSession.paramSpecs(forType: type), id: \.key) { spec in let arming = input.paramLearnSlot == slot && input.paramLearnKey == spec.key let cc = input.paramCc(slot: slot, key: spec.key) HStack(spacing: 8) { Text(spec.label).font(Theme.mono(12)).foregroundColor(Theme.text) .frame(maxWidth: .infinity, alignment: .leading) Text(arming ? "waiting…" : cc.map { "CC \($0)" } ?? "—").font(Theme.mono(11)) .foregroundColor(arming ? Theme.accent : Theme.dim).frame(width: 72, alignment: .leading) MixKit.Button(label: arming ? "ARMING" : "LEARN", active: arming, width: 78) { if arming { input.cancelParamLearn() } else { input.beginParamLearn(slot: slot, key: spec.key) } } MixKit.Button(label: "✕") { input.clearParamCc(slot: slot, key: spec.key) } } } } } } .padding(16) .background(Theme.surface.ignoresSafeArea()) .preferredColorScheme(.dark) .onDisappear { input.cancelParamLearn() } } }