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:
co-authored by
Claude Opus 5.5
parent
6688718bed
commit
5240019b47
@@ -5,6 +5,12 @@ version in `versions.properties`; versions before 0.28.0 are described in the gi
|
||||
log (one commit per version). Since 0.37.0 Android and iOS share one version and
|
||||
one feature set; the iOS side of each version is in `ios/CHANGELOG.md`.
|
||||
|
||||
## 0.39.1 (versionCode 74)
|
||||
|
||||
- Sampler, SF2/XI, Grain Cloud and Wavetable preset bundles now travel between
|
||||
Android and iOS in both directions (the fix is on the iOS side; Android's
|
||||
bundle format is unchanged and is now checked against the iOS code by tests).
|
||||
|
||||
## 0.39.0 (versionCode 73)
|
||||
|
||||
- **MIDI mappings as files:** the ⇄ MIDI panel of every toolbox device has
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package cc.tiredsysadmin.android.sizzle.audio
|
||||
|
||||
import cc.tiredsysadmin.android.sizzle.io.PresetLibrary
|
||||
import cc.tiredsysadmin.android.sizzle.model.ToolboxSlot
|
||||
import cc.tiredsysadmin.android.sizzle.model.ToolboxType
|
||||
import org.junit.Assume.assumeTrue
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
|
||||
/**
|
||||
* Writes a Sampler preset bundle with Android's own PresetLibrary (save, then
|
||||
* bundleForShare: what SHARE sends) to SIZZLE_GOLDEN_DIR/bundles/android_sampler.zip,
|
||||
* for core/tests/bundle_test.cpp to import as the iOS app does. The kit: pad 0 =
|
||||
* 100 frames at 44.1 kHz (start 0.25), pad 3 = 200 frames at 22.05 kHz.
|
||||
* Runs only when SIZZLE_GOLDEN_DIR is set (`make -C ios golden`).
|
||||
*/
|
||||
class IosGoldenPresetBundle {
|
||||
@Test
|
||||
fun writeAndroidBundle() {
|
||||
val out = System.getenv("SIZZLE_GOLDEN_DIR")
|
||||
assumeTrue(out != null)
|
||||
fun ramp(frames: Int, rate: Int) = SampleStore.Sample(FloatArray(frames) { it.toFloat() / frames - 0.5f }, rate)
|
||||
SampleStore.put("golden-kick", ramp(100, 44_100))
|
||||
SampleStore.put("golden-snare", ramp(200, 22_050))
|
||||
val slot = ToolboxSlot(0).apply {
|
||||
fill(ToolboxType.SAMPLER)
|
||||
set("pad0", "golden-kick")
|
||||
set("pad0S", 0.25f)
|
||||
set("pad3", "golden-snare")
|
||||
}
|
||||
val lib = PresetLibrary(Files.createTempDirectory("presets").toFile())
|
||||
lib.save(slot, "Kit")
|
||||
val zip = lib.bundleForShare(ToolboxType.SAMPLER, "Kit")!!
|
||||
val dir = File(out, "bundles").apply { mkdirs() }
|
||||
zip.copyTo(File(dir, "android_sampler.zip"), overwrite = true)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package cc.tiredsysadmin.android.sizzle.io
|
||||
|
||||
import cc.tiredsysadmin.android.sizzle.audio.SampleStore
|
||||
import cc.tiredsysadmin.android.sizzle.model.ToolboxSlot
|
||||
import cc.tiredsysadmin.android.sizzle.model.ToolboxType
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import java.nio.file.Files
|
||||
|
||||
/**
|
||||
* A Sampler bundle written by the iOS app (core/src/io/PresetBundle, the fixture
|
||||
* core/tests/bundle_test.cpp checks byte for byte) imports here like Android's own:
|
||||
* pad 0 = 100 frames at 44.1 kHz starting at 0.25, pad 3 = 200 frames at 22.05 kHz.
|
||||
*/
|
||||
class PresetBundleInteropTest {
|
||||
@Test
|
||||
fun importsTheIosBundle() {
|
||||
val bytes = javaClass.getResource("/presetbundle/ios_sampler.zip")!!.readBytes()
|
||||
val lib = PresetLibrary(Files.createTempDirectory("presets").toFile())
|
||||
val slot = ToolboxSlot(0).apply { fill(ToolboxType.FILTER) }
|
||||
assertTrue(lib.importZip(slot, bytes.inputStream()))
|
||||
assertEquals(ToolboxType.SAMPLER, slot.type)
|
||||
// (No name check: Android's PresetIo.import replaces the name with the device's, for its own bundles too.)
|
||||
val pad0 = SampleStore.get(slot.string("pad0"))!!
|
||||
val pad3 = SampleStore.get(slot.string("pad3"))!!
|
||||
assertEquals(100, pad0.data.size)
|
||||
assertEquals(44_100, pad0.sampleRate)
|
||||
assertEquals(200, pad3.data.size)
|
||||
assertEquals(22_050, pad3.sampleRate)
|
||||
assertEquals(0.25f, slot.float("pad0S"))
|
||||
assertEquals("", slot.string("pad1"))
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,100 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "io/PresetBundle.hpp"
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "io/PresetIo.hpp"
|
||||
#include "io/Zip.hpp"
|
||||
#include "sampler/SampleStore.hpp"
|
||||
|
||||
namespace sizzle::io {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr int PADS = 16;
|
||||
|
||||
std::string baseNameOf(const std::string &path) {
|
||||
const size_t slash = path.find_last_of("/\\");
|
||||
return slash == std::string::npos ? path : path.substr(slash + 1);
|
||||
}
|
||||
|
||||
bool endsWith(const std::string &s, const char *suffix) {
|
||||
const size_t n = std::char_traits<char>::length(suffix);
|
||||
return s.size() >= n && s.compare(s.size() - n, n, suffix) == 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool PresetBundle::carriesSamples(const std::string &type) {
|
||||
return type == "SAMPLER" || type == "SOUNDFONT" || type == "GRAIN_CLOUD" || type == "WAVETABLE";
|
||||
}
|
||||
|
||||
bool PresetBundle::importInto(model::ToolboxSlot &slot, const uint8_t *zipBytes, size_t size,
|
||||
const std::function<std::string(const std::string &, Sample)> &keep) {
|
||||
std::vector<zip::Entry> entries;
|
||||
if (!zip::read(zipBytes, size, entries, 64ull << 20)) return false; // ZipLimits.forBundle
|
||||
std::string preset;
|
||||
bool havePreset = false;
|
||||
std::map<std::string, const std::vector<uint8_t> *> files;
|
||||
for (const auto &e : entries) {
|
||||
const std::string name = baseNameOf(e.name);
|
||||
if (name.empty() || e.name.rfind("__MACOSX", 0) == 0 || name.rfind("._", 0) == 0) continue;
|
||||
if (!havePreset && endsWith(name, ".szp")) { preset.assign(e.data.begin(), e.data.end()); havePreset = true; }
|
||||
else files.emplace(name, &e.data);
|
||||
}
|
||||
if (!havePreset) return false;
|
||||
model::ToolboxSlot fresh = slot;
|
||||
if (!PresetIo::importText(fresh, preset)) return false;
|
||||
|
||||
auto resolve = [&](const char *fileKey, const char *idKey) {
|
||||
const std::string ref = fresh.s(fileKey, "");
|
||||
if (ref.empty()) return;
|
||||
auto it = files.find(baseNameOf(ref));
|
||||
if (it == files.end()) return;
|
||||
auto sample = sampler::SampleStore::decodeWav(it->second->data(), it->second->size());
|
||||
if (!sample) return;
|
||||
const std::string id = keep(it->first, std::move(*sample));
|
||||
if (!id.empty()) fresh.set(idKey, id.c_str());
|
||||
};
|
||||
if (fresh.type == "SAMPLER") {
|
||||
for (int p = 0; p < PADS; ++p) {
|
||||
const std::string pad = "pad" + std::to_string(p);
|
||||
resolve((pad + "File").c_str(), pad.c_str());
|
||||
}
|
||||
} else if (carriesSamples(fresh.type)) {
|
||||
resolve("sfFile", "sfSample");
|
||||
}
|
||||
slot = fresh;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> PresetBundle::exportFrom(const model::ToolboxSlot &slot, const std::string &baseName,
|
||||
const std::function<std::vector<uint8_t>(const std::string &)> &wavOf) {
|
||||
model::ToolboxSlot copy = slot;
|
||||
std::vector<zip::Entry> entries;
|
||||
auto carry = [&](const char *idKey, const char *fileKey, const std::string &fileName) {
|
||||
const std::string id = copy.s(idKey, "");
|
||||
copy.values.remove(fileKey);
|
||||
if (id.empty()) return;
|
||||
std::vector<uint8_t> wav = wavOf(id);
|
||||
copy.values.remove(idKey); // a sample id means nothing on another device
|
||||
if (wav.empty()) return;
|
||||
copy.set(fileKey, fileName.c_str());
|
||||
entries.push_back({fileName, std::move(wav)});
|
||||
};
|
||||
if (copy.type == "SAMPLER") {
|
||||
for (int p = 0; p < PADS; ++p) {
|
||||
const std::string pad = "pad" + std::to_string(p);
|
||||
carry(pad.c_str(), (pad + "File").c_str(), baseName + "_" + pad + ".wav");
|
||||
}
|
||||
} else if (carriesSamples(copy.type)) {
|
||||
carry("sfSample", "sfFile", baseName + "_sf.wav");
|
||||
}
|
||||
const std::string text = PresetIo::exportText(copy);
|
||||
entries.insert(entries.begin(), zip::Entry{baseName + ".szp", std::vector<uint8_t>(text.begin(), text.end())});
|
||||
return zip::write(entries);
|
||||
}
|
||||
|
||||
} // namespace sizzle::io
|
||||
@@ -0,0 +1,52 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// Preset bundles: a device preset with its own sounds, as the Android app shares
|
||||
// Sampler, SF2/XI, Grain Cloud and Wavetable presets (PresetLibrary.bundleForShare
|
||||
// / importZip). A ZIP holding `<name>.szp` (PresetIo text) and the WAVs it names:
|
||||
//
|
||||
// Kick.szp ... pad0File=Kick_pad0.wav, pad0S=..., pad0E=...
|
||||
// Kick_pad0.wav
|
||||
// Pad_sf.wav (sfFile=Pad_sf.wav for SF2/XI, Grain Cloud, Wavetable)
|
||||
//
|
||||
// In a song a slot names its sounds by sample id (`padN`, `sfSample`); in a bundle
|
||||
// by file (`padNFile`, `sfFile`). These functions translate between the two.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "sizzle/Model.hpp"
|
||||
#include "sizzle/Sample.hpp"
|
||||
|
||||
namespace sizzle::io {
|
||||
|
||||
class PresetBundle {
|
||||
public:
|
||||
/** Device types whose presets travel as bundles. */
|
||||
static bool carriesSamples(const std::string &type);
|
||||
|
||||
/**
|
||||
* Import bundle [zip] into [slot] (which takes the preset's device type, as
|
||||
* PresetIo::importText). Every WAV the preset names is decoded and handed to
|
||||
* [keep] (its file name, the sample), which stores it and returns its sample id;
|
||||
* the slot then plays it (`padN` / `sfSample`). False if [zip] isn't a ZIP or
|
||||
* holds no valid preset (the slot is then unchanged). The first `.szp` wins;
|
||||
* macOS `__MACOSX/` and `._` entries are skipped, and only base names count.
|
||||
*/
|
||||
static bool importInto(model::ToolboxSlot &slot, const uint8_t *zip, size_t size,
|
||||
const std::function<std::string(const std::string &file, Sample sample)> &keep);
|
||||
|
||||
/**
|
||||
* [slot] as a bundle named [baseName] (`<baseName>.szp` and its WAVs). [wavOf]
|
||||
* gives the WAV file bytes of a sample id (empty if unknown: that sound is left
|
||||
* out). The preset names files instead of sample ids, as Android writes them.
|
||||
*/
|
||||
static std::vector<uint8_t> exportFrom(const model::ToolboxSlot &slot, const std::string &baseName,
|
||||
const std::function<std::vector<uint8_t>(const std::string &id)> &wavOf);
|
||||
};
|
||||
|
||||
} // namespace sizzle::io
|
||||
@@ -0,0 +1,91 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// io::PresetBundle both ways with the Android app:
|
||||
// argv[1]: a Sampler bundle Android's PresetLibrary wrote (IosGoldenPresetBundle;
|
||||
// core/golden/bundles/android_sampler.zip), imported here;
|
||||
// argv[2]: app/src/test/resources/presetbundle/ios_sampler.zip, the bundle this
|
||||
// code writes, which Android's PresetBundleInteropTest imports. Checked
|
||||
// byte for byte here (`--write` regenerates it).
|
||||
// Both hold the same kit: pad 0 = 100 frames at 44.1 kHz (start 0.25), pad 3 = 200
|
||||
// frames at 22.05 kHz.
|
||||
|
||||
#include "io/PresetBundle.hpp"
|
||||
#include "io/PresetIo.hpp"
|
||||
#include "sampler/SampleStore.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <map>
|
||||
|
||||
using namespace sizzle;
|
||||
|
||||
static int failures = 0;
|
||||
#define CHECK(c) do { if (!(c)) { std::printf("FAIL %s:%d %s\n", __FILE__, __LINE__, #c); ++failures; } } while (0)
|
||||
|
||||
static std::vector<uint8_t> readFile(const char *path) {
|
||||
std::ifstream f(path, std::ios::binary);
|
||||
return std::vector<uint8_t>((std::istreambuf_iterator<char>(f)), {});
|
||||
}
|
||||
|
||||
static Sample ramp(int frames, int rate) {
|
||||
std::vector<float> d((size_t)frames);
|
||||
for (int i = 0; i < frames; ++i) d[(size_t)i] = (float)i / (float)frames - 0.5f;
|
||||
return Sample(std::move(d), rate);
|
||||
}
|
||||
|
||||
/// Imports [zip] and checks it is the kit; samples kept by file name.
|
||||
static void checkKit(const std::vector<uint8_t> &zip, const char *what) {
|
||||
std::map<std::string, Sample> kept;
|
||||
model::ToolboxSlot slot;
|
||||
slot.fill("FILTER"); // the bundle's type replaces it
|
||||
const bool ok = io::PresetBundle::importInto(slot, zip.data(), zip.size(), [&](const std::string &file, Sample s) {
|
||||
kept[file] = std::move(s);
|
||||
return "id:" + file;
|
||||
});
|
||||
std::printf(" %s: %s\n", what, ok ? "imported" : "NOT imported");
|
||||
CHECK(ok && slot.type == "SAMPLER");
|
||||
const std::string p0 = slot.s("pad0", ""), p3 = slot.s("pad3", "");
|
||||
CHECK(p0.rfind("id:", 0) == 0 && p3.rfind("id:", 0) == 0 && !*slot.s("pad1", ""));
|
||||
CHECK(kept.count(p0.substr(3)) && kept[p0.substr(3)].data.size() == 100 && kept[p0.substr(3)].sampleRate == 44100);
|
||||
CHECK(kept.count(p3.substr(3)) && kept[p3.substr(3)].data.size() == 200 && kept[p3.substr(3)].sampleRate == 22050);
|
||||
CHECK(slot.f("pad0S", -1) == 0.25f);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 3) { std::printf("usage: bundle_test <android_sampler.zip|-> <ios_sampler.zip> [--write]\n"); return 2; }
|
||||
|
||||
// The kit as an iOS slot: pads name sample ids.
|
||||
std::map<std::string, Sample> store;
|
||||
store["kick#1"] = ramp(100, 44100);
|
||||
store["snare#2"] = ramp(200, 22050);
|
||||
model::ToolboxSlot slot;
|
||||
slot.fill("SAMPLER");
|
||||
slot.name = "Kit";
|
||||
slot.set("pad0", "kick#1");
|
||||
slot.set("pad0S", 0.25f);
|
||||
slot.set("pad3", "snare#2");
|
||||
const auto zip = io::PresetBundle::exportFrom(slot, "Kit", [&](const std::string &id) {
|
||||
auto it = store.find(id);
|
||||
return it == store.end() ? std::vector<uint8_t>() : sampler::SampleStore::encodeWav(it->second);
|
||||
});
|
||||
checkKit(zip, "own bundle");
|
||||
|
||||
if (argc > 3 && !std::strcmp(argv[3], "--write")) {
|
||||
std::ofstream(argv[2], std::ios::binary).write((const char *)zip.data(), (std::streamsize)zip.size());
|
||||
std::printf(" wrote %s\n", argv[2]);
|
||||
} else {
|
||||
CHECK(readFile(argv[2]) == zip); // the fixture Android imports is what this code writes
|
||||
}
|
||||
|
||||
if (std::strcmp(argv[1], "-")) {
|
||||
const auto android = readFile(argv[1]);
|
||||
if (android.empty()) std::printf(" (no Android bundle at %s: run `make golden`)\n", argv[1]);
|
||||
else checkKit(android, "Android bundle");
|
||||
}
|
||||
|
||||
std::printf(failures ? "bundle_test: %d failure(s)\n" : "bundle_test: ok\n", failures);
|
||||
return failures ? 1 : 0;
|
||||
}
|
||||
@@ -776,6 +776,18 @@ attack=0.01
|
||||
```
|
||||
Copy/paste from the Toolbox parameter editor uses this exact text.
|
||||
|
||||
### Preset bundle (`.zip`)
|
||||
|
||||
What SHARE sends for a Sampler, SF2/XI, Grain Cloud or Wavetable preset: a ZIP
|
||||
holding `<name>.szp` and the WAVs it names. In a song, pads name sample ids
|
||||
(`padN`, `sfSample`); in a bundle they name files (`padNFile=<name>_padN.wav`,
|
||||
`sfFile=<name>_sf.wav`). Android: `PresetLibrary.bundleForShare` / `importZip`.
|
||||
iOS: `core/src/io/PresetBundle`. The two are checked against each other.
|
||||
`IosGoldenPresetBundle` (part of `make -C ios golden`) writes a bundle with
|
||||
Android's code for `core/tests/bundle_test.cpp` to import. `bundle_test` also
|
||||
writes `app/src/test/resources/presetbundle/ios_sampler.zip` (checked byte for
|
||||
byte), which `PresetBundleInteropTest` imports with Android's code.
|
||||
|
||||
### MIDI mapping (`MidiMapIo`, `.szm`, 0.39.0)
|
||||
|
||||
One device's parameter → MIDI CC mapping, exported and imported from the ⇄ MIDI
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
+2
-2
@@ -12,8 +12,8 @@
|
||||
# or polish. versionCode is monotonic and bumps by 1 on every release,
|
||||
# because F-Droid and the Android package manager order installs by it alone.
|
||||
|
||||
versionName = 0.39.0
|
||||
versionCode = 73
|
||||
versionName = 0.39.1
|
||||
versionCode = 74
|
||||
|
||||
# Namespace for every platform: cc.tiredsysadmin.<os>.sizzle. Android:
|
||||
# cc.tiredsysadmin.android.sizzle (app/), iOS/iPadOS: cc.tiredsysadmin.ios.sizzle
|
||||
|
||||
Reference in New Issue
Block a user