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
@@ -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.
Reference in New Issue
Block a user