0.39.0 (73): export and import MIDI mappings as .szm text (Android and iOS)
- SIZZLE-MIDIMAP 1 format: TYPE, NAME, one parameter=CC line each - core/src/io/MidiMapIo (iOS) and io/MidiMapIo.kt (Android), tested on one shared fixture (midimap_test, MidiMapIoTest) - EXPORT / IMPORT in each device's MIDI learn panel on both platforms - Params::remove; iOS clears a mapping by removing it - ios/Makefile regenerates the Xcode project when source folders change Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
4d9e2328cb
commit
6688718bed
@@ -6,12 +6,15 @@ 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@<key>` slot values), as on Android.
|
||||
/// EXPORT shares them as a .szm text file; IMPORT takes one for this device type.
|
||||
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
|
||||
@State private var importing = false
|
||||
@State private var importError: String?
|
||||
|
||||
var body: some View {
|
||||
let session = SizzleSession.shared
|
||||
@@ -19,6 +22,12 @@ struct MidiLearnSheet: View {
|
||||
HStack {
|
||||
Text("MIDI LEARN — \(session.name(ofSlot: slot))").font(Theme.mono(14)).foregroundColor(Theme.accent)
|
||||
Spacer()
|
||||
Text("EXPORT").font(Theme.mono(13)).foregroundColor(Theme.accent)
|
||||
.contentShape(Rectangle()).onTapGesture(perform: export)
|
||||
.padding(.trailing, 14)
|
||||
Text("IMPORT").font(Theme.mono(13)).foregroundColor(Theme.accent)
|
||||
.contentShape(Rectangle()).onTapGesture { importing = true }
|
||||
.padding(.trailing, 14)
|
||||
Text("DONE").font(Theme.mono(13)).foregroundColor(Theme.dim)
|
||||
.contentShape(Rectangle()).onTapGesture { dismiss() }
|
||||
}
|
||||
@@ -46,5 +55,32 @@ struct MidiLearnSheet: View {
|
||||
.background(Theme.surface.ignoresSafeArea())
|
||||
.preferredColorScheme(.dark)
|
||||
.onDisappear { input.cancelParamLearn() }
|
||||
// The completion needs nothing but the URL (iOS 15 resets the binding first).
|
||||
.fileImporter(isPresented: $importing, allowedContentTypes: [.item]) { result in
|
||||
guard case .success(let url) = result else { return }
|
||||
do {
|
||||
let data = try SetupFiles.readData(url, limit: 1 << 20)
|
||||
guard let text = String(data: data, encoding: .utf8) else { throw SetupFileError.notText }
|
||||
try SizzleSession.shared.importMidiMapText(text, intoSlot: slot)
|
||||
} catch {
|
||||
importError = error.localizedDescription
|
||||
}
|
||||
}
|
||||
.alert("Import failed", isPresented: Binding(get: { importError != nil }, set: { if !$0 { importError = nil } }),
|
||||
actions: { Button("OK") { importError = nil } }, message: { Text(importError ?? "") })
|
||||
}
|
||||
|
||||
/// The mapping as "<slot name> MIDI.szm", through the share sheet.
|
||||
private func export() {
|
||||
let session = SizzleSession.shared
|
||||
guard let text = session.midiMapText(ofSlot: slot) else { return }
|
||||
let name = session.name(ofSlot: slot).trimmingCharacters(in: .whitespaces)
|
||||
let base = SetupFiles.fileStem(name.isEmpty ? type : name) + " MIDI"
|
||||
do {
|
||||
let url = try SetupFiles.export(Data(text.utf8), name: base, ext: "szm")
|
||||
ShareSheet.present(url) { try? FileManager.default.removeItem(at: url.deletingLastPathComponent()) }
|
||||
} catch {
|
||||
importError = error.localizedDescription
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user