0.39.1 (74): preset bundles between Android and iOS, both ways

iOS couldn't import Android's Sampler preset bundle (a ZIP with the .szp and
its WAVs) and shared sample presets as bare text naming iOS sample ids.

- core/src/io/PresetBundle: import/export in Android's bundle layout
  (padNFile / sfFile), used by iOS IMPORT and SHARE
- bundle_test imports a bundle written by Android's PresetLibrary
  (IosGoldenPresetBundle); PresetBundleInteropTest imports the iOS-written
  fixture with Android's importZip

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Reactorcoremeltdown
2026-11-16 16:39:33 +01:00
co-authored by Claude Opus 5.5
parent 6688718bed
commit 5240019b47
14 changed files with 417 additions and 5 deletions
+8
View File
@@ -5,6 +5,14 @@ Sizzle for iOS/iPadOS (`cc.tiredsysadmin.ios.sizzle`). One entry per version in
is shared with Android, continuing Android's numbering, and both apps ship the
same features; the Android side of each version is in `../CHANGELOG.md`.
## 0.39.1 (build 74)
- Fix: a Sampler preset shared from Android (a .zip with the preset and its
WAVs) failed with "Couldn't import this preset". Preset IMPORT now takes these
bundles, for the Sampler, SF2/XI loader, Grain Cloud and Wavetable, and their
sounds come along. SHARE sends the same kind of bundle, so presets with samples
also go from iOS to Android (before, they named iOS-only sample ids).
## 0.39.0 (build 73)
- MIDI mappings as files: EXPORT / IMPORT in each device's ⇄ MIDI sheet share a
+6 -1
View File
@@ -86,6 +86,10 @@ build/core/midimap_test: $(CORE_SRC) $(CORE_HDR) ../core/tests/midimap_test.cpp
mkdir -p build/core
$(CXX) $(CXXFLAGS) -o $@ $(CORE_SRC) ../core/tests/midimap_test.cpp
build/core/bundle_test: $(CORE_SRC) $(CORE_HDR) ../core/tests/bundle_test.cpp
mkdir -p build/core
$(CXX) $(CXXFLAGS) -o $@ $(CORE_SRC) ../core/tests/bundle_test.cpp
build/core/midi_test: ../core/include/sizzle/Midi.hpp ../core/tests/midi_test.cpp
mkdir -p build/core
$(CXX) $(CXXFLAGS) -o $@ ../core/tests/midi_test.cpp
@@ -102,7 +106,7 @@ zip-test: build/core/zip_test
build/core/zip_test build/core/java.zip build/core/ours.zip
unzip -tq build/core/ours.zip
core-test: build/core/golden_test build/core/sampler_test build/core/engine_test build/core/io_test build/core/midi_test build/core/host_test build/core/midimap_test zip-test
core-test: build/core/golden_test build/core/sampler_test build/core/engine_test build/core/io_test build/core/midi_test build/core/host_test build/core/midimap_test build/core/bundle_test zip-test
@test -f $(GOLDEN)/input.f32 || $(MAKE) --no-print-directory golden
build/core/golden_test $(GOLDEN) $(TYPES)
build/core/sampler_test
@@ -111,6 +115,7 @@ core-test: build/core/golden_test build/core/sampler_test build/core/engine_test
build/core/midi_test
build/core/host_test $(GOLDEN)/songs
build/core/midimap_test ../app/src/test/resources/midimap/filter.szm
build/core/bundle_test $(GOLDEN)/bundles/android_sampler.zip ../app/src/test/resources/presetbundle/ios_sampler.zip
# ------------------------------------------------------------------ app
AU_SRC := app/FX/SizzleDeviceAU.mm app/FX/SizzleEffectAU.mm app/FX/SizzleInstrumentAU.mm app/FX/SizzleDeviceAU+Sources.mm
@@ -147,7 +147,8 @@ struct SlotEditor: View {
let name = url.deletingPathExtension().lastPathComponent
switch kind {
case .preset:
guard let text = String(data: data, encoding: .utf8), session.importPresetText(text, intoSlot: slot) else {
// Preset text, or a bundle with its sounds (how Android shares Sampler presets).
guard session.importPresetData(data, intoSlot: slot) else {
let display = SizzleSession.deviceTypes.first { $0.type == type }?.displayName ?? type
importError = "Couldn't import this preset. The file may be corrupt, or not a valid \(display) preset or bundle."
return
@@ -295,7 +296,7 @@ private struct PresetBar: View {
let name = slotName.trimmingCharacters(in: .whitespaces).isEmpty ? displayName : slotName
_ = session.savePreset(ofSlot: slot, name: name)
names = session.libraryPresets(forType: type)
guard let url = session.presetFile(forType: type, name: name) else { return }
guard let url = session.presetShareURL(forType: type, name: name) else { return }
#if canImport(UIKit)
let vc = UIActivityViewController(activityItems: [url], applicationActivities: nil)
let root = UIApplication.shared.connectedScenes.compactMap { ($0 as? UIWindowScene)?.keyWindow }.first?.rootViewController
+7
View File
@@ -41,6 +41,13 @@ NS_ASSUME_NONNULL_BEGIN
- (BOOL)importPresetText:(NSString *)text intoSlot:(NSInteger)slot;
/// The preset's file, for sharing (nil when missing).
- (nullable NSURL *)presetFileForType:(NSString *)type name:(NSString *)name;
/// Import a picked preset file into [slot]: preset text, or a bundle (a ZIP with
/// the preset and its WAVs, as Android shares Sampler, SF2/XI, Grain Cloud and
/// Wavetable presets). Saved to the library like importPresetText.
- (BOOL)importPresetData:(NSData *)data intoSlot:(NSInteger)slot;
/// What SHARE sends for a saved preset: a bundle with its sounds (Android's
/// layout) for the device types that carry samples, else the .szp itself.
- (nullable NSURL *)presetShareURLForType:(NSString *)type name:(NSString *)name;
@end
+52
View File
@@ -9,6 +9,7 @@
#include <set>
#include <string>
#include <vector>
#include "io/PresetBundle.hpp"
#include "io/PresetIo.hpp"
#include "sizzle/DeviceSpecs.gen.hpp"
@@ -17,6 +18,7 @@ using namespace sizzle;
/// SizzleSession.mm's own: put back into the store the samples the song refers to.
@interface SizzleSession (MixPrivate)
- (void)rehydrateSamples;
- (NSURL *)sampleURL:(const std::string &)id;
@end
namespace {
@@ -268,6 +270,56 @@ NSString *sanitize(NSString *name) {
return [self savePresetOfSlot:slot name:name.length ? name : [self typeOfSlot:slot]];
}
- (BOOL)importPresetData:(NSData *)data intoSlot:(NSInteger)slot {
if (slot < 0 || slot >= model::Project::TOOLBOX_SLOTS) return NO;
if (data.length < 4 || memcmp(data.bytes, "PK\x03\x04", 4)) {
NSString *text = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
return text && [self importPresetText:text intoSlot:slot];
}
// A bundle: each sound becomes one of the song's samples (store + Documents/samples).
__block model::ToolboxSlot fresh;
[self read:^(const model::Project &p, const engine::Engine &) { fresh = p.toolbox[(size_t)slot]; }];
sampler::SampleStore &store = [self sampleStore];
const bool ok = io::PresetBundle::importInto(fresh, (const uint8_t *)data.bytes, data.length,
[self, &store](const std::string &file, Sample sample) {
std::string stem = file.substr(0, file.rfind('.'));
std::string id = stem + "#" + NSUUID.UUID.UUIDString.UTF8String;
const auto wav = sampler::SampleStore::encodeWav(sample);
[[NSData dataWithBytes:wav.data() length:wav.size()] writeToURL:[self sampleURL:id] atomically:YES];
store.put(id, std::move(sample));
return id;
});
if (!ok) return NO;
[self edit:^(model::Project &p, engine::Engine &e) {
p.toolbox[(size_t)slot] = fresh;
++p.toolbox[(size_t)slot].version;
e.rebuildFxChains();
}];
NSString *name = [self nameOfSlot:slot];
return [self savePresetOfSlot:slot name:name.length ? name : [self typeOfSlot:slot]];
}
- (nullable NSURL *)presetShareURLForType:(NSString *)type name:(NSString *)name {
NSURL *file = [self presetFileForType:type name:name];
if (!file || !io::PresetBundle::carriesSamples(type.UTF8String)) return file;
NSString *text = [NSString stringWithContentsOfURL:file encoding:NSUTF8StringEncoding error:nil];
model::ToolboxSlot slot;
if (!text || !io::PresetIo::importText(slot, text.UTF8String)) return file;
sampler::SampleStore &store = [self sampleStore];
NSString *base = sanitize(name);
const auto zip = io::PresetBundle::exportFrom(slot, base.UTF8String, [self, &store](const std::string &id) {
if (NSData *d = [NSData dataWithContentsOfURL:[self sampleURL:id]])
return std::vector<uint8_t>((const uint8_t *)d.bytes, (const uint8_t *)d.bytes + d.length);
const Sample *s = store.get(id.c_str());
return s ? sampler::SampleStore::encodeWav(*s) : std::vector<uint8_t>();
});
NSURL *dir = [NSFileManager.defaultManager.temporaryDirectory URLByAppendingPathComponent:@"PresetShare" isDirectory:YES];
[NSFileManager.defaultManager removeItemAtURL:dir error:nil];
[NSFileManager.defaultManager createDirectoryAtURL:dir withIntermediateDirectories:YES attributes:nil error:nil];
NSURL *out = [dir URLByAppendingPathComponent:[base stringByAppendingPathExtension:@"zip"]];
return [[NSData dataWithBytes:zip.data() length:zip.size()] writeToURL:out atomically:YES] ? out : nil;
}
- (NSURL *)presetFileForType:(NSString *)type name:(NSString *)name {
NSURL *u = [self mixPresetURL:type name:name];
return [NSFileManager.defaultManager fileExistsAtPath:u.path] ? u : nil;