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:
Reactorcoremeltdown
2026-11-16 16:31:46 +01:00
co-authored by Claude Opus 5.5
parent 4d9e2328cb
commit 6688718bed
19 changed files with 580 additions and 8 deletions
+2 -1
View File
@@ -158,7 +158,7 @@ final class InputController: ObservableObject {
func paramCc(slot: Int, key: String) -> Int? { Int(session.value(ofSlot: slot, key: Self.ccPrefix + key)) }
func clearParamCc(slot: Int, key: String) { session.setValue("", ofSlot: slot, key: Self.ccPrefix + key) }
func clearParamCc(slot: Int, key: String) { session.removeValue(ofSlot: slot, key: Self.ccPrefix + key) }
private func onRaw(_ source: InputSource, _ code: Int, _ value: Float, _ modifier: Int) {
if let key = paramLearnKey {
@@ -187,6 +187,7 @@ final class InputController: ObservableObject {
clearParamCc(slot: s, key: spec.key)
}
}
// (Same rule as MidiMapIo.apply: one control drives one parameter.)
session.setValue(String(cc), ofSlot: slot, key: Self.ccPrefix + key)
}
@@ -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
}
}
}
+9
View File
@@ -19,6 +19,15 @@ NS_ASSUME_NONNULL_BEGIN
/// True for a ZIP archive (bundle or backup) rather than text.
+ (BOOL)isZipData:(NSData *)data;
/// Toolbox [slot]'s MIDI mapping as .szm text (io/MidiMapIo: TYPE, NAME, one
/// `parameter=CC` line each), or nil for an empty slot.
- (nullable NSString *)midiMapTextOfSlot:(NSInteger)slot;
/// Replace [slot]'s MIDI mapping with the .szm [text] (a CC another parameter used
/// moves here). NO with [error] set when it isn't a mapping or is for another device.
- (BOOL)importMidiMapText:(NSString *)text intoSlot:(NSInteger)slot error:(NSError **)error;
/// Remove setting [key] from [slot] (a cleared MIDI mapping).
- (void)removeValueOfSlot:(NSInteger)slot key:(NSString *)key;
/// Everything Sizzle keeps: Documents/songs, themes, presets and samples, the
/// autosaved song, and [settings] as settings.txt. The open song is autosaved first.
- (nullable NSData *)backupDataWithSettings:(NSString *)settings;
+40
View File
@@ -9,7 +9,9 @@
#include <string>
#include <vector>
#include "io/MidiMapIo.hpp"
#include "io/Zip.hpp"
#include "sizzle/Specs.hpp"
using namespace sizzle;
namespace zip = sizzle::io::zip;
@@ -138,6 +140,44 @@ NSString *const kSettings = @"settings.txt";
return [self importProjectText:text error:error];
}
#pragma mark - MIDI mappings
- (nullable NSString *)midiMapTextOfSlot:(NSInteger)slot {
if (slot < 0 || slot >= 16) return nil;
__block std::string text;
[self read:^(const model::Project &p, const engine::Engine &) {
const auto &s = p.toolbox[(size_t)slot];
if (!s.isEmpty()) text = io::MidiMapIo::save(io::MidiMapIo::fromSlot(s));
}];
return text.empty() ? nil : @(text.c_str());
}
- (BOOL)importMidiMapText:(NSString *)text intoSlot:(NSInteger)slot error:(NSError **)error {
const auto map = io::MidiMapIo::parse(text.UTF8String ?: "");
if (!map) {
if (error) *error = filesError(@"This doesn't look like a Sizzle MIDI mapping (.szm).");
return NO;
}
__block int applied = -1;
[self edit:^(model::Project &p, engine::Engine &) { applied = io::MidiMapIo::apply(p, (int)slot, *map); }];
if (applied < 0 && error) {
const DeviceSpec *want = findDevice(map->type.c_str());
const DeviceSpec *have = findDevice([self typeOfSlot:slot].UTF8String);
*error = filesError([NSString stringWithFormat:@"This mapping is for a %s, not a %s.",
want ? want->displayName : map->type.c_str(), have ? have->displayName : "empty slot"]);
}
return applied >= 0;
}
- (void)removeValueOfSlot:(NSInteger)slot key:(NSString *)key {
if (slot < 0 || slot >= 16) return;
std::string k = key.UTF8String ?: "";
[self edit:^(model::Project &p, engine::Engine &) {
p.toolbox[(size_t)slot].values.remove(k.c_str());
++p.toolbox[(size_t)slot].version;
}];
}
#pragma mark - backups
- (nullable NSData *)backupDataWithSettings:(NSString *)settings {