Compare commits
36
Commits
2d285592e2
...
main
@@ -16,3 +16,6 @@ dist/
|
||||
|
||||
# NOTE: gradle/wrapper/gradle-wrapper.jar IS committed (Gradle's recommended
|
||||
# practice) so ./gradlew works on a fresh clone with no extra setup.
|
||||
|
||||
# Reference audio for the C++ core, regenerated by `make -C ios golden`
|
||||
/core/golden/
|
||||
|
||||
+138
-1
@@ -2,7 +2,144 @@
|
||||
|
||||
Sizzletracker for Android (`cc.tiredsysadmin.android.sizzle`). One entry per
|
||||
version in `versions.properties`; versions before 0.28.0 are described in the git
|
||||
log (one commit per version).
|
||||
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.42.0 (versionCode 79)
|
||||
|
||||
- **RANDOM:** the Synth, Morph Pad, Grain Cloud, Wavetable and Ambience Reverb
|
||||
editors have a RANDOM button in the preset bar. It throws a new patch into the
|
||||
editor and names it ("Hazy Drift"). It is a starting point rather than a slot
|
||||
machine: a roll is always something you can hear and never something that
|
||||
clips, because levels, filters and envelopes are drawn inside ranges that keep a
|
||||
patch in that territory instead of scattered over the whole knob. It replaces
|
||||
the editor's settings like loading a preset does, so SAVE first if you want to
|
||||
keep what is there — but it never touches a sample you loaded or a wavetable you
|
||||
imported. The other devices have none on purpose: a Sampler is only as
|
||||
interesting as the sound you put in it, and the MIDI effects have too few
|
||||
settings for a dice roll to say anything. (iOS has the same in 0.42.0.)
|
||||
- Fix: the shared engine did not compile outside Apple's toolchain — a missing
|
||||
`<cstdint>` in `core/include/sizzle/Model.hpp`. No change to the apps; it means
|
||||
the engine's tests and benchmark now build with GCC too.
|
||||
|
||||
## 0.41.2 (versionCode 78)
|
||||
|
||||
Housekeeping and speed; nothing you can see changes, except that the app is
|
||||
half the size and lighter on the battery.
|
||||
|
||||
- **The APK is half as big** — 21.5 MB → 10.1 MB. Release builds now go through
|
||||
R8 (shrink, optimise, obfuscate, and drop unused resources), which throws away
|
||||
the Compose and Material icon code the app never calls. Only the two JNI
|
||||
classes are pinned by name (`app/proguard-rules.pro`), because the native
|
||||
library looks them up at runtime; `make dist` keeps the de-obfuscation map next
|
||||
to the APK so a crash report from a published build can still be read.
|
||||
- **Less battery while a song is stopped.** The thread that feeds the transport
|
||||
display polled the engine 100 times a second whatever was happening; it now
|
||||
does that only while the song plays or a recording is armed, and waits 100 ms a
|
||||
turn otherwise. Pressing Play still moves the playhead in the same frame — a
|
||||
transport call wakes it. iOS does the same (30 Hz playing, 10 Hz stopped).
|
||||
- **Smoother editing.** Every edit hands the engine the whole song as text. That
|
||||
text is now built in one pre-sized pass instead of a string per line, and a
|
||||
burst of edits — dragging a note column, sweeping a knob — is collected into
|
||||
one sync instead of one per touch event.
|
||||
- **The mixer costs less per sample.** Channel volume, mute/solo and the effect
|
||||
chain are read once per audio block rather than once per frame, in the shared
|
||||
C++ engine (so iOS gets it too). Bit-for-bit the same audio: all 61 reference
|
||||
scenarios still match the Kotlin DSP.
|
||||
- **Dead code gone.** The Kotlin DSP that `core/` replaced in 0.37.0 was still
|
||||
compiled into every APK although nothing called it; it has moved to the test
|
||||
source set, where it belongs as the reference the C++ is checked against. The
|
||||
golden tests' `TestVoice` wrappers left the shared engine's sources for the
|
||||
same reason, and a handful of unused declarations are gone.
|
||||
- Fix: `make lint` failed on a manifest that asked for `ACCESS_FINE_LOCATION`
|
||||
without `ACCESS_COARSE_LOCATION` (the BLE MIDI scan on Android 8–11). Both are
|
||||
declared and both are requested now, so `make check` passes again.
|
||||
|
||||
## 0.41.1 (versionCode 77)
|
||||
|
||||
- No Android change: an iOS redraw fix (see `ios/CHANGELOG.md`).
|
||||
|
||||
## 0.41.0 (versionCode 76)
|
||||
|
||||
- **Keep screen on:** a Settings › Interface toggle that stops the screen from
|
||||
dimming or locking while Sizzle is open (remembered). (iOS has the same in 0.41.0.)
|
||||
|
||||
## 0.40.0 (versionCode 75)
|
||||
|
||||
- **Sampler One-shot:** a ONE-SHOT toggle at the top of the Sampler editor. On,
|
||||
note-offs are ignored: releasing a MIDI key or pad, the tracker's `===` and a
|
||||
new note on the same track no longer cut a pad, which plays its whole slice
|
||||
(the bus's eight voices overlap). Stopping or pausing the song still fades the
|
||||
pads it played, and MIDI PANIC silences everything. It's a Sampler setting, so
|
||||
it's saved with the song and in presets, and the Sampler plugin offers it as a
|
||||
parameter. (iOS has the same in 0.40.0.)
|
||||
|
||||
## 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
|
||||
EXPORT and IMPORT. EXPORT shares the device's mapping (which MIDI CC drives
|
||||
which parameter) as a plain-text `.szm` file; IMPORT replaces the device's
|
||||
mapping with one from a file for the same kind of device, moving any CC another
|
||||
parameter used. The same files work on iOS. (iOS has the same in 0.39.0.)
|
||||
|
||||
## 0.38.0 (versionCode 72)
|
||||
|
||||
- **Bluetooth LE MIDI controllers:** Settings › MIDI Sync › MIDI inputs has a
|
||||
Bluetooth MIDI section. SCAN looks for BLE MIDI controllers for 15 s (asking for
|
||||
the Bluetooth permission the first time), CONNECT opens one, and from then on it
|
||||
is one of the MIDI inputs: listed, switchable and played on the mixer tracks of
|
||||
its channel. Connected controllers are remembered and connected again at every
|
||||
start until FORGET. (iOS has the same in 0.38.0.)
|
||||
|
||||
## 0.37.0 (versionCode 71)
|
||||
|
||||
- **One engine for Android and iOS:** Android now plays through the shared C++
|
||||
engine in `core/` (sequencer, mixer, every instrument and effect), the same
|
||||
code the iOS app runs, instead of the Kotlin engine. Audio is rendered entirely
|
||||
in native code inside the Oboe callback, so a Java garbage-collector pause can
|
||||
no longer glitch playback. Edits reach the engine as they happen; playback
|
||||
carries on through them.
|
||||
- **One version:** Android and iOS now carry the same version number and
|
||||
versionCode (continuing Android's), and from now on ship the same features.
|
||||
- The Kotlin engine stays in the unit tests as the reference the C++ engine is
|
||||
checked against.
|
||||
|
||||
## 0.36.2 (versionCode 70)
|
||||
|
||||
- **Instrument editors in landscape:** the audition keyboard (or the Sampler's
|
||||
pads) is now pinned on the right at the same width as on the Toolbox and
|
||||
Tracker tabs, with the controls scrolling on the left, instead of being stacked
|
||||
below the controls. Tab labels shrink when there are more than five, so the
|
||||
Wavetable's FILTER tab isn't cut off in the narrower column.
|
||||
|
||||
## 0.36.1 (versionCode 69)
|
||||
|
||||
- **Wavetable editor fits without scrolling:** tabs are now OSC 1 · OSC 2 · VOICE
|
||||
· FILTER · AMP · MOD · LFO, each oscillator's card draws its own table, and LOAD
|
||||
TABLE moved into Oscillator 1's title with the frame size below the table. The
|
||||
big table strip above the tabs is gone. Tabs in every device editor now share
|
||||
the width instead of scrolling sideways.
|
||||
|
||||
## 0.36.0 (versionCode 68)
|
||||
|
||||
- **One-tap transfer from Mikro Seq:** a song sent by Mikro Seq's "Current to
|
||||
Sizzle" button (the `extra.REPLACE` intent) loads straight away, without the
|
||||
"replace song?" question. Only Mikro Seq can do this: the URI must come from
|
||||
its own content provider. The replaced song is saved first as "Before Mikro Seq
|
||||
import" in the project list, and a toast says so. Every other app still gets
|
||||
the question.
|
||||
|
||||
## 0.35.1 (versionCode 67)
|
||||
|
||||
- **Fix:** knobs, switches, EQ faders and the envelope/filter/LFO drawings in the
|
||||
new device editors did not move when touched (the value changed, the screen
|
||||
didn't). They now redraw on every edit.
|
||||
|
||||
## 0.35.0 (versionCode 66)
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ ADB := adb
|
||||
|
||||
VERSIONS := versions.properties
|
||||
APP_ID := $(shell sed -n 's/^[[:space:]]*namespace[[:space:]]*=[[:space:]]*"\(.*\)".*/\1/p' app/build.gradle.kts)
|
||||
VERSION_NAME := $(shell sed -n 's/^android.versionName[[:space:]]*=[[:space:]]*//p' $(VERSIONS) | tr -d ' ')
|
||||
VERSION_CODE := $(shell sed -n 's/^android.versionCode[[:space:]]*=[[:space:]]*//p' $(VERSIONS) | tr -d ' ')
|
||||
VERSION_NAME := $(shell sed -n 's/^versionName[[:space:]]*=[[:space:]]*//p' $(VERSIONS) | tr -d ' ')
|
||||
VERSION_CODE := $(shell sed -n 's/^versionCode[[:space:]]*=[[:space:]]*//p' $(VERSIONS) | tr -d ' ')
|
||||
|
||||
# Publishing to the private F-Droid repo (CLAUDE.md). Both halves of a release
|
||||
# — the artifact and its metadata — live under the same host.
|
||||
@@ -35,6 +35,10 @@ FDROID_METADATA := /var/lib/fdroid/metadata
|
||||
# directory expects; app/build.gradle.kts stamps the same name onto the output.
|
||||
APK_NAME := $(APP_ID)_$(VERSION_CODE).apk
|
||||
RELEASE_APK := app/build/outputs/apk/release/$(APK_NAME)
|
||||
# R8 renames the release build, so a crash report from it is unreadable without
|
||||
# this. It is staged beside the APK and kept locally — never published.
|
||||
RELEASE_MAP := app/build/outputs/mapping/release/mapping.txt
|
||||
DIST_MAP := dist/$(APP_ID)_$(VERSION_CODE)-mapping.txt
|
||||
STAGING_APK := app/build/outputs/apk/staging/app-staging.apk
|
||||
METADATA_YML := dist/$(APP_ID).yml
|
||||
|
||||
@@ -110,12 +114,18 @@ launch:
|
||||
# ------------------------------------------------------------------ dist
|
||||
# Everything a publish needs, staged locally first so it can be inspected
|
||||
# before anything leaves the machine.
|
||||
dist: dist/$(APK_NAME) $(METADATA_YML)
|
||||
dist: dist/$(APK_NAME) $(DIST_MAP) $(METADATA_YML)
|
||||
|
||||
dist/$(APK_NAME): $(RELEASE_APK)
|
||||
@mkdir -p dist
|
||||
cp $(RELEASE_APK) $@
|
||||
|
||||
# The de-obfuscation map for this exact versionCode. `publish` does not upload it;
|
||||
# it stays here so a stack trace from the published APK can still be read.
|
||||
$(DIST_MAP): $(RELEASE_APK)
|
||||
@mkdir -p dist
|
||||
cp $(RELEASE_MAP) $@
|
||||
|
||||
# F-Droid metadata. Regenerated from versions.properties on every dist so the
|
||||
# CurrentVersion lines can never lag the APK next to them.
|
||||
$(METADATA_YML): $(VERSIONS) Makefile
|
||||
@@ -153,6 +163,7 @@ publish-metadata: $(METADATA_YML)
|
||||
|
||||
publish: publish-apk publish-metadata
|
||||
@echo "published $(APP_ID) $(VERSION_NAME) ($(VERSION_CODE)); sign it on the repo host"
|
||||
@echo "keep $(DIST_MAP) — it is the only way to read a crash from this build"
|
||||
|
||||
# ------------------------------------------------------------------ versioning
|
||||
# versionCode always moves by exactly 1: F-Droid and the package manager order
|
||||
@@ -163,15 +174,15 @@ bump-patch: ; @$(MAKE) --no-print-directory bump FIELD=3
|
||||
|
||||
bump:
|
||||
@awk -v field=$(FIELD) ' \
|
||||
/^android.versionName/ { \
|
||||
/^versionName/ { \
|
||||
split($$3, v, "."); \
|
||||
v[field]++; \
|
||||
for (i = field + 1; i <= 3; i++) v[i] = 0; \
|
||||
printf "android.versionName = %d.%d.%d\n", v[1], v[2], v[3]; next } \
|
||||
/^android.versionCode/ { printf "android.versionCode = %d\n", $$3 + 1; next } \
|
||||
printf "versionName = %d.%d.%d\n", v[1], v[2], v[3]; next } \
|
||||
/^versionCode/ { printf "versionCode = %d\n", $$3 + 1; next } \
|
||||
{ print }' $(VERSIONS) > $(VERSIONS).tmp
|
||||
@mv $(VERSIONS).tmp $(VERSIONS)
|
||||
@sed -n 's/^android\./ android./p' $(VERSIONS)
|
||||
@grep -E '^version(Name|Code)' $(VERSIONS) | sed 's/^/ /'
|
||||
|
||||
# ------------------------------------------------------------------ clean
|
||||
clean:
|
||||
|
||||
+12
-7
@@ -14,8 +14,8 @@ plugins {
|
||||
val appVersions = Properties().apply {
|
||||
rootProject.file("versions.properties").inputStream().use { load(it) }
|
||||
}
|
||||
val appVersionName: String = appVersions.getProperty("android.versionName").trim()
|
||||
val appVersionCode: Int = appVersions.getProperty("android.versionCode").trim().toInt()
|
||||
val appVersionName: String = appVersions.getProperty("versionName").trim()
|
||||
val appVersionCode: Int = appVersions.getProperty("versionCode").trim().toInt()
|
||||
|
||||
android {
|
||||
namespace = "cc.tiredsysadmin.android.sizzle"
|
||||
@@ -52,9 +52,13 @@ android {
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
// Shrinking is off by default so newcomers get readable stack traces.
|
||||
// Flip to true once the app stabilises.
|
||||
isMinifyEnabled = false
|
||||
// R8: shrink + optimise + obfuscate, and drop unreferenced resources.
|
||||
// Only the JNI entry points need keeping (see proguard-rules.pro); the
|
||||
// app reflects over nothing of its own. A release stack trace is now
|
||||
// obfuscated, so keep app/build/outputs/mapping/release/mapping.txt
|
||||
// beside any APK you publish — `make dist` copies it into dist/.
|
||||
isMinifyEnabled = true
|
||||
isShrinkResources = true
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro",
|
||||
@@ -66,8 +70,9 @@ android {
|
||||
// the app un-optimised and makes Compose several times slower — so measuring
|
||||
// UI "snappiness" on a debug build is misleading. This variant flips
|
||||
// debuggability off (the single biggest perf lever) while reusing the debug
|
||||
// signing key, so it still installs without a release keystore. R8/shrinking
|
||||
// stays off to avoid needing JNI/Compose keep-rules for now.
|
||||
// signing key, so it still installs without a release keystore. R8 stays off
|
||||
// here on purpose: staging exists to measure the UI, and un-obfuscated stack
|
||||
// traces are worth more than the last few hundred KB. `release` is minified.
|
||||
create("staging") {
|
||||
initWith(getByName("debug"))
|
||||
isDebuggable = false
|
||||
|
||||
Vendored
+19
-3
@@ -1,3 +1,19 @@
|
||||
# ProGuard/R8 rules for release builds. Minification is currently disabled in
|
||||
# build.gradle.kts (isMinifyEnabled = false), so this file is intentionally empty.
|
||||
# Add keep-rules here if/when you enable shrinking and hit reflection issues.
|
||||
# R8 rules for the release build (isMinifyEnabled = true in build.gradle.kts).
|
||||
#
|
||||
# Keep as little as possible: everything else — Compose, media3, DataStore,
|
||||
# coroutines — ships its own consumer rules inside its AAR, and the app itself
|
||||
# uses no reflection over its own classes (songs, presets, themes and bindings
|
||||
# are all read and written as text by hand-written parsers in io/).
|
||||
|
||||
# JNI. The native library resolves Java_<mangled package>_<class>_<method> by
|
||||
# name at *runtime*, so a renamed class or method is an UnsatisfiedLinkError on
|
||||
# first play — not a build error. Both halves of the bridge must keep their
|
||||
# names: audio/NativeEngine (the engine, src/main/cpp/jni_engine.cpp) and
|
||||
# audio/NativeAudioBridge (the Oboe stream, src/main/cpp/native_audio.cpp).
|
||||
-keepclasseswithmembernames,includedescriptorclasses class * {
|
||||
native <methods>;
|
||||
}
|
||||
|
||||
# Kotlin tells R8 what is nullable through these; dropping them makes R8's
|
||||
# warnings about the Kotlin stdlib noisy for no gain.
|
||||
-dontwarn kotlin.Unit
|
||||
|
||||
@@ -7,12 +7,25 @@
|
||||
FOREGROUND_SERVICE : keep the sequencer alive while the app is backgrounded.
|
||||
FOREGROUND_SERVICE_MEDIA_PLAYBACK : Android 14 requires a typed FGS.
|
||||
POST_NOTIFICATIONS : show the media transport notification (Android 13+).
|
||||
BLUETOOTH_CONNECT : Bluetooth MIDI + gamepad on Android 12+. -->
|
||||
BLUETOOTH_CONNECT : Bluetooth MIDI + gamepad on Android 12+.
|
||||
BLUETOOTH_SCAN : finding BLE MIDI controllers (Settings › MIDI inputs) on
|
||||
Android 12+; never used to derive location.
|
||||
BLUETOOTH / _ADMIN : the same scan on Android 8-11.
|
||||
ACCESS_FINE_LOCATION + ACCESS_COARSE_LOCATION : a BLE scan on Android 8-11
|
||||
was gated on location permission. Both are declared
|
||||
because the platform (and lint) treat FINE as an
|
||||
upgrade of COARSE, and we only ever scan with them. -->
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
|
||||
android:usesPermissionFlags="neverForLocation" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:maxSdkVersion="30" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30" />
|
||||
|
||||
<!-- Hardware we can *use* but do not *require* (so the app still installs on
|
||||
devices without them). Code must always feature-detect at runtime. -->
|
||||
@@ -20,8 +33,15 @@
|
||||
<uses-feature android:name="android.software.midi" android:required="false" />
|
||||
<uses-feature android:name="android.hardware.gamepad" android:required="false" />
|
||||
<uses-feature android:name="android.hardware.bluetooth" android:required="false" />
|
||||
<uses-feature android:name="android.hardware.bluetooth_le" android:required="false" />
|
||||
<uses-feature android:name="android.hardware.microphone" android:required="false" />
|
||||
|
||||
<!-- Lets SongIntents.isTrustedReplace see which app owns a content provider, so
|
||||
only Mikro Seq's one-tap transfer can replace the song without asking. -->
|
||||
<queries>
|
||||
<package android:name="cc.tiredsysadmin.android.mikroseq" />
|
||||
</queries>
|
||||
|
||||
<application
|
||||
android:name=".SizzleApp"
|
||||
android:allowBackup="true"
|
||||
|
||||
@@ -1,15 +1,32 @@
|
||||
# Native build for the Oboe (AAudio) low-latency output backend.
|
||||
# Native build: the shared C++ engine (../../../../core, the same code the iOS app
|
||||
# runs), its JNI glue (jni_engine.cpp) and the Oboe (AAudio) low-latency output.
|
||||
cmake_minimum_required(VERSION 3.22.1)
|
||||
project(sizzle_native)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# Oboe ships as a prefab package inside the com.google.oboe:oboe AAR; AGP exposes
|
||||
# it here when `buildFeatures { prefab = true }` is set in build.gradle.kts.
|
||||
find_package(oboe REQUIRED CONFIG)
|
||||
|
||||
add_library(sizzle_native SHARED native_audio.cpp)
|
||||
# The engine as an object library, not a static one: the devices are found through
|
||||
# weak placeholder makers (core/src/fx/Registry.cpp), so every object must be linked
|
||||
# in or the placeholders would win. Optimised even in debug builds (the DSP must
|
||||
# keep up in real time).
|
||||
set(CORE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../core)
|
||||
file(GLOB CORE_SRC CONFIGURE_DEPENDS ${CORE_DIR}/src/*.cpp ${CORE_DIR}/src/*/*.cpp)
|
||||
add_library(sizzle_core OBJECT ${CORE_SRC})
|
||||
target_include_directories(sizzle_core PUBLIC ${CORE_DIR}/include ${CORE_DIR}/src ${CORE_DIR}/src/fx)
|
||||
target_compile_options(sizzle_core PRIVATE -O2 -Wno-unused-parameter)
|
||||
|
||||
add_library(sizzle_native SHARED native_audio.cpp jni_engine.cpp $<TARGET_OBJECTS:sizzle_core>)
|
||||
target_include_directories(sizzle_native PRIVATE ${CORE_DIR}/include ${CORE_DIR}/src ${CORE_DIR}/src/fx)
|
||||
target_compile_options(sizzle_native PRIVATE -O2)
|
||||
|
||||
target_link_libraries(sizzle_native
|
||||
oboe::oboe
|
||||
z
|
||||
log)
|
||||
|
||||
# Align ELF load segments to 16 KB so the library works on Android 15+ devices
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// JNI for audio/NativeEngine.kt: the Android app drives the shared C++ engine
|
||||
// (core/src/host/EngineHost) through these. The Kotlin model stays the UI's
|
||||
// state; NativeEngine mirrors it here as project text (nativeSync).
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
#include "host/EngineHost.hpp"
|
||||
#include "sizzle/Randomizer.hpp"
|
||||
|
||||
using sizzle::host::EngineHost;
|
||||
|
||||
namespace {
|
||||
|
||||
std::atomic<EngineHost *> g_host{nullptr};
|
||||
|
||||
// A finished master take, until Kotlin collects it (nativeTakeFinished).
|
||||
std::mutex g_takeLock;
|
||||
std::string g_takePath;
|
||||
int64_t g_takeStart = 0;
|
||||
bool g_takeReady = false;
|
||||
|
||||
std::string str(JNIEnv *env, jstring s) {
|
||||
if (!s) return {};
|
||||
const char *c = env->GetStringUTFChars(s, nullptr);
|
||||
std::string out = c ? c : "";
|
||||
if (c) env->ReleaseStringUTFChars(s, c);
|
||||
return out;
|
||||
}
|
||||
|
||||
EngineHost *host() { return g_host.load(std::memory_order_acquire); }
|
||||
|
||||
} // namespace
|
||||
|
||||
sizzle::host::EngineHost *sizzleHost() { return host(); }
|
||||
|
||||
#define JNI_FN(ret, name) extern "C" JNIEXPORT ret JNICALL Java_cc_tiredsysadmin_android_sizzle_audio_NativeEngine_##name
|
||||
#define H if (EngineHost *h = host()) h
|
||||
|
||||
JNI_FN(void, nativeCreate)(JNIEnv *, jobject, jint sampleRate) {
|
||||
if (host()) return;
|
||||
auto *h = new EngineHost(sampleRate); // lives as long as the process
|
||||
h->recorder().onFinished = [](const std::string &path, int64_t start) {
|
||||
std::lock_guard<std::mutex> g(g_takeLock);
|
||||
g_takePath = path;
|
||||
g_takeStart = start;
|
||||
g_takeReady = true;
|
||||
};
|
||||
g_host.store(h, std::memory_order_release);
|
||||
}
|
||||
|
||||
JNI_FN(void, nativeLoad)(JNIEnv *env, jobject, jstring text) { H->loadProjectText(str(env, text)); }
|
||||
JNI_FN(void, nativeSync)(JNIEnv *env, jobject, jstring text) { H->syncProjectText(str(env, text)); }
|
||||
JNI_FN(void, nativeRebuildFxChains)(JNIEnv *, jobject) { H->rebuildFxChains(); }
|
||||
JNI_FN(void, nativeRebuildArrangement)(JNIEnv *, jobject) { H->rebuildArrangement(); }
|
||||
JNI_FN(void, nativeRefreshLoopPlaylist)(JNIEnv *, jobject) { H->refreshLoopPlaylist(); }
|
||||
|
||||
JNI_FN(void, nativePlay)(JNIEnv *, jobject, jint beat) { H->play(beat); }
|
||||
JNI_FN(void, nativePause)(JNIEnv *, jobject) { H->pause(); }
|
||||
JNI_FN(void, nativeStop)(JNIEnv *, jobject) { H->stop(); }
|
||||
JNI_FN(void, nativePanic)(JNIEnv *, jobject) { H->panic(); }
|
||||
|
||||
/** Playing in bit 62, the line in bits 31..61, the beat in bits 0..30. */
|
||||
JNI_FN(jlong, nativeTransport)(JNIEnv *, jobject) {
|
||||
EngineHost *h = host();
|
||||
if (!h) return 0;
|
||||
const auto t = h->transport();
|
||||
return ((jlong)(t.isPlaying ? 1 : 0) << 62) | ((jlong)(t.currentLine & 0x7FFFFFFF) << 31) | (jlong)(t.currentBeat & 0x7FFFFFFF);
|
||||
}
|
||||
|
||||
JNI_FN(void, nativeLiveNoteOn)(JNIEnv *, jobject, jint pitch, jint vel) { H->liveNoteOn(pitch, vel); }
|
||||
JNI_FN(void, nativeLiveNoteOff)(JNIEnv *, jobject, jint pitch) { H->liveNoteOff(pitch); }
|
||||
JNI_FN(void, nativeAuditionSlotOn)(JNIEnv *, jobject, jint slot, jint midi) { H->auditionSlotOn(slot, midi); }
|
||||
JNI_FN(void, nativeAuditionSlotOff)(JNIEnv *, jobject, jint midi) { H->auditionSlotOff(midi); }
|
||||
JNI_FN(void, nativeBusNoteOn)(JNIEnv *, jobject, jint ch, jint midi, jint vel) { H->busNoteOn(ch, midi, vel); }
|
||||
JNI_FN(void, nativeBusNoteOff)(JNIEnv *, jobject, jint ch, jint midi) { H->busNoteOff(ch, midi); }
|
||||
JNI_FN(jstring, nativeDescribeBusTargets)(JNIEnv *env, jobject, jint ch, jint midi) {
|
||||
EngineHost *h = host();
|
||||
return env->NewStringUTF(h ? h->describeBusTargets(ch, midi).c_str() : "");
|
||||
}
|
||||
|
||||
JNI_FN(jfloat, nativeChannelMeter)(JNIEnv *, jobject, jint ch) { EngineHost *h = host(); return h ? h->channelMeter(ch) : 0.f; }
|
||||
JNI_FN(jboolean, nativeChannelClipped)(JNIEnv *, jobject, jint ch) { EngineHost *h = host(); return h && h->channelClipped(ch); }
|
||||
JNI_FN(jint, nativeEffectScope)(JNIEnv *env, jobject, jint slot, jfloatArray out) {
|
||||
EngineHost *h = host();
|
||||
if (!h || !out) return -1;
|
||||
const jsize cap = env->GetArrayLength(out);
|
||||
jfloat *buf = env->GetFloatArrayElements(out, nullptr);
|
||||
const int n = h->effectScope(slot, buf, cap);
|
||||
env->ReleaseFloatArrayElements(out, buf, 0);
|
||||
return n;
|
||||
}
|
||||
JNI_FN(jfloat, nativeEffectPlayhead)(JNIEnv *, jobject, jint slot) { EngineHost *h = host(); return h ? h->effectPlayhead(slot) : -1.f; }
|
||||
|
||||
JNI_FN(void, nativeSetMidiOutEnabled)(JNIEnv *, jobject, jboolean on) { H->setMidiOutEnabled(on); }
|
||||
JNI_FN(jint, nativePollMidiOut)(JNIEnv *, jobject) { EngineHost *h = host(); return h ? h->pollMidiOut() : -1; }
|
||||
|
||||
JNI_FN(void, nativePutSample)(JNIEnv *env, jobject, jstring id, jfloatArray data, jint rate, jint loopStart, jint loopEnd) {
|
||||
EngineHost *h = host();
|
||||
if (!h || !data) return;
|
||||
const jsize n = env->GetArrayLength(data);
|
||||
std::vector<float> v((size_t)n);
|
||||
env->GetFloatArrayRegion(data, 0, n, v.data());
|
||||
h->putSample(str(env, id), sizzle::Sample(std::move(v), rate, loopStart, loopEnd));
|
||||
}
|
||||
JNI_FN(void, nativeRemoveSample)(JNIEnv *env, jobject, jstring id) { H->removeSample(str(env, id)); }
|
||||
|
||||
JNI_FN(void, nativeSetRecordPath)(JNIEnv *env, jobject, jstring path) { H->recorder().setPath(str(env, path)); }
|
||||
JNI_FN(void, nativeSetRecordingArm)(JNIEnv *, jobject, jboolean armed, jint tail) { H->setRecordingArm(armed, tail); }
|
||||
JNI_FN(void, nativeSetRecordTailBars)(JNIEnv *, jobject, jint tail) { H->setRecordTailBars(tail); }
|
||||
JNI_FN(jboolean, nativeRecordingActive)(JNIEnv *, jobject) { EngineHost *h = host(); return h && h->recorder().isActive(); }
|
||||
/** "<start millis>\t<path>" of a take that finished since the last call (path empty
|
||||
* when writing failed), or null. */
|
||||
JNI_FN(jstring, nativeTakeFinished)(JNIEnv *env, jobject) {
|
||||
std::lock_guard<std::mutex> g(g_takeLock);
|
||||
if (!g_takeReady) return nullptr;
|
||||
g_takeReady = false;
|
||||
return env->NewStringUTF((std::to_string(g_takeStart) + "\t" + g_takePath).c_str());
|
||||
}
|
||||
/** Shutting down: finish a take being captured so its file is complete. */
|
||||
JNI_FN(void, nativeEndCapture)(JNIEnv *, jobject) { H->recorder().endCapture(); }
|
||||
JNI_FN(void, nativeExternalClockStart)(JNIEnv *, jobject) { H->externalClockStart(); }
|
||||
JNI_FN(void, nativeExternalClockStop)(JNIEnv *, jobject) { H->externalClockStop(); }
|
||||
|
||||
// The preset randomizer (core/src/model/Randomizer.cpp). Pure functions of type and
|
||||
// seed — no engine involved — so unlike everything above they work before
|
||||
// nativeCreate and cannot be affected by what the audio thread is doing.
|
||||
JNI_FN(jboolean, nativeCanRandomize)(JNIEnv *env, jobject, jstring type) {
|
||||
return sizzle::model::canRandomize(str(env, type).c_str()) ? JNI_TRUE : JNI_FALSE;
|
||||
}
|
||||
|
||||
/** A random patch as preset text (io/PresetIo's format), for PresetIo.import. */
|
||||
JNI_FN(jstring, nativeRandomPreset)(JNIEnv *env, jobject, jstring type, jint seed) {
|
||||
const std::string text = sizzle::model::randomPresetText(str(env, type).c_str(), (uint32_t)seed);
|
||||
return env->NewStringUTF(text.c_str());
|
||||
}
|
||||
|
||||
/** The name that goes with that seed (PresetIo.import does not carry NAME through). */
|
||||
JNI_FN(jstring, nativeRandomName)(JNIEnv *env, jobject, jstring type, jint seed) {
|
||||
const std::string name = sizzle::model::randomName(str(env, type).c_str(), (uint32_t)seed);
|
||||
return env->NewStringUTF(name.c_str());
|
||||
}
|
||||
|
||||
/** The AudioTrack fallback's render: [frames] interleaved stereo frames into [out]. */
|
||||
JNI_FN(void, nativeRender)(JNIEnv *env, jobject, jfloatArray out, jint frames) {
|
||||
EngineHost *h = host();
|
||||
jfloat *buf = env->GetFloatArrayElements(out, nullptr);
|
||||
if (h) h->render(buf, frames);
|
||||
else for (jint i = 0; i < frames * 2; ++i) buf[i] = 0.f;
|
||||
env->ReleaseFloatArrayElements(out, buf, 0);
|
||||
}
|
||||
@@ -3,11 +3,12 @@
|
||||
|
||||
// Native Oboe (AAudio) output backend for Sizzletracker.
|
||||
//
|
||||
// Opens a low-latency mono float Oboe output stream. On each real-time data
|
||||
// callback it calls back into Kotlin (NativeAudioBridge.renderAudio) to fill a
|
||||
// reused Java float[] from the shared AudioEngine.fillBlock, then copies that
|
||||
// into Oboe's output buffer. This keeps ONE implementation of the synth/mixer
|
||||
// (in Kotlin) while delivering audio through the lower-latency native path.
|
||||
// Opens a low-latency stereo float Oboe output stream. Each real-time data
|
||||
// callback renders straight from the shared C++ engine (core/, through the
|
||||
// EngineHost that jni_engine.cpp owns): no JVM call on the audio thread, so no
|
||||
// garbage-collector pause can glitch it.
|
||||
|
||||
#include "host/EngineHost.hpp"
|
||||
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
@@ -25,13 +26,11 @@
|
||||
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
|
||||
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
|
||||
|
||||
// The engine host (jni_engine.cpp); null until the app creates it.
|
||||
sizzle::host::EngineHost *sizzleHost();
|
||||
|
||||
namespace {
|
||||
|
||||
JavaVM *g_vm = nullptr;
|
||||
jobject g_callback = nullptr; // global ref to the NativeAudioBridge
|
||||
jmethodID g_renderMethod = nullptr;
|
||||
jfloatArray g_buffer = nullptr; // reused Java float[] of g_frames length
|
||||
int g_frames = 0;
|
||||
int32_t g_prevXRuns = 0; // last-seen underrun count, for adaptive sizing
|
||||
int32_t g_sampleRate = 48000; // remembered so the stream can be reopened on disconnect
|
||||
std::atomic<bool> g_wantRunning{false}; // false once nativeStop is called, so a
|
||||
@@ -39,21 +38,9 @@ std::atomic<bool> g_wantRunning{false}; // false once nativeStop is called, so a
|
||||
// the app deliberately shut down
|
||||
|
||||
// How glitch-resistant the output buffer starts (in device bursts). The buffer
|
||||
// then grows adaptively (see onAudioReady) if underruns still occur. Profiling
|
||||
// showed the JVM render is fast on average (<1 ms) but spikes to 3-7 ms when a GC
|
||||
// pause freezes the callback thread; 4 bursts (~8 ms on a 96-frame device) absorbs
|
||||
// those from the first note instead of glitching until adaptive growth catches up.
|
||||
// then grows adaptively (see onAudioReady) if underruns still occur. (Sized when
|
||||
// the render went through the JVM and its GC pauses; kept, the cost is latency only.)
|
||||
constexpr int32_t kInitialBursts = 8;
|
||||
constexpr int32_t kMaxBufferFrames = 8192; // cap for the reused Java buffer
|
||||
|
||||
// Fetch a JNIEnv for the (persistent) audio callback thread, attaching once.
|
||||
JNIEnv *callbackEnv() {
|
||||
JNIEnv *env = nullptr;
|
||||
if (g_vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) == JNI_EDETACHED) {
|
||||
g_vm->AttachCurrentThread(&env, nullptr);
|
||||
}
|
||||
return env;
|
||||
}
|
||||
|
||||
class SizzleCallback : public oboe::AudioStreamDataCallback {
|
||||
public:
|
||||
@@ -76,19 +63,8 @@ public:
|
||||
stream->getBufferSizeInFrames() + stream->getFramesPerBurst());
|
||||
}
|
||||
|
||||
JNIEnv *env = callbackEnv();
|
||||
if (!env || !g_callback || !g_renderMethod || !g_buffer) {
|
||||
for (int i = 0; i < numFrames * 2; ++i) out[i] = 0.0f; // stereo silence
|
||||
return oboe::DataCallbackResult::Continue;
|
||||
}
|
||||
const int n = numFrames < g_frames ? numFrames : g_frames;
|
||||
// Ask Kotlin to render n frames; fillBlock writes 2*n interleaved-stereo
|
||||
// samples into the reused Java buffer ...
|
||||
env->CallVoidMethod(g_callback, g_renderMethod, g_buffer, n);
|
||||
// ... then copy them out to Oboe (2 samples/frame) and pad any remainder with
|
||||
// silence (the Java buffer is sized to the stream capacity, so rare).
|
||||
env->GetFloatArrayRegion(g_buffer, 0, n * 2, out);
|
||||
for (int i = n * 2; i < numFrames * 2; ++i) out[i] = 0.0f;
|
||||
if (sizzle::host::EngineHost *host = sizzleHost()) host->render(out, numFrames);
|
||||
else for (int i = 0; i < numFrames * 2; ++i) out[i] = 0.0f; // stereo silence
|
||||
|
||||
// Adaptive buffer sizing (timing path): a callback that renders slower than
|
||||
// its deadline will drain the buffer; a couple in a row means we're about to
|
||||
@@ -174,7 +150,7 @@ public:
|
||||
SizzleErrorCallback g_errorCallback;
|
||||
|
||||
// Opens, buffers and starts the low-latency output stream. Used both at initial
|
||||
// start and to recover from a disconnect. Reuses the already-allocated g_buffer.
|
||||
// start and to recover from a disconnect.
|
||||
bool openAndStartStream() {
|
||||
oboe::AudioStreamBuilder builder;
|
||||
builder.setDirection(oboe::Direction::Output)
|
||||
@@ -200,56 +176,30 @@ bool openAndStartStream() {
|
||||
g_stream.reset();
|
||||
return false;
|
||||
}
|
||||
LOGI("Oboe stream started (%d Hz, burst=%d, bufferSize=%d, capacity=%d, javaBuf=%d)",
|
||||
LOGI("Oboe stream started (%d Hz, burst=%d, bufferSize=%d, capacity=%d)",
|
||||
g_sampleRate, burst, g_stream->getBufferSizeInFrames(),
|
||||
g_stream->getBufferCapacityInFrames(), g_frames);
|
||||
g_stream->getBufferCapacityInFrames());
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void * /*reserved*/) {
|
||||
g_vm = vm;
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_cc_tiredsysadmin_android_sizzle_audio_NativeAudioBridge_nativeStart(
|
||||
JNIEnv *env, jobject /*thiz*/, jobject callback, jint sampleRate, jint framesPerCallback) {
|
||||
g_callback = env->NewGlobalRef(callback);
|
||||
jclass cls = env->GetObjectClass(callback);
|
||||
g_renderMethod = env->GetMethodID(cls, "renderAudio", "([FI)V");
|
||||
JNIEnv * /*env*/, jobject /*thiz*/, jint sampleRate) {
|
||||
g_prevXRuns = 0;
|
||||
g_sampleRate = sampleRate;
|
||||
g_wantRunning = true;
|
||||
|
||||
// Allocate the reused Java render buffer up front, sized to our maximum callback,
|
||||
// so the stream can be transparently reopened on a disconnect without touching
|
||||
// JNI from Oboe's (non-Java) error thread. The data callback only ever renders
|
||||
// min(numFrames, g_frames) frames, and low-latency bursts are far smaller.
|
||||
g_frames = kMaxBufferFrames;
|
||||
if (g_frames < framesPerCallback) g_frames = framesPerCallback;
|
||||
// Interleaved stereo: 2 samples per frame.
|
||||
g_buffer = static_cast<jfloatArray>(env->NewGlobalRef(env->NewFloatArray(g_frames * 2)));
|
||||
|
||||
if (!openAndStartStream()) {
|
||||
env->DeleteGlobalRef(g_buffer);
|
||||
g_buffer = nullptr;
|
||||
return JNI_FALSE;
|
||||
}
|
||||
return JNI_TRUE;
|
||||
return openAndStartStream() ? JNI_TRUE : JNI_FALSE;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_cc_tiredsysadmin_android_sizzle_audio_NativeAudioBridge_nativeStop(
|
||||
JNIEnv *env, jobject /*thiz*/) {
|
||||
JNIEnv * /*env*/, jobject /*thiz*/) {
|
||||
g_wantRunning = false; // stop the disconnect-recovery from reopening
|
||||
if (g_stream) {
|
||||
g_stream->stop();
|
||||
g_stream->close();
|
||||
g_stream.reset();
|
||||
}
|
||||
if (g_buffer) { env->DeleteGlobalRef(g_buffer); g_buffer = nullptr; }
|
||||
if (g_callback) { env->DeleteGlobalRef(g_callback); g_callback = nullptr; }
|
||||
g_renderMethod = nullptr;
|
||||
}
|
||||
|
||||
@@ -83,6 +83,12 @@ class MainActivity : ComponentActivity() {
|
||||
SizzleTheme(palette = viewModel.palette) {
|
||||
SizzleAppUi(viewModel)
|
||||
}
|
||||
// "Keep screen on" (Settings › Interface): the window's flag follows the setting.
|
||||
val keepOn = viewModel.keepScreenOn
|
||||
androidx.compose.runtime.LaunchedEffect(keepOn) {
|
||||
if (keepOn) window.addFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
else window.clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
}
|
||||
}
|
||||
|
||||
// Hold the MIDI ports (USB, Bluetooth, other apps' virtual devices) for the
|
||||
@@ -104,6 +110,7 @@ class MainActivity : ComponentActivity() {
|
||||
* A `.sng` handed over by another app (Mikro Seq's "Open in Sizzle", a file
|
||||
* manager, the share sheet): read it off the main thread, then let the UI ask
|
||||
* before it replaces the current song. See [SongIntents] for what is accepted.
|
||||
* Mikro Seq's one-tap transfer replaces it straight away, after a backup.
|
||||
*/
|
||||
private fun handleOpenIntent(intent: Intent?) {
|
||||
intent ?: return
|
||||
@@ -113,7 +120,7 @@ class MainActivity : ComponentActivity() {
|
||||
setIntent(Intent(this, MainActivity::class.java))
|
||||
lifecycleScope.launch {
|
||||
val song = withContext(Dispatchers.IO) { SongIntents.read(this@MainActivity, intent) }
|
||||
viewModel.offerIncomingSong(song)
|
||||
if (song.replaceNow) viewModel.replaceFromMikroSeq(song) else viewModel.offerIncomingSong(song)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,8 @@ class SizzleApp : Application() {
|
||||
val keyboardInput: KeyboardInput by lazy { KeyboardInput(inputRouter) }
|
||||
val gamepadInput: GamepadInput by lazy { GamepadInput(inputRouter) }
|
||||
val midiInput: MidiInput by lazy { MidiInput(this, inputRouter, soundModule) }
|
||||
/** Bluetooth LE MIDI controllers (found, connected and remembered in Settings). */
|
||||
val bleMidi: cc.tiredsysadmin.android.sizzle.input.BleMidi by lazy { cc.tiredsysadmin.android.sizzle.input.BleMidi(this) }
|
||||
|
||||
/** Headless MIDI → engine routing (see [MidiSoundModule]). Lives here, with the
|
||||
* engine, so it keeps playing incoming notes with no Activity or ViewModel. */
|
||||
@@ -102,10 +104,12 @@ class SizzleApp : Application() {
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
// The Grain Cloud's built-in sources are synthesised, not shipped: render them
|
||||
// in the background now so they're ready before anyone plays one.
|
||||
cc.tiredsysadmin.android.sizzle.audio.GrainSources.prewarm()
|
||||
cc.tiredsysadmin.android.sizzle.wavetable.WaveTables.prewarm()
|
||||
// The Grain Cloud's sources and the factory wavetables are synthesised, not
|
||||
// shipped — but the engine (core/, through EngineHost) renders its own set as
|
||||
// soon as it is created, and nothing outside the two editors' drawings reads
|
||||
// the Kotlin ones. They are built when those editors open (WavetablePreview /
|
||||
// GrainCloudEditor) instead of here, so launch no longer renders ~6 MB of PCM
|
||||
// twice and no longer holds the second copy for the life of the process.
|
||||
// Crash recovery: restore the last autosaved project before the engine or
|
||||
// UI read it, so a crash / process-death resumes where the user left off.
|
||||
projectStore.restore(project)
|
||||
@@ -141,7 +145,10 @@ class SizzleApp : Application() {
|
||||
}
|
||||
|
||||
fun acquireMidi(owner: String) {
|
||||
if (midiOwners.add(owner) && midiOwners.size == 1) { midiInput.start(); midiClock.start() }
|
||||
if (midiOwners.add(owner) && midiOwners.size == 1) {
|
||||
midiInput.start(); midiClock.start()
|
||||
bleMidi.start(); bleMidi.reconnectRemembered()
|
||||
}
|
||||
}
|
||||
|
||||
/** Re-scan MIDI sources (MainActivity.onResume): opens anything enabled that
|
||||
@@ -149,7 +156,7 @@ class SizzleApp : Application() {
|
||||
fun refreshMidi() { if (midiOwners.isNotEmpty()) midiInput.refresh() }
|
||||
|
||||
fun releaseMidi(owner: String) {
|
||||
if (midiOwners.remove(owner) && midiOwners.isEmpty()) { midiInput.stop(); midiClock.stop() }
|
||||
if (midiOwners.remove(owner) && midiOwners.isEmpty()) { bleMidi.closeAll(); midiInput.stop(); midiClock.stop() }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -199,7 +206,7 @@ class SizzleApp : Application() {
|
||||
if (MidiTrace.on && audioEngine.recordArmed) MidiTrace.log("clock ${if (start) "Start: armed recording starts" else "Stop: recording ends after its tail"}")
|
||||
main.post { if (start) audioEngine.externalClockStart() else audioEngine.externalClockStop() }
|
||||
}
|
||||
midiClock.onReceiveTempo = { bpm -> main.post { project.tempoBpm = bpm.coerceIn(20f, 300f) } }
|
||||
midiClock.onReceiveTempo = { bpm -> main.post { project.tempoBpm = bpm.coerceIn(20f, 300f); audioEngine.requestSync() } }
|
||||
val s = runBlocking { settingsStore.load() }
|
||||
midiClock.sendEnabled = s.sendMidiClock
|
||||
audioEngine.midiOutEnabled = s.sendMidiClock
|
||||
@@ -207,6 +214,8 @@ class SizzleApp : Application() {
|
||||
_soundModuleEnabled.value = s.soundModule
|
||||
midiInput.restoreDisabled(s.midiSourcesOff)
|
||||
midiInput.onDisabledChanged = { keys -> appScope.launch { settingsStore.saveMidiSourcesOff(keys) } }
|
||||
bleMidi.restoreRemembered(s.bleMidiDevices)
|
||||
bleMidi.onRememberedChanged = { devices -> appScope.launch { settingsStore.saveBleMidiDevices(devices) } }
|
||||
}
|
||||
|
||||
private val appScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,39 +4,23 @@
|
||||
package cc.tiredsysadmin.android.sizzle.audio
|
||||
|
||||
/**
|
||||
* Bridges the native Oboe (AAudio) output backend to the Kotlin [AudioEngine].
|
||||
*
|
||||
* The C++ side (see `src/main/cpp/native_audio.cpp`) opens a low-latency Oboe
|
||||
* stream whose real-time data callback calls [renderAudio] via JNI, which simply
|
||||
* delegates to [AudioEngine.fillBlock]. So the exact same synth/sequencer/mixer
|
||||
* code produces the audio; only the *delivery* path changes (a native callback
|
||||
* pulling data, vs. AudioTrack blocking writes), which is what lowers latency.
|
||||
*
|
||||
* If the native library fails to load (e.g. the NDK build was skipped) the whole
|
||||
* feature is inert and the engine transparently uses its AudioTrack loop.
|
||||
* The native Oboe (AAudio) output (src/main/cpp/native_audio.cpp). Its real-time
|
||||
* callback renders straight from the shared C++ engine; nothing calls back into
|
||||
* the JVM on the audio thread. If it can't start, [AudioEngine] falls back to an
|
||||
* AudioTrack loop that renders through [NativeEngine.nativeRender].
|
||||
*/
|
||||
class NativeAudioBridge(private val engine: AudioEngine) {
|
||||
|
||||
/** Invoked from the native audio callback thread. Must not allocate. */
|
||||
@Suppress("unused") // called via JNI
|
||||
fun renderAudio(buffer: FloatArray, frames: Int) {
|
||||
engine.fillBlock(buffer, frames)
|
||||
}
|
||||
|
||||
fun start(sampleRate: Int, framesPerCallback: Int): Boolean =
|
||||
if (LIB_LOADED) nativeStart(this, sampleRate, framesPerCallback) else false
|
||||
class NativeAudioBridge {
|
||||
fun start(sampleRate: Int): Boolean = if (NativeEngine.loaded) nativeStart(sampleRate) else false
|
||||
|
||||
fun stop() {
|
||||
if (LIB_LOADED) nativeStop()
|
||||
if (NativeEngine.loaded) nativeStop()
|
||||
}
|
||||
|
||||
private external fun nativeStart(callback: NativeAudioBridge, sampleRate: Int, framesPerCallback: Int): Boolean
|
||||
private external fun nativeStart(sampleRate: Int): Boolean
|
||||
private external fun nativeStop()
|
||||
|
||||
companion object {
|
||||
private val LIB_LOADED = runCatching { System.loadLibrary("sizzle_native") }.isSuccess
|
||||
|
||||
/** Whether the native Oboe backend is available on this build/device. */
|
||||
fun isAvailable(): Boolean = LIB_LOADED
|
||||
/** Whether the native library loaded on this build/device. */
|
||||
fun isAvailable(): Boolean = NativeEngine.loaded
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package cc.tiredsysadmin.android.sizzle.audio
|
||||
|
||||
/**
|
||||
* JNI to the shared C++ engine (core/src/host/EngineHost through
|
||||
* src/main/cpp/jni_engine.cpp): the same engine, devices and sequencer the iOS app
|
||||
* runs. [AudioEngine] is the app's face of it. Every call is a no-op when the
|
||||
* native library isn't loaded (JVM unit tests).
|
||||
*/
|
||||
object NativeEngine {
|
||||
val loaded: Boolean = runCatching { System.loadLibrary("sizzle_native") }.isSuccess
|
||||
@Volatile var created = false; private set
|
||||
|
||||
fun create(sampleRate: Int) {
|
||||
if (!loaded || created) return
|
||||
nativeCreate(sampleRate)
|
||||
created = true
|
||||
// Samples decoded before the engine existed (crash-recovery restore, presets).
|
||||
SampleStore.forEachSample { id, s -> putSample(id, s) }
|
||||
}
|
||||
|
||||
fun putSample(id: String, s: SampleStore.Sample) {
|
||||
if (created) nativePutSample(id, s.data, s.sampleRate, s.loopStart, s.loopEnd)
|
||||
}
|
||||
|
||||
fun removeSample(id: String) { if (created) nativeRemoveSample(id) }
|
||||
|
||||
// ---- the preset randomizer (core/src/model/Randomizer.cpp) ----
|
||||
// Gated on [loaded], not [created]: these need no engine, only the library.
|
||||
|
||||
/** Does this device type have a randomizer? */
|
||||
fun canRandomize(type: String): Boolean = loaded && nativeCanRandomize(type)
|
||||
|
||||
/** A random patch for [type] as preset text, or "" — feed it to PresetIo.import. */
|
||||
fun randomPreset(type: String, seed: Int): String = if (loaded) nativeRandomPreset(type, seed) else ""
|
||||
|
||||
/** The name belonging to that same [seed]. */
|
||||
fun randomName(type: String, seed: Int): String = if (loaded) nativeRandomName(type, seed) else ""
|
||||
|
||||
external fun nativeCreate(sampleRate: Int)
|
||||
external fun nativeLoad(text: String)
|
||||
external fun nativeSync(text: String)
|
||||
external fun nativeRebuildFxChains()
|
||||
external fun nativeRebuildArrangement()
|
||||
external fun nativeRefreshLoopPlaylist()
|
||||
external fun nativePlay(beat: Int)
|
||||
external fun nativePause()
|
||||
external fun nativeStop()
|
||||
external fun nativePanic()
|
||||
external fun nativeTransport(): Long
|
||||
external fun nativeLiveNoteOn(pitch: Int, velocity: Int)
|
||||
external fun nativeLiveNoteOff(pitch: Int)
|
||||
external fun nativeAuditionSlotOn(slot: Int, midi: Int)
|
||||
external fun nativeAuditionSlotOff(midi: Int)
|
||||
external fun nativeBusNoteOn(channel: Int, midi: Int, velocity: Int)
|
||||
external fun nativeBusNoteOff(channel: Int, midi: Int)
|
||||
external fun nativeDescribeBusTargets(channel: Int, midi: Int): String
|
||||
external fun nativeChannelMeter(ch: Int): Float
|
||||
external fun nativeChannelClipped(ch: Int): Boolean
|
||||
external fun nativeEffectScope(slot: Int, out: FloatArray): Int
|
||||
external fun nativeEffectPlayhead(slot: Int): Float
|
||||
external fun nativeSetMidiOutEnabled(on: Boolean)
|
||||
external fun nativePollMidiOut(): Int
|
||||
external fun nativePutSample(id: String, data: FloatArray, rate: Int, loopStart: Int, loopEnd: Int)
|
||||
external fun nativeRemoveSample(id: String)
|
||||
external fun nativeSetRecordPath(path: String)
|
||||
external fun nativeSetRecordingArm(armed: Boolean, tailBars: Int)
|
||||
external fun nativeSetRecordTailBars(tailBars: Int)
|
||||
external fun nativeRecordingActive(): Boolean
|
||||
external fun nativeTakeFinished(): String?
|
||||
external fun nativeEndCapture()
|
||||
external fun nativeExternalClockStart()
|
||||
external fun nativeExternalClockStop()
|
||||
external fun nativeRender(out: FloatArray, frames: Int)
|
||||
external fun nativeCanRandomize(type: String): Boolean
|
||||
external fun nativeRandomPreset(type: String, seed: Int): String
|
||||
external fun nativeRandomName(type: String, seed: Int): String
|
||||
}
|
||||
@@ -30,12 +30,16 @@ object SampleStore {
|
||||
|
||||
private val samples = ConcurrentHashMap<String, Sample>()
|
||||
|
||||
fun put(id: String, sample: Sample) { samples[id] = sample }
|
||||
/** Also hands the sample to the native engine, which plays from its own store. */
|
||||
fun put(id: String, sample: Sample) { samples[id] = sample; NativeEngine.putSample(id, sample) }
|
||||
|
||||
/** Every stored sample (NativeEngine copies them when it starts). */
|
||||
fun forEachSample(action: (String, Sample) -> Unit) { samples.forEach { (id, s) -> action(id, s) } }
|
||||
fun get(id: String): Sample? = if (id.isEmpty()) null else samples[id]
|
||||
|
||||
/** Drop a cached sample so its PCM can be GC'd. Any voice already playing it
|
||||
* keeps its own reference, so removing a live sample never crashes playback. */
|
||||
fun remove(id: String) { if (id.isNotEmpty()) samples.remove(id) }
|
||||
fun remove(id: String) { if (id.isNotEmpty()) { samples.remove(id); NativeEngine.removeSample(id) } }
|
||||
|
||||
/**
|
||||
* Decode a WAV file (the common uncompressed formats) into a mono [Sample].
|
||||
|
||||
@@ -0,0 +1,232 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package cc.tiredsysadmin.android.sizzle.input
|
||||
|
||||
import android.Manifest
|
||||
import android.annotation.SuppressLint
|
||||
import android.bluetooth.BluetoothManager
|
||||
import android.bluetooth.le.ScanCallback
|
||||
import android.bluetooth.le.ScanFilter
|
||||
import android.bluetooth.le.ScanResult
|
||||
import android.bluetooth.le.ScanSettings
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.bluetooth.BluetoothDevice
|
||||
import android.media.midi.MidiDevice
|
||||
import android.media.midi.MidiDeviceInfo
|
||||
import android.media.midi.MidiManager
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.ParcelUuid
|
||||
import android.util.Log
|
||||
import java.util.UUID
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
|
||||
/** A Bluetooth LE MIDI controller Sizzle found or remembers. */
|
||||
data class BleMidiDevice(
|
||||
val address: String,
|
||||
val name: String,
|
||||
val connected: Boolean,
|
||||
val connecting: Boolean,
|
||||
val remembered: Boolean,
|
||||
)
|
||||
|
||||
/**
|
||||
* Bluetooth LE MIDI controllers: Android lists a BLE MIDI device to MIDI apps only
|
||||
* once some app has connected it, so Settings scans for the BLE MIDI service,
|
||||
* shows what it finds, and connects the one the user picks
|
||||
* ([MidiManager.openBluetoothDevice]). The connection is held here for as long as
|
||||
* Sizzle runs; while it is, the device is an ordinary MIDI source that [MidiInput]
|
||||
* picks up through its device callback (listed, switchable, played).
|
||||
*
|
||||
* Connected devices are remembered ([remembered], persisted by the caller via
|
||||
* [onRememberedChanged]) and connected again by address at the next start
|
||||
* ([reconnectRemembered]) — no scan needed. Main thread.
|
||||
*/
|
||||
class BleMidi(private val context: Context) {
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private val midiManager = context.getSystemService(Context.MIDI_SERVICE) as? MidiManager
|
||||
private val adapter = (context.getSystemService(Context.BLUETOOTH_SERVICE) as? BluetoothManager)?.adapter
|
||||
|
||||
private val found = LinkedHashMap<String, String>() // address -> name, from scans and memory
|
||||
private val open = HashMap<String, MidiDevice>()
|
||||
private val connecting = HashSet<String>()
|
||||
|
||||
/** Addresses of the controllers to connect again at start ("address|name" when saved). */
|
||||
var remembered: Map<String, String> = emptyMap()
|
||||
private set
|
||||
var onRememberedChanged: ((Map<String, String>) -> Unit)? = null
|
||||
|
||||
private val _devices = MutableStateFlow<List<BleMidiDevice>>(emptyList())
|
||||
val devices: StateFlow<List<BleMidiDevice>> = _devices.asStateFlow()
|
||||
private val _scanning = MutableStateFlow(false)
|
||||
val scanning: StateFlow<Boolean> = _scanning.asStateFlow()
|
||||
private val _error = MutableStateFlow<String?>(null)
|
||||
/** Why the last scan or connection failed, for Settings; null when fine. */
|
||||
val error: StateFlow<String?> = _error.asStateFlow()
|
||||
|
||||
/** This device can do BLE MIDI at all (BLE + the MIDI API). */
|
||||
val supported: Boolean
|
||||
get() = adapter != null && midiManager != null &&
|
||||
context.packageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)
|
||||
|
||||
/** Runtime permissions a scan needs (Android 12+: scan + connect; before: location). */
|
||||
fun requiredPermissions(): Array<String> =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
arrayOf(Manifest.permission.BLUETOOTH_SCAN, Manifest.permission.BLUETOOTH_CONNECT)
|
||||
} else {
|
||||
// Both, as the manifest declares them: a FINE request without COARSE is
|
||||
// rejected by the platform's permission model (and flagged by lint).
|
||||
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION)
|
||||
}
|
||||
|
||||
fun hasPermissions(): Boolean = requiredPermissions().all {
|
||||
context.checkSelfPermission(it) == PackageManager.PERMISSION_GRANTED
|
||||
}
|
||||
|
||||
private fun canConnect(): Boolean = Build.VERSION.SDK_INT < Build.VERSION_CODES.S ||
|
||||
context.checkSelfPermission(Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED
|
||||
|
||||
private var callbackRegistered = false
|
||||
|
||||
/** Watch for connections that drop on their own (out of range, switched off). */
|
||||
fun start() {
|
||||
val mm = midiManager ?: return
|
||||
if (callbackRegistered) return
|
||||
callbackRegistered = true
|
||||
@Suppress("DEPRECATION")
|
||||
mm.registerDeviceCallback(object : MidiManager.DeviceCallback() {
|
||||
override fun onDeviceRemoved(device: MidiDeviceInfo) {
|
||||
if (device.type != MidiDeviceInfo.TYPE_BLUETOOTH) return
|
||||
@Suppress("DEPRECATION")
|
||||
val bt = device.properties.getParcelable<BluetoothDevice>(MidiDeviceInfo.PROPERTY_BLUETOOTH_DEVICE)
|
||||
bt?.address?.let(::deviceRemoved)
|
||||
}
|
||||
}, handler)
|
||||
}
|
||||
|
||||
fun restoreRemembered(saved: Map<String, String>) {
|
||||
remembered = saved
|
||||
found.putAll(saved)
|
||||
publish()
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- scanning
|
||||
private val callback = object : ScanCallback() {
|
||||
@SuppressLint("MissingPermission")
|
||||
override fun onScanResult(callbackType: Int, result: ScanResult) {
|
||||
val address = result.device.address ?: return
|
||||
val name = result.scanRecord?.deviceName ?: runCatching { result.device.name }.getOrNull() ?: "BLE MIDI device"
|
||||
if (found[address] != name) { found[address] = name; publish() }
|
||||
}
|
||||
|
||||
override fun onScanFailed(errorCode: Int) {
|
||||
_error.value = "Bluetooth scan failed (error $errorCode)."
|
||||
_scanning.value = false
|
||||
}
|
||||
}
|
||||
|
||||
private val stopScanLater = Runnable { stopScan() }
|
||||
|
||||
/** Look for BLE MIDI controllers for [SCAN_MS]. Needs [hasPermissions] and Bluetooth on. */
|
||||
@SuppressLint("MissingPermission")
|
||||
fun startScan() {
|
||||
_error.value = null
|
||||
if (!supported) { _error.value = "This device has no Bluetooth LE MIDI support."; return }
|
||||
if (!hasPermissions()) { _error.value = "Sizzle needs the Bluetooth permission to look for controllers."; return }
|
||||
val scanner = adapter?.takeIf { it.isEnabled }?.bluetoothLeScanner
|
||||
if (scanner == null) { _error.value = "Bluetooth is off. Turn it on, then scan again."; return }
|
||||
if (_scanning.value) return
|
||||
val filter = ScanFilter.Builder().setServiceUuid(ParcelUuid(MIDI_SERVICE)).build()
|
||||
val settings = ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build()
|
||||
runCatching { scanner.startScan(listOf(filter), settings, callback) }
|
||||
.onFailure { _error.value = "Couldn't start the Bluetooth scan: ${it.message}"; return }
|
||||
_scanning.value = true
|
||||
handler.postDelayed(stopScanLater, SCAN_MS)
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
fun stopScan() {
|
||||
handler.removeCallbacks(stopScanLater)
|
||||
if (!_scanning.value) return
|
||||
runCatching { adapter?.bluetoothLeScanner?.stopScan(callback) }
|
||||
_scanning.value = false
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- connecting
|
||||
/** Connect the controller at [address]; it then appears among the MIDI inputs. */
|
||||
@SuppressLint("MissingPermission")
|
||||
fun connect(address: String) {
|
||||
val mm = midiManager ?: return
|
||||
if (address in open || address in connecting) return
|
||||
if (!canConnect()) { _error.value = "Sizzle needs the Bluetooth permission to connect."; return }
|
||||
val device = runCatching { adapter?.getRemoteDevice(address) }.getOrNull() ?: return
|
||||
stopScan() // scanning slows connecting down
|
||||
connecting += address
|
||||
publish()
|
||||
mm.openBluetoothDevice(device, { midi ->
|
||||
connecting -= address
|
||||
if (midi == null) {
|
||||
_error.value = "Couldn't connect to ${found[address] ?: address}. Is it on and nearby?"
|
||||
} else {
|
||||
_error.value = null
|
||||
open[address] = midi
|
||||
remember(address, found[address] ?: midi.info.properties.getString(MidiDeviceInfo.PROPERTY_NAME) ?: address)
|
||||
Log.i(TAG, "${found[address]}: connected")
|
||||
}
|
||||
publish()
|
||||
}, handler)
|
||||
}
|
||||
|
||||
/** Disconnect the controller at [address]; [forget] also stops reconnecting it at start. */
|
||||
fun disconnect(address: String, forget: Boolean) {
|
||||
open.remove(address)?.let { runCatching { it.close() } }
|
||||
if (forget && address in remembered) {
|
||||
remembered = remembered - address
|
||||
onRememberedChanged?.invoke(remembered)
|
||||
}
|
||||
publish()
|
||||
}
|
||||
|
||||
/** Connect every remembered controller (at start and when Settings opens). */
|
||||
fun reconnectRemembered() {
|
||||
for (address in remembered.keys) if (address !in open) connect(address)
|
||||
}
|
||||
|
||||
/** A connection dropped on its own (out of range, switched off): forget the handle. */
|
||||
fun deviceRemoved(address: String) {
|
||||
open.remove(address)?.let { runCatching { it.close() } }
|
||||
publish()
|
||||
}
|
||||
|
||||
/** Close every connection (Sizzle shutting down MIDI). */
|
||||
fun closeAll() {
|
||||
stopScan()
|
||||
open.values.forEach { runCatching { it.close() } }
|
||||
open.clear()
|
||||
publish()
|
||||
}
|
||||
|
||||
private fun remember(address: String, name: String) {
|
||||
if (remembered[address] == name) return
|
||||
remembered = remembered + (address to name)
|
||||
onRememberedChanged?.invoke(remembered)
|
||||
}
|
||||
|
||||
private fun publish() {
|
||||
_devices.value = found.map { (address, name) ->
|
||||
BleMidiDevice(address, name, address in open, address in connecting, address in remembered)
|
||||
}.sortedWith(compareByDescending<BleMidiDevice> { it.connected }.thenBy { it.name.lowercase() })
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "SizzleBleMidi"
|
||||
/** The BLE MIDI service (Apple's / the MMA's BLE-MIDI specification). */
|
||||
val MIDI_SERVICE: UUID = UUID.fromString("03B80E5A-EDE8-4B33-A751-6CE34EC4C700")
|
||||
private const val SCAN_MS = 15_000L
|
||||
}
|
||||
}
|
||||
@@ -73,8 +73,8 @@ class MidiClock(context: Context) {
|
||||
override fun onDeviceAdded(device: MidiDeviceInfo) = openDevice(device)
|
||||
}
|
||||
callback = cb
|
||||
mm.devices.forEach(::openDevice)
|
||||
mm.registerDeviceCallback(cb, handler)
|
||||
allDevices(mm).forEach(::openDevice)
|
||||
registerCallback(mm, cb)
|
||||
running = true
|
||||
thread = Thread({ sendLoop() }, "sizzle-midi-clock").apply {
|
||||
priority = Thread.MAX_PRIORITY; isDaemon = true; start()
|
||||
@@ -90,6 +90,16 @@ class MidiClock(context: Context) {
|
||||
outPorts.clear()
|
||||
}
|
||||
|
||||
// Same two deprecations MidiInput suppresses the same way: getDevices and the
|
||||
// Handler overload of registerDeviceCallback are still the only ones that list
|
||||
// and watch every transport below API 33.
|
||||
@Suppress("DEPRECATION")
|
||||
private fun allDevices(mm: MidiManager): List<MidiDeviceInfo> = mm.devices.toList()
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
private fun registerCallback(mm: MidiManager, cb: MidiManager.DeviceCallback) =
|
||||
mm.registerDeviceCallback(cb, handler)
|
||||
|
||||
private fun openDevice(info: MidiDeviceInfo) {
|
||||
if (info.inputPortCount == 0) return // need a port we can send TO
|
||||
midiManager?.openDevice(info, { device ->
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package cc.tiredsysadmin.android.sizzle.io
|
||||
|
||||
import cc.tiredsysadmin.android.sizzle.model.Project
|
||||
import cc.tiredsysadmin.android.sizzle.model.ToolboxSlot
|
||||
|
||||
/**
|
||||
* A device's MIDI mapping as plain text (.szm), shared between Sizzle installs
|
||||
* (Android and iOS read and write the same format; the C++ core's io/MidiMapIo):
|
||||
*
|
||||
* SIZZLE-MIDIMAP 1
|
||||
* # comments start with '#'
|
||||
* TYPE=WAVETABLE
|
||||
* NAME=Lead
|
||||
* cutoff=74
|
||||
* resonance=71
|
||||
*
|
||||
* One `parameter=CC` line per mapped parameter (CC 0..127), in the device's
|
||||
* parameter order. In the song a mapping is the slot value `midicc@<parameter>`.
|
||||
*/
|
||||
object MidiMapIo {
|
||||
const val HEADER = "SIZZLE-MIDIMAP 1"
|
||||
const val EXT = ".szm"
|
||||
const val CC_PREFIX = "midicc@"
|
||||
|
||||
data class MidiMap(val type: String, val name: String, val bindings: List<Pair<String, Int>>)
|
||||
|
||||
/** [slot]'s mappings, in its device's parameter order. */
|
||||
fun fromSlot(slot: ToolboxSlot): MidiMap = MidiMap(
|
||||
type = slot.type?.name.orEmpty(),
|
||||
name = slot.name,
|
||||
bindings = slot.type?.params.orEmpty().mapNotNull { spec ->
|
||||
slot.string(CC_PREFIX + spec.key).toIntOrNull()?.takeIf { it in 0..127 }?.let { spec.key to it }
|
||||
},
|
||||
)
|
||||
|
||||
fun save(map: MidiMap): String = buildString {
|
||||
appendLine(HEADER)
|
||||
appendLine("# Sizzle MIDI mapping: parameter=CC number (0-127), one per line.")
|
||||
appendLine("TYPE=${map.type}")
|
||||
appendLine("NAME=${map.name}")
|
||||
for ((key, cc) in map.bindings) appendLine("$key=$cc")
|
||||
}
|
||||
|
||||
/** The mapping in [text], or null if it has no header or TYPE. Lines that aren't
|
||||
* `key=CC` with CC 0..127 are skipped; a repeated key or CC keeps its first line
|
||||
* (one control drives one parameter). */
|
||||
fun parse(text: String): MidiMap? {
|
||||
var header = false
|
||||
var type = ""
|
||||
var name = ""
|
||||
val bindings = ArrayList<Pair<String, Int>>()
|
||||
val keys = HashSet<String>()
|
||||
val ccs = HashSet<Int>()
|
||||
for (raw in text.lineSequence()) {
|
||||
val line = raw.trim()
|
||||
if (line.isEmpty() || line.startsWith("#")) continue
|
||||
if (line == HEADER) { header = true; continue }
|
||||
val eq = line.indexOf('=')
|
||||
if (eq <= 0) continue
|
||||
val key = line.substring(0, eq).trim()
|
||||
val value = line.substring(eq + 1).trim()
|
||||
when (key) {
|
||||
"TYPE" -> type = value
|
||||
"NAME" -> name = value
|
||||
else -> {
|
||||
val cc = value.toIntOrNull() ?: continue
|
||||
if (cc !in 0..127 || key in keys || cc in ccs) continue
|
||||
keys += key; ccs += cc
|
||||
bindings += key to cc
|
||||
}
|
||||
}
|
||||
}
|
||||
return if (header && type.isNotEmpty()) MidiMap(type, name, bindings) else null
|
||||
}
|
||||
|
||||
/** Replace toolbox [slotIndex]'s mappings with [map]'s: only parameters its device
|
||||
* has; a CC another parameter (of any slot) used moves to this one. Returns how
|
||||
* many were applied, or -1 when [map] is for another device type. */
|
||||
fun apply(project: Project, slotIndex: Int, map: MidiMap): Int {
|
||||
val target = project.toolbox.getOrNull(slotIndex) ?: return -1
|
||||
val type = target.type ?: return -1
|
||||
if (type.name != map.type) return -1
|
||||
type.params.forEach { target.values.remove(CC_PREFIX + it.key) }
|
||||
var applied = 0
|
||||
for ((key, cc) in map.bindings) {
|
||||
if (type.params.none { it.key == key }) continue
|
||||
for (s in project.toolbox) {
|
||||
s.values.entries.removeAll { it.key.startsWith(CC_PREFIX) && it.value.toIntOrNull() == cc }
|
||||
}
|
||||
target.set(CC_PREFIX + key, cc.toString())
|
||||
applied++
|
||||
}
|
||||
|
||||
return applied
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
package cc.tiredsysadmin.android.sizzle.io
|
||||
|
||||
import cc.tiredsysadmin.android.sizzle.model.Cell
|
||||
import cc.tiredsysadmin.android.sizzle.model.LoopRegion
|
||||
import cc.tiredsysadmin.android.sizzle.model.Mixer
|
||||
import cc.tiredsysadmin.android.sizzle.model.Pattern
|
||||
import cc.tiredsysadmin.android.sizzle.model.Project
|
||||
@@ -27,58 +28,100 @@ import cc.tiredsysadmin.android.sizzle.model.ToolboxType
|
||||
object ProjectIo {
|
||||
private const val HEADER = "SIZZLETRACKER-SNG 1"
|
||||
|
||||
/** Room for a typical song, so [save]'s buffer never has to grow and copy. */
|
||||
private const val INITIAL_CAPACITY = 32 * 1024
|
||||
|
||||
// ------------------------------------------------------------------- write
|
||||
fun save(project: Project): String = buildString {
|
||||
appendLine(HEADER)
|
||||
appendLine("NAME=${project.name}")
|
||||
appendLine("TEMPO=${project.tempoBpm}")
|
||||
appendLine("SIG=${project.timeSignature.name}")
|
||||
appendLine("SCALE=${project.scale.name}")
|
||||
appendLine("ROOT=${project.rootNote}")
|
||||
appendLine("ACTIVE=${project.activePatternId}")
|
||||
/**
|
||||
* The whole project as `.sng` text.
|
||||
*
|
||||
* This is the hot path of the UI → engine bridge, not just the file writer:
|
||||
* `AudioEngine.syncNow` calls it after every edit and the engine diffs the text
|
||||
* (see DEVELOPER_HANDOVER.md §5.4.2). So it builds into one pre-sized buffer and
|
||||
* appends numbers straight into it instead of formatting a String per line —
|
||||
* byte for byte the same output, a fraction of the garbage.
|
||||
*/
|
||||
fun save(project: Project): String {
|
||||
val sb = StringBuilder(INITIAL_CAPACITY)
|
||||
sb.append(HEADER).append('\n')
|
||||
sb.append("NAME=").append(project.name).append('\n')
|
||||
sb.append("TEMPO=").append(project.tempoBpm).append('\n')
|
||||
sb.append("SIG=").append(project.timeSignature.name).append('\n')
|
||||
sb.append("SCALE=").append(project.scale.name).append('\n')
|
||||
sb.append("ROOT=").append(project.rootNote).append('\n')
|
||||
sb.append("ACTIVE=").append(project.activePatternId).append('\n')
|
||||
|
||||
project.patterns.forEach { p ->
|
||||
appendLine("[PATTERN id=${p.id} name=${encodeName(p.name)} len=${p.length}]")
|
||||
sb.append("[PATTERN id=").append(p.id).append(" name=").append(encodeName(p.name))
|
||||
.append(" len=").append(p.length).append("]\n")
|
||||
for (t in 0 until Pattern.TRACK_COUNT) {
|
||||
val col = p.tracks[t]
|
||||
for (line in 0 until p.length) {
|
||||
val cell = p.cell(t, line)
|
||||
if (!cell.isEmpty) appendLine("$t,$line,${cell.note},${cell.velocity},${cell.channel}")
|
||||
val cell = col[line]
|
||||
if (cell.isEmpty) continue
|
||||
sb.append(t).append(',').append(line).append(',').append(cell.note)
|
||||
.append(',').append(cell.velocity).append(',').append(cell.channel).append('\n')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val arr = project.arrangement
|
||||
val mutes = arr.laneMuted.joinToString("") { if (it) "1" else "0" }
|
||||
appendLine("[ARRANGEMENT bars=${arr.lengthBars} loop=${arr.loopEnabled.b()} mutes=$mutes]")
|
||||
sb.append("[ARRANGEMENT bars=").append(arr.lengthBars)
|
||||
.append(" loop=").append(if (arr.loopEnabled) '1' else '0').append(" mutes=")
|
||||
for (muted in arr.laneMuted) sb.append(if (muted) '1' else '0')
|
||||
sb.append("]\n")
|
||||
val usedBeats = arr.lastFilledBeat() + 1
|
||||
for (lane in arr.slots.indices) {
|
||||
val row = arr.slots[lane]
|
||||
for (beat in 0 until usedBeats) {
|
||||
val pid = arr.slots[lane][beat]
|
||||
val pid = row[beat]
|
||||
// >= 0 is a block id; NOTE_OFF is a marker and must survive too.
|
||||
// Anything else is EMPTY and is simply omitted.
|
||||
if (pid >= 0 || pid == cc.tiredsysadmin.android.sizzle.model.Arrangement.NOTE_OFF) appendLine("$lane,$beat,$pid")
|
||||
if (pid < 0 && pid != cc.tiredsysadmin.android.sizzle.model.Arrangement.NOTE_OFF) continue
|
||||
sb.append(lane).append(',').append(beat).append(',').append(pid).append('\n')
|
||||
}
|
||||
}
|
||||
appendLine("[REGION A en=${arr.regionA.enabled.b()} s=${arr.regionA.start} e=${arr.regionA.end} r=${arr.regionA.repeats}]")
|
||||
appendLine("[REGION B en=${arr.regionB.enabled.b()} s=${arr.regionB.start} e=${arr.regionB.end} r=${arr.regionB.repeats}]")
|
||||
return sb.appendTail(project).toString()
|
||||
}
|
||||
|
||||
appendLine("[MIXER]")
|
||||
/** The rest of [save]: regions, mixer, toolbox. Split out only to keep each half
|
||||
* readable; the two together produce one buffer. */
|
||||
private fun StringBuilder.appendTail(project: Project): StringBuilder = apply {
|
||||
val arr = project.arrangement
|
||||
appendRegion('A', arr.regionA)
|
||||
appendRegion('B', arr.regionB)
|
||||
|
||||
append("[MIXER]\n")
|
||||
project.mixer.channels.forEach { ch ->
|
||||
appendLine(
|
||||
"${ch.index},${ch.instrumentSlot},${ch.fxSlots.joinToString(",")}," +
|
||||
"${ch.midiChannel},${ch.volume},${ch.mute.b()},${ch.solo.b()},${ch.limiter.b()}",
|
||||
)
|
||||
append(ch.index).append(',').append(ch.instrumentSlot)
|
||||
for (fx in ch.fxSlots) append(',').append(fx)
|
||||
append(',').append(ch.midiChannel).append(',').append(ch.volume)
|
||||
.append(',').append(if (ch.mute) '1' else '0')
|
||||
.append(',').append(if (ch.solo) '1' else '0')
|
||||
.append(',').append(if (ch.limiter) '1' else '0').append('\n')
|
||||
}
|
||||
|
||||
appendLine("[TOOLBOX]")
|
||||
append("[TOOLBOX]\n")
|
||||
project.toolbox.forEach { slot ->
|
||||
if (!slot.isEmpty) {
|
||||
val params = slot.values.entries.joinToString(",") { "${it.key}=${it.value}" }
|
||||
appendLine("${slot.index}=${slot.type!!.name};${slot.name};$params")
|
||||
if (slot.isEmpty) return@forEach
|
||||
append(slot.index).append('=').append(slot.type!!.name).append(';').append(slot.name).append(';')
|
||||
var first = true
|
||||
for ((k, v) in slot.values) {
|
||||
if (!first) append(',')
|
||||
first = false
|
||||
append(k).append('=').append(v)
|
||||
}
|
||||
append('\n')
|
||||
}
|
||||
}
|
||||
|
||||
private fun StringBuilder.appendRegion(id: Char, r: LoopRegion) {
|
||||
append("[REGION ").append(id)
|
||||
.append(" en=").append(if (r.enabled) '1' else '0')
|
||||
.append(" s=").append(r.start).append(" e=").append(r.end)
|
||||
.append(" r=").append(r.repeats).append("]\n")
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------- read
|
||||
/**
|
||||
* Parse [text] into the *existing* [project], replacing its contents. Used to
|
||||
@@ -153,8 +196,6 @@ object ProjectIo {
|
||||
}
|
||||
|
||||
// ----- small helpers -----
|
||||
private fun Boolean.b() = if (this) "1" else "0"
|
||||
|
||||
private fun parseAttrs(line: String): Map<String, String> =
|
||||
line.trim('[', ']').substringAfter(' ', "").split(' ')
|
||||
.mapNotNull { tok -> tok.split('=', limit = 2).takeIf { it.size == 2 }?.let { it[0] to it[1] } }
|
||||
@@ -195,7 +236,7 @@ object ProjectIo {
|
||||
p.arrangement.set(lane, beat, pid)
|
||||
}
|
||||
|
||||
private fun applyRegion(region: cc.tiredsysadmin.android.sizzle.model.LoopRegion, a: Map<String, String>) {
|
||||
private fun applyRegion(region: LoopRegion, a: Map<String, String>) {
|
||||
region.enabled = a["en"] == "1"
|
||||
region.start = a["s"]?.toIntOrNull() ?: 0
|
||||
region.end = a["e"]?.toIntOrNull() ?: 0
|
||||
|
||||
@@ -30,6 +30,8 @@ data class AppSettings(
|
||||
val kbdOctave: Int = 3,
|
||||
/** Show the live VU meters inside the mixer volume faders. */
|
||||
val vuMeters: Boolean = true,
|
||||
/** Keep the screen on while Sizzle is in front. */
|
||||
val keepScreenOn: Boolean = false,
|
||||
/** Send MIDI clock + start/stop to attached MIDI devices (drive external gear). */
|
||||
val sendMidiClock: Boolean = false,
|
||||
/** Follow an external MIDI clock's tempo + start/stop. */
|
||||
@@ -39,6 +41,8 @@ data class AppSettings(
|
||||
val soundModule: Boolean = false,
|
||||
/** MIDI sources the user switched off in Setup ([cc.tiredsysadmin.android.sizzle.input.MidiSourceKey]). */
|
||||
val midiSourcesOff: Set<String> = emptySet(),
|
||||
/** Bluetooth LE MIDI controllers to connect at start: address -> name. */
|
||||
val bleMidiDevices: Map<String, String> = emptyMap(),
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -61,10 +65,15 @@ class SettingsStore(private val context: Context) {
|
||||
kbdChannel = prefs[KBD_CHANNEL] ?: 0,
|
||||
kbdOctave = prefs[KBD_OCTAVE] ?: 3,
|
||||
vuMeters = prefs[VU_METERS] ?: true,
|
||||
keepScreenOn = prefs[KEEP_SCREEN_ON] ?: false,
|
||||
sendMidiClock = prefs[MIDI_CLOCK_SEND] ?: false,
|
||||
receiveMidiClock = prefs[MIDI_CLOCK_RECV] ?: false,
|
||||
soundModule = prefs[SOUND_MODULE] ?: false,
|
||||
midiSourcesOff = prefs[MIDI_SOURCES_OFF] ?: emptySet(),
|
||||
// "address|name" each (a BLE address never contains '|').
|
||||
bleMidiDevices = (prefs[BLE_MIDI] ?: emptySet()).associate {
|
||||
it.substringBefore('|') to it.substringAfter('|', it.substringBefore('|'))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -96,6 +105,11 @@ class SettingsStore(private val context: Context) {
|
||||
context.settingsDataStore.edit { prefs -> prefs[VU_METERS] = enabled }
|
||||
}
|
||||
|
||||
/** Persist "Keep screen on". */
|
||||
suspend fun saveKeepScreenOn(enabled: Boolean) {
|
||||
context.settingsDataStore.edit { prefs -> prefs[KEEP_SCREEN_ON] = enabled }
|
||||
}
|
||||
|
||||
/** Persist the MIDI-clock send / receive toggles. */
|
||||
suspend fun saveMidiClock(send: Boolean, receive: Boolean) {
|
||||
context.settingsDataStore.edit { prefs ->
|
||||
@@ -114,6 +128,11 @@ class SettingsStore(private val context: Context) {
|
||||
context.settingsDataStore.edit { prefs -> prefs[MIDI_SOURCES_OFF] = keys }
|
||||
}
|
||||
|
||||
/** Persist the remembered Bluetooth LE MIDI controllers. */
|
||||
suspend fun saveBleMidiDevices(devices: Map<String, String>) {
|
||||
context.settingsDataStore.edit { prefs -> prefs[BLE_MIDI] = devices.map { (a, n) -> "$a|$n" }.toSet() }
|
||||
}
|
||||
|
||||
private companion object {
|
||||
val PALETTE = stringPreferencesKey("palette")
|
||||
val RECORD_DIR = stringPreferencesKey("recordDirUri")
|
||||
@@ -121,9 +140,11 @@ class SettingsStore(private val context: Context) {
|
||||
val KBD_CHANNEL = intPreferencesKey("kbdChannel")
|
||||
val KBD_OCTAVE = intPreferencesKey("kbdOctave")
|
||||
val VU_METERS = booleanPreferencesKey("vuMeters")
|
||||
val KEEP_SCREEN_ON = booleanPreferencesKey("keepScreenOn")
|
||||
val MIDI_CLOCK_SEND = booleanPreferencesKey("midiClockSend")
|
||||
val MIDI_CLOCK_RECV = booleanPreferencesKey("midiClockRecv")
|
||||
val SOUND_MODULE = booleanPreferencesKey("soundModule")
|
||||
val MIDI_SOURCES_OFF = stringSetPreferencesKey("midiSourcesOff")
|
||||
val BLE_MIDI = stringSetPreferencesKey("bleMidiDevices")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,14 @@ import java.io.InputStream
|
||||
|
||||
/** A song handed over by another app: its display [name] and [text], or an [error]
|
||||
* to show instead. */
|
||||
data class IncomingSong(val name: String, val text: String?, val error: String? = null)
|
||||
data class IncomingSong(
|
||||
val name: String,
|
||||
val text: String?,
|
||||
val error: String? = null,
|
||||
/** Mikro Seq asked to overwrite the current song without asking (see
|
||||
* [SongIntents.isTrustedReplace]). */
|
||||
val replaceNow: Boolean = false,
|
||||
)
|
||||
|
||||
/**
|
||||
* Reads a `.sng` that another app opened in Sizzle (Mikro Seq's "Open in Sizzle",
|
||||
@@ -33,6 +40,29 @@ object SongIntents {
|
||||
/** Larger than any real song (Mikro Seq's biggest export is a few tens of KB). */
|
||||
const val MAX_BYTES = 4 * 1024 * 1024
|
||||
|
||||
/** Boolean extra Mikro Seq's one-tap transfer sets to replace the song without the dialog. */
|
||||
const val EXTRA_REPLACE = "cc.tiredsysadmin.android.sizzle.extra.REPLACE"
|
||||
|
||||
/** The only app allowed to skip the dialog. */
|
||||
const val MIKROSEQ_PACKAGE = "cc.tiredsysadmin.android.mikroseq"
|
||||
|
||||
/**
|
||||
* True only for Mikro Seq's one-tap transfer: an `ACTION_VIEW` with [EXTRA_REPLACE]
|
||||
* set, of a `content:` URI served by a provider that belongs to Mikro Seq. That
|
||||
* provider isn't exported, so nobody else can hand us such a URI; any other app
|
||||
* setting the extra still gets the confirmation dialog. Needs Mikro Seq in the
|
||||
* manifest's `<queries>` for the provider lookup to see it.
|
||||
*/
|
||||
fun isTrustedReplace(context: Context, intent: Intent): Boolean {
|
||||
if (intent.action != Intent.ACTION_VIEW) return false
|
||||
if (!intent.getBooleanExtra(EXTRA_REPLACE, false)) return false
|
||||
val uri = intent.data ?: return false
|
||||
if (uri.scheme != "content") return false
|
||||
val authority = uri.authority ?: return false
|
||||
val owner = runCatching { context.packageManager.resolveContentProvider(authority, 0)?.packageName }.getOrNull()
|
||||
return owner == MIKROSEQ_PACKAGE
|
||||
}
|
||||
|
||||
fun read(context: Context, intent: Intent): IncomingSong {
|
||||
val uri: Uri? = when (intent.action) {
|
||||
Intent.ACTION_VIEW -> intent.data
|
||||
@@ -55,7 +85,7 @@ object SongIntents {
|
||||
} ?: return IncomingSong(name, null, "Couldn't read $name.")
|
||||
val text = String(bytes, Charsets.UTF_8)
|
||||
if (!SngFormat.looksLikeSng(text)) return IncomingSong(name, null, NOT_A_SONG)
|
||||
return IncomingSong(name, text)
|
||||
return IncomingSong(name, text, replaceNow = isTrustedReplace(context, intent))
|
||||
}
|
||||
|
||||
private const val NOT_A_SONG = "This doesn't look like a Sizzle .sng song, so nothing was imported."
|
||||
|
||||
@@ -49,7 +49,7 @@ enum class ToolboxType(
|
||||
// ---------- Instruments ----------
|
||||
// A classic 3-oscillator subtractive synth (Minimoog-style): oscillators →
|
||||
// mixer → resonant filter (own contour) → amp (own envelope), with a tempo-synced
|
||||
// LFO and a small mod matrix. Rendered by [SynthVoice]; edited by NesSynthEditor.
|
||||
// LFO and a small mod matrix. Rendered by core/src/synth/SynthVoice; edited by NesSynthEditor.
|
||||
// NOTE: the enum name NES_SYNTH is the on-disk/serialized identifier (preset dirs,
|
||||
// .sng type) and must stay stable for backward compatibility; only the user-facing
|
||||
// displayName is generic.
|
||||
@@ -94,6 +94,10 @@ enum class ToolboxType(
|
||||
ToolboxKind.INSTRUMENT, "Sampler",
|
||||
listOf(
|
||||
ParamSpec("volume", "Volume", 0.8f, 0f, 1f),
|
||||
// On: note-offs (MIDI, the tracker's ===, a new note on the track) are
|
||||
// ignored and every pad plays its whole slice. Stop / pause / panic still
|
||||
// silence it. Played by the C++ engine (core/), not the Kotlin reference.
|
||||
ParamSpec("oneShot", "One-shot", choices = listOf("Off", "On")),
|
||||
// A 16-pad bank: each pad maps to a consecutive note from C2 (see
|
||||
// [SamplerPads]) and stores its own sample id + slice as string params
|
||||
// ("pad0", "pad0S", "pad0E", …). Edited by ui/toolbox/SamplerEditor.
|
||||
@@ -120,17 +124,17 @@ enum class ToolboxType(
|
||||
// FRASIL's drone voice (MPL-2.0, see the frasil package): three layers (a detuned
|
||||
// saw choir, drifting additive partials, noise through resonators) that evolve
|
||||
// while held, morphing toward one of FRASIL's 36 drone sounds. Rendered by
|
||||
// FrasilVoice inside SynthVoice; edited by the paged editor in ToolboxScreen.
|
||||
// core/src/frasil/FrasilVoice inside SynthVoice; edited by the paged editor in ToolboxScreen.
|
||||
MORPH_PAD(ToolboxKind.INSTRUMENT, "Morph Pad", FrasilDefs.PARAMS),
|
||||
// ECHOFIELD's granular engine (MIT, see the echofield package): one cloud of up to
|
||||
// 32 grains per mixer channel, read from a built-in source (audio/GrainSources)
|
||||
// or your own sample ("sfSample", as the SF2/XI loader keeps it); held notes pitch
|
||||
// the grains. Rendered by GrainCloud in AudioEngine; edited by GrainCloudEditor.
|
||||
// the grains. Rendered by core/src/echofield/GrainCloud; edited by GrainCloudEditor.
|
||||
GRAIN_CLOUD(ToolboxKind.INSTRUMENT, "Grain Cloud", EchofieldDefs.PARAMS),
|
||||
// A two-oscillator wavetable synth (Sizzle's own, see the wavetable package): 12
|
||||
// generated tables or an imported Serum / WaveEdit WAV ("sfSample"), band-limited
|
||||
// per octave, position swept by an envelope and LFO, unison, SVF filter. Rendered
|
||||
// by WaveVoice inside SynthVoice; edited by WavetableEditor + the paged list.
|
||||
// by core/src/wavetable/WaveVoice inside SynthVoice; edited by WavetableEditor + the paged list.
|
||||
WAVETABLE(ToolboxKind.INSTRUMENT, "Wavetable", WaveDefs.PARAMS),
|
||||
|
||||
// ---------- Effects ----------
|
||||
@@ -217,7 +221,7 @@ enum class ToolboxType(
|
||||
ToolboxKind.EFFECT, "Ambience Reverb",
|
||||
// A mono port of the Ambience 16-channel FDN reverb (OTODESK): 7 algorithms,
|
||||
// tempo-independent tunables and 21 factory spaces (seeded into the preset
|
||||
// library). Rendered by audio/AmbienceReverb.kt.
|
||||
// library). Rendered by core/src/fx/AmbienceReverb.cpp.
|
||||
listOf(
|
||||
ParamSpec("algo", "Algorithm", 0f, 0f, 6f, AmbiencePresets.ALGORITHMS),
|
||||
ParamSpec("predelay", "Pre-Delay", 10f, 0f, 500f),
|
||||
@@ -245,7 +249,7 @@ enum class ToolboxType(
|
||||
// morphs the whole chain from transparent (0) to the full preset (1). Every
|
||||
// per-band value is a hidden slot param set by the genre/instrument presets
|
||||
// (see MixTightenerPresets); only Strength is user-facing. Rendered by
|
||||
// MixTightener in Effects.kt, edited by ui/toolbox/MixTightenerEditor.
|
||||
// core/src/fx/MixTightener.cpp, edited by ui/toolbox/MixTightenerEditor.
|
||||
listOf(ParamSpec("strength", "Strength", 1f, 0f, 1f)),
|
||||
),
|
||||
TAPE_ENGINE(
|
||||
@@ -254,7 +258,7 @@ enum class ToolboxType(
|
||||
// the pitch dives like a slowing tape (the 'speed' param is driven by that reel
|
||||
// gesture, not a slider). wow/flutter add slow + fast pitch wobble, hiss adds
|
||||
// tape noise, and the wow wobble rate is tempo-synced via 'division'. Rendered
|
||||
// by TapeEngine in Effects.kt, edited by ui/toolbox/TapeEngineEditor.
|
||||
// by core/src/fx/TapeEngine.cpp, edited by ui/toolbox/TapeEngineEditor.
|
||||
listOf(
|
||||
ParamSpec("speed", "Speed", 1f, 0.25f, 1f),
|
||||
ParamSpec("wow", "Wow", 0.15f, 0f, 1f),
|
||||
@@ -268,7 +272,7 @@ enum class ToolboxType(
|
||||
// Stutters/repeats short grains read from a rolling buffer of the incoming
|
||||
// sound; the read head jumps around, and the editor draws it as a moving
|
||||
// playhead over a dotted scope of the signal. One control: Intensity (how often
|
||||
// it glitches + how mangled). Rendered by GranularGlitch in Effects.kt, edited
|
||||
// it glitches + how mangled). Rendered by core/src/fx/GranularGlitch.cpp, edited
|
||||
// by ui/toolbox/GranularEditor.
|
||||
listOf(ParamSpec("intensity", "Intensity", 0.3f, 0f, 1f)),
|
||||
);
|
||||
|
||||
@@ -21,6 +21,7 @@ import cc.tiredsysadmin.android.sizzle.model.Pitch
|
||||
import cc.tiredsysadmin.android.sizzle.model.Project
|
||||
import cc.tiredsysadmin.android.sizzle.model.TimeSignature
|
||||
import cc.tiredsysadmin.android.sizzle.model.ToolboxSlot
|
||||
import cc.tiredsysadmin.android.sizzle.model.ToolboxType
|
||||
import kotlin.math.roundToInt
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
@@ -116,6 +117,15 @@ class AppViewModel(
|
||||
/** Whether the mixer's fader VU meters are shown (Settings toggle). */
|
||||
var vuMeters by mutableStateOf(true); private set
|
||||
|
||||
/** Keep the screen on while Sizzle is in front (Settings toggle). */
|
||||
var keepScreenOn by mutableStateOf(false); private set
|
||||
|
||||
fun updateKeepScreenOn(enabled: Boolean) {
|
||||
keepScreenOn = enabled
|
||||
viewModelScope.launch { settingsStore.saveKeepScreenOn(enabled) }
|
||||
touched()
|
||||
}
|
||||
|
||||
/** Enable/disable the mixer fader VU meters and persist the choice. */
|
||||
fun updateVuMeters(enabled: Boolean) {
|
||||
vuMeters = enabled
|
||||
@@ -146,9 +156,6 @@ class AppViewModel(
|
||||
* notification's Stop action changes it with no UI around. */
|
||||
val soundModuleMode: StateFlow<Boolean> get() = sizzleApp.soundModuleEnabled
|
||||
|
||||
/** MIDI sources currently open (USB, Bluetooth, other apps' virtual ports). */
|
||||
val midiSources: StateFlow<Int> get() = sizzleApp.soundModule.sources
|
||||
|
||||
fun updateSoundModuleMode(enabled: Boolean) = sizzleApp.setSoundModuleEnabled(enabled)
|
||||
|
||||
/** Every MIDI source that can send to Sizzle, with whether it is listened to. */
|
||||
@@ -160,15 +167,35 @@ class AppViewModel(
|
||||
/** Close and reopen every MIDI source (e.g. after the sending app restarted). */
|
||||
fun reconnectMidi() = midiInput.reconnect()
|
||||
|
||||
/** Bluetooth LE MIDI controllers: scan, connect, forget (Settings › MIDI inputs). */
|
||||
val bleMidi: cc.tiredsysadmin.android.sizzle.input.BleMidi get() = sizzleApp.bleMidi
|
||||
|
||||
// ----- A song opened from another app (VIEW / SEND intent) -----
|
||||
/** Waiting for the user to confirm replacing the current song, or to read why
|
||||
* it can't be opened. */
|
||||
private val BEFORE_MIKROSEQ = "Before Mikro Seq import"
|
||||
|
||||
var incomingSong by mutableStateOf<cc.tiredsysadmin.android.sizzle.io.IncomingSong?>(null); private set
|
||||
|
||||
fun offerIncomingSong(song: cc.tiredsysadmin.android.sizzle.io.IncomingSong) { incomingSong = song }
|
||||
|
||||
fun dismissIncomingSong() { incomingSong = null }
|
||||
|
||||
/**
|
||||
* Mikro Seq's one-tap transfer ([cc.tiredsysadmin.android.sizzle.io.SongIntents.isTrustedReplace]):
|
||||
* nothing asks first, so the current song is saved in full to the library as
|
||||
* [BEFORE_MIKROSEQ] (overwriting the previous such backup), then replaced.
|
||||
*/
|
||||
fun replaceFromMikroSeq(song: cc.tiredsysadmin.android.sizzle.io.IncomingSong) {
|
||||
val backedUp = runCatching { songLibrary.save(BEFORE_MIKROSEQ, saveProjectText()) }.isSuccess
|
||||
incomingSong = song
|
||||
if (acceptIncomingSong()) {
|
||||
val msg = if (backedUp) "Loaded ${song.name}. Previous song saved as \"$BEFORE_MIKROSEQ\"."
|
||||
else "Loaded ${song.name}. Couldn't back up the previous song."
|
||||
android.widget.Toast.makeText(appContext, msg, android.widget.Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
|
||||
/** Replace the current song with the offered one. Stops playback first so the
|
||||
* audio thread isn't reading the model while it is rewritten. Returns false
|
||||
* (leaving the song as it was parsed so far) if the import fails. */
|
||||
@@ -691,6 +718,34 @@ class AppViewModel(
|
||||
touched()
|
||||
}
|
||||
|
||||
/** [slotIndex]'s MIDI mapping as a shareable `.szm` file (in presets/.export,
|
||||
* which the FileProvider serves), or null for an empty slot. */
|
||||
fun midiMapExportFile(slotIndex: Int): java.io.File? {
|
||||
val slot = project.toolbox.getOrNull(slotIndex)?.takeIf { !it.isEmpty } ?: return null
|
||||
val map = cc.tiredsysadmin.android.sizzle.io.MidiMapIo.fromSlot(slot)
|
||||
val dir = java.io.File(appContext.filesDir, "presets/.export").apply { mkdirs() }
|
||||
val base = slot.name.ifBlank { slot.type?.name ?: "device" }
|
||||
.replace(Regex("[^A-Za-z0-9._ -]"), "_").trim().ifBlank { "device" }
|
||||
return java.io.File(dir, "$base MIDI${cc.tiredsysadmin.android.sizzle.io.MidiMapIo.EXT}").apply {
|
||||
writeText(cc.tiredsysadmin.android.sizzle.io.MidiMapIo.save(map))
|
||||
}
|
||||
}
|
||||
|
||||
/** Replace [slotIndex]'s MIDI mapping with the `.szm` [text]; null when done,
|
||||
* else why not (for a dialog). */
|
||||
fun importMidiMap(slotIndex: Int, text: String): String? {
|
||||
val io = cc.tiredsysadmin.android.sizzle.io.MidiMapIo
|
||||
val map = io.parse(text) ?: return "This doesn't look like a Sizzle MIDI mapping (.szm)."
|
||||
val slot = project.toolbox.getOrNull(slotIndex) ?: return "No device here."
|
||||
if (slot.type?.name != map.type) {
|
||||
val want = runCatching { ToolboxType.valueOf(map.type).displayName }.getOrDefault(map.type)
|
||||
return "This mapping is for a $want, not a ${slot.type?.displayName ?: "empty slot"}."
|
||||
}
|
||||
io.apply(project, slotIndex, map)
|
||||
touched()
|
||||
return null
|
||||
}
|
||||
|
||||
/** Remove the MIDI-CC binding for [slotIndex]'s [paramKey]. */
|
||||
fun clearParamCc(slotIndex: Int, paramKey: String) {
|
||||
project.toolbox.getOrNull(slotIndex)?.values?.remove(ccKey(paramKey))
|
||||
@@ -808,7 +863,8 @@ class AppViewModel(
|
||||
viewModelScope.launch { bindingStore.save(keyboardInput, gamepadInput, midiInput) }
|
||||
}
|
||||
|
||||
private fun touched() { revision++ }
|
||||
/** Every edit ends here: redraw, and bring the engine's copy of the song up to date. */
|
||||
private fun touched() { revision++; engine.requestSync() }
|
||||
|
||||
/** Public hook so screens that mutate the model directly (e.g. dropdowns in
|
||||
* the toolbar, mixer faders) can request a redraw. */
|
||||
@@ -1048,6 +1104,7 @@ class AppViewModel(
|
||||
kbdChannel = s.kbdChannel.coerceIn(0, Cell.MAX_CHANNEL)
|
||||
kbdOctave = s.kbdOctave.coerceIn(0, 8)
|
||||
vuMeters = s.vuMeters
|
||||
keepScreenOn = s.keepScreenOn
|
||||
|
||||
// MIDI clock sync: the transport/tempo follow and the send thread's
|
||||
// providers are wired in SizzleApp (they must work with no UI); here we
|
||||
@@ -1348,6 +1405,32 @@ class AppViewModel(
|
||||
return ok
|
||||
}
|
||||
|
||||
/** Does this device have a dice button? (The randomizer lives in core/.) */
|
||||
fun canRandomize(type: cc.tiredsysadmin.android.sizzle.model.ToolboxType): Boolean =
|
||||
cc.tiredsysadmin.android.sizzle.audio.NativeEngine.canRandomize(type.name)
|
||||
|
||||
/**
|
||||
* Roll a new patch into [slot]: a playable one, generated by core/'s randomizer
|
||||
* (the same rules and the same seeds as iOS). The slot's own files are kept —
|
||||
* a loaded sample or an imported wavetable is the user's, and a dice roll of the
|
||||
* *settings* must not throw it away — so the keys the device's parameter list
|
||||
* doesn't name (`sfSample`, `sfFile`, the Sampler's pads) are put back afterwards.
|
||||
*/
|
||||
fun randomizeSlot(slot: cc.tiredsysadmin.android.sizzle.model.ToolboxSlot): Boolean {
|
||||
val type = slot.type ?: return false
|
||||
val seed = java.util.concurrent.ThreadLocalRandom.current().nextInt()
|
||||
val text = cc.tiredsysadmin.android.sizzle.audio.NativeEngine.randomPreset(type.name, seed)
|
||||
if (text.isBlank()) return false
|
||||
val keep = slot.values.filterKeys { key -> type.params.none { it.key == key } }
|
||||
if (!cc.tiredsysadmin.android.sizzle.io.PresetIo.import(slot, text)) return false
|
||||
keep.forEach { (k, v) -> slot.set(k, v) }
|
||||
slot.name = cc.tiredsysadmin.android.sizzle.audio.NativeEngine.randomName(type.name, seed)
|
||||
.ifBlank { type.displayName }
|
||||
engine.rebuildFxChains()
|
||||
touched()
|
||||
return true
|
||||
}
|
||||
|
||||
/** Import a preset from picked bytes: a `.zip` bundle (Sampler) or plain text. */
|
||||
fun importPreset(slot: cc.tiredsysadmin.android.sizzle.model.ToolboxSlot, bytes: ByteArray): Boolean {
|
||||
val isZip = bytes.size >= 2 && bytes[0] == 'P'.code.toByte() && bytes[1] == 'K'.code.toByte()
|
||||
|
||||
@@ -23,7 +23,7 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ArrowBack
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material.icons.filled.ChevronRight
|
||||
import androidx.compose.material.icons.filled.Piano
|
||||
import androidx.compose.material.icons.filled.ContentCopy
|
||||
@@ -170,7 +170,7 @@ fun SettingsScreen(vm: AppViewModel) {
|
||||
@Composable
|
||||
private fun SubHeader(title: String, onBack: () -> Unit) {
|
||||
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
|
||||
IconButton(onClick = onBack) { Icon(Icons.Filled.ArrowBack, contentDescription = "Back") }
|
||||
IconButton(onClick = onBack) { Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back") }
|
||||
Text(title, style = MaterialTheme.typography.titleMedium, color = MaterialTheme.colorScheme.primary)
|
||||
}
|
||||
}
|
||||
@@ -574,6 +574,89 @@ private fun MidiInputsList(vm: AppViewModel) {
|
||||
src.enabled,
|
||||
) { vm.setMidiSourceEnabled(src.key, it) }
|
||||
}
|
||||
HorizontalDivider()
|
||||
BluetoothMidiList(vm)
|
||||
}
|
||||
|
||||
/**
|
||||
* Bluetooth LE MIDI controllers: SCAN looks for them for 15 s (asking for the
|
||||
* Bluetooth permission first), CONNECT opens one, and from then on it is one of
|
||||
* the MIDI inputs above, connected again at every start until FORGET.
|
||||
*/
|
||||
@Composable
|
||||
private fun BluetoothMidiList(vm: AppViewModel) {
|
||||
val ble = vm.bleMidi
|
||||
val devices by ble.devices.collectAsState()
|
||||
val scanning by ble.scanning.collectAsState()
|
||||
val error by ble.error.collectAsState()
|
||||
val askPermission = rememberLauncherForActivityResult(
|
||||
ActivityResultContracts.RequestMultiplePermissions(),
|
||||
) { ble.startScan() } // without the permission it reports what is missing
|
||||
|
||||
Row(
|
||||
Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Column(Modifier.weight(1f)) {
|
||||
Text("Bluetooth MIDI", style = MaterialTheme.typography.bodyMedium)
|
||||
Text(
|
||||
if (!ble.supported) "This device has no Bluetooth LE MIDI support."
|
||||
else "Find Bluetooth LE MIDI controllers and connect them. Connected ones are listed " +
|
||||
"with the MIDI inputs and reconnect at every start.",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
if (ble.supported) {
|
||||
OutlinedButton(onClick = {
|
||||
when {
|
||||
scanning -> ble.stopScan()
|
||||
ble.hasPermissions() -> ble.startScan()
|
||||
else -> askPermission.launch(ble.requiredPermissions())
|
||||
}
|
||||
}) { Text(if (scanning) "Stop" else "Scan") }
|
||||
}
|
||||
}
|
||||
if (scanning) {
|
||||
Text(
|
||||
"Scanning… switch the controller on (or into pairing mode) nearby.",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
error?.let {
|
||||
Text(it, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.error)
|
||||
}
|
||||
for (d in devices) {
|
||||
Row(
|
||||
Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Column(Modifier.weight(1f)) {
|
||||
Text(d.name, style = MaterialTheme.typography.bodyMedium)
|
||||
Text(
|
||||
when {
|
||||
d.connecting -> "Connecting…"
|
||||
d.connected -> "Connected"
|
||||
d.remembered -> "Remembered — not connected"
|
||||
else -> "Found"
|
||||
},
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
when {
|
||||
d.connecting -> {}
|
||||
d.connected -> OutlinedButton(onClick = { ble.disconnect(d.address, forget = false) }) { Text("Disconnect") }
|
||||
else -> OutlinedButton(onClick = { ble.connect(d.address) }) { Text("Connect") }
|
||||
}
|
||||
if (d.remembered) {
|
||||
TextButton(onClick = { ble.disconnect(d.address, forget = true) }) { Text("Forget") }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** A labelled switch row (title + supporting text + trailing Switch). */
|
||||
@@ -602,6 +685,12 @@ private fun InterfaceCard(vm: AppViewModel) {
|
||||
"Show live level meters inside the mixer volume faders.",
|
||||
vm.vuMeters,
|
||||
) { vm.updateVuMeters(it) }
|
||||
HorizontalDivider()
|
||||
ToggleRow(
|
||||
"Keep screen on",
|
||||
"Don't let the screen dim or lock while Sizzle is open.",
|
||||
vm.keepScreenOn,
|
||||
) { vm.updateKeepScreenOn(it) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,20 +19,27 @@ object DeviceLayouts {
|
||||
|
||||
fun pagesFor(type: ToolboxType): List<Page> = when (type) {
|
||||
ToolboxType.WAVETABLE -> listOf(
|
||||
Page("Osc", listOf(
|
||||
Panel("Oscillator 1", Tone.SOURCE, osc(1)),
|
||||
Panel("Oscillator 2", Tone.SOURCE, osc(2)),
|
||||
// One oscillator per tab, each drawing its own table, so every page fits
|
||||
// above the keyboard without scrolling. A loaded WAV lands on oscillator 1,
|
||||
// so LOAD TABLE and its frame size sit on that card.
|
||||
Page("Osc 1", listOf(
|
||||
Panel("Oscillator 1", Tone.SOURCE, listOf("o1table", "wtframe") + osc(1).drop(1), Viz.Wavetable(1),
|
||||
labels = mapOf("wtframe" to "Frame"), action = { vm, slot -> LoadTableAction(vm, slot) }),
|
||||
)),
|
||||
Page("Osc 2", listOf(
|
||||
Panel("Oscillator 2", Tone.SOURCE, osc(2), Viz.Wavetable(2)),
|
||||
)),
|
||||
Page("Voice", listOf(
|
||||
Panel("Voice", Tone.SOURCE, listOf("unison", "spread", "sub", "noise", "velsens")),
|
||||
Panel("Table import", Tone.OUT, listOf("wtframe")),
|
||||
)),
|
||||
Page("Filter", listOf(
|
||||
Panel("Filter", Tone.FILTER, listOf("ftype", "cutoff", "reso", "keytrack", "fenv", "drive"),
|
||||
Viz.Filter("ftype", "cutoff", "reso"), labels = mapOf("ftype" to "Type", "fenv" to "Env Amt")),
|
||||
)),
|
||||
Page("Env", listOf(
|
||||
Page("Amp", listOf(
|
||||
Panel("Amp envelope", Tone.ENV, listOf("attack", "decay", "sustain", "release"), ADSR),
|
||||
)),
|
||||
Page("Mod", listOf(
|
||||
Panel("Mod envelope", Tone.MOD, listOf("mattack", "mdecay", "msustain", "mrelease", "menvpos"),
|
||||
Viz.Envelope("mattack", "mdecay", "msustain", "mrelease")),
|
||||
)),
|
||||
|
||||
@@ -16,6 +16,7 @@ import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
@@ -58,6 +59,12 @@ fun GrainCloudEditor(vm: AppViewModel, slot: ToolboxSlot) {
|
||||
}
|
||||
}
|
||||
|
||||
// Same as the wavetables: the ten built-in sources are synthesised, the engine
|
||||
// renders its own set in core/, and this Kotlin copy exists only to draw the
|
||||
// waveform below. Built when the editor opens rather than at launch — that is
|
||||
// about 6 MB of PCM an app that never opens one no longer renders or holds.
|
||||
LaunchedEffect(Unit) { GrainSources.prewarm() }
|
||||
|
||||
val sourceName = slot.string("source", EchofieldDefs.SOURCES[0])
|
||||
val custom = sourceName == EchofieldDefs.CUSTOM
|
||||
val sample = if (custom) SampleStore.get(slot.string(EchofieldDefs.SAMPLE_KEY)) else GrainSources.get(sourceName)
|
||||
|
||||
@@ -79,6 +79,8 @@ sealed interface Viz {
|
||||
data class Filter(val type: String?, val cutoff: String, val reso: String) : Viz
|
||||
/** Two cycles of the wave named by [wave]'s choice. */
|
||||
data class Lfo(val wave: String) : Viz
|
||||
/** The Wavetable oscillator [osc]'s table, frames stacked, the one at its position lit. */
|
||||
data class Wavetable(val osc: Int) : Viz
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,6 +97,8 @@ class Panel(
|
||||
val labels: Map<String, String> = emptyMap(),
|
||||
val faders: List<String>? = null,
|
||||
val faderScale: Float = 1f,
|
||||
/** A small action drawn at the right of the card's title (e.g. the Wavetable's LOAD TABLE). */
|
||||
val action: (@Composable (AppViewModel, ToolboxSlot) -> Unit)? = null,
|
||||
)
|
||||
|
||||
/** A tab of cards. */
|
||||
@@ -131,22 +135,23 @@ fun DevicePanels(vm: AppViewModel, slot: ToolboxSlot, pages: List<Page>) {
|
||||
@Composable
|
||||
private fun PageTabs(pages: List<Page>, selected: Int, onSelect: (Int) -> Unit) {
|
||||
val c = LocalRetro.current
|
||||
Row(
|
||||
Modifier.fillMaxWidth().horizontalScroll(rememberScrollState()),
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
// Tabs share the width (up to seven fit a phone), so none hides off-screen.
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
pages.forEachIndexed { i, p ->
|
||||
val on = i == selected
|
||||
val tone = toneColor(p.panels.first().tone)
|
||||
Box(
|
||||
Modifier
|
||||
.weight(1f)
|
||||
.border(1.dp, if (on) tone else c.grid, RectangleShape)
|
||||
.background(if (on) tone.copy(alpha = 0.22f) else c.surface)
|
||||
.clickable { onSelect(i) }
|
||||
.padding(horizontal = 12.dp, vertical = 7.dp),
|
||||
.padding(horizontal = 2.dp, vertical = 7.dp),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Text(p.title.uppercase(), color = if (on) tone else c.textDim,
|
||||
fontFamily = FontFamily.Monospace, fontSize = 12.sp)
|
||||
fontFamily = FontFamily.Monospace, fontSize = if (pages.size > 5) 10.sp else 12.sp,
|
||||
maxLines = 1, softWrap = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -174,12 +179,16 @@ fun PanelCard(vm: AppViewModel, slot: ToolboxSlot, panel: Panel, rev: Int = vm.r
|
||||
Box(Modifier.size(8.dp).background(tone))
|
||||
Spacer(Modifier.width(6.dp))
|
||||
Text(panel.title.uppercase(), color = tone, fontFamily = FontFamily.Monospace, fontSize = 11.sp,
|
||||
letterSpacing = 1.sp)
|
||||
letterSpacing = 1.sp, modifier = Modifier.weight(1f))
|
||||
panel.action?.invoke(vm, slot)
|
||||
}
|
||||
panel.viz?.let {
|
||||
if (it is Viz.Wavetable) WavetablePreview(slot, it.osc, tone, rev)
|
||||
else VizCanvas(slot, it, byKey, tone, rev)
|
||||
}
|
||||
panel.viz?.let { VizCanvas(slot, it, byKey, tone) }
|
||||
|
||||
if (panel.faders != null) {
|
||||
FaderBank(vm, slot, specs, panel, tone)
|
||||
FaderBank(vm, slot, specs, panel, tone, rev)
|
||||
return@Column
|
||||
}
|
||||
|
||||
@@ -201,7 +210,7 @@ fun PanelCard(vm: AppViewModel, slot: ToolboxSlot, panel: Panel, rev: Int = vm.r
|
||||
}
|
||||
}
|
||||
}
|
||||
segmented.forEach { Segmented(vm, slot, it, shortLabel(it, panel), tone) }
|
||||
segmented.forEach { Segmented(vm, slot, it, shortLabel(it, panel), tone, rev) }
|
||||
|
||||
if (knobs.isNotEmpty()) {
|
||||
val n = knobs.size
|
||||
@@ -211,7 +220,7 @@ fun PanelCard(vm: AppViewModel, slot: ToolboxSlot, panel: Panel, rev: Int = vm.r
|
||||
val pad = (slots - row.size) / 2f
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
if (pad > 0f) Spacer(Modifier.weight(pad))
|
||||
row.forEach { spec -> SpecKnob(vm, slot, spec, shortLabel(spec, panel), tone, Modifier.weight(1f)) }
|
||||
row.forEach { spec -> SpecKnob(vm, slot, spec, shortLabel(spec, panel), tone, rev, Modifier.weight(1f)) }
|
||||
if (pad > 0f) Spacer(Modifier.weight(pad))
|
||||
}
|
||||
}
|
||||
@@ -222,7 +231,8 @@ fun PanelCard(vm: AppViewModel, slot: ToolboxSlot, panel: Panel, rev: Int = vm.r
|
||||
// ---------------------------------------------------------------- controls
|
||||
|
||||
@Composable
|
||||
private fun SpecKnob(vm: AppViewModel, slot: ToolboxSlot, spec: ParamSpec, label: String, tone: Color, modifier: Modifier) {
|
||||
private fun SpecKnob(vm: AppViewModel, slot: ToolboxSlot, spec: ParamSpec, label: String, tone: Color, rev: Int, modifier: Modifier) {
|
||||
@Suppress("UNUSED_PARAMETER") val ignored = rev
|
||||
val value = slot.float(spec.key, spec.default).coerceIn(spec.min, spec.max)
|
||||
Knob(
|
||||
label = label.uppercase(), value = value, min = spec.min, max = spec.max,
|
||||
@@ -238,7 +248,8 @@ private fun isSegmentable(spec: ParamSpec): Boolean =
|
||||
spec.choices.size <= 6 && spec.choices.sumOf { it.length } <= 34
|
||||
|
||||
@Composable
|
||||
private fun Segmented(vm: AppViewModel, slot: ToolboxSlot, spec: ParamSpec, label: String, tone: Color) {
|
||||
private fun Segmented(vm: AppViewModel, slot: ToolboxSlot, spec: ParamSpec, label: String, tone: Color, rev: Int) {
|
||||
@Suppress("UNUSED_PARAMETER") val ignored = rev
|
||||
val c = LocalRetro.current
|
||||
val cur = slot.string(spec.key, spec.choices.first())
|
||||
Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
|
||||
@@ -265,7 +276,8 @@ private fun Segmented(vm: AppViewModel, slot: ToolboxSlot, spec: ParamSpec, labe
|
||||
|
||||
/** Vertical bipolar faders, one per key: drag or tap to set, double-tap to zero. */
|
||||
@Composable
|
||||
private fun FaderBank(vm: AppViewModel, slot: ToolboxSlot, specs: List<ParamSpec>, panel: Panel, tone: Color) {
|
||||
private fun FaderBank(vm: AppViewModel, slot: ToolboxSlot, specs: List<ParamSpec>, panel: Panel, tone: Color, rev: Int) {
|
||||
@Suppress("UNUSED_PARAMETER") val ignored = rev
|
||||
val c = LocalRetro.current
|
||||
val captions = panel.faders ?: return
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(3.dp)) {
|
||||
@@ -313,13 +325,17 @@ private fun FaderBank(vm: AppViewModel, slot: ToolboxSlot, specs: List<ParamSpec
|
||||
// ---------------------------------------------------------------- drawings
|
||||
|
||||
@Composable
|
||||
private fun VizCanvas(slot: ToolboxSlot, viz: Viz, byKey: Map<String, ParamSpec>, tone: Color) {
|
||||
private fun VizCanvas(slot: ToolboxSlot, viz: Viz, byKey: Map<String, ParamSpec>, tone: Color, rev: Int) {
|
||||
@Suppress("UNUSED_PARAMETER") val ignored = rev
|
||||
val c = LocalRetro.current
|
||||
fun num(key: String?): Float? = key?.let { k -> byKey[k]?.let { slot.float(k, it.default).coerceIn(it.min, it.max) } }
|
||||
fun frac(key: String?): Float? = key?.let { k -> byKey[k]?.let { s -> num(k)!!.let { (it - s.min) / (s.max - s.min) } } }
|
||||
fun choice(key: String?): String = key?.let { k -> byKey[k]?.let { slot.string(k, it.choices.firstOrNull() ?: "") } } ?: ""
|
||||
|
||||
Canvas(Modifier.fillMaxWidth().height(56.dp).background(c.background).border(1.dp, c.grid, RectangleShape)) {
|
||||
// Capture the revision so this lambda isn't memoized across parameter edits
|
||||
// (it reads the slot map directly, which Compose can't observe).
|
||||
if (rev < 0) return@Canvas
|
||||
val w = size.width; val h = size.height
|
||||
val top = h * 0.12f; val bottom = h * 0.92f
|
||||
val path = Path()
|
||||
@@ -361,6 +377,7 @@ private fun VizCanvas(slot: ToolboxSlot, viz: Viz, byKey: Map<String, ParamSpec>
|
||||
drawLine(c.grid, Offset(0f, zeroY), Offset(w, zeroY), strokeWidth = 1f)
|
||||
drawLine(c.grid, Offset(fc * w, top), Offset(fc * w, bottom), strokeWidth = 1f)
|
||||
}
|
||||
is Viz.Wavetable -> Unit // drawn by WavetablePreview
|
||||
is Viz.Lfo -> {
|
||||
val name = choice(viz.wave).lowercase()
|
||||
val n = 160
|
||||
|
||||
@@ -102,6 +102,24 @@ fun SamplerEditor(vm: AppViewModel, slot: ToolboxSlot, pad: Int, onSelectPad: (I
|
||||
}
|
||||
|
||||
Column(Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
// ----- One-shot (the whole Sampler): note-offs don't cut the pads -----
|
||||
val oneShot = slot.string("oneShot", "Off") == "On"
|
||||
Row(
|
||||
Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
RetroButton("ONE-SHOT", active = oneShot) {
|
||||
slot.set("oneShot", if (oneShot) "Off" else "On")
|
||||
vm.bumpForToolbar()
|
||||
}
|
||||
Text(
|
||||
if (oneShot) "Pads play their whole slice; note-offs are ignored."
|
||||
else "Pads stop on note-off (key release, ===).",
|
||||
color = c.textDim, fontFamily = FontFamily.Monospace, fontSize = 11.sp,
|
||||
)
|
||||
}
|
||||
|
||||
// ----- Selected pad + source buttons (act on the selected pad) -----
|
||||
Text(
|
||||
"Pad ${pad + 1} · ${Pitch.name(SamplerPads.noteFor(pad))}",
|
||||
|
||||
@@ -228,7 +228,7 @@ private fun roundedPoly(v: Array<Offset>, corner: Float): Path {
|
||||
val a = curr + toward(curr, prev, corner) // approach point on the incoming edge
|
||||
val b = curr + toward(curr, next, corner) // leave point on the outgoing edge
|
||||
if (i == 0) path.moveTo(a.x, a.y) else path.lineTo(a.x, a.y)
|
||||
path.quadraticBezierTo(curr.x, curr.y, b.x, b.y)
|
||||
path.quadraticTo(curr.x, curr.y, b.x, b.y)
|
||||
}
|
||||
path.close()
|
||||
return path
|
||||
|
||||
@@ -49,8 +49,10 @@ import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
@@ -324,64 +326,80 @@ private fun ParamEditor(vm: AppViewModel, slot: ToolboxSlot, onClose: () -> Unit
|
||||
// Whether the MIDI-learn popup (map controls to this device's parameters) is open.
|
||||
var showMidiLearn by remember(slot.index) { mutableStateOf(false) }
|
||||
|
||||
Box(Modifier.fillMaxSize().background(c.background.copy(alpha = 0.96f))) {
|
||||
Column(Modifier.fillMaxSize()) {
|
||||
Column(
|
||||
Modifier
|
||||
.weight(if (pinnedBottom) 1.7f else 1f)
|
||||
.fillMaxWidth()
|
||||
.padding(12.dp)
|
||||
.verticalScroll(rememberScrollState()),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
|
||||
Text(slot.name, color = c.accent, fontFamily = FontFamily.Monospace, fontSize = 15.sp)
|
||||
// Right-side toolbar: MIDI-learn (map controls to params) + close.
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(14.dp)) {
|
||||
Text("⇄ MIDI", color = c.accent, fontFamily = FontFamily.Monospace, fontSize = 13.sp,
|
||||
modifier = Modifier.pointerInput(Unit) { detectTapGestures { showMidiLearn = true } })
|
||||
Text("CLOSE ✕", color = c.textDim, fontFamily = FontFamily.Monospace, fontSize = 13.sp,
|
||||
modifier = Modifier.pointerInput(Unit) { detectTapGestures { onClose() } })
|
||||
}
|
||||
}
|
||||
// The playable part pinned beside the controls: the Sampler's pads, else an
|
||||
// audition keyboard.
|
||||
val pinned: @Composable (Modifier) -> Unit = { mod ->
|
||||
if (type == ToolboxType.SAMPLER) {
|
||||
SamplerPadBank(vm, slot, samplerPad, onSelect = { samplerPad = it }, mod)
|
||||
} else {
|
||||
SlotAuditionKeyboard(vm, slot, mod)
|
||||
}
|
||||
}
|
||||
// Landscape: controls on the left, keyboard / pads pinned on the right at the
|
||||
// same 1 : 1.3 split as the Toolbox tab. Portrait: controls above, 1.7 : 1.
|
||||
val sideBySide = pinnedBottom && isLandscape()
|
||||
|
||||
// Preset browser: load / save / import / share for this device.
|
||||
PresetBar(vm, slot)
|
||||
|
||||
// The Synth / Sampler / SoundFont / Delay / tape and glitch effects have
|
||||
// bespoke editors; everything else is grouped cards ([DevicePanels]), with
|
||||
// a source strip on top for the Wavetable and Grain Cloud and the LFO's
|
||||
// target picker below.
|
||||
when (type) {
|
||||
ToolboxType.NES_SYNTH -> NesSynthEditor(vm, slot)
|
||||
ToolboxType.MIX_TIGHTENER -> MixTightenerEditor(vm, slot)
|
||||
ToolboxType.TAPE_ENGINE -> TapeEngineEditor(vm, slot)
|
||||
ToolboxType.GRANULAR -> GranularEditor(vm, slot)
|
||||
ToolboxType.SAMPLER -> SamplerEditor(vm, slot, samplerPad, onSelectPad = { samplerPad = it })
|
||||
ToolboxType.SOUNDFONT -> SoundFontEditor(vm, slot)
|
||||
ToolboxType.DELAY -> DelayEditor(vm, slot)
|
||||
ToolboxType.WAVETABLE -> {
|
||||
WavetableEditor(vm, slot)
|
||||
DevicePanels(vm, slot, DeviceLayouts.pagesFor(type))
|
||||
}
|
||||
ToolboxType.GRAIN_CLOUD -> {
|
||||
GrainCloudEditor(vm, slot)
|
||||
DevicePanels(vm, slot, DeviceLayouts.pagesFor(type))
|
||||
}
|
||||
ToolboxType.LFO -> {
|
||||
DevicePanels(vm, slot, DeviceLayouts.pagesFor(type))
|
||||
LfoTargetPicker(vm, slot)
|
||||
}
|
||||
else -> DevicePanels(vm, slot, DeviceLayouts.pagesFor(type))
|
||||
// Header, presets and the device's own controls (scrolls on its own).
|
||||
val controls: @Composable (Modifier) -> Unit = { mod ->
|
||||
Column(
|
||||
Modifier
|
||||
.then(mod)
|
||||
.padding(12.dp)
|
||||
.verticalScroll(rememberScrollState()),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
|
||||
Text(slot.name, color = c.accent, fontFamily = FontFamily.Monospace, fontSize = 15.sp)
|
||||
// Right-side toolbar: MIDI-learn (map controls to params) + close.
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(14.dp)) {
|
||||
Text("⇄ MIDI", color = c.accent, fontFamily = FontFamily.Monospace, fontSize = 13.sp,
|
||||
modifier = Modifier.pointerInput(Unit) { detectTapGestures { showMidiLearn = true } })
|
||||
Text("CLOSE ✕", color = c.textDim, fontFamily = FontFamily.Monospace, fontSize = 13.sp,
|
||||
modifier = Modifier.pointerInput(Unit) { detectTapGestures { onClose() } })
|
||||
}
|
||||
}
|
||||
|
||||
if (pinnedBottom) {
|
||||
Box(Modifier.fillMaxWidth().height(2.dp).background(c.accent)) // fixed divider
|
||||
if (type == ToolboxType.SAMPLER) {
|
||||
SamplerPadBank(vm, slot, samplerPad, onSelect = { samplerPad = it }, Modifier.weight(1f))
|
||||
} else {
|
||||
SlotAuditionKeyboard(vm, slot, Modifier.weight(1f))
|
||||
// Preset browser: load / save / import / share for this device.
|
||||
PresetBar(vm, slot)
|
||||
|
||||
// The Synth / Sampler / SoundFont / Delay / tape and glitch effects have
|
||||
// bespoke editors; everything else is grouped cards ([DevicePanels]), with
|
||||
// a source strip on top for the Grain Cloud and the LFO's
|
||||
// target picker below.
|
||||
when (type) {
|
||||
ToolboxType.NES_SYNTH -> NesSynthEditor(vm, slot)
|
||||
ToolboxType.MIX_TIGHTENER -> MixTightenerEditor(vm, slot)
|
||||
ToolboxType.TAPE_ENGINE -> TapeEngineEditor(vm, slot)
|
||||
ToolboxType.GRANULAR -> GranularEditor(vm, slot)
|
||||
ToolboxType.SAMPLER -> SamplerEditor(vm, slot, samplerPad, onSelectPad = { samplerPad = it })
|
||||
ToolboxType.SOUNDFONT -> SoundFontEditor(vm, slot)
|
||||
ToolboxType.DELAY -> DelayEditor(vm, slot)
|
||||
ToolboxType.GRAIN_CLOUD -> {
|
||||
GrainCloudEditor(vm, slot)
|
||||
DevicePanels(vm, slot, DeviceLayouts.pagesFor(type))
|
||||
}
|
||||
ToolboxType.LFO -> {
|
||||
DevicePanels(vm, slot, DeviceLayouts.pagesFor(type))
|
||||
LfoTargetPicker(vm, slot)
|
||||
}
|
||||
else -> DevicePanels(vm, slot, DeviceLayouts.pagesFor(type))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Box(Modifier.fillMaxSize().background(c.background.copy(alpha = 0.96f))) {
|
||||
if (sideBySide) {
|
||||
Row(Modifier.fillMaxSize()) {
|
||||
controls(Modifier.weight(1f).fillMaxHeight())
|
||||
Box(Modifier.width(2.dp).fillMaxHeight().background(c.accent)) // fixed divider
|
||||
pinned(Modifier.weight(1.3f).fillMaxHeight())
|
||||
}
|
||||
} else {
|
||||
Column(Modifier.fillMaxSize()) {
|
||||
controls(Modifier.weight(if (pinnedBottom) 1.7f else 1f).fillMaxWidth())
|
||||
if (pinnedBottom) {
|
||||
Box(Modifier.fillMaxWidth().height(2.dp).background(c.accent)) // fixed divider
|
||||
pinned(Modifier.weight(1f))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -406,6 +424,16 @@ private fun MidiLearnPopup(vm: AppViewModel, slot: ToolboxSlot, onClose: () -> U
|
||||
val type = slot.type ?: return
|
||||
// Always disarm learn when the popup leaves the composition (closed / editor exited).
|
||||
DisposableEffect(slot.index) { onDispose { vm.cancelParamLearn() } }
|
||||
val context = LocalContext.current
|
||||
var importMessage by remember { mutableStateOf<String?>(null) }
|
||||
// IMPORT: a .szm mapping for this device type replaces this slot's mappings.
|
||||
val mapImporter = rememberLauncherForActivityResult(ActivityResultContracts.OpenDocument()) { uri ->
|
||||
if (uri == null) return@rememberLauncherForActivityResult
|
||||
val text = runCatching {
|
||||
context.contentResolver.openInputStream(uri)?.use { it.readBytes().takeIf { b -> b.size <= 1 shl 20 } }
|
||||
}.getOrNull()?.toString(Charsets.UTF_8)
|
||||
importMessage = if (text == null) "Couldn't read the selected file." else vm.importMidiMap(slot.index, text)
|
||||
}
|
||||
|
||||
Box(
|
||||
Modifier.fillMaxSize().background(c.background.copy(alpha = 0.92f))
|
||||
@@ -424,9 +452,28 @@ private fun MidiLearnPopup(vm: AppViewModel, slot: ToolboxSlot, onClose: () -> U
|
||||
) {
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
|
||||
Text("MIDI LEARN — ${slot.name}", color = c.accent,
|
||||
fontFamily = FontFamily.Monospace, fontSize = 14.sp)
|
||||
Text("DONE", color = c.textDim, fontFamily = FontFamily.Monospace, fontSize = 13.sp,
|
||||
modifier = Modifier.pointerInput(Unit) { detectTapGestures { onClose() } })
|
||||
fontFamily = FontFamily.Monospace, fontSize = 14.sp, modifier = Modifier.weight(1f))
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(14.dp)) {
|
||||
// Share this device's mapping as a .szm text file / take one in.
|
||||
Text("EXPORT", color = c.accent, fontFamily = FontFamily.Monospace, fontSize = 13.sp,
|
||||
modifier = Modifier.pointerInput(Unit) {
|
||||
detectTapGestures {
|
||||
vm.midiMapExportFile(slot.index)?.let { f ->
|
||||
val uri = FileProvider.getUriForFile(context, "${context.packageName}.fileprovider", f)
|
||||
val send = Intent(Intent.ACTION_SEND).apply {
|
||||
this.type = "text/plain"
|
||||
putExtra(Intent.EXTRA_STREAM, uri)
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
}
|
||||
context.startActivity(Intent.createChooser(send, "Share MIDI mapping"))
|
||||
}
|
||||
}
|
||||
})
|
||||
Text("IMPORT", color = c.accent, fontFamily = FontFamily.Monospace, fontSize = 13.sp,
|
||||
modifier = Modifier.pointerInput(Unit) { detectTapGestures { mapImporter.launch(arrayOf("*/*")) } })
|
||||
Text("DONE", color = c.textDim, fontFamily = FontFamily.Monospace, fontSize = 13.sp,
|
||||
modifier = Modifier.pointerInput(Unit) { detectTapGestures { onClose() } })
|
||||
}
|
||||
}
|
||||
Text(
|
||||
"Tap LEARN, then move a knob/fader on your MIDI controller.",
|
||||
@@ -465,6 +512,14 @@ private fun MidiLearnPopup(vm: AppViewModel, slot: ToolboxSlot, onClose: () -> U
|
||||
}
|
||||
}
|
||||
}
|
||||
importMessage?.let { msg ->
|
||||
AlertDialog(
|
||||
onDismissRequest = { importMessage = null },
|
||||
title = { Text("Import failed") },
|
||||
text = { Text(msg) },
|
||||
confirmButton = { TextButton(onClick = { importMessage = null }) { Text("OK") } },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -479,6 +534,7 @@ private fun MidiLearnPopup(vm: AppViewModel, slot: ToolboxSlot, onClose: () -> U
|
||||
private fun PresetBar(vm: AppViewModel, slot: ToolboxSlot) {
|
||||
val c = LocalRetro.current
|
||||
val context = LocalContext.current
|
||||
val haptics = LocalHapticFeedback.current
|
||||
@Suppress("UNUSED_VARIABLE") val rev = vm.revision // refresh the list after save/import
|
||||
val type = slot.type ?: return
|
||||
|
||||
@@ -536,6 +592,16 @@ private fun PresetBar(vm: AppViewModel, slot: ToolboxSlot) {
|
||||
RetroButton("DELETE", danger = true) { confirmDelete = current }
|
||||
Spacer(Modifier.width(20.dp))
|
||||
}
|
||||
// RANDOM only for the devices core/'s randomizer covers (the Synth, Morph
|
||||
// Pad, Grain Cloud, Wavetable and Ambience). It replaces the settings in
|
||||
// place, like loading a preset; the slot's own sample or table is kept.
|
||||
if (vm.canRandomize(type)) {
|
||||
RetroButton("RANDOM") {
|
||||
haptics.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
vm.randomizeSlot(slot)
|
||||
selected = null
|
||||
}
|
||||
}
|
||||
RetroButton("SAVE") { showSave = true }
|
||||
RetroButton("IMPORT") {
|
||||
// Accept text presets and (for the Sampler) zip bundles.
|
||||
|
||||
@@ -7,42 +7,99 @@ import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.RectangleShape
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import cc.tiredsysadmin.android.sizzle.model.ToolboxSlot
|
||||
import cc.tiredsysadmin.android.sizzle.ui.AppViewModel
|
||||
import cc.tiredsysadmin.android.sizzle.ui.components.RetroButton
|
||||
import cc.tiredsysadmin.android.sizzle.ui.theme.LocalRetro
|
||||
import cc.tiredsysadmin.android.sizzle.wavetable.WaveDefs
|
||||
import cc.tiredsysadmin.android.sizzle.wavetable.WaveTables
|
||||
|
||||
/**
|
||||
* The Wavetable's table strip: LOAD TABLE (a Serum / WaveEdit / power-of-two-frame
|
||||
* WAV becomes the "Custom" table) and a view of oscillator 1's table, every frame
|
||||
* stacked back to front with the one at its POSITION lit.
|
||||
/*
|
||||
* The Wavetable's own pieces inside its generic cards (see DeviceLayouts): each
|
||||
* oscillator card draws that oscillator's table ([WavetablePreview], via
|
||||
* [Viz.Wavetable]), and Oscillator 1's card carries LOAD TABLE ([LoadTableAction]),
|
||||
* because a loaded WAV becomes the "Custom" table and is selected on oscillator 1.
|
||||
*/
|
||||
|
||||
/** Every frame of oscillator [osc]'s table stacked back to front, the one at its POSITION lit. */
|
||||
@Composable
|
||||
fun WavetableEditor(vm: AppViewModel, slot: ToolboxSlot) {
|
||||
fun WavetablePreview(slot: ToolboxSlot, osc: Int, tone: Color, rev: Int) {
|
||||
// The factory tables are formulas, built on a worker, and only this drawing needs
|
||||
// the Kotlin copy — the engine builds its own in core/. So they are built when a
|
||||
// Wavetable editor is first opened, not at launch: an app that never shows one
|
||||
// pays nothing. Idempotent and non-blocking; `factory` returns null until ready
|
||||
// and the caption says "preparing…".
|
||||
LaunchedEffect(Unit) { WaveTables.prewarm() }
|
||||
val c = LocalRetro.current
|
||||
val name = slot.string("o${osc}table", WaveDefs.TABLES[0])
|
||||
val frame = slot.string("wtframe", WaveDefs.FRAME_SIZES[0]).toIntOrNull() ?: 0
|
||||
val table = if (name == WaveTables.CUSTOM) WaveTables.forSample(slot.string(WaveDefs.SAMPLE_KEY), frame) else WaveTables.factory(name)
|
||||
val pos = slot.float("o${osc}pos", 0f)
|
||||
val caption = if (table == null) "$name (preparing…)"
|
||||
else "${if (name == WaveTables.CUSTOM) "your table" else name} · ${table.frames} frames"
|
||||
|
||||
Box(Modifier.fillMaxWidth().height(72.dp).background(c.background).border(1.dp, c.grid, RectangleShape)) {
|
||||
if (table != null) {
|
||||
// 128 points of each frame's richest level, stacked; recomputed per table only
|
||||
val curves = remember(table) {
|
||||
val n = table.size(0); val step = maxOf(1, table.frames / 16)
|
||||
(0 until table.frames step step).map { f -> FloatArray(128) { i -> table.data[0][f * n + i * n / 128] } to f }
|
||||
}
|
||||
val lit = (pos * (table.frames - 1) + 0.5f).toInt()
|
||||
Canvas(Modifier.fillMaxWidth().height(72.dp)) {
|
||||
if (rev < 0) return@Canvas // capture the revision so the drawing follows edits
|
||||
val k = curves.size
|
||||
val rowH = size.height * 0.45f
|
||||
for ((idx, cf) in curves.withIndex().reversed()) {
|
||||
val (pts, f) = cf
|
||||
val depth = if (k > 1) idx.toFloat() / (k - 1) else 0f
|
||||
val x0 = size.width * 0.04f + depth * size.width * 0.18f
|
||||
val w = size.width * 0.76f
|
||||
val yMid = size.height * 0.72f - depth * size.height * 0.45f
|
||||
val near = kotlin.math.abs(f - lit) * 2 <= maxOf(1, table.frames / curves.size)
|
||||
val col = if (near) tone else c.text.copy(alpha = 0.25f)
|
||||
for (i in 1 until pts.size) {
|
||||
drawLine(col,
|
||||
Offset(x0 + w * (i - 1) / pts.size, yMid - pts[i - 1] * rowH * 0.5f),
|
||||
Offset(x0 + w * i / pts.size, yMid - pts[i] * rowH * 0.5f),
|
||||
strokeWidth = if (near) 2f else 1f)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Text(caption, color = c.textDim, fontFamily = FontFamily.Monospace, fontSize = 9.sp,
|
||||
modifier = Modifier.padding(horizontal = 4.dp, vertical = 2.dp))
|
||||
}
|
||||
}
|
||||
|
||||
/** LOAD TABLE in Oscillator 1's title: a Serum / WaveEdit / power-of-two-frame WAV
|
||||
* becomes the "Custom" table and is selected on oscillator 1. */
|
||||
@Composable
|
||||
fun LoadTableAction(vm: AppViewModel, slot: ToolboxSlot) {
|
||||
val c = LocalRetro.current
|
||||
val context = LocalContext.current
|
||||
@Suppress("UNUSED_VARIABLE") val rev = vm.revision
|
||||
|
||||
var importError by remember(slot.index) { mutableStateOf<String?>(null) }
|
||||
val picker = rememberLauncherForActivityResult(ActivityResultContracts.OpenDocument()) { uri ->
|
||||
if (uri == null) return@rememberLauncherForActivityResult
|
||||
@@ -54,47 +111,13 @@ fun WavetableEditor(vm: AppViewModel, slot: ToolboxSlot) {
|
||||
"Couldn't load this wavetable. Use an uncompressed .wav (Serum, WaveEdit, or frames of 256–2048 samples)."
|
||||
}
|
||||
}
|
||||
|
||||
val name = slot.string("o1table", WaveDefs.TABLES[0])
|
||||
val frame = slot.string("wtframe", WaveDefs.FRAME_SIZES[0]).toIntOrNull() ?: 0
|
||||
val table = if (name == WaveTables.CUSTOM) WaveTables.forSample(slot.string(WaveDefs.SAMPLE_KEY), frame) else WaveTables.factory(name)
|
||||
val pos = slot.float("o1pos", 0f)
|
||||
|
||||
Column(Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
RetroButton("LOAD TABLE") { picker.launch(arrayOf("*/*")) }
|
||||
Text(
|
||||
if (table == null) "Osc 1: $name (preparing…)" else "Osc 1: ${if (name == WaveTables.CUSTOM) "your table" else name} · ${table.frames} frames",
|
||||
color = c.textDim, fontFamily = FontFamily.Monospace, fontSize = 10.sp,
|
||||
)
|
||||
if (table != null) {
|
||||
// 128 points of each frame's richest level, stacked; recomputed per table only
|
||||
val curves = remember(table) {
|
||||
val n = table.size(0); val step = maxOf(1, table.frames / 16)
|
||||
(0 until table.frames step step).map { f -> FloatArray(128) { i -> table.data[0][f * n + i * n / 128] } to f }
|
||||
}
|
||||
val lit = (pos * (table.frames - 1) + 0.5f).toInt()
|
||||
Canvas(Modifier.fillMaxWidth().height(110.dp).background(c.surface)) {
|
||||
val k = curves.size
|
||||
val rowH = size.height * 0.45f
|
||||
for ((idx, cf) in curves.withIndex().reversed()) {
|
||||
val (pts, f) = cf
|
||||
val depth = if (k > 1) idx.toFloat() / (k - 1) else 0f
|
||||
val x0 = size.width * 0.04f + depth * size.width * 0.18f
|
||||
val w = size.width * 0.76f
|
||||
val yMid = size.height * 0.72f - depth * size.height * 0.45f
|
||||
val near = kotlin.math.abs(f - lit) * 2 <= maxOf(1, table.frames / curves.size)
|
||||
val col = if (near) c.accent else c.text.copy(alpha = 0.25f)
|
||||
for (i in 1 until pts.size) {
|
||||
drawLine(col,
|
||||
Offset(x0 + w * (i - 1) / pts.size, yMid - pts[i - 1] * rowH * 0.5f),
|
||||
Offset(x0 + w * i / pts.size, yMid - pts[i] * rowH * 0.5f),
|
||||
strokeWidth = if (near) 2f else 1f)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Text(
|
||||
"+ LOAD TABLE", color = c.accent, fontFamily = FontFamily.Monospace, fontSize = 11.sp,
|
||||
modifier = Modifier
|
||||
.border(1.dp, c.accent.copy(alpha = 0.6f), RectangleShape)
|
||||
.clickable { picker.launch(arrayOf("*/*")) }
|
||||
.padding(horizontal = 8.dp, vertical = 3.dp),
|
||||
)
|
||||
importError?.let { msg ->
|
||||
AlertDialog(
|
||||
onDismissRequest = { importError = null },
|
||||
|
||||
+6
@@ -1,6 +1,12 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// The Kotlin reference the C++ port in core/ is checked against (handover §5.4.2):
|
||||
// the IosGolden* tests render it, and `make -C ios core-test` compares the C++ with
|
||||
// that audio sample by sample. It lives in the TEST source set because both apps
|
||||
// play core/ — in src/main it would only be dead code in the APK. Keep it in step
|
||||
// with core/src/fx/AmbienceReverb.cpp.
|
||||
|
||||
package cc.tiredsysadmin.android.sizzle.audio
|
||||
|
||||
import cc.tiredsysadmin.android.sizzle.model.AmbiencePresets
|
||||
@@ -14,7 +14,7 @@ import org.junit.Test
|
||||
*/
|
||||
class ChannelArpTest {
|
||||
|
||||
private fun arp() = AudioEngine.ChannelArp()
|
||||
private fun arp() = ReferenceEngine.ChannelArp()
|
||||
|
||||
/** The Up sequence over a chord × octaves is octave-major over the sorted notes. */
|
||||
@Test fun upCyclesWholeChordAcrossOctaves() {
|
||||
|
||||
@@ -22,7 +22,7 @@ class ClockRecordingTest {
|
||||
private val fs = 48_000
|
||||
private val block = 192
|
||||
|
||||
private fun engine(dir: File, tailBars: Int, done: (File) -> Unit) = AudioEngine(fs).apply {
|
||||
private fun engine(dir: File, tailBars: Int, done: (File) -> Unit) = ReferenceEngine(fs).apply {
|
||||
setProject(Project().apply { tempoBpm = 120f })
|
||||
recTempDir = dir
|
||||
onRecordingComplete = { f, _ ->
|
||||
@@ -33,7 +33,7 @@ class ClockRecordingTest {
|
||||
|
||||
/** Render [frames], paced (about 10x real time) so the recorder's writer thread
|
||||
* keeps up with its one-second ring, as it does on a device. */
|
||||
private fun AudioEngine.run(frames: Int) {
|
||||
private fun ReferenceEngine.run(frames: Int) {
|
||||
val out = FloatArray(block * 2)
|
||||
repeat(frames / block) { i -> fillBlock(out, block); if (i % 25 == 24) Thread.sleep(10) }
|
||||
}
|
||||
|
||||
+6
@@ -1,6 +1,12 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// The Kotlin reference the C++ port in core/ is checked against (handover §5.4.2):
|
||||
// the IosGolden* tests render it, and `make -C ios core-test` compares the C++ with
|
||||
// that audio sample by sample. It lives in the TEST source set because both apps
|
||||
// play core/ — in src/main it would only be dead code in the APK. Keep it in step
|
||||
// with core/src/fx/.
|
||||
|
||||
package cc.tiredsysadmin.android.sizzle.audio
|
||||
|
||||
import cc.tiredsysadmin.android.sizzle.model.DelayDivisions
|
||||
@@ -0,0 +1,228 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package cc.tiredsysadmin.android.sizzle.audio
|
||||
|
||||
import cc.tiredsysadmin.android.sizzle.echofield.EchofieldDefs
|
||||
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs
|
||||
import cc.tiredsysadmin.android.sizzle.model.AmbiencePresets
|
||||
import cc.tiredsysadmin.android.sizzle.model.DelayDivisions
|
||||
import cc.tiredsysadmin.android.sizzle.model.TimeDivision
|
||||
import cc.tiredsysadmin.android.sizzle.ui.toolbox.DeviceLayouts
|
||||
import cc.tiredsysadmin.android.sizzle.ui.toolbox.Viz
|
||||
import cc.tiredsysadmin.android.sizzle.model.MixTightenerPresets
|
||||
import cc.tiredsysadmin.android.sizzle.model.NesSynthPresets
|
||||
import cc.tiredsysadmin.android.sizzle.wavetable.WaveDefs
|
||||
import cc.tiredsysadmin.android.sizzle.model.ToolboxKind
|
||||
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.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
import kotlin.math.PI
|
||||
import kotlin.math.exp
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.math.sin
|
||||
|
||||
/**
|
||||
* Feeds the shared C++ engine (core/): the Kotlin DSP is the reference the C++ port must
|
||||
* reproduce. Runs only when SIZZLE_GOLDEN_DIR is set (`make -C ios golden`), so the
|
||||
* normal `make check` skips it. Writes:
|
||||
*
|
||||
* - `core/include/sizzle/DeviceSpecs.gen.hpp` (SIZZLE_SPECS_OUT): every
|
||||
* device's parameters and the Mix Tightener presets, so iOS shares one definition;
|
||||
* - into SIZZLE_GOLDEN_DIR: `input.f32` (a fixed test signal) and, per audio
|
||||
* effect and scenario, `<TYPE>__<scenario>.scn` (its parameters) and
|
||||
* `<TYPE>__<scenario>.f32` (the Kotlin output), all raw little-endian float32.
|
||||
*/
|
||||
class IosGoldenExport {
|
||||
|
||||
@Test fun export() {
|
||||
val dir = System.getenv("SIZZLE_GOLDEN_DIR")
|
||||
assumeTrue("set SIZZLE_GOLDEN_DIR to export", dir != null)
|
||||
val out = File(dir!!).apply { mkdirs() }
|
||||
System.getenv("SIZZLE_SPECS_OUT")?.let { File(it).writeText(specsHeader()) }
|
||||
System.getenv("SIZZLE_LAYOUTS_OUT")?.let { File(it).writeText(layoutsJson()) }
|
||||
|
||||
val input = testSignal()
|
||||
writeF32(File(out, "input.f32"), input)
|
||||
|
||||
for (type in ToolboxType.entries) {
|
||||
if (AudioEffect.create(type, SR) == null) continue
|
||||
for ((name, values) in scenarios(type)) {
|
||||
val slot = ToolboxSlot(0).apply { fill(type) }
|
||||
values.forEach { (k, v) -> slot.set(k, v) }
|
||||
val fx = AudioEffect.create(type, SR)!!
|
||||
fx.update(slot, TEMPO)
|
||||
val y = FloatArray(input.size) { fx.process(input[it]) }
|
||||
val base = "${type.name}__$name"
|
||||
File(out, "$base.scn").writeText(buildString {
|
||||
append("type ${type.name}\nsr $SR\ntempo $TEMPO\n")
|
||||
// Every value the effect can read, in the slot's own string form.
|
||||
slot.values.toSortedMap().forEach { (k, v) -> append("p $k $v\n") }
|
||||
})
|
||||
writeF32(File(out, "$base.f32"), y)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Defaults, then two variants that move every listed parameter (enums to
|
||||
* other choices), so each control's code path is exercised. The Mix Tightener
|
||||
* hides its real settings in presets, so it uses two factory presets instead. */
|
||||
private fun scenarios(type: ToolboxType): List<Pair<String, Map<String, String>>> {
|
||||
if (type == ToolboxType.MIX_TIGHTENER) {
|
||||
return listOf("default" to emptyMap<String, String>()) +
|
||||
MixTightenerPresets.FACTORY.take(3).mapIndexed { i, p -> "preset$i" to p.params }
|
||||
}
|
||||
fun variant(frac: Float, choice: (Int) -> Int) = type.params.associate { s ->
|
||||
s.key to if (s.isEnum) s.choices[choice(s.choices.size)]
|
||||
else (s.min + frac * (s.max - s.min)).let { if (s.isInt) it.roundToInt().toFloat() else it }.toString()
|
||||
}
|
||||
return listOf(
|
||||
"default" to emptyMap(),
|
||||
"high" to variant(0.75f) { n -> n - 1 },
|
||||
"low" to variant(0.25f) { n -> minOf(1, n - 1) },
|
||||
)
|
||||
}
|
||||
|
||||
/** 1.5 s: a decaying saw burst, silence, LCG noise, silence, a sine sweep, then
|
||||
* silence for tails. Exercises gates, envelopes, filters and feedback paths. */
|
||||
private fun testSignal(): FloatArray {
|
||||
val n = (SR * 1.5).toInt()
|
||||
var seed = 0x1234567
|
||||
var sweepPhase = 0.0
|
||||
return FloatArray(n) { i ->
|
||||
val t = i.toDouble() / SR
|
||||
when {
|
||||
t < 0.25 -> (0.6 * (2 * ((t * 110) % 1.0) - 1) * exp(-t * 6)).toFloat()
|
||||
t < 0.40 -> 0f
|
||||
t < 0.70 -> { seed = seed * 1103515245 + 12345; ((seed ushr 8) and 0xFFFF) / 65535f * 0.6f - 0.3f }
|
||||
t < 0.90 -> 0f
|
||||
t < 1.20 -> {
|
||||
val f = 100 * Math.pow(50.0, (t - 0.9) / 0.3)
|
||||
sweepPhase += 2 * PI * f / SR
|
||||
(0.5 * sin(sweepPhase)).toFloat()
|
||||
}
|
||||
else -> 0f
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun writeF32(f: File, x: FloatArray) {
|
||||
val bb = ByteBuffer.allocate(x.size * 4).order(ByteOrder.LITTLE_ENDIAN)
|
||||
x.forEach { bb.putFloat(it) }
|
||||
f.writeBytes(bb.array())
|
||||
}
|
||||
|
||||
private fun cstr(s: String) = "\"" + s.replace("\\", "\\\\").replace("\"", "\\\"") + "\""
|
||||
|
||||
private fun specsHeader(): String = buildString {
|
||||
append("// GENERATED by IosGoldenExport (make -C ios golden). Do not edit.\n")
|
||||
append("// Every Sizzle device's parameters, from ToolboxType in the Android app.\n")
|
||||
append("#pragma once\n#include \"sizzle/Specs.hpp\"\n\nnamespace sizzle::gen {\n\n")
|
||||
for (t in ToolboxType.entries) {
|
||||
t.params.forEachIndexed { i, s ->
|
||||
if (s.isEnum) append("inline const char *const ${t.name}_c$i[] = {${s.choices.joinToString(", ") { cstr(it) }}, nullptr};\n")
|
||||
}
|
||||
if (t.params.isEmpty()) { append("inline const ParamSpec *const ${t.name}_params = nullptr;\n\n"); continue }
|
||||
append("inline const ParamSpec ${t.name}_params[] = {\n")
|
||||
t.params.forEachIndexed { i, s ->
|
||||
append(" {${cstr(s.key)}, ${cstr(s.label)}, ${s.default}f, ${s.min}f, ${s.max}f, ${s.isInt}, ")
|
||||
append(if (s.isEnum) "${t.name}_c$i" else "nullptr").append("},\n")
|
||||
}
|
||||
append("};\n\n")
|
||||
}
|
||||
append("inline const DeviceSpec devices[] = {\n")
|
||||
for (t in ToolboxType.entries) {
|
||||
val kind = if (t.kind == ToolboxKind.INSTRUMENT) "Kind::Instrument" else "Kind::Effect"
|
||||
append(" {${cstr(t.name)}, ${cstr(t.displayName)}, $kind, ${t.name}_params, ${t.params.size}},\n")
|
||||
}
|
||||
append("};\ninline constexpr int deviceCount = ${ToolboxType.entries.size};\n\n")
|
||||
append("// Mix Tightener factory presets: name, then key/value pairs, nullptr-terminated.\n")
|
||||
MixTightenerPresets.FACTORY.forEachIndexed { i, p ->
|
||||
append("inline const char *const mixTightener$i[] = {${cstr(p.name)}, ")
|
||||
p.params.toSortedMap().forEach { (k, v) -> append("${cstr(k)}, ${cstr(v)}, ") }
|
||||
append("nullptr};\n")
|
||||
}
|
||||
append("inline const char *const *const mixTightenerPresets[] = {")
|
||||
append(MixTightenerPresets.FACTORY.indices.joinToString(", ") { "mixTightener$it" })
|
||||
append(", nullptr};\n\n")
|
||||
|
||||
// Every device's factory presets, as PresetLibrary.seedFactoryPresets writes
|
||||
// them: a fresh slot with the preset applied, every key as text.
|
||||
append("// Factory presets (PresetLibrary.seedFactoryPresets): device, name, then the\n")
|
||||
append("// slot's full settings as key/value pairs, nullptr-terminated.\n")
|
||||
val all = factoryPresets()
|
||||
all.forEachIndexed { i, (type, name, values) ->
|
||||
append("inline const char *const factory$i[] = {")
|
||||
values.toSortedMap().forEach { (k, v) -> append("${cstr(k)}, ${cstr(v)}, ") }
|
||||
append("nullptr};\n")
|
||||
}
|
||||
append("inline const FactoryPreset factoryPresets[] = {\n")
|
||||
all.forEachIndexed { i, (type, name, _) -> append(" {${cstr(type)}, ${cstr(name)}, factory$i},\n") }
|
||||
append("};\ninline constexpr int factoryPresetCount = ${all.size};\n\n} // namespace sizzle::gen\n")
|
||||
}
|
||||
|
||||
private fun js(x: String) = "\"" + x.replace("\\", "\\\\").replace("\"", "\\\"") + "\""
|
||||
|
||||
/** Android's card layouts (DeviceLayouts.pagesFor) for every device, as JSON for
|
||||
* the iOS editor, plus the value names some knobs show. A device with a bespoke
|
||||
* Android editor comes out as Android's fallback (one card); iOS lays those out
|
||||
* itself (ios/app/FX/Editor/BespokeLayouts.swift). */
|
||||
private fun layoutsJson(): String = buildString {
|
||||
append("{\n \"devices\": {\n")
|
||||
ToolboxType.entries.forEachIndexed { ti, t ->
|
||||
append(" ${js(t.name)}: [")
|
||||
DeviceLayouts.pagesFor(t).forEachIndexed { pi, page ->
|
||||
if (pi > 0) append(",")
|
||||
append("\n {\"title\": ${js(page.title)}, \"panels\": [")
|
||||
page.panels.forEachIndexed { ki, p ->
|
||||
if (ki > 0) append(",")
|
||||
append("\n {\"title\": ${js(p.title)}, \"tone\": ${js(p.tone.name)}, ")
|
||||
append("\"keys\": [${p.keys.joinToString(", ") { js(it) }}]")
|
||||
when (val v = p.viz) {
|
||||
is Viz.Envelope -> append(", \"viz\": {\"kind\": \"envelope\", \"a\": ${js(v.a)}" +
|
||||
(v.d?.let { ", \"d\": ${js(it)}" } ?: "") + (v.s?.let { ", \"s\": ${js(it)}" } ?: "") + ", \"r\": ${js(v.r)}}")
|
||||
is Viz.Filter -> append(", \"viz\": {\"kind\": \"filter\"" + (v.type?.let { ", \"type\": ${js(it)}" } ?: "") +
|
||||
", \"cutoff\": ${js(v.cutoff)}, \"reso\": ${js(v.reso)}}")
|
||||
is Viz.Lfo -> append(", \"viz\": {\"kind\": \"lfo\", \"wave\": ${js(v.wave)}}")
|
||||
is Viz.Wavetable -> append(", \"viz\": {\"kind\": \"wavetable\", \"osc\": ${v.osc}}")
|
||||
null -> {}
|
||||
}
|
||||
if (p.labels.isNotEmpty()) append(", \"labels\": {${p.labels.entries.joinToString(", ") { "${js(it.key)}: ${js(it.value)}" }}}")
|
||||
p.faders?.let { append(", \"faders\": [${it.joinToString(", ") { f -> js(f) }}], \"faderScale\": ${p.faderScale}") }
|
||||
if (p.action != null) append(", \"action\": \"loadTable\"")
|
||||
append("}")
|
||||
}
|
||||
append("]}")
|
||||
}
|
||||
append("\n ]").append(if (ti < ToolboxType.entries.size - 1) ",\n" else "\n")
|
||||
}
|
||||
append(" },\n")
|
||||
append(" \"timeDivisions\": [${TimeDivision.entries.joinToString(", ") { js(it.label) }}],\n")
|
||||
append(" \"delayDivisions\": [${DelayDivisions.entries.joinToString(", ") { js(it.first) }}]\n}\n")
|
||||
}
|
||||
|
||||
private fun factoryPresets(): List<Triple<String, String, Map<String, String>>> {
|
||||
val out = mutableListOf<Triple<String, String, Map<String, String>>>()
|
||||
fun add(type: ToolboxType, name: String, apply: (ToolboxSlot) -> Unit) {
|
||||
val slot = ToolboxSlot(0).apply { fill(type) }
|
||||
apply(slot)
|
||||
out += Triple(type.name, name, slot.values.toMap())
|
||||
}
|
||||
AmbiencePresets.FACTORY.forEach { p -> add(ToolboxType.AMBIENCE, p.name) { AmbiencePresets.apply(it, p) } }
|
||||
NesSynthPresets.FACTORY.forEach { p -> add(ToolboxType.NES_SYNTH, p.name) { NesSynthPresets.apply(it, p) } }
|
||||
FrasilDefs.FACTORY.forEach { p -> add(ToolboxType.MORPH_PAD, p.name) { s -> p.values.forEach { (k, v) -> s.set(k, v) } } }
|
||||
EchofieldDefs.FACTORY.forEach { p -> add(ToolboxType.GRAIN_CLOUD, p.name) { s -> p.values.forEach { (k, v) -> s.set(k, v) } } }
|
||||
WaveDefs.FACTORY.forEach { p -> add(ToolboxType.WAVETABLE, p.name) { s -> p.values.forEach { (k, v) -> s.set(k, v) } } }
|
||||
MixTightenerPresets.FACTORY.forEach { p -> add(ToolboxType.MIX_TIGHTENER, p.name) { MixTightenerPresets.apply(it, p) } }
|
||||
return out
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val SR = 48_000
|
||||
const val TEMPO = 120f
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package cc.tiredsysadmin.android.sizzle.audio
|
||||
|
||||
import cc.tiredsysadmin.android.sizzle.echofield.EchofieldDefs
|
||||
import cc.tiredsysadmin.android.sizzle.echofield.GrainCloud
|
||||
import cc.tiredsysadmin.android.sizzle.echofield.GrainPatch
|
||||
import cc.tiredsysadmin.android.sizzle.frasil.FrasilClock
|
||||
import cc.tiredsysadmin.android.sizzle.frasil.FrasilPatch
|
||||
import cc.tiredsysadmin.android.sizzle.frasil.FrasilVoice
|
||||
import cc.tiredsysadmin.android.sizzle.model.SamplerPads
|
||||
import cc.tiredsysadmin.android.sizzle.model.ToolboxSlot
|
||||
import cc.tiredsysadmin.android.sizzle.model.ToolboxType
|
||||
import cc.tiredsysadmin.android.sizzle.wavetable.WavePatch
|
||||
import cc.tiredsysadmin.android.sizzle.wavetable.WaveTables
|
||||
import cc.tiredsysadmin.android.sizzle.wavetable.WaveVoice
|
||||
import org.junit.Assume.assumeTrue
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* Reference renders of the instrument voices for the iOS port (see ios/PORTING.md),
|
||||
* next to IosGoldenExport's effects. Runs only when SIZZLE_GOLDEN_DIR is set.
|
||||
*
|
||||
* Each scenario plays a fixed note script through one voice, the way AudioEngine
|
||||
* drives it: the patch is built from the slot exactly as the engine does
|
||||
* (patchForSlot / GrainPatch.from), and the Morph Pad's shared FrasilClock advances
|
||||
* once per 256-frame block before the block renders. Files, in SIZZLE_GOLDEN_DIR:
|
||||
*
|
||||
* <KIND>_<TYPE>__<variant>.scn kind, type, sr, tempo, block, the FrasilClock start
|
||||
* ("clock"), the slot's values ("p"), the note
|
||||
* script ("on <frame> <midi> <vel>", "off <frame> <midi>")
|
||||
* and the length ("frames")
|
||||
* <KIND>_<TYPE>__<variant>.f32 the output, raw little-endian float32
|
||||
* TABLE__<name>.scn / .f32 each factory wavetable's data, all mip levels
|
||||
* concatenated (checks the table generators)
|
||||
*
|
||||
* The Morph Pad and Grain Cloud seed each new voice from a private global counter;
|
||||
* "seeds <frasil> <grain>" records both counters right before the scenario builds
|
||||
* its voices (render() builds a SynthVoice, whose FrasilVoice takes the next
|
||||
* Frasil seed, then a FrasilVoice, then a GrainCloud).
|
||||
*
|
||||
* Kinds: SYNTH = SynthVoice with the engine's patch (Synth, Morph Pad, Wavetable);
|
||||
* FRASIL = FrasilVoice alone; WAVE = WaveVoice alone; GRAIN = GrainCloud;
|
||||
* SAMPLE = SampleVoice with the engine's voiceSample() settings (Sampler pads 0 and
|
||||
* 7, SF2/XI loader). SAMPLE scenarios also write the test sample as
|
||||
* <base>.smp.f32 and a line "sample <rate> <loopStart> <loopEnd>".
|
||||
*/
|
||||
class IosGoldenInstruments {
|
||||
|
||||
private data class Ev(val frame: Int, val on: Boolean, val midi: Int, val vel: Int)
|
||||
|
||||
/** Two notes: the second starts after the first's release has begun, so both
|
||||
* attack, release and retrigger paths run. GRAIN adds an overlapping third. */
|
||||
private fun script(kind: String): List<Ev> {
|
||||
if (kind == "SAMPLE") return listOf( // Sampler pads 0 and 7 (C2, G2); SF2 plays any note
|
||||
Ev(0, true, 36, 100), Ev(at(0.35), false, 36, 0),
|
||||
Ev(at(0.50), true, 43, 64), Ev(at(0.90), false, 43, 0),
|
||||
)
|
||||
val s = mutableListOf(
|
||||
Ev(0, true, 60, 100), Ev(at(0.35), false, 60, 0),
|
||||
Ev(at(0.50), true, 67, 64), Ev(at(0.90), false, 67, 0),
|
||||
)
|
||||
if (kind == "GRAIN") { s += Ev(at(0.10), true, 64, 90); s += Ev(at(0.60), false, 64, 0) }
|
||||
return s.sortedBy { it.frame }
|
||||
}
|
||||
|
||||
private fun at(seconds: Double) = (seconds * SR).roundToInt()
|
||||
|
||||
@Test fun export() {
|
||||
val dir = System.getenv("SIZZLE_GOLDEN_DIR")
|
||||
assumeTrue("set SIZZLE_GOLDEN_DIR to export", dir != null)
|
||||
val out = File(dir!!).apply { mkdirs() }
|
||||
WaveTables.prewarmBlocking()
|
||||
GrainSources.prewarmBlocking()
|
||||
exportTables(out)
|
||||
|
||||
val kinds = listOf(
|
||||
"SYNTH" to ToolboxType.NES_SYNTH, "SYNTH" to ToolboxType.MORPH_PAD, "SYNTH" to ToolboxType.WAVETABLE,
|
||||
"FRASIL" to ToolboxType.MORPH_PAD, "WAVE" to ToolboxType.WAVETABLE, "GRAIN" to ToolboxType.GRAIN_CLOUD,
|
||||
"SAMPLE" to ToolboxType.SAMPLER, "SAMPLE" to ToolboxType.SOUNDFONT,
|
||||
)
|
||||
// 0.6 s at 44.1 kHz (so playback resamples): a decaying saw plus a little
|
||||
// noise; loop points for the SF2 path.
|
||||
var seed = 0x2468ACE
|
||||
val smp = SampleStore.Sample(FloatArray(26_460) { i ->
|
||||
seed = seed * 1103515245 + 12345
|
||||
val t = i / 44_100.0
|
||||
(0.7 * (2 * ((t * 220) % 1.0) - 1) * kotlin.math.exp(-t * 3)).toFloat() +
|
||||
((seed ushr 8) and 0xFFFF) / 65535f * 0.05f - 0.025f
|
||||
}, 44_100, loopStart = 8_000, loopEnd = 20_000)
|
||||
SampleStore.put(SAMPLE_ID, smp)
|
||||
for ((kind, type) in kinds) for ((variant, values) in variants(type)) {
|
||||
val slot = ToolboxSlot(0).apply { fill(type) }
|
||||
values.forEach { (k, v) -> slot.set(k, v) }
|
||||
if (kind == "SAMPLE") sampleSlot(type, variant, slot)
|
||||
val events = script(kind)
|
||||
val clock0 = FrasilClock.seconds
|
||||
val seeds = "${counter(FrasilVoice::class.java)} ${counter(GrainCloud::class.java)}"
|
||||
val y = render(kind, type, slot, events)
|
||||
val base = "${kind}_${type.name}__$variant"
|
||||
File(out, "$base.scn").writeText(buildString {
|
||||
append("kind $kind\ntype ${type.name}\nsr $SR\ntempo $TEMPO\nblock $BLOCK\n")
|
||||
append("clock ${java.lang.Double.toString(clock0)}\nframes $FRAMES\nseeds $seeds\n")
|
||||
slot.values.toSortedMap().forEach { (k, v) -> append("p $k $v\n") }
|
||||
if (kind == "SAMPLE") append("sample ${smp.sampleRate} ${smp.loopStart} ${smp.loopEnd}\n")
|
||||
events.forEach { e -> append(if (e.on) "on ${e.frame} ${e.midi} ${e.vel}\n" else "off ${e.frame} ${e.midi}\n") }
|
||||
})
|
||||
val bb = ByteBuffer.allocate(y.size * 4).order(ByteOrder.LITTLE_ENDIAN)
|
||||
y.forEach { bb.putFloat(it) }
|
||||
File(out, "$base.f32").writeBytes(bb.array())
|
||||
if (kind == "SAMPLE") {
|
||||
val sb = ByteBuffer.allocate(smp.data.size * 4).order(ByteOrder.LITTLE_ENDIAN)
|
||||
smp.data.forEach { sb.putFloat(it) }
|
||||
File(out, "$base.smp.f32").writeBytes(sb.array())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The private `seeds` counter a voice class takes its next seed from. */
|
||||
private fun counter(c: Class<*>): Int {
|
||||
val f = runCatching { c.getDeclaredField("seeds") }.getOrElse {
|
||||
Class.forName(c.name + "\$Companion").getDeclaredField("seeds")
|
||||
}
|
||||
f.isAccessible = true
|
||||
return f.getInt(null)
|
||||
}
|
||||
|
||||
private fun exportTables(out: File) {
|
||||
for (name in WaveTables.FACTORY_NAMES) {
|
||||
val t = WaveTables.factory(name)!!
|
||||
val all = (0 until t.data.size).flatMap { t.data[it].asList() }
|
||||
val bb = ByteBuffer.allocate(all.size * 4).order(ByteOrder.LITTLE_ENDIAN)
|
||||
all.forEach { bb.putFloat(it) }
|
||||
val base = "TABLE__" + name.replace(Regex("[^A-Za-z0-9]"), "_")
|
||||
File(out, "$base.scn").writeText("kind TABLE\ntype WAVETABLE\ntable $name\n")
|
||||
File(out, "$base.f32").writeBytes(bb.array())
|
||||
}
|
||||
}
|
||||
|
||||
/** Point the slot at the test sample: Sampler pads 0 and 7 with per-variant
|
||||
* slices and volumes, or the SF2/XI loader's sample with root note 60. */
|
||||
private fun sampleSlot(type: ToolboxType, variant: String, slot: ToolboxSlot) {
|
||||
if (type == ToolboxType.SOUNDFONT) {
|
||||
slot.set("sfSample", SAMPLE_ID); slot.set("sfRoot", 60f)
|
||||
return
|
||||
}
|
||||
for (pad in listOf(0, 7)) {
|
||||
slot.set(SamplerPads.key(pad), SAMPLE_ID)
|
||||
when (variant) {
|
||||
"high" -> { slot.set(SamplerPads.sliceStartKey(pad), 0.1f); slot.set(SamplerPads.sliceEndKey(pad), 0.8f); slot.set(SamplerPads.volumeKey(pad), 1f) }
|
||||
"low" -> { slot.set(SamplerPads.sliceStartKey(pad), 0.7f); slot.set(SamplerPads.sliceEndKey(pad), 0.2f); slot.set(SamplerPads.volumeKey(pad), 0.3f) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The engine's voiceSample(): which sample a note plays and how. */
|
||||
private fun sampleNoteOn(v: SampleVoice, slot: ToolboxSlot, type: ToolboxType, note: Int, velocity: Int) {
|
||||
if (type == ToolboxType.SAMPLER) {
|
||||
val pad = SamplerPads.padFor(note)
|
||||
if (pad !in 0 until SamplerPads.COUNT) return
|
||||
val s = SampleStore.get(slot.string(SamplerPads.key(pad))) ?: return
|
||||
v.noteOn(s, note, velocity, note, slot.float(SamplerPads.sliceStartKey(pad), 0f),
|
||||
slot.float(SamplerPads.sliceEndKey(pad), 1f), slot.float(SamplerPads.volumeKey(pad), SamplerPads.DEFAULT_VOLUME))
|
||||
v.oneShot = slot.string("oneShot", "Off") == "On"
|
||||
} else {
|
||||
val s = SampleStore.get(slot.string("sfSample")) ?: return
|
||||
v.noteOn(s, note, velocity, slot.float("sfRoot", 60f).toInt(), 0f, 1f, slot.float("volume", 0.8f),
|
||||
slot.float("attack", 0.005f), slot.float("decay", 0.10f), slot.float("sustain", 1f),
|
||||
slot.float("release", 0.20f), slot.string("loop", "Off") == "On", slot.float("loopXfade", 0f))
|
||||
}
|
||||
}
|
||||
|
||||
private fun render(kind: String, type: ToolboxType, slot: ToolboxSlot, events: List<Ev>): FloatArray {
|
||||
val synth = SynthVoice(SR)
|
||||
val frasil = FrasilVoice(SR)
|
||||
val wave = WaveVoice(SR)
|
||||
val cloud = GrainCloud(SR)
|
||||
val sampler = SampleVoice(SR)
|
||||
val synthPatch = when (type) {
|
||||
ToolboxType.NES_SYNTH -> SynthPatch.from(slot, TEMPO)
|
||||
ToolboxType.MORPH_PAD -> SynthPatch.forPad(FrasilPatch.from(slot))
|
||||
ToolboxType.WAVETABLE -> SynthPatch.forWave(WavePatch.from(slot, TEMPO))
|
||||
else -> SynthPatch.DEFAULT
|
||||
}
|
||||
val frasilPatch = if (type == ToolboxType.MORPH_PAD) FrasilPatch.from(slot) else null
|
||||
val wavePatch = if (type == ToolboxType.WAVETABLE) WavePatch.from(slot, TEMPO) else null
|
||||
if (kind == "GRAIN") cloud.setPatch(GrainPatch.from(slot, TEMPO))
|
||||
|
||||
val y = FloatArray(FRAMES)
|
||||
var next = 0
|
||||
for (i in 0 until FRAMES) {
|
||||
if (i % BLOCK == 0) FrasilClock.advance(BLOCK, SR)
|
||||
while (next < events.size && events[next].frame == i) {
|
||||
val e = events[next++]
|
||||
when (kind) {
|
||||
"SYNTH" -> if (e.on) synth.noteOn(e.midi, e.vel, synthPatch) else synth.noteOff()
|
||||
"FRASIL" -> if (e.on) frasil.noteOn(e.midi, e.vel / 127f, frasilPatch!!) else frasil.noteOff()
|
||||
"WAVE" -> if (e.on) wave.noteOn(e.midi, e.vel / 127f, wavePatch!!) else wave.noteOff()
|
||||
"GRAIN" -> if (e.on) cloud.noteOn(e.midi, e.vel, GrainCloud.OWNER_LIVE) else cloud.noteOff(e.midi)
|
||||
"SAMPLE" -> if (e.on) sampleNoteOn(sampler, slot, type, e.midi, e.vel) else sampler.noteOff()
|
||||
}
|
||||
}
|
||||
y[i] = when (kind) {
|
||||
"SYNTH" -> synth.render()
|
||||
"FRASIL" -> frasil.render()
|
||||
"WAVE" -> wave.render()
|
||||
"SAMPLE" -> sampler.render()
|
||||
else -> cloud.render()
|
||||
}
|
||||
}
|
||||
return y
|
||||
}
|
||||
|
||||
/** Defaults, then every listed parameter at 75 % / 25 % of its range (enums at
|
||||
* other choices, never "Custom", which needs a user sample). */
|
||||
private fun variants(type: ToolboxType): List<Pair<String, Map<String, String>>> {
|
||||
fun variant(frac: Float, choice: (List<String>) -> String) = type.params.associate { s ->
|
||||
s.key to if (s.isEnum) choice(s.choices.filter { it != EchofieldDefs.CUSTOM && it != WaveTables.CUSTOM })
|
||||
else (s.min + frac * (s.max - s.min)).let { if (s.isInt) it.roundToInt().toFloat() else it }.toString()
|
||||
}
|
||||
return listOf(
|
||||
"default" to emptyMap(),
|
||||
"high" to variant(0.75f) { it.last() },
|
||||
"low" to variant(0.25f) { it[minOf(1, it.lastIndex)] },
|
||||
)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val SR = 48_000
|
||||
const val TEMPO = 120f
|
||||
const val BLOCK = 256
|
||||
const val FRAMES = 72_000 // 1.5 s
|
||||
const val SAMPLE_ID = "ios-golden-sample"
|
||||
}
|
||||
}
|
||||
@@ -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,248 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package cc.tiredsysadmin.android.sizzle.audio
|
||||
|
||||
import cc.tiredsysadmin.android.sizzle.echofield.EchofieldDefs
|
||||
import cc.tiredsysadmin.android.sizzle.frasil.FrasilClock
|
||||
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs
|
||||
import cc.tiredsysadmin.android.sizzle.frasil.FrasilVoice
|
||||
import cc.tiredsysadmin.android.sizzle.echofield.GrainCloud
|
||||
import cc.tiredsysadmin.android.sizzle.io.PresetIo
|
||||
import cc.tiredsysadmin.android.sizzle.io.ProjectIo
|
||||
import cc.tiredsysadmin.android.sizzle.io.SngFormat
|
||||
import cc.tiredsysadmin.android.sizzle.model.Arrangement
|
||||
import cc.tiredsysadmin.android.sizzle.model.Cell
|
||||
import cc.tiredsysadmin.android.sizzle.model.NesSynthPresets
|
||||
import cc.tiredsysadmin.android.sizzle.model.Pattern
|
||||
import cc.tiredsysadmin.android.sizzle.model.Project
|
||||
import cc.tiredsysadmin.android.sizzle.model.SamplerPads
|
||||
import cc.tiredsysadmin.android.sizzle.model.Scale
|
||||
import cc.tiredsysadmin.android.sizzle.model.TimeSignature
|
||||
import cc.tiredsysadmin.android.sizzle.model.ToolboxType
|
||||
import cc.tiredsysadmin.android.sizzle.wavetable.WaveDefs
|
||||
import cc.tiredsysadmin.android.sizzle.wavetable.WaveTables
|
||||
import org.junit.Assume.assumeTrue
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
|
||||
/**
|
||||
* Whole songs for the iOS port's model, file formats and engine (milestone 2 in
|
||||
* ios/PORTING.md). Runs only when SIZZLE_GOLDEN_DIR is set. Per song, in
|
||||
* SIZZLE_GOLDEN_DIR/songs/:
|
||||
*
|
||||
* <song>.szg ProjectIo.save (the full project format)
|
||||
* <song>.sng SngFormat.export (the desktop-compatible format)
|
||||
* <song>.slot<N>.szp PresetIo.export of every filled toolbox slot
|
||||
* <song>.render.f32 AudioEngine.fillBlock output (48 kHz, stereo interleaved,
|
||||
* 256-frame blocks) after play(), for songs with "render"
|
||||
* <song>.meta sr, block, seconds, the Morph Pad clock and the voice-seed
|
||||
* counters before the engine was built ("seeds <frasil> <grain>"),
|
||||
* and the sample the Sampler/SF2 slots use ("sample <id> <rate>
|
||||
* <loopStart> <loopEnd>", data in <song>.smp.f32)
|
||||
*
|
||||
* The C++ port must parse each .szg / .sng / .szp and write it back byte for
|
||||
* byte, and render the same audio from the parsed .szg.
|
||||
*/
|
||||
class IosGoldenSongs {
|
||||
|
||||
@Test fun export() {
|
||||
val dir = System.getenv("SIZZLE_GOLDEN_DIR")
|
||||
assumeTrue("set SIZZLE_GOLDEN_DIR to export", dir != null)
|
||||
val out = File(dir!!, "songs").apply { mkdirs() }
|
||||
WaveTables.prewarmBlocking()
|
||||
GrainSources.prewarmBlocking()
|
||||
SampleStore.put(SAMPLE_ID, testSample())
|
||||
|
||||
// The repo's demo song (despite its name, in the full ProjectIo format) as
|
||||
// it loads, then with instruments on its empty channels.
|
||||
val demoText = File(repoRoot(), "samples/demo.sng").readText()
|
||||
write(out, "demo_imported", ProjectIo.loadInto(Project(), demoText), seconds = 0.0)
|
||||
write(out, "demo", demoWithInstruments(demoText), seconds = 12.0)
|
||||
write(out, "mix", mixSong(), seconds = 12.0)
|
||||
write(out, "waltz", waltzSong(), seconds = 10.0)
|
||||
write(out, "midifx", midiFxSong(), seconds = 10.0)
|
||||
}
|
||||
|
||||
private fun repoRoot(): File {
|
||||
var f = File("").absoluteFile
|
||||
while (!File(f, "samples/demo.sng").exists()) f = f.parentFile ?: error("repo root not found")
|
||||
return f
|
||||
}
|
||||
|
||||
private fun write(out: File, name: String, p: Project, seconds: Double) {
|
||||
File(out, "$name.szg").writeText(ProjectIo.save(p))
|
||||
File(out, "$name.sng").writeText(SngFormat.export(p))
|
||||
p.toolbox.forEach { s -> if (!s.isEmpty) File(out, "$name.slot${s.index}.szp").writeText(PresetIo.export(s)) }
|
||||
val meta = StringBuilder("song $name\nsr $SR\nblock $BLOCK\nseconds $seconds\n")
|
||||
val smp = SampleStore.get(SAMPLE_ID)!!
|
||||
meta.append("sample $SAMPLE_ID ${smp.sampleRate} ${smp.loopStart} ${smp.loopEnd}\n")
|
||||
if (seconds > 0) {
|
||||
meta.append("clock ${java.lang.Double.toString(FrasilClock.seconds)}\n")
|
||||
meta.append("seeds ${counter(FrasilVoice::class.java)} ${counter(GrainCloud::class.java)}\n")
|
||||
val engine = ReferenceEngine(SR).apply { setProject(p) }
|
||||
engine.play()
|
||||
val frames = (seconds * SR).toInt() / BLOCK * BLOCK
|
||||
val buf = FloatArray(BLOCK * 2)
|
||||
val bb = ByteBuffer.allocate(frames * 2 * 4).order(ByteOrder.LITTLE_ENDIAN)
|
||||
repeat(frames / BLOCK) {
|
||||
engine.fillBlock(buf, BLOCK)
|
||||
buf.forEach { v -> bb.putFloat(v) }
|
||||
}
|
||||
File(out, "$name.render.f32").writeBytes(bb.array())
|
||||
}
|
||||
File(out, "$name.meta").writeText(meta.toString())
|
||||
val sb = ByteBuffer.allocate(smp.data.size * 4).order(ByteOrder.LITTLE_ENDIAN)
|
||||
smp.data.forEach { sb.putFloat(it) }
|
||||
File(out, "$name.smp.f32").writeBytes(sb.array())
|
||||
}
|
||||
|
||||
/** The private `seeds` counter a voice class takes its next seed from. */
|
||||
private fun counter(c: Class<*>): Int {
|
||||
val f = runCatching { c.getDeclaredField("seeds") }.getOrElse {
|
||||
Class.forName(c.name + "\$Companion").getDeclaredField("seeds")
|
||||
}
|
||||
f.isAccessible = true
|
||||
return f.getInt(null)
|
||||
}
|
||||
|
||||
private fun testSample() = SampleStore.Sample(FloatArray(44_100) { i ->
|
||||
val t = i / 44_100.0
|
||||
(0.6 * kotlin.math.sin(2 * Math.PI * 330 * t) * kotlin.math.exp(-t * 2.5) +
|
||||
0.2 * (2 * ((t * 110) % 1.0) - 1) * kotlin.math.exp(-t * 6)).toFloat()
|
||||
}, 44_100, loopStart = 6_000, loopEnd = 30_000)
|
||||
|
||||
// ----------------------------------------------------------------- songs
|
||||
|
||||
/** Deterministic notes: an LCG so every run writes the same song. */
|
||||
private class Gen(var s: Int) {
|
||||
fun next(n: Int): Int { s = s * 1103515245 + 12345; return ((s ushr 8) and 0x7FFFFF) % n }
|
||||
}
|
||||
|
||||
private fun fill(p: Project, pattern: Int, gen: Gen, scale: List<Int>, root: Int, density: Int, offs: Boolean) {
|
||||
val pat = p.patterns[pattern]
|
||||
for (t in 0 until Pattern.TRACK_COUNT) for (l in 0 until pat.length) {
|
||||
val c = pat.cell(t, l)
|
||||
c.channel = t + 1
|
||||
when {
|
||||
gen.next(100) < density -> {
|
||||
c.note = root + 12 * (t % 2) + scale[gen.next(scale.size)] + 12 * gen.next(2)
|
||||
c.velocity = 40 + gen.next(88)
|
||||
}
|
||||
offs && gen.next(100) < 10 -> c.note = Cell.OFF
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun route(p: Project, ch: Int, instrument: Int, vararg fx: Int, volume: Float = 0.8f) {
|
||||
val m = p.mixer.channels[ch]
|
||||
m.midiChannel = ch + 1
|
||||
m.instrumentSlot = instrument
|
||||
fx.forEachIndexed { i, s -> m.fxSlots[i] = s }
|
||||
m.volume = volume
|
||||
}
|
||||
|
||||
private fun preset(p: Project, slot: Int, type: ToolboxType, values: Map<String, String>) {
|
||||
p.toolbox[slot].fill(type)
|
||||
values.forEach { (k, v) -> p.toolbox[slot].set(k, v) }
|
||||
}
|
||||
|
||||
/** Four instruments with factory presets through eight different effects. */
|
||||
private fun mixSong(): Project = Project().apply {
|
||||
name = "iOS golden mix"
|
||||
tempoBpm = 126f
|
||||
scale = Scale.MINOR
|
||||
rootNote = 9
|
||||
NesSynthPresets.apply(toolbox[0].apply { fill(ToolboxType.NES_SYNTH) }, NesSynthPresets.FACTORY[1])
|
||||
preset(this, 1, ToolboxType.WAVETABLE, WaveDefs.FACTORY[2].values)
|
||||
preset(this, 2, ToolboxType.MORPH_PAD, FrasilDefs.FACTORY[3].values)
|
||||
preset(this, 3, ToolboxType.GRAIN_CLOUD, EchofieldDefs.FACTORY[0].values)
|
||||
listOf(ToolboxType.DELAY, ToolboxType.FILTER, ToolboxType.EQ10, ToolboxType.AMBIENCE,
|
||||
ToolboxType.BITCRUSHER, ToolboxType.MIX_TIGHTENER, ToolboxType.TAPE_ENGINE, ToolboxType.GRANULAR)
|
||||
.forEachIndexed { i, t -> toolbox[4 + i].fill(t) }
|
||||
toolbox[5].set("cutoff", 0.45f); toolbox[6].set("band2", 0.5f); toolbox[8].set("bits", 6f)
|
||||
route(this, 0, 0, 4, volume = 0.7f)
|
||||
route(this, 1, 1, 5, 6)
|
||||
route(this, 2, 2, 7, volume = 0.9f)
|
||||
route(this, 3, 3, 8, 9, 10, 11)
|
||||
mixer.channels[3].limiter = true
|
||||
val g = Gen(0x5EED)
|
||||
for (pt in 0 until 4) fill(this, pt, g, scale.intervals, 45, density = 30, offs = true)
|
||||
for (bar in 0 until 8) for (lane in 0 until 4) {
|
||||
val beat = bar * 4
|
||||
if ((bar + lane) % 3 != 2) arrangement.set(lane, beat, (bar + lane) % 4)
|
||||
}
|
||||
arrangement.set(1, 6 * 4 + 2, Arrangement.NOTE_OFF)
|
||||
}
|
||||
|
||||
/** 3/4, Sampler + SF2/XI with the test sample, tape effects, a loop region, mutes. */
|
||||
private fun waltzSong(): Project = Project().apply {
|
||||
name = "iOS golden waltz"
|
||||
tempoBpm = 95f
|
||||
timeSignature = TimeSignature.THREE_FOUR
|
||||
patterns.forEach { it.resize(timeSignature.lengthOptions[0]) }
|
||||
scale = Scale.MAJOR
|
||||
rootNote = 2
|
||||
toolbox[0].fill(ToolboxType.SAMPLER)
|
||||
for (pad in 0 until SamplerPads.COUNT) toolbox[0].set(SamplerPads.key(pad), SAMPLE_ID)
|
||||
toolbox[0].set(SamplerPads.sliceStartKey(3), 0.2f); toolbox[0].set(SamplerPads.volumeKey(5), 0.5f)
|
||||
toolbox[1].fill(ToolboxType.SOUNDFONT)
|
||||
toolbox[1].set("sfSample", SAMPLE_ID); toolbox[1].set("sfRoot", 62f); toolbox[1].set("loop", "On")
|
||||
toolbox[2].fill(ToolboxType.TAPE_ENGINE)
|
||||
toolbox[3].fill(ToolboxType.GRANULAR); toolbox[3].set("intensity", 0.6f)
|
||||
toolbox[4].fill(ToolboxType.AMBIENCE)
|
||||
route(this, 0, 0, 2)
|
||||
route(this, 1, 1, 3, 4)
|
||||
route(this, 2, 1, volume = 0.6f)
|
||||
route(this, 3, 0)
|
||||
mixer.channels[3].mute = true
|
||||
val g = Gen(0x3A17)
|
||||
for (pt in 0 until 4) {
|
||||
fill(this, pt, g, listOf(0, 2, 4, 7, 9), 36, density = 35, offs = false)
|
||||
// pads live at notes 36..51: keep track 0 (channel 1 → the Sampler) there
|
||||
for (l in 0 until patterns[pt].length) patterns[pt].cell(0, l).let { if (it.isPlayable) it.note = 36 + (it.note % 16) }
|
||||
}
|
||||
for (bar in 0 until 6) for (lane in 0 until 3) arrangement.set(lane, bar * 3, (bar + lane) % 4)
|
||||
arrangement.laneMuted[2] = true
|
||||
arrangement.loopEnabled = true
|
||||
arrangement.regionA.apply { enabled = true; start = 3; end = 9; repeats = 2 }
|
||||
}
|
||||
|
||||
/** MIDI effects: an arpeggiator, a transposer and an LFO on a filter cutoff. */
|
||||
private fun midiFxSong(): Project = Project().apply {
|
||||
name = "iOS golden midifx"
|
||||
tempoBpm = 110f
|
||||
NesSynthPresets.apply(toolbox[0].apply { fill(ToolboxType.NES_SYNTH) }, NesSynthPresets.FACTORY[2])
|
||||
preset(this, 1, ToolboxType.WAVETABLE, WaveDefs.FACTORY[5].values)
|
||||
toolbox[2].fill(ToolboxType.ARPEGGIATOR)
|
||||
toolbox[2].set("mode", "UpDown"); toolbox[2].set("octaves", 2f)
|
||||
toolbox[3].fill(ToolboxType.TRANSPOSER); toolbox[3].set("semitones", 7f)
|
||||
toolbox[4].fill(ToolboxType.FILTER)
|
||||
toolbox[5].fill(ToolboxType.LFO)
|
||||
toolbox[5].set("target", "4:cutoff"); toolbox[5].set("depth", 0.8f)
|
||||
route(this, 0, 0, 2, 4)
|
||||
route(this, 1, 1, 3)
|
||||
val g = Gen(0x1F0)
|
||||
for (pt in 0 until 2) fill(this, pt, g, Scale.MAJOR.intervals, 48, density = 20, offs = true)
|
||||
for (bar in 0 until 6) { arrangement.set(0, bar * 4, bar % 2); arrangement.set(1, bar * 4, (bar + 1) % 2) }
|
||||
}
|
||||
|
||||
/** The demo song with an instrument on each of its channels (its own mixer
|
||||
* routing kept: channel n listens on MIDI channel n + 1). */
|
||||
private fun demoWithInstruments(text: String): Project = ProjectIo.loadInto(Project(), text).apply {
|
||||
preset(this, 1, ToolboxType.WAVETABLE, WaveDefs.FACTORY[0].values)
|
||||
preset(this, 2, ToolboxType.MORPH_PAD, FrasilDefs.FACTORY[0].values)
|
||||
NesSynthPresets.apply(toolbox[3].apply { fill(ToolboxType.NES_SYNTH) }, NesSynthPresets.FACTORY[3])
|
||||
toolbox[4].fill(ToolboxType.AMBIENCE)
|
||||
for (ch in 1 until 4) mixer.channels[ch].instrumentSlot = ch
|
||||
mixer.channels[2].fxSlots[0] = 4
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val SR = 48_000
|
||||
const val BLOCK = 256
|
||||
const val SAMPLE_ID = "ios-golden-song-sample"
|
||||
}
|
||||
}
|
||||
+6
@@ -1,6 +1,12 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// The Kotlin reference the C++ port in core/ is checked against (handover §5.4.2):
|
||||
// the IosGolden* tests render it, and `make -C ios core-test` compares the C++ with
|
||||
// that audio sample by sample. It lives in the TEST source set because both apps
|
||||
// play core/ — in src/main it would only be dead code in the APK. Keep it in step
|
||||
// with core/src/host/MasterRecorder.cpp.
|
||||
|
||||
package cc.tiredsysadmin.android.sizzle.audio
|
||||
|
||||
import java.io.File
|
||||
File diff suppressed because it is too large
Load Diff
+15
-1
@@ -1,6 +1,12 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// The Kotlin reference the C++ port in core/ is checked against (handover §5.4.2):
|
||||
// the IosGolden* tests render it, and `make -C ios core-test` compares the C++ with
|
||||
// that audio sample by sample. It lives in the TEST source set because both apps
|
||||
// play core/ — in src/main it would only be dead code in the APK. Keep it in step
|
||||
// with core/src/sampler/SampleVoice.cpp.
|
||||
|
||||
package cc.tiredsysadmin.android.sizzle.audio
|
||||
|
||||
import kotlin.math.exp
|
||||
@@ -86,6 +92,7 @@ class SampleVoice(private val engineSampleRate: Int) {
|
||||
attack: Float = 0.002f, decay: Float = 0f, sustain: Float = 1f, release: Float = 0.02f,
|
||||
loop: Boolean = false, crossfadeMs: Float = 0f,
|
||||
) {
|
||||
oneShot = false // the caller sets it again for a One-shot Sampler
|
||||
// Carry the level we're interrupting so the new note starts continuously
|
||||
// (the new note fades in from ~0; without this the sum would jump from the
|
||||
// old voice's level straight to ~0 → a click when stealing a loud voice).
|
||||
@@ -139,8 +146,15 @@ class SampleVoice(private val engineSampleRate: Int) {
|
||||
endGain = 1f
|
||||
}
|
||||
|
||||
/** Playing a One-shot Sampler pad: [noteOff] leaves it be (it plays to its slice
|
||||
* end); [release] still fades it. Reset by [noteOn]. */
|
||||
var oneShot = false
|
||||
|
||||
/** A note-off: the release stage, unless the voice is one-shot. */
|
||||
fun noteOff() { if (!oneShot) release() }
|
||||
|
||||
/** Enter the release stage: fade from the current level to 0 over the release time. */
|
||||
fun noteOff() {
|
||||
fun release() {
|
||||
val sr = engineSampleRate.toFloat()
|
||||
releaseInc = if (releaseSeconds <= 0f) 1f else env / (releaseSeconds * sr)
|
||||
if (releaseInc <= 0f) releaseInc = 1f
|
||||
+6
@@ -1,6 +1,12 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// The Kotlin reference the C++ port in core/ is checked against (handover §5.4.2):
|
||||
// the IosGolden* tests render it, and `make -C ios core-test` compares the C++ with
|
||||
// that audio sample by sample. It lives in the TEST source set because both apps
|
||||
// play core/ — in src/main it would only be dead code in the APK. Keep it in step
|
||||
// with core/src/synth/SynthPatch.cpp.
|
||||
|
||||
package cc.tiredsysadmin.android.sizzle.audio
|
||||
|
||||
import cc.tiredsysadmin.android.sizzle.frasil.FrasilPatch
|
||||
+6
-1
@@ -1,6 +1,12 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// The Kotlin reference the C++ port in core/ is checked against (handover §5.4.2):
|
||||
// the IosGolden* tests render it, and `make -C ios core-test` compares the C++ with
|
||||
// that audio sample by sample. It lives in the TEST source set because both apps
|
||||
// play core/ — in src/main it would only be dead code in the APK. Keep it in step
|
||||
// with core/src/synth/SynthVoice.cpp.
|
||||
|
||||
package cc.tiredsysadmin.android.sizzle.audio
|
||||
|
||||
import cc.tiredsysadmin.android.sizzle.frasil.FrasilVoice
|
||||
@@ -80,7 +86,6 @@ class SynthVoice(private val sampleRate: Int) {
|
||||
private val pad = FrasilVoice(sampleRate)
|
||||
private val wave = WaveVoice(sampleRate)
|
||||
private var mode = MODE_SYNTH
|
||||
private val padMode get() = mode == MODE_PAD
|
||||
|
||||
val isActive: Boolean get() = when (mode) { MODE_PAD -> pad.isActive; MODE_WAVE -> wave.isActive; else -> ampEnv.active }
|
||||
/** Gate is still open (attack/decay/sustain) — the note is *held*. A voice in its
|
||||
+6
@@ -7,6 +7,12 @@
|
||||
// spawn, render_grains_part, schedule, ef_render's gate and source fade, auto_level).
|
||||
// The MIT licence text is in LICENSES/MIT.txt of this repository.
|
||||
|
||||
// The Kotlin reference the C++ port in core/ is checked against (handover §5.4.2):
|
||||
// the IosGolden* tests render it, and `make -C ios core-test` compares the C++ with
|
||||
// that audio sample by sample. It lives in the TEST source set because both apps
|
||||
// play core/ — in src/main it would only be dead code in the APK. Keep it in step
|
||||
// with core/src/echofield/GrainCloud.cpp.
|
||||
|
||||
package cc.tiredsysadmin.android.sizzle.echofield
|
||||
|
||||
import cc.tiredsysadmin.android.sizzle.audio.GrainSources
|
||||
+6
@@ -6,6 +6,12 @@
|
||||
// If a copy of the MPL was not distributed with this file, You can obtain one at
|
||||
// https://mozilla.org/MPL/2.0/ (also in LICENSES/MPL-2.0.txt of this repository).
|
||||
|
||||
// The Kotlin reference the C++ port in core/ is checked against (handover §5.4.2):
|
||||
// the IosGolden* tests render it, and `make -C ios core-test` compares the C++ with
|
||||
// that audio sample by sample. It lives in the TEST source set because both apps
|
||||
// play core/ — in src/main it would only be dead code in the APK. Keep it in step
|
||||
// with core/src/frasil/FrasilVoice.cpp.
|
||||
|
||||
package cc.tiredsysadmin.android.sizzle.frasil
|
||||
|
||||
import cc.tiredsysadmin.android.sizzle.model.ToolboxSlot
|
||||
+6
@@ -11,6 +11,12 @@
|
||||
// ch_svf, ch_lp, blepi, partial_ramp, partials_chunk, souffle_chunk, breath_noise,
|
||||
// render_part) and the mix's DC blocker, warmth and FULLNESS high-pass.
|
||||
|
||||
// The Kotlin reference the C++ port in core/ is checked against (handover §5.4.2):
|
||||
// the IosGolden* tests render it, and `make -C ios core-test` compares the C++ with
|
||||
// that audio sample by sample. It lives in the TEST source set because both apps
|
||||
// play core/ — in src/main it would only be dead code in the APK. Keep it in step
|
||||
// with core/src/frasil/FrasilVoice.cpp.
|
||||
|
||||
package cc.tiredsysadmin.android.sizzle.frasil
|
||||
|
||||
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.AIR
|
||||
@@ -0,0 +1,46 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package cc.tiredsysadmin.android.sizzle.io
|
||||
|
||||
import cc.tiredsysadmin.android.sizzle.model.Project
|
||||
import cc.tiredsysadmin.android.sizzle.model.ToolboxType
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
|
||||
/** The same expectations as core/tests/midimap_test.cpp, on the same fixture. */
|
||||
class MidiMapIoTest {
|
||||
private val fixture = javaClass.getResource("/midimap/filter.szm")!!.readText()
|
||||
|
||||
@Test
|
||||
fun parsesTheSharedFixture() {
|
||||
val map = MidiMapIo.parse(fixture)
|
||||
assertNotNull(map)
|
||||
assertEquals("FILTER", map!!.type)
|
||||
assertEquals("Sweep", map.name)
|
||||
assertEquals(listOf("cutoff" to 74, "resonance" to 71, "nosuchparam" to 20, "release" to 7), map.bindings)
|
||||
assertNull(MidiMapIo.parse("TYPE=FILTER\ncutoff=1\n"))
|
||||
assertNull(MidiMapIo.parse("SIZZLE-MIDIMAP 1\ncutoff=1\n"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun appliesExportsAndRoundTrips() {
|
||||
val map = MidiMapIo.parse(fixture)!!
|
||||
val p = Project()
|
||||
p.toolbox[2].fill(ToolboxType.FILTER)
|
||||
p.toolbox[5].fill(ToolboxType.BITCRUSHER)
|
||||
p.toolbox[5].set("midicc@bits", "71")
|
||||
p.toolbox[2].set("midicc@warmth", "30")
|
||||
assertEquals(-1, MidiMapIo.apply(p, 5, map))
|
||||
assertEquals(3, MidiMapIo.apply(p, 2, map))
|
||||
assertFalse("midicc@bits" in p.toolbox[5].values)
|
||||
assertFalse("midicc@warmth" in p.toolbox[2].values)
|
||||
val applied = listOf("cutoff" to 74, "resonance" to 71, "release" to 7)
|
||||
val back = MidiMapIo.fromSlot(p.toolbox[2])
|
||||
assertEquals(applied, back.bindings)
|
||||
assertEquals(applied, MidiMapIo.parse(MidiMapIo.save(back))!!.bindings)
|
||||
}
|
||||
}
|
||||
@@ -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"))
|
||||
}
|
||||
}
|
||||
+6
@@ -1,6 +1,12 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// The Kotlin reference the C++ port in core/ is checked against (handover §5.4.2):
|
||||
// the IosGolden* tests render it, and `make -C ios core-test` compares the C++ with
|
||||
// that audio sample by sample. It lives in the TEST source set because both apps
|
||||
// play core/ — in src/main it would only be dead code in the APK. Keep it in step
|
||||
// with core/src/wavetable/WaveVoice.cpp.
|
||||
|
||||
package cc.tiredsysadmin.android.sizzle.wavetable
|
||||
|
||||
import cc.tiredsysadmin.android.sizzle.model.TimeDivision
|
||||
@@ -0,0 +1,13 @@
|
||||
SIZZLE-MIDIMAP 1
|
||||
# A shared fixture: core/tests/midimap_test.cpp and MidiMapIoTest.kt read it.
|
||||
TYPE=FILTER
|
||||
NAME=Sweep
|
||||
cutoff = 74
|
||||
resonance=71
|
||||
cutoff=12
|
||||
warmth=74
|
||||
envamt=300
|
||||
nosuchparam=20
|
||||
garbage line
|
||||
decay=x
|
||||
release=7
|
||||
Binary file not shown.
@@ -0,0 +1,626 @@
|
||||
// GENERATED by IosGoldenExport (make -C ios golden). Do not edit.
|
||||
// Every Sizzle device's parameters, from ToolboxType in the Android app.
|
||||
#pragma once
|
||||
#include "sizzle/Specs.hpp"
|
||||
|
||||
namespace sizzle::gen {
|
||||
|
||||
inline const char *const NES_SYNTH_c0[] = {"Tri", "Saw", "Square", "Pulse25", "Pulse12", nullptr};
|
||||
inline const char *const NES_SYNTH_c5[] = {"Tri", "Saw", "Square", "Pulse25", "Pulse12", nullptr};
|
||||
inline const char *const NES_SYNTH_c10[] = {"Tri", "Saw", "Square", "Pulse25", "Pulse12", nullptr};
|
||||
inline const char *const NES_SYNTH_c28[] = {"Tri", "Saw", "Square", "Sine", "S&H", nullptr};
|
||||
inline const char *const NES_SYNTH_c30[] = {"0°", "45°", "90°", "135°", "180°", "225°", "270°", "315°", nullptr};
|
||||
inline const char *const NES_SYNTH_c31[] = {"Off", "LFO", "FiltEnv", "AmpEnv", "Vel", "KeyTrk", nullptr};
|
||||
inline const char *const NES_SYNTH_c32[] = {"Pitch", "Osc2", "Osc3", "Cutoff", "PWM", "Amp", nullptr};
|
||||
inline const char *const NES_SYNTH_c34[] = {"Off", "LFO", "FiltEnv", "AmpEnv", "Vel", "KeyTrk", nullptr};
|
||||
inline const char *const NES_SYNTH_c35[] = {"Pitch", "Osc2", "Osc3", "Cutoff", "PWM", "Amp", nullptr};
|
||||
inline const char *const NES_SYNTH_c37[] = {"Off", "LFO", "FiltEnv", "AmpEnv", "Vel", "KeyTrk", nullptr};
|
||||
inline const char *const NES_SYNTH_c38[] = {"Pitch", "Osc2", "Osc3", "Cutoff", "PWM", "Amp", nullptr};
|
||||
inline const char *const NES_SYNTH_c40[] = {"Off", "LFO", "FiltEnv", "AmpEnv", "Vel", "KeyTrk", nullptr};
|
||||
inline const char *const NES_SYNTH_c41[] = {"Pitch", "Osc2", "Osc3", "Cutoff", "PWM", "Amp", nullptr};
|
||||
inline const ParamSpec NES_SYNTH_params[] = {
|
||||
{"osc0wave", "Osc1 Wave", 0.0f, 0.0f, 1.0f, false, NES_SYNTH_c0},
|
||||
{"osc0oct", "Osc1 Oct", 0.0f, -2.0f, 2.0f, true, nullptr},
|
||||
{"osc0semi", "Osc1 Semi", 0.0f, -12.0f, 12.0f, true, nullptr},
|
||||
{"osc0fine", "Osc1 Fine", 0.0f, -50.0f, 50.0f, false, nullptr},
|
||||
{"osc0level", "Osc1 Level", 0.9f, 0.0f, 1.0f, false, nullptr},
|
||||
{"osc1wave", "Osc2 Wave", 0.0f, 0.0f, 1.0f, false, NES_SYNTH_c5},
|
||||
{"osc1oct", "Osc2 Oct", 0.0f, -2.0f, 2.0f, true, nullptr},
|
||||
{"osc1semi", "Osc2 Semi", 0.0f, -12.0f, 12.0f, true, nullptr},
|
||||
{"osc1fine", "Osc2 Fine", 0.0f, -50.0f, 50.0f, false, nullptr},
|
||||
{"osc1level", "Osc2 Level", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"osc2wave", "Osc3 Wave", 0.0f, 0.0f, 1.0f, false, NES_SYNTH_c10},
|
||||
{"osc2oct", "Osc3 Oct", 0.0f, -2.0f, 2.0f, true, nullptr},
|
||||
{"osc2semi", "Osc3 Semi", 0.0f, -12.0f, 12.0f, true, nullptr},
|
||||
{"osc2fine", "Osc3 Fine", 0.0f, -50.0f, 50.0f, false, nullptr},
|
||||
{"osc2level", "Osc3 Level", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"noise", "Noise", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"cutoff", "Cutoff", 0.55f, 0.0f, 1.0f, false, nullptr},
|
||||
{"reso", "Resonance", 0.15f, 0.0f, 1.0f, false, nullptr},
|
||||
{"keytrack", "Key Track", 0.3f, 0.0f, 1.0f, false, nullptr},
|
||||
{"fenvamt", "Filter Env", 0.4f, -1.0f, 1.0f, false, nullptr},
|
||||
{"fatk", "F.Attack", 0.005f, 0.0f, 2.0f, false, nullptr},
|
||||
{"fdec", "F.Decay", 0.25f, 0.0f, 2.0f, false, nullptr},
|
||||
{"fsus", "F.Sustain", 0.4f, 0.0f, 1.0f, false, nullptr},
|
||||
{"frel", "F.Release", 0.2f, 0.0f, 3.0f, false, nullptr},
|
||||
{"attack", "Attack", 0.005f, 0.0f, 2.0f, false, nullptr},
|
||||
{"decay", "Decay", 0.2f, 0.0f, 2.0f, false, nullptr},
|
||||
{"sustain", "Sustain", 0.7f, 0.0f, 1.0f, false, nullptr},
|
||||
{"release", "Release", 0.2f, 0.0f, 3.0f, false, nullptr},
|
||||
{"lfowave", "LFO Wave", 0.0f, 0.0f, 1.0f, false, NES_SYNTH_c28},
|
||||
{"lfodiv", "LFO Rate", 3.0f, 0.0f, 6.0f, true, nullptr},
|
||||
{"lfophase", "LFO Phase", 0.0f, 0.0f, 1.0f, false, NES_SYNTH_c30},
|
||||
{"m0src", "Mod1 Src", 0.0f, 0.0f, 1.0f, false, NES_SYNTH_c31},
|
||||
{"m0dst", "Mod1 Dst", 0.0f, 0.0f, 1.0f, false, NES_SYNTH_c32},
|
||||
{"m0amt", "Mod1 Amt", 0.0f, -1.0f, 1.0f, false, nullptr},
|
||||
{"m1src", "Mod2 Src", 0.0f, 0.0f, 1.0f, false, NES_SYNTH_c34},
|
||||
{"m1dst", "Mod2 Dst", 0.0f, 0.0f, 1.0f, false, NES_SYNTH_c35},
|
||||
{"m1amt", "Mod2 Amt", 0.0f, -1.0f, 1.0f, false, nullptr},
|
||||
{"m2src", "Mod3 Src", 0.0f, 0.0f, 1.0f, false, NES_SYNTH_c37},
|
||||
{"m2dst", "Mod3 Dst", 0.0f, 0.0f, 1.0f, false, NES_SYNTH_c38},
|
||||
{"m2amt", "Mod3 Amt", 0.0f, -1.0f, 1.0f, false, nullptr},
|
||||
{"m3src", "Mod4 Src", 0.0f, 0.0f, 1.0f, false, NES_SYNTH_c40},
|
||||
{"m3dst", "Mod4 Dst", 0.0f, 0.0f, 1.0f, false, NES_SYNTH_c41},
|
||||
{"m3amt", "Mod4 Amt", 0.0f, -1.0f, 1.0f, false, nullptr},
|
||||
};
|
||||
|
||||
inline const char *const SAMPLER_c1[] = {"Off", "On", nullptr};
|
||||
inline const ParamSpec SAMPLER_params[] = {
|
||||
{"volume", "Volume", 0.8f, 0.0f, 1.0f, false, nullptr},
|
||||
{"oneShot", "One-shot", 0.0f, 0.0f, 1.0f, false, SAMPLER_c1},
|
||||
};
|
||||
|
||||
inline const char *const SOUNDFONT_c6[] = {"Off", "On", nullptr};
|
||||
inline const ParamSpec SOUNDFONT_params[] = {
|
||||
{"program", "Program", 0.0f, 0.0f, 127.0f, true, nullptr},
|
||||
{"volume", "Volume", 0.8f, 0.0f, 1.0f, false, nullptr},
|
||||
{"attack", "Attack", 0.005f, 0.0f, 2.0f, false, nullptr},
|
||||
{"decay", "Decay", 0.1f, 0.0f, 2.0f, false, nullptr},
|
||||
{"sustain", "Sustain", 1.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"release", "Release", 0.2f, 0.0f, 3.0f, false, nullptr},
|
||||
{"loop", "Loop", 0.0f, 0.0f, 1.0f, false, SOUNDFONT_c6},
|
||||
{"loopXfade", "Loop XFade", 0.0f, 0.0f, 500.0f, false, nullptr},
|
||||
};
|
||||
|
||||
inline const char *const MORPH_PAD_c0[] = {"Off", "Mist", "Cathedral", "Glacier", "Abyss", "Aurora", "Ember", "Tide", "Dust", "Wind", "Organ", "Hollow", "Vowel", "Shimmer", "Chanter", "Ensemble", "Bells", "Nocturne", "Haze", "Pulse", "Rime", "Deep", "Spectral", "Rust", "Still", "Velvet", "Chrome", "Swarm", "Foghorn", "Solar", "Cave", "Glass Harp", "Monk", "Static", "Lullaby", "Storm", "Prism", nullptr};
|
||||
inline const char *const MORPH_PAD_c19[] = {"Unison", "-12", "+7", "+12", nullptr};
|
||||
inline const char *const MORPH_PAD_c21[] = {"Low", "Band", "High", nullptr};
|
||||
inline const char *const MORPH_PAD_c33[] = {"-12", "Unison", "+12", "+19", "+24", nullptr};
|
||||
inline const ParamSpec MORPH_PAD_params[] = {
|
||||
{"morphTo", "Morph To", 0.0f, 0.0f, 1.0f, false, MORPH_PAD_c0},
|
||||
{"morph", "Morph", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"mtime", "Morph Time s", 0.0f, 0.0f, 120.0f, false, nullptr},
|
||||
{"choir", "Choir", 0.5984252f, 0.0f, 1.0f, false, nullptr},
|
||||
{"partials", "Partials", 0.7007874f, 0.0f, 1.0f, false, nullptr},
|
||||
{"breath", "Breath", 0.2519685f, 0.0f, 1.0f, false, nullptr},
|
||||
{"timbre", "Timbre", 0.503937f, 0.0f, 1.0f, false, nullptr},
|
||||
{"warmth", "Warmth", 0.1496063f, 0.0f, 1.0f, false, nullptr},
|
||||
{"body", "Body", 1.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"attack", "Attack", 0.7007874f, 0.0f, 1.0f, false, nullptr},
|
||||
{"release", "Release", 0.6535433f, 0.0f, 1.0f, false, nullptr},
|
||||
{"velsens", "Velocity", 0.2992126f, 0.0f, 1.0f, false, nullptr},
|
||||
{"motion", "Motion", 0.3464567f, 0.0f, 1.0f, false, nullptr},
|
||||
{"mrate", "Motion Rate", 0.4015748f, 0.0f, 1.0f, false, nullptr},
|
||||
{"tide", "Tide", 0.19685039f, 0.0f, 1.0f, false, nullptr},
|
||||
{"tperiod", "Tide Speed", 0.2992126f, 0.0f, 1.0f, false, nullptr},
|
||||
{"detune", "Detune", 0.4015748f, 0.0f, 1.0f, false, nullptr},
|
||||
{"cfilter", "Filter", 0.3464567f, 0.0f, 1.0f, false, nullptr},
|
||||
{"shape", "Shape", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"interval", "Interval", 0.0f, 0.0f, 1.0f, false, MORPH_PAD_c19},
|
||||
{"creso", "Resonance", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"ctype", "Filter Type", 0.0f, 0.0f, 1.0f, false, MORPH_PAD_c21},
|
||||
{"soft", "Soft", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"tilt", "Tilt", 0.4488189f, 0.0f, 1.0f, false, nullptr},
|
||||
{"odd", "Odd", 0.19685039f, 0.0f, 1.0f, false, nullptr},
|
||||
{"stretch", "Stretch", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"evolve", "Evolve", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"beat", "Beat", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"formant", "Formant", 0.6692913f, 0.0f, 1.0f, false, nullptr},
|
||||
{"peak", "Peak", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"bres", "Glass", 0.5511811f, 0.0f, 1.0f, false, nullptr},
|
||||
{"color", "Color", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"grain", "Grain", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"bpitch", "Pitch", 0.0f, 0.0f, 1.0f, false, MORPH_PAD_c33},
|
||||
{"btone", "Tone", 0.503937f, 0.0f, 1.0f, false, nullptr},
|
||||
{"air", "Air", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
};
|
||||
|
||||
inline const char *const GRAIN_CLOUD_c0[] = {"Felt Piano", "Bowed Glass", "Music Box", "Warm Pad", "Strings", "Low Drone", "Rain Field", "Kalimba", "Breath Choir", "Glass Tines", "Custom", nullptr};
|
||||
inline const char *const GRAIN_CLOUD_c1[] = {"Cloud", "Dust", "Tape", "Bloom", "Pulse", "Drift", nullptr};
|
||||
inline const char *const GRAIN_CLOUD_c15[] = {"Auto", "Hann", "Tukey", "Perc", "Swell", "Gauss", nullptr};
|
||||
inline const char *const GRAIN_CLOUD_c22[] = {"Off", "On", nullptr};
|
||||
inline const ParamSpec GRAIN_CLOUD_params[] = {
|
||||
{"source", "Source", 0.0f, 0.0f, 1.0f, false, GRAIN_CLOUD_c0},
|
||||
{"mode", "Mode", 0.0f, 0.0f, 1.0f, false, GRAIN_CLOUD_c1},
|
||||
{"position", "Position", 0.35f, 0.0f, 1.0f, false, nullptr},
|
||||
{"texture", "Texture", 0.72f, 0.0f, 1.0f, false, nullptr},
|
||||
{"scatter", "Scatter", 0.45f, 0.0f, 1.0f, false, nullptr},
|
||||
{"drift", "Drift", 0.35f, 0.0f, 1.0f, false, nullptr},
|
||||
{"motion", "Evolve", 0.35f, 0.0f, 1.0f, false, nullptr},
|
||||
{"pitch", "Pitch", 0.0f, -24.0f, 24.0f, true, nullptr},
|
||||
{"harmony", "Harmony", 0.3f, 0.0f, 1.0f, false, nullptr},
|
||||
{"size_mul", "Size", 0.0f, -2.0f, 2.0f, false, nullptr},
|
||||
{"dens_mul", "Density", 0.0f, -2.0f, 2.0f, false, nullptr},
|
||||
{"scan", "Scan", 0.0f, -1.0f, 1.0f, false, nullptr},
|
||||
{"reverse", "Reverse", 0.1f, 0.0f, 1.0f, false, nullptr},
|
||||
{"pitch_rand", "Pitch Rnd", 0.0f, 0.0f, 12.0f, false, nullptr},
|
||||
{"size_rand", "Size Rnd", 0.3f, 0.0f, 1.0f, false, nullptr},
|
||||
{"window", "Envelope", 0.0f, 0.0f, 1.0f, false, GRAIN_CLOUD_c15},
|
||||
{"grain_tone", "Tone", -0.1f, -1.0f, 1.0f, false, nullptr},
|
||||
{"attack", "Attack", 0.15f, 0.0f, 1.0f, false, nullptr},
|
||||
{"release", "Release", 0.45f, 0.0f, 1.0f, false, nullptr},
|
||||
{"velo", "Velocity", 0.5f, 0.0f, 1.0f, false, nullptr},
|
||||
{"start", "Start", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"end", "End", 1.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"freeze", "Freeze", 0.0f, 0.0f, 1.0f, false, GRAIN_CLOUD_c22},
|
||||
{"level", "Level", 0.75f, 0.0f, 1.0f, false, nullptr},
|
||||
};
|
||||
|
||||
inline const char *const WAVETABLE_c0[] = {"Classic", "PWM", "Vowels", "Harmonic Sweep", "Sync", "FM", "Organ", "Fold", "Digital", "Glass", "Odd Even", "Comb", "Custom", nullptr};
|
||||
inline const char *const WAVETABLE_c7[] = {"Classic", "PWM", "Vowels", "Harmonic Sweep", "Sync", "FM", "Organ", "Fold", "Digital", "Glass", "Odd Even", "Comb", "Custom", nullptr};
|
||||
inline const char *const WAVETABLE_c19[] = {"Auto", "256", "512", "1024", "2048", nullptr};
|
||||
inline const char *const WAVETABLE_c20[] = {"Low", "Band", "High", nullptr};
|
||||
inline const char *const WAVETABLE_c35[] = {"Sine", "Tri", "Saw", "Square", "S&H", nullptr};
|
||||
inline const ParamSpec WAVETABLE_params[] = {
|
||||
{"o1table", "Osc1 Table", 0.0f, 0.0f, 1.0f, false, WAVETABLE_c0},
|
||||
{"o1pos", "Osc1 Position", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"o1oct", "Osc1 Oct", 0.0f, -2.0f, 2.0f, true, nullptr},
|
||||
{"o1semi", "Osc1 Semi", 0.0f, -12.0f, 12.0f, true, nullptr},
|
||||
{"o1fine", "Osc1 Fine", 0.0f, -50.0f, 50.0f, false, nullptr},
|
||||
{"o1level", "Osc1 Level", 0.8f, 0.0f, 1.0f, false, nullptr},
|
||||
{"o1bend", "Osc1 Bend", 0.0f, -1.0f, 1.0f, false, nullptr},
|
||||
{"o2table", "Osc2 Table", 0.0f, 0.0f, 1.0f, false, WAVETABLE_c7},
|
||||
{"o2pos", "Osc2 Position", 0.3f, 0.0f, 1.0f, false, nullptr},
|
||||
{"o2oct", "Osc2 Oct", 0.0f, -2.0f, 2.0f, true, nullptr},
|
||||
{"o2semi", "Osc2 Semi", 0.0f, -12.0f, 12.0f, true, nullptr},
|
||||
{"o2fine", "Osc2 Fine", 7.0f, -50.0f, 50.0f, false, nullptr},
|
||||
{"o2level", "Osc2 Level", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"o2bend", "Osc2 Bend", 0.0f, -1.0f, 1.0f, false, nullptr},
|
||||
{"unison", "Unison", 1.0f, 1.0f, 4.0f, true, nullptr},
|
||||
{"spread", "Spread", 0.3f, 0.0f, 1.0f, false, nullptr},
|
||||
{"sub", "Sub", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"noise", "Noise", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"velsens", "Velocity", 0.5f, 0.0f, 1.0f, false, nullptr},
|
||||
{"wtframe", "Frame Size", 0.0f, 0.0f, 1.0f, false, WAVETABLE_c19},
|
||||
{"ftype", "Filter", 0.0f, 0.0f, 1.0f, false, WAVETABLE_c20},
|
||||
{"cutoff", "Cutoff", 0.75f, 0.0f, 1.0f, false, nullptr},
|
||||
{"reso", "Resonance", 0.15f, 0.0f, 1.0f, false, nullptr},
|
||||
{"keytrack", "Key Track", 0.4f, 0.0f, 1.0f, false, nullptr},
|
||||
{"fenv", "Env Amount", 0.2f, -1.0f, 1.0f, false, nullptr},
|
||||
{"drive", "Drive", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"attack", "Attack", 0.01f, 0.0f, 5.0f, false, nullptr},
|
||||
{"decay", "Decay", 0.3f, 0.0f, 5.0f, false, nullptr},
|
||||
{"sustain", "Sustain", 0.8f, 0.0f, 1.0f, false, nullptr},
|
||||
{"release", "Release", 0.4f, 0.0f, 8.0f, false, nullptr},
|
||||
{"mattack", "Mod Attack", 0.5f, 0.0f, 10.0f, false, nullptr},
|
||||
{"mdecay", "Mod Decay", 2.0f, 0.0f, 10.0f, false, nullptr},
|
||||
{"msustain", "Mod Sustain", 0.5f, 0.0f, 1.0f, false, nullptr},
|
||||
{"mrelease", "Mod Release", 1.0f, 0.0f, 10.0f, false, nullptr},
|
||||
{"menvpos", "Env > Position", 0.3f, -1.0f, 1.0f, false, nullptr},
|
||||
{"lfowave", "LFO Wave", 0.0f, 0.0f, 1.0f, false, WAVETABLE_c35},
|
||||
{"lfodiv", "LFO Sync", 1.0f, 0.0f, 6.0f, true, nullptr},
|
||||
{"lfopos", "LFO > Position", 0.15f, 0.0f, 1.0f, false, nullptr},
|
||||
{"lfopitch", "LFO > Pitch", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"lfocut", "LFO > Cutoff", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
};
|
||||
|
||||
inline const char *const ARPEGGIATOR_c0[] = {"Up", "Down", "UpDown", "Random", nullptr};
|
||||
inline const char *const ARPEGGIATOR_c3[] = {"Off", "On", nullptr};
|
||||
inline const ParamSpec ARPEGGIATOR_params[] = {
|
||||
{"mode", "Mode", 0.0f, 0.0f, 1.0f, false, ARPEGGIATOR_c0},
|
||||
{"octaves", "Octaves", 1.0f, 1.0f, 4.0f, true, nullptr},
|
||||
{"division", "Division", 3.0f, 0.0f, 6.0f, true, nullptr},
|
||||
{"resetbar", "Reset/Bar", 0.0f, 0.0f, 1.0f, false, ARPEGGIATOR_c3},
|
||||
};
|
||||
|
||||
inline const ParamSpec TRANSPOSER_params[] = {
|
||||
{"octaves", "Octaves", 0.0f, -4.0f, 4.0f, true, nullptr},
|
||||
{"semitones", "Semitones", 0.0f, -24.0f, 24.0f, true, nullptr},
|
||||
};
|
||||
|
||||
inline const char *const LFO_c0[] = {"Sine", "Triangle", "Saw", "Square", "SampleHold", nullptr};
|
||||
inline const ParamSpec LFO_params[] = {
|
||||
{"wave", "Wave", 0.0f, 0.0f, 1.0f, false, LFO_c0},
|
||||
{"phase", "Phase", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"depth", "Depth", 0.5f, 0.0f, 1.0f, false, nullptr},
|
||||
{"division", "Division", 3.0f, 0.0f, 6.0f, true, nullptr},
|
||||
};
|
||||
|
||||
inline const ParamSpec DELAY_params[] = {
|
||||
{"feedback", "Feedback", 0.4f, 0.0f, 0.9f, false, nullptr},
|
||||
{"drywet", "Dry/Wet", 0.35f, 0.0f, 1.0f, false, nullptr},
|
||||
{"tape", "Tape Strength", 0.3f, 0.0f, 1.0f, false, nullptr},
|
||||
{"head0On", "Head 1 On", 1.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"head0Div", "Head 1 Div", 5.0f, 0.0f, 12.0f, false, nullptr},
|
||||
{"head1On", "Head 2 On", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"head1Div", "Head 2 Div", 8.0f, 0.0f, 12.0f, false, nullptr},
|
||||
{"head2On", "Head 3 On", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"head2Div", "Head 3 Div", 3.0f, 0.0f, 12.0f, false, nullptr},
|
||||
{"head3On", "Head 4 On", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"head3Div", "Head 4 Div", 2.0f, 0.0f, 12.0f, false, nullptr},
|
||||
};
|
||||
|
||||
inline const char *const FILTER_c0[] = {"LPF", "HPF", "BPF", nullptr};
|
||||
inline const ParamSpec FILTER_params[] = {
|
||||
{"type", "Type", 0.0f, 0.0f, 1.0f, false, FILTER_c0},
|
||||
{"cutoff", "Cutoff", 0.7f, 0.0f, 1.0f, false, nullptr},
|
||||
{"resonance", "Resonance", 0.2f, 0.0f, 1.0f, false, nullptr},
|
||||
{"warmth", "Warmth", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"envamt", "Env Amount", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"attack", "Attack", 0.005f, 0.0f, 2.0f, false, nullptr},
|
||||
{"decay", "Decay", 0.1f, 0.0f, 2.0f, false, nullptr},
|
||||
{"sustain", "Sustain", 1.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"release", "Release", 0.2f, 0.0f, 3.0f, false, nullptr},
|
||||
};
|
||||
|
||||
inline const ParamSpec EQ10_params[] = {
|
||||
{"band0", "Band 1", 0.0f, -1.0f, 1.0f, false, nullptr},
|
||||
{"band1", "Band 2", 0.0f, -1.0f, 1.0f, false, nullptr},
|
||||
{"band2", "Band 3", 0.0f, -1.0f, 1.0f, false, nullptr},
|
||||
{"band3", "Band 4", 0.0f, -1.0f, 1.0f, false, nullptr},
|
||||
{"band4", "Band 5", 0.0f, -1.0f, 1.0f, false, nullptr},
|
||||
{"band5", "Band 6", 0.0f, -1.0f, 1.0f, false, nullptr},
|
||||
{"band6", "Band 7", 0.0f, -1.0f, 1.0f, false, nullptr},
|
||||
{"band7", "Band 8", 0.0f, -1.0f, 1.0f, false, nullptr},
|
||||
{"band8", "Band 9", 0.0f, -1.0f, 1.0f, false, nullptr},
|
||||
{"band9", "Band 10", 0.0f, -1.0f, 1.0f, false, nullptr},
|
||||
};
|
||||
|
||||
inline const ParamSpec BITCRUSHER_params[] = {
|
||||
{"bits", "Bits", 8.0f, 1.0f, 16.0f, true, nullptr},
|
||||
{"downsample", "Downsample", 1.0f, 1.0f, 32.0f, true, nullptr},
|
||||
{"drive", "Drive", 0.2f, 0.0f, 1.0f, false, nullptr},
|
||||
};
|
||||
|
||||
inline const char *const AMBIENCE_c0[] = {"Room 1", "Room 2", "Hall 1", "Hall 2", "Plate", "Spring", "Goldfoil", nullptr};
|
||||
inline const ParamSpec AMBIENCE_params[] = {
|
||||
{"algo", "Algorithm", 0.0f, 0.0f, 6.0f, false, AMBIENCE_c0},
|
||||
{"predelay", "Pre-Delay", 10.0f, 0.0f, 500.0f, false, nullptr},
|
||||
{"roomsize", "Room Size", 1.0f, 0.3f, 2.0f, false, nullptr},
|
||||
{"decay", "Decay", 1.5f, 0.1f, 20.0f, false, nullptr},
|
||||
{"hfdamp", "HF Damp", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"lfabsorb", "LF Absorb", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"diffusion", "Diffusion", 0.7f, 0.0f, 1.0f, false, nullptr},
|
||||
{"modamt", "Mod Amount", 0.25f, 0.0f, 1.0f, false, nullptr},
|
||||
{"modrate", "Mod Rate", 0.5f, 0.05f, 2.0f, false, nullptr},
|
||||
{"erlevel", "ER Level", 0.6f, 0.0f, 1.0f, false, nullptr},
|
||||
{"saturation", "Saturation", 0.0f, 0.0f, 1.0f, false, nullptr},
|
||||
{"wet", "Wet (dB)", -4.0f, -60.0f, 0.0f, false, nullptr},
|
||||
{"dry", "Dry (dB)", 0.0f, -60.0f, 0.0f, false, nullptr},
|
||||
{"duckamt", "Ducking (dB)", 0.0f, 0.0f, 20.0f, false, nullptr},
|
||||
{"duckthresh", "Duck Thresh (dB)", -20.0f, -60.0f, 0.0f, false, nullptr},
|
||||
{"duckattack", "Duck Attack (ms)", 10.0f, 0.5f, 100.0f, false, nullptr},
|
||||
{"duckrelease", "Duck Release (ms)", 200.0f, 10.0f, 2000.0f, false, nullptr},
|
||||
};
|
||||
|
||||
inline const ParamSpec MIX_TIGHTENER_params[] = {
|
||||
{"strength", "Strength", 1.0f, 0.0f, 1.0f, false, nullptr},
|
||||
};
|
||||
|
||||
inline const ParamSpec TAPE_ENGINE_params[] = {
|
||||
{"speed", "Speed", 1.0f, 0.25f, 1.0f, false, nullptr},
|
||||
{"wow", "Wow", 0.15f, 0.0f, 1.0f, false, nullptr},
|
||||
{"flutter", "Flutter", 0.15f, 0.0f, 1.0f, false, nullptr},
|
||||
{"hiss", "Hiss", 0.1f, 0.0f, 1.0f, false, nullptr},
|
||||
{"division", "Wow Sync", 2.0f, 0.0f, 6.0f, true, nullptr},
|
||||
};
|
||||
|
||||
inline const ParamSpec GRANULAR_params[] = {
|
||||
{"intensity", "Intensity", 0.3f, 0.0f, 1.0f, false, nullptr},
|
||||
};
|
||||
|
||||
inline const DeviceSpec devices[] = {
|
||||
{"NES_SYNTH", "Synth", Kind::Instrument, NES_SYNTH_params, 43},
|
||||
{"SAMPLER", "Sampler", Kind::Instrument, SAMPLER_params, 2},
|
||||
{"SOUNDFONT", "SF2 / XI Loader", Kind::Instrument, SOUNDFONT_params, 8},
|
||||
{"MORPH_PAD", "Morph Pad", Kind::Instrument, MORPH_PAD_params, 36},
|
||||
{"GRAIN_CLOUD", "Grain Cloud", Kind::Instrument, GRAIN_CLOUD_params, 24},
|
||||
{"WAVETABLE", "Wavetable", Kind::Instrument, WAVETABLE_params, 40},
|
||||
{"ARPEGGIATOR", "MIDI Arpeggiator", Kind::Effect, ARPEGGIATOR_params, 4},
|
||||
{"TRANSPOSER", "MIDI Transposer", Kind::Effect, TRANSPOSER_params, 2},
|
||||
{"LFO", "MIDI LFO", Kind::Effect, LFO_params, 4},
|
||||
{"DELAY", "Tape Delay", Kind::Effect, DELAY_params, 11},
|
||||
{"FILTER", "Filter (LP/HP/BP)", Kind::Effect, FILTER_params, 9},
|
||||
{"EQ10", "10-Band EQ", Kind::Effect, EQ10_params, 10},
|
||||
{"BITCRUSHER", "Bitcrusher", Kind::Effect, BITCRUSHER_params, 3},
|
||||
{"AMBIENCE", "Ambience Reverb", Kind::Effect, AMBIENCE_params, 17},
|
||||
{"MIX_TIGHTENER", "Mix Tightener", Kind::Effect, MIX_TIGHTENER_params, 1},
|
||||
{"TAPE_ENGINE", "Tape Engine", Kind::Effect, TAPE_ENGINE_params, 5},
|
||||
{"GRANULAR", "Granular Glitch", Kind::Effect, GRANULAR_params, 1},
|
||||
};
|
||||
inline constexpr int deviceCount = 17;
|
||||
|
||||
// Mix Tightener factory presets: name, then key/value pairs, nullptr-terminated.
|
||||
inline const char *const mixTightener0[] = {"808 Crisp", "cHiAtk", "3", "cHiMk", "2", "cHiRatio", "3", "cHiRel", "80", "cHiThr", "-24", "cLoAtk", "8", "cLoMk", "3", "cLoRatio", "4", "cLoRel", "140", "cLoThr", "-22", "cMidMk", "1", "cMidRatio", "2.5", "cMidThr", "-20", "eqHiFreq", "9000", "eqHiGain", "4", "eqLoFreq", "70", "eqLoGain", "4", "eqMidFreq", "450", "eqMidGain", "-2", "limCeil", "-0.3", "limRel", "80", "outGain", "2", "xHi", "3000", "xLo", "120", nullptr};
|
||||
inline const char *const mixTightener1[] = {"Boom-Bap Kit", "cLoAtk", "12", "cLoMk", "2", "cLoRatio", "3", "cLoRel", "160", "cLoThr", "-20", "cMidMk", "1", "cMidRatio", "2.5", "cMidThr", "-18", "eqHiFreq", "10000", "eqHiGain", "1.5", "eqLoFreq", "90", "eqLoGain", "2", "limCeil", "-0.5", "outGain", "1.5", "xHi", "2500", "xLo", "160", nullptr};
|
||||
inline const char *const mixTightener2[] = {"Trap Hats", "cHiAtk", "2", "cHiMk", "2", "cHiRatio", "4", "cHiRel", "60", "cHiThr", "-26", "cLoRatio", "1.5", "cMidRatio", "2", "eqHiFreq", "11000", "eqHiGain", "5", "eqMidFreq", "4000", "eqMidGain", "1", "limCeil", "-0.3", "outGain", "2", "xHi", "4000", nullptr};
|
||||
inline const char *const mixTightener3[] = {"Industrial Drums", "cHiMk", "2", "cHiRatio", "3", "cHiThr", "-20", "cLoAtk", "6", "cLoMk", "3", "cLoRatio", "5", "cLoRel", "120", "cLoThr", "-18", "cMidAtk", "8", "cMidMk", "3", "cMidRatio", "4", "cMidRel", "120", "cMidThr", "-16", "eqHiFreq", "8000", "eqHiGain", "2", "eqLoFreq", "80", "eqLoGain", "3", "eqMidFreq", "2200", "eqMidGain", "3", "eqMidQ", "1.2", "limCeil", "-0.2", "limRel", "60", "outGain", "3", "xHi", "2000", "xLo", "150", nullptr};
|
||||
inline const char *const mixTightener4[] = {"Techno Kick", "cHiRatio", "1.5", "cLoAtk", "4", "cLoMk", "3", "cLoRatio", "6", "cLoRel", "100", "cLoThr", "-16", "cMidRatio", "2", "eqLoFreq", "60", "eqLoGain", "3", "eqMidFreq", "700", "eqMidGain", "-2", "limCeil", "-0.2", "outGain", "2.5", "xHi", "3000", "xLo", "120", nullptr};
|
||||
inline const char *const mixTightener5[] = {"House Groove", "cHiMk", "1", "cHiRatio", "2", "cHiThr", "-22", "cLoMk", "1.5", "cLoRatio", "2.5", "cLoThr", "-22", "cMidMk", "1", "cMidRatio", "2", "cMidThr", "-20", "eqHiFreq", "9000", "eqHiGain", "1.5", "eqLoFreq", "90", "eqLoGain", "1.5", "limCeil", "-0.5", "outGain", "1.5", "strength", "0.85", "xHi", "2600", "xLo", "180", nullptr};
|
||||
inline const char *const mixTightener6[] = {"DnB Breaks", "cHiAtk", "2", "cHiMk", "2", "cHiRatio", "3", "cHiRel", "60", "cHiThr", "-22", "cLoAtk", "3", "cLoMk", "2", "cLoRatio", "4", "cLoRel", "90", "cLoThr", "-18", "cMidAtk", "4", "cMidMk", "2", "cMidRatio", "3", "cMidRel", "90", "cMidThr", "-18", "eqHiFreq", "9000", "eqHiGain", "2", "eqLoFreq", "80", "eqLoGain", "2", "eqMidFreq", "2500", "eqMidGain", "1.5", "limCeil", "-0.3", "limRel", "50", "outGain", "2", "xHi", "2500", "xLo", "150", nullptr};
|
||||
inline const char *const mixTightener7[] = {"Lo-Fi Kit", "cHiRatio", "1.5", "cLoMk", "1", "cLoRatio", "2.5", "cLoThr", "-22", "cMidRatio", "2", "eqHiFreq", "6000", "eqHiGain", "-4", "eqLoFreq", "100", "eqLoGain", "2", "eqMidFreq", "500", "eqMidGain", "1", "limCeil", "-1", "outGain", "1", "strength", "0.8", "xHi", "2200", "xLo", "200", nullptr};
|
||||
inline const char *const mixTightener8[] = {"Snare Crack", "cHiAtk", "2", "cHiMk", "2", "cHiRatio", "3", "cHiRel", "70", "cHiThr", "-22", "cLoRatio", "1.5", "cMidAtk", "3", "cMidMk", "2", "cMidRatio", "4", "cMidRel", "100", "cMidThr", "-18", "eqHiFreq", "8000", "eqHiGain", "3", "eqLoFreq", "200", "eqLoGain", "-2", "eqMidFreq", "2000", "eqMidGain", "3", "eqMidQ", "1.5", "limCeil", "-0.3", "outGain", "2", "xHi", "1800", "xLo", "250", nullptr};
|
||||
inline const char *const mixTightener9[] = {"Clap Snap", "cHiAtk", "2", "cHiMk", "2", "cHiRatio", "3", "cLoRatio", "1.5", "cMidAtk", "3", "cMidMk", "1", "cMidRatio", "3", "eqHiFreq", "9000", "eqHiGain", "4", "eqMidFreq", "1500", "eqMidGain", "2", "outGain", "2", "xHi", "3000", nullptr};
|
||||
inline const char *const mixTightener10[] = {"Cymbal Sheen", "cHiAtk", "5", "cHiMk", "1", "cHiRatio", "2.5", "cHiRel", "120", "cHiThr", "-26", "eqHiFreq", "12000", "eqHiGain", "4", "eqMidFreq", "3000", "eqMidGain", "-1", "limCeil", "-0.5", "outGain", "1.5", "strength", "0.75", "xHi", "5000", nullptr};
|
||||
inline const char *const mixTightener11[] = {"Percussion Tight", "cHiMk", "1", "cHiRatio", "2.5", "cLoMk", "1", "cLoRatio", "2", "cMidAtk", "4", "cMidMk", "1.5", "cMidRatio", "3", "eqHiFreq", "8000", "eqHiGain", "2", "eqMidFreq", "2500", "eqMidGain", "1.5", "outGain", "1.5", "xHi", "2500", "xLo", "200", nullptr};
|
||||
inline const char *const mixTightener12[] = {"EBM Bass", "cHiRatio", "1.5", "cLoAtk", "10", "cLoMk", "3", "cLoRatio", "4", "cLoRel", "130", "cLoThr", "-18", "cMidAtk", "12", "cMidMk", "2", "cMidRatio", "3", "cMidRel", "130", "cMidThr", "-18", "eqHiFreq", "9000", "eqHiGain", "-2", "eqLoFreq", "80", "eqLoGain", "3", "eqMidFreq", "800", "eqMidGain", "2", "eqMidQ", "1.2", "limCeil", "-0.3", "outGain", "2.5", "xHi", "1500", "xLo", "150", nullptr};
|
||||
inline const char *const mixTightener13[] = {"Reese Bass", "cHiRatio", "1.5", "cLoAtk", "8", "cLoMk", "3", "cLoRatio", "5", "cLoRel", "120", "cLoThr", "-16", "cMidMk", "2", "cMidRatio", "3", "cMidThr", "-18", "eqLoFreq", "70", "eqLoGain", "2", "eqMidFreq", "500", "eqMidGain", "2", "limCeil", "-0.3", "outGain", "2", "xHi", "1200", "xLo", "140", nullptr};
|
||||
inline const char *const mixTightener14[] = {"Acid 303", "cHiRatio", "2", "cLoMk", "2", "cLoRatio", "3", "cMidAtk", "6", "cMidMk", "2", "cMidRatio", "4", "cMidRel", "110", "cMidThr", "-18", "eqLoFreq", "90", "eqLoGain", "1", "eqMidFreq", "1200", "eqMidGain", "3", "eqMidQ", "1.5", "limCeil", "-0.4", "outGain", "2", "xHi", "1800", "xLo", "160", nullptr};
|
||||
inline const char *const mixTightener15[] = {"Sub Bass Tame", "cHiRatio", "1.2", "cLoAtk", "12", "cLoMk", "3", "cLoRatio", "6", "cLoRel", "150", "cLoThr", "-14", "cMidRatio", "2", "eqLoFreq", "55", "eqLoGain", "2", "eqMidFreq", "900", "eqMidGain", "-2", "limCeil", "-0.5", "outGain", "2", "strength", "0.9", "xHi", "2000", "xLo", "120", nullptr};
|
||||
inline const char *const mixTightener16[] = {"FM Bass Punch", "cHiRatio", "2", "cLoAtk", "6", "cLoMk", "2", "cLoRatio", "4", "cLoRel", "110", "cLoThr", "-18", "cMidMk", "1.5", "cMidRatio", "3", "cMidThr", "-18", "eqLoFreq", "90", "eqLoGain", "2", "eqMidFreq", "1000", "eqMidGain", "1.5", "limCeil", "-0.3", "outGain", "2", "xHi", "2200", "xLo", "160", nullptr};
|
||||
inline const char *const mixTightener17[] = {"Goth Bass", "cHiRatio", "1.5", "cLoAtk", "10", "cLoMk", "3", "cLoRatio", "4", "cLoRel", "140", "cLoThr", "-18", "cMidMk", "1", "cMidRatio", "2.5", "eqHiFreq", "8000", "eqHiGain", "-2", "eqLoFreq", "75", "eqLoGain", "3", "eqMidFreq", "600", "eqMidGain", "-1", "limCeil", "-0.5", "outGain", "2", "strength", "0.9", "xHi", "1600", "xLo", "140", nullptr};
|
||||
inline const char *const mixTightener18[] = {"Synthwave Bass", "cHiRatio", "2", "cLoAtk", "10", "cLoMk", "2", "cLoRatio", "3", "cLoRel", "130", "cLoThr", "-20", "cMidMk", "1", "cMidRatio", "2.5", "eqHiFreq", "7000", "eqHiGain", "1", "eqLoFreq", "80", "eqLoGain", "2.5", "eqMidFreq", "900", "eqMidGain", "1", "limCeil", "-0.5", "outGain", "1.8", "xHi", "2000", "xLo", "150", nullptr};
|
||||
inline const char *const mixTightener19[] = {"Synthwave Lead", "cHiMk", "1.5", "cHiRatio", "2", "cHiThr", "-22", "cLoRatio", "1.5", "cMidAtk", "12", "cMidMk", "1.5", "cMidRatio", "2.5", "cMidRel", "150", "cMidThr", "-20", "eqHiFreq", "9000", "eqHiGain", "4", "eqLoFreq", "200", "eqLoGain", "-1", "eqMidFreq", "2000", "eqMidGain", "1.5", "limCeil", "-0.5", "outGain", "2", "strength", "0.85", "xHi", "3000", "xLo", "300", nullptr};
|
||||
inline const char *const mixTightener20[] = {"Cutting Lead", "cHiMk", "1", "cHiRatio", "2", "cLoRatio", "1.5", "cMidAtk", "8", "cMidMk", "2", "cMidRatio", "3", "cMidRel", "130", "cMidThr", "-18", "eqHiFreq", "8000", "eqHiGain", "2", "eqLoFreq", "200", "eqLoGain", "-2", "eqMidFreq", "3000", "eqMidGain", "3", "eqMidQ", "1.2", "limCeil", "-0.4", "outGain", "2", "xHi", "3500", "xLo", "300", nullptr};
|
||||
inline const char *const mixTightener21[] = {"Darkwave Pad", "cHiRatio", "2", "cLoMk", "1", "cLoRatio", "2", "cMidAtk", "20", "cMidMk", "1", "cMidRatio", "2", "cMidRel", "200", "cMidThr", "-24", "eqHiFreq", "8000", "eqHiGain", "-2", "eqLoFreq", "150", "eqLoGain", "1", "eqMidFreq", "1000", "eqMidGain", "0.5", "limCeil", "-1", "outGain", "1", "strength", "0.7", "xHi", "2500", "xLo", "250", nullptr};
|
||||
inline const char *const mixTightener22[] = {"Ambient Wash", "cMidAtk", "30", "cMidMk", "0.5", "cMidRatio", "1.8", "cMidRel", "250", "cMidThr", "-26", "eqHiFreq", "10000", "eqHiGain", "1", "eqLoFreq", "120", "eqLoGain", "1", "limCeil", "-1.5", "outGain", "0.5", "strength", "0.6", "xHi", "3000", "xLo", "300", nullptr};
|
||||
inline const char *const mixTightener23[] = {"Pluck Tight", "cHiAtk", "2", "cHiMk", "1.5", "cHiRatio", "2.5", "cHiRel", "70", "cHiThr", "-22", "cLoRatio", "1.5", "cMidAtk", "3", "cMidMk", "1.5", "cMidRatio", "3", "cMidRel", "100", "cMidThr", "-18", "eqHiFreq", "9000", "eqHiGain", "3", "eqMidFreq", "2500", "eqMidGain", "2", "outGain", "1.5", "xHi", "3000", "xLo", "300", nullptr};
|
||||
inline const char *const mixTightener24[] = {"Arp Sparkle", "cHiAtk", "4", "cHiMk", "1.5", "cHiRatio", "2.5", "cHiThr", "-24", "cMidMk", "1", "cMidRatio", "2", "eqHiFreq", "11000", "eqHiGain", "4", "eqMidFreq", "3000", "eqMidGain", "1", "limCeil", "-0.5", "outGain", "1.5", "strength", "0.8", "xHi", "4000", nullptr};
|
||||
inline const char *const mixTightener25[] = {"Chip Lead", "cHiMk", "1", "cHiRatio", "2", "cLoRatio", "1.2", "cMidMk", "2", "cMidRatio", "3", "cMidThr", "-18", "eqHiFreq", "8000", "eqHiGain", "2", "eqLoFreq", "150", "eqLoGain", "-3", "eqMidFreq", "2500", "eqMidGain", "2.5", "eqMidQ", "1.2", "limCeil", "-0.4", "outGain", "2", "xHi", "3000", "xLo", "350", nullptr};
|
||||
inline const char *const mixTightener26[] = {"Bell Clarity", "cHiAtk", "4", "cHiMk", "1", "cHiRatio", "2", "cMidAtk", "6", "cMidMk", "1", "cMidRatio", "2", "eqHiFreq", "10000", "eqHiGain", "3", "eqMidFreq", "1800", "eqMidGain", "1.5", "limCeil", "-0.5", "outGain", "1", "strength", "0.75", "xHi", "4000", nullptr};
|
||||
inline const char *const mixTightener27[] = {"Keys Clarity", "cHiMk", "1", "cHiRatio", "2", "cLoRatio", "1.8", "cMidAtk", "10", "cMidMk", "1", "cMidRatio", "2.5", "cMidRel", "150", "cMidThr", "-22", "eqHiFreq", "9000", "eqHiGain", "2", "eqLoFreq", "200", "eqLoGain", "-1", "eqMidFreq", "2500", "eqMidGain", "1.5", "limCeil", "-0.5", "outGain", "1.5", "strength", "0.8", "xHi", "3000", "xLo", "250", nullptr};
|
||||
inline const char *const mixTightener28[] = {"Mix Glue", "cHiAtk", "15", "cHiMk", "1", "cHiRatio", "2", "cHiRel", "180", "cHiThr", "-22", "cLoAtk", "20", "cLoMk", "1", "cLoRatio", "2", "cLoRel", "200", "cLoThr", "-22", "cMidAtk", "25", "cMidMk", "1", "cMidRatio", "2", "cMidRel", "200", "cMidThr", "-22", "eqHiFreq", "10000", "eqHiGain", "1", "eqLoFreq", "100", "eqLoGain", "0.5", "limCeil", "-0.8", "outGain", "1", "strength", "0.7", "xHi", "2500", "xLo", "200", nullptr};
|
||||
inline const char *const mixTightener29[] = {"Loudness Max", "cHiMk", "2", "cHiRatio", "3", "cHiThr", "-20", "cLoMk", "2", "cLoRatio", "3", "cLoThr", "-20", "cMidMk", "2", "cMidRatio", "3", "cMidThr", "-18", "eqHiFreq", "9000", "eqHiGain", "2", "eqLoFreq", "90", "eqLoGain", "1", "limCeil", "-0.1", "limRel", "40", "outGain", "4", "xHi", "2800", "xLo", "180", nullptr};
|
||||
inline const char *const *const mixTightenerPresets[] = {mixTightener0, mixTightener1, mixTightener2, mixTightener3, mixTightener4, mixTightener5, mixTightener6, mixTightener7, mixTightener8, mixTightener9, mixTightener10, mixTightener11, mixTightener12, mixTightener13, mixTightener14, mixTightener15, mixTightener16, mixTightener17, mixTightener18, mixTightener19, mixTightener20, mixTightener21, mixTightener22, mixTightener23, mixTightener24, mixTightener25, mixTightener26, mixTightener27, mixTightener28, mixTightener29, nullptr};
|
||||
|
||||
// Factory presets (PresetLibrary.seedFactoryPresets): device, name, then the
|
||||
// slot's full settings as key/value pairs, nullptr-terminated.
|
||||
inline const char *const factory0[] = {"algo", "Room 1", "decay", "0.45", "diffusion", "0.55", "dry", "0.0", "duckamt", "0.0", "duckattack", "10.0", "duckrelease", "200.0", "duckthresh", "-20.0", "erlevel", "0.7", "hfdamp", "0.0", "lfabsorb", "0.0", "modamt", "0.15", "modrate", "0.3", "predelay", "10.0", "roomsize", "0.75", "saturation", "0.08", "wet", "-6.0", nullptr};
|
||||
inline const char *const factory1[] = {"algo", "Room 2", "decay", "1.8", "diffusion", "0.7", "dry", "0.0", "duckamt", "0.0", "duckattack", "10.0", "duckrelease", "200.0", "duckthresh", "-20.0", "erlevel", "0.6", "hfdamp", "0.0", "lfabsorb", "0.0", "modamt", "0.25", "modrate", "0.4", "predelay", "10.0", "roomsize", "1.6", "saturation", "0.08", "wet", "-4.0", nullptr};
|
||||
inline const char *const factory2[] = {"algo", "Room 2", "decay", "1.4", "diffusion", "0.65", "dry", "0.0", "duckamt", "0.0", "duckattack", "10.0", "duckrelease", "200.0", "duckthresh", "-20.0", "erlevel", "0.65", "hfdamp", "0.0", "lfabsorb", "0.0", "modamt", "0.2", "modrate", "0.35", "predelay", "10.0", "roomsize", "1.35", "saturation", "0.1", "wet", "-4.0", nullptr};
|
||||
inline const char *const factory3[] = {"algo", "Room 2", "decay", "2.0", "diffusion", "0.75", "dry", "0.0", "duckamt", "0.0", "duckattack", "10.0", "duckrelease", "200.0", "duckthresh", "-20.0", "erlevel", "0.55", "hfdamp", "0.0", "lfabsorb", "0.0", "modamt", "0.3", "modrate", "0.45", "predelay", "10.0", "roomsize", "1.7", "saturation", "0.06", "wet", "-4.0", nullptr};
|
||||
inline const char *const factory4[] = {"algo", "Hall 1", "decay", "1.7", "diffusion", "0.72", "dry", "0.0", "duckamt", "0.0", "duckattack", "10.0", "duckrelease", "200.0", "duckthresh", "-20.0", "erlevel", "0.55", "hfdamp", "0.0", "lfabsorb", "0.0", "modamt", "0.2", "modrate", "0.3", "predelay", "10.0", "roomsize", "1.5", "saturation", "0.08", "wet", "-4.0", nullptr};
|
||||
inline const char *const factory5[] = {"algo", "Hall 1", "decay", "2.0", "diffusion", "0.75", "dry", "0.0", "duckamt", "0.0", "duckattack", "10.0", "duckrelease", "200.0", "duckthresh", "-20.0", "erlevel", "0.5", "hfdamp", "0.0", "lfabsorb", "0.0", "modamt", "0.25", "modrate", "0.35", "predelay", "10.0", "roomsize", "1.65", "saturation", "0.06", "wet", "-4.0", nullptr};
|
||||
inline const char *const factory6[] = {"algo", "Hall 1", "decay", "2.0", "diffusion", "0.73", "dry", "0.0", "duckamt", "0.0", "duckattack", "10.0", "duckrelease", "200.0", "duckthresh", "-20.0", "erlevel", "0.52", "hfdamp", "0.0", "lfabsorb", "0.0", "modamt", "0.22", "modrate", "0.32", "predelay", "10.0", "roomsize", "1.6", "saturation", "0.07", "wet", "0.0", nullptr};
|
||||
inline const char *const factory7[] = {"algo", "Hall 2", "decay", "2.05", "diffusion", "0.8", "dry", "0.0", "duckamt", "0.0", "duckattack", "10.0", "duckrelease", "200.0", "duckthresh", "-20.0", "erlevel", "0.5", "hfdamp", "0.0", "lfabsorb", "0.0", "modamt", "0.25", "modrate", "0.3", "predelay", "10.0", "roomsize", "1.8", "saturation", "0.07", "wet", "-4.0", nullptr};
|
||||
inline const char *const factory8[] = {"algo", "Hall 2", "decay", "1.85", "diffusion", "0.78", "dry", "0.0", "duckamt", "0.0", "duckattack", "10.0", "duckrelease", "200.0", "duckthresh", "-20.0", "erlevel", "0.52", "hfdamp", "0.0", "lfabsorb", "0.0", "modamt", "0.22", "modrate", "0.28", "predelay", "10.0", "roomsize", "1.7", "saturation", "0.06", "wet", "-4.0", nullptr};
|
||||
inline const char *const factory9[] = {"algo", "Hall 2", "decay", "2.05", "diffusion", "0.82", "dry", "0.0", "duckamt", "0.0", "duckattack", "10.0", "duckrelease", "200.0", "duckthresh", "-20.0", "erlevel", "0.48", "hfdamp", "0.0", "lfabsorb", "0.0", "modamt", "0.28", "modrate", "0.32", "predelay", "10.0", "roomsize", "1.85", "saturation", "0.06", "wet", "-4.0", nullptr};
|
||||
inline const char *const factory10[] = {"algo", "Plate", "decay", "1.8", "diffusion", "0.85", "dry", "0.0", "duckamt", "0.0", "duckattack", "10.0", "duckrelease", "200.0", "duckthresh", "-20.0", "erlevel", "0.4", "hfdamp", "0.0", "lfabsorb", "0.0", "modamt", "0.3", "modrate", "0.5", "predelay", "10.0", "roomsize", "1.0", "saturation", "0.12", "wet", "-4.0", nullptr};
|
||||
inline const char *const factory11[] = {"algo", "Plate", "decay", "1.0", "diffusion", "0.8", "dry", "0.0", "duckamt", "0.0", "duckattack", "10.0", "duckrelease", "200.0", "duckthresh", "-20.0", "erlevel", "0.35", "hfdamp", "0.0", "lfabsorb", "0.0", "modamt", "0.2", "modrate", "0.45", "predelay", "10.0", "roomsize", "0.8", "saturation", "0.15", "wet", "-4.0", nullptr};
|
||||
inline const char *const factory12[] = {"algo", "Plate", "decay", "2.5", "diffusion", "0.88", "dry", "0.0", "duckamt", "0.0", "duckattack", "10.0", "duckrelease", "200.0", "duckthresh", "-20.0", "erlevel", "0.1", "hfdamp", "0.0", "lfabsorb", "0.0", "modamt", "0.35", "modrate", "0.55", "predelay", "10.0", "roomsize", "1.2", "saturation", "0.1", "wet", "-4.0", nullptr};
|
||||
inline const char *const factory13[] = {"algo", "Spring", "decay", "1.5", "diffusion", "0.45", "dry", "0.0", "duckamt", "0.0", "duckattack", "10.0", "duckrelease", "200.0", "duckthresh", "-20.0", "erlevel", "0.45", "hfdamp", "0.0", "lfabsorb", "0.0", "modamt", "0.5", "modrate", "0.7", "predelay", "10.0", "roomsize", "0.7", "saturation", "0.2", "wet", "-4.0", nullptr};
|
||||
inline const char *const factory14[] = {"algo", "Plate", "decay", "2.2", "diffusion", "0.5", "dry", "0.0", "duckamt", "0.0", "duckattack", "10.0", "duckrelease", "200.0", "duckthresh", "-20.0", "erlevel", "0.4", "hfdamp", "0.0", "lfabsorb", "0.0", "modamt", "0.55", "modrate", "0.65", "predelay", "10.0", "roomsize", "0.85", "saturation", "0.35", "wet", "-4.0", nullptr};
|
||||
inline const char *const factory15[] = {"algo", "Spring", "decay", "3.5", "diffusion", "0.55", "dry", "0.0", "duckamt", "0.0", "duckattack", "10.0", "duckrelease", "200.0", "duckthresh", "-20.0", "erlevel", "0.38", "hfdamp", "0.0", "lfabsorb", "0.0", "modamt", "0.6", "modrate", "0.6", "predelay", "10.0", "roomsize", "1.1", "saturation", "0.45", "wet", "-4.0", nullptr};
|
||||
inline const char *const factory16[] = {"algo", "Goldfoil", "decay", "8.0", "diffusion", "0.9", "dry", "0.0", "duckamt", "0.0", "duckattack", "10.0", "duckrelease", "200.0", "duckthresh", "-20.0", "erlevel", "0.35", "hfdamp", "0.0", "lfabsorb", "0.0", "modamt", "0.4", "modrate", "0.25", "predelay", "10.0", "roomsize", "2.0", "saturation", "0.05", "wet", "-4.0", nullptr};
|
||||
inline const char *const factory17[] = {"algo", "Goldfoil", "decay", "4.0", "diffusion", "0.85", "dry", "0.0", "duckamt", "0.0", "duckattack", "10.0", "duckrelease", "200.0", "duckthresh", "-20.0", "erlevel", "0.4", "hfdamp", "0.0", "lfabsorb", "0.0", "modamt", "0.45", "modrate", "0.3", "predelay", "10.0", "roomsize", "1.8", "saturation", "0.2", "wet", "-4.0", nullptr};
|
||||
inline const char *const factory18[] = {"algo", "Goldfoil", "decay", "12.0", "diffusion", "0.95", "dry", "0.0", "duckamt", "0.0", "duckattack", "10.0", "duckrelease", "200.0", "duckthresh", "-20.0", "erlevel", "0.25", "hfdamp", "0.0", "lfabsorb", "0.0", "modamt", "0.65", "modrate", "0.28", "predelay", "10.0", "roomsize", "2.0", "saturation", "0.1", "wet", "-4.0", nullptr};
|
||||
inline const char *const factory19[] = {"algo", "Room 1", "decay", "0.3", "diffusion", "0.4", "dry", "0.0", "duckamt", "0.0", "duckattack", "10.0", "duckrelease", "200.0", "duckthresh", "-20.0", "erlevel", "0.8", "hfdamp", "0.0", "lfabsorb", "0.0", "modamt", "0.1", "modrate", "0.2", "predelay", "10.0", "roomsize", "0.55", "saturation", "0.05", "wet", "-4.0", nullptr};
|
||||
inline const char *const factory20[] = {"algo", "Room 1", "decay", "0.6", "diffusion", "0.65", "dry", "0.0", "duckamt", "0.0", "duckattack", "10.0", "duckrelease", "200.0", "duckthresh", "-20.0", "erlevel", "0.65", "hfdamp", "0.0", "lfabsorb", "0.0", "modamt", "0.2", "modrate", "0.35", "predelay", "10.0", "roomsize", "0.9", "saturation", "0.1", "wet", "-4.0", nullptr};
|
||||
inline const char *const factory21[] = {"attack", "0.005", "cutoff", "0.8", "decay", "0.1", "fatk", "0.005", "fdec", "0.25", "fenvamt", "0.2", "frel", "0.2", "fsus", "0.4", "keytrack", "0.3", "lfodiv", "3.0", "lfophase", "0°", "lfowave", "Tri", "m0amt", "0.0", "m0dst", "Pitch", "m0src", "Off", "m1amt", "0.0", "m1dst", "Pitch", "m1src", "Off", "m2amt", "0.0", "m2dst", "Pitch", "m2src", "Off", "m3amt", "0.0", "m3dst", "Pitch", "m3src", "Off", "noise", "0.0", "osc0fine", "0.0", "osc0level", "0.9", "osc0oct", "0.0", "osc0semi", "0.0", "osc0wave", "Pulse25", "osc1fine", "0.0", "osc1level", "0.0", "osc1oct", "0.0", "osc1semi", "0.0", "osc1wave", "Tri", "osc2fine", "0.0", "osc2level", "0.0", "osc2oct", "0.0", "osc2semi", "0.0", "osc2wave", "Tri", "release", "0.1", "reso", "0.1", "sustain", "0.85", nullptr};
|
||||
inline const char *const factory22[] = {"attack", "0.002", "cutoff", "0.45", "decay", "0.15", "fatk", "0.005", "fdec", "0.18", "fenvamt", "0.5", "frel", "0.2", "fsus", "0.2", "keytrack", "0.3", "lfodiv", "3.0", "lfophase", "0°", "lfowave", "Tri", "m0amt", "0.0", "m0dst", "Pitch", "m0src", "Off", "m1amt", "0.0", "m1dst", "Pitch", "m1src", "Off", "m2amt", "0.0", "m2dst", "Pitch", "m2src", "Off", "m3amt", "0.0", "m3dst", "Pitch", "m3src", "Off", "noise", "0.0", "osc0fine", "0.0", "osc0level", "0.9", "osc0oct", "-1", "osc0semi", "0.0", "osc0wave", "Square", "osc1fine", "6", "osc1level", "0.5", "osc1oct", "-1", "osc1semi", "0.0", "osc1wave", "Pulse25", "osc2fine", "0.0", "osc2level", "0.0", "osc2oct", "0.0", "osc2semi", "0.0", "osc2wave", "Tri", "release", "0.12", "reso", "0.25", "sustain", "0.6", nullptr};
|
||||
inline const char *const factory23[] = {"attack", "0.002", "cutoff", "0.5", "decay", "0.2", "fatk", "0.002", "fdec", "0.12", "fenvamt", "0.6", "frel", "0.2", "fsus", "0.1", "keytrack", "0.3", "lfodiv", "4", "lfophase", "0°", "lfowave", "Tri", "m0amt", "0.5", "m0dst", "PWM", "m0src", "LFO", "m1amt", "0.0", "m1dst", "Pitch", "m1src", "Off", "m2amt", "0.0", "m2dst", "Pitch", "m2src", "Off", "m3amt", "0.0", "m3dst", "Pitch", "m3src", "Off", "noise", "0.0", "osc0fine", "0.0", "osc0level", "0.9", "osc0oct", "0.0", "osc0semi", "0.0", "osc0wave", "Pulse12", "osc1fine", "0.0", "osc1level", "0.0", "osc1oct", "0.0", "osc1semi", "0.0", "osc1wave", "Tri", "osc2fine", "0.0", "osc2level", "0.0", "osc2oct", "0.0", "osc2semi", "0.0", "osc2wave", "Tri", "release", "0.15", "reso", "0.3", "sustain", "0.4", nullptr};
|
||||
inline const char *const factory24[] = {"attack", "0.004", "cutoff", "0.35", "decay", "0.2", "fatk", "0.005", "fdec", "0.25", "fenvamt", "0.2", "frel", "0.2", "fsus", "0.4", "keytrack", "0.3", "lfodiv", "3.0", "lfophase", "0°", "lfowave", "Tri", "m0amt", "0.0", "m0dst", "Pitch", "m0src", "Off", "m1amt", "0.0", "m1dst", "Pitch", "m1src", "Off", "m2amt", "0.0", "m2dst", "Pitch", "m2src", "Off", "m3amt", "0.0", "m3dst", "Pitch", "m3src", "Off", "noise", "0.0", "osc0fine", "0.0", "osc0level", "1.0", "osc0oct", "-1", "osc0semi", "0.0", "osc0wave", "Tri", "osc1fine", "0.0", "osc1level", "0.0", "osc1oct", "0.0", "osc1semi", "0.0", "osc1wave", "Tri", "osc2fine", "0.0", "osc2level", "0.0", "osc2oct", "0.0", "osc2semi", "0.0", "osc2wave", "Tri", "release", "0.15", "reso", "0.05", "sustain", "0.7", nullptr};
|
||||
inline const char *const factory25[] = {"attack", "0.01", "cutoff", "0.7", "decay", "0.3", "fatk", "0.005", "fdec", "0.25", "fenvamt", "0.3", "frel", "0.2", "fsus", "0.4", "keytrack", "0.3", "lfodiv", "3.0", "lfophase", "0°", "lfowave", "Tri", "m0amt", "0.0", "m0dst", "Pitch", "m0src", "Off", "m1amt", "0.0", "m1dst", "Pitch", "m1src", "Off", "m2amt", "0.0", "m2dst", "Pitch", "m2src", "Off", "m3amt", "0.0", "m3dst", "Pitch", "m3src", "Off", "noise", "0.0", "osc0fine", "0.0", "osc0level", "0.7", "osc0oct", "0.0", "osc0semi", "0.0", "osc0wave", "Saw", "osc1fine", "8", "osc1level", "0.7", "osc1oct", "0.0", "osc1semi", "0.0", "osc1wave", "Saw", "osc2fine", "0.0", "osc2level", "0.3", "osc2oct", "1", "osc2semi", "0.0", "osc2wave", "Square", "release", "0.2", "reso", "0.15", "sustain", "0.7", nullptr};
|
||||
inline const char *const factory26[] = {"attack", "0.001", "cutoff", "0.85", "decay", "0.08", "fatk", "0.001", "fdec", "0.08", "fenvamt", "-0.3", "frel", "0.2", "fsus", "0.0", "keytrack", "0.3", "lfodiv", "3.0", "lfophase", "0°", "lfowave", "Tri", "m0amt", "0.0", "m0dst", "Pitch", "m0src", "Off", "m1amt", "0.0", "m1dst", "Pitch", "m1src", "Off", "m2amt", "0.0", "m2dst", "Pitch", "m2src", "Off", "m3amt", "0.0", "m3dst", "Pitch", "m3src", "Off", "noise", "1.0", "osc0fine", "0.0", "osc0level", "0.0", "osc0oct", "0.0", "osc0semi", "0.0", "osc0wave", "Tri", "osc1fine", "0.0", "osc1level", "0.0", "osc1oct", "0.0", "osc1semi", "0.0", "osc1wave", "Tri", "osc2fine", "0.0", "osc2level", "0.0", "osc2oct", "0.0", "osc2semi", "0.0", "osc2wave", "Tri", "release", "0.06", "reso", "0.2", "sustain", "0.0", nullptr};
|
||||
inline const char *const factory27[] = {"attack", "0.01", "cutoff", "0.75", "decay", "0.2", "fatk", "0.005", "fdec", "0.25", "fenvamt", "0.4", "frel", "0.2", "fsus", "0.4", "keytrack", "0.3", "lfodiv", "3", "lfophase", "0°", "lfowave", "Sine", "m0amt", "0.06", "m0dst", "Pitch", "m0src", "LFO", "m1amt", "0.0", "m1dst", "Pitch", "m1src", "Off", "m2amt", "0.0", "m2dst", "Pitch", "m2src", "Off", "m3amt", "0.0", "m3dst", "Pitch", "m3src", "Off", "noise", "0.0", "osc0fine", "0.0", "osc0level", "0.9", "osc0oct", "0.0", "osc0semi", "0.0", "osc0wave", "Square", "osc1fine", "0.0", "osc1level", "0.0", "osc1oct", "0.0", "osc1semi", "0.0", "osc1wave", "Tri", "osc2fine", "0.0", "osc2level", "0.0", "osc2oct", "0.0", "osc2semi", "0.0", "osc2wave", "Tri", "release", "0.15", "reso", "0.1", "sustain", "0.85", nullptr};
|
||||
inline const char *const factory28[] = {"attack", "0.01", "cutoff", "0.4", "decay", "0.3", "fatk", "0.005", "fdec", "0.25", "fenvamt", "0.4", "frel", "0.2", "fsus", "0.4", "keytrack", "0.3", "lfodiv", "3", "lfophase", "0°", "lfowave", "Tri", "m0amt", "0.5", "m0dst", "Cutoff", "m0src", "LFO", "m1amt", "0.0", "m1dst", "Pitch", "m1src", "Off", "m2amt", "0.0", "m2dst", "Pitch", "m2src", "Off", "m3amt", "0.0", "m3dst", "Pitch", "m3src", "Off", "noise", "0.0", "osc0fine", "0.0", "osc0level", "0.9", "osc0oct", "0.0", "osc0semi", "0.0", "osc0wave", "Saw", "osc1fine", "0.0", "osc1level", "0.0", "osc1oct", "0.0", "osc1semi", "0.0", "osc1wave", "Tri", "osc2fine", "0.0", "osc2level", "0.0", "osc2oct", "0.0", "osc2semi", "0.0", "osc2wave", "Tri", "release", "0.2", "reso", "0.5", "sustain", "0.8", nullptr};
|
||||
inline const char *const factory29[] = {"attack", "0.002", "cutoff", "0.42", "decay", "0.13", "fatk", "0.001", "fdec", "0.11", "fenvamt", "0.6", "frel", "0.10", "fsus", "0.0", "keytrack", "0.4", "lfodiv", "3.0", "lfophase", "0°", "lfowave", "Tri", "m0amt", "0.0", "m0dst", "Pitch", "m0src", "Off", "m1amt", "0.0", "m1dst", "Pitch", "m1src", "Off", "m2amt", "0.0", "m2dst", "Pitch", "m2src", "Off", "m3amt", "0.0", "m3dst", "Pitch", "m3src", "Off", "noise", "0.0", "osc0fine", "0.0", "osc0level", "0.9", "osc0oct", "-1", "osc0semi", "0.0", "osc0wave", "Square", "osc1fine", "6", "osc1level", "0.45", "osc1oct", "-1", "osc1semi", "0.0", "osc1wave", "Saw", "osc2fine", "0.0", "osc2level", "0.0", "osc2oct", "0.0", "osc2semi", "0.0", "osc2wave", "Tri", "release", "0.09", "reso", "0.38", "sustain", "0.0", nullptr};
|
||||
inline const char *const factory30[] = {"attack", "0.002", "cutoff", "0.38", "decay", "0.18", "fatk", "0.001", "fdec", "0.14", "fenvamt", "0.70", "frel", "0.10", "fsus", "0.05", "keytrack", "0.5", "lfodiv", "3.0", "lfophase", "0°", "lfowave", "Tri", "m0amt", "0.0", "m0dst", "Pitch", "m0src", "Off", "m1amt", "0.0", "m1dst", "Pitch", "m1src", "Off", "m2amt", "0.0", "m2dst", "Pitch", "m2src", "Off", "m3amt", "0.0", "m3dst", "Pitch", "m3src", "Off", "noise", "0.0", "osc0fine", "0.0", "osc0level", "0.95", "osc0oct", "-1", "osc0semi", "0.0", "osc0wave", "Saw", "osc1fine", "0.0", "osc1level", "0.0", "osc1oct", "0.0", "osc1semi", "0.0", "osc1wave", "Tri", "osc2fine", "0.0", "osc2level", "0.0", "osc2oct", "0.0", "osc2semi", "0.0", "osc2wave", "Tri", "release", "0.10", "reso", "0.70", "sustain", "0.0", nullptr};
|
||||
inline const char *const factory31[] = {"attack", "0.006", "cutoff", "0.72", "decay", "0.2", "fatk", "0.004", "fdec", "0.25", "fenvamt", "0.25", "frel", "0.2", "fsus", "0.5", "keytrack", "0.5", "lfodiv", "3.0", "lfophase", "0°", "lfowave", "Tri", "m0amt", "0.0", "m0dst", "Pitch", "m0src", "Off", "m1amt", "0.0", "m1dst", "Pitch", "m1src", "Off", "m2amt", "0.0", "m2dst", "Pitch", "m2src", "Off", "m3amt", "0.0", "m3dst", "Pitch", "m3src", "Off", "noise", "0.0", "osc0fine", "0.0", "osc0level", "0.8", "osc0oct", "0.0", "osc0semi", "0.0", "osc0wave", "Saw", "osc1fine", "-7", "osc1level", "0.55", "osc1oct", "0.0", "osc1semi", "0.0", "osc1wave", "Pulse25", "osc2fine", "0.0", "osc2level", "0.3", "osc2oct", "1", "osc2semi", "0.0", "osc2wave", "Saw", "release", "0.18", "reso", "0.40", "sustain", "0.85", nullptr};
|
||||
inline const char *const factory32[] = {"attack", "0.01", "cutoff", "0.66", "decay", "0.25", "fatk", "0.005", "fdec", "0.25", "fenvamt", "0.3", "frel", "0.2", "fsus", "0.4", "keytrack", "0.5", "lfodiv", "4", "lfophase", "0°", "lfowave", "Tri", "m0amt", "0.4", "m0dst", "PWM", "m0src", "LFO", "m1amt", "0.0", "m1dst", "Pitch", "m1src", "Off", "m2amt", "0.0", "m2dst", "Pitch", "m2src", "Off", "m3amt", "0.0", "m3dst", "Pitch", "m3src", "Off", "noise", "0.0", "osc0fine", "0.0", "osc0level", "0.9", "osc0oct", "0.0", "osc0semi", "0.0", "osc0wave", "Pulse25", "osc1fine", "8", "osc1level", "0.5", "osc1oct", "0.0", "osc1semi", "0.0", "osc1wave", "Square", "osc2fine", "0.0", "osc2level", "0.0", "osc2oct", "0.0", "osc2semi", "0.0", "osc2wave", "Tri", "release", "0.2", "reso", "0.45", "sustain", "0.8", nullptr};
|
||||
inline const char *const factory33[] = {"attack", "0.008", "cutoff", "0.48", "decay", "0.35", "fatk", "0.008", "fdec", "0.45", "fenvamt", "0.3", "frel", "0.3", "fsus", "0.55", "keytrack", "0.3", "lfodiv", "3.0", "lfophase", "0°", "lfowave", "Tri", "m0amt", "0.0", "m0dst", "Pitch", "m0src", "Off", "m1amt", "0.0", "m1dst", "Pitch", "m1src", "Off", "m2amt", "0.0", "m2dst", "Pitch", "m2src", "Off", "m3amt", "0.0", "m3dst", "Pitch", "m3src", "Off", "noise", "0.06", "osc0fine", "0.0", "osc0level", "0.75", "osc0oct", "-1", "osc0semi", "0.0", "osc0wave", "Saw", "osc1fine", "-14", "osc1level", "0.75", "osc1oct", "-1", "osc1semi", "0.0", "osc1wave", "Saw", "osc2fine", "0.0", "osc2level", "0.5", "osc2oct", "-2", "osc2semi", "0.0", "osc2wave", "Square", "release", "0.28", "reso", "0.50", "sustain", "0.85", nullptr};
|
||||
inline const char *const factory34[] = {"attack", "0.02", "cutoff", "0.44", "decay", "0.4", "fatk", "0.005", "fdec", "0.25", "fenvamt", "0.25", "frel", "0.2", "fsus", "0.4", "keytrack", "0.25", "lfodiv", "3.0", "lfophase", "0°", "lfowave", "Tri", "m0amt", "0.0", "m0dst", "Pitch", "m0src", "Off", "m1amt", "0.0", "m1dst", "Pitch", "m1src", "Off", "m2amt", "0.0", "m2dst", "Pitch", "m2src", "Off", "m3amt", "0.0", "m3dst", "Pitch", "m3src", "Off", "noise", "0.10", "osc0fine", "-20", "osc0level", "0.7", "osc0oct", "-1", "osc0semi", "0.0", "osc0wave", "Saw", "osc1fine", "20", "osc1level", "0.7", "osc1oct", "-1", "osc1semi", "0.0", "osc1wave", "Saw", "osc2fine", "0.0", "osc2level", "0.4", "osc2oct", "-1", "osc2semi", "0.0", "osc2wave", "Pulse25", "release", "0.35", "reso", "0.55", "sustain", "0.9", nullptr};
|
||||
inline const char *const factory35[] = {"air", "0.0", "attack", "0.7007874", "beat", "0.0", "body", "1.0", "bpitch", "Unison", "breath", "0.2519685", "bres", "0.5511811", "btone", "0.503937", "cfilter", "0.3464567", "choir", "0.5984252", "color", "0.0", "creso", "0.0", "ctype", "Low", "detune", "0.4015748", "evolve", "0.0", "formant", "0.6692913", "grain", "0.0", "interval", "Unison", "morph", "0.0", "morphTo", "Off", "motion", "0.3464567", "mrate", "0.4015748", "mtime", "0.0", "odd", "0.19685039", "partials", "0.7007874", "peak", "0.0", "release", "0.6535433", "shape", "0.0", "soft", "0.0", "stretch", "0.0", "tide", "0.19685039", "tilt", "0.4488189", "timbre", "0.503937", "tperiod", "0.2992126", "velsens", "0.2992126", "warmth", "0.1496063", nullptr};
|
||||
inline const char *const factory36[] = {"air", "0.0", "attack", "0.78740156", "beat", "0.0", "body", "1.0", "bpitch", "Unison", "breath", "0.15748031", "bres", "0.47244096", "btone", "0.503937", "cfilter", "0.43307087", "choir", "0.86614174", "color", "0.0", "creso", "0.15748031", "ctype", "Low", "detune", "0.6692913", "evolve", "0.07874016", "formant", "0.6692913", "grain", "0.0", "interval", "-12", "morph", "0.0", "morphTo", "Off", "motion", "0.47244096", "mrate", "0.31496063", "mtime", "0.0", "odd", "0.23622048", "partials", "0.39370078", "peak", "0.0", "release", "0.78740156", "shape", "0.0", "soft", "0.0", "stretch", "0.0", "tide", "0.15748031", "tilt", "0.47244096", "timbre", "0.47244096", "tperiod", "0.39370078", "velsens", "0.2992126", "warmth", "0.19685039", nullptr};
|
||||
inline const char *const factory37[] = {"air", "0.0", "attack", "0.62992126", "beat", "0.11811024", "body", "1.0", "bpitch", "+12", "breath", "0.5511811", "bres", "0.9055118", "btone", "0.62992126", "cfilter", "0.47244096", "choir", "0.15748031", "color", "1.0", "creso", "0.0", "ctype", "Low", "detune", "0.23622048", "evolve", "0.31496063", "formant", "0.78740156", "grain", "0.15748031", "interval", "Unison", "morph", "0.0", "morphTo", "Off", "motion", "0.31496063", "mrate", "0.23622048", "mtime", "0.0", "odd", "0.39370078", "partials", "0.78740156", "peak", "0.23622048", "release", "0.86614174", "shape", "0.0", "soft", "0.0", "stretch", "0.47244096", "tide", "0.23622048", "tilt", "0.27559054", "timbre", "0.62992126", "tperiod", "0.31496063", "velsens", "0.2992126", "warmth", "0.03937008", nullptr};
|
||||
inline const char *const factory38[] = {"air", "0.0", "attack", "0.78740156", "beat", "0.0", "body", "1.0", "bpitch", "-12", "breath", "0.19685039", "bres", "0.39370078", "btone", "0.23622048", "cfilter", "0.15748031", "choir", "0.70866144", "color", "0.0", "creso", "0.31496063", "ctype", "Low", "detune", "0.5511811", "evolve", "0.15748031", "formant", "0.47244096", "grain", "0.0", "interval", "-12", "morph", "0.0", "morphTo", "Off", "motion", "0.39370078", "mrate", "0.19685039", "mtime", "0.0", "odd", "0.31496063", "partials", "0.5511811", "peak", "0.0", "release", "0.8267717", "shape", "0.23622048", "soft", "0.0", "stretch", "0.0", "tide", "0.39370078", "tilt", "0.70866144", "timbre", "0.31496063", "tperiod", "0.19685039", "velsens", "0.2992126", "warmth", "0.39370078", nullptr};
|
||||
inline const char *const factory39[] = {"air", "0.07874016", "attack", "0.70866144", "beat", "0.19685039", "body", "1.0", "bpitch", "+12", "breath", "0.31496063", "bres", "0.6692913", "btone", "0.5905512", "cfilter", "0.511811", "choir", "0.47244096", "color", "0.47244096", "creso", "0.0", "ctype", "Low", "detune", "0.35433072", "evolve", "0.5511811", "formant", "0.70866144", "grain", "0.0", "interval", "Unison", "morph", "0.0", "morphTo", "Off", "motion", "0.43307087", "mrate", "0.35433072", "mtime", "0.0", "odd", "0.11811024", "partials", "0.8267717", "peak", "0.27559054", "release", "0.8267717", "shape", "0.0", "soft", "0.0", "stretch", "0.07874016", "tide", "0.35433072", "tilt", "0.31496063", "timbre", "0.5905512", "tperiod", "0.39370078", "velsens", "0.2992126", "warmth", "0.11811024", nullptr};
|
||||
inline const char *const factory40[] = {"air", "0.0", "attack", "0.5511811", "beat", "0.0", "body", "1.0", "bpitch", "Unison", "breath", "0.15748031", "bres", "0.39370078", "btone", "0.39370078", "cfilter", "0.31496063", "choir", "0.78740156", "color", "0.23622048", "creso", "0.39370078", "ctype", "Low", "detune", "0.31496063", "evolve", "0.07874016", "formant", "0.5511811", "grain", "0.0", "interval", "Unison", "morph", "0.0", "morphTo", "Off", "motion", "0.27559054", "mrate", "0.31496063", "mtime", "0.0", "odd", "0.47244096", "partials", "0.43307087", "peak", "0.0", "release", "0.62992126", "shape", "0.503937", "soft", "0.0", "stretch", "0.0", "tide", "0.15748031", "tilt", "0.5511811", "timbre", "0.43307087", "tperiod", "0.31496063", "velsens", "0.2992126", "warmth", "0.62992126", nullptr};
|
||||
inline const char *const factory41[] = {"air", "0.0", "attack", "0.7480315", "beat", "0.0", "body", "1.0", "bpitch", "Unison", "breath", "0.35433072", "bres", "0.5905512", "btone", "0.503937", "cfilter", "0.35433072", "choir", "0.62992126", "color", "0.31496063", "creso", "0.23622048", "ctype", "Low", "detune", "0.47244096", "evolve", "0.23622048", "formant", "0.6692913", "grain", "0.0", "interval", "Unison", "morph", "0.0", "morphTo", "Off", "motion", "0.5511811", "mrate", "0.23622048", "mtime", "0.0", "odd", "0.23622048", "partials", "0.62992126", "peak", "0.0", "release", "0.78740156", "shape", "0.0", "soft", "0.0", "stretch", "0.07874016", "tide", "0.86614174", "tilt", "0.43307087", "timbre", "0.47244096", "tperiod", "0.47244096", "velsens", "0.2992126", "warmth", "0.19685039", nullptr};
|
||||
inline const char *const factory42[] = {"air", "0.31496063", "attack", "0.47244096", "beat", "0.0", "body", "1.0", "bpitch", "+12", "breath", "0.6692913", "bres", "0.78740156", "btone", "0.6692913", "cfilter", "0.39370078", "choir", "0.19685039", "color", "0.47244096", "creso", "0.0", "ctype", "Low", "detune", "0.31496063", "evolve", "0.23622048", "formant", "0.6692913", "grain", "0.70866144", "interval", "Unison", "morph", "0.0", "morphTo", "Off", "motion", "0.39370078", "mrate", "0.39370078", "mtime", "0.0", "odd", "0.23622048", "partials", "0.31496063", "peak", "0.0", "release", "0.70866144", "shape", "0.0", "soft", "0.0", "stretch", "0.15748031", "tide", "0.23622048", "tilt", "0.47244096", "timbre", "0.47244096", "tperiod", "0.31496063", "velsens", "0.2992126", "warmth", "0.15748031", nullptr};
|
||||
inline const char *const factory43[] = {"air", "0.39370078", "attack", "0.62992126", "beat", "0.0", "body", "1.0", "bpitch", "Unison", "breath", "0.6692913", "bres", "0.15748031", "btone", "0.5905512", "cfilter", "0.39370078", "choir", "0.0", "color", "0.23622048", "creso", "0.0", "ctype", "Low", "detune", "0.31496063", "evolve", "0.0", "formant", "0.6692913", "grain", "0.0", "interval", "Unison", "morph", "0.0", "morphTo", "Off", "motion", "0.70866144", "mrate", "0.62992126", "mtime", "0.0", "odd", "0.23622048", "partials", "0.15748031", "peak", "0.0", "release", "0.7480315", "shape", "0.0", "soft", "0.0", "stretch", "0.0", "tide", "0.39370078", "tilt", "0.47244096", "timbre", "0.503937", "tperiod", "0.5511811", "velsens", "0.2992126", "warmth", "0.0", nullptr};
|
||||
inline const char *const factory44[] = {"air", "0.0", "attack", "0.31496063", "beat", "0.0", "body", "1.0", "bpitch", "Unison", "breath", "0.07874016", "bres", "0.47244096", "btone", "0.503937", "cfilter", "0.39370078", "choir", "0.31496063", "color", "0.0", "creso", "0.0", "ctype", "Low", "detune", "0.07874016", "evolve", "0.0", "formant", "0.6692913", "grain", "0.0", "interval", "+7", "morph", "0.0", "morphTo", "Off", "motion", "0.11811024", "mrate", "0.31496063", "mtime", "0.0", "odd", "0.0", "partials", "0.9055118", "peak", "0.0", "release", "0.47244096", "shape", "0.0", "soft", "0.0", "stretch", "0.0", "tide", "0.07874016", "tilt", "0.35433072", "timbre", "0.503937", "tperiod", "0.31496063", "velsens", "0.2992126", "warmth", "0.23622048", nullptr};
|
||||
inline const char *const factory45[] = {"air", "0.0", "attack", "0.62992126", "beat", "0.0", "body", "1.0", "bpitch", "Unison", "breath", "0.19685039", "bres", "0.5511811", "btone", "0.47244096", "cfilter", "0.39370078", "choir", "0.8267717", "color", "0.503937", "creso", "0.31496063", "ctype", "Band", "detune", "0.27559054", "evolve", "0.11811024", "formant", "0.6692913", "grain", "0.0", "interval", "Unison", "morph", "0.0", "morphTo", "Off", "motion", "0.31496063", "mrate", "0.35433072", "mtime", "0.0", "odd", "0.86614174", "partials", "0.62992126", "peak", "0.0", "release", "0.70866144", "shape", "0.503937", "soft", "0.0", "stretch", "0.0", "tide", "0.19685039", "tilt", "0.39370078", "timbre", "0.47244096", "tperiod", "0.31496063", "velsens", "0.2992126", "warmth", "0.15748031", nullptr};
|
||||
inline const char *const factory46[] = {"air", "0.0", "attack", "0.70866144", "beat", "0.0", "body", "1.0", "bpitch", "Unison", "breath", "0.11811024", "bres", "0.5511811", "btone", "0.503937", "cfilter", "0.43307087", "choir", "0.511811", "color", "0.0", "creso", "0.47244096", "ctype", "Band", "detune", "0.23622048", "evolve", "0.15748031", "formant", "0.7480315", "grain", "0.0", "interval", "Unison", "morph", "0.0", "morphTo", "Off", "motion", "0.35433072", "mrate", "0.27559054", "mtime", "0.0", "odd", "0.15748031", "partials", "0.984252", "peak", "0.8267717", "release", "0.7480315", "shape", "0.0", "soft", "0.0", "stretch", "0.0", "tide", "0.47244096", "tilt", "0.23622048", "timbre", "0.503937", "tperiod", "0.35433072", "velsens", "0.2992126", "warmth", "0.07874016", nullptr};
|
||||
inline const char *const factory47[] = {"air", "0.15748031", "attack", "0.6692913", "beat", "0.39370078", "body", "1.0", "bpitch", "+19", "breath", "0.39370078", "bres", "0.78740156", "btone", "0.70866144", "cfilter", "0.5905512", "choir", "0.35433072", "color", "0.70866144", "creso", "0.0", "ctype", "Low", "detune", "0.43307087", "evolve", "0.31496063", "formant", "0.78740156", "grain", "0.07874016", "interval", "+12", "morph", "0.0", "morphTo", "Off", "motion", "0.39370078", "mrate", "0.43307087", "mtime", "0.0", "odd", "0.15748031", "partials", "0.78740156", "peak", "0.15748031", "release", "0.86614174", "shape", "0.0", "soft", "0.0", "stretch", "0.11811024", "tide", "0.23622048", "tilt", "0.19685039", "timbre", "0.6692913", "tperiod", "0.31496063", "velsens", "0.2992126", "warmth", "0.07874016", nullptr};
|
||||
inline const char *const factory48[] = {"air", "0.0", "attack", "0.39370078", "beat", "0.0", "body", "1.0", "bpitch", "Unison", "breath", "0.11811024", "bres", "0.47244096", "btone", "0.503937", "cfilter", "0.43307087", "choir", "0.8267717", "color", "0.23622048", "creso", "0.27559054", "ctype", "Band", "detune", "0.23622048", "evolve", "0.0", "formant", "0.6692913", "grain", "0.0", "interval", "Unison", "morph", "0.0", "morphTo", "Off", "motion", "0.23622048", "mrate", "0.35433072", "mtime", "0.0", "odd", "0.5511811", "partials", "0.35433072", "peak", "0.0", "release", "0.5511811", "shape", "0.86614174", "soft", "0.0", "stretch", "0.0", "tide", "0.11811024", "tilt", "0.47244096", "timbre", "0.47244096", "tperiod", "0.31496063", "velsens", "0.2992126", "warmth", "0.31496063", nullptr};
|
||||
inline const char *const factory49[] = {"air", "0.0", "attack", "0.7480315", "beat", "0.0", "body", "1.0", "bpitch", "Unison", "breath", "0.15748031", "bres", "0.47244096", "btone", "0.503937", "cfilter", "0.47244096", "choir", "0.9055118", "color", "0.0", "creso", "0.11811024", "ctype", "Low", "detune", "0.5905512", "evolve", "0.0", "formant", "0.6692913", "grain", "0.0", "interval", "Unison", "morph", "0.0", "morphTo", "Off", "motion", "0.43307087", "mrate", "0.43307087", "mtime", "0.0", "odd", "0.19685039", "partials", "0.31496063", "peak", "0.0", "release", "0.70866144", "shape", "0.70866144", "soft", "0.0", "stretch", "0.0", "tide", "0.15748031", "tilt", "0.43307087", "timbre", "0.511811", "tperiod", "0.31496063", "velsens", "0.2992126", "warmth", "0.23622048", nullptr};
|
||||
inline const char *const factory50[] = {"air", "0.0", "attack", "0.31496063", "beat", "0.23622048", "body", "1.0", "bpitch", "+12", "breath", "0.35433072", "bres", "0.86614174", "btone", "0.62992126", "cfilter", "0.39370078", "choir", "0.11811024", "color", "1.0", "creso", "0.0", "ctype", "Low", "detune", "0.19685039", "evolve", "0.23622048", "formant", "0.6692913", "grain", "0.0", "interval", "Unison", "morph", "0.0", "morphTo", "Off", "motion", "0.23622048", "mrate", "0.31496063", "mtime", "0.0", "odd", "0.15748031", "partials", "0.9055118", "peak", "0.0", "release", "0.86614174", "shape", "0.0", "soft", "0.0", "stretch", "0.7480315", "tide", "0.15748031", "tilt", "0.23622048", "timbre", "0.5905512", "tperiod", "0.31496063", "velsens", "0.2992126", "warmth", "0.03937008", nullptr};
|
||||
inline const char *const factory51[] = {"air", "0.0", "attack", "0.86614174", "beat", "0.0", "body", "1.0", "bpitch", "-12", "breath", "0.23622048", "bres", "0.43307087", "btone", "0.27559054", "cfilter", "0.19685039", "choir", "0.70866144", "color", "0.0", "creso", "0.5511811", "ctype", "Low", "detune", "0.43307087", "evolve", "0.19685039", "formant", "0.5511811", "grain", "0.0", "interval", "-12", "morph", "0.0", "morphTo", "Off", "motion", "0.35433072", "mrate", "0.15748031", "mtime", "0.0", "odd", "0.23622048", "partials", "0.47244096", "peak", "0.0", "release", "0.9055118", "shape", "0.15748031", "soft", "0.0", "stretch", "0.0", "tide", "0.31496063", "tilt", "0.6692913", "timbre", "0.35433072", "tperiod", "0.15748031", "velsens", "0.2992126", "warmth", "0.27559054", nullptr};
|
||||
inline const char *const factory52[] = {"air", "0.23622048", "attack", "0.78740156", "beat", "0.0", "body", "1.0", "bpitch", "+12", "breath", "0.47244096", "bres", "0.31496063", "btone", "0.62992126", "cfilter", "0.5511811", "choir", "0.6692913", "color", "0.23622048", "creso", "0.15748031", "ctype", "High", "detune", "0.47244096", "evolve", "0.15748031", "formant", "0.6692913", "grain", "0.0", "interval", "+12", "morph", "0.0", "morphTo", "Off", "motion", "0.47244096", "mrate", "0.39370078", "mtime", "0.0", "odd", "0.19685039", "partials", "0.39370078", "peak", "0.0", "release", "0.8267717", "shape", "0.0", "soft", "0.0", "stretch", "0.0", "tide", "0.23622048", "tilt", "0.39370078", "timbre", "0.5511811", "tperiod", "0.39370078", "velsens", "0.2992126", "warmth", "0.07874016", nullptr};
|
||||
inline const char *const factory53[] = {"air", "0.0", "attack", "0.47244096", "beat", "0.78740156", "body", "1.0", "bpitch", "Unison", "breath", "0.19685039", "bres", "0.5511811", "btone", "0.503937", "cfilter", "0.39370078", "choir", "0.39370078", "color", "0.15748031", "creso", "0.0", "ctype", "Low", "detune", "0.23622048", "evolve", "0.11811024", "formant", "0.6692913", "grain", "0.0", "interval", "Unison", "morph", "0.0", "morphTo", "Off", "motion", "0.23622048", "mrate", "0.39370078", "mtime", "0.0", "odd", "0.23622048", "partials", "0.7480315", "peak", "0.0", "release", "0.62992126", "shape", "0.0", "soft", "0.0", "stretch", "0.0", "tide", "0.15748031", "tilt", "0.35433072", "timbre", "0.503937", "tperiod", "0.31496063", "velsens", "0.2992126", "warmth", "0.15748031", nullptr};
|
||||
inline const char *const factory54[] = {"air", "0.11811024", "attack", "0.5511811", "beat", "0.15748031", "body", "1.0", "bpitch", "+24", "breath", "0.5511811", "bres", "0.9448819", "btone", "0.78740156", "cfilter", "0.62992126", "choir", "0.23622048", "color", "0.78740156", "creso", "0.0", "ctype", "High", "detune", "0.15748031", "evolve", "0.23622048", "formant", "0.86614174", "grain", "0.31496063", "interval", "+12", "morph", "0.0", "morphTo", "Off", "motion", "0.27559054", "mrate", "0.47244096", "mtime", "0.0", "odd", "0.31496063", "partials", "0.86614174", "peak", "0.31496063", "release", "0.78740156", "shape", "0.0", "soft", "0.0", "stretch", "0.23622048", "tide", "0.15748031", "tilt", "0.15748031", "timbre", "0.70866144", "tperiod", "0.31496063", "velsens", "0.2992126", "warmth", "0.0", nullptr};
|
||||
inline const char *const factory55[] = {"air", "0.0", "attack", "0.70866144", "beat", "0.0", "body", "1.0", "bpitch", "-12", "breath", "0.0", "bres", "0.39370078", "btone", "0.23622048", "cfilter", "0.19685039", "choir", "0.78740156", "color", "0.0", "creso", "0.07874016", "ctype", "Low", "detune", "0.19685039", "evolve", "0.0", "formant", "0.31496063", "grain", "0.0", "interval", "-12", "morph", "0.0", "morphTo", "Off", "motion", "0.19685039", "mrate", "0.23622048", "mtime", "0.0", "odd", "0.15748031", "partials", "0.78740156", "peak", "0.0", "release", "0.7480315", "shape", "0.0", "soft", "0.0", "stretch", "0.0", "tide", "0.15748031", "tilt", "0.78740156", "timbre", "0.31496063", "tperiod", "0.23622048", "velsens", "0.2992126", "warmth", "0.31496063", nullptr};
|
||||
inline const char *const factory56[] = {"air", "0.0", "attack", "0.70866144", "beat", "0.07874016", "body", "1.0", "bpitch", "Unison", "breath", "0.11811024", "bres", "0.5511811", "btone", "0.503937", "cfilter", "0.39370078", "choir", "0.15748031", "color", "0.0", "creso", "0.0", "ctype", "Low", "detune", "0.15748031", "evolve", "0.39370078", "formant", "0.6692913", "grain", "0.0", "interval", "Unison", "morph", "0.0", "morphTo", "Off", "motion", "0.39370078", "mrate", "0.31496063", "mtime", "0.0", "odd", "0.07874016", "partials", "0.9448819", "peak", "1.0", "release", "0.78740156", "shape", "0.0", "soft", "0.0", "stretch", "0.0", "tide", "0.62992126", "tilt", "0.15748031", "timbre", "0.503937", "tperiod", "0.39370078", "velsens", "0.2992126", "warmth", "0.03937008", nullptr};
|
||||
inline const char *const factory57[] = {"air", "0.15748031", "attack", "0.47244096", "beat", "0.11811024", "body", "1.0", "bpitch", "Unison", "breath", "0.31496063", "bres", "0.62992126", "btone", "0.35433072", "cfilter", "0.35433072", "choir", "0.62992126", "color", "0.31496063", "creso", "0.62992126", "ctype", "Band", "detune", "0.39370078", "evolve", "0.15748031", "formant", "0.5905512", "grain", "0.47244096", "interval", "Unison", "morph", "0.0", "morphTo", "Off", "motion", "0.31496063", "mrate", "0.43307087", "mtime", "0.0", "odd", "0.47244096", "partials", "0.39370078", "peak", "0.0", "release", "0.62992126", "shape", "0.5511811", "soft", "0.0", "stretch", "0.15748031", "tide", "0.19685039", "tilt", "0.511811", "timbre", "0.43307087", "tperiod", "0.31496063", "velsens", "0.2992126", "warmth", "0.78740156", nullptr};
|
||||
inline const char *const factory58[] = {"air", "0.0", "attack", "0.78740156", "beat", "0.0", "body", "1.0", "bpitch", "Unison", "breath", "0.0", "bres", "0.39370078", "btone", "0.503937", "cfilter", "0.39370078", "choir", "0.0", "color", "0.0", "creso", "0.0", "ctype", "Low", "detune", "0.0", "evolve", "0.0", "formant", "0.6692913", "grain", "0.0", "interval", "Unison", "morph", "0.0", "morphTo", "Off", "motion", "0.03937008", "mrate", "0.15748031", "mtime", "0.0", "odd", "0.0", "partials", "0.984252", "peak", "0.0", "release", "0.78740156", "shape", "0.0", "soft", "0.0", "stretch", "0.0", "tide", "0.0", "tilt", "1.0", "timbre", "0.39370078", "tperiod", "0.31496063", "velsens", "0.2992126", "warmth", "0.0", nullptr};
|
||||
inline const char *const factory59[] = {"air", "0.0", "attack", "0.8267717", "beat", "0.0", "body", "1.0", "bpitch", "Unison", "breath", "0.07874016", "bres", "0.39370078", "btone", "0.39370078", "cfilter", "0.31496063", "choir", "0.7480315", "color", "0.0", "creso", "0.07874016", "ctype", "Low", "detune", "0.27559054", "evolve", "0.0", "formant", "0.6692913", "grain", "0.0", "interval", "Unison", "morph", "0.0", "morphTo", "Off", "motion", "0.27559054", "mrate", "0.23622048", "mtime", "0.0", "odd", "0.15748031", "partials", "0.35433072", "peak", "0.0", "release", "0.86614174", "shape", "0.0", "soft", "0.9448819", "stretch", "0.0", "tide", "0.15748031", "tilt", "0.6692913", "timbre", "0.40944883", "tperiod", "0.35433072", "velsens", "0.2992126", "warmth", "0.11811024", nullptr};
|
||||
inline const char *const factory60[] = {"air", "0.0", "attack", "0.47244096", "beat", "0.27559054", "body", "1.0", "bpitch", "+19", "breath", "0.11811024", "bres", "0.70866144", "btone", "0.7480315", "cfilter", "0.5905512", "choir", "0.27559054", "color", "0.62992126", "creso", "0.6692913", "ctype", "High", "detune", "0.11811024", "evolve", "0.15748031", "formant", "0.86614174", "grain", "0.0", "interval", "+12", "morph", "0.0", "morphTo", "Off", "motion", "0.27559054", "mrate", "0.43307087", "mtime", "0.0", "odd", "0.9448819", "partials", "0.9055118", "peak", "0.5511811", "release", "0.70866144", "shape", "0.503937", "soft", "0.0", "stretch", "0.35433072", "tide", "0.11811024", "tilt", "0.11811024", "timbre", "0.6692913", "tperiod", "0.31496063", "velsens", "0.2992126", "warmth", "0.27559054", nullptr};
|
||||
inline const char *const factory61[] = {"air", "0.15748031", "attack", "0.5511811", "beat", "0.5511811", "body", "1.0", "bpitch", "+12", "breath", "0.23622048", "bres", "0.47244096", "btone", "0.5511811", "cfilter", "0.47244096", "choir", "0.9448819", "color", "0.15748031", "creso", "0.31496063", "ctype", "Band", "detune", "0.9448819", "evolve", "0.31496063", "formant", "0.6692913", "grain", "0.23622048", "interval", "Unison", "morph", "0.0", "morphTo", "Off", "motion", "0.86614174", "mrate", "0.78740156", "mtime", "0.0", "odd", "0.23622048", "partials", "0.5905512", "peak", "0.0", "release", "0.6692913", "shape", "0.9448819", "soft", "0.0", "stretch", "0.0", "tide", "0.31496063", "tilt", "0.31496063", "timbre", "0.5511811", "tperiod", "0.11811024", "velsens", "0.2992126", "warmth", "0.23622048", nullptr};
|
||||
inline const char *const factory62[] = {"air", "0.0", "attack", "0.9448819", "beat", "0.0", "body", "1.0", "bpitch", "-12", "breath", "0.11811024", "bres", "0.31496063", "btone", "0.23622048", "cfilter", "0.17322835", "choir", "1.0", "color", "0.0", "creso", "0.47244096", "ctype", "Low", "detune", "0.15748031", "evolve", "0.0", "formant", "0.31496063", "grain", "0.0", "interval", "-12", "morph", "0.0", "morphTo", "Off", "motion", "0.15748031", "mrate", "0.15748031", "mtime", "0.0", "odd", "0.70866144", "partials", "0.47244096", "peak", "0.23622048", "release", "0.9448819", "shape", "0.503937", "soft", "0.23622048", "stretch", "0.0", "tide", "0.47244096", "tilt", "0.7480315", "timbre", "0.27559054", "tperiod", "0.5511811", "velsens", "0.2992126", "warmth", "0.5511811", nullptr};
|
||||
inline const char *const factory63[] = {"air", "0.23622048", "attack", "0.78740156", "beat", "0.19685039", "body", "1.0", "bpitch", "+19", "breath", "0.35433072", "bres", "0.62992126", "btone", "0.86614174", "cfilter", "0.70866144", "choir", "0.5511811", "color", "0.23622048", "creso", "0.11811024", "ctype", "High", "detune", "0.43307087", "evolve", "0.47244096", "formant", "0.9448819", "grain", "0.0", "interval", "+12", "morph", "0.0", "morphTo", "Off", "motion", "0.47244096", "mrate", "0.39370078", "mtime", "0.0", "odd", "0.11811024", "partials", "0.8267717", "peak", "0.31496063", "release", "0.86614174", "shape", "0.07874016", "soft", "0.0", "stretch", "0.03937008", "tide", "0.5511811", "tilt", "0.11811024", "timbre", "0.78740156", "tperiod", "0.27559054", "velsens", "0.2992126", "warmth", "0.15748031", nullptr};
|
||||
inline const char *const factory64[] = {"air", "0.03937008", "attack", "0.86614174", "beat", "0.0", "body", "1.0", "bpitch", "-12", "breath", "0.7480315", "bres", "0.78740156", "btone", "0.14173229", "cfilter", "0.14173229", "choir", "0.43307087", "color", "0.47244096", "creso", "0.39370078", "ctype", "Low", "detune", "0.23622048", "evolve", "0.07874016", "formant", "0.31496063", "grain", "0.39370078", "interval", "-12", "morph", "0.0", "morphTo", "Off", "motion", "0.23622048", "mrate", "0.15748031", "mtime", "0.0", "odd", "0.23622048", "partials", "0.31496063", "peak", "0.0", "release", "0.9448819", "shape", "0.0", "soft", "0.47244096", "stretch", "0.0", "tide", "0.35433072", "tilt", "0.86614174", "timbre", "0.23622048", "tperiod", "0.47244096", "velsens", "0.2992126", "warmth", "0.23622048", nullptr};
|
||||
inline const char *const factory65[] = {"air", "0.0", "attack", "0.39370078", "beat", "0.31496063", "body", "1.0", "bpitch", "+24", "breath", "0.15748031", "bres", "0.78740156", "btone", "0.78740156", "cfilter", "0.47244096", "choir", "0.07874016", "color", "0.70866144", "creso", "0.0", "ctype", "Low", "detune", "0.09448819", "evolve", "0.35433072", "formant", "0.9448819", "grain", "0.0", "interval", "+12", "morph", "0.0", "morphTo", "Off", "motion", "0.19685039", "mrate", "0.23622048", "mtime", "0.0", "odd", "0.07874016", "partials", "0.9448819", "peak", "0.86614174", "release", "0.9448819", "shape", "0.0", "soft", "1.0", "stretch", "0.19685039", "tide", "0.11811024", "tilt", "0.23622048", "timbre", "0.70866144", "tperiod", "0.43307087", "velsens", "0.2992126", "warmth", "0.0", nullptr};
|
||||
inline const char *const factory66[] = {"air", "0.0", "attack", "0.78740156", "beat", "0.0", "body", "1.0", "bpitch", "Unison", "breath", "0.07874016", "bres", "0.47244096", "btone", "0.39370078", "cfilter", "0.2992126", "choir", "0.86614174", "color", "0.0", "creso", "0.43307087", "ctype", "Band", "detune", "0.23622048", "evolve", "0.11811024", "formant", "0.48818898", "grain", "0.0", "interval", "-12", "morph", "0.0", "morphTo", "Off", "motion", "0.23622048", "mrate", "0.19685039", "mtime", "0.0", "odd", "0.31496063", "partials", "0.6692913", "peak", "0.70866144", "release", "0.78740156", "shape", "0.0", "soft", "0.70866144", "stretch", "0.0", "tide", "0.23622048", "tilt", "0.5511811", "timbre", "0.39370078", "tperiod", "0.511811", "velsens", "0.2992126", "warmth", "0.19685039", nullptr};
|
||||
inline const char *const factory67[] = {"air", "0.31496063", "attack", "0.31496063", "beat", "0.0", "body", "1.0", "bpitch", "+19", "breath", "1.0", "bres", "0.86614174", "btone", "0.78740156", "cfilter", "0.5511811", "choir", "0.27559054", "color", "0.70866144", "creso", "0.23622048", "ctype", "High", "detune", "0.31496063", "evolve", "0.0", "formant", "0.6692913", "grain", "0.6692913", "interval", "Unison", "morph", "0.0", "morphTo", "Off", "motion", "0.62992126", "mrate", "0.86614174", "mtime", "0.0", "odd", "0.39370078", "partials", "0.31496063", "peak", "0.0", "release", "0.5511811", "shape", "0.23622048", "soft", "0.0", "stretch", "0.0", "tide", "0.15748031", "tilt", "0.31496063", "timbre", "0.62992126", "tperiod", "0.15748031", "velsens", "0.2992126", "warmth", "0.11811024", nullptr};
|
||||
inline const char *const factory68[] = {"air", "0.0", "attack", "0.86614174", "beat", "0.062992126", "body", "1.0", "bpitch", "Unison", "breath", "0.062992126", "bres", "0.47244096", "btone", "0.503937", "cfilter", "0.35433072", "choir", "0.6692913", "color", "0.0", "creso", "0.0", "ctype", "Low", "detune", "0.17322835", "evolve", "0.07874016", "formant", "0.6692913", "grain", "0.0", "interval", "+7", "morph", "0.0", "morphTo", "Off", "motion", "0.15748031", "mrate", "0.11811024", "mtime", "0.0", "odd", "0.07874016", "partials", "0.5511811", "peak", "0.15748031", "release", "0.9448819", "shape", "0.0", "soft", "0.86614174", "stretch", "0.0", "tide", "0.27559054", "tilt", "0.78740156", "timbre", "0.43307087", "tperiod", "0.62992126", "velsens", "0.2992126", "warmth", "0.07874016", nullptr};
|
||||
inline const char *const factory69[] = {"air", "0.47244096", "attack", "0.70866144", "beat", "0.15748031", "body", "1.0", "bpitch", "-12", "breath", "0.86614174", "bres", "0.5511811", "btone", "0.27559054", "cfilter", "0.22047244", "choir", "0.62992126", "color", "0.31496063", "creso", "0.5511811", "ctype", "Low", "detune", "0.5511811", "evolve", "0.39370078", "formant", "0.47244096", "grain", "0.5511811", "interval", "-12", "morph", "0.0", "morphTo", "Off", "motion", "0.78740156", "mrate", "0.6692913", "mtime", "0.0", "odd", "0.31496063", "partials", "0.31496063", "peak", "0.0", "release", "0.86614174", "shape", "0.23622048", "soft", "0.15748031", "stretch", "0.0", "tide", "0.9448819", "tilt", "0.70866144", "timbre", "0.31496063", "tperiod", "0.19685039", "velsens", "0.2992126", "warmth", "0.70866144", nullptr};
|
||||
inline const char *const factory70[] = {"air", "0.07874016", "attack", "0.6692913", "beat", "0.23622048", "body", "1.0", "bpitch", "+12", "breath", "0.19685039", "bres", "0.70866144", "btone", "0.6692913", "cfilter", "0.511811", "choir", "0.39370078", "color", "0.39370078", "creso", "0.15748031", "ctype", "Band", "detune", "0.31496063", "evolve", "0.78740156", "formant", "0.8267717", "grain", "0.0", "interval", "+12", "morph", "0.0", "morphTo", "Off", "motion", "0.47244096", "mrate", "0.35433072", "mtime", "0.0", "odd", "0.47244096", "partials", "0.9448819", "peak", "0.62992126", "release", "0.8267717", "shape", "0.0", "soft", "0.31496063", "stretch", "0.11811024", "tide", "0.39370078", "tilt", "0.19685039", "timbre", "0.62992126", "tperiod", "0.31496063", "velsens", "0.2992126", "warmth", "0.07874016", nullptr};
|
||||
inline const char *const factory71[] = {"attack", "0.15", "dens_mul", "0.0", "drift", "0.35", "end", "1.0", "freeze", "Off", "grain_tone", "-0.1", "harmony", "0.35", "level", "0.75", "mode", "Cloud", "motion", "0.3", "pitch", "0.0", "pitch_rand", "0.0", "position", "0.35", "release", "0.45", "reverse", "0.1", "scan", "0.0", "scatter", "0.5", "size_mul", "0.0", "size_rand", "0.3", "source", "Felt Piano", "start", "0.0", "texture", "0.78", "velo", "0.5", "window", "Auto", nullptr};
|
||||
inline const char *const factory72[] = {"attack", "0.15", "dens_mul", "0.0", "drift", "0.3", "end", "1.0", "freeze", "Off", "grain_tone", "-0.1", "harmony", "0.5", "level", "0.75", "mode", "Bloom", "motion", "0.35", "pitch", "0.0", "pitch_rand", "0.0", "position", "0.35", "release", "0.45", "reverse", "0.1", "scan", "0.0", "scatter", "0.4", "size_mul", "0.0", "size_rand", "0.3", "source", "Bowed Glass", "start", "0.0", "texture", "0.7", "velo", "0.5", "window", "Auto", nullptr};
|
||||
inline const char *const factory73[] = {"attack", "0.15", "dens_mul", "0.0", "drift", "0.3", "end", "1.0", "freeze", "Off", "grain_tone", "-0.1", "harmony", "0.3", "level", "0.75", "mode", "Dust", "motion", "0.4", "pitch", "0.0", "pitch_rand", "0.0", "position", "0.35", "release", "0.45", "reverse", "0.1", "scan", "0.0", "scatter", "0.7", "size_mul", "0.0", "size_rand", "0.3", "source", "Music Box", "start", "0.0", "texture", "0.45", "velo", "0.5", "window", "Auto", nullptr};
|
||||
inline const char *const factory74[] = {"attack", "0.15", "dens_mul", "0.0", "drift", "0.55", "end", "1.0", "freeze", "Off", "grain_tone", "-0.1", "harmony", "0.25", "level", "0.75", "mode", "Drift", "motion", "0.4", "pitch", "0.0", "pitch_rand", "0.0", "position", "0.35", "release", "0.45", "reverse", "0.1", "scan", "0.0", "scatter", "0.45", "size_mul", "0.0", "size_rand", "0.3", "source", "Warm Pad", "start", "0.0", "texture", "0.7", "velo", "0.5", "window", "Auto", nullptr};
|
||||
inline const char *const factory75[] = {"attack", "0.15", "dens_mul", "0.0", "drift", "0.4", "end", "1.0", "freeze", "Off", "grain_tone", "-0.1", "harmony", "0.15", "level", "0.75", "mode", "Tape", "motion", "0.35", "pitch", "0.0", "pitch_rand", "0.0", "position", "0.35", "release", "0.45", "reverse", "0.1", "scan", "0.0", "scatter", "0.25", "size_mul", "0.0", "size_rand", "0.3", "source", "Strings", "start", "0.0", "texture", "0.6", "velo", "0.5", "window", "Auto", nullptr};
|
||||
inline const char *const factory76[] = {"attack", "0.15", "dens_mul", "0.0", "drift", "0.4", "end", "1.0", "freeze", "Off", "grain_tone", "-0.1", "harmony", "0.4", "level", "0.75", "mode", "Cloud", "motion", "0.25", "pitch", "0.0", "pitch_rand", "0.0", "position", "0.35", "release", "0.45", "reverse", "0.1", "scan", "0.0", "scatter", "0.4", "size_mul", "0.0", "size_rand", "0.3", "source", "Low Drone", "start", "0.0", "texture", "0.85", "velo", "0.5", "window", "Auto", nullptr};
|
||||
inline const char *const factory77[] = {"attack", "0.15", "dens_mul", "0.0", "drift", "0.4", "end", "1.0", "freeze", "Off", "grain_tone", "-0.1", "harmony", "0.45", "level", "0.75", "mode", "Cloud", "motion", "0.3", "pitch", "0.0", "pitch_rand", "0.0", "position", "0.35", "release", "0.45", "reverse", "0.1", "scan", "0.0", "scatter", "0.6", "size_mul", "0.0", "size_rand", "0.3", "source", "Rain Field", "start", "0.0", "texture", "0.88", "velo", "0.5", "window", "Auto", nullptr};
|
||||
inline const char *const factory78[] = {"attack", "0.15", "dens_mul", "0.0", "drift", "0.3", "end", "1.0", "freeze", "Off", "grain_tone", "-0.1", "harmony", "0.2", "level", "0.75", "mode", "Pulse", "motion", "0.3", "pitch", "0.0", "pitch_rand", "0.0", "position", "0.35", "release", "0.45", "reverse", "0.1", "scan", "0.0", "scatter", "0.6", "size_mul", "0.0", "size_rand", "0.3", "source", "Kalimba", "start", "0.0", "texture", "0.4", "velo", "0.5", "window", "Auto", nullptr};
|
||||
inline const char *const factory79[] = {"attack", "0.15", "dens_mul", "0.0", "drift", "0.35", "end", "1.0", "freeze", "Off", "grain_tone", "-0.1", "harmony", "0.4", "level", "0.75", "mode", "Cloud", "motion", "0.3", "pitch", "0.0", "pitch_rand", "0.0", "position", "0.35", "release", "0.45", "reverse", "0.1", "scan", "0.0", "scatter", "0.45", "size_mul", "0.0", "size_rand", "0.3", "source", "Breath Choir", "start", "0.0", "texture", "0.85", "velo", "0.5", "window", "Auto", nullptr};
|
||||
inline const char *const factory80[] = {"attack", "0.15", "dens_mul", "0.0", "drift", "0.4", "end", "1.0", "freeze", "Off", "grain_tone", "-0.1", "harmony", "0.35", "level", "0.75", "mode", "Bloom", "motion", "0.4", "pitch", "0.0", "pitch_rand", "0.0", "position", "0.35", "release", "0.45", "reverse", "0.1", "scan", "0.0", "scatter", "0.5", "size_mul", "0.0", "size_rand", "0.3", "source", "Breath Choir", "start", "0.0", "texture", "0.75", "velo", "0.5", "window", "Auto", nullptr};
|
||||
inline const char *const factory81[] = {"attack", "0.15", "dens_mul", "0.0", "drift", "0.6", "end", "1.0", "freeze", "Off", "grain_tone", "-0.1", "harmony", "0.3", "level", "0.75", "mode", "Drift", "motion", "0.4", "pitch", "0.0", "pitch_rand", "0.0", "position", "0.35", "release", "0.45", "reverse", "0.1", "scan", "0.0", "scatter", "0.4", "size_mul", "0.0", "size_rand", "0.3", "source", "Low Drone", "start", "0.0", "texture", "0.65", "velo", "0.5", "window", "Auto", nullptr};
|
||||
inline const char *const factory82[] = {"attack", "0.15", "dens_mul", "0.0", "drift", "0.2", "end", "1.0", "freeze", "Off", "grain_tone", "0.4", "harmony", "0.3", "level", "0.75", "mode", "Dust", "motion", "0.5", "pitch", "12.0", "pitch_rand", "0.0", "position", "0.35", "release", "0.45", "reverse", "0.2", "scan", "0.0", "scatter", "0.55", "size_mul", "0.0", "size_rand", "0.3", "source", "Glass Tines", "start", "0.0", "texture", "0.35", "velo", "0.5", "window", "Auto", nullptr};
|
||||
inline const char *const factory83[] = {"attack", "0.15", "dens_mul", "0.0", "drift", "0.5", "end", "1.0", "freeze", "Off", "grain_tone", "-0.1", "harmony", "0.3", "level", "0.75", "mode", "Bloom", "motion", "0.5", "pitch", "0.0", "pitch_rand", "0.0", "position", "0.35", "release", "0.45", "reverse", "0.1", "scan", "0.0", "scatter", "0.7", "size_mul", "0.0", "size_rand", "0.3", "source", "Kalimba", "start", "0.0", "texture", "0.6", "velo", "0.5", "window", "Auto", nullptr};
|
||||
inline const char *const factory84[] = {"attack", "0.15", "dens_mul", "0.0", "drift", "0.4", "end", "1.0", "freeze", "Off", "grain_tone", "-0.1", "harmony", "0.3", "level", "0.75", "mode", "Tape", "motion", "0.4", "pitch", "0.0", "pitch_rand", "0.0", "position", "0.35", "release", "0.45", "reverse", "0.1", "scan", "0.0", "scatter", "0.2", "size_mul", "0.0", "size_rand", "0.3", "source", "Rain Field", "start", "0.0", "texture", "0.5", "velo", "0.5", "window", "Auto", nullptr};
|
||||
inline const char *const factory85[] = {"attack", "0.01", "cutoff", "0.8", "decay", "0.3", "drive", "0.0", "fenv", "0.2", "ftype", "Low", "keytrack", "0.4", "lfocut", "0.0", "lfodiv", "3", "lfopitch", "0.15", "lfopos", "0.15", "lfowave", "Sine", "mattack", "0.01", "mdecay", "0.8", "menvpos", "0.5", "mrelease", "1.0", "msustain", "0.2", "noise", "0.0", "o1bend", "0.0", "o1fine", "0.0", "o1level", "0.8", "o1oct", "0.0", "o1pos", "0.4", "o1semi", "0.0", "o1table", "Classic", "o2bend", "0.0", "o2fine", "7.0", "o2level", "0.0", "o2oct", "0.0", "o2pos", "0.3", "o2semi", "0.0", "o2table", "Classic", "release", "0.25", "reso", "0.25", "spread", "0.3", "sub", "0.0", "sustain", "0.8", "unison", "1.0", "velsens", "0.5", "wtframe", "Auto", nullptr};
|
||||
inline const char *const factory86[] = {"attack", "0.8", "cutoff", "0.7", "decay", "0.3", "drive", "0.0", "fenv", "0.2", "ftype", "Low", "keytrack", "0.4", "lfocut", "0.0", "lfodiv", "0", "lfopitch", "0.0", "lfopos", "0.2", "lfowave", "Sine", "mattack", "3.0", "mdecay", "4.0", "menvpos", "0.6", "mrelease", "1.0", "msustain", "0.7", "noise", "0.0", "o1bend", "0.0", "o1fine", "0.0", "o1level", "0.8", "o1oct", "0.0", "o1pos", "0.0", "o1semi", "0.0", "o1table", "Vowels", "o2bend", "0.0", "o2fine", "9.0", "o2level", "0.6", "o2oct", "0.0", "o2pos", "0.5", "o2semi", "0.0", "o2table", "Vowels", "release", "2.5", "reso", "0.15", "spread", "0.4", "sub", "0.0", "sustain", "0.8", "unison", "3", "velsens", "0.5", "wtframe", "Auto", nullptr};
|
||||
inline const char *const factory87[] = {"attack", "0.4", "cutoff", "0.65", "decay", "0.3", "drive", "0.0", "fenv", "0.2", "ftype", "Low", "keytrack", "0.4", "lfocut", "0.0", "lfodiv", "1", "lfopitch", "0.0", "lfopos", "0.4", "lfowave", "Sine", "mattack", "0.5", "mdecay", "2.0", "menvpos", "0.0", "mrelease", "1.0", "msustain", "0.5", "noise", "0.0", "o1bend", "0.0", "o1fine", "0.0", "o1level", "0.8", "o1oct", "0.0", "o1pos", "0.2", "o1semi", "0.0", "o1table", "PWM", "o2bend", "0.0", "o2fine", "-8.0", "o2level", "0.7", "o2oct", "0.0", "o2pos", "0.6", "o2semi", "0.0", "o2table", "PWM", "release", "1.2", "reso", "0.1", "spread", "0.5", "sub", "0.0", "sustain", "0.8", "unison", "2", "velsens", "0.5", "wtframe", "Auto", nullptr};
|
||||
inline const char *const factory88[] = {"attack", "0.01", "cutoff", "0.85", "decay", "0.5", "drive", "0.3", "fenv", "0.3", "ftype", "Low", "keytrack", "0.4", "lfocut", "0.0", "lfodiv", "1.0", "lfopitch", "0.0", "lfopos", "0.15", "lfowave", "Sine", "mattack", "0.0", "mdecay", "0.6", "menvpos", "0.9", "mrelease", "1.0", "msustain", "0.1", "noise", "0.0", "o1bend", "0.0", "o1fine", "0.0", "o1level", "0.8", "o1oct", "0.0", "o1pos", "0.0", "o1semi", "0.0", "o1table", "Sync", "o2bend", "0.0", "o2fine", "7.0", "o2level", "0.0", "o2oct", "0.0", "o2pos", "0.3", "o2semi", "0.0", "o2table", "Classic", "release", "0.2", "reso", "0.15", "spread", "0.3", "sub", "0.0", "sustain", "0.6", "unison", "1.0", "velsens", "0.5", "wtframe", "Auto", nullptr};
|
||||
inline const char *const factory89[] = {"attack", "0.0", "cutoff", "0.9", "decay", "2.5", "drive", "0.0", "fenv", "0.0", "ftype", "Low", "keytrack", "0.8", "lfocut", "0.0", "lfodiv", "1.0", "lfopitch", "0.0", "lfopos", "0.15", "lfowave", "Sine", "mattack", "0.0", "mdecay", "1.5", "menvpos", "-0.6", "mrelease", "1.0", "msustain", "0.0", "noise", "0.0", "o1bend", "0.0", "o1fine", "0.0", "o1level", "0.8", "o1oct", "0.0", "o1pos", "0.6", "o1semi", "0.0", "o1table", "FM", "o2bend", "0.0", "o2fine", "7.0", "o2level", "0.0", "o2oct", "0.0", "o2pos", "0.3", "o2semi", "0.0", "o2table", "Classic", "release", "2.0", "reso", "0.15", "spread", "0.3", "sub", "0.0", "sustain", "0.0", "unison", "1.0", "velsens", "0.5", "wtframe", "Auto", nullptr};
|
||||
inline const char *const factory90[] = {"attack", "0.005", "cutoff", "0.75", "decay", "1.2", "drive", "0.0", "fenv", "0.2", "ftype", "Low", "keytrack", "0.4", "lfocut", "0.0", "lfodiv", "1.0", "lfopitch", "0.0", "lfopos", "0.15", "lfowave", "Sine", "mattack", "0.0", "mdecay", "1.2", "menvpos", "0.4", "mrelease", "1.0", "msustain", "0.2", "noise", "0.0", "o1bend", "0.0", "o1fine", "0.0", "o1level", "0.8", "o1oct", "0.0", "o1pos", "0.2", "o1semi", "0.0", "o1table", "Glass", "o2bend", "0.0", "o2fine", "7.0", "o2level", "0.3", "o2oct", "1", "o2pos", "0.0", "o2semi", "0.0", "o2table", "Classic", "release", "1.0", "reso", "0.15", "spread", "0.3", "sub", "0.0", "sustain", "0.3", "unison", "1.0", "velsens", "0.5", "wtframe", "Auto", nullptr};
|
||||
inline const char *const factory91[] = {"attack", "0.02", "cutoff", "0.9", "decay", "0.3", "drive", "0.0", "fenv", "0.2", "ftype", "Low", "keytrack", "0.4", "lfocut", "0.0", "lfodiv", "0", "lfopitch", "0.0", "lfopos", "0.5", "lfowave", "Tri", "mattack", "0.5", "mdecay", "2.0", "menvpos", "0.0", "mrelease", "1.0", "msustain", "0.5", "noise", "0.0", "o1bend", "0.0", "o1fine", "0.0", "o1level", "0.8", "o1oct", "0.0", "o1pos", "0.0", "o1semi", "0.0", "o1table", "Organ", "o2bend", "0.0", "o2fine", "7.0", "o2level", "0.0", "o2oct", "0.0", "o2pos", "0.3", "o2semi", "0.0", "o2table", "Classic", "release", "0.15", "reso", "0.0", "spread", "0.3", "sub", "0.0", "sustain", "1.0", "unison", "1.0", "velsens", "0.5", "wtframe", "Auto", nullptr};
|
||||
inline const char *const factory92[] = {"attack", "0.0", "cutoff", "0.55", "decay", "0.4", "drive", "0.4", "fenv", "0.35", "ftype", "Low", "keytrack", "0.4", "lfocut", "0.0", "lfodiv", "1.0", "lfopitch", "0.0", "lfopos", "0.15", "lfowave", "Sine", "mattack", "0.0", "mdecay", "0.3", "menvpos", "0.7", "mrelease", "1.0", "msustain", "0.0", "noise", "0.0", "o1bend", "0.0", "o1fine", "0.0", "o1level", "0.8", "o1oct", "-1", "o1pos", "0.1", "o1semi", "0.0", "o1table", "Fold", "o2bend", "0.0", "o2fine", "7.0", "o2level", "0.0", "o2oct", "0.0", "o2pos", "0.3", "o2semi", "0.0", "o2table", "Classic", "release", "0.15", "reso", "0.15", "spread", "0.3", "sub", "0.5", "sustain", "0.7", "unison", "1.0", "velsens", "0.5", "wtframe", "Auto", nullptr};
|
||||
inline const char *const factory93[] = {"attack", "0.01", "cutoff", "0.8", "decay", "0.3", "drive", "0.0", "fenv", "0.2", "ftype", "Low", "keytrack", "0.4", "lfocut", "0.0", "lfodiv", "4", "lfopitch", "0.0", "lfopos", "0.6", "lfowave", "S&H", "mattack", "0.5", "mdecay", "2.0", "menvpos", "0.0", "mrelease", "1.0", "msustain", "0.5", "noise", "0.0", "o1bend", "0.0", "o1fine", "0.0", "o1level", "0.8", "o1oct", "0.0", "o1pos", "0.3", "o1semi", "0.0", "o1table", "Digital", "o2bend", "0.0", "o2fine", "7.0", "o2level", "0.5", "o2oct", "0.0", "o2pos", "0.9", "o2semi", "7", "o2table", "Digital", "release", "0.4", "reso", "0.3", "spread", "0.3", "sub", "0.0", "sustain", "0.8", "unison", "1.0", "velsens", "0.5", "wtframe", "Auto", nullptr};
|
||||
inline const char *const factory94[] = {"attack", "1.2", "cutoff", "0.7", "decay", "0.3", "drive", "0.0", "fenv", "0.2", "ftype", "Low", "keytrack", "0.4", "lfocut", "0.2", "lfodiv", "0", "lfopitch", "0.0", "lfopos", "0.15", "lfowave", "Sine", "mattack", "6.0", "mdecay", "6.0", "menvpos", "1.0", "mrelease", "1.0", "msustain", "1.0", "noise", "0.0", "o1bend", "0.0", "o1fine", "0.0", "o1level", "0.8", "o1oct", "0.0", "o1pos", "0.0", "o1semi", "0.0", "o1table", "Comb", "o2bend", "0.0", "o2fine", "7.0", "o2level", "0.0", "o2oct", "0.0", "o2pos", "0.3", "o2semi", "0.0", "o2table", "Classic", "release", "3.0", "reso", "0.15", "spread", "0.45", "sub", "0.0", "sustain", "0.8", "unison", "4", "velsens", "0.5", "wtframe", "Auto", nullptr};
|
||||
inline const char *const factory95[] = {"attack", "0.0", "cutoff", "0.7", "decay", "0.6", "drive", "0.0", "fenv", "0.4", "ftype", "Low", "keytrack", "0.4", "lfocut", "0.0", "lfodiv", "1.0", "lfopitch", "0.0", "lfopos", "0.15", "lfowave", "Sine", "mattack", "0.0", "mdecay", "0.5", "menvpos", "-1.0", "mrelease", "1.0", "msustain", "0.0", "noise", "0.0", "o1bend", "0.0", "o1fine", "0.0", "o1level", "0.8", "o1oct", "0.0", "o1pos", "1.0", "o1semi", "0.0", "o1table", "Odd Even", "o2bend", "0.0", "o2fine", "7.0", "o2level", "0.0", "o2oct", "0.0", "o2pos", "0.3", "o2semi", "0.0", "o2table", "Classic", "release", "0.4", "reso", "0.3", "spread", "0.3", "sub", "0.0", "sustain", "0.0", "unison", "1.0", "velsens", "0.5", "wtframe", "Auto", nullptr};
|
||||
inline const char *const factory96[] = {"attack", "2.0", "cutoff", "0.85", "decay", "0.3", "drive", "0.0", "fenv", "0.2", "ftype", "Low", "keytrack", "0.4", "lfocut", "0.0", "lfodiv", "1.0", "lfopitch", "0.0", "lfopos", "0.15", "lfowave", "Sine", "mattack", "5.0", "mdecay", "8.0", "menvpos", "1.0", "mrelease", "1.0", "msustain", "1.0", "noise", "0.0", "o1bend", "0.0", "o1fine", "0.0", "o1level", "0.8", "o1oct", "0.0", "o1pos", "0.0", "o1semi", "0.0", "o1table", "Harmonic Sweep", "o2bend", "0.0", "o2fine", "10.0", "o2level", "0.6", "o2oct", "0.0", "o2pos", "0.0", "o2semi", "0.0", "o2table", "Harmonic Sweep", "release", "3.0", "reso", "0.05", "spread", "0.3", "sub", "0.0", "sustain", "0.8", "unison", "2", "velsens", "0.5", "wtframe", "Auto", nullptr};
|
||||
inline const char *const factory97[] = {"cHiAtk", "3", "cHiMk", "2", "cHiRatio", "3", "cHiRel", "80", "cHiThr", "-24", "cLoAtk", "8", "cLoMk", "3", "cLoRatio", "4", "cLoRel", "140", "cLoThr", "-22", "cMidMk", "1", "cMidRatio", "2.5", "cMidThr", "-20", "eqHiFreq", "9000", "eqHiGain", "4", "eqLoFreq", "70", "eqLoGain", "4", "eqMidFreq", "450", "eqMidGain", "-2", "limCeil", "-0.3", "limRel", "80", "outGain", "2", "strength", "1.0", "xHi", "3000", "xLo", "120", nullptr};
|
||||
inline const char *const factory98[] = {"cLoAtk", "12", "cLoMk", "2", "cLoRatio", "3", "cLoRel", "160", "cLoThr", "-20", "cMidMk", "1", "cMidRatio", "2.5", "cMidThr", "-18", "eqHiFreq", "10000", "eqHiGain", "1.5", "eqLoFreq", "90", "eqLoGain", "2", "limCeil", "-0.5", "outGain", "1.5", "strength", "1.0", "xHi", "2500", "xLo", "160", nullptr};
|
||||
inline const char *const factory99[] = {"cHiAtk", "2", "cHiMk", "2", "cHiRatio", "4", "cHiRel", "60", "cHiThr", "-26", "cLoRatio", "1.5", "cMidRatio", "2", "eqHiFreq", "11000", "eqHiGain", "5", "eqMidFreq", "4000", "eqMidGain", "1", "limCeil", "-0.3", "outGain", "2", "strength", "1.0", "xHi", "4000", nullptr};
|
||||
inline const char *const factory100[] = {"cHiMk", "2", "cHiRatio", "3", "cHiThr", "-20", "cLoAtk", "6", "cLoMk", "3", "cLoRatio", "5", "cLoRel", "120", "cLoThr", "-18", "cMidAtk", "8", "cMidMk", "3", "cMidRatio", "4", "cMidRel", "120", "cMidThr", "-16", "eqHiFreq", "8000", "eqHiGain", "2", "eqLoFreq", "80", "eqLoGain", "3", "eqMidFreq", "2200", "eqMidGain", "3", "eqMidQ", "1.2", "limCeil", "-0.2", "limRel", "60", "outGain", "3", "strength", "1.0", "xHi", "2000", "xLo", "150", nullptr};
|
||||
inline const char *const factory101[] = {"cHiRatio", "1.5", "cLoAtk", "4", "cLoMk", "3", "cLoRatio", "6", "cLoRel", "100", "cLoThr", "-16", "cMidRatio", "2", "eqLoFreq", "60", "eqLoGain", "3", "eqMidFreq", "700", "eqMidGain", "-2", "limCeil", "-0.2", "outGain", "2.5", "strength", "1.0", "xHi", "3000", "xLo", "120", nullptr};
|
||||
inline const char *const factory102[] = {"cHiMk", "1", "cHiRatio", "2", "cHiThr", "-22", "cLoMk", "1.5", "cLoRatio", "2.5", "cLoThr", "-22", "cMidMk", "1", "cMidRatio", "2", "cMidThr", "-20", "eqHiFreq", "9000", "eqHiGain", "1.5", "eqLoFreq", "90", "eqLoGain", "1.5", "limCeil", "-0.5", "outGain", "1.5", "strength", "0.85", "xHi", "2600", "xLo", "180", nullptr};
|
||||
inline const char *const factory103[] = {"cHiAtk", "2", "cHiMk", "2", "cHiRatio", "3", "cHiRel", "60", "cHiThr", "-22", "cLoAtk", "3", "cLoMk", "2", "cLoRatio", "4", "cLoRel", "90", "cLoThr", "-18", "cMidAtk", "4", "cMidMk", "2", "cMidRatio", "3", "cMidRel", "90", "cMidThr", "-18", "eqHiFreq", "9000", "eqHiGain", "2", "eqLoFreq", "80", "eqLoGain", "2", "eqMidFreq", "2500", "eqMidGain", "1.5", "limCeil", "-0.3", "limRel", "50", "outGain", "2", "strength", "1.0", "xHi", "2500", "xLo", "150", nullptr};
|
||||
inline const char *const factory104[] = {"cHiRatio", "1.5", "cLoMk", "1", "cLoRatio", "2.5", "cLoThr", "-22", "cMidRatio", "2", "eqHiFreq", "6000", "eqHiGain", "-4", "eqLoFreq", "100", "eqLoGain", "2", "eqMidFreq", "500", "eqMidGain", "1", "limCeil", "-1", "outGain", "1", "strength", "0.8", "xHi", "2200", "xLo", "200", nullptr};
|
||||
inline const char *const factory105[] = {"cHiAtk", "2", "cHiMk", "2", "cHiRatio", "3", "cHiRel", "70", "cHiThr", "-22", "cLoRatio", "1.5", "cMidAtk", "3", "cMidMk", "2", "cMidRatio", "4", "cMidRel", "100", "cMidThr", "-18", "eqHiFreq", "8000", "eqHiGain", "3", "eqLoFreq", "200", "eqLoGain", "-2", "eqMidFreq", "2000", "eqMidGain", "3", "eqMidQ", "1.5", "limCeil", "-0.3", "outGain", "2", "strength", "1.0", "xHi", "1800", "xLo", "250", nullptr};
|
||||
inline const char *const factory106[] = {"cHiAtk", "2", "cHiMk", "2", "cHiRatio", "3", "cLoRatio", "1.5", "cMidAtk", "3", "cMidMk", "1", "cMidRatio", "3", "eqHiFreq", "9000", "eqHiGain", "4", "eqMidFreq", "1500", "eqMidGain", "2", "outGain", "2", "strength", "1.0", "xHi", "3000", nullptr};
|
||||
inline const char *const factory107[] = {"cHiAtk", "5", "cHiMk", "1", "cHiRatio", "2.5", "cHiRel", "120", "cHiThr", "-26", "eqHiFreq", "12000", "eqHiGain", "4", "eqMidFreq", "3000", "eqMidGain", "-1", "limCeil", "-0.5", "outGain", "1.5", "strength", "0.75", "xHi", "5000", nullptr};
|
||||
inline const char *const factory108[] = {"cHiMk", "1", "cHiRatio", "2.5", "cLoMk", "1", "cLoRatio", "2", "cMidAtk", "4", "cMidMk", "1.5", "cMidRatio", "3", "eqHiFreq", "8000", "eqHiGain", "2", "eqMidFreq", "2500", "eqMidGain", "1.5", "outGain", "1.5", "strength", "1.0", "xHi", "2500", "xLo", "200", nullptr};
|
||||
inline const char *const factory109[] = {"cHiRatio", "1.5", "cLoAtk", "10", "cLoMk", "3", "cLoRatio", "4", "cLoRel", "130", "cLoThr", "-18", "cMidAtk", "12", "cMidMk", "2", "cMidRatio", "3", "cMidRel", "130", "cMidThr", "-18", "eqHiFreq", "9000", "eqHiGain", "-2", "eqLoFreq", "80", "eqLoGain", "3", "eqMidFreq", "800", "eqMidGain", "2", "eqMidQ", "1.2", "limCeil", "-0.3", "outGain", "2.5", "strength", "1.0", "xHi", "1500", "xLo", "150", nullptr};
|
||||
inline const char *const factory110[] = {"cHiRatio", "1.5", "cLoAtk", "8", "cLoMk", "3", "cLoRatio", "5", "cLoRel", "120", "cLoThr", "-16", "cMidMk", "2", "cMidRatio", "3", "cMidThr", "-18", "eqLoFreq", "70", "eqLoGain", "2", "eqMidFreq", "500", "eqMidGain", "2", "limCeil", "-0.3", "outGain", "2", "strength", "1.0", "xHi", "1200", "xLo", "140", nullptr};
|
||||
inline const char *const factory111[] = {"cHiRatio", "2", "cLoMk", "2", "cLoRatio", "3", "cMidAtk", "6", "cMidMk", "2", "cMidRatio", "4", "cMidRel", "110", "cMidThr", "-18", "eqLoFreq", "90", "eqLoGain", "1", "eqMidFreq", "1200", "eqMidGain", "3", "eqMidQ", "1.5", "limCeil", "-0.4", "outGain", "2", "strength", "1.0", "xHi", "1800", "xLo", "160", nullptr};
|
||||
inline const char *const factory112[] = {"cHiRatio", "1.2", "cLoAtk", "12", "cLoMk", "3", "cLoRatio", "6", "cLoRel", "150", "cLoThr", "-14", "cMidRatio", "2", "eqLoFreq", "55", "eqLoGain", "2", "eqMidFreq", "900", "eqMidGain", "-2", "limCeil", "-0.5", "outGain", "2", "strength", "0.9", "xHi", "2000", "xLo", "120", nullptr};
|
||||
inline const char *const factory113[] = {"cHiRatio", "2", "cLoAtk", "6", "cLoMk", "2", "cLoRatio", "4", "cLoRel", "110", "cLoThr", "-18", "cMidMk", "1.5", "cMidRatio", "3", "cMidThr", "-18", "eqLoFreq", "90", "eqLoGain", "2", "eqMidFreq", "1000", "eqMidGain", "1.5", "limCeil", "-0.3", "outGain", "2", "strength", "1.0", "xHi", "2200", "xLo", "160", nullptr};
|
||||
inline const char *const factory114[] = {"cHiRatio", "1.5", "cLoAtk", "10", "cLoMk", "3", "cLoRatio", "4", "cLoRel", "140", "cLoThr", "-18", "cMidMk", "1", "cMidRatio", "2.5", "eqHiFreq", "8000", "eqHiGain", "-2", "eqLoFreq", "75", "eqLoGain", "3", "eqMidFreq", "600", "eqMidGain", "-1", "limCeil", "-0.5", "outGain", "2", "strength", "0.9", "xHi", "1600", "xLo", "140", nullptr};
|
||||
inline const char *const factory115[] = {"cHiRatio", "2", "cLoAtk", "10", "cLoMk", "2", "cLoRatio", "3", "cLoRel", "130", "cLoThr", "-20", "cMidMk", "1", "cMidRatio", "2.5", "eqHiFreq", "7000", "eqHiGain", "1", "eqLoFreq", "80", "eqLoGain", "2.5", "eqMidFreq", "900", "eqMidGain", "1", "limCeil", "-0.5", "outGain", "1.8", "strength", "1.0", "xHi", "2000", "xLo", "150", nullptr};
|
||||
inline const char *const factory116[] = {"cHiMk", "1.5", "cHiRatio", "2", "cHiThr", "-22", "cLoRatio", "1.5", "cMidAtk", "12", "cMidMk", "1.5", "cMidRatio", "2.5", "cMidRel", "150", "cMidThr", "-20", "eqHiFreq", "9000", "eqHiGain", "4", "eqLoFreq", "200", "eqLoGain", "-1", "eqMidFreq", "2000", "eqMidGain", "1.5", "limCeil", "-0.5", "outGain", "2", "strength", "0.85", "xHi", "3000", "xLo", "300", nullptr};
|
||||
inline const char *const factory117[] = {"cHiMk", "1", "cHiRatio", "2", "cLoRatio", "1.5", "cMidAtk", "8", "cMidMk", "2", "cMidRatio", "3", "cMidRel", "130", "cMidThr", "-18", "eqHiFreq", "8000", "eqHiGain", "2", "eqLoFreq", "200", "eqLoGain", "-2", "eqMidFreq", "3000", "eqMidGain", "3", "eqMidQ", "1.2", "limCeil", "-0.4", "outGain", "2", "strength", "1.0", "xHi", "3500", "xLo", "300", nullptr};
|
||||
inline const char *const factory118[] = {"cHiRatio", "2", "cLoMk", "1", "cLoRatio", "2", "cMidAtk", "20", "cMidMk", "1", "cMidRatio", "2", "cMidRel", "200", "cMidThr", "-24", "eqHiFreq", "8000", "eqHiGain", "-2", "eqLoFreq", "150", "eqLoGain", "1", "eqMidFreq", "1000", "eqMidGain", "0.5", "limCeil", "-1", "outGain", "1", "strength", "0.7", "xHi", "2500", "xLo", "250", nullptr};
|
||||
inline const char *const factory119[] = {"cMidAtk", "30", "cMidMk", "0.5", "cMidRatio", "1.8", "cMidRel", "250", "cMidThr", "-26", "eqHiFreq", "10000", "eqHiGain", "1", "eqLoFreq", "120", "eqLoGain", "1", "limCeil", "-1.5", "outGain", "0.5", "strength", "0.6", "xHi", "3000", "xLo", "300", nullptr};
|
||||
inline const char *const factory120[] = {"cHiAtk", "2", "cHiMk", "1.5", "cHiRatio", "2.5", "cHiRel", "70", "cHiThr", "-22", "cLoRatio", "1.5", "cMidAtk", "3", "cMidMk", "1.5", "cMidRatio", "3", "cMidRel", "100", "cMidThr", "-18", "eqHiFreq", "9000", "eqHiGain", "3", "eqMidFreq", "2500", "eqMidGain", "2", "outGain", "1.5", "strength", "1.0", "xHi", "3000", "xLo", "300", nullptr};
|
||||
inline const char *const factory121[] = {"cHiAtk", "4", "cHiMk", "1.5", "cHiRatio", "2.5", "cHiThr", "-24", "cMidMk", "1", "cMidRatio", "2", "eqHiFreq", "11000", "eqHiGain", "4", "eqMidFreq", "3000", "eqMidGain", "1", "limCeil", "-0.5", "outGain", "1.5", "strength", "0.8", "xHi", "4000", nullptr};
|
||||
inline const char *const factory122[] = {"cHiMk", "1", "cHiRatio", "2", "cLoRatio", "1.2", "cMidMk", "2", "cMidRatio", "3", "cMidThr", "-18", "eqHiFreq", "8000", "eqHiGain", "2", "eqLoFreq", "150", "eqLoGain", "-3", "eqMidFreq", "2500", "eqMidGain", "2.5", "eqMidQ", "1.2", "limCeil", "-0.4", "outGain", "2", "strength", "1.0", "xHi", "3000", "xLo", "350", nullptr};
|
||||
inline const char *const factory123[] = {"cHiAtk", "4", "cHiMk", "1", "cHiRatio", "2", "cMidAtk", "6", "cMidMk", "1", "cMidRatio", "2", "eqHiFreq", "10000", "eqHiGain", "3", "eqMidFreq", "1800", "eqMidGain", "1.5", "limCeil", "-0.5", "outGain", "1", "strength", "0.75", "xHi", "4000", nullptr};
|
||||
inline const char *const factory124[] = {"cHiMk", "1", "cHiRatio", "2", "cLoRatio", "1.8", "cMidAtk", "10", "cMidMk", "1", "cMidRatio", "2.5", "cMidRel", "150", "cMidThr", "-22", "eqHiFreq", "9000", "eqHiGain", "2", "eqLoFreq", "200", "eqLoGain", "-1", "eqMidFreq", "2500", "eqMidGain", "1.5", "limCeil", "-0.5", "outGain", "1.5", "strength", "0.8", "xHi", "3000", "xLo", "250", nullptr};
|
||||
inline const char *const factory125[] = {"cHiAtk", "15", "cHiMk", "1", "cHiRatio", "2", "cHiRel", "180", "cHiThr", "-22", "cLoAtk", "20", "cLoMk", "1", "cLoRatio", "2", "cLoRel", "200", "cLoThr", "-22", "cMidAtk", "25", "cMidMk", "1", "cMidRatio", "2", "cMidRel", "200", "cMidThr", "-22", "eqHiFreq", "10000", "eqHiGain", "1", "eqLoFreq", "100", "eqLoGain", "0.5", "limCeil", "-0.8", "outGain", "1", "strength", "0.7", "xHi", "2500", "xLo", "200", nullptr};
|
||||
inline const char *const factory126[] = {"cHiMk", "2", "cHiRatio", "3", "cHiThr", "-20", "cLoMk", "2", "cLoRatio", "3", "cLoThr", "-20", "cMidMk", "2", "cMidRatio", "3", "cMidThr", "-18", "eqHiFreq", "9000", "eqHiGain", "2", "eqLoFreq", "90", "eqLoGain", "1", "limCeil", "-0.1", "limRel", "40", "outGain", "4", "strength", "1.0", "xHi", "2800", "xLo", "180", nullptr};
|
||||
inline const FactoryPreset factoryPresets[] = {
|
||||
{"AMBIENCE", "Abbey Road", factory0},
|
||||
{"AMBIENCE", "Abbey Road 2", factory1},
|
||||
{"AMBIENCE", "Capitol Studio A", factory2},
|
||||
{"AMBIENCE", "Skywalker Sound", factory3},
|
||||
{"AMBIENCE", "Carnegie Hall", factory4},
|
||||
{"AMBIENCE", "Tokyo Opera City", factory5},
|
||||
{"AMBIENCE", "Berlin Konzerthaus", factory6},
|
||||
{"AMBIENCE", "Vienna Musikverein", factory7},
|
||||
{"AMBIENCE", "Boston Symphony", factory8},
|
||||
{"AMBIENCE", "Concertgebouw", factory9},
|
||||
{"AMBIENCE", "EMT140 Vocal", factory10},
|
||||
{"AMBIENCE", "EMT140 Snare", factory11},
|
||||
{"AMBIENCE", "Dark Plate", factory12},
|
||||
{"AMBIENCE", "Surf Guitar", factory13},
|
||||
{"AMBIENCE", "Vintage Studio", factory14},
|
||||
{"AMBIENCE", "Deep Tank", factory15},
|
||||
{"AMBIENCE", "Gothic Cathedral", factory16},
|
||||
{"AMBIENCE", "Stone Chamber", factory17},
|
||||
{"AMBIENCE", "Infinite Space", factory18},
|
||||
{"AMBIENCE", "Drums in a Box", factory19},
|
||||
{"AMBIENCE", "Tracking Room", factory20},
|
||||
{"NES_SYNTH", "NES Lead", factory21},
|
||||
{"NES_SYNTH", "Square Bass", factory22},
|
||||
{"NES_SYNTH", "Pulse Pluck", factory23},
|
||||
{"NES_SYNTH", "Triangle Sub", factory24},
|
||||
{"NES_SYNTH", "Detune Lead", factory25},
|
||||
{"NES_SYNTH", "Noise Perc", factory26},
|
||||
{"NES_SYNTH", "Vibrato Lead", factory27},
|
||||
{"NES_SYNTH", "Wah Sweep", factory28},
|
||||
{"NES_SYNTH", "Pluck Bass", factory29},
|
||||
{"NES_SYNTH", "Acid Pluck", factory30},
|
||||
{"NES_SYNTH", "Razor Lead", factory31},
|
||||
{"NES_SYNTH", "Cold Lead", factory32},
|
||||
{"NES_SYNTH", "Grit Sub", factory33},
|
||||
{"NES_SYNTH", "Detune Wall", factory34},
|
||||
{"MORPH_PAD", "Mist", factory35},
|
||||
{"MORPH_PAD", "Cathedral", factory36},
|
||||
{"MORPH_PAD", "Glacier", factory37},
|
||||
{"MORPH_PAD", "Abyss", factory38},
|
||||
{"MORPH_PAD", "Aurora", factory39},
|
||||
{"MORPH_PAD", "Ember", factory40},
|
||||
{"MORPH_PAD", "Tide", factory41},
|
||||
{"MORPH_PAD", "Dust", factory42},
|
||||
{"MORPH_PAD", "Wind", factory43},
|
||||
{"MORPH_PAD", "Organ", factory44},
|
||||
{"MORPH_PAD", "Hollow", factory45},
|
||||
{"MORPH_PAD", "Vowel", factory46},
|
||||
{"MORPH_PAD", "Shimmer", factory47},
|
||||
{"MORPH_PAD", "Chanter", factory48},
|
||||
{"MORPH_PAD", "Ensemble", factory49},
|
||||
{"MORPH_PAD", "Bells", factory50},
|
||||
{"MORPH_PAD", "Nocturne", factory51},
|
||||
{"MORPH_PAD", "Haze", factory52},
|
||||
{"MORPH_PAD", "Pulse", factory53},
|
||||
{"MORPH_PAD", "Rime", factory54},
|
||||
{"MORPH_PAD", "Deep", factory55},
|
||||
{"MORPH_PAD", "Spectral", factory56},
|
||||
{"MORPH_PAD", "Rust", factory57},
|
||||
{"MORPH_PAD", "Still", factory58},
|
||||
{"MORPH_PAD", "Velvet", factory59},
|
||||
{"MORPH_PAD", "Chrome", factory60},
|
||||
{"MORPH_PAD", "Swarm", factory61},
|
||||
{"MORPH_PAD", "Foghorn", factory62},
|
||||
{"MORPH_PAD", "Solar", factory63},
|
||||
{"MORPH_PAD", "Cave", factory64},
|
||||
{"MORPH_PAD", "Glass Harp", factory65},
|
||||
{"MORPH_PAD", "Monk", factory66},
|
||||
{"MORPH_PAD", "Static", factory67},
|
||||
{"MORPH_PAD", "Lullaby", factory68},
|
||||
{"MORPH_PAD", "Storm", factory69},
|
||||
{"MORPH_PAD", "Prism", factory70},
|
||||
{"GRAIN_CLOUD", "Felt Clouds", factory71},
|
||||
{"GRAIN_CLOUD", "Glass Choir", factory72},
|
||||
{"GRAIN_CLOUD", "Dust Lights", factory73},
|
||||
{"GRAIN_CLOUD", "Warm Tide", factory74},
|
||||
{"GRAIN_CLOUD", "Slow Tapes", factory75},
|
||||
{"GRAIN_CLOUD", "Deep Water", factory76},
|
||||
{"GRAIN_CLOUD", "Rain Cathedral", factory77},
|
||||
{"GRAIN_CLOUD", "Kalimba Steps", factory78},
|
||||
{"GRAIN_CLOUD", "Hymn", factory79},
|
||||
{"GRAIN_CLOUD", "Breath Choir", factory80},
|
||||
{"GRAIN_CLOUD", "Night Current", factory81},
|
||||
{"GRAIN_CLOUD", "Glass Rain", factory82},
|
||||
{"GRAIN_CLOUD", "Broken Stars", factory83},
|
||||
{"GRAIN_CLOUD", "Far Broadcast", factory84},
|
||||
{"WAVETABLE", "Morph Lead", factory85},
|
||||
{"WAVETABLE", "Vowel Pad", factory86},
|
||||
{"WAVETABLE", "PWM Strings", factory87},
|
||||
{"WAVETABLE", "Sync Sweep", factory88},
|
||||
{"WAVETABLE", "FM Bells", factory89},
|
||||
{"WAVETABLE", "Glass Keys", factory90},
|
||||
{"WAVETABLE", "Organ Drift", factory91},
|
||||
{"WAVETABLE", "Fold Bass", factory92},
|
||||
{"WAVETABLE", "Digital Grit", factory93},
|
||||
{"WAVETABLE", "Comb Choir", factory94},
|
||||
{"WAVETABLE", "Odd Even Pluck", factory95},
|
||||
{"WAVETABLE", "Harmonic Rise", factory96},
|
||||
{"MIX_TIGHTENER", "808 Crisp", factory97},
|
||||
{"MIX_TIGHTENER", "Boom-Bap Kit", factory98},
|
||||
{"MIX_TIGHTENER", "Trap Hats", factory99},
|
||||
{"MIX_TIGHTENER", "Industrial Drums", factory100},
|
||||
{"MIX_TIGHTENER", "Techno Kick", factory101},
|
||||
{"MIX_TIGHTENER", "House Groove", factory102},
|
||||
{"MIX_TIGHTENER", "DnB Breaks", factory103},
|
||||
{"MIX_TIGHTENER", "Lo-Fi Kit", factory104},
|
||||
{"MIX_TIGHTENER", "Snare Crack", factory105},
|
||||
{"MIX_TIGHTENER", "Clap Snap", factory106},
|
||||
{"MIX_TIGHTENER", "Cymbal Sheen", factory107},
|
||||
{"MIX_TIGHTENER", "Percussion Tight", factory108},
|
||||
{"MIX_TIGHTENER", "EBM Bass", factory109},
|
||||
{"MIX_TIGHTENER", "Reese Bass", factory110},
|
||||
{"MIX_TIGHTENER", "Acid 303", factory111},
|
||||
{"MIX_TIGHTENER", "Sub Bass Tame", factory112},
|
||||
{"MIX_TIGHTENER", "FM Bass Punch", factory113},
|
||||
{"MIX_TIGHTENER", "Goth Bass", factory114},
|
||||
{"MIX_TIGHTENER", "Synthwave Bass", factory115},
|
||||
{"MIX_TIGHTENER", "Synthwave Lead", factory116},
|
||||
{"MIX_TIGHTENER", "Cutting Lead", factory117},
|
||||
{"MIX_TIGHTENER", "Darkwave Pad", factory118},
|
||||
{"MIX_TIGHTENER", "Ambient Wash", factory119},
|
||||
{"MIX_TIGHTENER", "Pluck Tight", factory120},
|
||||
{"MIX_TIGHTENER", "Arp Sparkle", factory121},
|
||||
{"MIX_TIGHTENER", "Chip Lead", factory122},
|
||||
{"MIX_TIGHTENER", "Bell Clarity", factory123},
|
||||
{"MIX_TIGHTENER", "Keys Clarity", factory124},
|
||||
{"MIX_TIGHTENER", "Mix Glue", factory125},
|
||||
{"MIX_TIGHTENER", "Loudness Max", factory126},
|
||||
};
|
||||
inline constexpr int factoryPresetCount = 127;
|
||||
|
||||
} // namespace sizzle::gen
|
||||
@@ -0,0 +1,40 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "sizzle/Params.hpp"
|
||||
|
||||
namespace sizzle {
|
||||
|
||||
/**
|
||||
* An insert effect: the C++ twin of AudioEffect in Effects.kt. `update` refreshes
|
||||
* cached settings (call it when the params change, and once before processing);
|
||||
* `process` runs per mono sample and must never allocate or lock. Construct on a
|
||||
* normal thread: constructors allocate delay lines for [sampleRate].
|
||||
*/
|
||||
class Effect {
|
||||
public:
|
||||
virtual ~Effect() = default;
|
||||
virtual void update(const Params &p, float tempoBpm) = 0;
|
||||
virtual float process(float x) = 0;
|
||||
|
||||
// ---- visualisation (Kotlin's VizEffect), optional
|
||||
// The audio thread publishes a small snapshot while it runs process(); the UI
|
||||
// reads it at frame rate from another thread, without locks (relaxed atomics: a
|
||||
// value one frame stale is harmless). Publishing must never change the audio.
|
||||
|
||||
/** True if this effect publishes a scope and playhead (a VizEffect). */
|
||||
virtual bool hasScope() const { return false; }
|
||||
/** Copy up to [capacity] of the latest scope samples, oldest to newest, into
|
||||
* [out]; returns the count written, or -1 if the effect has no scope. */
|
||||
virtual int copyScope(float *out, int capacity) const { (void)out; (void)capacity; return -1; }
|
||||
/** The read/play head within the scope window, 0 (oldest) to 1 (newest), or -1. */
|
||||
virtual float playhead() const { return -1.f; }
|
||||
|
||||
/** The effect for ToolboxType name [type] ("DELAY", "FILTER", …), or nullptr
|
||||
* for types without an audio processor (the MIDI effects) or not ported yet. */
|
||||
static std::unique_ptr<Effect> create(const char *type, int sampleRate);
|
||||
};
|
||||
|
||||
} // namespace sizzle
|
||||
@@ -0,0 +1,145 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
|
||||
// The sequencer and mixer engine: a port of audio/AudioEngine.kt (plus its
|
||||
// ChannelArp, the MIDI LFO, the transposer, the arrangement playlist with loop
|
||||
// regions, note-offs, mutes/solo, per-channel FX chains, the master limiter).
|
||||
// Checked against whole songs rendered by the Kotlin engine (core/tests/engine_test).
|
||||
//
|
||||
// Not here: the audio output (the app calls fillBlock from its AVAudioEngine
|
||||
// render callback), WAV writing for master recording (plug in a MasterSink),
|
||||
// CoreMIDI (the engine fills an outgoing MIDI queue; the app drains pollMidiOut).
|
||||
//
|
||||
// Threads, as in the Kotlin: setProject / play / pause / stop / rebuild* run on
|
||||
// the main thread, fillBlock on the audio thread (no allocation, no locks). The
|
||||
// live note calls (liveNoteOn, auditionSlotOn, busNoteOn, panic, ...) touch the
|
||||
// voices directly, as the Kotlin does: call them from the audio thread (e.g. drain
|
||||
// a queue before fillBlock) or otherwise serialise them with it.
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace sizzle::model {
|
||||
struct Project;
|
||||
}
|
||||
namespace sizzle::sampler {
|
||||
class SampleStore;
|
||||
}
|
||||
|
||||
namespace sizzle::engine {
|
||||
|
||||
/** TransportState.kt: where playback is, for the playhead. */
|
||||
struct TransportState {
|
||||
bool isPlaying = false;
|
||||
/** Absolute line index within the currently-playing pattern. */
|
||||
int currentLine = 0;
|
||||
/** Beat index within the arrangement. */
|
||||
int currentBeat = 0;
|
||||
};
|
||||
|
||||
/** Kotlin's process-wide voice state at the moment the engine is built: the Morph
|
||||
* Pad's shared clock (FrasilClock.seconds) and the seed counters every new
|
||||
* FrasilVoice / GrainCloud draws from. The defaults are a fresh process's. */
|
||||
struct EngineGlobals {
|
||||
double clockSeconds = 0.0;
|
||||
uint32_t frasilSeeds = 0x2545F491u;
|
||||
uint32_t grainSeeds = 0x1234567u;
|
||||
};
|
||||
|
||||
/** Where a master recording goes (MasterRecorder.kt, minus the file): begin() when
|
||||
* an armed take starts (false = can't record), write() per output frame on the
|
||||
* audio thread (must not block), endCapture() after the FX tail. */
|
||||
class MasterSink {
|
||||
public:
|
||||
virtual ~MasterSink() = default;
|
||||
virtual bool isActive() const = 0;
|
||||
virtual bool begin() = 0;
|
||||
virtual void write(float left, float right) = 0;
|
||||
virtual void endCapture() = 0;
|
||||
};
|
||||
|
||||
class Engine {
|
||||
public:
|
||||
static constexpr int BLOCK_FRAMES = 192; // the Kotlin's block (the MIDI LFO steps by it)
|
||||
static constexpr int POLYPHONY = 8;
|
||||
static constexpr int LIVE_POLYPHONY = 8;
|
||||
static constexpr int AUDITION_POLYPHONY = 8;
|
||||
static constexpr int BUS_POLYPHONY = 8;
|
||||
|
||||
/** [store]: where Sampler / SF2 / Grain Cloud samples are looked up (may be null:
|
||||
* no samples). Builds every voice in AudioEngine's order from [globals]. */
|
||||
explicit Engine(int sampleRate = 48000, sampler::SampleStore *store = nullptr,
|
||||
const EngineGlobals &globals = {});
|
||||
~Engine();
|
||||
Engine(const Engine &) = delete;
|
||||
Engine &operator=(const Engine &) = delete;
|
||||
|
||||
int sampleRate() const;
|
||||
|
||||
// ---- song (main thread)
|
||||
/** The song to play; it must outlive the engine or the next setProject. */
|
||||
void setProject(model::Project *p);
|
||||
/** Re-resolve each channel's FX slots into effect processors (routing changed). */
|
||||
void rebuildFxChains();
|
||||
/** Rebuild the arrangement playlist and reset the position. */
|
||||
void rebuildArrangement();
|
||||
/** Rebuild the playlist (loop region edits) without moving the position. */
|
||||
void refreshLoopPlaylist();
|
||||
|
||||
// ---- transport (main thread)
|
||||
void play(int startBeat = -1);
|
||||
void pause();
|
||||
/** Stop; if already stopped, rewind to the top. */
|
||||
void stop();
|
||||
/** Hard-silence every voice and cancel the arpeggiators. */
|
||||
void panic();
|
||||
TransportState transport() const;
|
||||
bool isPlaying() const;
|
||||
|
||||
// ---- audio thread
|
||||
/** Render [frames] interleaved stereo frames into [out] (frames * 2 floats). */
|
||||
void fillBlock(float *out, int frames);
|
||||
|
||||
// ---- live notes (see the thread note above)
|
||||
void liveNoteOn(int pitch, int velocity);
|
||||
void liveNoteOff(int pitch);
|
||||
void auditionSlotOn(int slotIndex, int midi);
|
||||
void auditionSlotOff(int midi);
|
||||
void busNoteOn(int midiChannel, int midi, int velocity);
|
||||
void busNoteOff(int midiChannel, int midi);
|
||||
/** For a MIDI trace: what busNoteOn would play (allocates; not for the audio thread). */
|
||||
std::string describeBusTargets(int midiChannel, int midi) const;
|
||||
|
||||
// ---- mixer meters (any thread, display only)
|
||||
float channelMeter(int ch) const;
|
||||
bool channelClipped(int ch) const;
|
||||
/** Effect visualisation (AudioEngine.effectScope / effectPlayhead), any thread:
|
||||
* toolbox [slotIndex]'s live scope (oldest → newest, up to [capacity] samples)
|
||||
* and read head (0..1) from the first channel chain that runs it, or -1 when it
|
||||
* isn't a scope effect placed on a mixer channel (nothing to draw). Lock-free;
|
||||
* chains swapped out meanwhile are kept alive until the read is done. */
|
||||
int effectScope(int slotIndex, float *out, int capacity) const;
|
||||
float effectPlayhead(int slotIndex) const;
|
||||
|
||||
// ---- outgoing MIDI: (status << 16) | (data1 << 8) | data2, or -1 when empty
|
||||
void setMidiOutEnabled(bool on);
|
||||
bool midiOutEnabled() const;
|
||||
int pollMidiOut();
|
||||
|
||||
// ---- master recording
|
||||
void setMasterSink(MasterSink *sink);
|
||||
void setRecordingArm(bool armed, int tailBars);
|
||||
void setRecordTailBars(int tailBars);
|
||||
bool recordArmed() const;
|
||||
void externalClockStart();
|
||||
void externalClockStop();
|
||||
|
||||
class Impl;
|
||||
|
||||
private:
|
||||
std::unique_ptr<Impl> impl;
|
||||
};
|
||||
|
||||
} // namespace sizzle::engine
|
||||
@@ -0,0 +1,50 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "sizzle/Params.hpp"
|
||||
|
||||
namespace sizzle {
|
||||
|
||||
namespace sampler { class SampleStore; }
|
||||
|
||||
/**
|
||||
* One playable instrument: a pool of voices for a ToolboxType, the way AudioEngine
|
||||
* plays one mixer channel's instrument (8 voices, a free voice first, else the
|
||||
* round-robin one; synth voices are cut when stolen, sample voices declick).
|
||||
* Used by the AUv3 instruments and the in-app host until the full engine is ported.
|
||||
*
|
||||
* Threads: construct and call update()/noteOn()/noteOff()/render() from the audio
|
||||
* thread only (the AU wrapper hands parameter changes over itself). No allocation
|
||||
* after construction.
|
||||
*/
|
||||
class Instrument {
|
||||
public:
|
||||
virtual ~Instrument() = default;
|
||||
/** New settings (and tempo): rebuild the patch, and let held notes follow it
|
||||
* where the Kotlin engine does (synth voices take the new patch). */
|
||||
virtual void update(const Params &p, float tempoBpm) = 0;
|
||||
virtual void noteOn(int midi, int velocity) = 0;
|
||||
/** Release the held note(s) at [midi]. */
|
||||
virtual void noteOff(int midi) = 0;
|
||||
/** Release everything (MIDI all-notes-off, transport stop). */
|
||||
virtual void allNotesOff() = 0;
|
||||
/** Hard stop, no release tails. */
|
||||
virtual void kill() = 0;
|
||||
/** Before each render block of [frames]: advances the Morph Pad's shared clock
|
||||
* and lets the sample store reclaim memory. */
|
||||
virtual void blockStart(int frames) = 0;
|
||||
/** One mono output sample. */
|
||||
virtual float render() = 0;
|
||||
|
||||
static constexpr int POLYPHONY = 8;
|
||||
|
||||
/** The instrument for ToolboxType [type] (NES_SYNTH, MORPH_PAD, WAVETABLE,
|
||||
* GRAIN_CLOUD, SAMPLER, SOUNDFONT), or nullptr. [store] supplies samples for
|
||||
* the Sampler, SF2/XI loader and Grain Cloud custom sources (may be null:
|
||||
* those then stay silent); it must outlive the instrument. */
|
||||
static std::unique_ptr<Instrument> create(const char *type, int sampleRate, sampler::SampleStore *store);
|
||||
};
|
||||
|
||||
} // namespace sizzle
|
||||
@@ -0,0 +1,194 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// MIDI input pieces with no platform types, ported from the Android app:
|
||||
// - MidiByteParser (input/MidiByteParser.kt): raw bytes -> whole messages, with
|
||||
// running status, split messages, real-time bytes anywhere, SysEx skipped.
|
||||
// - MidiSoundModule (playback/MidiSoundModule.kt): notes per source -> a NoteSink,
|
||||
// All Notes Off / All Sound Off, release of a vanished source's held notes.
|
||||
// Tested by core/tests/midi_test.cpp.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <utility>
|
||||
|
||||
namespace sizzle::midi {
|
||||
|
||||
/** One parser per stream (running status is per stream). Not thread-safe. */
|
||||
class MidiByteParser {
|
||||
public:
|
||||
/** A complete channel message: status 0x80..0xEF and its data bytes (0 when absent). */
|
||||
using Channel = std::function<void(int status, int d1, int d2)>;
|
||||
/** A System Real-Time byte: clock 0xF8, Start 0xFA, Continue 0xFB, Stop 0xFC, ... */
|
||||
using Realtime = std::function<void(int status)>;
|
||||
|
||||
MidiByteParser(Channel onChannel, Realtime onRealtime)
|
||||
: onChannel(std::move(onChannel)), onRealtime(std::move(onRealtime)) {}
|
||||
|
||||
void feed(const uint8_t *data, size_t count) {
|
||||
for (size_t i = 0; i < count; ++i) byte(data[i]);
|
||||
}
|
||||
|
||||
private:
|
||||
void byte(int b) {
|
||||
if (b >= 0xF8) { onRealtime(b); return; } // never disturbs running status
|
||||
if (b == 0xF0) { inSysex = true; running = 0; return; }
|
||||
if (b == 0xF7) { inSysex = false; return; }
|
||||
if (b >= 0xF1) { inSysex = false; running = 0; need = 0; return; } // system common
|
||||
if (b >= 0x80) {
|
||||
inSysex = false;
|
||||
running = b; got = 0;
|
||||
need = ((b & 0xF0) == 0xC0 || (b & 0xF0) == 0xD0) ? 1 : 2;
|
||||
return;
|
||||
}
|
||||
if (inSysex || running == 0) return; // stray data byte
|
||||
if (got == 0) d1 = b;
|
||||
if (++got >= need) {
|
||||
onChannel(running, d1, need == 2 ? b : 0);
|
||||
got = 0; // running status: the next data byte starts a new message
|
||||
}
|
||||
}
|
||||
|
||||
Channel onChannel;
|
||||
Realtime onRealtime;
|
||||
int running = 0, need = 0, got = 0, d1 = 0;
|
||||
bool inSysex = false;
|
||||
};
|
||||
|
||||
/** Where the sound module plays notes (channel 1..16). */
|
||||
class NoteSink {
|
||||
public:
|
||||
virtual ~NoteSink() = default;
|
||||
virtual void busNoteOn(int channel, int note, int velocity) = 0;
|
||||
virtual void busNoteOff(int channel, int note) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* The headless multitimbral sound module: Note On/Off on channel N play/release the
|
||||
* mixer tracks listening on N; CC 123 / 120 release that channel's held notes from
|
||||
* every source; notes are tracked per source so a source that goes away has its
|
||||
* notes released. [listener] mirrors every note played or released (for the UI).
|
||||
* Thread-safe (one lock; each MIDI stream may deliver on its own thread).
|
||||
*/
|
||||
class MidiSoundModule {
|
||||
public:
|
||||
using Listener = std::function<void(bool on, int channel, int note, int velocity)>;
|
||||
|
||||
explicit MidiSoundModule(NoteSink &sink) : sink(sink) {}
|
||||
|
||||
Listener listener;
|
||||
|
||||
void sourceConnected(intptr_t source) { std::lock_guard<std::mutex> g(lock); held[source]; }
|
||||
|
||||
void sourceDisconnected(intptr_t source) {
|
||||
std::lock_guard<std::mutex> g(lock);
|
||||
auto it = held.find(source);
|
||||
if (it == held.end()) return;
|
||||
for (int k : it->second) release(k);
|
||||
held.erase(it);
|
||||
}
|
||||
|
||||
/** True when consumed (notes, all-notes-off); other messages are the caller's. */
|
||||
bool onChannelMessage(intptr_t source, int status, int d1, int d2) {
|
||||
const int channel = (status & 0x0F) + 1, note = d1 & 0x7F;
|
||||
switch (status & 0xF0) {
|
||||
case 0x90: if (d2 > 0) noteOn(source, channel, note, d2); else noteOff(source, channel, note); return true;
|
||||
case 0x80: noteOff(source, channel, note); return true;
|
||||
case 0xB0: if (d1 == 123 || d1 == 120) { channelOff(channel); return true; } return false;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** Release everything any source holds (panic, shutdown). */
|
||||
void releaseAll() {
|
||||
std::lock_guard<std::mutex> g(lock);
|
||||
for (auto &[src, keys] : held) { for (int k : keys) release(k); keys.clear(); }
|
||||
}
|
||||
|
||||
/** Held (channel, note) pairs of [source], for tests. */
|
||||
std::set<std::pair<int, int>> heldNotes(intptr_t source) {
|
||||
std::lock_guard<std::mutex> g(lock);
|
||||
std::set<std::pair<int, int>> out;
|
||||
auto it = held.find(source);
|
||||
if (it != held.end()) for (int k : it->second) out.insert({k / 128 + 1, k % 128});
|
||||
return out;
|
||||
}
|
||||
|
||||
int sourceCount() { std::lock_guard<std::mutex> g(lock); return (int)held.size(); }
|
||||
|
||||
private:
|
||||
void noteOn(intptr_t source, int channel, int note, int velocity) {
|
||||
std::lock_guard<std::mutex> g(lock);
|
||||
held[source].insert(key(channel, note));
|
||||
sink.busNoteOn(channel, note, velocity);
|
||||
if (listener) listener(true, channel, note, velocity);
|
||||
}
|
||||
|
||||
// Every Note Off reaches the engine, even for a note we don't think is held:
|
||||
// a stuck voice is worse than a redundant release.
|
||||
void noteOff(intptr_t source, int channel, int note) {
|
||||
std::lock_guard<std::mutex> g(lock);
|
||||
auto it = held.find(source);
|
||||
if (it != held.end()) it->second.erase(key(channel, note));
|
||||
sink.busNoteOff(channel, note);
|
||||
if (listener) listener(false, channel, note, 0);
|
||||
}
|
||||
|
||||
void channelOff(int channel) {
|
||||
std::lock_guard<std::mutex> g(lock);
|
||||
for (auto &[src, keys] : held) {
|
||||
for (auto it = keys.begin(); it != keys.end();) {
|
||||
if (*it / 128 + 1 == channel) { release(*it); it = keys.erase(it); } else ++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void release(int k) {
|
||||
sink.busNoteOff(k / 128 + 1, k % 128);
|
||||
if (listener) listener(false, k / 128 + 1, k % 128, 0);
|
||||
}
|
||||
|
||||
static int key(int channel, int note) { return (channel - 1) * 128 + note; }
|
||||
|
||||
NoteSink &sink;
|
||||
std::mutex lock;
|
||||
std::map<intptr_t, std::set<int>> held;
|
||||
};
|
||||
|
||||
/** MidiClock.kt's receive side: Start/Continue/Stop and a tempo from the pulse
|
||||
* rate, averaged over a quarter note (24 pulses). [nowNs] is a monotonic clock. */
|
||||
class ClockFollower {
|
||||
public:
|
||||
std::function<void(bool start)> onTransport; // Start/Continue = true, Stop = false
|
||||
std::function<void(float bpm)> onTempo;
|
||||
|
||||
void realtime(int status, int64_t nowNs) {
|
||||
if (status == 0xFA || status == 0xFB) { reset(); if (onTransport) onTransport(true); }
|
||||
else if (status == 0xFC) { if (onTransport) onTransport(false); }
|
||||
else if (status == 0xF8) pulse(nowNs);
|
||||
}
|
||||
|
||||
private:
|
||||
void reset() { lastNs = 0; accum = 0; count = 0; }
|
||||
void pulse(int64_t now) {
|
||||
if (lastNs != 0) {
|
||||
accum += (double)(now - lastNs);
|
||||
if (++count >= 24) {
|
||||
const float bpm = (float)(60'000'000'000.0 / (accum / count * 24.0));
|
||||
if (bpm >= 20.f && bpm <= 300.f && onTempo) onTempo(bpm);
|
||||
accum = 0; count = 0;
|
||||
}
|
||||
}
|
||||
lastNs = now;
|
||||
}
|
||||
int64_t lastNs = 0;
|
||||
double accum = 0;
|
||||
int count = 0;
|
||||
};
|
||||
|
||||
} // namespace sizzle::midi
|
||||
@@ -0,0 +1,170 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
|
||||
// The song model: the C++ twin of the Android app's model/ package (Project,
|
||||
// Pattern, Cell, Arrangement, LoopRegion, Mixer, MixerChannel, ToolboxSlot,
|
||||
// TimeSignature, Scale, Pitch). Plain data with the same names, fields, defaults
|
||||
// and constants, so the file formats (core/src/io) and the engine
|
||||
// (core/src/engine) read like their Kotlin originals.
|
||||
//
|
||||
// Threads: like Android's, the model is edited by the UI and read by the audio
|
||||
// thread. Toolbox values are text (sizzle::Params), as ToolboxSlot's map is.
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "sizzle/Params.hpp"
|
||||
|
||||
namespace sizzle::model {
|
||||
|
||||
struct Pitch {
|
||||
static constexpr int LOWEST = 0, HIGHEST = 127, MIDDLE_C = 60;
|
||||
};
|
||||
|
||||
struct TimeSignatureInfo {
|
||||
const char *name; // enum name, as files store it ("FOUR_FOUR")
|
||||
const char *label; // "4/4"
|
||||
int linesPerBeat;
|
||||
int beatsPerBar;
|
||||
int lengthOptions[3];
|
||||
int linesPerBar() const { return linesPerBeat * beatsPerBar; }
|
||||
};
|
||||
|
||||
enum class TimeSignature { THREE_FOUR, FOUR_FOUR, FIVE_FOUR };
|
||||
inline constexpr int TIME_SIGNATURE_COUNT = 3;
|
||||
const TimeSignatureInfo &info(TimeSignature t);
|
||||
|
||||
struct ScaleInfo {
|
||||
const char *name; // "MINOR"
|
||||
const char *label; // "Natural Minor"
|
||||
int intervals[12];
|
||||
int count;
|
||||
};
|
||||
|
||||
enum class Scale { CHROMATIC, MAJOR, MINOR, HARMONIC_MINOR, DORIAN, PHRYGIAN, MIXOLYDIAN,
|
||||
PENTATONIC_MAJOR, PENTATONIC_MINOR, BLUES };
|
||||
inline constexpr int SCALE_COUNT = 10;
|
||||
const ScaleInfo &info(Scale s);
|
||||
|
||||
struct Cell {
|
||||
static constexpr int EMPTY = -1, OFF = -2, MAX_VELOCITY = 0x7F, MAX_CHANNEL = 16;
|
||||
int note = EMPTY;
|
||||
int velocity = MAX_VELOCITY;
|
||||
int channel = 1;
|
||||
bool isEmpty() const { return note == EMPTY; }
|
||||
bool isNoteOff() const { return note == OFF; }
|
||||
bool isPlayable() const { return note >= Pitch::LOWEST && note <= Pitch::HIGHEST; }
|
||||
void clear() { note = EMPTY; velocity = MAX_VELOCITY; }
|
||||
};
|
||||
|
||||
struct Pattern {
|
||||
static constexpr int TRACK_COUNT = 4;
|
||||
int id = 0;
|
||||
std::string name = "PTN";
|
||||
int length = 16;
|
||||
/** tracks[track][line]; cells start with channel 0, as Kotlin's do. */
|
||||
std::array<std::vector<Cell>, TRACK_COUNT> tracks;
|
||||
|
||||
Pattern(int id_ = 0, std::string name_ = "PTN", int length_ = 16);
|
||||
Cell &cell(int track, int line) { return tracks[track][line]; }
|
||||
const Cell &cell(int track, int line) const { return tracks[track][line]; }
|
||||
void resize(int newLength);
|
||||
};
|
||||
|
||||
struct LoopRegion {
|
||||
bool enabled = false;
|
||||
int start = 0, end = 0, repeats = 2;
|
||||
bool isValid() const { return enabled && end > start; }
|
||||
};
|
||||
|
||||
struct Arrangement {
|
||||
static constexpr int LANE_COUNT = 8, MAX_BARS = 256, MAX_BEATS = MAX_BARS * 5;
|
||||
static constexpr int EMPTY = -1, NOTE_OFF = -2;
|
||||
/** slots[lane][beat]: a pattern id, EMPTY or NOTE_OFF. */
|
||||
std::array<std::vector<int>, LANE_COUNT> slots;
|
||||
std::array<bool, LANE_COUNT> laneMuted{};
|
||||
int lengthBars = MAX_BARS;
|
||||
bool loopEnabled = false;
|
||||
LoopRegion regionA, regionB;
|
||||
|
||||
Arrangement();
|
||||
int canvasBeats(TimeSignature sig) const;
|
||||
int patternAt(int lane, int beat) const;
|
||||
bool hasBlockAt(int lane, int beat) const { return patternAt(lane, beat) >= 0; }
|
||||
int lastFilledBeat() const;
|
||||
void set(int lane, int beat, int patternId);
|
||||
};
|
||||
|
||||
struct MixerChannel {
|
||||
static constexpr int FX_SLOTS = 4;
|
||||
int index = 0;
|
||||
int instrumentSlot = -1;
|
||||
std::array<int, FX_SLOTS> fxSlots{-1, -1, -1, -1};
|
||||
int midiChannel = 1;
|
||||
float volume = 0.8f;
|
||||
bool mute = false, solo = false, limiter = false;
|
||||
bool audible(bool anySolo) const { return !mute && (!anySolo || solo); }
|
||||
};
|
||||
|
||||
struct Mixer {
|
||||
static constexpr int CHANNEL_COUNT = Pattern::TRACK_COUNT, FX_SLOTS = MixerChannel::FX_SLOTS;
|
||||
static constexpr int NO_DEVICE = -1;
|
||||
static constexpr float DEFAULT_VOLUME = 0.8f;
|
||||
std::array<MixerChannel, CHANNEL_COUNT> channels;
|
||||
Mixer(); // channel i: index i, midiChannel 0 (as Kotlin's Mixer builds them)
|
||||
bool anySolo() const;
|
||||
};
|
||||
|
||||
/** One toolbox slot: a device type (ToolboxType name; empty = no device), its
|
||||
* display name and its settings as text. */
|
||||
struct ToolboxSlot {
|
||||
int index = 0;
|
||||
std::string type;
|
||||
std::string name;
|
||||
Params values;
|
||||
/** Bumped on every settings write (Kotlin's `version`), so the engine can
|
||||
* skip re-reading unchanged slots. */
|
||||
uint32_t version = 0;
|
||||
|
||||
bool isEmpty() const { return type.empty(); }
|
||||
/** ToolboxSlot.fill: the type's defaults (spec order), its display name. */
|
||||
void fill(const std::string &newType);
|
||||
void clearSlot();
|
||||
float f(const char *key, float fallback = 0.f) const { return values.f(key, fallback); }
|
||||
const char *s(const char *key, const char *fallback = "") const { return values.s(key, fallback); }
|
||||
void set(const char *key, float v); // stored as Kotlin's Float.toString text (no allocation)
|
||||
void set(const char *key, const char *v);
|
||||
};
|
||||
|
||||
struct Project {
|
||||
static constexpr int TOOLBOX_SLOTS = 16;
|
||||
std::string name = "untitled";
|
||||
float tempoBpm = 120.f;
|
||||
TimeSignature timeSignature = TimeSignature::FOUR_FOUR;
|
||||
Scale scale = Scale::CHROMATIC;
|
||||
int rootNote = 0;
|
||||
/** LANE_COUNT patterns, ids 0..7, named BLK1..BLK8, first length option. */
|
||||
std::vector<Pattern> patterns;
|
||||
Arrangement arrangement;
|
||||
Mixer mixer;
|
||||
std::array<ToolboxSlot, TOOLBOX_SLOTS> toolbox;
|
||||
int activePatternId = 0;
|
||||
|
||||
Project();
|
||||
Pattern *pattern(int id);
|
||||
const Pattern *pattern(int id) const;
|
||||
Pattern &activePattern();
|
||||
};
|
||||
|
||||
/** Kotlin's Float.toString (JDK 17's algorithm), e.g. "120.0", "0.8", "1.0E-4":
|
||||
* what Android writes into settings and files. */
|
||||
std::string kotlinFloatToString(float v);
|
||||
/** Buffer size for kotlinFloatToChars (at most 26 chars + NUL). */
|
||||
inline constexpr int KOTLIN_FLOAT_CHARS = 32;
|
||||
/** The same text written into [out] (KOTLIN_FLOAT_CHARS bytes), NUL-terminated;
|
||||
* returns its length. No allocation: safe on the audio thread. */
|
||||
int kotlinFloatToChars(float v, char *out);
|
||||
|
||||
} // namespace sizzle::model
|
||||
@@ -0,0 +1,47 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include "sizzle/Specs.hpp"
|
||||
|
||||
namespace sizzle {
|
||||
|
||||
/**
|
||||
* A device's settings, the C++ twin of ToolboxSlot's string map: every value is
|
||||
* kept as text so `f()` / `s()` read exactly what the Kotlin `slot.float()` /
|
||||
* `slot.string()` would. Fixed capacity, no allocation: safe to read from
|
||||
* `Effect::update` on the audio thread. Keys are stored by copy, so values can
|
||||
* come from a file (tests), a preset, or AU parameters.
|
||||
*/
|
||||
class Params {
|
||||
public:
|
||||
static constexpr int kMax = 128;
|
||||
static constexpr int kKeyLen = 32;
|
||||
static constexpr int kValLen = 256; // sample ids and file paths
|
||||
|
||||
/** All of [spec]'s defaults, like ToolboxSlot.fill(). */
|
||||
void fill(const DeviceSpec &spec);
|
||||
void set(const char *key, const char *value);
|
||||
void set(const char *key, float value);
|
||||
/** Drop [key] (Kotlin's values.remove); the others keep their order. */
|
||||
void remove(const char *key);
|
||||
/** Number as Kotlin's String.toFloat would parse it, else [fallback]. */
|
||||
float f(const char *key, float fallback = 0.f) const;
|
||||
/** The stored text (enum choice name), else [fallback]. */
|
||||
const char *s(const char *key, const char *fallback = "") const;
|
||||
bool has(const char *key) const { return find(key) >= 0; }
|
||||
/** Stored entries in insertion order (for saving state). */
|
||||
int size() const { return n_; }
|
||||
const char *keyAt(int i) const { return keys_[i]; }
|
||||
const char *valueAt(int i) const { return vals_[i]; }
|
||||
|
||||
private:
|
||||
int find(const char *key) const;
|
||||
char keys_[kMax][kKeyLen] = {};
|
||||
char vals_[kMax][kValLen] = {};
|
||||
int n_ = 0;
|
||||
};
|
||||
|
||||
} // namespace sizzle
|
||||
@@ -0,0 +1,56 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
|
||||
// The preset pseudorandomizer: a playable patch from a seed, for the five devices
|
||||
// where "surprise me" is a musical thing to ask for. Shared by both apps (handover
|
||||
// §5.4.2's parity rule), so a roll of the dice gives the same patch on Android and
|
||||
// on iOS for the same seed.
|
||||
//
|
||||
// "Playable" is the whole point, and it is what makes this more than scattering
|
||||
// values over the parameter ranges:
|
||||
//
|
||||
// - audible. Something always sounds: at least one oscillator or layer is up, an
|
||||
// amp envelope that decays to nothing gets a body, a filter is never shut, and
|
||||
// a reverb is never fully dry.
|
||||
// - inside the rails. Oscillator levels share a budget, resonance, drive and
|
||||
// saturation stay below the range where a patch screams, and the reverb's wet
|
||||
// and dry cannot both sit at 0 dB. `randomizer_test` renders every device over
|
||||
// many seeds and fails if a patch comes out silent or clipping.
|
||||
// - musical where it matters. Tunings come from consonant intervals rather than
|
||||
// a uniform draw over ±12 semitones, detune stays inside a chorus, and pitch
|
||||
// modulation is small enough to stay in tune.
|
||||
//
|
||||
// Nothing structural is rolled: a sample or an imported wavetable is the user's
|
||||
// choice, so "Custom" sources and tables are never picked, and the sample keys a
|
||||
// slot already holds are left alone.
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include "sizzle/Params.hpp"
|
||||
|
||||
namespace sizzle::model {
|
||||
|
||||
/** True when [type] (a ToolboxType name) has a randomizer: NES_SYNTH, MORPH_PAD,
|
||||
* GRAIN_CLOUD, WAVETABLE and AMBIENCE. The UI shows its dice button for these. */
|
||||
bool canRandomize(const char *type);
|
||||
|
||||
/** Fill [out] with a playable random patch for [type]. Every value is written
|
||||
* through the device's own ParamSpec, so nothing can land outside its range or
|
||||
* off an enum's choices. [seed] makes it reproducible: the same seed is the same
|
||||
* patch, here and on the other platform. Returns false, leaving [out] untouched,
|
||||
* for a type with no randomizer. */
|
||||
bool randomize(const char *type, uint32_t seed, Params &out);
|
||||
|
||||
/** A short two-word name for the patch [seed] produces ("Hazy Drift"), so a roll
|
||||
* arrives with something to call it and SAVE has a name to offer. Empty for a
|
||||
* type with no randomizer. */
|
||||
std::string randomName(const char *type, uint32_t seed);
|
||||
|
||||
/** The whole thing as preset text (io::PresetIo's format, NAME included) — what
|
||||
* the Android app receives over JNI and hands to PresetIo.import. Empty for a
|
||||
* type with no randomizer. */
|
||||
std::string randomPresetText(const char *type, uint32_t seed);
|
||||
|
||||
} // namespace sizzle::model
|
||||
@@ -0,0 +1,45 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
|
||||
// SampleStore.Sample (SampleStore.kt): decoded mono PCM at its own rate, shared by
|
||||
// the Sampler / SoundFont voice (core/src/sampler) and the Grain Cloud's custom
|
||||
// source (core/src/echofield).
|
||||
|
||||
#include <atomic>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace sizzle {
|
||||
|
||||
struct Sample {
|
||||
std::vector<float> data;
|
||||
int sampleRate = 0;
|
||||
/** Sample-loop points in frames (from an SF2/XI file), or -1 when the source has
|
||||
* none; the SoundFont voice uses them for sustain looping. */
|
||||
int loopStart = -1;
|
||||
int loopEnd = -1;
|
||||
/** Players currently holding this sample across audio blocks (SampleVoice pins
|
||||
* it from noteOn until it lets go). sampler::SampleStore frees a removed sample
|
||||
* only once this is 0, which is what "a voice keeps its own reference" means in
|
||||
* the Kotlin. Not copied: a copy is a new, unpinned sample. */
|
||||
mutable std::atomic<int> users{0};
|
||||
|
||||
Sample() = default;
|
||||
Sample(std::vector<float> d, int rate, int ls = -1, int le = -1)
|
||||
: data(std::move(d)), sampleRate(rate), loopStart(ls), loopEnd(le) {}
|
||||
Sample(const Sample &o)
|
||||
: data(o.data), sampleRate(o.sampleRate), loopStart(o.loopStart), loopEnd(o.loopEnd) {}
|
||||
Sample(Sample &&o) noexcept
|
||||
: data(std::move(o.data)), sampleRate(o.sampleRate), loopStart(o.loopStart), loopEnd(o.loopEnd) {}
|
||||
Sample &operator=(const Sample &o) {
|
||||
data = o.data; sampleRate = o.sampleRate; loopStart = o.loopStart; loopEnd = o.loopEnd;
|
||||
return *this;
|
||||
}
|
||||
Sample &operator=(Sample &&o) noexcept {
|
||||
data = std::move(o.data); sampleRate = o.sampleRate; loopStart = o.loopStart; loopEnd = o.loopEnd;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace sizzle
|
||||
@@ -0,0 +1,43 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
|
||||
// Plain descriptions of Sizzle's devices and their parameters. The tables
|
||||
// themselves are generated from the Android app (DeviceSpecs.gen.hpp).
|
||||
|
||||
namespace sizzle {
|
||||
|
||||
enum class Kind { Instrument, Effect };
|
||||
|
||||
/** One parameter, as ToolboxType's ParamSpec: choices != nullptr marks an enum
|
||||
* (nullptr-terminated list of names; the default is an index into it). */
|
||||
struct ParamSpec {
|
||||
const char *key;
|
||||
const char *label;
|
||||
float def, min, max;
|
||||
bool isInt;
|
||||
const char *const *choices;
|
||||
bool isEnum() const { return choices != nullptr; }
|
||||
int choiceCount() const { int n = 0; if (choices) while (choices[n]) ++n; return n; }
|
||||
};
|
||||
|
||||
struct DeviceSpec {
|
||||
const char *type; // ToolboxType name, e.g. "BITCRUSHER"
|
||||
const char *displayName;
|
||||
Kind kind;
|
||||
const ParamSpec *params;
|
||||
int paramCount;
|
||||
};
|
||||
|
||||
/** A factory preset: the device it belongs to, its name, and the slot's full
|
||||
* settings as nullptr-terminated key/value text pairs. */
|
||||
struct FactoryPreset {
|
||||
const char *type;
|
||||
const char *name;
|
||||
const char *const *values;
|
||||
};
|
||||
|
||||
/** The device with ToolboxType name [type], or nullptr. */
|
||||
const DeviceSpec *findDevice(const char *type);
|
||||
|
||||
} // namespace sizzle
|
||||
@@ -0,0 +1,77 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "sizzle/Params.hpp"
|
||||
#include <cctype>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
namespace sizzle {
|
||||
|
||||
void Params::fill(const DeviceSpec &spec) {
|
||||
n_ = 0;
|
||||
for (int i = 0; i < spec.paramCount; ++i) {
|
||||
const ParamSpec &p = spec.params[i];
|
||||
if (p.isEnum()) {
|
||||
int idx = (int)p.def;
|
||||
int n = p.choiceCount();
|
||||
if (idx < 0) idx = 0;
|
||||
if (idx > n - 1) idx = n - 1;
|
||||
set(p.key, p.choices[idx]);
|
||||
} else {
|
||||
set(p.key, p.def);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int Params::find(const char *key) const {
|
||||
for (int i = 0; i < n_; ++i) if (std::strcmp(keys_[i], key) == 0) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Params::set(const char *key, const char *value) {
|
||||
int i = find(key);
|
||||
if (i < 0) {
|
||||
if (n_ >= kMax) return;
|
||||
i = n_++;
|
||||
std::snprintf(keys_[i], kKeyLen, "%s", key);
|
||||
}
|
||||
std::snprintf(vals_[i], kValLen, "%s", value);
|
||||
}
|
||||
|
||||
void Params::remove(const char *key) {
|
||||
const int i = find(key);
|
||||
if (i < 0) return;
|
||||
for (int k = i; k + 1 < n_; ++k) { // keep the insertion order of the rest
|
||||
std::memcpy(keys_[k], keys_[k + 1], kKeyLen);
|
||||
std::memcpy(vals_[k], vals_[k + 1], kValLen);
|
||||
}
|
||||
--n_;
|
||||
keys_[n_][0] = vals_[n_][0] = '\0';
|
||||
}
|
||||
|
||||
void Params::set(const char *key, float value) {
|
||||
// Shortest text that reads back as the same float (Kotlin stores toString()).
|
||||
char buf[kValLen];
|
||||
std::snprintf(buf, sizeof buf, "%.9g", (double)value);
|
||||
set(key, buf);
|
||||
}
|
||||
|
||||
float Params::f(const char *key, float fallback) const {
|
||||
int i = find(key);
|
||||
if (i < 0) return fallback;
|
||||
const char *s = vals_[i];
|
||||
while (std::isspace((unsigned char)*s)) ++s;
|
||||
if (!*s) return fallback;
|
||||
char *end = nullptr;
|
||||
float v = std::strtof(s, &end);
|
||||
while (end && std::isspace((unsigned char)*end)) ++end;
|
||||
return (end && *end == '\0') ? v : fallback;
|
||||
}
|
||||
|
||||
const char *Params::s(const char *key, const char *fallback) const {
|
||||
int i = find(key);
|
||||
return i < 0 ? fallback : vals_[i];
|
||||
}
|
||||
|
||||
} // namespace sizzle
|
||||
@@ -0,0 +1,14 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include <cstring>
|
||||
#include "sizzle/DeviceSpecs.gen.hpp"
|
||||
|
||||
namespace sizzle {
|
||||
|
||||
const DeviceSpec *findDevice(const char *type) {
|
||||
for (const auto &d : gen::devices) if (std::strcmp(d.type, type) == 0) return &d;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace sizzle
|
||||
@@ -0,0 +1,57 @@
|
||||
// SPDX-FileCopyrightText: 2026 Philip Bos (ECHOFIELD)
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown (port for Sizzle)
|
||||
// SPDX-License-Identifier: MIT
|
||||
#pragma once
|
||||
|
||||
// Port of EchofieldDefs.kt: the Grain Cloud's choice lists and factory presets.
|
||||
// The parameter specs themselves come from DeviceSpecs.gen.hpp (GRAIN_CLOUD).
|
||||
|
||||
namespace sizzle::echofield {
|
||||
|
||||
inline constexpr const char *MODES[] = {"Cloud", "Dust", "Tape", "Bloom", "Pulse", "Drift"};
|
||||
inline constexpr int MODE_COUNT = 6;
|
||||
inline constexpr const char *WINDOWS[] = {"Auto", "Hann", "Tukey", "Perc", "Swell", "Gauss"};
|
||||
inline constexpr int WINDOW_COUNT = 6;
|
||||
inline constexpr const char *CUSTOM = "Custom";
|
||||
|
||||
/** The built-in sources (synthesised, see GrainSources), then your own. */
|
||||
inline constexpr const char *SOURCES[] = {
|
||||
"Felt Piano", "Bowed Glass", "Music Box", "Warm Pad", "Strings",
|
||||
"Low Drone", "Rain Field", "Kalimba", "Breath Choir", "Glass Tines", "Custom",
|
||||
};
|
||||
inline constexpr int SOURCE_COUNT = 11;
|
||||
inline constexpr int BUILTIN_SOURCE_COUNT = 10;
|
||||
|
||||
/** Where a custom sample's id lives (the SF2/XI loader's key). */
|
||||
inline constexpr const char *SAMPLE_KEY = "sfSample";
|
||||
|
||||
/** A factory preset: every other setting at its default (ParamSpec), then these. */
|
||||
struct PresetValue { const char *key; float value; };
|
||||
struct Preset {
|
||||
const char *name;
|
||||
const char *source;
|
||||
int mode;
|
||||
PresetValue values[8];
|
||||
int count;
|
||||
};
|
||||
|
||||
/** ECHOFIELD's 14 factory presets (presets.c FACTORY), as in EchofieldDefs.FACTORY. */
|
||||
inline constexpr Preset FACTORY[] = {
|
||||
{"Felt Clouds", "Felt Piano", 0, {{"texture", 0.78f}, {"scatter", 0.50f}, {"drift", 0.35f}, {"motion", 0.30f}, {"harmony", 0.35f}}, 5},
|
||||
{"Glass Choir", "Bowed Glass", 3, {{"texture", 0.70f}, {"scatter", 0.40f}, {"drift", 0.30f}, {"motion", 0.35f}, {"harmony", 0.50f}}, 5},
|
||||
{"Dust Lights", "Music Box", 1, {{"texture", 0.45f}, {"scatter", 0.70f}, {"drift", 0.30f}, {"motion", 0.40f}, {"harmony", 0.30f}}, 5},
|
||||
{"Warm Tide", "Warm Pad", 5, {{"texture", 0.70f}, {"scatter", 0.45f}, {"drift", 0.55f}, {"motion", 0.40f}, {"harmony", 0.25f}}, 5},
|
||||
{"Slow Tapes", "Strings", 2, {{"texture", 0.60f}, {"scatter", 0.25f}, {"drift", 0.40f}, {"motion", 0.35f}, {"harmony", 0.15f}}, 5},
|
||||
{"Deep Water", "Low Drone", 0, {{"texture", 0.85f}, {"scatter", 0.40f}, {"drift", 0.40f}, {"motion", 0.25f}, {"harmony", 0.40f}}, 5},
|
||||
{"Rain Cathedral", "Rain Field", 0, {{"texture", 0.88f}, {"scatter", 0.60f}, {"drift", 0.40f}, {"motion", 0.30f}, {"harmony", 0.45f}}, 5},
|
||||
{"Kalimba Steps", "Kalimba", 4, {{"texture", 0.40f}, {"scatter", 0.60f}, {"drift", 0.30f}, {"motion", 0.30f}, {"harmony", 0.20f}}, 5},
|
||||
{"Hymn", "Breath Choir", 0, {{"texture", 0.85f}, {"scatter", 0.45f}, {"drift", 0.35f}, {"motion", 0.30f}, {"harmony", 0.40f}}, 5},
|
||||
{"Breath Choir", "Breath Choir", 3, {{"texture", 0.75f}, {"scatter", 0.50f}, {"drift", 0.40f}, {"motion", 0.40f}, {"harmony", 0.35f}}, 5},
|
||||
{"Night Current", "Low Drone", 5, {{"texture", 0.65f}, {"scatter", 0.40f}, {"drift", 0.60f}, {"motion", 0.40f}}, 4},
|
||||
{"Glass Rain", "Glass Tines", 1, {{"texture", 0.35f}, {"scatter", 0.55f}, {"drift", 0.20f}, {"motion", 0.50f}, {"pitch", 12.f}, {"reverse", 0.20f}, {"grain_tone", 0.40f}}, 7},
|
||||
{"Broken Stars", "Kalimba", 3, {{"texture", 0.60f}, {"scatter", 0.70f}, {"drift", 0.50f}, {"motion", 0.50f}}, 4},
|
||||
{"Far Broadcast", "Rain Field", 2, {{"texture", 0.50f}, {"scatter", 0.20f}, {"drift", 0.40f}, {"motion", 0.40f}}, 4},
|
||||
};
|
||||
inline constexpr int FACTORY_COUNT = 14;
|
||||
|
||||
} // namespace sizzle::echofield
|
||||
@@ -0,0 +1,620 @@
|
||||
// SPDX-FileCopyrightText: 2026 Philip Bos (ECHOFIELD)
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown (port for Sizzle)
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// Port of echofield/GrainCloud.kt, line for line with the same names and Float
|
||||
// precision. No FMA contraction: the grains draw random numbers against
|
||||
// thresholds, so a one-ulp difference would change which grains are born.
|
||||
|
||||
#pragma clang fp contract(off)
|
||||
|
||||
#include "GrainCloud.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include "EchofieldDefs.hpp"
|
||||
#include "GrainSources.hpp"
|
||||
#include "KotlinMath.hpp"
|
||||
|
||||
namespace sizzle::echofield {
|
||||
namespace {
|
||||
|
||||
using kt::coerceIn;
|
||||
using kt::expf_;
|
||||
using kt::powf_;
|
||||
using kt::sinf_;
|
||||
using kt::cosf_;
|
||||
using kt::sqrtf_;
|
||||
|
||||
constexpr int WIN_N = 256;
|
||||
constexpr float STEP_MAX = 4.f;
|
||||
constexpr float LOAD_MAX = 56.f;
|
||||
constexpr float AGC_TARGET = 0.126f;
|
||||
/** Brings the auto-levelled cloud to about the level of a Sizzle synth note. */
|
||||
constexpr float OUT_GAIN = 1.0f;
|
||||
constexpr float TWO_PI = 6.2831853f;
|
||||
constexpr float PI_F = 3.14159265f;
|
||||
|
||||
constexpr int WIN_HANN = 0, WIN_TUKEY = 1, WIN_PERC = 2, WIN_SWELL = 3, WIN_GAUSS = 4, WIN_COUNT = 5;
|
||||
|
||||
constexpr float HARMONY_IV[] = {12.f, 12.f, -12.f, 7.f, 19.f, 24.f, -5.f, 7.f};
|
||||
constexpr float TAPE_HR[] = {1.f, 0.5f, 2.f};
|
||||
constexpr float TAPE_HA[] = {1.f, 0.8f, 0.4f};
|
||||
constexpr float DUST_LEAP[] = {12.f, 19.f, 24.f, 7.f, -12.f};
|
||||
constexpr float BLOOM_PART[] = {0.f, 12.f, 7.f, -12.f};
|
||||
|
||||
inline float ffloor(float x) { return (float)std::floor((double)x); }
|
||||
inline float semis(float st) { return powf_(2.f, st / 12.f); }
|
||||
inline float lerp(float a, float b, float t) { return a + (b - a) * t; }
|
||||
inline float flush(float x) { return (x > -1e-20f && x < 1e-20f) ? 0.f : x; }
|
||||
inline bool isFinite(float x) { return std::isfinite(x); }
|
||||
|
||||
int euclid(int k, int n, int rot) {
|
||||
int pat = 0;
|
||||
if (k <= 0) return 0;
|
||||
for (int i = 0; i < n; ++i) if ((i * k) % n < k) pat = pat | (1 << ((i + rot) % n));
|
||||
return pat;
|
||||
}
|
||||
|
||||
int indexOfChoice(const char *const *list, int n, const char *s) {
|
||||
for (int i = 0; i < n; ++i) if (std::strcmp(list[i], s) == 0) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/** The grain windows (ef_window), 0..1 over WIN_N + 2 points. */
|
||||
struct WinTab {
|
||||
float t[WIN_COUNT][WIN_N + 2];
|
||||
WinTab() {
|
||||
for (int w = 0; w < WIN_COUNT; ++w)
|
||||
for (int i = 0; i < WIN_N + 2; ++i) t[w][i] = GrainCloud::window(w, (float)i / WIN_N);
|
||||
}
|
||||
};
|
||||
const WinTab &winTab() { static const WinTab tab; return tab; }
|
||||
|
||||
} // namespace
|
||||
|
||||
// ------------------------------------------------------------------- patch ---
|
||||
GrainPatch GrainPatch::from(const Params *slot, float tempoBpm) {
|
||||
GrainPatch g;
|
||||
float *p = g.p;
|
||||
auto f = [&](int i, const char *key, float def) { p[i] = slot ? slot->f(key, def) : def; };
|
||||
using C = GrainCloud;
|
||||
f(C::P_POSITION, "position", 0.35f); f(C::P_TEXTURE, "texture", 0.72f);
|
||||
f(C::P_SCATTER, "scatter", 0.45f); f(C::P_DRIFT, "drift", 0.35f);
|
||||
f(C::P_MOTION, "motion", 0.35f); f(C::P_PITCH, "pitch", 0.f);
|
||||
f(C::P_HARMONY, "harmony", 0.30f); f(C::P_SIZE_MUL, "size_mul", 0.f);
|
||||
f(C::P_DENS_MUL, "dens_mul", 0.f); f(C::P_SCAN, "scan", 0.f);
|
||||
f(C::P_REVERSE, "reverse", 0.10f); f(C::P_PITCH_RAND, "pitch_rand", 0.f);
|
||||
f(C::P_SIZE_RAND, "size_rand", 0.3f); f(C::P_GRAIN_TONE, "grain_tone", -0.1f);
|
||||
f(C::P_ATTACK, "attack", 0.15f); f(C::P_RELEASE, "release", 0.45f);
|
||||
f(C::P_VELO, "velo", 0.5f); f(C::P_START, "start", 0.f); f(C::P_END, "end", 1.f);
|
||||
f(C::P_LEVEL, "level", 0.75f);
|
||||
p[C::P_MODE] = (float)std::max(0, indexOfChoice(MODES, MODE_COUNT, slot ? slot->s("mode", "Cloud") : "Cloud"));
|
||||
p[C::P_WINDOW] = (float)std::max(0, indexOfChoice(WINDOWS, WINDOW_COUNT, slot ? slot->s("window", "Auto") : "Auto"));
|
||||
p[C::P_FREEZE] = (slot && std::strcmp(slot->s("freeze", "Off"), "On") == 0) ? 1.f : 0.f;
|
||||
const char *src = slot ? slot->s("source", SOURCES[0]) : SOURCES[0];
|
||||
if (std::strcmp(src, CUSTOM) == 0) g.source = SOURCE_CUSTOM;
|
||||
else { int i = GrainSources::indexOf(src); g.source = i >= 0 ? i : SOURCE_NONE; }
|
||||
const char *id = slot ? slot->s(SAMPLE_KEY, "") : "";
|
||||
std::strncpy(g.sampleId, id, ID_LEN - 1);
|
||||
g.sampleId[ID_LEN - 1] = 0;
|
||||
g.tempoBpm = tempoBpm;
|
||||
return g;
|
||||
}
|
||||
|
||||
uint32_t GrainSeeds::next() {
|
||||
seeds += 0x6D2B79F5u;
|
||||
return seeds == 0 ? 0x1234567u : seeds;
|
||||
}
|
||||
|
||||
uint32_t GrainSeeds::nth(int n) {
|
||||
GrainSeeds s;
|
||||
uint32_t v = 0;
|
||||
for (int i = 0; i < n; ++i) v = s.next();
|
||||
return v;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------- cloud ---
|
||||
GrainCloud::GrainCloud(int fs_, uint32_t seed)
|
||||
: fsf((float)fs_),
|
||||
smoothA(1.f - expf_((float)-SUB / (0.04f * (float)fs_))),
|
||||
playK(1.f - powf_(0.99f, 44100.f / (float)fs_)),
|
||||
rng(seed) {
|
||||
winTab();
|
||||
for (int i = 0; i < 16; ++i) stepPos[i] = rndf();
|
||||
}
|
||||
|
||||
bool GrainCloud::isActive() const {
|
||||
if (nNotes > 0 || env > 0.0005f || playGain > 0.0005f) return true;
|
||||
for (int k = 0; k < MAX_GRAINS; ++k) if (gOn[k]) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void GrainCloud::noteOn(int note, int velocity, int owner) {
|
||||
for (int k = 0; k < nNotes; ++k) if (noteNum[k] == note) { noteVel[k] = velocity; noteOwner[k] = owner; noteSeq++; return; }
|
||||
if (nNotes == MAX_NOTES) removeAt(0); // the oldest makes room
|
||||
noteNum[nNotes] = note; noteVel[nNotes] = velocity; noteOwner[nNotes] = owner;
|
||||
nNotes++;
|
||||
noteSeq++;
|
||||
}
|
||||
|
||||
void GrainCloud::noteOff(int note) {
|
||||
int k = 0;
|
||||
while (k < nNotes) if (noteNum[k] == note) removeAt(k); else k++;
|
||||
}
|
||||
|
||||
void GrainCloud::releaseOwner(int owner) {
|
||||
int k = 0;
|
||||
while (k < nNotes) if (noteOwner[k] == owner) removeAt(k); else k++;
|
||||
}
|
||||
|
||||
void GrainCloud::releaseSequenced() {
|
||||
int k = 0;
|
||||
while (k < nNotes) if (noteOwner[k] != OWNER_LIVE) removeAt(k); else k++;
|
||||
}
|
||||
|
||||
void GrainCloud::kill() {
|
||||
nNotes = 0; heldN = 0; env = 0.f; playGain = 0.f;
|
||||
std::fill(gOn, gOn + MAX_GRAINS, false); loadNow = 0.f; pos = SUB;
|
||||
}
|
||||
|
||||
void GrainCloud::removeAt(int k) {
|
||||
for (int i = k; i < nNotes - 1; ++i) { noteNum[i] = noteNum[i + 1]; noteVel[i] = noteVel[i + 1]; noteOwner[i] = noteOwner[i + 1]; }
|
||||
nNotes--;
|
||||
}
|
||||
|
||||
float GrainCloud::render() {
|
||||
if (pos >= SUB) { block(); pos = 0; }
|
||||
return bus[pos++];
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------- block ---
|
||||
void GrainCloud::block() {
|
||||
if (!hasPatch) { std::fill(bus, bus + SUB, 0.f); return; }
|
||||
const GrainPatch &pt = patch;
|
||||
float dt = SUB / fsf;
|
||||
for (int i = 0; i < P_COUNT; ++i) {
|
||||
float t = pt.p[i];
|
||||
sm[i] = (!smPrimed || i == P_MODE || i == P_WINDOW || i == P_FREEZE) ? t : sm[i] + (t - sm[i]) * smoothA;
|
||||
}
|
||||
smPrimed = true;
|
||||
|
||||
// a new source: fade out, swap, fade in
|
||||
const Sample *want = pt.source >= 0 ? GrainSources::get(pt.source)
|
||||
: pt.source == GrainPatch::SOURCE_CUSTOM && lookup ? lookup(lookupCtx, pt.sampleId) : nullptr;
|
||||
if (want && want->data.size() < 512) want = nullptr;
|
||||
if (want != src) {
|
||||
if (src == nullptr || fadeGain <= 0.f) {
|
||||
src = want;
|
||||
std::fill(gOn, gOn + MAX_GRAINS, false); loadNow = 0.f;
|
||||
tapeHead = 0.f;
|
||||
fadeGain = 0.f;
|
||||
} else {
|
||||
fadeGain = std::max(0.f, fadeGain - SUB / (0.02f * fsf));
|
||||
}
|
||||
} else if (fadeGain < 1.f) {
|
||||
fadeGain = std::min(1.f, fadeGain + SUB / (0.02f * fsf));
|
||||
}
|
||||
|
||||
// the gate: keys open it with their attack, release closes it
|
||||
float atk = 0.005f * powf_(800.f, sm[P_ATTACK]);
|
||||
float rel = 0.01f * powf_(800.f, sm[P_RELEASE]);
|
||||
float envTarget = nNotes > 0 ? 1.f : 0.f;
|
||||
env += (envTarget - env) * std::min(1.f, dt / (envTarget > env ? atk : rel));
|
||||
|
||||
computeCtl(dt);
|
||||
const Sample *s = src;
|
||||
if (cTape && s != nullptr && !frozen()) {
|
||||
float a = std::min(sm[P_START], sm[P_END]), b = std::max(sm[P_START], sm[P_END]);
|
||||
float rlen = std::max(512.f, (b - a) * (float)(int)s->data.size());
|
||||
tapeHead += cTapeSpeed * SUB * ((float)s->sampleRate / fsf) / rlen;
|
||||
tapeHead -= ffloor(tapeHead);
|
||||
}
|
||||
std::fill(bus, bus + SUB, 0.f);
|
||||
if (want == src) schedule();
|
||||
renderGrains();
|
||||
for (int i = 0; i < SUB; ++i) {
|
||||
playGain += (env - playGain) * playK;
|
||||
bus[i] *= playGain * fadeGain;
|
||||
}
|
||||
autoLevel();
|
||||
float level = sm[P_LEVEL] * OUT_GAIN;
|
||||
for (int i = 0; i < SUB; ++i) {
|
||||
float y = bus[i] * level;
|
||||
bus[i] = isFinite(y) ? y : 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
float GrainCloud::regionSeconds() const {
|
||||
const Sample *s = src;
|
||||
if (!s) return 1.f;
|
||||
float a = std::min(sm[P_START], sm[P_END]), b = std::max(sm[P_START], sm[P_END]);
|
||||
return (b - a) * (float)(int)s->data.size() / (float)s->sampleRate;
|
||||
}
|
||||
|
||||
void GrainCloud::computeCtl(float dt) {
|
||||
int mode = kt::toInt(sm[P_MODE]);
|
||||
float t = sm[P_TEXTURE], sc = sm[P_SCATTER], d = sm[P_DRIFT], m = sm[P_MOTION];
|
||||
float sizeMul = powf_(2.f, sm[P_SIZE_MUL]), densMul = powf_(2.f, sm[P_DENS_MUL]);
|
||||
if (!frozen()) {
|
||||
lfo1 += dt * (0.03f + 0.3f * m);
|
||||
if (lfo1 > 1.f) lfo1 -= 1.f;
|
||||
lfo2T += dt * (0.1f + 1.5f * m);
|
||||
if (lfo2T >= 1.f) { lfo2T -= 1.f; lfo2Tgt = rndb(); }
|
||||
lfo2Cur += (lfo2Tgt - lfo2Cur) * std::min(1.f, dt * (0.5f + 3.f * m));
|
||||
float wr = (mode == MODE_DRIFT ? 0.25f + 1.2f * m : 0.08f + 0.4f * m) * dt;
|
||||
{ float r = rndb(); walkV1 += r * wr * 2.f - walkV1 * wr * 2.f; }
|
||||
walkPos = coerceIn(walkPos + walkV1 * wr * 4.f - walkPos * wr * 0.3f, -1.f, 1.f);
|
||||
{ float r = rndb(); walkV2 += r * wr * 2.f - walkV2 * wr * 2.f; }
|
||||
walkPitch = coerceIn(walkPitch + walkV2 * wr * 4.f - walkPitch * wr * 0.3f, -1.f, 1.f);
|
||||
{ float r = rndb(); walkSize += (r - walkSize) * dt * 0.3f; }
|
||||
if (src != nullptr) {
|
||||
scan += sm[P_SCAN] * dt / std::max(0.05f, std::fabs(regionSeconds()));
|
||||
scan -= ffloor(scan);
|
||||
}
|
||||
}
|
||||
float lfo = sinf_(TWO_PI * lfo1);
|
||||
float pos0 = sm[P_POSITION];
|
||||
cJitter = 0.5f;
|
||||
cPitchRand = sm[P_PITCH_RAND] + 0.08f + d * 0.3f;
|
||||
cRevProb = sm[P_REVERSE];
|
||||
cAmp = 1.f;
|
||||
cTone = sm[P_GRAIN_TONE];
|
||||
cToneRand = 0.f;
|
||||
cWin = WIN_HANN;
|
||||
cClocked = false;
|
||||
cTape = false;
|
||||
cTapeSpeed = 1.f;
|
||||
float wander = d * 0.3f * walkPos;
|
||||
switch (mode) {
|
||||
case MODE_DUST:
|
||||
cSize = 0.02f * powf_(200.f / 20.f, t);
|
||||
cDensity = (6.f + 24.f * (1.f - t * 0.5f)) * (0.5f + sc);
|
||||
cJitter = 0.7f + 0.3f * sc;
|
||||
cCenter = pos0 + 0.1f * m * lfo + wander;
|
||||
cScatter = 0.1f + 0.85f * sc;
|
||||
cRevProb += 0.2f + 0.3f * sc;
|
||||
cWin = WIN_GAUSS;
|
||||
cAmp = 0.85f;
|
||||
cTone = coerceIn(sm[P_GRAIN_TONE] + 0.25f, -1.f, 1.f);
|
||||
cToneRand = 0.3f;
|
||||
break;
|
||||
case MODE_TAPE: {
|
||||
float target = semis(sm[P_PITCH]) * lerp(1.f, 0.3f, powf_(t, 1.2f));
|
||||
target *= 1.f + 0.03f * m * lfo2Cur + 0.02f * d * walkPitch;
|
||||
if (!frozen() && tapeStop <= 0.f && rndf() < m * 0.02f * dt) tapeStop = 1.6f;
|
||||
if (tapeStop > 0.f) {
|
||||
tapeStop -= dt;
|
||||
float ph = 1.6f - tapeStop;
|
||||
target *= ph < 0.8f ? 1.f - ph / 0.8f : (ph - 0.8f) / 0.8f;
|
||||
target = std::max(target, 0.02f);
|
||||
}
|
||||
tapeSpeed += (target - tapeSpeed) * std::min(1.f, dt * 6.f);
|
||||
cTape = true;
|
||||
cTapeSpeed = tapeSpeed;
|
||||
cSize = 0.18f * (1.f + t);
|
||||
cDensity = 4.f / cSize;
|
||||
cJitter = 0.15f;
|
||||
cCenter = tapeHead;
|
||||
cScatter = 0.002f + sc * 0.03f;
|
||||
cPitchRand = sm[P_PITCH_RAND];
|
||||
break;
|
||||
}
|
||||
case MODE_BLOOM:
|
||||
cSize = 0.6f * powf_(2.5f / 0.6f, t);
|
||||
cDensity = (3.f + 3.f * t) / cSize * (1.f + 0.5f * m * lfo2Cur);
|
||||
cJitter = 0.9f;
|
||||
cCenter = pos0 + 0.2f * m * lfo + wander;
|
||||
cScatter = 0.08f + 0.5f * sc;
|
||||
cRevProb += 0.25f;
|
||||
cTone = coerceIn(sm[P_GRAIN_TONE] + 0.15f, -1.f, 1.f);
|
||||
cToneRand = 0.25f;
|
||||
cWin = rndf() < 0.5f ? WIN_HANN : WIN_GAUSS;
|
||||
cAmp = 0.95f;
|
||||
break;
|
||||
case MODE_PULSE:
|
||||
cClocked = true;
|
||||
cSize = 0.06f * powf_(1200.f / 60.f, t);
|
||||
cDensity = 0.f;
|
||||
cCenter = pos0 + wander;
|
||||
cScatter = sc;
|
||||
cWin = t > 0.6f ? WIN_HANN : WIN_PERC;
|
||||
cJitter = 0.f;
|
||||
break;
|
||||
case MODE_DRIFT:
|
||||
cSize = 0.1f * powf_(12.f, t) * (1.f + 0.5f * walkSize);
|
||||
cDensity = (2.f + 4.f * t) * (1.f + 0.5f * lfo) / cSize;
|
||||
cJitter = 0.8f;
|
||||
cCenter = pos0 + walkPos * (0.1f + 0.5f * sc);
|
||||
cScatter = 0.03f + 0.3f * sc;
|
||||
cPitchRand = sm[P_PITCH_RAND] + d * 0.5f;
|
||||
cRevProb += 0.15f;
|
||||
cWin = WIN_GAUSS;
|
||||
break;
|
||||
default: // CLOUD
|
||||
cSize = 0.12f * powf_(1500.f / 120.f, t);
|
||||
cDensity = (4.f + 8.f * t) / cSize * (1.f + 0.4f * m * lfo2Cur);
|
||||
cJitter = 0.4f + 0.6f * sc;
|
||||
cCenter = pos0 + 0.15f * m * lfo + wander;
|
||||
cScatter = 0.03f + 0.6f * powf_(sc, 1.3f);
|
||||
cRevProb += sc * 0.1f;
|
||||
break;
|
||||
}
|
||||
cSize *= sizeMul;
|
||||
cDensity *= densMul;
|
||||
int wsel = kt::toInt(sm[P_WINDOW]);
|
||||
if (wsel > 0) cWin = wsel - 1;
|
||||
cRevProb = coerceIn(cRevProb, 0.f, 1.f);
|
||||
cSize = coerceIn(cSize, 0.004f, 2.5f);
|
||||
cDensity = coerceIn(cDensity, 0.f, 400.f);
|
||||
cScatter = coerceIn(cScatter, 0.f, 1.f);
|
||||
if (!cTape) { float cc = cCenter + scan; cCenter = cc - ffloor(cc); }
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ grains ---
|
||||
void GrainCloud::notesTrack() {
|
||||
if (nNotes == 0) return;
|
||||
for (int k = 0; k < nNotes; ++k) { heldNote[k] = noteNum[k] - 60; heldVel[k] = noteVel[k]; }
|
||||
heldN = nNotes;
|
||||
}
|
||||
|
||||
float GrainCloud::notePitch() {
|
||||
if (heldN == 0) return 0.f;
|
||||
int k = (int)((noteRr++ & 0x7FFFFFFFu) % (uint32_t)heldN);
|
||||
float velo = sm[P_VELO];
|
||||
ampScale *= (1.f - velo) + velo * (float)heldVel[k] / 127.f;
|
||||
return (float)heldNote[k];
|
||||
}
|
||||
|
||||
void GrainCloud::spawn(int offset, float amp0, float extraPitch, float posOverride) {
|
||||
const Sample *s = src;
|
||||
if (!s) return;
|
||||
int frames = (int)s->data.size();
|
||||
int g = -1;
|
||||
int active = 0;
|
||||
for (int i = 0; i < MAX_GRAINS; ++i) { if (gOn[i]) active++; else if (g < 0) g = i; }
|
||||
if (g < 0 || active >= MAX_GRAINS) return;
|
||||
float ra = std::min(sm[P_START], sm[P_END]), rb = std::max(sm[P_START], sm[P_END]);
|
||||
float rs = ra * (float)frames, re = rb * (float)frames;
|
||||
if (re - rs < 512.f) { re = std::min((float)frames - 1.f, rs + 512.f); rs = std::max(0.f, re - 512.f); }
|
||||
re = std::min(re, (float)frames - 2.f);
|
||||
float rlen = re - rs;
|
||||
if (rlen < 64.f) return;
|
||||
|
||||
float size = cSize * (1.f + rndb() * sm[P_SIZE_RAND] * 0.7f * (cTape ? 0.3f : 1.f));
|
||||
int len = kt::toInt(std::max(size, 0.003f) * fsf);
|
||||
ampScale = amp0;
|
||||
float pitch = sm[P_PITCH];
|
||||
pitch = pitch + notePitch();
|
||||
float harm = 0.f;
|
||||
if (rndf() < sm[P_HARMONY] * 0.65f) {
|
||||
harm = HARMONY_IV[nextRand() & 7u];
|
||||
ampScale *= 0.7f;
|
||||
}
|
||||
float step;
|
||||
if (cTape) {
|
||||
int head = tapeK;
|
||||
tapeK = (tapeK + 1) % 3;
|
||||
step = cTapeSpeed * TAPE_HR[head] * semis(harm + (pitch - sm[P_PITCH]));
|
||||
ampScale *= TAPE_HA[head];
|
||||
tapeGrainHead = head;
|
||||
} else {
|
||||
float st = pitch + harm + extraPitch;
|
||||
st = st + rndb() * cPitchRand;
|
||||
st = coerceIn(st + walkPitch * sm[P_DRIFT] * 2.f, -48.f, 36.f);
|
||||
step = semis(st);
|
||||
}
|
||||
step *= (float)s->sampleRate / fsf;
|
||||
step = coerceIn(step, 1.f / 64.f, STEP_MAX);
|
||||
if (loadNow + 1.f + step > LOAD_MAX) return;
|
||||
if (len < 64) len = 64;
|
||||
float span = (float)len * step;
|
||||
if (span > rlen * 0.98f) { len = kt::toInt(rlen * 0.98f / step); span = (float)len * step; }
|
||||
if (len < 32) return;
|
||||
bool rev = rndf() < cRevProb;
|
||||
float center = posOverride >= 0.f ? posOverride : cCenter + rndb() * cScatter * 0.5f;
|
||||
if (cTape) center = cCenter + (float)tapeGrainHead / 3.f + rndb() * cScatter;
|
||||
center -= ffloor(center);
|
||||
float cpos = rs + center * rlen;
|
||||
float start = !rev ? coerceIn(cpos - span * 0.5f, rs, re - span) : coerceIn(cpos + span * 0.5f, rs + span, re - 1.f);
|
||||
gPos[g] = (double)std::max(start, 0.f);
|
||||
gInc[g] = (double)step;
|
||||
gRev[g] = rev;
|
||||
gLen[g] = len;
|
||||
gAge[g] = 0;
|
||||
gDelay[g] = offset;
|
||||
gWin[g] = coerceIn(cWin, 0, WIN_COUNT - 1);
|
||||
gWph[g] = 0.f;
|
||||
gWstep[g] = (float)WIN_N / (float)len;
|
||||
gLoad[g] = 1.f + step;
|
||||
float overlap = std::max(1.f, cDensity * cSize);
|
||||
gAmp[g] = coerceIn(cAmp * ampScale * 0.75f / sqrtf_(overlap), 0.f, 1.9f);
|
||||
float tone = coerceIn(cTone + rndb() * cToneRand, -1.f, 1.f);
|
||||
if (std::fabs(tone) < 0.02f) gTone[g] = 0;
|
||||
else if (tone < 0.f) { gTone[g] = 1; gToneA[g] = onepole(std::min(18000.f * powf_(0.02f, -tone), std::min(20000.f, 0.45f * fsf))); }
|
||||
else { gTone[g] = 2; gToneA[g] = onepole(150.f * powf_(30.f, tone)); }
|
||||
gZ[g] = 0.f;
|
||||
gOn[g] = true;
|
||||
loadNow += gLoad[g];
|
||||
}
|
||||
|
||||
void GrainCloud::renderGrains() {
|
||||
const Sample *s = src;
|
||||
if (!s) { std::fill(gOn, gOn + MAX_GRAINS, false); loadNow = 0.f; return; }
|
||||
const float *data = s->data.data();
|
||||
int last = (int)s->data.size() - 1;
|
||||
float load = 0.f;
|
||||
const WinTab &tab = winTab();
|
||||
for (int k = 0; k < MAX_GRAINS; ++k) {
|
||||
if (!gOn[k]) continue;
|
||||
const float *w = tab.t[gWin[k]];
|
||||
int i = gDelay[k];
|
||||
gDelay[k] = 0;
|
||||
double p = gPos[k];
|
||||
double inc = gInc[k];
|
||||
bool rev = gRev[k];
|
||||
int tone = gTone[k];
|
||||
float ta = gToneA[k];
|
||||
float z = gZ[k];
|
||||
float wph = gWph[k];
|
||||
float wstep = gWstep[k];
|
||||
float amp = gAmp[k];
|
||||
int left = gLen[k] - gAge[k];
|
||||
if (left > SUB - i) left = SUB - i;
|
||||
gAge[k] += left;
|
||||
while (left > 0) {
|
||||
int idx = (int)p; // p stays within the sample, so Double.toInt's saturation never applies
|
||||
if (p < 0.0 || idx >= last) { gAge[k] = gLen[k]; break; }
|
||||
float fr = (float)(p - idx);
|
||||
float x = data[idx] + (data[idx + 1] - data[idx]) * fr;
|
||||
if (tone != 0) { z += (x - z) * ta; x = tone == 1 ? z : x - z; }
|
||||
int wi = std::min(kt::toInt(wph), WIN_N);
|
||||
float wv = w[wi] + (w[wi + 1] - w[wi]) * (wph - (float)wi);
|
||||
bus[i] += x * wv * amp;
|
||||
p = rev ? p - inc : p + inc;
|
||||
wph = std::min(wph + wstep, (float)WIN_N);
|
||||
i++; left--;
|
||||
}
|
||||
gPos[k] = p; gWph[k] = wph; gZ[k] = flush(z);
|
||||
if (gAge[k] >= gLen[k]) gOn[k] = false; else load += gLoad[k];
|
||||
}
|
||||
loadNow = load;
|
||||
}
|
||||
|
||||
void GrainCloud::schedule() {
|
||||
notesTrack();
|
||||
if (src == nullptr || (env <= 0.0005f && nNotes == 0)) return;
|
||||
if (noteSeq != noteSeqSeen) { // a new key: two grains at once, so the key answers
|
||||
noteSeqSeen = noteSeq;
|
||||
if (!cClocked && nNotes > 0) { spawn(0, 1.f, 0.f, -1.f); spawn(0, 0.8f, 0.f, -1.f); }
|
||||
}
|
||||
if (cClocked) {
|
||||
// PULSE: on the song's tempo, its 1/16, 1/8 or 1/4, whichever is nearest ECHOFIELD's own pace
|
||||
float own = 30.f + 90.f * sm[P_MOTION];
|
||||
float ext = hasPatch ? patch.tempoBpm : 0.f;
|
||||
float bpm = own;
|
||||
if (ext > 0.f) {
|
||||
float best = 1e9f;
|
||||
int dv = 1;
|
||||
while (dv <= 4) {
|
||||
float r = ext / (float)dv;
|
||||
float e = r > own ? r / own : own / r;
|
||||
if (e < best) { best = e; bpm = r; }
|
||||
dv = dv << 1;
|
||||
}
|
||||
}
|
||||
float stepSamples = fsf * 60.f / bpm / 4.f;
|
||||
int kk = kt::toInt(coerceIn(5.f + sm[P_DENS_MUL] * 2.5f + 0.5f, 1.f, 16.f));
|
||||
int pat = euclid(kk, 16, pulseRot);
|
||||
for (int i = 0; i < SUB; ++i) {
|
||||
pulseAcc -= 1.f;
|
||||
if (pulseAcc <= 0.f) {
|
||||
int st = pulseStep;
|
||||
pulseAcc += stepSamples * (1.f + ((pulseStep & 1) == 1 ? 0.08f : -0.08f) * sm[P_DRIFT]);
|
||||
pulseStep = (pulseStep + 1) & 15;
|
||||
if (st == 0 && !frozen() && rndf() < sm[P_MOTION] * 0.35f) {
|
||||
int j = kt::toInt(rndf() * 16.f) & 15;
|
||||
stepPos[j] = rndf();
|
||||
if (rndf() < sm[P_DRIFT] * 0.5f) stepOct[j] = rndf() < 0.5f ? 12 : 7;
|
||||
else stepOct[j] = 0;
|
||||
if (rndf() < sm[P_MOTION] * 0.3f) pulseRot = (pulseRot + 1) & 15;
|
||||
}
|
||||
if (((pat >> st) & 1) == 1) {
|
||||
float p = cCenter + (stepPos[st] - 0.5f) * cScatter;
|
||||
p -= ffloor(p);
|
||||
spawn(i, st % 4 == 0 ? 1.1f : 0.77f, (float)stepOct[st], p);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (cDensity <= 0.f) return;
|
||||
float mean = fsf / cDensity;
|
||||
int mode = kt::toInt(sm[P_MODE]);
|
||||
for (int i = 0; i < SUB; ++i) {
|
||||
spawnWait -= 1.f;
|
||||
if (spawnWait > 0.f) continue;
|
||||
spawnWait += mean * (1.f - cJitter + cJitter * 2.f * rndf());
|
||||
if (spawnWait < 1.f) spawnWait = 1.f;
|
||||
switch (mode) {
|
||||
case MODE_DUST: {
|
||||
if (stutterLeft > 0) { stutterLeft--; spawn(i, 1.f, 0.f, stutterPos); continue; }
|
||||
if (rndf() < sm[P_MOTION] * 0.05f) {
|
||||
stutterLeft = 2 + kt::toInt(rndf() * 4.f);
|
||||
float r = rndb();
|
||||
stutterPos = cCenter + r * cScatter * 0.5f;
|
||||
stutterPos -= ffloor(stutterPos);
|
||||
}
|
||||
float sp = rndf() < sm[P_SCATTER] * 0.35f ? DUST_LEAP[kt::toInt(rndf() * 5.f) % 5] : 0.f;
|
||||
spawn(i, 1.f, sp, -1.f);
|
||||
break;
|
||||
}
|
||||
case MODE_BLOOM: {
|
||||
float r = rndf();
|
||||
int k = r < 0.55f ? 0 : r < 0.75f ? 1 : r < 0.9f ? 2 : 3;
|
||||
float a = 0.5f + 0.5f * rndf();
|
||||
spawn(i, a, BLOOM_PART[k], -1.f);
|
||||
break;
|
||||
}
|
||||
default: spawn(i, 1.f, 0.f, -1.f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** ECHOFIELD's auto-level: the cloud held near one loudness whatever its density or
|
||||
* source; a tail that dies away is never pulled back up. */
|
||||
void GrainCloud::autoLevel() {
|
||||
float blk = SUB / fsf;
|
||||
float ms = 0.f;
|
||||
for (int i = 0; i < SUB; ++i) ms += bus[i] * bus[i];
|
||||
ms /= SUB;
|
||||
float g0 = agcGain;
|
||||
agcMs += (ms - agcMs) * (1.f - expf_(-blk / 2.5f));
|
||||
float target = agcGain;
|
||||
if (agcMs > 1e-6f) target = coerceIn(AGC_TARGET / sqrtf_(agcMs), 0.5f, 4.f);
|
||||
if (env <= 0.5f && target > agcGain) target = agcGain;
|
||||
float tc = target < agcGain ? 0.4f : 2.5f;
|
||||
agcGain += (target - agcGain) * (1.f - expf_(-blk / tc));
|
||||
for (int i = 0; i < SUB; ++i) bus[i] *= g0 + (agcGain - g0) * (float)i / SUB;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------- helpers ---
|
||||
float GrainCloud::onepole(float hz) const { return 1.f - expf_(-TWO_PI * hz / fsf); }
|
||||
|
||||
uint32_t GrainCloud::nextRand() {
|
||||
uint32_t x = rng;
|
||||
x = x ^ (x << 13); x = x ^ (x >> 17); x = x ^ (x << 5);
|
||||
rng = x;
|
||||
return x;
|
||||
}
|
||||
|
||||
float GrainCloud::rndf() { return (float)(int32_t)(nextRand() >> 8) * (1.f / 16777216.f); }
|
||||
|
||||
float GrainCloud::window(int w, float x0) {
|
||||
float x = coerceIn(x0, 0.f, 1.f);
|
||||
switch (w) {
|
||||
case WIN_TUKEY: {
|
||||
float a = 0.3f;
|
||||
if (x < a * 0.5f) return 0.5f - 0.5f * cosf_(TWO_PI * x / a);
|
||||
if (x > 1.f - a * 0.5f) return 0.5f - 0.5f * cosf_(TWO_PI * (1.f - x) / a);
|
||||
return 1.f;
|
||||
}
|
||||
case WIN_PERC: {
|
||||
float att = 0.03f;
|
||||
float v = x < att ? sinf_(0.5f * PI_F * x / att) : expf_(-5.f * (x - att) / (1.f - att));
|
||||
if (x > 0.92f) v *= 0.5f + 0.5f * cosf_(PI_F * (x - 0.92f) / 0.08f);
|
||||
return v;
|
||||
}
|
||||
case WIN_SWELL: return window(WIN_PERC, 1.f - x);
|
||||
case WIN_GAUSS: {
|
||||
float d = (x - 0.5f) / 0.16f;
|
||||
float g = expf_(-0.5f * d * d);
|
||||
float e = 0.00752f;
|
||||
return coerceIn((g - e) / (1.f - e), 0.f, 1.f);
|
||||
}
|
||||
default: return 0.5f - 0.5f * cosf_(TWO_PI * x);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sizzle::echofield
|
||||
@@ -0,0 +1,197 @@
|
||||
// SPDX-FileCopyrightText: 2026 Philip Bos (ECHOFIELD)
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown (port for Sizzle)
|
||||
// SPDX-License-Identifier: MIT
|
||||
#pragma once
|
||||
|
||||
// Port of echofield/GrainCloud.kt (ECHOFIELD's granular engine): one mixer
|
||||
// channel's grain cloud. See the Kotlin for the musical description.
|
||||
//
|
||||
// Differences from the Kotlin, all about ownership rather than sound:
|
||||
// - Kotlin seeds each GrainCloud from a global counter (companion `seeds`); here the
|
||||
// seed is passed in. GrainSeeds reproduces the counter for an owner (the engine)
|
||||
// that constructs clouds in the same order as AudioEngine.
|
||||
// - The patch is a fixed-size value (no strings on the heap); setPatch copies it.
|
||||
// - The custom source ("Custom", SampleStore.get(id) in Kotlin) goes through a
|
||||
// lookup hook (setSampleLookup), asked once per 64-frame block like the Kotlin.
|
||||
//
|
||||
// Allocation- and lock-free after construction.
|
||||
|
||||
#include <cstdint>
|
||||
#include "Sample.hpp"
|
||||
#include "sizzle/Params.hpp"
|
||||
|
||||
namespace sizzle::echofield {
|
||||
|
||||
/** A parsed Grain Cloud slot (GrainPatch.kt): the smoothed settings' targets, the
|
||||
* source to read and the song's tempo. Built off the hot path, per slot change. */
|
||||
struct GrainPatch {
|
||||
static constexpr int SOURCE_CUSTOM = -1; // the custom sample [sampleId]
|
||||
static constexpr int SOURCE_NONE = -2; // a name that is no built-in source
|
||||
static constexpr int ID_LEN = 64;
|
||||
|
||||
float p[23] = {};
|
||||
/** Index into GrainSources (EchofieldDefs SOURCES), or SOURCE_CUSTOM / SOURCE_NONE. */
|
||||
int source = 0;
|
||||
char sampleId[ID_LEN] = {};
|
||||
float tempoBpm = 120.f;
|
||||
|
||||
/** GrainPatch.from(slot, tempoBpm); [slot] may be null (all defaults). */
|
||||
static GrainPatch from(const Params *slot, float tempoBpm);
|
||||
};
|
||||
|
||||
/** The Kotlin companion's seed counter (GrainCloud.nextSeed), made explicit. */
|
||||
struct GrainSeeds {
|
||||
uint32_t seeds = 0x1234567;
|
||||
uint32_t next();
|
||||
/** The seed of the [n]-th cloud constructed (1-based) from a fresh counter. */
|
||||
static uint32_t nth(int n);
|
||||
};
|
||||
|
||||
class GrainCloud {
|
||||
public:
|
||||
static constexpr int P_POSITION = 0, P_TEXTURE = 1, P_SCATTER = 2, P_DRIFT = 3;
|
||||
static constexpr int P_MOTION = 4, P_PITCH = 5, P_HARMONY = 6, P_SIZE_MUL = 7;
|
||||
static constexpr int P_DENS_MUL = 8, P_SCAN = 9, P_REVERSE = 10, P_PITCH_RAND = 11;
|
||||
static constexpr int P_SIZE_RAND = 12, P_WINDOW = 13, P_GRAIN_TONE = 14, P_ATTACK = 15;
|
||||
static constexpr int P_RELEASE = 16, P_VELO = 17, P_START = 18, P_END = 19;
|
||||
static constexpr int P_MODE = 20, P_FREEZE = 21, P_LEVEL = 22;
|
||||
static constexpr int P_COUNT = 23;
|
||||
|
||||
/** A note from live input (keys, MIDI); OWNER_SEQ one the sequencer played with no track. */
|
||||
static constexpr int OWNER_LIVE = -1;
|
||||
static constexpr int OWNER_SEQ = -2;
|
||||
|
||||
static constexpr int SUB = 64;
|
||||
static constexpr int MAX_GRAINS = 32;
|
||||
static constexpr int MAX_NOTES = 8;
|
||||
|
||||
static constexpr int MODE_CLOUD = 0, MODE_DUST = 1, MODE_TAPE = 2;
|
||||
static constexpr int MODE_BLOOM = 3, MODE_PULSE = 4, MODE_DRIFT = 5;
|
||||
|
||||
/** Resolves a custom sample id to its data (the sample store), or nullptr. Called
|
||||
* on the audio thread once per block: must not block or allocate. */
|
||||
using SampleLookup = const Sample *(*)(void *ctx, const char *id);
|
||||
|
||||
/** [seed]: GrainSeeds::next() of the owner's counter (never 0). */
|
||||
GrainCloud(int fs, uint32_t seed);
|
||||
|
||||
void setPatch(const GrainPatch &p) { patch = p; hasPatch = true; }
|
||||
void setSampleLookup(SampleLookup fn, void *ctx) { lookup = fn; lookupCtx = ctx; }
|
||||
|
||||
void noteOn(int note, int velocity, int owner = OWNER_LIVE);
|
||||
void noteOff(int note);
|
||||
/** Let go of every note tracker track [owner] holds. */
|
||||
void releaseOwner(int owner);
|
||||
void releaseAll() { nNotes = 0; }
|
||||
/** Let go of the sequencer's notes (owner >= 0 or OWNER_SEQ), keeping live ones. */
|
||||
void releaseSequenced();
|
||||
/** Silence now: every grain off, no tail. */
|
||||
void kill();
|
||||
|
||||
float render();
|
||||
|
||||
/** Sounding: a note held, the gate's release still open, or a grain still playing. */
|
||||
bool isActive() const;
|
||||
|
||||
/** The grain window [w] (ef_window) at [x0] in 0..1. */
|
||||
static float window(int w, float x0);
|
||||
|
||||
private:
|
||||
static constexpr int WIN_N = 256;
|
||||
static constexpr int WIN_COUNT = 5;
|
||||
|
||||
void removeAt(int k);
|
||||
void block();
|
||||
bool frozen() const { return sm[P_FREEZE] >= 0.5f; }
|
||||
float regionSeconds() const;
|
||||
void computeCtl(float dt);
|
||||
void notesTrack();
|
||||
float notePitch();
|
||||
void spawn(int offset, float amp0, float extraPitch, float posOverride);
|
||||
void renderGrains();
|
||||
void schedule();
|
||||
void autoLevel();
|
||||
float onepole(float hz) const;
|
||||
uint32_t nextRand();
|
||||
float rndf();
|
||||
float rndb() { return rndf() * 2.f - 1.f; }
|
||||
|
||||
float fsf;
|
||||
GrainPatch patch;
|
||||
bool hasPatch = false;
|
||||
SampleLookup lookup = nullptr;
|
||||
void *lookupCtx = nullptr;
|
||||
float sm[P_COUNT] = {};
|
||||
bool smPrimed = false;
|
||||
float smoothA, playK;
|
||||
|
||||
// grains
|
||||
bool gOn[MAX_GRAINS] = {};
|
||||
int gWin[MAX_GRAINS] = {};
|
||||
bool gRev[MAX_GRAINS] = {};
|
||||
int gTone[MAX_GRAINS] = {};
|
||||
double gPos[MAX_GRAINS] = {};
|
||||
double gInc[MAX_GRAINS] = {};
|
||||
int gLen[MAX_GRAINS] = {};
|
||||
int gAge[MAX_GRAINS] = {};
|
||||
int gDelay[MAX_GRAINS] = {};
|
||||
float gWph[MAX_GRAINS] = {};
|
||||
float gWstep[MAX_GRAINS] = {};
|
||||
float gAmp[MAX_GRAINS] = {};
|
||||
float gToneA[MAX_GRAINS] = {};
|
||||
float gZ[MAX_GRAINS] = {};
|
||||
float gLoad[MAX_GRAINS] = {};
|
||||
float loadNow = 0.f;
|
||||
|
||||
// the source and its swap fade
|
||||
const Sample *src = nullptr;
|
||||
float fadeGain = 1.f;
|
||||
|
||||
// modes
|
||||
uint32_t rng; // xorshift state (Kotlin Int)
|
||||
float spawnWait = 0.f, scan = 0.f;
|
||||
float walkPos = 0.f, walkPitch = 0.f, walkV1 = 0.f, walkV2 = 0.f;
|
||||
float walkSize = 0.f;
|
||||
float lfo1 = 0.f, lfo2Cur = 0.f, lfo2Tgt = 0.f, lfo2T = 0.f;
|
||||
float tapeHead = 0.f, tapeSpeed = 1.f, tapeStop = 0.f;
|
||||
int tapeK = 0;
|
||||
int stutterLeft = 0;
|
||||
float stutterPos = 0.f;
|
||||
int pulseStep = 0, pulseRot = 0;
|
||||
float pulseAcc = 0.f;
|
||||
float stepPos[16];
|
||||
int stepOct[16] = {};
|
||||
float env = 0.f;
|
||||
float playGain = 0.f;
|
||||
float agcMs = 0.f;
|
||||
float agcGain = 1.f;
|
||||
|
||||
// notes held now (owner: the tracker track, or OWNER_LIVE)
|
||||
int noteNum[MAX_NOTES] = {};
|
||||
int noteVel[MAX_NOTES] = {};
|
||||
int noteOwner[MAX_NOTES] = {};
|
||||
int nNotes = 0;
|
||||
uint32_t noteSeq = 0, noteSeqSeen = 0; // Kotlin Int, wrapping
|
||||
// the notes grains are born on: those held, or while the release sounds, the last ones held
|
||||
int heldNote[MAX_NOTES] = {};
|
||||
int heldVel[MAX_NOTES] = {};
|
||||
int heldN = 0;
|
||||
uint32_t noteRr = 0;
|
||||
|
||||
// control values (ECHOFIELD's ctl_t), recomputed each sub-block
|
||||
float cSize = 0.f, cDensity = 0.f, cJitter = 0.f, cCenter = 0.f;
|
||||
float cScatter = 0.f, cPitchRand = 0.f, cRevProb = 0.f, cAmp = 1.f;
|
||||
float cTone = 0.f, cToneRand = 0.f;
|
||||
int cWin = 0;
|
||||
bool cClocked = false;
|
||||
bool cTape = false;
|
||||
float cTapeSpeed = 1.f;
|
||||
|
||||
float ampScale = 1.f;
|
||||
int tapeGrainHead = 0;
|
||||
|
||||
float bus[SUB] = {};
|
||||
int pos = SUB;
|
||||
};
|
||||
|
||||
} // namespace sizzle::echofield
|
||||
@@ -0,0 +1,323 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// Port of audio/GrainSources.kt, line for line, in the same (double) precision.
|
||||
|
||||
#pragma clang fp contract(off)
|
||||
|
||||
#include "GrainSources.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include "EchofieldDefs.hpp"
|
||||
|
||||
namespace sizzle::echofield::GrainSources {
|
||||
namespace {
|
||||
|
||||
constexpr double SECONDS = 6.0;
|
||||
const int N = (int)(RATE * SECONDS);
|
||||
|
||||
using Buf = std::vector<float>;
|
||||
|
||||
// ------------------------------------------------------------------ helpers ---
|
||||
constexpr double C4 = 261.6256;
|
||||
double hz(int semisFromC4) { return C4 * std::pow(2.0, semisFromC4 / 12.0); }
|
||||
constexpr double TAU = 2 * M_PI;
|
||||
|
||||
/** A struck note: partials (ratio, level, decay per second) from [t0] with a soft
|
||||
* [attack], each partial's decay scaled by its ratio for brighter-dies-first. */
|
||||
void strike(Buf &out, double t0, double f, const std::vector<std::vector<double>> &partials, double attack, double gain) {
|
||||
int start = (int)(t0 * RATE);
|
||||
for (const auto &p : partials) {
|
||||
double fr = f * p[0];
|
||||
if (fr > RATE * 0.45) continue;
|
||||
double w = TAU * fr / RATE;
|
||||
double ph = std::fmod(p[0] * 1.7, TAU);
|
||||
for (int i = start; i < N; ++i) {
|
||||
double t = (double)(i - start) / RATE;
|
||||
double env = (t < attack ? t / attack : 1.0) * std::exp(-p[2] * t);
|
||||
if (env < 1e-4 && t > attack) break;
|
||||
out[i] += (float)(gain * p[1] * env * std::sin(ph));
|
||||
ph += w;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** A band-limited saw by its harmonics, with a slow vibrato. */
|
||||
template <class Env>
|
||||
void saw(Buf &out, double f, double gain, double vibHz, double vibCents, double phase, Env ampEnv) {
|
||||
int maxK = std::min(std::max(1, (int)((RATE * 0.45) / f)), 40);
|
||||
std::vector<double> phs(maxK);
|
||||
for (int it = 0; it < maxK; ++it) phs[it] = phase * (it + 1);
|
||||
for (int i = 0; i < N; ++i) {
|
||||
double t = (double)i / RATE;
|
||||
double fm = f * std::pow(2.0, vibCents * std::sin(TAU * vibHz * t + phase) / 1200.0);
|
||||
double s = 0.0;
|
||||
for (int k = 1; k <= maxK; ++k) {
|
||||
phs[k - 1] += TAU * fm * k / RATE;
|
||||
s += std::sin(phs[k - 1]) / k;
|
||||
}
|
||||
out[i] += (float)(gain * ampEnv(t) * s);
|
||||
}
|
||||
}
|
||||
|
||||
/** Kotlin's Int xorshift (wrapping, `ushr` logical). */
|
||||
struct Rng {
|
||||
uint32_t s;
|
||||
explicit Rng(uint32_t seed) : s(seed) {}
|
||||
uint32_t next() { uint32_t x = s; x ^= x << 13; x ^= x >> 17; x ^= x << 5; s = x; return x; }
|
||||
double f() { return (int32_t)(next() >> 8) / 16777216.0; }
|
||||
double b() { return f() * 2 - 1; }
|
||||
};
|
||||
|
||||
/** A two-pole resonant band-pass (RBJ, constant peak gain) run over [x]. */
|
||||
Buf bandpass(const Buf &x, double f, double q) {
|
||||
double w = TAU * f / RATE;
|
||||
double alpha = std::sin(w) / (2 * q);
|
||||
double a0 = 1 + alpha;
|
||||
double b0 = alpha / a0, b2 = -alpha / a0;
|
||||
double a1 = -2 * std::cos(w) / a0, a2 = (1 - alpha) / a0;
|
||||
Buf y(x.size());
|
||||
double x1 = 0.0, x2 = 0.0, y1 = 0.0, y2 = 0.0;
|
||||
for (size_t i = 0; i < x.size(); ++i) {
|
||||
double v = b0 * x[i] + b2 * x2 - a1 * y1 - a2 * y2;
|
||||
x2 = x1; x1 = (double)x[i]; y2 = y1; y1 = v;
|
||||
y[i] = (float)v;
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
void lowpass(Buf &x, double f) {
|
||||
double a = 1 - std::exp(-TAU * f / RATE);
|
||||
double z = 0.0;
|
||||
for (size_t i = 0; i < x.size(); ++i) { z += a * (x[i] - z); x[i] = (float)z; }
|
||||
}
|
||||
|
||||
Buf normalize(Buf x) {
|
||||
float pk = 1e-9f;
|
||||
for (float v : x) pk = std::max(pk, std::fabs(v));
|
||||
float g = 0.89f / pk;
|
||||
int fade = RATE / 50;
|
||||
int size = (int)x.size();
|
||||
for (int i = 0; i < size; ++i) {
|
||||
float e = 1.f;
|
||||
if (i < fade) e = (float)i / fade;
|
||||
if (i > size - fade) e = (float)(size - i) / fade;
|
||||
x[i] *= g * e;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ recipes ---
|
||||
const int PENT[] = {0, 2, 4, 7, 9, 12, 14, 16, 19, 21, 24};
|
||||
|
||||
Buf feltPiano() {
|
||||
Buf out(N);
|
||||
std::vector<std::vector<double>> partials(8);
|
||||
for (int k = 0; k < 8; ++k)
|
||||
partials[k] = {k + 1.0 + 0.0008 * (k + 1) * (k + 1), 1.0 / std::pow((double)(k + 1), 1.6), 0.9 + 0.7 * k};
|
||||
const int melody[] = {0, 7, 4, 11, 2, 9, 7, 16, 12, 4, 14, 7};
|
||||
for (int n = 0; n < 12; ++n) strike(out, 0.05 + n * 0.48, hz(melody[n]), partials, 0.006, 0.6);
|
||||
lowpass(out, 3200.0);
|
||||
return out;
|
||||
}
|
||||
|
||||
Buf bowedGlass() {
|
||||
Buf out(N);
|
||||
const double ratios[] = {1.0, 2.32, 4.25, 6.63};
|
||||
const double levels[] = {1.0, 0.45, 0.22, 0.1};
|
||||
for (int k = 0; k < 4; ++k) {
|
||||
double f = hz(12) * ratios[k];
|
||||
double ph = k * 0.9;
|
||||
for (int i = 0; i < N; ++i) {
|
||||
double t = (double)i / RATE;
|
||||
double env = (1 - std::exp(-t / 1.2)) * (0.85 + 0.15 * std::sin(TAU * 0.23 * t + k));
|
||||
double vib = 1 + 0.0015 * std::sin(TAU * 4.6 * t);
|
||||
ph += TAU * f * vib / RATE;
|
||||
out[i] += (float)(levels[k] * env * std::sin(ph));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
Buf musicBox() {
|
||||
Buf out(N);
|
||||
std::vector<std::vector<double>> partials = {{1.0, 1.0, 1.4}, {3.01, 0.32, 3.5}, {5.4, 0.14, 6.0}, {8.9, 0.05, 9.0}};
|
||||
const int melody[] = {12, 16, 19, 24, 21, 19, 16, 14, 12, 19, 16, 24, 26, 24};
|
||||
for (int n = 0; n < 14; ++n) strike(out, 0.04 + n * 0.41, hz(melody[n]), partials, 0.002, 0.5);
|
||||
return out;
|
||||
}
|
||||
|
||||
Buf kalimba() {
|
||||
Buf out(N);
|
||||
std::vector<std::vector<double>> partials = {{1.0, 1.0, 1.1}, {5.93, 0.22, 7.0}, {13.4, 0.06, 14.0}};
|
||||
Rng rng(0x51A1);
|
||||
double t = 0.03;
|
||||
while (t < SECONDS - 0.8) {
|
||||
strike(out, t, hz(PENT[(int)(rng.f() * 8)]), partials, 0.003, 0.55);
|
||||
t += 0.28 + 0.3 * rng.f();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
Buf glassTines() {
|
||||
Buf out(N);
|
||||
std::vector<std::vector<double>> partials = {{1.0, 1.0, 0.8}, {2.756, 0.4, 1.6}, {5.404, 0.18, 2.8}, {8.93, 0.07, 4.0}};
|
||||
Rng rng(0x7123);
|
||||
double t = 0.02;
|
||||
while (t < SECONDS - 0.6) {
|
||||
strike(out, t, hz(12 + PENT[(int)(rng.f() * 9)]), partials, 0.002, 0.4);
|
||||
t += 0.17 + 0.25 * rng.f();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
Buf warmPad() {
|
||||
Buf out(N);
|
||||
const int chord[] = {-12, 0, 4, 7, 11, 14};
|
||||
for (int n = 0; n < 6; ++n) for (int d = 0; d < 2; ++d) {
|
||||
double det = d == 0 ? -6.0 : 6.0;
|
||||
saw(out, hz(chord[n]) * std::pow(2.0, det / 1200), 0.18, 0.2 + 0.05 * n, 4.0, n * 0.7 + d,
|
||||
[](double t) { return 1 - std::exp(-t / 0.8); });
|
||||
}
|
||||
// a slow opening low-pass: three passes at a cutoff that rises over the sound
|
||||
Buf a = out;
|
||||
double z1 = 0.0, z2 = 0.0;
|
||||
for (int i = 0; i < N; ++i) {
|
||||
double t = (double)i / RATE;
|
||||
double fc = 500 + 1800 * (0.5 - 0.5 * std::cos(TAU * t / SECONDS));
|
||||
double k = 1 - std::exp(-TAU * fc / RATE);
|
||||
z1 += k * (a[i] - z1); z2 += k * (z1 - z2);
|
||||
out[i] = (float)z2;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
Buf strings() {
|
||||
Buf out(N);
|
||||
const int voices[] = {-12, -5, 0, 4, 7};
|
||||
for (int n = 0; n < 5; ++n) for (int d = 0; d < 3; ++d) {
|
||||
double det = (d - 1) * 7.0;
|
||||
saw(out, hz(voices[n]) * std::pow(2.0, det / 1200), 0.14, 5.1 + 0.4 * d, 9.0, n * 1.3 + d * 0.5,
|
||||
[n](double t) { return (1 - std::exp(-t / 0.45)) * (0.8 + 0.2 * std::sin(TAU * 0.3 * t + n)); });
|
||||
}
|
||||
lowpass(out, 2600.0); lowpass(out, 5000.0);
|
||||
return out;
|
||||
}
|
||||
|
||||
Buf lowDrone() {
|
||||
Buf out(N);
|
||||
const double parts[][2] = {{hz(-24), 1.0}, {hz(-24) * 2.003, 0.5}, {hz(-17), 0.55},
|
||||
{hz(-17) * 2.0, 0.25}, {hz(-12) * 1.002, 0.3}, {hz(-24) * 3.0, 0.18}};
|
||||
for (int n = 0; n < 6; ++n) {
|
||||
const double *p = parts[n];
|
||||
double ph = n * 1.1;
|
||||
for (int i = 0; i < N; ++i) {
|
||||
double t = (double)i / RATE;
|
||||
ph += TAU * p[0] / RATE;
|
||||
double am = 0.75 + 0.25 * std::sin(TAU * (0.11 + 0.07 * n) * t + n);
|
||||
out[i] += (float)(p[1] * am * (std::sin(ph) + 0.15 * std::sin(2 * ph)));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
Buf breathChoir() {
|
||||
Rng rng(0x0B2E);
|
||||
Buf noise(N);
|
||||
for (int i = 0; i < N; ++i) noise[i] = (float)rng.b();
|
||||
// a voiced source under the breath: a soft buzz at C4 and its fifth
|
||||
Buf buzz(N);
|
||||
saw(buzz, hz(0), 0.25, 5.0, 8.0, 0.0, [](double t) { return 1 - std::exp(-t / 0.6); });
|
||||
saw(buzz, hz(7), 0.18, 4.6, 8.0, 1.0, [](double t) { return 1 - std::exp(-t / 0.9); });
|
||||
Buf src(N);
|
||||
for (int i = 0; i < N; ++i) src[i] = noise[i] * 0.6f + buzz[i];
|
||||
// "ah" formants drifting toward "oh"
|
||||
Buf f1 = bandpass(src, 750.0, 6.0), f2 = bandpass(src, 1150.0, 8.0), f3 = bandpass(src, 2600.0, 10.0);
|
||||
Buf g1 = bandpass(src, 500.0, 6.0), g2 = bandpass(src, 900.0, 8.0);
|
||||
Buf out(N);
|
||||
for (int i = 0; i < N; ++i) {
|
||||
double t = (double)i / RATE;
|
||||
double m = 0.5 - 0.5 * std::cos(TAU * t / SECONDS);
|
||||
double swell = (1 - std::exp(-t / 0.7)) * (0.7 + 0.3 * std::sin(TAU * 0.4 * t));
|
||||
out[i] = (float)(swell * ((1 - m) * (f1[i] + 0.7 * f2[i]) + m * (g1[i] + 0.6 * g2[i]) + 0.3 * f3[i]));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
Buf rainField() {
|
||||
Buf out(N);
|
||||
Rng rng(0x2A1F);
|
||||
// the bed: soft filtered noise
|
||||
double z = 0.0, z2 = 0.0;
|
||||
for (int i = 0; i < N; ++i) {
|
||||
z += 0.08 * (rng.b() - z); z2 += 0.3 * (z - z2);
|
||||
out[i] = (float)(0.5 * (z - 0.6 * z2));
|
||||
}
|
||||
// drops: short pitched blips at random
|
||||
double t = 0.0;
|
||||
while (t < SECONDS - 0.1) {
|
||||
double f = 900 + 3200 * rng.f();
|
||||
int start = (int)(t * RATE);
|
||||
double a = 0.15 + 0.35 * rng.f();
|
||||
double ph = 0.0;
|
||||
int end = std::min(N, start + RATE / 10);
|
||||
for (int i = start; i < end; ++i) {
|
||||
double tt = (double)(i - start) / RATE;
|
||||
ph += TAU * f * (1 + 0.6 * std::exp(-tt * 60)) / RATE;
|
||||
out[i] += (float)(a * std::exp(-tt * 55) * std::sin(ph));
|
||||
}
|
||||
t += 0.01 + 0.08 * std::pow(rng.f(), 2.0);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
using Recipe = Buf (*)();
|
||||
// Same order as EchofieldDefs SOURCES.
|
||||
const Recipe RECIPES[COUNT] = {
|
||||
feltPiano, bowedGlass, musicBox, warmPad, strings,
|
||||
lowDrone, rainField, kalimba, breathChoir, glassTines,
|
||||
};
|
||||
|
||||
Sample cache[COUNT];
|
||||
std::atomic<bool> ready[COUNT];
|
||||
std::mutex buildLock; // builders only (never the audio thread)
|
||||
std::atomic<bool> started{false};
|
||||
|
||||
} // namespace
|
||||
|
||||
int indexOf(const char *name) {
|
||||
if (!name) return -1;
|
||||
for (int i = 0; i < COUNT; ++i) if (std::strcmp(SOURCES[i], name) == 0) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
const Sample *get(int index) {
|
||||
if (index < 0 || index >= COUNT) return nullptr;
|
||||
return ready[index].load(std::memory_order_acquire) ? &cache[index] : nullptr;
|
||||
}
|
||||
|
||||
const Sample *get(const char *name) { return get(indexOf(name)); }
|
||||
|
||||
void prewarmBlocking() {
|
||||
std::lock_guard<std::mutex> g(buildLock);
|
||||
for (int i = 0; i < COUNT; ++i) {
|
||||
if (ready[i].load(std::memory_order_acquire)) continue;
|
||||
cache[i].data = normalize(RECIPES[i]());
|
||||
cache[i].sampleRate = RATE;
|
||||
ready[i].store(true, std::memory_order_release);
|
||||
}
|
||||
}
|
||||
|
||||
void prewarm() {
|
||||
if (started.exchange(true)) return;
|
||||
std::thread([] { prewarmBlocking(); }).detach();
|
||||
}
|
||||
|
||||
} // namespace sizzle::echofield::GrainSources
|
||||
@@ -0,0 +1,30 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
|
||||
// Port of audio/GrainSources.kt: the Grain Cloud's ten built-in sources,
|
||||
// synthesised in code (about six seconds each at RATE, mono, pitched on C).
|
||||
// Generated off the audio thread: prewarm() renders them on a background thread
|
||||
// (once), prewarmBlocking() renders them on the calling thread (tests). get()
|
||||
// never blocks and returns nullptr until a source is ready.
|
||||
|
||||
#include "Sample.hpp"
|
||||
|
||||
namespace sizzle::echofield::GrainSources {
|
||||
|
||||
constexpr int RATE = 24000;
|
||||
constexpr int COUNT = 10;
|
||||
|
||||
/** The source named [name] (EchofieldDefs SOURCES[0..9]) once rendered, else nullptr. */
|
||||
const Sample *get(const char *name);
|
||||
/** By index into the built-in list, or nullptr (not ready / out of range). */
|
||||
const Sample *get(int index);
|
||||
/** Index of the built-in source [name], or -1. */
|
||||
int indexOf(const char *name);
|
||||
|
||||
/** Render every source on a detached background thread (once). */
|
||||
void prewarm();
|
||||
/** Render every source not yet rendered, now, on this thread. */
|
||||
void prewarmBlocking();
|
||||
|
||||
} // namespace sizzle::echofield::GrainSources
|
||||
@@ -0,0 +1,11 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
|
||||
// The Grain Cloud's name for the shared sample type (sizzle/Sample.hpp).
|
||||
|
||||
#include "sizzle/Sample.hpp"
|
||||
|
||||
namespace sizzle::echofield {
|
||||
using Sample = sizzle::Sample;
|
||||
} // namespace sizzle::echofield
|
||||
@@ -0,0 +1,111 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
|
||||
// AudioEngine.ChannelArp: per-(lane,track) arpeggiator. Notes are kept sorted
|
||||
// ascending; the linear step sequence is octave-major (all chord notes in octave 0,
|
||||
// then octave 1, ...), walked up / down / up-down / randomly by advance(). genStamp
|
||||
// identifies the line whose chord this holds (the engine's lineTriggerGen).
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
namespace sizzle::engine {
|
||||
|
||||
class ChannelArp {
|
||||
public:
|
||||
int velocity = 100;
|
||||
double stepSamples = 0.0, samplesLeft = 0.0;
|
||||
bool resetOnBar = false;
|
||||
int genStamp = -1;
|
||||
|
||||
/** Active while it holds at least one note. */
|
||||
bool active() const { return noteCount_ > 0; }
|
||||
|
||||
/** Start a fresh chord on [note], resetting the phase to step 0. */
|
||||
void startChord(int note, int vel, int octs, const char *modeStr, double stepSamp, bool resetBar) {
|
||||
noteCount_ = 0; addNote(note); velocity = vel; octaves = clamp(octs, 1, 4);
|
||||
mode = modeOf(modeStr);
|
||||
stepSamples = stepSamp < 1.0 ? 1.0 : stepSamp; samplesLeft = stepSamples; step = 0; dir = 1;
|
||||
resetOnBar = resetBar; pendingReset = false;
|
||||
}
|
||||
|
||||
/** Replace the chord with [note] while keeping the running phase. */
|
||||
void resetChord(int note, int vel, int octs, const char *modeStr, double stepSamp, bool resetBar) {
|
||||
noteCount_ = 0; addNote(note); velocity = vel;
|
||||
refresh(octs, modeStr, stepSamp, resetBar);
|
||||
}
|
||||
|
||||
/** Add a note to the held chord (sorted ascending, de-duplicated). */
|
||||
void addNote(int note) {
|
||||
const int n = clamp(note, 0, 127);
|
||||
int i = 0;
|
||||
while (i < noteCount_ && notes[i] < n) i++;
|
||||
if (i < noteCount_ && notes[i] == n) return;
|
||||
if (noteCount_ >= MAX_CHORD) return;
|
||||
for (int j = noteCount_; j >= i + 1; --j) notes[j] = notes[j - 1];
|
||||
notes[i] = n; noteCount_++;
|
||||
}
|
||||
|
||||
/** Update params without resetting the running phase. */
|
||||
void refresh(int octs, const char *modeStr, double stepSamp, bool resetBar) {
|
||||
octaves = clamp(octs, 1, 4);
|
||||
mode = modeOf(modeStr);
|
||||
stepSamples = stepSamp < 1.0 ? 1.0 : stepSamp;
|
||||
resetOnBar = resetBar;
|
||||
}
|
||||
|
||||
void resetToBar() { step = 0; dir = 1; samplesLeft = 0.0; pendingReset = true; }
|
||||
bool consumePendingReset() { bool p = pendingReset; pendingReset = false; return p; }
|
||||
|
||||
void stop() { noteCount_ = 0; genStamp = -1; }
|
||||
|
||||
int currentNote() const {
|
||||
if (noteCount_ <= 0) return 0;
|
||||
const int idx = clamp(step, 0, total() - 1);
|
||||
const int oct = idx / noteCount_;
|
||||
return clamp(notes[idx % noteCount_] + 12 * oct, 0, 127);
|
||||
}
|
||||
|
||||
void advance() {
|
||||
const int t = total();
|
||||
switch (mode) {
|
||||
case 1: step = (step - 1 + t) % t; break;
|
||||
case 2:
|
||||
if (t > 1) {
|
||||
step += dir;
|
||||
if (step >= t - 1) { step = t - 1; dir = -1; }
|
||||
else if (step <= 0) { step = 0; dir = 1; }
|
||||
}
|
||||
break;
|
||||
case 3: step = t > 1 ? rnd(t) : 0; break;
|
||||
default: step = (step + 1) % t; break;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr int MAX_CHORD = 8;
|
||||
static int clamp(int v, int lo, int hi) { return v < lo ? lo : (v > hi ? hi : v); }
|
||||
static int modeOf(const char *m) {
|
||||
if (std::strcmp(m, "Down") == 0) return 1;
|
||||
if (std::strcmp(m, "UpDown") == 0) return 2;
|
||||
if (std::strcmp(m, "Random") == 0) return 3;
|
||||
return 0;
|
||||
}
|
||||
int total() const { int t = noteCount_ * octaves; return t < 1 ? 1 : t; }
|
||||
int rnd(int bound) {
|
||||
uint32_t s = rng;
|
||||
s ^= s << 13; s ^= s >> 17; s ^= s << 5;
|
||||
rng = s;
|
||||
return (int)(s % (uint32_t)bound);
|
||||
}
|
||||
|
||||
int notes[MAX_CHORD] = {};
|
||||
int noteCount_ = 0;
|
||||
int octaves = 1, mode = 0;
|
||||
int step = 0, dir = 1;
|
||||
bool pendingReset = false;
|
||||
uint32_t rng = 0x2545F491u;
|
||||
};
|
||||
|
||||
} // namespace sizzle::engine
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,159 @@
|
||||
// SPDX-FileCopyrightText: 2026 Styves Goupil (FRASIL)
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown (Kotlin port for Sizzle, C++ port)
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
||||
// If a copy of the MPL was not distributed with this file, You can obtain one at
|
||||
// https://mozilla.org/MPL/2.0/ (also in LICENSES/MPL-2.0.txt of this repository).
|
||||
//
|
||||
// Port of FrasilDefs.kt (engineFrom, the 36 drone presets) and FrasilPatch.from.
|
||||
|
||||
#include <cstring>
|
||||
#include "frasil/FrasilVoice.hpp"
|
||||
#include "sizzle/Params.hpp"
|
||||
#include "KotlinMath.hpp"
|
||||
|
||||
namespace sizzle::frasil {
|
||||
namespace {
|
||||
|
||||
using namespace defs;
|
||||
|
||||
const char *const INTERVALS[] = {"Unison", "-12", "+7", "+12"};
|
||||
constexpr float INTERVAL_RATIO[] = {1.f, 0.5f, 1.4983071f, 2.f};
|
||||
const char *const FILTER_TYPES[] = {"Low", "Band", "High"};
|
||||
const char *const BREATH_PITCHES[] = {"-12", "Unison", "+12", "+19", "+24"};
|
||||
constexpr float BREATH_RATIO[] = {0.5f, 1.f, 2.f, 2.9966142f, 4.f};
|
||||
|
||||
template <int K> int indexOf(const char *const (&list)[K], const char *s) {
|
||||
for (int i = 0; i < K; ++i) if (!std::strcmp(list[i], s)) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
float r(int v) { return (float)v / 127.f; }
|
||||
|
||||
/** engineFrom: [num](key, def) reads a slider, [choice](key, def) a choice. */
|
||||
template <class Num, class Choice> int engineFrom(float *e, Num num, Choice choice) {
|
||||
auto u = [&](const char *key, float def) { return kt::coerceIn(num(key, def), 0.f, 1.f); };
|
||||
e[CHOIR] = u("choir", r(76)); e[PARTIALS] = u("partials", r(89)); e[BREATH] = u("breath", r(32));
|
||||
e[WARMTH] = u("warmth", r(19)); e[DETUNE] = u("detune", r(51)); e[CUTOFF] = u("cfilter", r(44));
|
||||
e[TILT] = u("tilt", r(57)); e[ODD] = u("odd", r(25)); e[STRETCH] = u("stretch", 0.f);
|
||||
e[RESONANCE] = u("bres", r(70)); e[COLOR] = u("color", 0.f);
|
||||
e[ATTACK] = u("attack", r(89)); e[RELEASE] = u("release", r(83));
|
||||
e[MOTION] = u("motion", r(44)); e[MOTION_RATE] = u("mrate", r(51));
|
||||
e[TIDE] = u("tide", r(25)); e[TIDE_RATE] = u("tperiod", r(38)); e[TIMBRE] = u("timbre", r(64));
|
||||
e[SHAPE] = u("shape", 0.f); e[CH_RESO] = u("creso", 0.f);
|
||||
e[EVOLVE] = u("evolve", 0.f); e[BEAT] = u("beat", 0.f);
|
||||
e[FORMANT] = 3.f * u("formant", r(85)); e[PEAK] = u("peak", 0.f);
|
||||
e[GRAIN] = u("grain", 0.f);
|
||||
float tn = u("btone", r(64)) * 127.f;
|
||||
e[TONE] = tn >= 126.5f ? 1.f : (tn - 64.f) / 63.f;
|
||||
e[AIR] = u("air", 0.f); e[SOFT] = u("soft", 0.f);
|
||||
e[VELOCITY] = u("velsens", r(38)); e[BODY] = u("body", 1.f);
|
||||
e[INTERVAL] = INTERVAL_RATIO[kt::coerceAtLeast(indexOf(INTERVALS, choice("interval", INTERVALS[0])), 0)];
|
||||
int bp = indexOf(BREATH_PITCHES, choice("bpitch", BREATH_PITCHES[1]));
|
||||
e[BR_PITCH] = BREATH_RATIO[bp < 0 ? 1 : bp];
|
||||
return kt::coerceAtLeast(indexOf(FILTER_TYPES, choice("ctype", FILTER_TYPES[0])), 0);
|
||||
}
|
||||
|
||||
// CHO PAR SOU WAR DET FIL TIL ODD STR BRES COL SPR ATT REL MOT RAT TID PER TIM SPA SHP INT CRES TYP EVO BEAT
|
||||
// FORM PEAK GRN PIT TONE AIR SOFT. SPREAD and SPACE (null) are FRASIL's stereo field and reverb.
|
||||
constexpr int NCOL = 33;
|
||||
const char *const COLS[NCOL] = {
|
||||
"choir", "partials", "breath", "warmth", "detune", "cfilter", "tilt", "odd", "stretch", "bres", "color",
|
||||
nullptr, "attack", "release", "motion", "mrate", "tide", "tperiod", "timbre", nullptr, "shape", "interval",
|
||||
"creso", "ctype", "evolve", "beat", "formant", "peak", "grain", "bpitch", "btone", "air", "soft",
|
||||
};
|
||||
|
||||
struct Raw { const char *name; int row[NCOL]; };
|
||||
|
||||
const Raw RAW[] = {
|
||||
{"Mist", {76, 89, 32, 19, 51, 44, 57, 25, 0, 70, 0, 89, 89, 83, 44, 51, 25, 38, 64, 57, 0, 0, 0, 0, 0, 0, 85, 0, 0, 1, 64, 0, 0}},
|
||||
{"Cathedral", {110, 50, 20, 25, 85, 55, 60, 30, 0, 60, 0, 110, 100, 100, 60, 40, 20, 50, 60, 95, 0, 1, 20, 0, 10, 0, 85, 0, 0, 1, 64, 0, 0}},
|
||||
{"Glacier", {20, 100, 70, 5, 30, 60, 35, 50, 60, 115, 127, 100, 80, 110, 40, 30, 30, 40, 80, 90, 0, 0, 0, 0, 40, 15, 100, 30, 20, 2, 80, 0, 0}},
|
||||
{"Abyss", {90, 70, 25, 50, 70, 20, 90, 40, 0, 50, 0, 70, 100, 105, 50, 25, 50, 25, 40, 70, 30, 1, 40, 0, 20, 0, 60, 0, 0, 0, 30, 0, 0}},
|
||||
{"Aurora", {60, 105, 40, 15, 45, 65, 40, 15, 10, 85, 60, 115, 90, 105, 55, 45, 45, 50, 75, 95, 0, 0, 0, 0, 70, 25, 90, 35, 0, 2, 75, 10, 0}},
|
||||
{"Ember", {100, 55, 20, 80, 40, 40, 70, 60, 0, 50, 30, 80, 70, 80, 35, 40, 20, 40, 55, 50, 64, 0, 50, 0, 10, 0, 70, 0, 0, 1, 50, 0, 0}},
|
||||
{"Tide", {80, 80, 45, 25, 60, 45, 55, 30, 10, 75, 40, 100, 95, 100, 70, 30, 110, 60, 60, 70, 0, 0, 30, 0, 30, 0, 85, 0, 0, 1, 64, 0, 0}},
|
||||
{"Dust", {25, 40, 85, 20, 40, 50, 60, 30, 20, 100, 60, 120, 60, 90, 50, 50, 30, 40, 60, 75, 0, 0, 0, 0, 30, 0, 85, 0, 90, 2, 85, 40, 0}},
|
||||
{"Wind", {0, 20, 85, 0, 40, 50, 60, 30, 0, 20, 30, 127, 80, 95, 90, 80, 50, 70, 64, 80, 0, 0, 0, 0, 0, 0, 85, 0, 0, 1, 75, 50, 0}},
|
||||
{"Organ", {40, 115, 10, 30, 10, 50, 45, 0, 0, 60, 0, 60, 40, 60, 15, 40, 10, 40, 64, 50, 0, 2, 0, 0, 0, 0, 85, 0, 0, 1, 64, 0, 0}},
|
||||
{"Hollow", {105, 80, 25, 20, 35, 50, 50, 110, 0, 70, 64, 90, 80, 90, 40, 45, 25, 40, 60, 65, 64, 0, 40, 1, 15, 0, 85, 0, 0, 1, 60, 0, 0}},
|
||||
{"Vowel", {65, 125, 15, 10, 30, 55, 30, 20, 0, 70, 0, 85, 90, 95, 45, 35, 60, 45, 64, 70, 0, 0, 60, 1, 20, 0, 95, 105, 0, 1, 64, 0, 0}},
|
||||
{"Shimmer", {45, 100, 50, 10, 55, 75, 25, 20, 15, 100, 90, 120, 85, 110, 50, 55, 30, 40, 85, 100, 0, 3, 0, 0, 40, 50, 100, 20, 10, 3, 90, 20, 0}},
|
||||
{"Chanter", {105, 45, 15, 40, 30, 55, 60, 70, 0, 60, 30, 70, 50, 70, 30, 45, 15, 40, 60, 45, 110, 0, 35, 1, 0, 0, 85, 0, 0, 1, 64, 0, 0}},
|
||||
{"Ensemble", {115, 40, 20, 30, 75, 60, 55, 25, 0, 60, 0, 115, 95, 90, 55, 55, 20, 40, 65, 75, 90, 0, 15, 0, 0, 0, 85, 0, 0, 1, 64, 0, 0}},
|
||||
{"Bells", {15, 115, 45, 5, 25, 50, 30, 20, 95, 110, 127, 95, 40, 110, 30, 40, 20, 40, 75, 85, 0, 0, 0, 0, 30, 30, 85, 0, 0, 2, 80, 0, 0}},
|
||||
{"Nocturne", {90, 60, 30, 35, 55, 25, 85, 30, 0, 55, 0, 90, 110, 115, 45, 20, 40, 20, 45, 85, 20, 1, 70, 0, 25, 0, 70, 0, 0, 0, 35, 0, 0}},
|
||||
{"Haze", {85, 50, 60, 10, 60, 70, 50, 25, 0, 40, 30, 120, 100, 105, 60, 50, 30, 50, 70, 90, 0, 3, 20, 2, 20, 0, 85, 0, 0, 2, 80, 30, 0}},
|
||||
{"Pulse", {50, 95, 25, 20, 30, 50, 45, 30, 0, 70, 20, 100, 60, 80, 30, 50, 20, 40, 64, 65, 0, 0, 0, 0, 15, 100, 85, 0, 0, 1, 64, 0, 0}},
|
||||
{"Rime", {30, 110, 70, 0, 20, 80, 20, 40, 30, 120, 100, 110, 70, 100, 35, 60, 20, 40, 90, 90, 0, 3, 0, 2, 30, 20, 110, 40, 40, 4, 100, 15, 0}},
|
||||
{"Deep", {100, 100, 0, 40, 25, 25, 100, 20, 0, 50, 0, 60, 90, 95, 25, 30, 20, 30, 40, 45, 0, 1, 10, 0, 0, 0, 40, 0, 0, 0, 30, 0, 0}},
|
||||
{"Spectral", {20, 120, 15, 5, 20, 50, 20, 10, 0, 70, 0, 90, 90, 100, 50, 40, 80, 50, 64, 80, 0, 0, 0, 0, 50, 10, 85, 127, 0, 1, 64, 0, 0}},
|
||||
{"Rust", {80, 50, 40, 100, 50, 45, 65, 60, 20, 80, 40, 80, 60, 80, 40, 55, 25, 40, 55, 55, 70, 0, 80, 1, 20, 15, 75, 0, 60, 1, 45, 20, 0}},
|
||||
{"Still", {0, 125, 0, 0, 0, 50, 127, 0, 0, 50, 0, 60, 100, 100, 5, 20, 0, 40, 50, 70, 0, 0, 0, 0, 0, 0, 85, 0, 0, 1, 64, 0, 0}},
|
||||
{"Velvet", {95, 45, 10, 15, 35, 40, 85, 20, 0, 50, 0, 100, 105, 110, 35, 30, 20, 45, 52, 70, 0, 0, 10, 0, 0, 0, 85, 0, 0, 1, 50, 0, 120}},
|
||||
{"Chrome", {35, 115, 15, 35, 15, 75, 15, 120, 45, 90, 80, 85, 60, 90, 35, 55, 15, 40, 85, 60, 64, 3, 85, 2, 20, 35, 110, 70, 0, 3, 95, 0, 0}},
|
||||
{"Swarm", {120, 75, 30, 30, 120, 60, 40, 30, 0, 60, 20, 127, 70, 85, 110, 100, 40, 15, 70, 60, 120, 0, 40, 1, 40, 70, 85, 0, 30, 2, 70, 20, 0}},
|
||||
{"Foghorn", {127, 60, 15, 70, 20, 22, 95, 90, 0, 40, 0, 50, 120, 120, 20, 20, 60, 70, 35, 65, 64, 1, 60, 0, 0, 0, 40, 30, 0, 0, 30, 0, 30}},
|
||||
{"Solar", {70, 105, 45, 20, 55, 90, 15, 15, 5, 80, 30, 120, 100, 110, 60, 50, 70, 35, 100, 90, 10, 3, 15, 2, 60, 25, 120, 40, 0, 3, 110, 30, 0}},
|
||||
{"Cave", {55, 40, 95, 30, 30, 18, 110, 30, 0, 100, 60, 70, 110, 120, 30, 20, 45, 60, 30, 100, 0, 1, 50, 0, 10, 0, 40, 0, 50, 0, 18, 5, 60}},
|
||||
{"Glass Harp", {10, 120, 20, 0, 12, 60, 30, 10, 25, 100, 90, 110, 50, 120, 25, 30, 15, 55, 90, 95, 0, 3, 0, 0, 45, 40, 120, 110, 0, 4, 100, 0, 127}},
|
||||
{"Monk", {110, 85, 10, 25, 30, 38, 70, 40, 0, 60, 0, 70, 100, 100, 30, 25, 30, 65, 50, 80, 0, 1, 55, 1, 15, 0, 62, 90, 0, 1, 50, 0, 90}},
|
||||
{"Static", {35, 40, 127, 15, 40, 70, 40, 50, 0, 110, 90, 127, 40, 70, 80, 110, 20, 20, 80, 55, 30, 0, 30, 2, 0, 0, 85, 0, 85, 3, 100, 40, 0}},
|
||||
{"Lullaby", {85, 70, 8, 10, 22, 45, 100, 10, 0, 60, 0, 80, 110, 120, 20, 15, 35, 80, 55, 85, 0, 2, 0, 0, 10, 8, 85, 20, 0, 1, 64, 0, 110}},
|
||||
{"Storm", {80, 40, 110, 90, 70, 28, 90, 40, 0, 70, 40, 127, 90, 110, 100, 85, 120, 25, 40, 75, 30, 1, 70, 0, 50, 20, 60, 0, 70, 0, 35, 60, 20}},
|
||||
{"Prism", {50, 120, 25, 10, 40, 65, 25, 60, 15, 90, 50, 120, 85, 105, 60, 45, 50, 40, 80, 90, 0, 3, 20, 1, 100, 30, 105, 80, 0, 2, 85, 10, 40}},
|
||||
};
|
||||
constexpr int NRAW = (int)(sizeof(RAW) / sizeof(RAW[0]));
|
||||
|
||||
int colOf(const char *key) {
|
||||
for (int c = 0; c < NCOL; ++c) if (COLS[c] && !std::strcmp(COLS[c], key)) return c;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/** factoryEngine(name): a preset's values as FACTORY stores them (row / 127f as text,
|
||||
* which round-trips exactly, the choices by name), through engineFrom. */
|
||||
bool factoryEngine(const char *name, float *e, int &type) {
|
||||
for (const Raw &p : RAW) {
|
||||
if (std::strcmp(p.name, name)) continue;
|
||||
auto num = [&](const char *k, float d) -> float {
|
||||
if (!std::strcmp(k, "velsens")) return r(38);
|
||||
if (!std::strcmp(k, "body")) return 1.f;
|
||||
int c = colOf(k);
|
||||
return c < 0 ? d : (float)p.row[c] / 127.f;
|
||||
};
|
||||
auto choice = [&](const char *k, const char *d) -> const char * {
|
||||
int c = colOf(k);
|
||||
if (c < 0) return d;
|
||||
if (!std::strcmp(k, "interval")) return INTERVALS[p.row[c] % 4];
|
||||
if (!std::strcmp(k, "ctype")) return FILTER_TYPES[p.row[c] % 3];
|
||||
if (!std::strcmp(k, "bpitch")) return BREATH_PITCHES[p.row[c] % 5];
|
||||
return d;
|
||||
};
|
||||
type = engineFrom(e, num, choice);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int defs::factoryCount() { return NRAW; }
|
||||
const char *defs::factoryName(int i) { return i >= 0 && i < NRAW ? RAW[i].name : ""; }
|
||||
|
||||
FrasilPatch FrasilPatch::from(const Params *slot) {
|
||||
FrasilPatch p;
|
||||
p.aType = engineFrom(
|
||||
p.a,
|
||||
[&](const char *k, float d) { return slot ? slot->f(k, d) : d; },
|
||||
[&](const char *k, const char *d) { return slot ? slot->s(k, d) : d; });
|
||||
const char *target = slot ? slot->s(MORPH_TO, "Off") : "Off";
|
||||
int bt = 0;
|
||||
p.hasB = std::strcmp(target, "Off") != 0 && factoryEngine(target, p.b, bt);
|
||||
p.bType = p.hasB ? bt : p.aType;
|
||||
p.morph = kt::coerceIn(slot ? slot->f(MORPH, 0.f) : 0.f, 0.f, 1.f);
|
||||
p.morphTime = kt::coerceIn(slot ? slot->f(MORPH_TIME, 0.f) : 0.f, 0.f, 120.f);
|
||||
return p;
|
||||
}
|
||||
|
||||
} // namespace sizzle::frasil
|
||||
@@ -0,0 +1,521 @@
|
||||
// SPDX-FileCopyrightText: 2026 Styves Goupil (FRASIL)
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown (Kotlin port for Sizzle, C++ port)
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
||||
// If a copy of the MPL was not distributed with this file, You can obtain one at
|
||||
// https://mozilla.org/MPL/2.0/ (also in LICENSES/MPL-2.0.txt of this repository).
|
||||
//
|
||||
// Port of FrasilVoice.kt, line for line (FRASIL 3.3's drone voice). See the Kotlin
|
||||
// for the commentary on the sound; comments here are about the port.
|
||||
|
||||
#include <cmath>
|
||||
#include "frasil/FrasilVoice.hpp"
|
||||
#include "KotlinMath.hpp"
|
||||
|
||||
// Kotlin rounds every float operation; no fused multiply-adds.
|
||||
#if defined(__clang__)
|
||||
#pragma clang fp contract(off)
|
||||
#endif
|
||||
|
||||
namespace sizzle::frasil {
|
||||
namespace {
|
||||
|
||||
using namespace defs;
|
||||
|
||||
constexpr float VOICE_G = 0.2f;
|
||||
constexpr float TAIL_END = 0.01f;
|
||||
constexpr float SIDE_GAIN = 0.70710678f;
|
||||
constexpr float OUT_GAIN = 2.2f;
|
||||
constexpr float TIDE_SMOOTH_S = 0.5f;
|
||||
constexpr float PI = 3.14159265f;
|
||||
constexpr float TWO_PI = 6.2831853f;
|
||||
constexpr float SIDE[3] = {0.f, -1.f, 1.f};
|
||||
constexpr float PWR[3] = {0.21f, 0.29f, 0.37f};
|
||||
constexpr float LOG2K[8] = {0.f, 1.f, 1.5849625f, 2.f, 2.3219281f, 2.5849625f, 2.8073549f, 3.f};
|
||||
constexpr float BEAT_SPREAD[8] = {0.55f, 1.25f, 0.8f, 1.45f, 0.65f, 1.1f, 0.95f, 1.35f};
|
||||
|
||||
/** BREATH's ratios (log2): ln(r) / ln(2) in double, to float. */
|
||||
struct RatioL2 {
|
||||
float v[3][3];
|
||||
RatioL2() {
|
||||
const double r[3][3] = {{1, 2, 3}, {1, 3, 5}, {1, 2.756f, 5.404f}};
|
||||
for (int i = 0; i < 3; ++i)
|
||||
for (int k = 0; k < 3; ++k) v[i][k] = (float)(std::log(r[i][k]) / std::log(2.0));
|
||||
}
|
||||
};
|
||||
const RatioL2 RATIO_L2;
|
||||
|
||||
inline float tanf_(float x) { return (float)std::tan((double)x); }
|
||||
inline float floorf_(float x) { return (float)std::floor((double)x); }
|
||||
|
||||
/** A blep with the step's inverse. */
|
||||
inline float blep(float t0, float dt, float idt) {
|
||||
if (t0 < dt) { float t = t0 * idt; return t + t - t * t - 1.f; }
|
||||
if (t0 > 1.f - dt) { float t = (t0 - 1.f) * idt; return t * t + t + t + 1.f; }
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
inline float flush(float x) { return (x > -1e-20f && x < 1e-20f) ? 0.f : x; }
|
||||
|
||||
} // namespace
|
||||
|
||||
FrasilVoice::FrasilVoice(int fs_, const FrasilClock &clock_, int32_t seed)
|
||||
: clock(&clock_), invFs(1.f / (float)fs_), r44(44100.f / (float)fs_), nyq(0.45f * (float)fs_),
|
||||
patch(FrasilPatch::defaults()), rng((uint32_t)seed),
|
||||
kdc(brK(0.0014f)), glideK(brK(0.2f)),
|
||||
tideK(1.f - kt::expf_(-(float)BLOCK / ((float)fs_ * TIDE_SMOOTH_S))) {}
|
||||
|
||||
void FrasilVoice::noteOn(int midi, float velocity, const FrasilPatch &p) {
|
||||
bool fresh = note_ < 0;
|
||||
note_ = midi;
|
||||
gate = true;
|
||||
vel = kt::coerceIn(velocity, 0.f, 1.f);
|
||||
patch = p;
|
||||
ageFrames = 0;
|
||||
ending = false;
|
||||
chunk = 0;
|
||||
if (fresh) start();
|
||||
}
|
||||
|
||||
void FrasilVoice::kill() {
|
||||
note_ = -1; gate = false; env = 0.f; lvl = 0.f; pos = CH; ending = false;
|
||||
}
|
||||
|
||||
float FrasilVoice::render() {
|
||||
if (pos >= CH) {
|
||||
if (note_ < 0) return 0.f;
|
||||
if (ending) { note_ = -1; ending = false; return 0.f; }
|
||||
renderChunk();
|
||||
pos = 0;
|
||||
}
|
||||
return out[pos++];
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------- start ---
|
||||
void FrasilVoice::start() {
|
||||
env = 0.f; lvl = 0.f; pos = CH; prime = true;
|
||||
dcState = 0.f; thinState = 0.f; nlp = 0.f;
|
||||
for (int k = 0; k < 3; ++k) {
|
||||
cph[k] = urand();
|
||||
cpw[k] = (float)k * 0.33f;
|
||||
ouC[k] = randf() * 0.5f;
|
||||
}
|
||||
for (float &v : clp) v = 0.f;
|
||||
for (float &v : cint) v = 0.f;
|
||||
csvf = false;
|
||||
for (int k = 0; k < NP; ++k) {
|
||||
float ph = urand() * TWO_PI;
|
||||
px[k] = kt::cosf_(ph); py[k] = kt::sinf_(ph);
|
||||
ps[k] = 0.f; pc[k] = 1.f;
|
||||
ouPa[k] = randf() * 0.5f; ouPf[k] = randf() * 0.5f;
|
||||
pac[k] = 0.f; pda[k] = 0.f;
|
||||
pbt[k] = urand();
|
||||
}
|
||||
for (int k = 0; k < NR; ++k) { r1[k] = 0.f; r2[k] = 0.f; ouR[k] = randf() * 0.5f; }
|
||||
ouCut = randf() * 0.5f;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------- block ---
|
||||
void FrasilVoice::block() {
|
||||
const FrasilPatch &p = patch;
|
||||
const float *b = p.hasB ? p.b : nullptr;
|
||||
float m = b == nullptr ? 0.f : morphPosition(p);
|
||||
float gk = prime ? 1.f : glideK;
|
||||
for (int i = 0; i < N; ++i) {
|
||||
float t = b == nullptr ? p.a[i] : p.a[i] + (b[i] - p.a[i]) * m;
|
||||
cur[i] += (t - cur[i]) * gk;
|
||||
}
|
||||
type = (b != nullptr && m >= 0.5f) ? p.bType : p.aType;
|
||||
float period = 300.f * kt::powf_(1.f / 30.f, cur[TIDE_RATE]);
|
||||
double ph = clock->seconds / (double)period;
|
||||
float tideT = kt::sinf_(TWO_PI * (float)(ph - std::floor(ph)));
|
||||
tideV = prime ? tideT : tideV + (tideT - tideV) * tideK;
|
||||
bool wasPrime = prime;
|
||||
prime = false;
|
||||
ageFrames += BLOCK;
|
||||
|
||||
drift();
|
||||
voiceBlock(wasPrime);
|
||||
|
||||
ka = 1.f - kt::expf_(-CH * invFs * 3.f / (0.005f * kt::powf_(6000.f, cur[ATTACK])));
|
||||
kr = 1.f - kt::expf_(-CH * invFs * 3.f / (0.05f * kt::powf_(1200.f, cur[RELEASE])));
|
||||
float full = cur[BODY];
|
||||
dk = 1.f + 5.f * cur[WARMTH] * full;
|
||||
dmake = 1.f / kt::tanhf_(dk * 0.35f) * 0.35f;
|
||||
driveOn = cur[WARMTH] * full > 0.001f;
|
||||
thin = full < 0.995f;
|
||||
thinA = 1.f - kt::expf_(-TWO_PI * 20.f * kt::powf_(20.f, 1.f - full) * invFs);
|
||||
}
|
||||
|
||||
float FrasilVoice::morphPosition(const FrasilPatch &p) const {
|
||||
if (p.morphTime <= 0.f) return p.morph;
|
||||
float x = kt::coerceIn(((float)ageFrames * invFs) / p.morphTime, 0.f, 1.f);
|
||||
return p.morph + (1.f - p.morph) * x * x * (3.f - 2.f * x);
|
||||
}
|
||||
|
||||
float FrasilVoice::ou(float x, float th, float s) {
|
||||
// Kotlin evaluates the three randf() left to right.
|
||||
float a = randf();
|
||||
float b = randf();
|
||||
float c = randf();
|
||||
return kt::coerceIn(x - th * x + s * (a + b + c), -1.5f, 1.5f);
|
||||
}
|
||||
|
||||
void FrasilVoice::drift() {
|
||||
float tau = 20.f * kt::powf_(0.025f, cur[MOTION_RATE]);
|
||||
float th = BLOCK * invFs / tau;
|
||||
float s = 0.6f * kt::sqrtf_(2.f * th);
|
||||
float te = th * (1.f + 3.f * cur[EVOLVE]);
|
||||
float se = 0.6f * kt::sqrtf_(2.f * te);
|
||||
for (int k = 0; k < 3; ++k) ouC[k] = ou(ouC[k], th, s);
|
||||
for (int k = 0; k < NP; ++k) { ouPa[k] = ou(ouPa[k], te, se); ouPf[k] = ou(ouPf[k], th, s); }
|
||||
for (int k = 0; k < NR; ++k) ouR[k] = ou(ouR[k], th, s);
|
||||
ouCut = ou(ouCut, th, s);
|
||||
}
|
||||
|
||||
void FrasilVoice::voiceBlock(bool fresh) {
|
||||
const float *c = cur;
|
||||
float f = 440.f * kt::powf_(2.f, (float)(note_ - 69) / 12.f);
|
||||
float m = c[MOTION];
|
||||
float mw = m * (1.f + 2.f * m);
|
||||
float bright = (c[TIMBRE] - 0.5f) + tideV * c[TIDE] * 0.5f;
|
||||
float full = c[BODY];
|
||||
|
||||
// CHOIR
|
||||
if (c[CHOIR] > 0.001f) {
|
||||
float dc = c[DETUNE] * c[DETUNE] * 40.f * (0.2f + 0.8f * full);
|
||||
float sh = c[SHAPE];
|
||||
float a = sh < 0.5f ? 2.f * sh : 1.f;
|
||||
float w = sh < 0.5f ? 0.5f : 0.5f - 0.8f * (sh - 0.5f);
|
||||
float sw = sh > 0.5f ? 0.03f + 0.18f * (sh - 0.5f) : 0.03f * a;
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
float cents = SIDE[j] * dc + mw * 7.f * ouC[j];
|
||||
cdt[j] = kt::coerceIn(f * (j == 0 ? c[INTERVAL] : 1.f) * kt::powf_(2.f, cents / 1200.f) * invFs, 1e-6f, 0.45f);
|
||||
cid[j] = 1.f / cdt[j];
|
||||
cpw[j] += PWR[j] * BLOCK * invFs;
|
||||
cpw[j] -= floorf_(cpw[j]);
|
||||
cw[j] = kt::coerceIn(w + sw * kt::sinf_(TWO_PI * cpw[j]) + 0.1f * mw * ouC[j] * a, 0.04f, 0.96f);
|
||||
}
|
||||
csh = a;
|
||||
float ce = kt::coerceIn(c[CUTOFF] + bright * 0.6f + mw * 0.2f * ouCut, 0.f, 1.f);
|
||||
float hc = 1.f + 39.f * ce * ce;
|
||||
float fc = kt::coerceIn(f * hc, 20.f, std::fmin(16000.f, nyq));
|
||||
ca = 1.f - kt::expf_(-TWO_PI * fc * invFs);
|
||||
float pv = (1.f + a * a) / 3.f - 2.f * a * (1.f / 3.f - 2.f * w * (1.f - w));
|
||||
cgain = kt::sqrtf_((1.f / 3.f) / (pv > 0.05f ? pv : 0.05f));
|
||||
if (c[CH_RESO] > 0.002f || type != 0) {
|
||||
float g = tanf_(PI * fc * invFs);
|
||||
float q = 0.5f * kt::powf_(40.f, c[CH_RESO]);
|
||||
float k = 1.f / q;
|
||||
sa1 = 1.f / (1.f + g * (g + k)); sa2 = g * sa1; sa3 = g * sa2;
|
||||
switch (type) {
|
||||
case 1: sc0 = 0.f; sc1 = k * (1.4f + 0.12f * kt::sqrtf_(hc)) * kt::sqrtf_(q); sc2 = 0.f; break;
|
||||
case 2: {
|
||||
float mk = kt::coerceIn(kt::sqrtf_(0.75f * hc), 1.f, 4.f);
|
||||
sc0 = mk; sc1 = -k * mk; sc2 = -mk;
|
||||
break;
|
||||
}
|
||||
default: sc0 = 0.f; sc1 = 0.f; sc2 = 1.f; break;
|
||||
}
|
||||
cgain *= 1.f / kt::sqrtf_(1.f + 0.22f * (q - 0.5f));
|
||||
}
|
||||
if (fresh) { sp0 = sc0; sp1 = sc1; sp2 = sc2; }
|
||||
}
|
||||
|
||||
// PARTIALS
|
||||
if (c[PARTIALS] > 0.001f) {
|
||||
float pe = kt::coerceIn(c[TILT] - bright * 0.7f, 0.f, 1.f);
|
||||
float pw = 0.3f + 2.7f * pe;
|
||||
float sx = 1.f + 0.12f * c[STRETCH];
|
||||
float fnp = 2.f + 6.f * full;
|
||||
int nmax = kt::toInt(fnp);
|
||||
float top = fnp - (float)nmax;
|
||||
if (top > 0.001f) nmax++; else top = 1.f;
|
||||
if (nmax > NP) nmax = NP;
|
||||
float sum2 = 0.f;
|
||||
int n = 0;
|
||||
for (int j = 0; j < nmax; ++j) {
|
||||
float fk = f * kt::powf_(2.f, sx * LOG2K[j] + mw * 5.f * ouPf[j] / 1200.f);
|
||||
if (fk > std::fmin(15000.f, nyq)) break;
|
||||
float w = TWO_PI * fk * invFs;
|
||||
float cw0 = kt::cosf_(w); float sn = kt::sinf_(w);
|
||||
float q = kt::sqrtf_(2.f * (1.f + cw0));
|
||||
float x = px[j];
|
||||
float y = (py[j] - x * ps[j]) * pc[j];
|
||||
float gn = 1.5f - 0.5f * (x * x + y * y);
|
||||
float shh = sn / q;
|
||||
float chh = (1.f + cw0) / q;
|
||||
x *= gn; y *= gn;
|
||||
ps[j] = shh;
|
||||
pc[j] = q / (1.f + cw0);
|
||||
px[j] = x;
|
||||
py[j] = y * chh + x * shh;
|
||||
float a = kt::powf_(2.f, -pw * LOG2K[j] + 1.6f * (m + 2.5f * c[EVOLVE]) * ouPa[j]);
|
||||
if ((j & 1) == 1) a *= 1.f - c[ODD];
|
||||
float pk = c[PEAK];
|
||||
if (pk > 0.001f) {
|
||||
float d = (sx * LOG2K[j] - c[FORMANT]) * (1.5f + 4.f * pk);
|
||||
float fl = 1.f - 0.97f * pk;
|
||||
a *= fl + (1.f + 7.f * pk - fl) / (1.f + d * d);
|
||||
}
|
||||
if (j + 1 == nmax) a *= top;
|
||||
pa[j] = a;
|
||||
sum2 += a * a;
|
||||
n++;
|
||||
}
|
||||
np = n;
|
||||
float norm = 0.6f / kt::sqrtf_(sum2 + 1e-9f);
|
||||
for (int j = 0; j < n; ++j) pa[j] *= norm;
|
||||
if (c[BEAT] > 0.001f) {
|
||||
float bt = c[BEAT];
|
||||
float dep = std::fmin(1.f, bt * 1.4f);
|
||||
float hz = 0.15f + 5.f * bt * bt;
|
||||
for (int j = 0; j < n; ++j) {
|
||||
pbt[j] += hz * BEAT_SPREAD[j] * BLOCK * invFs;
|
||||
pbt[j] -= floorf_(pbt[j]);
|
||||
pa[j] *= (1.f - dep * (0.5f + 0.5f * kt::sinf_(TWO_PI * pbt[j]))) / (1.f - 0.5f * dep);
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < n; ++j) pda[j] = (pa[j] - pac[j]) / BLOCK;
|
||||
for (int j = n; j < NP; ++j) { pac[j] = 0.f; pda[j] = 0.f; }
|
||||
}
|
||||
|
||||
// BREATH
|
||||
if (c[BREATH] > 0.001f) {
|
||||
float col = kt::coerceIn(c[COLOR], 0.f, 1.f) * 2.f;
|
||||
bool lo = col < 1.f;
|
||||
const float *ra = RATIO_L2.v[lo ? 0 : 1];
|
||||
const float *rb = RATIO_L2.v[lo ? 1 : 2];
|
||||
if (!lo) col -= 1.f;
|
||||
float q = 2.f * kt::powf_(300.f, kt::coerceIn(c[RESONANCE] + mw * 0.1f * ouR[0], 0.f, 1.f));
|
||||
float sb = kt::coerceIn(0.55f + bright * 0.8f, 0.05f, 1.f);
|
||||
for (int j = 0; j < NR; ++j) {
|
||||
float l2 = ra[j] + (rb[j] - ra[j]) * col + mw * 12.f * ouR[j] / 1200.f;
|
||||
float fr = kt::coerceIn(f * c[BR_PITCH] * kt::powf_(2.f, l2), 20.f, std::fmin(16000.f, nyq));
|
||||
double r = (double)kt::expf_(-PI * fr / q * invFs);
|
||||
double b1 = 2.0 * r * (double)kt::cosf_(TWO_PI * fr * invFs);
|
||||
double b2 = r * r;
|
||||
double ng = (1.0 + b2) / ((1.0 - b2) * ((1.0 + b2) * (1.0 + b2) - b1 * b1));
|
||||
rb1[j] = (float)b1; rb2[j] = (float)b2;
|
||||
rg[j] = (float)(0.4 * std::sqrt(3.0 / ng)) * (j == 0 ? 1.f : sb * (j == 2 ? sb : 1.f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------- chunk ---
|
||||
void FrasilVoice::renderChunk() {
|
||||
if (chunk == 0) block();
|
||||
chunk = (chunk + 1) % (BLOCK / CH);
|
||||
const float *c = cur;
|
||||
env += ((gate ? 1.f : 0.f) - env) * (gate ? ka : kr);
|
||||
float level = (1.f - c[VELOCITY] + c[VELOCITY] * vel) * VOICE_G;
|
||||
float g1 = (!gate && env < TAIL_END) ? 0.f : level * env * env;
|
||||
float g = lvl;
|
||||
lvl = g1;
|
||||
float dg = (g1 - g) / CH;
|
||||
for (int i = 0; i < CH; ++i) { bc[i] = 0.f; ba[i] = 0.f; bb[i] = 0.f; }
|
||||
float full = c[BODY];
|
||||
if (c[CHOIR] > 0.001f) choirChunk(0.35f * c[CHOIR] * (0.3f + 0.7f * full));
|
||||
if (c[PARTIALS] > 0.001f) partialsChunk(c[PARTIALS] * (0.7f + 0.3f * full));
|
||||
if (c[BREATH] > 0.001f) { breathNoise(); souffleChunk(c[BREATH] * full * full); }
|
||||
|
||||
float z = bc[CH - 1] + ba[CH - 1] + bb[CH - 1] + bc[CH / 2] + ba[CH / 2] + bb[CH / 2];
|
||||
if (!(z > -1e4f && z < 1e4f)) {
|
||||
for (int i = 0; i < CH; ++i) { bc[i] = 0.f; ba[i] = 0.f; bb[i] = 0.f; }
|
||||
start();
|
||||
prime = false;
|
||||
}
|
||||
|
||||
float dcs = dcState;
|
||||
float th = thinState;
|
||||
for (int i = 0; i < CH; ++i) {
|
||||
g += dg;
|
||||
float x = (bc[i] + SIDE_GAIN * (ba[i] + bb[i])) * g;
|
||||
dcs += kdc * (x - dcs);
|
||||
x -= dcs;
|
||||
if (driveOn) x = kt::tanhf_(x * dk) * dmake;
|
||||
if (thin) { th += thinA * (x - th); x -= th; }
|
||||
out[i] = x * OUT_GAIN;
|
||||
}
|
||||
dcState = flush(dcs);
|
||||
thinState = thin ? flush(th) : 0.f;
|
||||
if (g1 == 0.f && !gate && env < TAIL_END) ending = true;
|
||||
}
|
||||
|
||||
void FrasilVoice::choirChunk(float g0) {
|
||||
bool svf = cur[CH_RESO] > 0.002f || type != 0;
|
||||
bool sq = cur[SHAPE] > 0.002f;
|
||||
bool soft = cur[SOFT] > 0.002f;
|
||||
if (svf != csvf) {
|
||||
clp[0] = svf ? 0.f : clp[1];
|
||||
clp[2] = svf ? 0.f : clp[3];
|
||||
csvf = svf;
|
||||
}
|
||||
float g = g0 * cgain;
|
||||
float p0 = cph[0], p1 = cph[1], p2 = cph[2];
|
||||
const float d0 = cdt[0], d1 = cdt[1], d2 = cdt[2];
|
||||
const float i0 = cid[0], i1 = cid[1], i2 = cid[2];
|
||||
const float sh = csh, w0 = cw[0], w1 = cw[1], w2 = cw[2];
|
||||
for (int i = 0; i < CH; ++i) {
|
||||
p0 += d0; if (p0 >= 1.f) p0 -= 1.f;
|
||||
p1 += d1; if (p1 >= 1.f) p1 -= 1.f;
|
||||
p2 += d2; if (p2 >= 1.f) p2 -= 1.f;
|
||||
float s0 = 2.f * p0 - 1.f - blep(p0, d0, i0);
|
||||
float s1 = 2.f * p1 - 1.f - blep(p1, d1, i1);
|
||||
float s2 = 2.f * p2 - 1.f - blep(p2, d2, i2);
|
||||
if (sq) {
|
||||
float q0 = p0 + w0; if (q0 >= 1.f) q0 -= 1.f;
|
||||
float q1 = p1 + w1; if (q1 >= 1.f) q1 -= 1.f;
|
||||
float q2 = p2 + w2; if (q2 >= 1.f) q2 -= 1.f;
|
||||
s0 -= sh * (2.f * q0 - 1.f - blep(q0, d0, i0));
|
||||
s1 -= sh * (2.f * q1 - 1.f - blep(q1, d1, i1));
|
||||
s2 -= sh * (2.f * q2 - 1.f - blep(q2, d2, i2));
|
||||
}
|
||||
if (soft) { xc[i] = s0; x0[i] = s1; x1[i] = s2; } else { x0[i] = s0 + s1; x1[i] = s0 + s2; }
|
||||
}
|
||||
cph[0] = p0; cph[1] = p1; cph[2] = p2;
|
||||
if (soft) {
|
||||
float kc = TWO_PI * d0; float ks = TWO_PI * d1;
|
||||
float lc = 1.f - 0.15f * kc; float ls = 1.f - 0.15f * ks;
|
||||
float u = cur[SOFT];
|
||||
float a0, a1, a2;
|
||||
if (u < 0.5f) { a0 = kt::cosf_(PI * u); a1 = kt::sinf_(PI * u); a2 = 0.f; }
|
||||
else { a0 = 0.f; a1 = kt::cosf_(PI * (u - 0.5f)); a2 = kt::sinf_(PI * (u - 0.5f)); }
|
||||
float c1 = a1 * kc, c2 = a2 * kc * kc, e1 = a1 * ks, e2 = a2 * ks * ks;
|
||||
float cA = cint[0], cB = cint[1], l1 = cint[2], l2 = cint[3], q1 = cint[4], q2 = cint[5];
|
||||
for (int j = 0; j < CH; ++j) {
|
||||
float vc = xc[j], vl = x0[j], vr = x1[j];
|
||||
cA = lc * cA + vc; cB = lc * cB + cA;
|
||||
l1 = ls * l1 + vl; l2 = ls * l2 + l1;
|
||||
q1 = ls * q1 + vr; q2 = ls * q2 + q1;
|
||||
float cc = a0 * vc + c1 * cA + c2 * cB;
|
||||
x0[j] = cc + a0 * vl + e1 * l1 + e2 * l2;
|
||||
x1[j] = cc + a0 * vr + e1 * q1 + e2 * q2;
|
||||
}
|
||||
if (!(cB > -1e9f && cB < 1e9f && l2 > -1e9f && l2 < 1e9f && q2 > -1e9f && q2 < 1e9f)) {
|
||||
cA = 0.f; cB = 0.f; l1 = 0.f; l2 = 0.f; q1 = 0.f; q2 = 0.f;
|
||||
}
|
||||
cint[0] = cA; cint[1] = cB; cint[2] = l1; cint[3] = l2; cint[4] = q1; cint[5] = q2;
|
||||
} else {
|
||||
for (float &v : cint) v = 0.f;
|
||||
}
|
||||
if (svf) {
|
||||
float o0 = sp0 * g, o1 = sp1 * g, o2 = sp2 * g;
|
||||
float e0 = (sc0 - sp0) * g / CH, e1 = (sc1 - sp1) * g / CH, e2 = (sc2 - sp2) * g / CH;
|
||||
svfRun(ba, x0, 0, o0, o1, o2, e0, e1, e2);
|
||||
svfRun(bb, x1, 2, o0, o1, o2, e0, e1, e2);
|
||||
} else {
|
||||
float a = ca;
|
||||
float l1 = clp[0], l2 = clp[1], q1 = clp[2], q2 = clp[3];
|
||||
for (int i = 0; i < CH; ++i) {
|
||||
l1 += a * (x0[i] - l1); l2 += a * (l1 - l2);
|
||||
q1 += a * (x1[i] - q1); q2 += a * (q1 - q2);
|
||||
ba[i] += l2 * g; bb[i] += q2 * g;
|
||||
}
|
||||
clp[0] = l1; clp[1] = l2; clp[2] = q1; clp[3] = q2;
|
||||
}
|
||||
sp0 = sc0; sp1 = sc1; sp2 = sc2;
|
||||
}
|
||||
|
||||
void FrasilVoice::svfRun(float *b, const float *x, int s, float o0i, float o1i, float o2i,
|
||||
float e0, float e1, float e2) {
|
||||
float s1 = clp[s], s2 = clp[s + 1];
|
||||
float o0 = o0i, o1 = o1i, o2 = o2i;
|
||||
const float a1 = sa1, a2 = sa2, a3 = sa3;
|
||||
for (int i = 0; i < CH; ++i) {
|
||||
float v = x[i] - s2;
|
||||
float t1 = a1 * s1 + a2 * v;
|
||||
float t2 = s2 + a2 * s1 + a3 * v;
|
||||
s1 = 2.f * t1 - s1;
|
||||
s2 = 2.f * t2 - s2;
|
||||
b[i] += o0 * x[i] + o1 * t1 + o2 * t2;
|
||||
o0 += e0; o1 += e1; o2 += e2;
|
||||
}
|
||||
clp[s] = s1; clp[s + 1] = s2;
|
||||
}
|
||||
|
||||
void FrasilVoice::partialsChunk(float g) {
|
||||
for (int j = 0; j < np; ++j) {
|
||||
float *bus = j == 0 ? bc : ((j & 1) == 1 ? ba : bb); // 1, 3, 5, 7 -> ba; 2, 4, 6 -> bb
|
||||
float x = px[j], y = py[j];
|
||||
float e = 2.f * ps[j];
|
||||
float a = pac[j] * g;
|
||||
float d = pda[j] * g;
|
||||
for (int i = 0; i < CH; ++i) {
|
||||
x -= e * y;
|
||||
y += e * x;
|
||||
bus[i] += a * x;
|
||||
a += d;
|
||||
}
|
||||
px[j] = x; py[j] = y;
|
||||
pac[j] += pda[j] * CH;
|
||||
}
|
||||
}
|
||||
|
||||
void FrasilVoice::breathNoise() {
|
||||
float grain = cur[GRAIN];
|
||||
if (grain < 0.002f) {
|
||||
for (int i = 0; i < CH; ++i) nz[i] = randf();
|
||||
} else {
|
||||
float p = kt::powf_(2.f, -13.f * grain) * r44;
|
||||
float amp = std::fmin(16.f, kt::sqrtf_(1.f / (3.f * 0.5833f * p)));
|
||||
int32_t th = kt::toInt(p * 16777216.f);
|
||||
for (int i = 0; i < CH; ++i) {
|
||||
int32_t r = nextRand();
|
||||
float a = amp * (0.5f + (float)(r & 255) * (0.5f / 255.f));
|
||||
nz[i] = (int32_t)((uint32_t)r >> 8) < th ? ((r & 256) != 0 ? a : -a) : 0.f;
|
||||
}
|
||||
}
|
||||
float t = cur[TONE];
|
||||
if (t < -0.01f) {
|
||||
float fc = 16000.f * kt::powf_(300.f / 16000.f, -t);
|
||||
float a = 1.f - kt::expf_(-TWO_PI * std::fmin(fc, nyq) * invFs);
|
||||
float gn = kt::sqrtf_((2.f - a) / a);
|
||||
float l = nlp;
|
||||
for (int i = 0; i < CH; ++i) { l += a * (nz[i] - l); nz[i] = l * gn; }
|
||||
nlp = flush(l);
|
||||
} else if (t > 0.01f) {
|
||||
float fc = 20.f * kt::powf_(150.f, t);
|
||||
float a = 1.f - kt::expf_(-TWO_PI * fc * invFs);
|
||||
float gn = 1.f / kt::sqrtf_(1.f + a / (2.f - a) - 2.f * a);
|
||||
float l = nlp;
|
||||
for (int i = 0; i < CH; ++i) { l += a * (nz[i] - l); nz[i] = (nz[i] - l) * gn; }
|
||||
nlp = flush(l);
|
||||
}
|
||||
}
|
||||
|
||||
void FrasilVoice::souffleChunk(float g) {
|
||||
float air = cur[AIR];
|
||||
float ga = air * 0.7f * g;
|
||||
for (int j = 0; j < NR; ++j) {
|
||||
float *bus = j == 0 ? bc : (j == 1 ? ba : bb);
|
||||
float y1 = r1[j], y2 = r2[j];
|
||||
const float b1 = rb1[j], b2 = rb2[j], gg = rg[j] * g;
|
||||
bool withAir = j == 0 && air > 0.001f;
|
||||
for (int i = 0; i < CH; ++i) {
|
||||
float y = gg * nz[i] + b1 * y1 - b2 * y2;
|
||||
y2 = y1; y1 = y;
|
||||
bus[i] += withAir ? y + ga * nz[i] : y;
|
||||
}
|
||||
if (y1 > -1e-20f && y1 < 1e-20f && y2 > -1e-20f && y2 < 1e-20f) { y1 = 0.f; y2 = 0.f; }
|
||||
r1[j] = y1; r2[j] = y2;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------- helpers ---
|
||||
float FrasilVoice::brK(float k) const { return 1.f - kt::powf_(1.f - k, r44); }
|
||||
|
||||
int32_t FrasilVoice::nextRand() {
|
||||
uint32_t x = rng;
|
||||
x ^= x << 13;
|
||||
x ^= x >> 17;
|
||||
x ^= x << 5;
|
||||
rng = x;
|
||||
return (int32_t)x;
|
||||
}
|
||||
|
||||
float FrasilVoice::randf() { return (float)nextRand() * (1.f / 2147483648.f); }
|
||||
float FrasilVoice::urand() { return (float)((uint32_t)nextRand() >> 8) * (1.f / 16777216.f); }
|
||||
|
||||
} // namespace sizzle::frasil
|
||||
@@ -0,0 +1,184 @@
|
||||
// SPDX-FileCopyrightText: 2026 Styves Goupil (FRASIL)
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown (Kotlin port for Sizzle, C++ port)
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
||||
// If a copy of the MPL was not distributed with this file, You can obtain one at
|
||||
// https://mozilla.org/MPL/2.0/ (also in LICENSES/MPL-2.0.txt of this repository).
|
||||
//
|
||||
// Port of frasil/FrasilVoice.kt, FrasilPatch.kt and FrasilDefs.kt (the Morph Pad).
|
||||
// Kotlin's globals become explicit state: FrasilClock (TIDE's shared time) and
|
||||
// FrasilSeeds (the companion's seed counter) are owned by the engine and handed in.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace sizzle {
|
||||
class Params;
|
||||
}
|
||||
|
||||
namespace sizzle::frasil {
|
||||
|
||||
/** FRASIL's TIDE is one slow sine shared by every voice: the engine advances this
|
||||
* clock once a block, each voice reads it. Audio thread only. */
|
||||
struct FrasilClock {
|
||||
double seconds = 0.0;
|
||||
void advance(int frames, int sampleRate) { seconds += (double)frames / sampleRate; }
|
||||
};
|
||||
|
||||
/** The Kotlin companion's seed counter (FrasilVoice.nextSeed): each new voice takes
|
||||
* the next seed. One per engine, so voices get the seeds the Kotlin app gives them. */
|
||||
struct FrasilSeeds {
|
||||
uint32_t seeds = 0x2545F491u;
|
||||
int32_t next() {
|
||||
seeds += 0x6D2B79F5u;
|
||||
return seeds == 0 ? (int32_t)0x2545F491 : (int32_t)seeds;
|
||||
}
|
||||
};
|
||||
|
||||
/** Engine parameter indices (FrasilDefs). */
|
||||
namespace defs {
|
||||
constexpr int CHOIR = 0, PARTIALS = 1, BREATH = 2, WARMTH = 3, DETUNE = 4, CUTOFF = 5, TILT = 6,
|
||||
ODD = 7, STRETCH = 8, RESONANCE = 9, COLOR = 10, ATTACK = 11, RELEASE = 12,
|
||||
MOTION = 13, MOTION_RATE = 14, TIDE = 15, TIDE_RATE = 16, TIMBRE = 17, SHAPE = 18,
|
||||
CH_RESO = 19, EVOLVE = 20, BEAT = 21, FORMANT = 22, PEAK = 23, GRAIN = 24, TONE = 25,
|
||||
AIR = 26, SOFT = 27, VELOCITY = 28, BODY = 29, INTERVAL = 30, BR_PITCH = 31, N = 32;
|
||||
constexpr const char *MORPH_TO = "morphTo";
|
||||
constexpr const char *MORPH = "morph";
|
||||
constexpr const char *MORPH_TIME = "mtime";
|
||||
/** FRASIL's 36 drone presets (MORPH TO's targets). */
|
||||
int factoryCount();
|
||||
const char *factoryName(int i);
|
||||
} // namespace defs
|
||||
|
||||
/** A Morph Pad slot's snapshot (FrasilPatch): build it off the audio thread. */
|
||||
struct FrasilPatch {
|
||||
float a[defs::N] = {};
|
||||
int aType = 0;
|
||||
bool hasB = false; // Kotlin's b != null
|
||||
float b[defs::N] = {};
|
||||
int bType = 0;
|
||||
/** Where a note starts between a (0) and b (1). */
|
||||
float morph = 0.f;
|
||||
/** Seconds a held note takes from morph to b; 0 stays at morph. */
|
||||
float morphTime = 0.f;
|
||||
|
||||
/** FrasilPatch.from(slot); nullptr is Kotlin's from(null) (all defaults). */
|
||||
static FrasilPatch from(const Params *slot);
|
||||
static FrasilPatch from(const Params &slot) { return from(&slot); }
|
||||
/** FrasilPatch.DEFAULT. */
|
||||
static FrasilPatch defaults() { return from(nullptr); }
|
||||
};
|
||||
|
||||
/** One note of the Morph Pad (FrasilVoice). Allocation-free; the patch is copied in. */
|
||||
class FrasilVoice {
|
||||
public:
|
||||
static constexpr int NP = 8;
|
||||
static constexpr int NR = 3;
|
||||
static constexpr int CH = 64;
|
||||
static constexpr int BLOCK = 256;
|
||||
|
||||
/** [clock] must outlive the voice; [seed] from the engine's FrasilSeeds. */
|
||||
FrasilVoice(int fs, const FrasilClock &clock, int32_t seed);
|
||||
|
||||
int note() const { return note_; }
|
||||
bool isActive() const { return note_ >= 0; }
|
||||
bool isGated() const { return note_ >= 0 && gate; }
|
||||
|
||||
/** Start [midi] at [velocity] (0..1); a sounding voice goes on from where it is. */
|
||||
void noteOn(int midi, float velocity, const FrasilPatch &p);
|
||||
void noteOff() { gate = false; }
|
||||
/** Silence now, no tail. */
|
||||
void kill();
|
||||
/** Follow edits while sounding: the values glide there over ~25 ms. */
|
||||
void setPatch(const FrasilPatch &p) { patch = p; }
|
||||
float render();
|
||||
|
||||
private:
|
||||
void start();
|
||||
void block();
|
||||
float morphPosition(const FrasilPatch &p) const;
|
||||
float ou(float x, float th, float s);
|
||||
void drift();
|
||||
void voiceBlock(bool fresh);
|
||||
void renderChunk();
|
||||
void choirChunk(float g0);
|
||||
void svfRun(float *b, const float *x, int s, float o0i, float o1i, float o2i, float e0, float e1, float e2);
|
||||
void partialsChunk(float g);
|
||||
void breathNoise();
|
||||
void souffleChunk(float g);
|
||||
float brK(float k) const;
|
||||
int32_t nextRand();
|
||||
float randf();
|
||||
float urand();
|
||||
|
||||
const FrasilClock *clock;
|
||||
const float invFs;
|
||||
const float r44;
|
||||
const float nyq;
|
||||
|
||||
int note_ = -1;
|
||||
bool gate = false;
|
||||
float vel = 0.f;
|
||||
float env = 0.f;
|
||||
float lvl = 0.f;
|
||||
FrasilPatch patch;
|
||||
bool prime = true;
|
||||
float cur[defs::N] = {};
|
||||
int type = 0;
|
||||
int64_t ageFrames = 0;
|
||||
float tideV = 0.f;
|
||||
uint32_t rng;
|
||||
|
||||
// drift
|
||||
float ouC[3] = {};
|
||||
float ouCut = 0.f;
|
||||
float ouPa[NP] = {};
|
||||
float ouPf[NP] = {};
|
||||
float ouR[NR] = {};
|
||||
|
||||
// CHOIR
|
||||
float cph[3] = {}, cdt[3] = {}, cid[3] = {}, cw[3] = {}, cpw[3] = {};
|
||||
float csh = 0.f;
|
||||
float sc0 = 0.f, sc1 = 0.f, sc2 = 1.f;
|
||||
float sp0 = 0.f, sp1 = 0.f, sp2 = 1.f;
|
||||
float clp[4] = {};
|
||||
float ca = 0.f;
|
||||
float sa1 = 0.f, sa2 = 0.f, sa3 = 0.f;
|
||||
float cgain = 1.f;
|
||||
float cint[6] = {};
|
||||
bool csvf = false;
|
||||
|
||||
// PARTIALS
|
||||
float px[NP] = {}, py[NP] = {}, pa[NP] = {}, ps[NP] = {}, pc[NP] = {};
|
||||
float pac[NP] = {}, pda[NP] = {}, pbt[NP] = {};
|
||||
int np = 0;
|
||||
|
||||
// BREATH
|
||||
float r1[NR] = {}, r2[NR] = {}, rb1[NR] = {}, rb2[NR] = {}, rg[NR] = {};
|
||||
float nlp = 0.f;
|
||||
|
||||
// output stages
|
||||
float dcState = 0.f;
|
||||
float thinState = 0.f;
|
||||
float ka = 0.f, kr = 0.f;
|
||||
float dk = 1.f, dmake = 1.f;
|
||||
bool driveOn = false;
|
||||
float thinA = 0.f;
|
||||
bool thin = false;
|
||||
const float kdc;
|
||||
const float glideK;
|
||||
const float tideK;
|
||||
|
||||
// chunk buffers
|
||||
float bc[CH] = {}, ba[CH] = {}, bb[CH] = {};
|
||||
float x0[CH] = {}, x1[CH] = {}, xc[CH] = {};
|
||||
float nz[CH] = {};
|
||||
float out[CH] = {};
|
||||
int pos = CH;
|
||||
int chunk = 0;
|
||||
bool ending = false;
|
||||
};
|
||||
|
||||
} // namespace sizzle::frasil
|
||||
@@ -0,0 +1,401 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// Port of AmbienceReverb.kt: mono 8-line FDN reverb (OTODESK "Ambience" style) with
|
||||
// predelay, early reflections, input diffusers, nested allpasses, xorshift-noise
|
||||
// LFOs, ducking and wet saturation. Line-for-line; Float stays float.
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include "sizzle/Effect.hpp"
|
||||
#include "KotlinMath.hpp"
|
||||
|
||||
// The JVM never fuses a*b+c; keep the compiler from contracting into FMA.
|
||||
#if defined(__clang__)
|
||||
#pragma clang fp contract(off)
|
||||
#endif
|
||||
|
||||
namespace sizzle {
|
||||
namespace {
|
||||
|
||||
constexpr int N = 8;
|
||||
const float FWHT_NORM = 1.f / kt::sqrtf_((float)N);
|
||||
constexpr float LATE_SCALE = 2.f / N;
|
||||
constexpr int MAX_ER = 12;
|
||||
constexpr int MAX_ER_ACTIVE = 6;
|
||||
constexpr float PHI = 1.6180339887f;
|
||||
constexpr float TWO_PI = 6.28318530718f;
|
||||
|
||||
const float ALGO_HF[] = {0.00f, 0.26f, 0.26f, 0.22f, 0.36f, 0.14f, 0.30f};
|
||||
const float ALGO_OFFSET_DB[] = {0.8f, 0.9f, 0.5f, 0.5f, 1.5f, 0.6f, 0.6f};
|
||||
const float ALGO_SAT_MUL[] = {0.90f, 0.90f, 0.93f, 0.93f, 1.00f, 1.05f, 1.02f};
|
||||
const float SIGN_FLIP[N] = {1.f, -1.f, 1.f, -1.f, -1.f, 1.f, -1.f, 1.f};
|
||||
|
||||
const char *const ALGORITHMS[] = {"Room 1", "Room 2", "Hall 1", "Hall 2", "Plate", "Spring", "Goldfoil"};
|
||||
|
||||
const float ER_ROOM1[] = {
|
||||
5.2f, 0.65f, 8.7f, 0.58f, 12.4f, 0.52f, 15.8f, 0.46f, 19.3f, 0.42f, 24.1f, 0.36f,
|
||||
28.6f, 0.32f, 33.5f, 0.28f, 38.9f, 0.24f, 45.2f, 0.20f, 52.8f, 0.16f, 62.4f, 0.13f,
|
||||
};
|
||||
const float ER_ROOM2[] = {
|
||||
7.5f, 0.62f, 12.3f, 0.55f, 17.1f, 0.49f, 22.8f, 0.43f, 28.5f, 0.38f, 34.2f, 0.33f,
|
||||
41.6f, 0.28f, 49.3f, 0.24f, 57.8f, 0.20f, 67.5f, 0.17f, 78.2f, 0.14f, 90.6f, 0.11f,
|
||||
};
|
||||
const float ER_HALL1[] = {
|
||||
12.0f, 0.58f, 18.5f, 0.52f, 25.7f, 0.47f, 33.4f, 0.42f, 42.1f, 0.38f, 51.6f, 0.33f,
|
||||
62.3f, 0.29f, 73.9f, 0.25f, 86.5f, 0.21f, 99.8f, 0.18f, 113.4f, 0.15f, 128.7f, 0.12f,
|
||||
};
|
||||
const float ER_HALL2[] = {
|
||||
16.5f, 0.55f, 24.8f, 0.50f, 33.7f, 0.45f, 43.5f, 0.40f, 54.2f, 0.36f, 65.8f, 0.32f,
|
||||
78.4f, 0.28f, 92.1f, 0.24f, 107.3f, 0.21f, 123.6f, 0.18f, 141.2f, 0.15f, 160.5f, 0.12f,
|
||||
};
|
||||
const float *const ER_PATTERNS[] = {ER_ROOM1, ER_ROOM2, ER_HALL1, ER_HALL2, nullptr, nullptr, nullptr};
|
||||
const int ER_PATTERN_SIZE[] = {24, 24, 24, 24, 0, 0, 0};
|
||||
|
||||
inline float lnf_(float x) { return (float)std::log((double)x); }
|
||||
inline float floorf_(float x) { return (float)std::floor((double)x); }
|
||||
|
||||
inline float pow10(float x) { return kt::expf_(x * 2.302585093f); }
|
||||
inline float db2lin(float db) { return pow10(db / 20.f); }
|
||||
|
||||
/** In-place size-N Fast Walsh-Hadamard transform, normalised (÷√N) → orthonormal. */
|
||||
void fwht(float *v) {
|
||||
int h = 1;
|
||||
while (h < N) {
|
||||
int i = 0;
|
||||
while (i < N) {
|
||||
int j = i;
|
||||
while (j < i + h) {
|
||||
float a = v[j]; float b = v[j + h];
|
||||
v[j] = a + b; v[j + h] = a - b;
|
||||
j++;
|
||||
}
|
||||
i += h * 2;
|
||||
}
|
||||
h *= 2;
|
||||
}
|
||||
for (int k = 0; k < N; ++k) v[k] *= FWHT_NORM;
|
||||
}
|
||||
|
||||
bool isPrime(int n) {
|
||||
if (n < 2) return false;
|
||||
if (n == 2) return true;
|
||||
if (n % 2 == 0) return false;
|
||||
int i = 3;
|
||||
while (i * i <= n) { if (n % i == 0) return false; i += 2; }
|
||||
return true;
|
||||
}
|
||||
|
||||
bool usedNone(const int *used, int count, int v) {
|
||||
for (int k = 0; k < count; ++k) if (used[k] == v) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
int nearestUniquePrime(int target, const int *used, int count) {
|
||||
int t = std::max(target, 2);
|
||||
int offset = 0;
|
||||
while (offset < 100000) {
|
||||
int hi = t + offset;
|
||||
if (isPrime(hi) && usedNone(used, count, hi)) return hi;
|
||||
int lo = t - offset;
|
||||
if (offset > 0 && lo >= 2 && isPrime(lo) && usedNone(used, count, lo)) return lo;
|
||||
offset++;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
float softClip(float x) {
|
||||
if (x > 1.f) return 1.f - 1.f / (x + 1.f);
|
||||
if (x < -1.f) return -1.f + 1.f / (-x + 1.f);
|
||||
return x;
|
||||
}
|
||||
|
||||
/** A power-of-two circular buffer with fractional (linear-interpolated) reads. */
|
||||
class DelayLine {
|
||||
std::vector<float> buf;
|
||||
int mask;
|
||||
int w = 0;
|
||||
|
||||
public:
|
||||
explicit DelayLine(int size) {
|
||||
int p = 1;
|
||||
while (p < size) p *= 2;
|
||||
buf.assign((size_t)p, 0.f);
|
||||
mask = p - 1;
|
||||
}
|
||||
float maxDelay() const { return (float)(mask - 2); }
|
||||
void write(float x) { buf[(size_t)w] = x; w = (w + 1) & mask; }
|
||||
float read(float delay) const {
|
||||
float d = kt::coerceIn(delay, 1.f, (float)mask - 1.f);
|
||||
float rp = (float)w - d;
|
||||
float i0f = floorf_(rp);
|
||||
float frac = rp - i0f;
|
||||
int i0 = kt::toInt(i0f) & mask;
|
||||
int i1 = (i0 + 1) & mask;
|
||||
return buf[(size_t)i0] * (1.f - frac) + buf[(size_t)i1] * frac;
|
||||
}
|
||||
};
|
||||
|
||||
class AmbienceReverb final : public Effect {
|
||||
float fs;
|
||||
|
||||
DelayLine preDelay;
|
||||
DelayLine erLine;
|
||||
std::vector<DelayLine> diffusers;
|
||||
std::vector<DelayLine> fdn;
|
||||
std::vector<DelayLine> apf;
|
||||
|
||||
float fbVec[N] = {};
|
||||
float fbScratch[N] = {};
|
||||
float nextFb[N] = {};
|
||||
float baseDelay[N] = {};
|
||||
float decayGain[N] = {};
|
||||
float hfState[N] = {};
|
||||
float lfState[N] = {};
|
||||
float freqMod[N];
|
||||
float apfBase[N];
|
||||
float diffuserSmp[4];
|
||||
|
||||
int32_t lfoState[N];
|
||||
float lfoSmooth[N] = {};
|
||||
float lfoCoeff[N] = {};
|
||||
float lfoRateMul[N];
|
||||
|
||||
float hfCoeff = 1.f;
|
||||
float lfCoeff = 0.f;
|
||||
float lfAmt = 0.f;
|
||||
float apfGain = 0.5f;
|
||||
float diffusionSens = 1.f;
|
||||
bool bypassER = false;
|
||||
float makeup = 1.f;
|
||||
float satMul = 1.f;
|
||||
float modDepthScale = 1.f;
|
||||
int erCount = 0;
|
||||
float erDelaySmp[MAX_ER] = {};
|
||||
float erGain[MAX_ER] = {};
|
||||
|
||||
float wetLin = 0.63f;
|
||||
float dryLin = 1.f;
|
||||
float preDelaySmp = 480.f;
|
||||
float modDepth = 0.f;
|
||||
float diffGain = 0.63f;
|
||||
float effApfGain = 0.4f;
|
||||
float satAmt = 0.f;
|
||||
float erLevel = 0.6f;
|
||||
float duckAmtDb = 0.f;
|
||||
float duckThreshDb = -20.f;
|
||||
float duckThreshLin = 0.1f;
|
||||
float duckAtt = 0.01f;
|
||||
float duckRel = 0.001f;
|
||||
float duckEnv = 0.f;
|
||||
|
||||
float dc1 = 0.f;
|
||||
float dcY = 0.f;
|
||||
|
||||
int lastAlgo = -1;
|
||||
float lastSize = NAN;
|
||||
float lastDecay = NAN;
|
||||
float lastHf = NAN;
|
||||
float lastLf = NAN;
|
||||
float lastDiffusion = NAN;
|
||||
|
||||
void recompute(int algo, float size, float decay, float hf, float lf, float diffusion) {
|
||||
(void)diffusion;
|
||||
switch (algo) {
|
||||
case 0: case 1: apfGain = 0.3f; diffusionSens = 1.f; bypassER = false; break;
|
||||
case 2: case 3: apfGain = 0.618f; diffusionSens = 1.f; bypassER = false; break;
|
||||
case 4: apfGain = 0.7f; diffusionSens = 0.7f; bypassER = true; break;
|
||||
case 5: apfGain = 0.5f; diffusionSens = 0.5f; bypassER = true; break;
|
||||
default: apfGain = 0.75f; diffusionSens = 0.8f; bypassER = true; break;
|
||||
}
|
||||
|
||||
float sizeCoeff = kt::coerceIn(size + 0.5f, 0.5f, 2.f);
|
||||
float minMs = 15.f + sizeCoeff * 7.5f;
|
||||
float maxMs = 50.f + sizeCoeff * 75.f;
|
||||
int minS = std::max(11, kt::toInt(minMs * 0.001f * fs));
|
||||
int maxS = kt::coerceAtLeast(kt::toInt(maxMs * 0.001f * fs), minS + 1);
|
||||
float logMin = lnf_((float)minS);
|
||||
float logMax = lnf_((float)maxS);
|
||||
int used[N] = {};
|
||||
for (int i = 0; i < N; ++i) {
|
||||
float t = (float)i / ((float)N - 1.f);
|
||||
int target = kt::toInt(kt::expf_(logMin + t * (logMax - logMin)));
|
||||
int p = nearestUniquePrime(target, used, i);
|
||||
used[i] = p;
|
||||
baseDelay[i] = kt::coerceAtMost((float)p, fdn[(size_t)i].maxDelay());
|
||||
}
|
||||
|
||||
for (int i = 0; i < N; ++i) {
|
||||
float tSec = baseDelay[i] / fs;
|
||||
decayGain[i] = kt::coerceIn(pow10(-3.f * tSec / decay), 0.f, 0.9995f);
|
||||
}
|
||||
|
||||
float totalHf = kt::coerceIn(hf + ALGO_HF[algo], 0.f, 0.95f);
|
||||
float hfCut = 16000.f * (1.f - totalHf) + 700.f * totalHf;
|
||||
hfCoeff = kt::coerceIn(1.f - kt::expf_(-TWO_PI * hfCut / fs), 0.02f, 1.f);
|
||||
lfCoeff = kt::coerceIn(1.f - kt::expf_(-TWO_PI * 200.f / fs), 0.f, 1.f);
|
||||
lfAmt = lf * 0.9f;
|
||||
|
||||
modDepthScale = 1.f + kt::coerceIn((decay - 1.f) * 0.5f, 0.f, 2.f);
|
||||
|
||||
float decayCompDb = 7.f * kt::log10f_(kt::coerceAtLeast(decay, 0.1f));
|
||||
makeup = db2lin(16.f + decayCompDb + ALGO_OFFSET_DB[algo]);
|
||||
satMul = ALGO_SAT_MUL[algo];
|
||||
|
||||
const float *pattern = ER_PATTERNS[algo];
|
||||
erCount = bypassER ? 0 : std::min(ER_PATTERN_SIZE[algo] / 2, MAX_ER_ACTIVE);
|
||||
float erSizeScale = 0.5f + size;
|
||||
for (int t = 0; t < erCount; ++t) {
|
||||
erDelaySmp[t] = kt::coerceIn(pattern[t * 2] * 0.001f * fs * erSizeScale, 1.f, erLine.maxDelay());
|
||||
erGain[t] = pattern[t * 2 + 1];
|
||||
}
|
||||
}
|
||||
|
||||
float nextLfo(int i) {
|
||||
uint32_t s = (uint32_t)lfoState[i];
|
||||
s = s ^ (s << 13); s = s ^ (s >> 17); s = s ^ (s << 5);
|
||||
lfoState[i] = (int32_t)s;
|
||||
float n = (float)s * 2.3283064e-10f * 2.f - 1.f;
|
||||
lfoSmooth[i] += (n - lfoSmooth[i]) * lfoCoeff[i];
|
||||
return lfoSmooth[i];
|
||||
}
|
||||
|
||||
public:
|
||||
explicit AmbienceReverb(int sampleRate)
|
||||
: fs((float)sampleRate),
|
||||
preDelay(kt::toInt(fs * 0.55f)),
|
||||
erLine(kt::toInt(fs * 0.6f)) {
|
||||
diffusers.reserve(4);
|
||||
for (int i = 0; i < 4; ++i) diffusers.emplace_back(kt::toInt(fs * 0.03f));
|
||||
fdn.reserve(N);
|
||||
apf.reserve(N);
|
||||
for (int i = 0; i < N; ++i) fdn.emplace_back(kt::toInt(fs * 0.3f));
|
||||
for (int i = 0; i < N; ++i) apf.emplace_back(kt::toInt(fs * 0.03f));
|
||||
for (int it = 0; it < N; ++it) {
|
||||
freqMod[it] = 0.5f + (1.f - (float)it / ((float)N - 1.f));
|
||||
apfBase[it] = (2.3f + (float)it * 0.37f) * 0.001f * fs;
|
||||
lfoState[it] = 12345 + it * 9876;
|
||||
float a = (float)it * PHI;
|
||||
lfoRateMul[it] = 0.8f + (a - floorf_(a)) * 0.4f;
|
||||
}
|
||||
for (int it = 0; it < 4; ++it) diffuserSmp[it] = (3.f + (float)it * 2.f) * 0.001f * fs;
|
||||
}
|
||||
|
||||
void update(const Params &p, float) override {
|
||||
const char *algoName = p.s("algo", "Room 1");
|
||||
int algo = -1;
|
||||
for (int k = 0; k < 7; ++k) if (std::strcmp(ALGORITHMS[k], algoName) == 0) { algo = k; break; }
|
||||
algo = kt::coerceIn(algo, 0, 6);
|
||||
float size = kt::coerceIn(p.f("roomsize", 1.f), 0.3f, 2.f);
|
||||
float decay = kt::coerceIn(p.f("decay", 1.5f), 0.1f, 20.f);
|
||||
float hf = kt::coerceIn(p.f("hfdamp", 0.f), 0.f, 1.f);
|
||||
float lf = kt::coerceIn(p.f("lfabsorb", 0.f), 0.f, 1.f);
|
||||
float diffusion = kt::coerceIn(p.f("diffusion", 0.7f), 0.f, 1.f);
|
||||
|
||||
wetLin = db2lin(p.f("wet", -4.f));
|
||||
dryLin = db2lin(p.f("dry", 0.f));
|
||||
preDelaySmp = kt::coerceIn(p.f("predelay", 10.f), 0.f, 500.f) * 0.001f * fs;
|
||||
erLevel = kt::coerceIn(p.f("erlevel", 0.6f), 0.f, 1.f);
|
||||
satAmt = kt::coerceIn(p.f("saturation", 0.f), 0.f, 1.f);
|
||||
float modAmt = kt::coerceIn(p.f("modamt", 0.25f), 0.f, 1.f);
|
||||
float modRate = kt::coerceIn(p.f("modrate", 0.5f), 0.05f, 2.f);
|
||||
// Uses the modDepthScale from the previous recompute (as the Kotlin does).
|
||||
modDepth = modAmt * modAmt * 0.001f * fs * modDepthScale;
|
||||
for (int i = 0; i < N; ++i) {
|
||||
lfoCoeff[i] = kt::coerceIn(1.f - kt::expf_(-TWO_PI * modRate * lfoRateMul[i] / fs), 0.0001f, 0.9999f);
|
||||
}
|
||||
duckAmtDb = kt::coerceIn(p.f("duckamt", 0.f), 0.f, 20.f);
|
||||
duckThreshDb = p.f("duckthresh", -20.f);
|
||||
duckThreshLin = db2lin(duckThreshDb);
|
||||
duckAtt = 1.f - kt::expf_(-1.f / (fs * kt::coerceAtLeast(p.f("duckattack", 10.f), 0.1f) * 0.001f));
|
||||
duckRel = 1.f - kt::expf_(-1.f / (fs * kt::coerceAtLeast(p.f("duckrelease", 200.f), 0.1f) * 0.001f));
|
||||
float effDiff = diffusion * diffusionSens;
|
||||
diffGain = 0.25f + effDiff * 0.55f;
|
||||
effApfGain = apfGain * (0.6f + effDiff * 0.4f) * 0.78f;
|
||||
|
||||
if (algo != lastAlgo || size != lastSize || decay != lastDecay ||
|
||||
hf != lastHf || lf != lastLf || diffusion != lastDiffusion) {
|
||||
lastAlgo = algo; lastSize = size; lastDecay = decay;
|
||||
lastHf = hf; lastLf = lf; lastDiffusion = diffusion;
|
||||
recompute(algo, size, decay, hf, lf, diffusion);
|
||||
float d2 = diffusion * diffusionSens;
|
||||
diffGain = 0.25f + d2 * 0.55f;
|
||||
effApfGain = apfGain * (0.6f + d2 * 0.4f) * 0.78f;
|
||||
}
|
||||
}
|
||||
|
||||
float process(float x) override {
|
||||
preDelay.write(x);
|
||||
float din = preDelaySmp > 0.5f ? preDelay.read(preDelaySmp) : x;
|
||||
|
||||
float peak = std::fabs(x);
|
||||
duckEnv += (peak - duckEnv) * (peak > duckEnv ? duckAtt : duckRel);
|
||||
float duckGain = 1.f;
|
||||
if (duckAmtDb > 0.001f && duckEnv > duckThreshLin) {
|
||||
float overDb = 20.f * kt::log10f_(std::max(duckEnv, 1e-6f)) - duckThreshDb;
|
||||
duckGain = db2lin(-std::min(overDb, duckAmtDb));
|
||||
}
|
||||
|
||||
float fdnIn = din;
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
float d = diffusers[(size_t)i].read(diffuserSmp[i]);
|
||||
float w = fdnIn + diffGain * d;
|
||||
diffusers[(size_t)i].write(w);
|
||||
fdnIn = d - diffGain * w;
|
||||
}
|
||||
|
||||
float er = 0.f;
|
||||
if (!bypassER) {
|
||||
erLine.write(din);
|
||||
for (int t = 0; t < erCount; ++t) er += erLine.read(erDelaySmp[t]) * erGain[t] * 0.5f;
|
||||
fdnIn += er * 0.15f;
|
||||
}
|
||||
|
||||
std::memcpy(fbScratch, fbVec, sizeof(fbScratch));
|
||||
fwht(fbScratch);
|
||||
for (int i = 0; i < N; ++i) fbScratch[i] *= SIGN_FLIP[i];
|
||||
|
||||
float inPerCh = fdnIn * 0.25f;
|
||||
float out = 0.f;
|
||||
for (int i = 0; i < N; ++i) {
|
||||
float lfo = nextLfo(i);
|
||||
DelayLine &line = fdn[(size_t)i];
|
||||
float d = line.read(baseDelay[i] + lfo * modDepth * freqMod[i]);
|
||||
d *= decayGain[i];
|
||||
hfState[i] += hfCoeff * (d - hfState[i]); d = hfState[i];
|
||||
lfState[i] += lfCoeff * (d - lfState[i]); d -= lfAmt * lfState[i];
|
||||
DelayLine &ap = apf[(size_t)i];
|
||||
float ad = ap.read(apfBase[i] + lfo * modDepth * 0.1f * freqMod[i]);
|
||||
float aw = d + effApfGain * ad;
|
||||
ap.write(aw);
|
||||
float apfOut = ad - effApfGain * aw;
|
||||
|
||||
nextFb[i] = apfOut;
|
||||
line.write(inPerCh + fbScratch[i]);
|
||||
out += apfOut;
|
||||
}
|
||||
std::memcpy(fbVec, nextFb, sizeof(fbVec));
|
||||
|
||||
float late = out * LATE_SCALE * makeup;
|
||||
float amt = kt::coerceIn(satAmt * satMul, 0.f, 1.f);
|
||||
if (amt > 0.0001f) late += amt * (kt::tanhf_(late * 2.f) * 0.5f - late);
|
||||
|
||||
float wetRaw = (bypassER ? 0.f : er * erLevel) + late;
|
||||
float dcOut = wetRaw - dc1 + 0.999f * dcY;
|
||||
dc1 = wetRaw; dcY = dcOut;
|
||||
|
||||
float wet = softClip(dcOut * wetLin * duckGain);
|
||||
return x * dryLin + wet;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<Effect> makeAmbienceReverb(int sampleRate) {
|
||||
return std::make_unique<AmbienceReverb>(sampleRate);
|
||||
}
|
||||
|
||||
} // namespace sizzle
|
||||
@@ -0,0 +1,42 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// Port of Bitcrusher (Effects.kt): bit-depth reduction + sample-rate reduction + drive.
|
||||
|
||||
#include "sizzle/Effect.hpp"
|
||||
#include "KotlinMath.hpp"
|
||||
|
||||
namespace sizzle {
|
||||
namespace {
|
||||
|
||||
class Bitcrusher final : public Effect {
|
||||
float levels = 256.f;
|
||||
int downsample = 1;
|
||||
float drive = 1.f;
|
||||
int counter = 0;
|
||||
float held = 0.f;
|
||||
|
||||
public:
|
||||
void update(const Params &p, float) override {
|
||||
float bits = kt::coerceIn(p.f("bits", 8.f), 1.f, 16.f);
|
||||
levels = kt::powf_(2.f, bits);
|
||||
downsample = kt::coerceAtLeast(kt::toInt(p.f("downsample", 1.f)), 1);
|
||||
drive = 1.f + p.f("drive", 0.2f) * 4.f;
|
||||
}
|
||||
|
||||
float process(float x) override {
|
||||
if (counter <= 0) {
|
||||
counter = downsample;
|
||||
float driven = kt::tanhf_(x * drive);
|
||||
held = (float)kt::roundToInt(driven * levels) / levels;
|
||||
}
|
||||
counter--;
|
||||
return held;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<Effect> makeBitcrusher(int) { return std::make_unique<Bitcrusher>(); }
|
||||
|
||||
} // namespace sizzle
|
||||
@@ -0,0 +1,111 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// Port of BiquadFilterEffect (Effects.kt): RBJ LP/HP/BP biquad whose cutoff an
|
||||
// input-level-gated ADSR opens, plus soft-saturation "warmth".
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include "sizzle/Effect.hpp"
|
||||
#include "KotlinMath.hpp"
|
||||
|
||||
namespace sizzle {
|
||||
namespace {
|
||||
|
||||
constexpr int CTRL_INTERVAL = 32;
|
||||
constexpr float GATE_HI = 0.010f;
|
||||
constexpr float GATE_LO = 0.004f;
|
||||
|
||||
class Filter final : public Effect {
|
||||
double b0 = 1, b1 = 0, b2 = 0, a1 = 0, a2 = 0, z1 = 0, z2 = 0;
|
||||
int sampleRate;
|
||||
float sr;
|
||||
enum Type { LPF, HPF, BPF } type = LPF;
|
||||
float baseCutoff = 0.7f;
|
||||
double q = 1.0;
|
||||
float warmth = 0.f, envAmount = 0.f;
|
||||
enum Phase { IDLE, ATTACK, DECAY, SUSTAIN, RELEASE } phase = IDLE;
|
||||
float env = 0.f, attackInc = 1.f, decayInc = 1.f, sustainLevel = 1.f;
|
||||
float releaseSeconds = 0.2f, releaseInc = 1.f, levelEnv = 0.f, levelCoeff = 0.f;
|
||||
bool gateOpen = false;
|
||||
int ctrl = 0;
|
||||
|
||||
void computeCoefficients(Type t, double freq, double qq) {
|
||||
double w0 = 2.0 * M_PI * freq / sampleRate;
|
||||
double cosW = std::cos(w0);
|
||||
double alpha = std::sin(w0) / (2.0 * qq);
|
||||
double a0;
|
||||
switch (t) {
|
||||
case HPF:
|
||||
b0 = (1 + cosW) / 2; b1 = -(1 + cosW); b2 = (1 + cosW) / 2;
|
||||
a0 = 1 + alpha; a1 = -2 * cosW; a2 = 1 - alpha; break;
|
||||
case BPF:
|
||||
b0 = alpha; b1 = 0.0; b2 = -alpha;
|
||||
a0 = 1 + alpha; a1 = -2 * cosW; a2 = 1 - alpha; break;
|
||||
default:
|
||||
b0 = (1 - cosW) / 2; b1 = 1 - cosW; b2 = (1 - cosW) / 2;
|
||||
a0 = 1 + alpha; a1 = -2 * cosW; a2 = 1 - alpha; break;
|
||||
}
|
||||
b0 /= a0; b1 /= a0; b2 /= a0; a1 /= a0; a2 /= a0;
|
||||
}
|
||||
|
||||
public:
|
||||
explicit Filter(int rate) : sampleRate(rate), sr((float)rate) {}
|
||||
|
||||
void update(const Params &p, float) override {
|
||||
const char *t = p.s("type", "LPF");
|
||||
type = std::strcmp(t, "HPF") == 0 ? HPF : std::strcmp(t, "BPF") == 0 ? BPF : LPF;
|
||||
baseCutoff = kt::coerceIn(p.f("cutoff", 0.7f), 0.f, 1.f);
|
||||
q = (double)(0.5 + p.f("resonance", 0.2f) * 8.f);
|
||||
warmth = kt::coerceIn(p.f("warmth", 0.f), 0.f, 1.f);
|
||||
envAmount = kt::coerceIn(p.f("envamt", 0.f), 0.f, 1.f);
|
||||
sustainLevel = kt::coerceIn(p.f("sustain", 1.f), 0.f, 1.f);
|
||||
attackInc = 1.f / (std::max(p.f("attack", 0.005f), 0.0005f) * sr);
|
||||
float decay = p.f("decay", 0.10f);
|
||||
decayInc = decay <= 0.f ? 1.f : (1.f - sustainLevel) / (decay * sr);
|
||||
releaseSeconds = p.f("release", 0.20f);
|
||||
levelCoeff = 1.f - kt::expf_(-1.f / (sr * 0.005f));
|
||||
ctrl = 0;
|
||||
}
|
||||
|
||||
float process(float x) override {
|
||||
levelEnv += (std::fabs(x) - levelEnv) * levelCoeff;
|
||||
if (!gateOpen && levelEnv > GATE_HI) {
|
||||
gateOpen = true; phase = ATTACK;
|
||||
} else if (gateOpen && levelEnv < GATE_LO) {
|
||||
gateOpen = false;
|
||||
releaseInc = releaseSeconds <= 0.f ? 1.f : env / (releaseSeconds * sr);
|
||||
if (releaseInc <= 0.f) releaseInc = 1.f;
|
||||
phase = RELEASE;
|
||||
}
|
||||
switch (phase) {
|
||||
case ATTACK: env += attackInc; if (env >= 1.f) { env = 1.f; phase = DECAY; } break;
|
||||
case DECAY: env -= decayInc; if (env <= sustainLevel) { env = sustainLevel; phase = SUSTAIN; } break;
|
||||
case RELEASE: env -= releaseInc; if (env <= 0.f) { env = 0.f; phase = IDLE; } break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
if (ctrl <= 0) {
|
||||
ctrl = CTRL_INTERVAL;
|
||||
float eff = kt::coerceIn(baseCutoff + envAmount * env * (1.f - baseCutoff), 0.f, 1.f);
|
||||
double freq = 20.0 * std::pow(900.0, (double)eff);
|
||||
computeCoefficients(type, kt::coerceIn(freq, 20.0, sampleRate * 0.45), q);
|
||||
}
|
||||
ctrl--;
|
||||
|
||||
double input = (double)x;
|
||||
double out = b0 * input + z1;
|
||||
z1 = b1 * input - a1 * out + z2;
|
||||
z2 = b2 * input - a2 * out;
|
||||
float y = (float)out;
|
||||
if (warmth > 0.0001f) y += warmth * (kt::tanhf_(y * 1.8f) / 1.8f - y);
|
||||
return y;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<Effect> makeFilter(int sr) { return std::make_unique<Filter>(sr); }
|
||||
|
||||
} // namespace sizzle
|
||||
@@ -0,0 +1,129 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// Port of GranularGlitch (Effects.kt): a rolling 1 s buffer whose read head randomly
|
||||
// jumps back to replay short (sometimes octave-shifted) grains, dry in between. Also
|
||||
// its VizEffect side: a decimated scope of the incoming signal and the read head's
|
||||
// place in that window, written here with relaxed atomics (plain stores on arm64 and
|
||||
// x86) and read by the editor from the UI thread. It never feeds back into the audio.
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include "sizzle/Effect.hpp"
|
||||
#include "KotlinMath.hpp"
|
||||
|
||||
namespace sizzle {
|
||||
namespace {
|
||||
|
||||
constexpr float MAX_TRIGGER = 0.0009f;
|
||||
constexpr float MIN_JUMP_S = 0.03f;
|
||||
constexpr float MAX_JUMP_S = 0.5f;
|
||||
constexpr float GRAIN_MIN_S = 0.02f;
|
||||
constexpr float GRAIN_MAX_S = 0.15f;
|
||||
constexpr int SCOPE_N = 96; // scope points drawn
|
||||
constexpr int SCOPE_DECIM = 96; // input samples per point (~192 ms window at 48 kHz)
|
||||
|
||||
class GranularGlitch final : public Effect {
|
||||
int sampleRate;
|
||||
std::vector<float> buf;
|
||||
int size;
|
||||
int writePos = 0;
|
||||
double readPos = 0.0;
|
||||
int grainLeft = 0;
|
||||
double grainRate = 1.0;
|
||||
float intensity = 0.f;
|
||||
uint32_t rng = 0x2F6E1DB7u;
|
||||
|
||||
// Visualisation: a ring of decimated INPUT samples plus the normalised read head.
|
||||
std::atomic<float> scope[SCOPE_N];
|
||||
std::atomic<int> scopeWrite{0};
|
||||
int decCount = 0;
|
||||
std::atomic<float> playheadNorm{1.f};
|
||||
|
||||
float nextUnit() {
|
||||
uint32_t s = rng; s ^= s << 13; s ^= s >> 17; s ^= s << 5; rng = s;
|
||||
return (float)s * 2.3283064e-10f; // 0 … 1
|
||||
}
|
||||
|
||||
bool maybeStartGrain(int wp) {
|
||||
if (nextUnit() > intensity * intensity * MAX_TRIGGER) return false;
|
||||
float minJ = MIN_JUMP_S * (float)sampleRate;
|
||||
float maxJ = (MIN_JUMP_S + intensity * (MAX_JUMP_S - MIN_JUMP_S)) * (float)sampleRate;
|
||||
float jump = minJ + nextUnit() * (maxJ - minJ);
|
||||
double rp = (double)wp - (double)jump;
|
||||
while (rp < 0) rp += size;
|
||||
readPos = rp;
|
||||
float lenSec = GRAIN_MAX_S - intensity * (GRAIN_MAX_S - GRAIN_MIN_S);
|
||||
grainLeft = kt::coerceAtLeast(kt::toInt(lenSec * (float)sampleRate * (0.5f + nextUnit())), 64);
|
||||
if (nextUnit() < intensity * 0.3f) grainRate = 2.0;
|
||||
else if (nextUnit() < intensity * 0.2f) grainRate = 0.5;
|
||||
else grainRate = 1.0;
|
||||
return true;
|
||||
}
|
||||
|
||||
public:
|
||||
explicit GranularGlitch(int rate) : sampleRate(rate), buf((size_t)rate, 0.f), size(rate) {
|
||||
for (auto &v : scope) v.store(0.f, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
void update(const Params &p, float) override {
|
||||
intensity = kt::coerceIn(p.f("intensity", 0.3f), 0.f, 1.f);
|
||||
}
|
||||
|
||||
float process(float x) override {
|
||||
int wp = writePos;
|
||||
buf[wp] = x;
|
||||
writePos++; if (writePos >= size) writePos = 0;
|
||||
|
||||
float out;
|
||||
if (grainLeft <= 0 && (intensity < 0.001f || !maybeStartGrain(wp))) {
|
||||
readPos = (double)wp;
|
||||
out = x;
|
||||
} else {
|
||||
int i0 = (int)readPos % size;
|
||||
int i1 = (i0 + 1) % size;
|
||||
float frac = (float)(readPos - (int)readPos);
|
||||
out = buf[i0] + (buf[i1] - buf[i0]) * frac;
|
||||
double rp = readPos + grainRate;
|
||||
if (rp >= size) rp -= size;
|
||||
if (rp < 0) rp += size;
|
||||
double gap = wp - rp; if (gap < 0) gap += size;
|
||||
if (gap < 2.0) { rp = wp - 2.0; if (rp < 0) rp += size; }
|
||||
readPos = rp;
|
||||
grainLeft--;
|
||||
}
|
||||
|
||||
// Scope: decimate the incoming signal into the ring.
|
||||
if (++decCount >= SCOPE_DECIM) {
|
||||
decCount = 0;
|
||||
int sw = scopeWrite.load(std::memory_order_relaxed);
|
||||
scope[sw].store(x, std::memory_order_relaxed);
|
||||
sw++; if (sw >= SCOPE_N) sw = 0;
|
||||
scopeWrite.store(sw, std::memory_order_relaxed);
|
||||
}
|
||||
// Playhead: where the read head sits within the displayed window (0 oldest … 1 now).
|
||||
double behind = wp - readPos; if (behind < 0) behind += size;
|
||||
playheadNorm.store(kt::coerceIn(1.f - (float)behind / (float)(SCOPE_N * SCOPE_DECIM), 0.f, 1.f),
|
||||
std::memory_order_relaxed);
|
||||
return out;
|
||||
}
|
||||
|
||||
bool hasScope() const override { return true; }
|
||||
|
||||
int copyScope(float *out, int capacity) const override {
|
||||
int n = capacity < SCOPE_N ? capacity : SCOPE_N;
|
||||
if (n < 0) n = 0;
|
||||
int start = scopeWrite.load(std::memory_order_relaxed); // oldest sample in the ring
|
||||
for (int k = 0; k < n; ++k) out[k] = scope[(start + k) % SCOPE_N].load(std::memory_order_relaxed);
|
||||
return n;
|
||||
}
|
||||
|
||||
float playhead() const override { return playheadNorm.load(std::memory_order_relaxed); }
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<Effect> makeGranularGlitch(int sr) { return std::make_unique<GranularGlitch>(sr); }
|
||||
|
||||
} // namespace sizzle
|
||||
@@ -0,0 +1,67 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// Port of GraphicEq (Effects.kt): ten peaking biquads at octave-spaced centres.
|
||||
|
||||
#include <cmath>
|
||||
#include "sizzle/Effect.hpp"
|
||||
#include "KotlinMath.hpp"
|
||||
|
||||
namespace sizzle {
|
||||
namespace {
|
||||
|
||||
struct PeakBiquad {
|
||||
double b0 = 1, b1 = 0, b2 = 0, a1 = 0, a2 = 0, z1 = 0, z2 = 0;
|
||||
|
||||
void set(int sampleRate, float freq, float gainDb) {
|
||||
if (freq >= sampleRate * 0.45f) return;
|
||||
double a = std::pow(10.0, gainDb / 40.0);
|
||||
double w0 = 2.0 * M_PI * freq / sampleRate;
|
||||
double cosW = std::cos(w0);
|
||||
double alpha = std::sin(w0) / (2.0 * 1.0);
|
||||
double a0 = 1 + alpha / a;
|
||||
b0 = (1 + alpha * a) / a0;
|
||||
b1 = (-2 * cosW) / a0;
|
||||
b2 = (1 - alpha * a) / a0;
|
||||
a1 = (-2 * cosW) / a0;
|
||||
a2 = (1 - alpha / a) / a0;
|
||||
}
|
||||
|
||||
float process(float x) {
|
||||
double input = (double)x;
|
||||
double out = b0 * input + z1;
|
||||
z1 = b1 * input - a1 * out + z2;
|
||||
z2 = b2 * input - a2 * out;
|
||||
return (float)out;
|
||||
}
|
||||
};
|
||||
|
||||
class GraphicEq final : public Effect {
|
||||
static constexpr float centers[10] = {31.f, 63.f, 125.f, 250.f, 500.f, 1000.f, 2000.f, 4000.f, 8000.f, 16000.f};
|
||||
static constexpr const char *keys[10] = {"band0", "band1", "band2", "band3", "band4",
|
||||
"band5", "band6", "band7", "band8", "band9"};
|
||||
PeakBiquad bands[10];
|
||||
int sampleRate;
|
||||
|
||||
public:
|
||||
explicit GraphicEq(int sr) : sampleRate(sr) {}
|
||||
|
||||
void update(const Params &p, float) override {
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
float gainDb = kt::coerceIn(p.f(keys[i], 0.f), -1.f, 1.f) * 12.f;
|
||||
bands[i].set(sampleRate, centers[i], gainDb);
|
||||
}
|
||||
}
|
||||
|
||||
float process(float x) override {
|
||||
float y = x;
|
||||
for (auto &b : bands) y = b.process(y);
|
||||
return y;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<Effect> makeGraphicEq(int sr) { return std::make_unique<GraphicEq>(sr); }
|
||||
|
||||
} // namespace sizzle
|
||||
@@ -0,0 +1,34 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
|
||||
// Kotlin/JVM math semantics, so ports read like the Kotlin and match its output.
|
||||
// kotlin.math on Float goes through Java's double Math and rounds back to float.
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace sizzle::kt {
|
||||
|
||||
inline float tanhf_(float x) { return (float)std::tanh((double)x); }
|
||||
inline float expf_(float x) { return (float)std::exp((double)x); }
|
||||
inline float sinf_(float x) { return (float)std::sin((double)x); }
|
||||
inline float cosf_(float x) { return (float)std::cos((double)x); }
|
||||
inline float powf_(float a, float b) { return (float)std::pow((double)a, (double)b); }
|
||||
inline float sqrtf_(float x) { return (float)std::sqrt((double)x); }
|
||||
inline float log10f_(float x) { return (float)std::log10((double)x); }
|
||||
|
||||
/** Float.roundToInt(): Math.round, i.e. floor(x + 0.5). */
|
||||
inline int roundToInt(float x) { return (int)std::floor((double)x + 0.5); }
|
||||
inline int roundToInt(double x) { return (int)std::floor(x + 0.5); }
|
||||
/** Float.toInt(): truncation toward zero, NaN → 0, saturating. */
|
||||
inline int toInt(float x) {
|
||||
if (std::isnan(x)) return 0;
|
||||
if (x >= 2147483647.f) return 2147483647;
|
||||
if (x <= -2147483648.f) return (-2147483647 - 1);
|
||||
return (int)x;
|
||||
}
|
||||
template <class T> inline T coerceIn(T v, T lo, T hi) { return v < lo ? lo : (v > hi ? hi : v); }
|
||||
template <class T> inline T coerceAtLeast(T v, T lo) { return v < lo ? lo : v; }
|
||||
template <class T> inline T coerceAtMost(T v, T hi) { return v > hi ? hi : v; }
|
||||
|
||||
} // namespace sizzle::kt
|
||||
@@ -0,0 +1,190 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// Port of MixTightener (Effects.kt): parametric EQ -> 3-band multiband compressor ->
|
||||
// peak limiter, morphed by one Strength control; per-band values are hidden params
|
||||
// set by presets. Includes the private Bq biquad (TDF-II, double state).
|
||||
|
||||
#include <cmath>
|
||||
#include "sizzle/Effect.hpp"
|
||||
#include "KotlinMath.hpp"
|
||||
|
||||
namespace sizzle {
|
||||
namespace {
|
||||
|
||||
class Bq {
|
||||
double b0 = 1.0, b1 = 0.0, b2 = 0.0;
|
||||
double a1 = 0.0, a2 = 0.0;
|
||||
double z1 = 0.0, z2 = 0.0;
|
||||
|
||||
void setRaw(double nb0, double nb1, double nb2, double a0, double na1, double na2) {
|
||||
b0 = nb0 / a0; b1 = nb1 / a0; b2 = nb2 / a0; a1 = na1 / a0; a2 = na2 / a0;
|
||||
}
|
||||
|
||||
public:
|
||||
void identity() { b0 = 1.0; b1 = 0.0; b2 = 0.0; a1 = 0.0; a2 = 0.0; }
|
||||
|
||||
void peak(int sr, float freq, float gainDb, float q) {
|
||||
float f = kt::coerceIn(freq, 20.f, sr * 0.45f);
|
||||
double a = std::pow(10.0, gainDb / 40.0);
|
||||
double w0 = 2.0 * M_PI * f / sr; double cw = std::cos(w0);
|
||||
double alpha = std::sin(w0) / (2.0 * kt::coerceAtLeast(q, 0.1f));
|
||||
setRaw(1 + alpha * a, -2 * cw, 1 - alpha * a, 1 + alpha / a, -2 * cw, 1 - alpha / a);
|
||||
}
|
||||
|
||||
void lowShelf(int sr, float freq, float gainDb) {
|
||||
float f = kt::coerceIn(freq, 20.f, sr * 0.45f);
|
||||
double a = std::pow(10.0, gainDb / 40.0); double w0 = 2.0 * M_PI * f / sr; double cw = std::cos(w0);
|
||||
double alpha = std::sin(w0) / 2.0 * std::sqrt(2.0); double ta = 2.0 * std::sqrt(a) * alpha;
|
||||
setRaw(
|
||||
a * ((a + 1) - (a - 1) * cw + ta), 2 * a * ((a - 1) - (a + 1) * cw),
|
||||
a * ((a + 1) - (a - 1) * cw - ta), (a + 1) + (a - 1) * cw + ta,
|
||||
-2 * ((a - 1) + (a + 1) * cw), (a + 1) + (a - 1) * cw - ta);
|
||||
}
|
||||
|
||||
void highShelf(int sr, float freq, float gainDb) {
|
||||
float f = kt::coerceIn(freq, 20.f, sr * 0.45f);
|
||||
double a = std::pow(10.0, gainDb / 40.0); double w0 = 2.0 * M_PI * f / sr; double cw = std::cos(w0);
|
||||
double alpha = std::sin(w0) / 2.0 * std::sqrt(2.0); double ta = 2.0 * std::sqrt(a) * alpha;
|
||||
setRaw(
|
||||
a * ((a + 1) + (a - 1) * cw + ta), -2 * a * ((a - 1) + (a + 1) * cw),
|
||||
a * ((a + 1) + (a - 1) * cw - ta), (a + 1) - (a - 1) * cw + ta,
|
||||
2 * ((a - 1) - (a + 1) * cw), (a + 1) - (a - 1) * cw - ta);
|
||||
}
|
||||
|
||||
void lowPass(int sr, float freq, float q) {
|
||||
float f = kt::coerceIn(freq, 20.f, sr * 0.45f);
|
||||
double w0 = 2.0 * M_PI * f / sr; double cw = std::cos(w0); double alpha = std::sin(w0) / (2.0 * q);
|
||||
setRaw((1 - cw) / 2, 1 - cw, (1 - cw) / 2, 1 + alpha, -2 * cw, 1 - alpha);
|
||||
}
|
||||
|
||||
void highPass(int sr, float freq, float q) {
|
||||
float f = kt::coerceIn(freq, 20.f, sr * 0.45f);
|
||||
double w0 = 2.0 * M_PI * f / sr; double cw = std::cos(w0); double alpha = std::sin(w0) / (2.0 * q);
|
||||
setRaw((1 + cw) / 2, -(1 + cw), (1 + cw) / 2, 1 + alpha, -2 * cw, 1 - alpha);
|
||||
}
|
||||
|
||||
void reset() { z1 = 0.0; z2 = 0.0; }
|
||||
|
||||
float process(float x) {
|
||||
double inp = (double)x;
|
||||
double out = b0 * inp + z1;
|
||||
z1 = b1 * inp - a1 * out + z2;
|
||||
z2 = b2 * inp - a2 * out;
|
||||
if (!std::isfinite(out)) { z1 = 0.0; z2 = 0.0; out = 0.0; }
|
||||
return (float)out;
|
||||
}
|
||||
};
|
||||
|
||||
constexpr int CTRL = 16; // samples between (expensive) gain recomputes
|
||||
constexpr float GAIN_SMOOTH = 0.05f; // per-sample gain ramp toward the control-rate target
|
||||
|
||||
class MixTightener final : public Effect {
|
||||
int sampleRate;
|
||||
Bq eqLo, eqMid, eqHi;
|
||||
bool eqActive = false;
|
||||
Bq xLoLP, xLoHP, xHiLP, xHiHP;
|
||||
bool compActive = false;
|
||||
float env[3] = {0.f, 0.f, 0.f};
|
||||
float gain[3] = {1.f, 1.f, 1.f};
|
||||
float target[3] = {1.f, 1.f, 1.f};
|
||||
float atkCoef[3] = {}, relCoef[3] = {};
|
||||
float thrDb[3] = {}, ratio[3] = {}, makeDb[3] = {};
|
||||
int ctrl = 0;
|
||||
float limCeil = 1.f, limRelCoef = 0.f, limEnv = 0.f;
|
||||
float outGain = 1.f;
|
||||
float strength = 1.f;
|
||||
float compScale = 1.f;
|
||||
|
||||
static float dbToLin(float db) { return (float)std::pow(10.0, db / 20.0); }
|
||||
float coefFromMs(float ms) const {
|
||||
float t = kt::coerceAtLeast(ms, 0.1f) * 0.001f * sampleRate;
|
||||
return (float)(1.0 - std::exp(-1.0 / t));
|
||||
}
|
||||
|
||||
float compBand(int i, float band) {
|
||||
float r = std::fabs(band);
|
||||
float e = env[i];
|
||||
env[i] = r > e ? e + atkCoef[i] * (r - e) : e + relCoef[i] * (r - e);
|
||||
gain[i] += GAIN_SMOOTH * (target[i] - gain[i]);
|
||||
return band * gain[i];
|
||||
}
|
||||
|
||||
public:
|
||||
explicit MixTightener(int rate) : sampleRate(rate) {}
|
||||
|
||||
void update(const Params &p, float) override {
|
||||
strength = kt::coerceIn(p.f("strength", 1.f), 0.f, 1.f);
|
||||
float eqS = strength * kt::coerceIn(p.f("eqAmt", 1.f), 0.f, 1.f);
|
||||
float compAmt = kt::coerceIn(p.f("compAmt", 1.f), 0.f, 1.f);
|
||||
compScale = strength * compAmt;
|
||||
float limS = strength * kt::coerceIn(p.f("limAmt", 1.f), 0.f, 1.f);
|
||||
|
||||
float loG = kt::coerceIn(p.f("eqLoGain", 0.f), -18.f, 18.f) * eqS;
|
||||
float midG = kt::coerceIn(p.f("eqMidGain", 0.f), -18.f, 18.f) * eqS;
|
||||
float hiG = kt::coerceIn(p.f("eqHiGain", 0.f), -18.f, 18.f) * eqS;
|
||||
if (std::fabs(loG) > 0.1f) eqLo.lowShelf(sampleRate, p.f("eqLoFreq", 120.f), loG); else eqLo.identity();
|
||||
if (std::fabs(midG) > 0.1f) eqMid.peak(sampleRate, p.f("eqMidFreq", 1000.f), midG,
|
||||
kt::coerceIn(p.f("eqMidQ", 1.0f), 0.2f, 8.f)); else eqMid.identity();
|
||||
if (std::fabs(hiG) > 0.1f) eqHi.highShelf(sampleRate, p.f("eqHiFreq", 8000.f), hiG); else eqHi.identity();
|
||||
eqActive = std::fabs(loG) > 0.1f || std::fabs(midG) > 0.1f || std::fabs(hiG) > 0.1f;
|
||||
|
||||
float xl = kt::coerceIn(p.f("xLo", 200.f), 40.f, sampleRate * 0.4f);
|
||||
float xh = kt::coerceIn(p.f("xHi", 2500.f), xl + 50.f, sampleRate * 0.45f);
|
||||
xLoLP.lowPass(sampleRate, xl, 0.5f); xLoHP.highPass(sampleRate, xl, 0.5f);
|
||||
xHiLP.lowPass(sampleRate, xh, 0.5f); xHiHP.highPass(sampleRate, xh, 0.5f);
|
||||
|
||||
thrDb[0] = p.f("cLoThr", -24.f); ratio[0] = kt::coerceIn(p.f("cLoRatio", 2.f), 1.f, 20.f);
|
||||
makeDb[0] = p.f("cLoMk", 0.f); atkCoef[0] = coefFromMs(p.f("cLoAtk", 10.f)); relCoef[0] = coefFromMs(p.f("cLoRel", 120.f));
|
||||
thrDb[1] = p.f("cMidThr", -22.f); ratio[1] = kt::coerceIn(p.f("cMidRatio", 2.f), 1.f, 20.f);
|
||||
makeDb[1] = p.f("cMidMk", 0.f); atkCoef[1] = coefFromMs(p.f("cMidAtk", 15.f)); relCoef[1] = coefFromMs(p.f("cMidRel", 140.f));
|
||||
thrDb[2] = p.f("cHiThr", -24.f); ratio[2] = kt::coerceIn(p.f("cHiRatio", 2.f), 1.f, 20.f);
|
||||
makeDb[2] = p.f("cHiMk", 0.f); atkCoef[2] = coefFromMs(p.f("cHiAtk", 5.f)); relCoef[2] = coefFromMs(p.f("cHiRel", 90.f));
|
||||
bool anyRatio = false, anyMake = false;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (ratio[i] > 1.01f) anyRatio = true;
|
||||
if (std::fabs(makeDb[i]) > 0.1f) anyMake = true;
|
||||
}
|
||||
compActive = compAmt > 0.001f && (anyRatio || anyMake);
|
||||
|
||||
limCeil = 1.f + (dbToLin(kt::coerceIn(p.f("limCeil", -0.5f), -24.f, 0.f)) - 1.f) * limS;
|
||||
limRelCoef = coefFromMs(p.f("limRel", 100.f));
|
||||
outGain = 1.f + (dbToLin(kt::coerceIn(p.f("outGain", 0.f), -12.f, 18.f)) - 1.f) * limS;
|
||||
}
|
||||
|
||||
float process(float x) override {
|
||||
if (strength < 0.001f) return x;
|
||||
float s = x;
|
||||
if (eqActive) { s = eqLo.process(s); s = eqMid.process(s); s = eqHi.process(s); }
|
||||
|
||||
if (compActive) {
|
||||
float low = xLoLP.process(s);
|
||||
float hp = xLoHP.process(s);
|
||||
float mid = xHiLP.process(hp);
|
||||
float high = xHiHP.process(hp);
|
||||
if (ctrl <= 0) {
|
||||
ctrl = CTRL;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
float envDb = 20.f * kt::log10f_(env[i] + 1e-9f);
|
||||
float over = envDb - thrDb[i];
|
||||
float grDb = over > 0.f ? -over * (1.f - 1.f / ratio[i]) : 0.f;
|
||||
target[i] = dbToLin(kt::coerceIn((grDb + makeDb[i]) * compScale, -40.f, 24.f));
|
||||
}
|
||||
}
|
||||
ctrl--;
|
||||
s = compBand(0, low) + compBand(1, mid) + compBand(2, high);
|
||||
}
|
||||
|
||||
float r = std::fabs(s);
|
||||
limEnv = r > limEnv ? r : limEnv + limRelCoef * (r - limEnv);
|
||||
if (limEnv > limCeil && limEnv > 1e-6f) s *= limCeil / limEnv;
|
||||
s *= outGain;
|
||||
return s > 1.f ? 1.f : s < -1.f ? -1.f : !std::isfinite(s) ? 0.f : s;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<Effect> makeMixTightener(int sampleRate) { return std::make_unique<MixTightener>(sampleRate); }
|
||||
|
||||
} // namespace sizzle
|
||||
@@ -0,0 +1,39 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// Effect::create. Each effect lives in src/fx/<Name>.cpp and defines its maker
|
||||
// below. The defaults here are weak definitions returning nullptr; a port's own
|
||||
// (strong) definition replaces its default at link time, so a build without some
|
||||
// of those files still links (lets ports land one by one).
|
||||
|
||||
#include <cstring>
|
||||
#include "sizzle/Effect.hpp"
|
||||
|
||||
#define SIZZLE_MAKER(fn) \
|
||||
__attribute__((weak)) std::unique_ptr<Effect> fn(int) { return nullptr; }
|
||||
|
||||
namespace sizzle {
|
||||
|
||||
SIZZLE_MAKER(makeBitcrusher);
|
||||
SIZZLE_MAKER(makeFilter);
|
||||
SIZZLE_MAKER(makeGraphicEq);
|
||||
SIZZLE_MAKER(makeTapeDelay);
|
||||
SIZZLE_MAKER(makeMixTightener);
|
||||
SIZZLE_MAKER(makeTapeEngine);
|
||||
SIZZLE_MAKER(makeGranularGlitch);
|
||||
SIZZLE_MAKER(makeAmbienceReverb);
|
||||
|
||||
std::unique_ptr<Effect> Effect::create(const char *type, int sr) {
|
||||
struct Entry { const char *type; std::unique_ptr<Effect> (*make)(int); };
|
||||
const Entry table[] = {
|
||||
{"BITCRUSHER", makeBitcrusher}, {"FILTER", makeFilter},
|
||||
{"EQ10", makeGraphicEq}, {"DELAY", makeTapeDelay},
|
||||
{"MIX_TIGHTENER", makeMixTightener}, {"TAPE_ENGINE", makeTapeEngine},
|
||||
{"GRANULAR", makeGranularGlitch}, {"AMBIENCE", makeAmbienceReverb},
|
||||
};
|
||||
for (const auto &e : table)
|
||||
if (std::strcmp(type, e.type) == 0) return e.make(sr);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace sizzle
|
||||
@@ -0,0 +1,122 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// Port of TapeDelay (Effects.kt): one shared delay line read by up to four
|
||||
// tempo-synced tape heads (averaged), with saturation, a darkening one-pole LP
|
||||
// in the feedback path and sine wow/flutter, all scaled by "tape".
|
||||
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
#include "sizzle/Effect.hpp"
|
||||
#include "KotlinMath.hpp"
|
||||
|
||||
// The JVM never fuses a*b+c; keep clang from contracting into FMAs.
|
||||
#if defined(__clang__)
|
||||
#pragma STDC FP_CONTRACT OFF
|
||||
#endif
|
||||
|
||||
namespace sizzle {
|
||||
namespace {
|
||||
|
||||
// DelayDivisions (model/Toolbox.kt).
|
||||
constexpr int HEADS = 4;
|
||||
constexpr float MAX_FEEDBACK = 0.9f;
|
||||
constexpr double BEAT_FRACTIONS[] = {
|
||||
4.0, // 1/1
|
||||
3.0, // 1/2.
|
||||
2.0, // 1/2
|
||||
1.5, // 1/4.
|
||||
4.0 / 3.0, // 1/2T
|
||||
1.0, // 1/4
|
||||
0.75, // 1/8.
|
||||
2.0 / 3.0, // 1/4T
|
||||
0.5, // 1/8
|
||||
0.375, // 1/16.
|
||||
1.0 / 3.0, // 1/8T
|
||||
0.25, // 1/16
|
||||
1.0 / 6.0, // 1/16T
|
||||
};
|
||||
constexpr int DIV_COUNT = (int)(sizeof(BEAT_FRACTIONS) / sizeof(BEAT_FRACTIONS[0]));
|
||||
constexpr int DIV_DEFAULT = 5; // indexOf("1/4")
|
||||
inline double beatFraction(int i) { return BEAT_FRACTIONS[kt::coerceIn(i, 0, DIV_COUNT - 1)]; }
|
||||
|
||||
constexpr double FLUTTER_HZ = 5.0;
|
||||
const char *const HEAD_ON_KEYS[HEADS] = {"head0On", "head1On", "head2On", "head3On"};
|
||||
const char *const HEAD_DIV_KEYS[HEADS] = {"head0Div", "head1Div", "head2Div", "head3Div"};
|
||||
|
||||
class TapeDelay final : public Effect {
|
||||
int sampleRate;
|
||||
std::vector<float> buffer; // up to 4 s of delay line
|
||||
int bufferSize;
|
||||
int writeIndex = 0;
|
||||
int delaySamples[HEADS];
|
||||
bool headOn[HEADS] = {};
|
||||
float feedback = 0.4f;
|
||||
float dryWet = 0.35f;
|
||||
float satBlend = 0.f;
|
||||
float lpAlpha = 1.f;
|
||||
float lpState = 0.f;
|
||||
double flutterInc = 0.0;
|
||||
float flutterDepth = 0.f;
|
||||
double flutterPhase = 0.0;
|
||||
|
||||
public:
|
||||
explicit TapeDelay(int rate)
|
||||
: sampleRate(rate), buffer((size_t)rate * 4, 0.f), bufferSize(rate * 4) {
|
||||
for (int h = 0; h < HEADS; h++) delaySamples[h] = rate / 2;
|
||||
}
|
||||
|
||||
void update(const Params &p, float tempoBpm) override {
|
||||
double samplesPerBeat = (60.0 / (double)tempoBpm) * sampleRate;
|
||||
for (int h = 0; h < HEADS; h++) {
|
||||
headOn[h] = p.f(HEAD_ON_KEYS[h], h == 0 ? 1.f : 0.f) >= 0.5f;
|
||||
int idx = kt::toInt(p.f(HEAD_DIV_KEYS[h], (float)DIV_DEFAULT));
|
||||
// Double.toInt(): truncation (values here are small and positive).
|
||||
double d = beatFraction(idx) * samplesPerBeat;
|
||||
int ds = std::isnan(d) ? 0 : d >= 2147483647.0 ? 2147483647 : (int)d;
|
||||
delaySamples[h] = kt::coerceIn(ds, 1, bufferSize - 2);
|
||||
}
|
||||
feedback = kt::coerceIn(p.f("feedback", 0.4f), 0.f, MAX_FEEDBACK);
|
||||
dryWet = kt::coerceIn(p.f("drywet", 0.35f), 0.f, 1.f);
|
||||
float tape = kt::coerceIn(p.f("tape", 0.3f), 0.f, 1.f);
|
||||
satBlend = tape;
|
||||
lpAlpha = 1.f - tape * 0.85f;
|
||||
flutterInc = 2.0 * M_PI * FLUTTER_HZ / sampleRate;
|
||||
flutterDepth = tape * (float)sampleRate * 0.0015f;
|
||||
}
|
||||
|
||||
float process(float x) override {
|
||||
flutterPhase += flutterInc;
|
||||
if (flutterPhase > 2 * M_PI) flutterPhase -= 2 * M_PI;
|
||||
float flutter = (float)std::sin(flutterPhase) * flutterDepth;
|
||||
|
||||
float wet = 0.f;
|
||||
int active = 0;
|
||||
for (int h = 0; h < HEADS; h++) {
|
||||
if (!headOn[h]) continue;
|
||||
active++;
|
||||
float pos = (float)(writeIndex - delaySamples[h]) - flutter;
|
||||
while (pos < 0.f) pos += (float)bufferSize;
|
||||
int i0 = kt::toInt(pos) % bufferSize;
|
||||
int i1 = (i0 + 1) % bufferSize;
|
||||
float frac = pos - (float)kt::toInt(pos);
|
||||
wet += buffer[i0] + (buffer[i1] - buffer[i0]) * frac;
|
||||
}
|
||||
if (active > 0) wet /= (float)active;
|
||||
|
||||
float fb = wet * feedback;
|
||||
fb += satBlend * (kt::tanhf_(fb) - fb);
|
||||
lpState += lpAlpha * (fb - lpState);
|
||||
fb = lpState;
|
||||
|
||||
buffer[writeIndex] = x + fb;
|
||||
writeIndex = (writeIndex + 1) % bufferSize;
|
||||
return x * (1.f - dryWet) + wet * dryWet;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<Effect> makeTapeDelay(int sampleRate) { return std::make_unique<TapeDelay>(sampleRate); }
|
||||
|
||||
} // namespace sizzle
|
||||
@@ -0,0 +1,102 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// Port of TapeEngine (Effects.kt): a varispeed reel-to-reel. Input is written into
|
||||
// a ring at rate 1 and read back at a gliding `speed`, with wow/flutter wobble and
|
||||
// xorshift hiss.
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include "sizzle/Effect.hpp"
|
||||
#include "KotlinMath.hpp"
|
||||
|
||||
namespace sizzle {
|
||||
namespace {
|
||||
|
||||
constexpr int NOMINAL_DELAY = 128;
|
||||
constexpr float MIN_SPEED = 0.25f;
|
||||
constexpr float MAX_WOW = 0.03f;
|
||||
constexpr float MAX_FLUT = 0.008f;
|
||||
constexpr float MAX_HISS = 0.02f;
|
||||
constexpr double FLUTTER_HZ = 11.0;
|
||||
constexpr float SPEED_GLIDE = 0.00012f;
|
||||
constexpr double MIN_GAP = 2.0;
|
||||
|
||||
/** TimeDivision.beatFraction by index, with fromIndex's clamping. */
|
||||
double beatFraction(int i) {
|
||||
static constexpr double kFrac[] = {4.0, 2.0, 1.0, 0.5, 0.25, 0.125, 0.75};
|
||||
return kFrac[kt::coerceIn(i, 0, 6)];
|
||||
}
|
||||
|
||||
class TapeEngine final : public Effect {
|
||||
int sampleRate;
|
||||
std::vector<float> buf;
|
||||
int size;
|
||||
int writePos = NOMINAL_DELAY;
|
||||
double readPos = 0.0;
|
||||
double targetSpeed = 1.0;
|
||||
double curSpeed = 1.0;
|
||||
double wowInc = 0.0, wowPhase = 0.0; float wowDepth = 0.f;
|
||||
double flutInc, flutPhase = 0.0; float flutDepth = 0.f;
|
||||
float hiss = 0.f;
|
||||
uint32_t rng = 0x51ED2A19u;
|
||||
|
||||
float nextRand() {
|
||||
uint32_t s = rng; s ^= s << 13; s ^= s >> 17; s ^= s << 5; rng = s;
|
||||
return (float)(int32_t)s * 4.656613e-10f; // -1 … 1
|
||||
}
|
||||
|
||||
public:
|
||||
explicit TapeEngine(int rate)
|
||||
: sampleRate(rate), buf((size_t)rate * 2, 0.f), size(rate * 2),
|
||||
flutInc(FLUTTER_HZ / rate) {}
|
||||
|
||||
void update(const Params &p, float tempoBpm) override {
|
||||
targetSpeed = (double)kt::coerceIn(p.f("speed", 1.f), MIN_SPEED, 1.f);
|
||||
wowDepth = kt::coerceIn(p.f("wow", 0.15f), 0.f, 1.f) * MAX_WOW;
|
||||
flutDepth = kt::coerceIn(p.f("flutter", 0.15f), 0.f, 1.f) * MAX_FLUT;
|
||||
hiss = kt::coerceIn(p.f("hiss", 0.10f), 0.f, 1.f) * MAX_HISS;
|
||||
double secPerBeat = 60.0 / (double)tempoBpm;
|
||||
double frac = beatFraction(kt::toInt(p.f("division", 2.f)));
|
||||
double wowHz = 1.0 / kt::coerceAtLeast(frac * secPerBeat, 1e-4);
|
||||
wowInc = wowHz / sampleRate;
|
||||
flutInc = FLUTTER_HZ / sampleRate;
|
||||
}
|
||||
|
||||
float process(float x) override {
|
||||
buf[writePos] = x;
|
||||
writePos++; if (writePos >= size) writePos = 0;
|
||||
|
||||
curSpeed += (targetSpeed - curSpeed) * (double)SPEED_GLIDE; // tape inertia
|
||||
|
||||
wowPhase += wowInc; if (wowPhase >= 1.0) wowPhase -= 1.0;
|
||||
flutPhase += flutInc; if (flutPhase >= 1.0) flutPhase -= 1.0;
|
||||
double wow = std::sin(2.0 * M_PI * wowPhase) * (double)wowDepth;
|
||||
double flut = std::sin(2.0 * M_PI * flutPhase) * (double)flutDepth;
|
||||
double rate = curSpeed * (1.0 + wow + flut);
|
||||
if (rate < 0.01) rate = 0.01;
|
||||
|
||||
int i0 = (int)readPos % size;
|
||||
int i1 = (i0 + 1) % size;
|
||||
float frac = (float)(readPos - (int)readPos);
|
||||
float out = buf[i0] + (buf[i1] - buf[i0]) * frac;
|
||||
|
||||
double rp = readPos + rate;
|
||||
if (rp >= size) rp -= size;
|
||||
double gap = writePos - rp; if (gap < 0) gap += size;
|
||||
double maxGap = size - 2.0;
|
||||
if (gap < MIN_GAP) { rp = writePos - MIN_GAP; if (rp < 0) rp += size; }
|
||||
else if (gap > maxGap) { rp = writePos - maxGap; if (rp < 0) rp += size; }
|
||||
readPos = rp;
|
||||
|
||||
if (hiss > 0.f) out += nextRand() * hiss;
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<Effect> makeTapeEngine(int sr) { return std::make_unique<TapeEngine>(sr); }
|
||||
|
||||
} // namespace sizzle
|
||||
@@ -0,0 +1,287 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "host/EngineHost.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include "echofield/GrainSources.hpp"
|
||||
#include "io/ProjectIo.hpp"
|
||||
#include "wavetable/WaveDefs.hpp"
|
||||
#include "wavetable/WaveTables.hpp"
|
||||
|
||||
namespace sizzle::host {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr int kChunk = engine::Engine::BLOCK_FRAMES; // the MIDI LFO steps by it (see ios/PORTING.md)
|
||||
|
||||
/// The store WaveTables reads custom tables from (one host per process).
|
||||
std::atomic<sampler::SampleStore *> gStore{nullptr};
|
||||
|
||||
bool storeSource(const char *id, std::vector<float> &out) {
|
||||
sampler::SampleStore *store = gStore.load();
|
||||
const Sample *s = store ? store->get(id) : nullptr;
|
||||
if (!s) return false;
|
||||
sampler::SampleStore::pin(s);
|
||||
out = s->data;
|
||||
sampler::SampleStore::unpin(s);
|
||||
return true;
|
||||
}
|
||||
|
||||
// ---- equality, field by field (Params by position: an unchanged map saves in
|
||||
// the same order; a reordered one is just copied again)
|
||||
|
||||
bool same(const Params &a, const Params &b) {
|
||||
if (a.size() != b.size()) return false;
|
||||
for (int i = 0; i < a.size(); ++i)
|
||||
if (std::strcmp(a.keyAt(i), b.keyAt(i)) || std::strcmp(a.valueAt(i), b.valueAt(i))) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool same(const model::ToolboxSlot &a, const model::ToolboxSlot &b) {
|
||||
return a.type == b.type && a.name == b.name && same(a.values, b.values);
|
||||
}
|
||||
|
||||
bool sameCells(const model::Pattern &a, const model::Pattern &b) {
|
||||
for (int t = 0; t < model::Pattern::TRACK_COUNT; ++t) {
|
||||
if (a.tracks[t].size() != b.tracks[t].size()) return false;
|
||||
for (size_t l = 0; l < a.tracks[t].size(); ++l) {
|
||||
const model::Cell &x = a.tracks[t][l], &y = b.tracks[t][l];
|
||||
if (x.note != y.note || x.velocity != y.velocity || x.channel != y.channel) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool same(const model::LoopRegion &a, const model::LoopRegion &b) {
|
||||
return a.enabled == b.enabled && a.start == b.start && a.end == b.end && a.repeats == b.repeats;
|
||||
}
|
||||
|
||||
bool same(const model::Arrangement &a, const model::Arrangement &b) {
|
||||
return a.slots == b.slots && a.laneMuted == b.laneMuted && a.lengthBars == b.lengthBars &&
|
||||
a.loopEnabled == b.loopEnabled && same(a.regionA, b.regionA) && same(a.regionB, b.regionB);
|
||||
}
|
||||
|
||||
bool same(const model::Mixer &a, const model::Mixer &b) {
|
||||
for (int c = 0; c < model::Mixer::CHANNEL_COUNT; ++c) {
|
||||
const auto &x = a.channels[c], &y = b.channels[c];
|
||||
if (x.instrumentSlot != y.instrumentSlot || x.fxSlots != y.fxSlots || x.midiChannel != y.midiChannel ||
|
||||
x.volume != y.volume || x.mute != y.mute || x.solo != y.solo || x.limiter != y.limiter) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// WaveVoice's frame length: wtframe's choice ("Auto" or unknown -> 0).
|
||||
int frameLenOf(const model::ToolboxSlot &slot) {
|
||||
namespace WD = wavetable::WaveDefs;
|
||||
const char *v = slot.s("wtframe", WD::FRAME_SIZES[0]);
|
||||
for (int i = 1; i < WD::FRAME_SIZE_COUNT; ++i)
|
||||
if (!std::strcmp(v, WD::FRAME_SIZES[i])) return std::atoi(WD::FRAME_SIZES[i]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool playsCustom(const model::ToolboxSlot &slot) {
|
||||
namespace WT = wavetable::WaveTables;
|
||||
return slot.type == "WAVETABLE" && *slot.s(wavetable::WaveDefs::SAMPLE_KEY, "") &&
|
||||
(!std::strcmp(slot.s("o1table", ""), WT::CUSTOM) || !std::strcmp(slot.s("o2table", ""), WT::CUSTOM));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
EngineHost::EngineHost(int sampleRate)
|
||||
: sampleRate_(sampleRate),
|
||||
store_(std::make_unique<sampler::SampleStore>()),
|
||||
project_(std::make_unique<model::Project>()),
|
||||
shadow_(std::make_unique<model::Project>()),
|
||||
recorder_(std::make_unique<MasterRecorder>(sampleRate)) {
|
||||
wavetable::WaveTables::prewarm();
|
||||
echofield::GrainSources::prewarm();
|
||||
gStore.store(store_.get());
|
||||
wavetable::WaveTables::setSampleSource(&storeSource);
|
||||
engine_ = std::make_unique<engine::Engine>(sampleRate, store_.get());
|
||||
engine_->setProject(project_.get());
|
||||
engine_->setMasterSink(recorder_.get());
|
||||
}
|
||||
|
||||
EngineHost::~EngineHost() {
|
||||
{
|
||||
std::lock_guard<std::mutex> b(builderLock_);
|
||||
if (builder_.joinable()) builder_.join();
|
||||
}
|
||||
engine_.reset();
|
||||
gStore.store(nullptr);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- song
|
||||
|
||||
void EngineHost::loadProjectText(const std::string &text) {
|
||||
auto fresh = std::make_unique<model::Project>();
|
||||
io::ProjectIo::loadInto(*fresh, text);
|
||||
{
|
||||
std::lock_guard<std::mutex> g(lock_);
|
||||
engine_->stop();
|
||||
*project_ = model::Project();
|
||||
io::ProjectIo::loadInto(*project_, text);
|
||||
engine_->setProject(project_.get());
|
||||
}
|
||||
shadow_ = std::move(fresh);
|
||||
lastText_ = text;
|
||||
scheduleTables();
|
||||
}
|
||||
|
||||
void EngineHost::syncProjectText(const std::string &text) {
|
||||
if (text == lastText_) return;
|
||||
auto fresh = std::make_unique<model::Project>();
|
||||
io::ProjectIo::loadInto(*fresh, text);
|
||||
const model::Project &old = *shadow_;
|
||||
|
||||
// What differs from the last sync, worked out without the lock.
|
||||
const bool scalars = fresh->name != old.name || fresh->tempoBpm != old.tempoBpm ||
|
||||
fresh->timeSignature != old.timeSignature || fresh->scale != old.scale ||
|
||||
fresh->rootNote != old.rootNote || fresh->activePatternId != old.activePatternId;
|
||||
const bool patternSet = fresh->patterns.size() != old.patterns.size();
|
||||
std::vector<size_t> cells, patterns; // same shape, other cells / other shape
|
||||
if (!patternSet) {
|
||||
for (size_t i = 0; i < fresh->patterns.size(); ++i) {
|
||||
const auto &a = fresh->patterns[i], &b = old.patterns[i];
|
||||
if (a.id != b.id || a.name != b.name || a.length != b.length) patterns.push_back(i);
|
||||
else if (!sameCells(a, b)) cells.push_back(i);
|
||||
}
|
||||
}
|
||||
const bool arrangement = !same(fresh->arrangement, old.arrangement);
|
||||
const bool mixer = !same(fresh->mixer, old.mixer);
|
||||
std::vector<size_t> slots;
|
||||
for (size_t i = 0; i < fresh->toolbox.size(); ++i)
|
||||
if (!same(fresh->toolbox[i], old.toolbox[i])) slots.push_back(i);
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> g(lock_);
|
||||
model::Project &p = *project_;
|
||||
if (scalars) {
|
||||
p.name = fresh->name;
|
||||
p.tempoBpm = fresh->tempoBpm;
|
||||
p.timeSignature = fresh->timeSignature;
|
||||
p.scale = fresh->scale;
|
||||
p.rootNote = fresh->rootNote;
|
||||
p.activePatternId = fresh->activePatternId;
|
||||
}
|
||||
if (patternSet) p.patterns = fresh->patterns;
|
||||
for (size_t i : patterns) p.patterns[i] = fresh->patterns[i];
|
||||
for (size_t i : cells) // same lengths: copy in place, no allocation
|
||||
for (int t = 0; t < model::Pattern::TRACK_COUNT; ++t)
|
||||
std::copy(fresh->patterns[i].tracks[t].begin(), fresh->patterns[i].tracks[t].end(), p.patterns[i].tracks[t].begin());
|
||||
if (arrangement) p.arrangement = fresh->arrangement;
|
||||
if (mixer) p.mixer = fresh->mixer;
|
||||
for (size_t i : slots) {
|
||||
model::ToolboxSlot &s = p.toolbox[i];
|
||||
s.type = fresh->toolbox[i].type;
|
||||
s.name = fresh->toolbox[i].name;
|
||||
s.values = fresh->toolbox[i].values;
|
||||
++s.version; // the engine re-reads a slot when its version moves
|
||||
}
|
||||
}
|
||||
shadow_ = std::move(fresh);
|
||||
lastText_ = text;
|
||||
if (!slots.empty()) scheduleTables();
|
||||
}
|
||||
|
||||
std::string EngineHost::projectText() {
|
||||
std::lock_guard<std::mutex> g(lock_);
|
||||
return io::ProjectIo::save(*project_);
|
||||
}
|
||||
|
||||
void EngineHost::rebuildFxChains() { std::lock_guard<std::mutex> g(lock_); engine_->rebuildFxChains(); }
|
||||
void EngineHost::rebuildArrangement() { std::lock_guard<std::mutex> g(lock_); engine_->rebuildArrangement(); }
|
||||
void EngineHost::refreshLoopPlaylist() { std::lock_guard<std::mutex> g(lock_); engine_->refreshLoopPlaylist(); }
|
||||
|
||||
void EngineHost::play(int startBeat) { std::lock_guard<std::mutex> g(lock_); engine_->play(startBeat); }
|
||||
void EngineHost::pause() { std::lock_guard<std::mutex> g(lock_); engine_->pause(); }
|
||||
void EngineHost::stop() { std::lock_guard<std::mutex> g(lock_); engine_->stop(); }
|
||||
void EngineHost::panic() { std::lock_guard<std::mutex> g(lock_); engine_->panic(); }
|
||||
|
||||
void EngineHost::setRecordingArm(bool armed, int tailBars) { engine_->setRecordingArm(armed, tailBars); }
|
||||
void EngineHost::setRecordTailBars(int tailBars) { engine_->setRecordTailBars(tailBars); }
|
||||
|
||||
std::string EngineHost::describeBusTargets(int midiChannel, int midi) {
|
||||
std::lock_guard<std::mutex> g(lock_);
|
||||
return engine_->describeBusTargets(midiChannel, midi);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- notes
|
||||
|
||||
void EngineHost::push(NoteEvent e) {
|
||||
std::lock_guard<std::mutex> g(pushLock_);
|
||||
const uint32_t h = head_.load(std::memory_order_relaxed);
|
||||
if (h - tail_.load(std::memory_order_acquire) >= ring_.size()) return; // full: drop
|
||||
ring_[h % ring_.size()] = e;
|
||||
head_.store(h + 1, std::memory_order_release);
|
||||
}
|
||||
|
||||
void EngineHost::liveNoteOn(int pitch, int velocity) { push({4, pitch, velocity, 0}); }
|
||||
void EngineHost::liveNoteOff(int pitch) { push({5, pitch, 0, 0}); }
|
||||
void EngineHost::auditionSlotOn(int slot, int midi) { push({2, slot, midi, 0}); }
|
||||
void EngineHost::auditionSlotOff(int midi) { push({3, 0, midi, 0}); }
|
||||
void EngineHost::busNoteOn(int ch, int midi, int velocity) { push({0, ch, midi, velocity}); }
|
||||
void EngineHost::busNoteOff(int ch, int midi) { push({1, ch, midi, 0}); }
|
||||
|
||||
// ---------------------------------------------------------------- audio
|
||||
|
||||
void EngineHost::render(float *out, int frames) {
|
||||
std::unique_lock<std::mutex> g(lock_, std::try_to_lock);
|
||||
if (!g.owns_lock()) { // an edit is being applied: this block is silent (notes wait)
|
||||
std::memset(out, 0, sizeof(float) * 2 * (size_t)frames);
|
||||
return;
|
||||
}
|
||||
engine::Engine &e = *engine_;
|
||||
uint32_t t = tail_.load(std::memory_order_relaxed);
|
||||
const uint32_t h = head_.load(std::memory_order_acquire);
|
||||
for (; t != h; ++t) {
|
||||
const NoteEvent &n = ring_[t % ring_.size()];
|
||||
switch (n.kind) {
|
||||
case 0: e.busNoteOn(n.a, n.b, n.c); break;
|
||||
case 1: e.busNoteOff(n.a, n.b); break;
|
||||
case 2: e.auditionSlotOn(n.a, n.b); break;
|
||||
case 3: e.auditionSlotOff(n.b); break;
|
||||
case 4: e.liveNoteOn(n.a, n.b); break;
|
||||
case 5: e.liveNoteOff(n.a); break;
|
||||
}
|
||||
}
|
||||
tail_.store(t, std::memory_order_release);
|
||||
for (int done = 0; done < frames;) {
|
||||
const int n = std::min(kChunk, frames - done);
|
||||
e.fillBlock(out + 2 * done, n);
|
||||
done += n;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- samples
|
||||
|
||||
void EngineHost::putSample(const std::string &id, Sample sample) {
|
||||
store_->put(id, std::move(sample));
|
||||
scheduleTables();
|
||||
}
|
||||
|
||||
void EngineHost::removeSample(const std::string &id) { store_->remove(id); }
|
||||
|
||||
/// Ask WaveTables for every Custom table the song plays (recording the request),
|
||||
/// then build what's missing on a background thread, one build at a time.
|
||||
void EngineHost::scheduleTables() {
|
||||
bool missing = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> g(lock_);
|
||||
for (const auto &slot : project_->toolbox)
|
||||
if (playsCustom(slot) && !wavetable::WaveTables::forSample(slot.s(wavetable::WaveDefs::SAMPLE_KEY, ""), frameLenOf(slot)))
|
||||
missing = true;
|
||||
}
|
||||
std::lock_guard<std::mutex> b(builderLock_);
|
||||
if (!missing || building_.exchange(true)) return;
|
||||
if (builder_.joinable()) builder_.join();
|
||||
builder_ = std::thread([this] {
|
||||
wavetable::WaveTables::buildRequested();
|
||||
building_.store(false);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace sizzle::host
|
||||
@@ -0,0 +1,117 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// The engine as an app hosts it: the song, the sample store, the engine, live
|
||||
// notes queued to the audio thread, the master recorder and custom wavetable
|
||||
// building, behind one lock the audio thread only ever try-locks (a block that
|
||||
// meets an edit plays silence instead of waiting).
|
||||
//
|
||||
// The Android app drives it through JNI (app/src/main/cpp/jni_engine.cpp): its
|
||||
// Kotlin model stays the UI's state and is mirrored here as project text
|
||||
// (syncProjectText), applied as a diff so an edit holds the lock for microseconds.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <array>
|
||||
|
||||
#include "host/MasterRecorder.hpp"
|
||||
#include "sampler/SampleStore.hpp"
|
||||
#include "sizzle/Engine.hpp"
|
||||
#include "sizzle/Model.hpp"
|
||||
|
||||
namespace sizzle::host {
|
||||
|
||||
class EngineHost {
|
||||
public:
|
||||
explicit EngineHost(int sampleRate);
|
||||
~EngineHost();
|
||||
EngineHost(const EngineHost &) = delete;
|
||||
EngineHost &operator=(const EngineHost &) = delete;
|
||||
|
||||
int sampleRate() const { return sampleRate_; }
|
||||
|
||||
// ---- the song (main thread)
|
||||
/** Replace the song with [text] (a .szg project), stopping playback. */
|
||||
void loadProjectText(const std::string &text);
|
||||
/** Make the song equal [text], changing only what differs from the last text:
|
||||
* playback continues. Cheap when nothing changed. */
|
||||
void syncProjectText(const std::string &text);
|
||||
void rebuildFxChains();
|
||||
void rebuildArrangement();
|
||||
void refreshLoopPlaylist();
|
||||
|
||||
// ---- transport (main thread)
|
||||
void play(int startBeat = -1);
|
||||
void pause();
|
||||
void stop();
|
||||
void panic();
|
||||
engine::TransportState transport() const { return engine_->transport(); }
|
||||
bool isPlaying() const { return engine_->isPlaying(); }
|
||||
|
||||
// ---- live notes (any thread; queued to the audio thread)
|
||||
void liveNoteOn(int pitch, int velocity);
|
||||
void liveNoteOff(int pitch);
|
||||
void auditionSlotOn(int slot, int midi);
|
||||
void auditionSlotOff(int midi);
|
||||
void busNoteOn(int midiChannel, int midi, int velocity);
|
||||
void busNoteOff(int midiChannel, int midi);
|
||||
std::string describeBusTargets(int midiChannel, int midi);
|
||||
|
||||
// ---- audio thread
|
||||
/** [frames] interleaved stereo frames into [out], in the engine's 192-frame blocks. */
|
||||
void render(float *out, int frames);
|
||||
|
||||
// ---- display (any thread)
|
||||
float channelMeter(int ch) const { return engine_->channelMeter(ch); }
|
||||
bool channelClipped(int ch) const { return engine_->channelClipped(ch); }
|
||||
int effectScope(int slot, float *out, int capacity) const { return engine_->effectScope(slot, out, capacity); }
|
||||
float effectPlayhead(int slot) const { return engine_->effectPlayhead(slot); }
|
||||
|
||||
// ---- outgoing MIDI
|
||||
void setMidiOutEnabled(bool on) { engine_->setMidiOutEnabled(on); }
|
||||
int pollMidiOut() { return engine_->pollMidiOut(); }
|
||||
|
||||
// ---- samples (not the audio thread)
|
||||
void putSample(const std::string &id, Sample sample);
|
||||
void removeSample(const std::string &id);
|
||||
sampler::SampleStore &store() { return *store_; }
|
||||
/** The engine's song as project text (tests, diagnostics). */
|
||||
std::string projectText();
|
||||
|
||||
// ---- master recording
|
||||
MasterRecorder &recorder() { return *recorder_; }
|
||||
void setRecordingArm(bool armed, int tailBars);
|
||||
void setRecordTailBars(int tailBars);
|
||||
void externalClockStart() { engine_->externalClockStart(); }
|
||||
void externalClockStop() { engine_->externalClockStop(); }
|
||||
|
||||
private:
|
||||
struct NoteEvent { int kind, a, b, c; };
|
||||
void push(NoteEvent e);
|
||||
void scheduleTables();
|
||||
|
||||
const int sampleRate_;
|
||||
std::unique_ptr<sampler::SampleStore> store_;
|
||||
std::unique_ptr<model::Project> project_; // the engine's song (under lock_)
|
||||
std::unique_ptr<model::Project> shadow_; // the last synced text, parsed (main thread)
|
||||
std::string lastText_;
|
||||
std::unique_ptr<engine::Engine> engine_;
|
||||
std::unique_ptr<MasterRecorder> recorder_;
|
||||
std::mutex lock_;
|
||||
|
||||
// Live notes: producers serialised by pushLock_, the audio thread drains.
|
||||
std::array<NoteEvent, 1024> ring_{};
|
||||
std::atomic<uint32_t> head_{0}, tail_{0};
|
||||
std::mutex pushLock_;
|
||||
|
||||
std::thread builder_;
|
||||
std::atomic<bool> building_{false};
|
||||
std::mutex builderLock_; // scheduleTables runs on the main thread and wherever samples arrive
|
||||
};
|
||||
|
||||
} // namespace sizzle::host
|
||||
@@ -0,0 +1,90 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "host/MasterRecorder.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
|
||||
namespace sizzle::host {
|
||||
|
||||
MasterRecorder::MasterRecorder(int sampleRate) : sr_(sampleRate), ring_((size_t)std::max(2, sampleRate * 4)) {}
|
||||
|
||||
MasterRecorder::~MasterRecorder() {
|
||||
capturing_.store(false);
|
||||
if (writer_.joinable()) writer_.join();
|
||||
}
|
||||
|
||||
bool MasterRecorder::begin() {
|
||||
if (active_.load() || path_.empty()) return false;
|
||||
if (writer_.joinable()) writer_.join(); // the previous take's thread is done (active_ is false)
|
||||
writePos_.store(0);
|
||||
readPos_.store(0);
|
||||
active_.store(true);
|
||||
capturing_.store(true);
|
||||
const int64_t start = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch()).count();
|
||||
const std::string path = path_;
|
||||
writer_ = std::thread([this, path, start] {
|
||||
const bool ok = writeLoop(path);
|
||||
active_.store(false);
|
||||
if (onFinished) onFinished(ok ? path : std::string(), start);
|
||||
});
|
||||
if (onStarted) onStarted();
|
||||
return true;
|
||||
}
|
||||
|
||||
void MasterRecorder::write(float left, float right) {
|
||||
if (!capturing_.load(std::memory_order_relaxed)) return;
|
||||
const uint64_t w = writePos_.load(std::memory_order_relaxed);
|
||||
if (w - readPos_.load(std::memory_order_acquire) > ring_.size() - 2) return; // writer starved: drop
|
||||
ring_[w % ring_.size()] = left;
|
||||
ring_[(w + 1) % ring_.size()] = right;
|
||||
writePos_.store(w + 2, std::memory_order_release);
|
||||
}
|
||||
|
||||
bool MasterRecorder::writeLoop(const std::string &path) {
|
||||
FILE *f = std::fopen(path.c_str(), "wb");
|
||||
if (!f) { capturing_.store(false); return false; }
|
||||
writeHeader(f, 0);
|
||||
uint64_t samples = 0;
|
||||
constexpr size_t chunk = 4096;
|
||||
uint8_t out[chunk * 2];
|
||||
bool ok = true;
|
||||
for (;;) {
|
||||
const uint64_t w = writePos_.load(std::memory_order_acquire);
|
||||
const uint64_t r = readPos_.load(std::memory_order_relaxed);
|
||||
if (r < w) {
|
||||
const size_t n = (size_t)std::min<uint64_t>(w - r, chunk);
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
const float s = std::clamp(ring_[(r + i) % ring_.size()], -1.f, 1.f);
|
||||
const int v = (int)(s * 32767.f);
|
||||
out[i * 2] = (uint8_t)(v & 0xFF);
|
||||
out[i * 2 + 1] = (uint8_t)((v >> 8) & 0xFF);
|
||||
}
|
||||
if (std::fwrite(out, 2, n, f) != n) ok = false;
|
||||
samples += n;
|
||||
readPos_.store(r + n, std::memory_order_release);
|
||||
} else if (!capturing_.load()) {
|
||||
break;
|
||||
} else {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
||||
}
|
||||
}
|
||||
writeHeader(f, samples);
|
||||
return std::fclose(f) == 0 && ok;
|
||||
}
|
||||
|
||||
void MasterRecorder::writeHeader(FILE *f, uint64_t sampleCount) {
|
||||
const uint32_t data = (uint32_t)(sampleCount * 2);
|
||||
auto u32 = [f](uint32_t v) { uint8_t b[4] = {(uint8_t)v, (uint8_t)(v >> 8), (uint8_t)(v >> 16), (uint8_t)(v >> 24)}; std::fwrite(b, 1, 4, f); };
|
||||
auto u16 = [f](uint16_t v) { uint8_t b[2] = {(uint8_t)v, (uint8_t)(v >> 8)}; std::fwrite(b, 1, 2, f); };
|
||||
std::fseek(f, 0, SEEK_SET);
|
||||
std::fwrite("RIFF", 1, 4, f); u32(36 + data); std::fwrite("WAVE", 1, 4, f);
|
||||
std::fwrite("fmt ", 1, 4, f); u32(16); u16(1); u16(2); u32((uint32_t)sr_); u32((uint32_t)sr_ * 4); u16(4); u16(16);
|
||||
std::fwrite("data", 1, 4, f); u32(data);
|
||||
std::fseek(f, 0, SEEK_END);
|
||||
}
|
||||
|
||||
} // namespace sizzle::host
|
||||
@@ -0,0 +1,54 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// The engine's MasterSink as a WAV writer (MasterRecorder.kt): the audio thread
|
||||
// writes interleaved stereo floats into a single-producer/single-consumer ring
|
||||
// (about two seconds), a writer thread drains it into a 16-bit stereo WAV at
|
||||
// [path] and patches the header sizes at the end. No allocation, locks or I/O on
|
||||
// the audio thread. Used by both apps' engine hosts.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "sizzle/Engine.hpp"
|
||||
|
||||
namespace sizzle::host {
|
||||
|
||||
class MasterRecorder final : public engine::MasterSink {
|
||||
public:
|
||||
explicit MasterRecorder(int sampleRate);
|
||||
~MasterRecorder() override;
|
||||
|
||||
/** Where the next take is written (set before arming). */
|
||||
void setPath(std::string path) { path_ = std::move(path); }
|
||||
/** Called when a take starts capturing (the thread that started it: main or MIDI). */
|
||||
std::function<void()> onStarted;
|
||||
/** Called on the writer thread when the file is finished: its path, or "" when
|
||||
* writing failed, and the take's start in milliseconds since the epoch. */
|
||||
std::function<void(const std::string &path, int64_t startMillis)> onFinished;
|
||||
|
||||
bool isActive() const override { return active_.load(); }
|
||||
bool begin() override;
|
||||
void write(float left, float right) override;
|
||||
void endCapture() override { capturing_.store(false); }
|
||||
|
||||
private:
|
||||
bool writeLoop(const std::string &path);
|
||||
void writeHeader(FILE *f, uint64_t sampleCount);
|
||||
|
||||
const int sr_;
|
||||
std::vector<float> ring_;
|
||||
std::string path_;
|
||||
std::atomic<uint64_t> writePos_{0}, readPos_{0};
|
||||
std::atomic<bool> capturing_{false}, active_{false};
|
||||
std::thread writer_;
|
||||
};
|
||||
|
||||
} // namespace sizzle::host
|
||||
@@ -0,0 +1,142 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "sizzle/Instrument.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include "echofield/GrainCloud.hpp"
|
||||
#include "frasil/FrasilVoice.hpp"
|
||||
#include "sampler/SampleStore.hpp"
|
||||
#include "sampler/SampleVoice.hpp"
|
||||
#include "synth/SynthPatch.hpp"
|
||||
#include "synth/SynthVoice.hpp"
|
||||
#include "echofield/GrainSources.hpp"
|
||||
#include "wavetable/WaveTables.hpp"
|
||||
#include "wavetable/WaveVoice.hpp"
|
||||
|
||||
namespace sizzle {
|
||||
namespace {
|
||||
|
||||
constexpr int N = Instrument::POLYPHONY;
|
||||
|
||||
/** Synth, Morph Pad, Wavetable: SynthVoice pool with the engine's patch. */
|
||||
class SynthInstrument final : public Instrument {
|
||||
public:
|
||||
enum Kind { SYNTH, PAD, WAVE };
|
||||
|
||||
private:
|
||||
Kind kind;
|
||||
int sr;
|
||||
frasil::FrasilClock clock;
|
||||
frasil::FrasilSeeds seeds;
|
||||
std::unique_ptr<synth::SynthVoice> voices[N];
|
||||
synth::SynthPatch patch = synth::SynthPatch::defaults();
|
||||
int alloc = 0;
|
||||
|
||||
public:
|
||||
SynthInstrument(Kind k, int sampleRate) : kind(k), sr(sampleRate) {
|
||||
for (auto &v : voices) v = std::make_unique<synth::SynthVoice>(sr, clock, seeds.next());
|
||||
}
|
||||
void update(const Params &p, float tempo) override {
|
||||
switch (kind) {
|
||||
case PAD: patch = synth::SynthPatch::forPad(frasil::FrasilPatch::from(&p)); break;
|
||||
case WAVE: patch = synth::SynthPatch::forWave(wavetable::WavePatch::from(&p, tempo)); break;
|
||||
default: patch = synth::SynthPatch::from(&p, tempo); break;
|
||||
}
|
||||
for (auto &v : voices) if (v->isActive()) v->setPatch(patch);
|
||||
}
|
||||
void noteOn(int midi, int vel) override {
|
||||
for (auto &v : voices) if (!v->isActive()) { v->noteOn(midi, vel, patch); return; }
|
||||
auto &v = voices[alloc];
|
||||
alloc = (alloc + 1) % N;
|
||||
v->kill();
|
||||
v->noteOn(midi, vel, patch);
|
||||
}
|
||||
void noteOff(int midi) override {
|
||||
for (auto &v : voices) if (v->isGated() && v->pitch() == midi) v->noteOff();
|
||||
}
|
||||
void allNotesOff() override { for (auto &v : voices) v->noteOff(); }
|
||||
void kill() override { for (auto &v : voices) v->kill(); }
|
||||
void blockStart(int frames) override { clock.advance(frames, sr); }
|
||||
float render() override {
|
||||
float s = 0.f;
|
||||
for (auto &v : voices) if (v->isActive()) s += v->render();
|
||||
return s;
|
||||
}
|
||||
};
|
||||
|
||||
/** Sampler pads and the SF2/XI loader: SampleVoice pool. */
|
||||
class SampleInstrument final : public Instrument {
|
||||
std::string type;
|
||||
sampler::SampleStore *store;
|
||||
std::unique_ptr<sampler::SampleVoice> voices[N];
|
||||
Params params;
|
||||
int alloc = 0;
|
||||
|
||||
public:
|
||||
SampleInstrument(const char *t, int sr, sampler::SampleStore *s) : type(t), store(s) {
|
||||
for (auto &v : voices) v = std::make_unique<sampler::SampleVoice>(sr);
|
||||
}
|
||||
void update(const Params &p, float) override { params = p; }
|
||||
void noteOn(int midi, int vel) override {
|
||||
if (!store) return;
|
||||
sampler::VoiceSample vs;
|
||||
if (!sampler::voiceSample(type.c_str(), params, *store, midi, vs)) return;
|
||||
for (auto &v : voices) if (!v->isActive()) { v->noteOn(vs, midi, vel); return; }
|
||||
auto &v = voices[alloc];
|
||||
alloc = (alloc + 1) % N;
|
||||
v->noteOn(vs, midi, vel); // declicks the hand-off itself
|
||||
}
|
||||
void noteOff(int midi) override {
|
||||
for (auto &v : voices) if (v->isGated() && v->pitch == midi) v->noteOff();
|
||||
}
|
||||
void allNotesOff() override { for (auto &v : voices) v->noteOff(); }
|
||||
void kill() override { for (auto &v : voices) v->kill(); }
|
||||
void blockStart(int) override { if (store) store->quiescent(); }
|
||||
float render() override {
|
||||
float s = 0.f;
|
||||
for (auto &v : voices) if (v->isActive()) s += v->render();
|
||||
return s;
|
||||
}
|
||||
};
|
||||
|
||||
/** Grain Cloud: one polyphonic cloud. */
|
||||
class GrainInstrument final : public Instrument {
|
||||
echofield::GrainCloud cloud;
|
||||
sampler::SampleStore *store;
|
||||
|
||||
static const Sample *lookup(void *ctx, const char *id) {
|
||||
auto *s = static_cast<sampler::SampleStore *>(ctx);
|
||||
return s ? s->get(id) : nullptr;
|
||||
}
|
||||
|
||||
public:
|
||||
GrainInstrument(int sr, sampler::SampleStore *s) : cloud(sr, echofield::GrainSeeds{}.next()), store(s) {
|
||||
cloud.setSampleLookup(&GrainInstrument::lookup, store);
|
||||
}
|
||||
void update(const Params &p, float tempo) override { cloud.setPatch(echofield::GrainPatch::from(&p, tempo)); }
|
||||
void noteOn(int midi, int vel) override { cloud.noteOn(midi, vel, echofield::GrainCloud::OWNER_LIVE); }
|
||||
void noteOff(int midi) override { cloud.noteOff(midi); }
|
||||
void allNotesOff() override { cloud.releaseAll(); }
|
||||
void kill() override { cloud.kill(); }
|
||||
void blockStart(int) override { if (store) store->quiescent(); }
|
||||
float render() override { return cloud.render(); }
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<Instrument> Instrument::create(const char *type, int sr, sampler::SampleStore *store) {
|
||||
auto is = [&](const char *t) { return std::strcmp(type, t) == 0; };
|
||||
if (is("NES_SYNTH")) return std::make_unique<SynthInstrument>(SynthInstrument::SYNTH, sr);
|
||||
if (is("MORPH_PAD")) return std::make_unique<SynthInstrument>(SynthInstrument::PAD, sr);
|
||||
// Wavetables and grain sources are generated once, off the audio thread; until
|
||||
// they're ready those oscillators / clouds are silent (as on Android, where the
|
||||
// app starts this at launch). prewarm() returns at once.
|
||||
if (is("WAVETABLE")) { wavetable::WaveTables::prewarm(); return std::make_unique<SynthInstrument>(SynthInstrument::WAVE, sr); }
|
||||
if (is("GRAIN_CLOUD")) { echofield::GrainSources::prewarm(); return std::make_unique<GrainInstrument>(sr, store); }
|
||||
if (is("SAMPLER") || is("SOUNDFONT")) return std::make_unique<SampleInstrument>(type, sr, store);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace sizzle
|
||||
@@ -0,0 +1,215 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "io/KotlinText.hpp"
|
||||
|
||||
#include <climits>
|
||||
#include <clocale>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
namespace sizzle::io::kt {
|
||||
|
||||
unsigned decodeUtf8(const std::string &s, size_t &i) {
|
||||
const unsigned char c0 = (unsigned char)s[i];
|
||||
if (c0 < 0x80) { ++i; return c0; }
|
||||
int n; unsigned cp, min;
|
||||
if ((c0 & 0xE0) == 0xC0) { n = 1; cp = c0 & 0x1F; min = 0x80; }
|
||||
else if ((c0 & 0xF0) == 0xE0) { n = 2; cp = c0 & 0x0F; min = 0x800; }
|
||||
else if ((c0 & 0xF8) == 0xF0) { n = 3; cp = c0 & 0x07; min = 0x10000; }
|
||||
else { ++i; return 0xFFFD; }
|
||||
if (i + (size_t)n >= s.size()) { ++i; return 0xFFFD; }
|
||||
for (int k = 1; k <= n; ++k) {
|
||||
const unsigned char c = (unsigned char)s[i + (size_t)k];
|
||||
if ((c & 0xC0) != 0x80) { ++i; return 0xFFFD; }
|
||||
cp = (cp << 6) | (c & 0x3F);
|
||||
}
|
||||
if (cp < min || cp > 0x10FFFF || (cp >= 0xD800 && cp <= 0xDFFF)) { ++i; return 0xFFFD; }
|
||||
i += (size_t)n + 1;
|
||||
return cp;
|
||||
}
|
||||
|
||||
bool isWhitespace(unsigned cp) {
|
||||
return (cp >= 0x09 && cp <= 0x0D) || (cp >= 0x1C && cp <= 0x20) || cp == 0xA0 || cp == 0x1680 ||
|
||||
(cp >= 0x2000 && cp <= 0x200A) || cp == 0x2028 || cp == 0x2029 || cp == 0x202F || cp == 0x205F ||
|
||||
cp == 0x3000;
|
||||
}
|
||||
|
||||
// Zeros of the BMP's Nd (decimal digit) runs, Unicode 13 (JDK 17). Supplementary
|
||||
// digits arrive in Kotlin as surrogate pairs, which are not digits.
|
||||
static const unsigned kDigitZeros[] = {
|
||||
0x0030, 0x0660, 0x06F0, 0x07C0, 0x0966, 0x09E6, 0x0A66, 0x0AE6, 0x0B66, 0x0BE6, 0x0C66, 0x0CE6,
|
||||
0x0D66, 0x0DE6, 0x0E50, 0x0ED0, 0x0F20, 0x1040, 0x1090, 0x17E0, 0x1810, 0x1946, 0x19D0, 0x1A80,
|
||||
0x1A90, 0x1B50, 0x1BB0, 0x1C40, 0x1C50, 0xA620, 0xA8D0, 0xA900, 0xA9D0, 0xA9F0, 0xAA50, 0xABF0, 0xFF10};
|
||||
|
||||
int decimalDigit(unsigned cp) {
|
||||
for (unsigned z : kDigitZeros)
|
||||
if (cp >= z && cp < z + 10) return (int)(cp - z);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/** Character.digit(cp, radix). */
|
||||
static int digitOf(unsigned cp, int radix) {
|
||||
int d = decimalDigit(cp);
|
||||
if (d < 0) {
|
||||
if (cp >= 'a' && cp <= 'z') d = (int)(cp - 'a') + 10;
|
||||
else if (cp >= 'A' && cp <= 'Z') d = (int)(cp - 'A') + 10;
|
||||
else if (cp >= 0xFF41 && cp <= 0xFF5A) d = (int)(cp - 0xFF41) + 10;
|
||||
else if (cp >= 0xFF21 && cp <= 0xFF3A) d = (int)(cp - 0xFF21) + 10;
|
||||
}
|
||||
return d >= 0 && d < radix ? d : -1;
|
||||
}
|
||||
|
||||
std::vector<std::string> lines(const std::string &text) {
|
||||
std::vector<std::string> out;
|
||||
size_t start = 0;
|
||||
for (size_t i = 0; i < text.size(); ++i) {
|
||||
if (text[i] == '\n' || text[i] == '\r') {
|
||||
out.emplace_back(text, start, i - start);
|
||||
if (text[i] == '\r' && i + 1 < text.size() && text[i + 1] == '\n') ++i;
|
||||
start = i + 1;
|
||||
}
|
||||
}
|
||||
out.emplace_back(text, start, text.size() - start);
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string trim(const std::string &s) {
|
||||
size_t first = s.size(), last = 0; // [first, last) of non-whitespace
|
||||
size_t i = 0;
|
||||
while (i < s.size()) {
|
||||
size_t at = i;
|
||||
unsigned cp = decodeUtf8(s, i);
|
||||
if (!isWhitespace(cp)) { if (first == s.size()) first = at; last = i; }
|
||||
}
|
||||
return first == s.size() ? std::string() : s.substr(first, last - first);
|
||||
}
|
||||
|
||||
std::vector<std::string> split(const std::string &s, char c) {
|
||||
std::vector<std::string> out;
|
||||
size_t start = 0;
|
||||
for (size_t i = 0; i < s.size(); ++i)
|
||||
if (s[i] == c) { out.emplace_back(s, start, i - start); start = i + 1; }
|
||||
out.emplace_back(s, start, s.size() - start);
|
||||
return out;
|
||||
}
|
||||
|
||||
size_t utf16Length(const std::string &s) {
|
||||
size_t n = 0;
|
||||
forEachIndexed(s, [&](size_t idx, unsigned cp) { n = idx + (cp >= 0x10000 ? 2 : 1); });
|
||||
return n;
|
||||
}
|
||||
|
||||
bool startsWith(const std::string &s, const char *prefix) {
|
||||
size_t n = std::strlen(prefix);
|
||||
return s.size() >= n && s.compare(0, n, prefix) == 0;
|
||||
}
|
||||
|
||||
bool toIntOrNull(const std::string &s, int &out, int radix) {
|
||||
if (s.empty()) return false;
|
||||
size_t i = 0;
|
||||
bool negative = false;
|
||||
if ((unsigned char)s[0] < '0') { // a possible sign (Kotlin: firstChar < '0')
|
||||
if (s.size() == 1) return false;
|
||||
if (s[0] == '-') negative = true;
|
||||
else if (s[0] != '+') return false;
|
||||
i = 1;
|
||||
}
|
||||
int64_t v = 0;
|
||||
const int64_t limit = negative ? -(int64_t)INT_MIN : (int64_t)INT_MAX;
|
||||
while (i < s.size()) {
|
||||
int d = digitOf(decodeUtf8(s, i), radix);
|
||||
if (d < 0) return false;
|
||||
v = v * radix + d;
|
||||
if (v > limit) return false;
|
||||
}
|
||||
out = (int)(negative ? -v : v);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Java's Double.valueOf grammar (what Kotlin screens toFloatOrNull with):
|
||||
// [\x00-\x20]*[+-]?(NaN|Infinity|((Number)[fFdD]?))[\x00-\x20]*
|
||||
bool toFloatOrNull(const std::string &str, float &out) {
|
||||
size_t b = 0, e = str.size();
|
||||
while (b < e && (unsigned char)str[b] <= 0x20) ++b;
|
||||
while (e > b && (unsigned char)str[e - 1] <= 0x20) --e;
|
||||
if (b == e) return false;
|
||||
std::string s = str.substr(b, e - b);
|
||||
size_t i = 0;
|
||||
bool neg = false;
|
||||
if (s[i] == '+' || s[i] == '-') { neg = s[i] == '-'; ++i; }
|
||||
std::string rest = s.substr(i);
|
||||
if (rest == "NaN") { out = NAN; return true; }
|
||||
if (rest == "Infinity") { out = neg ? -INFINITY : INFINITY; return true; }
|
||||
auto isDec = [](char c) { return c >= '0' && c <= '9'; };
|
||||
auto isHex = [](char c) { return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); };
|
||||
size_t j = i;
|
||||
auto run = [&](auto pred) { size_t n = 0; while (j < s.size() && pred(s[j])) { ++j; ++n; } return n; };
|
||||
if (j + 1 < s.size() && s[j] == '0' && (s[j + 1] == 'x' || s[j + 1] == 'X')) {
|
||||
j += 2;
|
||||
size_t a = run(isHex), f = 0;
|
||||
bool dot = j < s.size() && s[j] == '.';
|
||||
if (dot) { ++j; f = run(isHex); }
|
||||
if (a == 0 && f == 0) return false;
|
||||
if (j >= s.size() || (s[j] != 'p' && s[j] != 'P')) return false;
|
||||
++j;
|
||||
if (j < s.size() && (s[j] == '+' || s[j] == '-')) ++j;
|
||||
if (run(isDec) == 0) return false;
|
||||
} else {
|
||||
size_t a = run(isDec), f = 0;
|
||||
if (j < s.size() && s[j] == '.') { ++j; f = run(isDec); }
|
||||
if (a == 0 && f == 0) return false;
|
||||
if (j < s.size() && (s[j] == 'e' || s[j] == 'E')) {
|
||||
++j;
|
||||
if (j < s.size() && (s[j] == '+' || s[j] == '-')) ++j;
|
||||
if (run(isDec) == 0) return false;
|
||||
}
|
||||
}
|
||||
size_t numEnd = j;
|
||||
if (j < s.size() && (s[j] == 'f' || s[j] == 'F' || s[j] == 'd' || s[j] == 'D')) ++j;
|
||||
if (j != s.size()) return false;
|
||||
std::string num = s.substr(0, numEnd);
|
||||
// strtof reads the C locale's decimal point; keep it right if a host changed it.
|
||||
const char *dp = std::localeconv()->decimal_point;
|
||||
if (dp && std::strcmp(dp, ".") != 0) {
|
||||
size_t p = num.find('.');
|
||||
if (p != std::string::npos) num.replace(p, 1, dp);
|
||||
}
|
||||
out = std::strtof(num.c_str(), nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
int floatToInt(float v) {
|
||||
if (std::isnan(v)) return 0;
|
||||
if (v >= 2147483648.f) return INT_MAX;
|
||||
if (v <= -2147483648.f) return INT_MIN;
|
||||
return (int)v;
|
||||
}
|
||||
|
||||
std::string hexUpper(int v) {
|
||||
uint32_t m = v < 0 ? (uint32_t)0 - (uint32_t)v : (uint32_t)v;
|
||||
std::string r;
|
||||
do { r.insert(r.begin(), "0123456789ABCDEF"[m & 15]); m >>= 4; } while (m);
|
||||
return v < 0 ? "-" + r : r;
|
||||
}
|
||||
|
||||
std::string padStart(const std::string &s, size_t n, char c) {
|
||||
size_t len = utf16Length(s);
|
||||
return len >= n ? s : std::string(n - len, c) + s;
|
||||
}
|
||||
|
||||
std::string replaceAll(const std::string &s, const std::string &from, const std::string &to) {
|
||||
if (from.empty()) return s;
|
||||
std::string out;
|
||||
size_t pos = 0;
|
||||
for (size_t f; (f = s.find(from, pos)) != std::string::npos; pos = f + from.size()) {
|
||||
out.append(s, pos, f - pos);
|
||||
out += to;
|
||||
}
|
||||
out.append(s, pos, std::string::npos);
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace sizzle::io::kt
|
||||
@@ -0,0 +1,55 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
|
||||
// Kotlin/JVM string semantics the file formats rely on, for UTF-8 text: lines
|
||||
// (lineSequence), trim (Char.isWhitespace), split (keeps empty parts), lengths and
|
||||
// indices in UTF-16 units (String.length, forEachIndexed), toIntOrNull (Unicode
|
||||
// decimal digits, as Character.digit) and toFloatOrNull (Java's Float.parseFloat
|
||||
// grammar). Malformed UTF-8 bytes are kept as they are and count as one unit each.
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace sizzle::io::kt {
|
||||
|
||||
/** One code point at s[i], advancing i; malformed bytes come back one at a time. */
|
||||
unsigned decodeUtf8(const std::string &s, size_t &i);
|
||||
/** Kotlin's Char.isWhitespace (Character.isWhitespace || isSpaceChar), BMP. */
|
||||
bool isWhitespace(unsigned cp);
|
||||
/** Character.isDigit's decimal value of [cp] (0..9), or -1. */
|
||||
int decimalDigit(unsigned cp);
|
||||
|
||||
/** text.lineSequence(): split on CRLF, LF and CR. */
|
||||
std::vector<std::string> lines(const std::string &text);
|
||||
/** String.trim(). */
|
||||
std::string trim(const std::string &s);
|
||||
/** String.split(c): every part, empty ones included. */
|
||||
std::vector<std::string> split(const std::string &s, char c);
|
||||
/** String.length (UTF-16 units). */
|
||||
size_t utf16Length(const std::string &s);
|
||||
/** The code points of [s] with their UTF-16 index (as forEachIndexed sees them). */
|
||||
template <typename F> void forEachIndexed(const std::string &s, F f) {
|
||||
size_t i = 0, idx = 0;
|
||||
while (i < s.size()) {
|
||||
unsigned cp = decodeUtf8(s, i);
|
||||
f(idx, cp);
|
||||
idx += cp >= 0x10000 ? 2 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
bool startsWith(const std::string &s, const char *prefix);
|
||||
/** String.toIntOrNull(radix). */
|
||||
bool toIntOrNull(const std::string &s, int &out, int radix = 10);
|
||||
/** String.toFloatOrNull(). */
|
||||
bool toFloatOrNull(const std::string &s, float &out);
|
||||
/** Float.toInt(): NaN -> 0, saturating. */
|
||||
int floatToInt(float v);
|
||||
/** Integer.toString(v, 16), upper-cased. */
|
||||
std::string hexUpper(int v);
|
||||
/** padStart(n, '0'). */
|
||||
std::string padStart(const std::string &s, size_t n, char c = '0');
|
||||
/** replace(from, to) on every non-overlapping occurrence, left to right. */
|
||||
std::string replaceAll(const std::string &s, const std::string &from, const std::string &to);
|
||||
|
||||
} // namespace sizzle::io::kt
|
||||
@@ -0,0 +1,97 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "io/MidiMapIo.hpp"
|
||||
|
||||
#include <set>
|
||||
|
||||
#include "io/KotlinText.hpp"
|
||||
#include "sizzle/Specs.hpp"
|
||||
|
||||
namespace sizzle::io {
|
||||
|
||||
namespace {
|
||||
|
||||
std::string ccKey(const std::string ¶m) { return std::string(MidiMapIo::CC_PREFIX) + param; }
|
||||
|
||||
/// The CC [slot] maps [param] to, or -1 (Kotlin: string(key).toIntOrNull()).
|
||||
int ccOf(const model::ToolboxSlot &slot, const std::string ¶m) {
|
||||
int v = -1;
|
||||
return kt::toIntOrNull(slot.s(ccKey(param).c_str(), ""), v) ? v : -1;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
MidiMap MidiMapIo::fromSlot(const model::ToolboxSlot &slot) {
|
||||
MidiMap m;
|
||||
m.type = slot.type;
|
||||
m.name = slot.name;
|
||||
if (const DeviceSpec *spec = findDevice(slot.type.c_str())) {
|
||||
for (int i = 0; i < spec->paramCount; ++i) {
|
||||
const int cc = ccOf(slot, spec->params[i].key);
|
||||
if (cc >= 0 && cc <= 127) m.bindings.emplace_back(spec->params[i].key, cc);
|
||||
}
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
std::string MidiMapIo::save(const MidiMap &map) {
|
||||
std::string out = std::string(HEADER) + "\n";
|
||||
out += "# Sizzle MIDI mapping: parameter=CC number (0-127), one per line.\n";
|
||||
out += "TYPE=" + map.type + "\n";
|
||||
out += "NAME=" + map.name + "\n";
|
||||
for (const auto &[key, cc] : map.bindings) out += key + "=" + std::to_string(cc) + "\n";
|
||||
return out;
|
||||
}
|
||||
|
||||
std::optional<MidiMap> MidiMapIo::parse(const std::string &text) {
|
||||
MidiMap m;
|
||||
bool header = false, typed = false;
|
||||
std::set<std::string> keys;
|
||||
std::set<int> ccs;
|
||||
for (const std::string &raw : kt::lines(text)) {
|
||||
const std::string line = kt::trim(raw);
|
||||
if (line.empty() || line[0] == '#') continue;
|
||||
if (line == HEADER) { header = true; continue; }
|
||||
const size_t eq = line.find('=');
|
||||
if (eq == std::string::npos || eq == 0) continue;
|
||||
const std::string key = kt::trim(line.substr(0, eq)), value = kt::trim(line.substr(eq + 1));
|
||||
if (key == "TYPE") { m.type = value; typed = !value.empty(); continue; }
|
||||
if (key == "NAME") { m.name = value; continue; }
|
||||
int cc = -1;
|
||||
if (!kt::toIntOrNull(value, cc) || cc < 0 || cc > 127 || keys.count(key) || ccs.count(cc)) continue;
|
||||
keys.insert(key);
|
||||
ccs.insert(cc);
|
||||
m.bindings.emplace_back(key, cc);
|
||||
}
|
||||
if (!header || !typed) return std::nullopt;
|
||||
return m;
|
||||
}
|
||||
|
||||
int MidiMapIo::apply(model::Project &project, int slot, const MidiMap &map) {
|
||||
if (slot < 0 || slot >= model::Project::TOOLBOX_SLOTS) return -1;
|
||||
model::ToolboxSlot &target = project.toolbox[(size_t)slot];
|
||||
if (target.type != map.type) return -1;
|
||||
const DeviceSpec *spec = findDevice(target.type.c_str());
|
||||
if (!spec) return -1;
|
||||
for (int i = 0; i < spec->paramCount; ++i) target.values.remove(ccKey(spec->params[i].key).c_str());
|
||||
int applied = 0;
|
||||
for (const auto &[key, cc] : map.bindings) {
|
||||
bool known = false;
|
||||
for (int i = 0; i < spec->paramCount && !known; ++i) known = key == spec->params[i].key;
|
||||
if (!known) continue;
|
||||
// One physical control drives one parameter: take the CC from wherever it was.
|
||||
for (auto &s : project.toolbox) {
|
||||
if (s.isEmpty()) continue;
|
||||
const DeviceSpec *other = findDevice(s.type.c_str());
|
||||
for (int i = 0; other && i < other->paramCount; ++i)
|
||||
if (ccOf(s, other->params[i].key) == cc) s.values.remove(ccKey(other->params[i].key).c_str());
|
||||
}
|
||||
target.set(ccKey(key).c_str(), std::to_string(cc).c_str());
|
||||
++applied;
|
||||
}
|
||||
++target.version;
|
||||
return applied;
|
||||
}
|
||||
|
||||
} // namespace sizzle::io
|
||||
@@ -0,0 +1,52 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// A device's MIDI mapping as plain text (.szm), the same format the Android app
|
||||
// reads and writes (io/MidiMapIo.kt):
|
||||
//
|
||||
// SIZZLE-MIDIMAP 1
|
||||
// # comments start with '#'
|
||||
// TYPE=WAVETABLE
|
||||
// NAME=Lead
|
||||
// cutoff=74
|
||||
// resonance=71
|
||||
//
|
||||
// One `parameter=CC` line per mapped parameter (CC 0..127), in the device's
|
||||
// parameter order. In the song a mapping is the slot value `midicc@<parameter>`.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "sizzle/Model.hpp"
|
||||
|
||||
namespace sizzle::io {
|
||||
|
||||
struct MidiMap {
|
||||
std::string type; // ToolboxType name
|
||||
std::string name; // the slot's name when exported (informational)
|
||||
std::vector<std::pair<std::string, int>> bindings; // parameter key, CC
|
||||
};
|
||||
|
||||
class MidiMapIo {
|
||||
public:
|
||||
static constexpr const char *HEADER = "SIZZLE-MIDIMAP 1";
|
||||
static constexpr const char *CC_PREFIX = "midicc@";
|
||||
|
||||
/** [slot]'s mappings, in its device's parameter order. */
|
||||
static MidiMap fromSlot(const model::ToolboxSlot &slot);
|
||||
static std::string save(const MidiMap &map);
|
||||
/** The mapping in [text], or nothing if it has no header or TYPE. Lines that
|
||||
* aren't `key=CC` with CC 0..127 are skipped; a repeated key or CC keeps its
|
||||
* first line (one control drives one parameter). */
|
||||
static std::optional<MidiMap> parse(const std::string &text);
|
||||
/** Replace toolbox [slot]'s mappings with [map]'s: only parameters its device
|
||||
* has; a CC another parameter (of any slot) used moves to this one. Returns
|
||||
* how many were applied, or -1 when [map] is for another device type. */
|
||||
static int apply(model::Project &project, int slot, const MidiMap &map);
|
||||
};
|
||||
|
||||
} // namespace sizzle::io
|
||||
@@ -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,69 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "io/PresetIo.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "io/KotlinText.hpp"
|
||||
#include "sizzle/Specs.hpp"
|
||||
|
||||
namespace sizzle::io {
|
||||
|
||||
using namespace model;
|
||||
|
||||
std::string PresetIo::exportText(const ToolboxSlot &slot) {
|
||||
if (slot.isEmpty()) return std::string(HEADER) + "\nTYPE=EMPTY";
|
||||
const DeviceSpec *spec = findDevice(slot.type.c_str());
|
||||
std::string o;
|
||||
auto line = [&](const std::string &s) { o += s; o += '\n'; };
|
||||
line(HEADER);
|
||||
line("TYPE=" + slot.type);
|
||||
line("NAME=" + slot.name);
|
||||
// Params in the type's declared order, then any extra keys the slot holds.
|
||||
const int n = spec ? spec->paramCount : 0;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
const ParamSpec &p = spec->params[i];
|
||||
line(std::string(p.key) + "=" + slot.s(p.key, kotlinFloatToString(p.def).c_str()));
|
||||
}
|
||||
for (int i = 0; i < slot.values.size(); ++i) {
|
||||
const char *key = slot.values.keyAt(i);
|
||||
bool declared = false;
|
||||
for (int k = 0; k < n && !declared; ++k) declared = std::strcmp(spec->params[k].key, key) == 0;
|
||||
if (!declared) line(std::string(key) + "=" + slot.values.valueAt(i));
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
bool PresetIo::importText(ToolboxSlot &slot, const std::string &text) {
|
||||
std::vector<std::pair<std::string, std::string>> map; // a LinkedHashMap
|
||||
std::unordered_map<std::string, size_t> index;
|
||||
std::string type;
|
||||
bool hasType = false;
|
||||
for (const std::string &raw : kt::lines(text)) {
|
||||
const std::string line = kt::trim(raw);
|
||||
if (line.empty() || line == HEADER) continue;
|
||||
const size_t eq = line.find('=');
|
||||
if (eq == std::string::npos) continue;
|
||||
std::string key = line.substr(0, eq), value = line.substr(eq + 1);
|
||||
if (key == "TYPE") {
|
||||
hasType = value.find('\0') == std::string::npos && findDevice(value.c_str()) != nullptr;
|
||||
type = hasType ? value : std::string();
|
||||
} else if (key == "NAME") {
|
||||
slot.name = value;
|
||||
} else {
|
||||
auto it = index.find(key);
|
||||
if (it != index.end()) map[it->second].second = std::move(value);
|
||||
else { index.emplace(key, map.size()); map.emplace_back(std::move(key), std::move(value)); }
|
||||
}
|
||||
}
|
||||
if (!hasType) return false;
|
||||
slot.fill(type); // reset to defaults for the type (and its display name) ...
|
||||
if (kt::trim(slot.name).empty()) slot.name = findDevice(type.c_str())->displayName;
|
||||
for (const auto &kv : map) slot.set(kv.first.c_str(), kv.second.c_str()); // ... then the saved values
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace sizzle::io
|
||||
@@ -0,0 +1,23 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
|
||||
// Port of io/PresetIo.kt: one device's settings as text ("SIZZLE-PRESET 1",
|
||||
// TYPE=, NAME=, then key=value in the device's parameter order, then any extra
|
||||
// keys the slot holds, e.g. sample ids).
|
||||
|
||||
#include <string>
|
||||
#include "sizzle/Model.hpp"
|
||||
|
||||
namespace sizzle::io {
|
||||
|
||||
struct PresetIo {
|
||||
static constexpr const char *HEADER = "SIZZLE-PRESET 1";
|
||||
static std::string exportText(const model::ToolboxSlot &slot);
|
||||
/** Parse preset [text] into [slot]; false (slot settings untouched) unless a
|
||||
* known TYPE is found. As in Kotlin, the slot's name ends up as the device's
|
||||
* display name: NAME is applied before fill(), which overwrites it. */
|
||||
static bool importText(model::ToolboxSlot &slot, const std::string &text);
|
||||
};
|
||||
|
||||
} // namespace sizzle::io
|
||||
@@ -0,0 +1,295 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "io/ProjectIo.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include "io/KotlinText.hpp"
|
||||
#include "sizzle/Specs.hpp"
|
||||
|
||||
namespace sizzle::io {
|
||||
|
||||
using namespace model;
|
||||
|
||||
static const char *HEADER = "SIZZLETRACKER-SNG 1";
|
||||
|
||||
static const char *b(bool v) { return v ? "1" : "0"; }
|
||||
|
||||
// ------------------------------------------------------------------- write
|
||||
std::string ProjectIo::save(const Project &project) {
|
||||
std::string o;
|
||||
auto line = [&](const std::string &s) { o += s; o += '\n'; };
|
||||
auto num = [](int v) { return std::to_string(v); };
|
||||
line(HEADER);
|
||||
line("NAME=" + project.name);
|
||||
line("TEMPO=" + kotlinFloatToString(project.tempoBpm));
|
||||
line(std::string("SIG=") + info(project.timeSignature).name);
|
||||
line(std::string("SCALE=") + info(project.scale).name);
|
||||
line("ROOT=" + num(project.rootNote));
|
||||
line("ACTIVE=" + num(project.activePatternId));
|
||||
|
||||
for (const Pattern &p : project.patterns) {
|
||||
line("[PATTERN id=" + num(p.id) + " name=" + encodeName(p.name) + " len=" + num(p.length) + "]");
|
||||
for (int t = 0; t < Pattern::TRACK_COUNT; ++t) {
|
||||
const int n = std::min(p.length, (int)p.tracks[t].size());
|
||||
for (int ln = 0; ln < n; ++ln) {
|
||||
const Cell &c = p.tracks[t][ln];
|
||||
if (!c.isEmpty())
|
||||
line(num(t) + "," + num(ln) + "," + num(c.note) + "," + num(c.velocity) + "," + num(c.channel));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const Arrangement &arr = project.arrangement;
|
||||
std::string mutes;
|
||||
for (bool m : arr.laneMuted) mutes += m ? '1' : '0';
|
||||
line("[ARRANGEMENT bars=" + num(arr.lengthBars) + " loop=" + b(arr.loopEnabled) + " mutes=" + mutes + "]");
|
||||
const int usedBeats = arr.lastFilledBeat() + 1;
|
||||
for (int lane = 0; lane < Arrangement::LANE_COUNT; ++lane) {
|
||||
for (int beat = 0; beat < usedBeats; ++beat) {
|
||||
const int pid = arr.slots[lane][beat];
|
||||
// >= 0 is a block id; NOTE_OFF is a marker and must survive too.
|
||||
if (pid >= 0 || pid == Arrangement::NOTE_OFF) line(num(lane) + "," + num(beat) + "," + num(pid));
|
||||
}
|
||||
}
|
||||
auto region = [&](const char *n, const LoopRegion &r) {
|
||||
line(std::string("[REGION ") + n + " en=" + b(r.enabled) + " s=" + num(r.start) + " e=" + num(r.end) +
|
||||
" r=" + num(r.repeats) + "]");
|
||||
};
|
||||
region("A", arr.regionA);
|
||||
region("B", arr.regionB);
|
||||
|
||||
line("[MIXER]");
|
||||
for (const MixerChannel &ch : project.mixer.channels) {
|
||||
std::string s = num(ch.index) + "," + num(ch.instrumentSlot) + ",";
|
||||
for (int i = 0; i < MixerChannel::FX_SLOTS; ++i) s += (i ? "," : "") + num(ch.fxSlots[i]);
|
||||
s += "," + num(ch.midiChannel) + "," + kotlinFloatToString(ch.volume) + "," + b(ch.mute) + "," +
|
||||
b(ch.solo) + "," + b(ch.limiter);
|
||||
line(s);
|
||||
}
|
||||
|
||||
line("[TOOLBOX]");
|
||||
for (const ToolboxSlot &slot : project.toolbox) {
|
||||
if (slot.isEmpty()) continue;
|
||||
std::string s = num(slot.index) + "=" + slot.type + ";" + slot.name + ";";
|
||||
for (int i = 0; i < slot.values.size(); ++i) {
|
||||
if (i) s += ',';
|
||||
s += slot.values.keyAt(i);
|
||||
s += '=';
|
||||
s += slot.values.valueAt(i);
|
||||
}
|
||||
line(s);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------- read
|
||||
namespace {
|
||||
|
||||
/** parseAttrs: "[NAME k=v k=v]" -> {k: v}; the last duplicate wins. */
|
||||
std::map<std::string, std::string> parseAttrs(const std::string &line) {
|
||||
size_t a = 0, z = line.size();
|
||||
while (a < z && (line[a] == '[' || line[a] == ']')) ++a;
|
||||
while (z > a && (line[z - 1] == '[' || line[z - 1] == ']')) --z;
|
||||
const std::string inner = line.substr(a, z - a);
|
||||
const size_t sp = inner.find(' ');
|
||||
std::map<std::string, std::string> out;
|
||||
if (sp == std::string::npos) return out;
|
||||
for (const std::string &tok : kt::split(inner.substr(sp + 1), ' ')) {
|
||||
const size_t eq = tok.find('=');
|
||||
if (eq != std::string::npos) out[tok.substr(0, eq)] = tok.substr(eq + 1);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
const std::string *get(const std::map<std::string, std::string> &m, const char *k) {
|
||||
auto it = m.find(k);
|
||||
return it == m.end() ? nullptr : &it->second;
|
||||
}
|
||||
|
||||
int intOr(const std::string *s, int fallback) {
|
||||
int v;
|
||||
return s && kt::toIntOrNull(*s, v) ? v : fallback;
|
||||
}
|
||||
|
||||
int intOr(const std::string &s, int fallback) { return intOr(&s, fallback); }
|
||||
|
||||
void applyHeaderField(Project &p, const std::string &line) {
|
||||
const size_t eq = line.find('=');
|
||||
const std::string k = line.substr(0, eq), v = line.substr(eq + 1);
|
||||
if (k == "NAME") p.name = v;
|
||||
else if (k == "TEMPO") { float f; p.tempoBpm = kt::toFloatOrNull(v, f) ? f : 120.f; }
|
||||
else if (k == "SIG") {
|
||||
p.timeSignature = TimeSignature::FOUR_FOUR;
|
||||
for (int i = 0; i < TIME_SIGNATURE_COUNT; ++i)
|
||||
if (v == info((TimeSignature)i).name) p.timeSignature = (TimeSignature)i;
|
||||
} else if (k == "SCALE") {
|
||||
p.scale = Scale::CHROMATIC;
|
||||
for (int i = 0; i < SCALE_COUNT; ++i)
|
||||
if (v == info((Scale)i).name) p.scale = (Scale)i;
|
||||
} else if (k == "ROOT") p.rootNote = intOr(v, 0);
|
||||
else if (k == "ACTIVE") p.activePatternId = intOr(v, 0);
|
||||
}
|
||||
|
||||
void applyPatternCell(Pattern *pattern, const std::string &line) {
|
||||
if (!pattern) return;
|
||||
Pattern &p = *pattern;
|
||||
const auto f = kt::split(line, ',');
|
||||
if (f.size() < 5) return;
|
||||
int t, ln;
|
||||
if (!kt::toIntOrNull(f[0], t) || !kt::toIntOrNull(f[1], ln)) return;
|
||||
if (t < 0 || t >= Pattern::TRACK_COUNT || ln < 0 || ln >= p.length || ln >= (int)p.tracks[t].size()) return;
|
||||
Cell &c = p.tracks[t][ln];
|
||||
c.note = intOr(f[2], Cell::EMPTY);
|
||||
c.velocity = std::clamp(intOr(f[3], Cell::MAX_VELOCITY), 0, (int)Cell::MAX_VELOCITY);
|
||||
c.channel = std::clamp(intOr(f[4], 1), 1, (int)Cell::MAX_CHANNEL);
|
||||
}
|
||||
|
||||
void applyArrangementSlot(Project &p, const std::string &line) {
|
||||
const auto f = kt::split(line, ',');
|
||||
if (f.size() < 3) return;
|
||||
int lane, beat, pid;
|
||||
if (!kt::toIntOrNull(f[0], lane) || !kt::toIntOrNull(f[1], beat) || !kt::toIntOrNull(f[2], pid)) return;
|
||||
p.arrangement.set(lane, beat, pid);
|
||||
}
|
||||
|
||||
void applyRegion(LoopRegion &r, const std::map<std::string, std::string> &a) {
|
||||
const std::string *en = get(a, "en");
|
||||
r.enabled = en && *en == "1";
|
||||
r.start = intOr(get(a, "s"), 0);
|
||||
r.end = intOr(get(a, "e"), 0);
|
||||
r.repeats = intOr(get(a, "r"), 2);
|
||||
}
|
||||
|
||||
void applyMixerRow(Project &p, const std::string &line) {
|
||||
const auto f = kt::split(line, ',');
|
||||
if (f.size() < 10) return;
|
||||
int idx;
|
||||
if (!kt::toIntOrNull(f[0], idx) || idx < 0 || idx >= Mixer::CHANNEL_COUNT) return;
|
||||
MixerChannel &ch = p.mixer.channels[idx];
|
||||
ch.instrumentSlot = intOr(f[1], -1);
|
||||
for (int i = 0; i < Mixer::FX_SLOTS; ++i) ch.fxSlots[i] = intOr(f[2 + i], -1);
|
||||
ch.midiChannel = intOr(f[6], 0);
|
||||
float v;
|
||||
ch.volume = kt::toFloatOrNull(f[7], v) ? v : 0.8f;
|
||||
ch.mute = f[8] == "1";
|
||||
ch.solo = f[9] == "1";
|
||||
ch.limiter = f.size() > 10 && f[10] == "1"; // optional: absent in older saves
|
||||
}
|
||||
|
||||
void applyToolboxRow(Project &p, const std::string &line) {
|
||||
const size_t eq = line.find('=');
|
||||
int idx;
|
||||
if (!kt::toIntOrNull(line.substr(0, eq), idx)) return;
|
||||
const std::string rest = eq == std::string::npos ? line : line.substr(eq + 1);
|
||||
const auto parts = kt::split(rest, ';');
|
||||
if (parts.size() < 2) return;
|
||||
if (!findDevice(parts[0].c_str()) || parts[0].find('\0') != std::string::npos) return;
|
||||
if (idx < 0 || idx >= Project::TOOLBOX_SLOTS) return;
|
||||
ToolboxSlot &slot = p.toolbox[idx];
|
||||
slot.fill(parts[0]);
|
||||
slot.name = parts[1];
|
||||
if (parts.size() >= 3 && !kt::trim(parts[2]).empty()) {
|
||||
for (const std::string &kv : kt::split(parts[2], ',')) {
|
||||
const size_t e = kv.find('=');
|
||||
if (e != std::string::npos) slot.set(kv.substr(0, e).c_str(), kv.substr(e + 1).c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
model::Project &ProjectIo::loadInto(Project &project, const std::string &text) {
|
||||
// Reset everything Kotlin resets to a clean slate first.
|
||||
project.patterns.clear();
|
||||
for (auto &lane : project.arrangement.slots) std::fill(lane.begin(), lane.end(), Arrangement::EMPTY);
|
||||
project.arrangement.laneMuted.fill(false);
|
||||
for (auto &slot : project.toolbox) slot.clearSlot();
|
||||
for (auto &ch : project.mixer.channels) {
|
||||
ch.instrumentSlot = -1; ch.fxSlots.fill(-1); ch.midiChannel = 0;
|
||||
ch.volume = 0.8f; ch.mute = false; ch.solo = false; ch.limiter = false;
|
||||
}
|
||||
std::string section;
|
||||
int current = -1; // index into project.patterns (Kotlin keeps a reference)
|
||||
long cells = 0;
|
||||
|
||||
for (const std::string &raw : kt::lines(text)) {
|
||||
const std::string line = kt::trim(raw);
|
||||
if (line.empty()) continue;
|
||||
if (line == HEADER) {
|
||||
} else if (kt::startsWith(line, "[PATTERN")) {
|
||||
const auto attrs = parseAttrs(line);
|
||||
const int id = intOr(get(attrs, "id"), (int)project.patterns.size());
|
||||
const std::string *name = get(attrs, "name");
|
||||
const int len = intOr(get(attrs, "len"), 16);
|
||||
// Kotlin: a negative length throws in Pattern's constructor (line skipped);
|
||||
// a huge one runs out of memory (also skipped).
|
||||
if (len < 0 || cells + 4L * len > MAX_TOTAL_CELLS) continue;
|
||||
cells += 4L * len;
|
||||
project.patterns.emplace_back(id, name ? decodeName(*name) : std::string("PTN"), len);
|
||||
current = (int)project.patterns.size() - 1;
|
||||
section = "PATTERN";
|
||||
} else if (kt::startsWith(line, "[ARRANGEMENT")) {
|
||||
const auto attrs = parseAttrs(line);
|
||||
// "bars" is the canvas unit; older files stored "len" in beats and get the
|
||||
// default 256-bar canvas.
|
||||
project.arrangement.lengthBars = intOr(get(attrs, "bars"), Arrangement::MAX_BARS);
|
||||
const std::string *loop = get(attrs, "loop");
|
||||
project.arrangement.loopEnabled = loop && *loop == "1";
|
||||
if (const std::string *m = get(attrs, "mutes")) {
|
||||
auto &lanes = project.arrangement.laneMuted;
|
||||
kt::forEachIndexed(*m, [&](size_t i, unsigned cp) {
|
||||
if (i < lanes.size()) lanes[i] = cp == '1';
|
||||
});
|
||||
}
|
||||
section = "ARRANGEMENT";
|
||||
} else if (kt::startsWith(line, "[REGION A")) {
|
||||
applyRegion(project.arrangement.regionA, parseAttrs(line));
|
||||
} else if (kt::startsWith(line, "[REGION B")) {
|
||||
applyRegion(project.arrangement.regionB, parseAttrs(line));
|
||||
} else if (kt::startsWith(line, "[MIXER]")) {
|
||||
section = "MIXER";
|
||||
} else if (kt::startsWith(line, "[TOOLBOX]")) {
|
||||
section = "TOOLBOX";
|
||||
} else if (line.find('=') != std::string::npos && line[0] != '[' && section.empty()) {
|
||||
applyHeaderField(project, line);
|
||||
} else if (section == "PATTERN") {
|
||||
applyPatternCell(current >= 0 ? &project.patterns[current] : nullptr, line);
|
||||
} else if (section == "ARRANGEMENT") {
|
||||
applyArrangementSlot(project, line);
|
||||
} else if (section == "MIXER") {
|
||||
applyMixerRow(project, line);
|
||||
} else if (section == "TOOLBOX") {
|
||||
applyToolboxRow(project, line);
|
||||
}
|
||||
}
|
||||
// One block per lane (lane i is tied to block i): pad any the file did not define.
|
||||
for (int id = 0; id < Arrangement::LANE_COUNT; ++id) {
|
||||
if (!project.pattern(id)) project.patterns.emplace_back(id, "BLK" + std::to_string(id + 1), 16);
|
||||
}
|
||||
std::stable_sort(project.patterns.begin(), project.patterns.end(),
|
||||
[](const Pattern &a, const Pattern &b) { return a.id < b.id; });
|
||||
project.activePatternId = std::clamp(project.activePatternId, 0, (int)project.patterns.size() - 1);
|
||||
return project;
|
||||
}
|
||||
|
||||
std::string ProjectIo::encodeName(const std::string &name) {
|
||||
std::string o;
|
||||
for (char c : name) {
|
||||
switch (c) {
|
||||
case '%': o += "%25"; break;
|
||||
case ' ': o += "%20"; break;
|
||||
case ']': o += "%5D"; break;
|
||||
case '\t': case '\n': case '\r': o += "%20"; break;
|
||||
default: o += c;
|
||||
}
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
std::string ProjectIo::decodeName(const std::string &text) {
|
||||
return kt::replaceAll(kt::replaceAll(kt::replaceAll(text, "%20", " "), "%5D", "]"), "%25", "%");
|
||||
}
|
||||
|
||||
} // namespace sizzle::io
|
||||
@@ -0,0 +1,32 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
|
||||
// Port of io/ProjectIo.kt: the full project format (.szg, "SIZZLETRACKER-SNG 1").
|
||||
// Files written by the Kotlin app load and save back byte for byte, except that
|
||||
// each [TOOLBOX] line lists its key=value pairs in the slot's insertion order where
|
||||
// Kotlin wrote ConcurrentHashMap order (both read back the same).
|
||||
|
||||
#include <string>
|
||||
#include "sizzle/Model.hpp"
|
||||
|
||||
namespace sizzle::io {
|
||||
|
||||
struct ProjectIo {
|
||||
static std::string save(const model::Project &project);
|
||||
/** Parse [text] into the existing [project], replacing its contents (what
|
||||
* Kotlin resets; header fields missing from the file keep their values).
|
||||
* Malformed lines are skipped one by one, as Kotlin's runCatching does. */
|
||||
static model::Project &loadInto(model::Project &project, const std::string &text);
|
||||
|
||||
/** Block names go into a whitespace-split header: escape space, '%' and ']'. */
|
||||
static std::string encodeName(const std::string &name);
|
||||
static std::string decodeName(const std::string &text);
|
||||
|
||||
/** Not in Kotlin (it would run out of memory and skip the line): a [PATTERN]
|
||||
* line whose length would take the file's patterns past this many cells is
|
||||
* skipped, so an untrusted file can't allocate without bound. */
|
||||
static constexpr long MAX_TOTAL_CELLS = 1L << 22;
|
||||
};
|
||||
|
||||
} // namespace sizzle::io
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user