Compare commits
47
Commits
68e9ed8b41
..
main
@@ -16,3 +16,6 @@ dist/
|
|||||||
|
|
||||||
# NOTE: gradle/wrapper/gradle-wrapper.jar IS committed (Gradle's recommended
|
# NOTE: gradle/wrapper/gradle-wrapper.jar IS committed (Gradle's recommended
|
||||||
# practice) so ./gradlew works on a fresh clone with no extra setup.
|
# 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/
|
||||||
|
|||||||
+253
@@ -0,0 +1,253 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
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). 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)
|
||||||
|
|
||||||
|
- **Device editors redesigned:** instruments and effects no longer show two
|
||||||
|
columns of horizontal sliders. Their controls are grouped into titled cards by
|
||||||
|
what they do (oscillators, filter, envelopes, modulation, output), each tinted
|
||||||
|
by its role, with knobs for numbers, segmented switches for short choices and
|
||||||
|
tabs for the bigger devices. Envelope, filter-response and LFO-wave drawings
|
||||||
|
follow the knobs live. Values read in their units (ms / s, dB, semitones, cents,
|
||||||
|
%, note divisions). The 10-Band EQ is a graphic EQ of vertical faders. Applies
|
||||||
|
to Wavetable, Morph Pad, Grain Cloud, Ambience, Filter, EQ, Bitcrusher and the
|
||||||
|
MIDI Arpeggiator / Transposer / LFO; the Tape Delay's feedback, mix and tape
|
||||||
|
controls are knobs. The Synth's editor is unchanged.
|
||||||
|
|
||||||
|
## 0.34.0 (versionCode 65)
|
||||||
|
|
||||||
|
- **Recording follows MIDI clock:** while ● ARM is on, an external clock Start (or
|
||||||
|
Continue) starts the master recording and its Stop ends it after the TAIL, the
|
||||||
|
same as Sizzle's own Play/Stop. Works in sound-module mode, where the clock
|
||||||
|
doesn't start Sizzle's song, and whether or not "Receive MIDI clock" is on.
|
||||||
|
Sizzle's own Stop also ends a clock-started take.
|
||||||
|
|
||||||
|
## 0.33.0 (versionCode 64)
|
||||||
|
|
||||||
|
- **Mix tab:** long-press an instrument or FX slot to open that device's settings
|
||||||
|
(the Toolbox editor); closing it returns to the Mix. A short tap still picks the
|
||||||
|
device.
|
||||||
|
|
||||||
|
## 0.32.0 (versionCode 63)
|
||||||
|
|
||||||
|
- **Wavetable**, a new two-oscillator wavetable synth: twelve built-in tables
|
||||||
|
(Classic, PWM, Vowels, Harmonic Sweep, Sync, FM, Organ, Fold, Digital, Glass,
|
||||||
|
Odd Even, Comb), Serum / WaveEdit WAV import, position swept by its own envelope
|
||||||
|
and a tempo-synced LFO, phase bend, up to 4-voice unison, sub, noise, drive and a
|
||||||
|
low/band/high filter. Band-limited per octave, so high notes don't alias. 12
|
||||||
|
factory presets. Written for Sizzle (GPL-3.0-or-later), not ported.
|
||||||
|
|
||||||
|
## 0.31.0 (versionCode 62)
|
||||||
|
|
||||||
|
- **Grain Cloud**, a new granular drone instrument: ECHOFIELD's grain engine (by
|
||||||
|
Philip Bos, an M-VAVE FM-1 firmware) ported to Kotlin. Six modes (Cloud, Dust,
|
||||||
|
Tape, Bloom, Pulse, Drift), up to 32 grains per channel, held notes pitch the
|
||||||
|
grains, freeze, and an auto-level that keeps every sound at one loudness. Ten
|
||||||
|
built-in sources synthesised by Sizzle, or load / record your own (kept across
|
||||||
|
restarts). 14 factory presets. Plays from the tracker, the toolbox keyboard and
|
||||||
|
live MIDI.
|
||||||
|
- The ported files (`echofield/`) are MIT, as ECHOFIELD is (`LICENSES/MIT.txt`).
|
||||||
|
|
||||||
|
## 0.30.0 (versionCode 61)
|
||||||
|
|
||||||
|
- **Morph Pad**, a new instrument for evolving pads and drones: the drone voice of
|
||||||
|
FRASIL (a custom firmware for the M-VAVE FM-1 by Styves Goupil), ported to
|
||||||
|
Kotlin. A detuned saw choir, eight drifting additive partials and noise through
|
||||||
|
resonators, slow random motion and a shared tide on the timbre. Morph toward
|
||||||
|
any of the 36 factory sounds by hand, by MIDI LFO or over a set time while a
|
||||||
|
note is held. Plays from the tracker, the toolbox keyboard and live MIDI
|
||||||
|
(including sound-module mode).
|
||||||
|
- The ported files (`frasil/`) are MPL-2.0, as FRASIL is; the licence text is in
|
||||||
|
`LICENSES/MPL-2.0.txt`. The rest of Sizzle stays GPL-3.0-or-later.
|
||||||
|
|
||||||
|
## 0.29.2 (versionCode 60)
|
||||||
|
|
||||||
|
- While Sizzle runs as a MIDI sound module, another app's clock Start/Stop no
|
||||||
|
longer starts or stops Sizzle's own song (tempo is still followed). Before, a
|
||||||
|
song opened from Mikro Seq played along with Mikro Seq's live notes, doubling
|
||||||
|
parts that Mikro Seq's mutes couldn't silence.
|
||||||
|
|
||||||
|
## 0.29.1 (versionCode 59)
|
||||||
|
|
||||||
|
- **MIDI trace** for checking what reaches Sizzle and what it plays: every
|
||||||
|
received packet (bytes, lateness) and every note with the mixer strips it
|
||||||
|
reaches, flagged when Sizzle's own transport is also playing. Off by default;
|
||||||
|
`adb shell setprop log.tag.SizzleMidiTrace VERBOSE`, then
|
||||||
|
`adb logcat -s SizzleMidiTrace`.
|
||||||
|
- Block names with spaces (e.g. Mikro Seq's "C1 muted") survive the autosave and
|
||||||
|
project save/load (they were cut at the first space).
|
||||||
|
- "Receive MIDI clock" now says that it starts Sizzle's own song, which then
|
||||||
|
plays along with the notes another app sends.
|
||||||
|
|
||||||
|
## 0.29.0 (versionCode 58)
|
||||||
|
|
||||||
|
- **MIDI inputs list** (Setup → MIDI Sync): every MIDI source Sizzle can hear
|
||||||
|
(controllers, other apps' virtual ports such as Mikro Seq), each with a switch
|
||||||
|
and its state (Listening / Not connected / Off), plus a **Reconnect** button.
|
||||||
|
The choice is saved; new sources are on by default.
|
||||||
|
- **Automatic reconnect** when the app behind a virtual source restarts (crash,
|
||||||
|
update, force stop). Android gives no signal for that and left Sizzle holding a
|
||||||
|
dead connection, so Mikro Seq could play into nothing. Sizzle now checks open
|
||||||
|
virtual sources every 3 s and reopens a dead one, and re-scans on every resume.
|
||||||
|
|
||||||
|
## 0.28.0 (versionCode 57)
|
||||||
|
|
||||||
|
- **Background MIDI sound module.** New setting "Keep running as MIDI sound
|
||||||
|
module" (Setup → MIDI Sync). While on, a foreground service with a notification
|
||||||
|
(open-source count, Stop) keeps Sizzle from being frozen in the background, so
|
||||||
|
another app such as Mikro Seq can play Sizzle's mixer over MIDI with Sizzle's
|
||||||
|
transport stopped and its screen gone.
|
||||||
|
- MIDI notes are now played by a sound-module layer that lives with the engine,
|
||||||
|
not the UI. The UI still shows them and punch-in still records them.
|
||||||
|
- Notes held by a MIDI source are released when it disconnects; All Notes Off
|
||||||
|
(CC 123) and All Sound Off (CC 120) release a channel.
|
||||||
|
- MIDI input understands running status and messages split across packets.
|
||||||
|
- MIDI clock follow (Start/Stop/tempo) works without the UI.
|
||||||
|
- **Open `.sng` from other apps**: "Open with" / "Share to" Sizzletracker for
|
||||||
|
`.sng` files (`application/octet-stream`, `text/plain`,
|
||||||
|
`application/x-sizzle-song`, or the `.sng` extension). Sizzle asks before it
|
||||||
|
replaces the current song's patterns and arrangement.
|
||||||
|
- `.sng` import follows the desktop reader: block names with spaces, `#`
|
||||||
|
comments, `loop`, `group`/`scale`/`root` lines, track slots by number with
|
||||||
|
fallback, on-roll blocks kept first when a file has more than 8, block length
|
||||||
|
capped. Mikro Seq exports in 4/4 and 3/4 import correctly.
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2026 Philip Bos
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,373 @@
|
|||||||
|
Mozilla Public License Version 2.0
|
||||||
|
==================================
|
||||||
|
|
||||||
|
1. Definitions
|
||||||
|
--------------
|
||||||
|
|
||||||
|
1.1. "Contributor"
|
||||||
|
means each individual or legal entity that creates, contributes to
|
||||||
|
the creation of, or owns Covered Software.
|
||||||
|
|
||||||
|
1.2. "Contributor Version"
|
||||||
|
means the combination of the Contributions of others (if any) used
|
||||||
|
by a Contributor and that particular Contributor's Contribution.
|
||||||
|
|
||||||
|
1.3. "Contribution"
|
||||||
|
means Covered Software of a particular Contributor.
|
||||||
|
|
||||||
|
1.4. "Covered Software"
|
||||||
|
means Source Code Form to which the initial Contributor has attached
|
||||||
|
the notice in Exhibit A, the Executable Form of such Source Code
|
||||||
|
Form, and Modifications of such Source Code Form, in each case
|
||||||
|
including portions thereof.
|
||||||
|
|
||||||
|
1.5. "Incompatible With Secondary Licenses"
|
||||||
|
means
|
||||||
|
|
||||||
|
(a) that the initial Contributor has attached the notice described
|
||||||
|
in Exhibit B to the Covered Software; or
|
||||||
|
|
||||||
|
(b) that the Covered Software was made available under the terms of
|
||||||
|
version 1.1 or earlier of the License, but not also under the
|
||||||
|
terms of a Secondary License.
|
||||||
|
|
||||||
|
1.6. "Executable Form"
|
||||||
|
means any form of the work other than Source Code Form.
|
||||||
|
|
||||||
|
1.7. "Larger Work"
|
||||||
|
means a work that combines Covered Software with other material, in
|
||||||
|
a separate file or files, that is not Covered Software.
|
||||||
|
|
||||||
|
1.8. "License"
|
||||||
|
means this document.
|
||||||
|
|
||||||
|
1.9. "Licensable"
|
||||||
|
means having the right to grant, to the maximum extent possible,
|
||||||
|
whether at the time of the initial grant or subsequently, any and
|
||||||
|
all of the rights conveyed by this License.
|
||||||
|
|
||||||
|
1.10. "Modifications"
|
||||||
|
means any of the following:
|
||||||
|
|
||||||
|
(a) any file in Source Code Form that results from an addition to,
|
||||||
|
deletion from, or modification of the contents of Covered
|
||||||
|
Software; or
|
||||||
|
|
||||||
|
(b) any new file in Source Code Form that contains any Covered
|
||||||
|
Software.
|
||||||
|
|
||||||
|
1.11. "Patent Claims" of a Contributor
|
||||||
|
means any patent claim(s), including without limitation, method,
|
||||||
|
process, and apparatus claims, in any patent Licensable by such
|
||||||
|
Contributor that would be infringed, but for the grant of the
|
||||||
|
License, by the making, using, selling, offering for sale, having
|
||||||
|
made, import, or transfer of either its Contributions or its
|
||||||
|
Contributor Version.
|
||||||
|
|
||||||
|
1.12. "Secondary License"
|
||||||
|
means either the GNU General Public License, Version 2.0, the GNU
|
||||||
|
Lesser General Public License, Version 2.1, the GNU Affero General
|
||||||
|
Public License, Version 3.0, or any later versions of those
|
||||||
|
licenses.
|
||||||
|
|
||||||
|
1.13. "Source Code Form"
|
||||||
|
means the form of the work preferred for making modifications.
|
||||||
|
|
||||||
|
1.14. "You" (or "Your")
|
||||||
|
means an individual or a legal entity exercising rights under this
|
||||||
|
License. For legal entities, "You" includes any entity that
|
||||||
|
controls, is controlled by, or is under common control with You. For
|
||||||
|
purposes of this definition, "control" means (a) the power, direct
|
||||||
|
or indirect, to cause the direction or management of such entity,
|
||||||
|
whether by contract or otherwise, or (b) ownership of more than
|
||||||
|
fifty percent (50%) of the outstanding shares or beneficial
|
||||||
|
ownership of such entity.
|
||||||
|
|
||||||
|
2. License Grants and Conditions
|
||||||
|
--------------------------------
|
||||||
|
|
||||||
|
2.1. Grants
|
||||||
|
|
||||||
|
Each Contributor hereby grants You a world-wide, royalty-free,
|
||||||
|
non-exclusive license:
|
||||||
|
|
||||||
|
(a) under intellectual property rights (other than patent or trademark)
|
||||||
|
Licensable by such Contributor to use, reproduce, make available,
|
||||||
|
modify, display, perform, distribute, and otherwise exploit its
|
||||||
|
Contributions, either on an unmodified basis, with Modifications, or
|
||||||
|
as part of a Larger Work; and
|
||||||
|
|
||||||
|
(b) under Patent Claims of such Contributor to make, use, sell, offer
|
||||||
|
for sale, have made, import, and otherwise transfer either its
|
||||||
|
Contributions or its Contributor Version.
|
||||||
|
|
||||||
|
2.2. Effective Date
|
||||||
|
|
||||||
|
The licenses granted in Section 2.1 with respect to any Contribution
|
||||||
|
become effective for each Contribution on the date the Contributor first
|
||||||
|
distributes such Contribution.
|
||||||
|
|
||||||
|
2.3. Limitations on Grant Scope
|
||||||
|
|
||||||
|
The licenses granted in this Section 2 are the only rights granted under
|
||||||
|
this License. No additional rights or licenses will be implied from the
|
||||||
|
distribution or licensing of Covered Software under this License.
|
||||||
|
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
||||||
|
Contributor:
|
||||||
|
|
||||||
|
(a) for any code that a Contributor has removed from Covered Software;
|
||||||
|
or
|
||||||
|
|
||||||
|
(b) for infringements caused by: (i) Your and any other third party's
|
||||||
|
modifications of Covered Software, or (ii) the combination of its
|
||||||
|
Contributions with other software (except as part of its Contributor
|
||||||
|
Version); or
|
||||||
|
|
||||||
|
(c) under Patent Claims infringed by Covered Software in the absence of
|
||||||
|
its Contributions.
|
||||||
|
|
||||||
|
This License does not grant any rights in the trademarks, service marks,
|
||||||
|
or logos of any Contributor (except as may be necessary to comply with
|
||||||
|
the notice requirements in Section 3.4).
|
||||||
|
|
||||||
|
2.4. Subsequent Licenses
|
||||||
|
|
||||||
|
No Contributor makes additional grants as a result of Your choice to
|
||||||
|
distribute the Covered Software under a subsequent version of this
|
||||||
|
License (see Section 10.2) or under the terms of a Secondary License (if
|
||||||
|
permitted under the terms of Section 3.3).
|
||||||
|
|
||||||
|
2.5. Representation
|
||||||
|
|
||||||
|
Each Contributor represents that the Contributor believes its
|
||||||
|
Contributions are its original creation(s) or it has sufficient rights
|
||||||
|
to grant the rights to its Contributions conveyed by this License.
|
||||||
|
|
||||||
|
2.6. Fair Use
|
||||||
|
|
||||||
|
This License is not intended to limit any rights You have under
|
||||||
|
applicable copyright doctrines of fair use, fair dealing, or other
|
||||||
|
equivalents.
|
||||||
|
|
||||||
|
2.7. Conditions
|
||||||
|
|
||||||
|
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
|
||||||
|
in Section 2.1.
|
||||||
|
|
||||||
|
3. Responsibilities
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
3.1. Distribution of Source Form
|
||||||
|
|
||||||
|
All distribution of Covered Software in Source Code Form, including any
|
||||||
|
Modifications that You create or to which You contribute, must be under
|
||||||
|
the terms of this License. You must inform recipients that the Source
|
||||||
|
Code Form of the Covered Software is governed by the terms of this
|
||||||
|
License, and how they can obtain a copy of this License. You may not
|
||||||
|
attempt to alter or restrict the recipients' rights in the Source Code
|
||||||
|
Form.
|
||||||
|
|
||||||
|
3.2. Distribution of Executable Form
|
||||||
|
|
||||||
|
If You distribute Covered Software in Executable Form then:
|
||||||
|
|
||||||
|
(a) such Covered Software must also be made available in Source Code
|
||||||
|
Form, as described in Section 3.1, and You must inform recipients of
|
||||||
|
the Executable Form how they can obtain a copy of such Source Code
|
||||||
|
Form by reasonable means in a timely manner, at a charge no more
|
||||||
|
than the cost of distribution to the recipient; and
|
||||||
|
|
||||||
|
(b) You may distribute such Executable Form under the terms of this
|
||||||
|
License, or sublicense it under different terms, provided that the
|
||||||
|
license for the Executable Form does not attempt to limit or alter
|
||||||
|
the recipients' rights in the Source Code Form under this License.
|
||||||
|
|
||||||
|
3.3. Distribution of a Larger Work
|
||||||
|
|
||||||
|
You may create and distribute a Larger Work under terms of Your choice,
|
||||||
|
provided that You also comply with the requirements of this License for
|
||||||
|
the Covered Software. If the Larger Work is a combination of Covered
|
||||||
|
Software with a work governed by one or more Secondary Licenses, and the
|
||||||
|
Covered Software is not Incompatible With Secondary Licenses, this
|
||||||
|
License permits You to additionally distribute such Covered Software
|
||||||
|
under the terms of such Secondary License(s), so that the recipient of
|
||||||
|
the Larger Work may, at their option, further distribute the Covered
|
||||||
|
Software under the terms of either this License or such Secondary
|
||||||
|
License(s).
|
||||||
|
|
||||||
|
3.4. Notices
|
||||||
|
|
||||||
|
You may not remove or alter the substance of any license notices
|
||||||
|
(including copyright notices, patent notices, disclaimers of warranty,
|
||||||
|
or limitations of liability) contained within the Source Code Form of
|
||||||
|
the Covered Software, except that You may alter any license notices to
|
||||||
|
the extent required to remedy known factual inaccuracies.
|
||||||
|
|
||||||
|
3.5. Application of Additional Terms
|
||||||
|
|
||||||
|
You may choose to offer, and to charge a fee for, warranty, support,
|
||||||
|
indemnity or liability obligations to one or more recipients of Covered
|
||||||
|
Software. However, You may do so only on Your own behalf, and not on
|
||||||
|
behalf of any Contributor. You must make it absolutely clear that any
|
||||||
|
such warranty, support, indemnity, or liability obligation is offered by
|
||||||
|
You alone, and You hereby agree to indemnify every Contributor for any
|
||||||
|
liability incurred by such Contributor as a result of warranty, support,
|
||||||
|
indemnity or liability terms You offer. You may include additional
|
||||||
|
disclaimers of warranty and limitations of liability specific to any
|
||||||
|
jurisdiction.
|
||||||
|
|
||||||
|
4. Inability to Comply Due to Statute or Regulation
|
||||||
|
---------------------------------------------------
|
||||||
|
|
||||||
|
If it is impossible for You to comply with any of the terms of this
|
||||||
|
License with respect to some or all of the Covered Software due to
|
||||||
|
statute, judicial order, or regulation then You must: (a) comply with
|
||||||
|
the terms of this License to the maximum extent possible; and (b)
|
||||||
|
describe the limitations and the code they affect. Such description must
|
||||||
|
be placed in a text file included with all distributions of the Covered
|
||||||
|
Software under this License. Except to the extent prohibited by statute
|
||||||
|
or regulation, such description must be sufficiently detailed for a
|
||||||
|
recipient of ordinary skill to be able to understand it.
|
||||||
|
|
||||||
|
5. Termination
|
||||||
|
--------------
|
||||||
|
|
||||||
|
5.1. The rights granted under this License will terminate automatically
|
||||||
|
if You fail to comply with any of its terms. However, if You become
|
||||||
|
compliant, then the rights granted under this License from a particular
|
||||||
|
Contributor are reinstated (a) provisionally, unless and until such
|
||||||
|
Contributor explicitly and finally terminates Your grants, and (b) on an
|
||||||
|
ongoing basis, if such Contributor fails to notify You of the
|
||||||
|
non-compliance by some reasonable means prior to 60 days after You have
|
||||||
|
come back into compliance. Moreover, Your grants from a particular
|
||||||
|
Contributor are reinstated on an ongoing basis if such Contributor
|
||||||
|
notifies You of the non-compliance by some reasonable means, this is the
|
||||||
|
first time You have received notice of non-compliance with this License
|
||||||
|
from such Contributor, and You become compliant prior to 30 days after
|
||||||
|
Your receipt of the notice.
|
||||||
|
|
||||||
|
5.2. If You initiate litigation against any entity by asserting a patent
|
||||||
|
infringement claim (excluding declaratory judgment actions,
|
||||||
|
counter-claims, and cross-claims) alleging that a Contributor Version
|
||||||
|
directly or indirectly infringes any patent, then the rights granted to
|
||||||
|
You by any and all Contributors for the Covered Software under Section
|
||||||
|
2.1 of this License shall terminate.
|
||||||
|
|
||||||
|
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
|
||||||
|
end user license agreements (excluding distributors and resellers) which
|
||||||
|
have been validly granted by You or Your distributors under this License
|
||||||
|
prior to termination shall survive termination.
|
||||||
|
|
||||||
|
************************************************************************
|
||||||
|
* *
|
||||||
|
* 6. Disclaimer of Warranty *
|
||||||
|
* ------------------------- *
|
||||||
|
* *
|
||||||
|
* Covered Software is provided under this License on an "as is" *
|
||||||
|
* basis, without warranty of any kind, either expressed, implied, or *
|
||||||
|
* statutory, including, without limitation, warranties that the *
|
||||||
|
* Covered Software is free of defects, merchantable, fit for a *
|
||||||
|
* particular purpose or non-infringing. The entire risk as to the *
|
||||||
|
* quality and performance of the Covered Software is with You. *
|
||||||
|
* Should any Covered Software prove defective in any respect, You *
|
||||||
|
* (not any Contributor) assume the cost of any necessary servicing, *
|
||||||
|
* repair, or correction. This disclaimer of warranty constitutes an *
|
||||||
|
* essential part of this License. No use of any Covered Software is *
|
||||||
|
* authorized under this License except under this disclaimer. *
|
||||||
|
* *
|
||||||
|
************************************************************************
|
||||||
|
|
||||||
|
************************************************************************
|
||||||
|
* *
|
||||||
|
* 7. Limitation of Liability *
|
||||||
|
* -------------------------- *
|
||||||
|
* *
|
||||||
|
* Under no circumstances and under no legal theory, whether tort *
|
||||||
|
* (including negligence), contract, or otherwise, shall any *
|
||||||
|
* Contributor, or anyone who distributes Covered Software as *
|
||||||
|
* permitted above, be liable to You for any direct, indirect, *
|
||||||
|
* special, incidental, or consequential damages of any character *
|
||||||
|
* including, without limitation, damages for lost profits, loss of *
|
||||||
|
* goodwill, work stoppage, computer failure or malfunction, or any *
|
||||||
|
* and all other commercial damages or losses, even if such party *
|
||||||
|
* shall have been informed of the possibility of such damages. This *
|
||||||
|
* limitation of liability shall not apply to liability for death or *
|
||||||
|
* personal injury resulting from such party's negligence to the *
|
||||||
|
* extent applicable law prohibits such limitation. Some *
|
||||||
|
* jurisdictions do not allow the exclusion or limitation of *
|
||||||
|
* incidental or consequential damages, so this exclusion and *
|
||||||
|
* limitation may not apply to You. *
|
||||||
|
* *
|
||||||
|
************************************************************************
|
||||||
|
|
||||||
|
8. Litigation
|
||||||
|
-------------
|
||||||
|
|
||||||
|
Any litigation relating to this License may be brought only in the
|
||||||
|
courts of a jurisdiction where the defendant maintains its principal
|
||||||
|
place of business and such litigation shall be governed by laws of that
|
||||||
|
jurisdiction, without reference to its conflict-of-law provisions.
|
||||||
|
Nothing in this Section shall prevent a party's ability to bring
|
||||||
|
cross-claims or counter-claims.
|
||||||
|
|
||||||
|
9. Miscellaneous
|
||||||
|
----------------
|
||||||
|
|
||||||
|
This License represents the complete agreement concerning the subject
|
||||||
|
matter hereof. If any provision of this License is held to be
|
||||||
|
unenforceable, such provision shall be reformed only to the extent
|
||||||
|
necessary to make it enforceable. Any law or regulation which provides
|
||||||
|
that the language of a contract shall be construed against the drafter
|
||||||
|
shall not be used to construe this License against a Contributor.
|
||||||
|
|
||||||
|
10. Versions of the License
|
||||||
|
---------------------------
|
||||||
|
|
||||||
|
10.1. New Versions
|
||||||
|
|
||||||
|
Mozilla Foundation is the license steward. Except as provided in Section
|
||||||
|
10.3, no one other than the license steward has the right to modify or
|
||||||
|
publish new versions of this License. Each version will be given a
|
||||||
|
distinguishing version number.
|
||||||
|
|
||||||
|
10.2. Effect of New Versions
|
||||||
|
|
||||||
|
You may distribute the Covered Software under the terms of the version
|
||||||
|
of the License under which You originally received the Covered Software,
|
||||||
|
or under the terms of any subsequent version published by the license
|
||||||
|
steward.
|
||||||
|
|
||||||
|
10.3. Modified Versions
|
||||||
|
|
||||||
|
If you create software not governed by this License, and you want to
|
||||||
|
create a new license for such software, you may create and use a
|
||||||
|
modified version of this License if you rename the license and remove
|
||||||
|
any references to the name of the license steward (except to note that
|
||||||
|
such modified license differs from this License).
|
||||||
|
|
||||||
|
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
||||||
|
Licenses
|
||||||
|
|
||||||
|
If You choose to distribute Source Code Form that is Incompatible With
|
||||||
|
Secondary Licenses under the terms of this version of the License, the
|
||||||
|
notice described in Exhibit B of this License must be attached.
|
||||||
|
|
||||||
|
Exhibit A - Source Code Form License Notice
|
||||||
|
-------------------------------------------
|
||||||
|
|
||||||
|
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 http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
If it is not possible or desirable to put the notice in a particular
|
||||||
|
file, then You may include the notice in a location (such as a LICENSE
|
||||||
|
file in a relevant directory) where a recipient would be likely to look
|
||||||
|
for such a notice.
|
||||||
|
|
||||||
|
You may add additional accurate notices of copyright ownership.
|
||||||
|
|
||||||
|
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
||||||
|
---------------------------------------------------------
|
||||||
|
|
||||||
|
This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||||
|
defined by the Mozilla Public License, v. 2.0.
|
||||||
@@ -22,8 +22,8 @@ ADB := adb
|
|||||||
|
|
||||||
VERSIONS := versions.properties
|
VERSIONS := versions.properties
|
||||||
APP_ID := $(shell sed -n 's/^[[:space:]]*namespace[[:space:]]*=[[:space:]]*"\(.*\)".*/\1/p' app/build.gradle.kts)
|
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_NAME := $(shell sed -n 's/^versionName[[:space:]]*=[[:space:]]*//p' $(VERSIONS) | tr -d ' ')
|
||||||
VERSION_CODE := $(shell sed -n 's/^android.versionCode[[: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
|
# Publishing to the private F-Droid repo (CLAUDE.md). Both halves of a release
|
||||||
# — the artifact and its metadata — live under the same host.
|
# — 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.
|
# directory expects; app/build.gradle.kts stamps the same name onto the output.
|
||||||
APK_NAME := $(APP_ID)_$(VERSION_CODE).apk
|
APK_NAME := $(APP_ID)_$(VERSION_CODE).apk
|
||||||
RELEASE_APK := app/build/outputs/apk/release/$(APK_NAME)
|
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
|
STAGING_APK := app/build/outputs/apk/staging/app-staging.apk
|
||||||
METADATA_YML := dist/$(APP_ID).yml
|
METADATA_YML := dist/$(APP_ID).yml
|
||||||
|
|
||||||
@@ -110,12 +114,18 @@ launch:
|
|||||||
# ------------------------------------------------------------------ dist
|
# ------------------------------------------------------------------ dist
|
||||||
# Everything a publish needs, staged locally first so it can be inspected
|
# Everything a publish needs, staged locally first so it can be inspected
|
||||||
# before anything leaves the machine.
|
# before anything leaves the machine.
|
||||||
dist: dist/$(APK_NAME) $(METADATA_YML)
|
dist: dist/$(APK_NAME) $(DIST_MAP) $(METADATA_YML)
|
||||||
|
|
||||||
dist/$(APK_NAME): $(RELEASE_APK)
|
dist/$(APK_NAME): $(RELEASE_APK)
|
||||||
@mkdir -p dist
|
@mkdir -p dist
|
||||||
cp $(RELEASE_APK) $@
|
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
|
# F-Droid metadata. Regenerated from versions.properties on every dist so the
|
||||||
# CurrentVersion lines can never lag the APK next to them.
|
# CurrentVersion lines can never lag the APK next to them.
|
||||||
$(METADATA_YML): $(VERSIONS) Makefile
|
$(METADATA_YML): $(VERSIONS) Makefile
|
||||||
@@ -153,6 +163,7 @@ publish-metadata: $(METADATA_YML)
|
|||||||
|
|
||||||
publish: publish-apk publish-metadata
|
publish: publish-apk publish-metadata
|
||||||
@echo "published $(APP_ID) $(VERSION_NAME) ($(VERSION_CODE)); sign it on the repo host"
|
@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
|
# ------------------------------------------------------------------ versioning
|
||||||
# versionCode always moves by exactly 1: F-Droid and the package manager order
|
# 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:
|
bump:
|
||||||
@awk -v field=$(FIELD) ' \
|
@awk -v field=$(FIELD) ' \
|
||||||
/^android.versionName/ { \
|
/^versionName/ { \
|
||||||
split($$3, v, "."); \
|
split($$3, v, "."); \
|
||||||
v[field]++; \
|
v[field]++; \
|
||||||
for (i = field + 1; i <= 3; i++) v[i] = 0; \
|
for (i = field + 1; i <= 3; i++) v[i] = 0; \
|
||||||
printf "android.versionName = %d.%d.%d\n", v[1], v[2], v[3]; next } \
|
printf "versionName = %d.%d.%d\n", v[1], v[2], v[3]; next } \
|
||||||
/^android.versionCode/ { printf "android.versionCode = %d\n", $$3 + 1; next } \
|
/^versionCode/ { printf "versionCode = %d\n", $$3 + 1; next } \
|
||||||
{ print }' $(VERSIONS) > $(VERSIONS).tmp
|
{ print }' $(VERSIONS) > $(VERSIONS).tmp
|
||||||
@mv $(VERSIONS).tmp $(VERSIONS)
|
@mv $(VERSIONS).tmp $(VERSIONS)
|
||||||
@sed -n 's/^android\./ android./p' $(VERSIONS)
|
@grep -E '^version(Name|Code)' $(VERSIONS) | sed 's/^/ /'
|
||||||
|
|
||||||
# ------------------------------------------------------------------ clean
|
# ------------------------------------------------------------------ clean
|
||||||
clean:
|
clean:
|
||||||
|
|||||||
@@ -80,3 +80,13 @@ the terms of the **GNU General Public License v3.0 or later**
|
|||||||
source file carries an SPDX `GPL-3.0-or-later` header.
|
source file carries an SPDX `GPL-3.0-or-later` header.
|
||||||
|
|
||||||
Copyright © 2026 Reactorcoremeltdown
|
Copyright © 2026 Reactorcoremeltdown
|
||||||
|
|
||||||
|
The Morph Pad instrument (`app/src/main/java/cc/tiredsysadmin/android/sizzle/frasil/`)
|
||||||
|
is ported from [FRASIL](https://github.com/styvesgoupil/frasil), Copyright © 2026
|
||||||
|
Styves Goupil, and those files remain under the **Mozilla Public License 2.0**
|
||||||
|
([`LICENSES/MPL-2.0.txt`](LICENSES/MPL-2.0.txt)).
|
||||||
|
|
||||||
|
The Grain Cloud instrument (`app/src/main/java/cc/tiredsysadmin/android/sizzle/echofield/`)
|
||||||
|
is ported from [ECHOFIELD FM-1](https://github.com/Philip-Bos/echofield-fm1),
|
||||||
|
Copyright © 2026 Philip Bos, and those files remain under the **MIT License**
|
||||||
|
([`LICENSES/MIT.txt`](LICENSES/MIT.txt)).
|
||||||
|
|||||||
+12
-7
@@ -14,8 +14,8 @@ plugins {
|
|||||||
val appVersions = Properties().apply {
|
val appVersions = Properties().apply {
|
||||||
rootProject.file("versions.properties").inputStream().use { load(it) }
|
rootProject.file("versions.properties").inputStream().use { load(it) }
|
||||||
}
|
}
|
||||||
val appVersionName: String = appVersions.getProperty("android.versionName").trim()
|
val appVersionName: String = appVersions.getProperty("versionName").trim()
|
||||||
val appVersionCode: Int = appVersions.getProperty("android.versionCode").trim().toInt()
|
val appVersionCode: Int = appVersions.getProperty("versionCode").trim().toInt()
|
||||||
|
|
||||||
android {
|
android {
|
||||||
namespace = "cc.tiredsysadmin.android.sizzle"
|
namespace = "cc.tiredsysadmin.android.sizzle"
|
||||||
@@ -52,9 +52,13 @@ android {
|
|||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
// Shrinking is off by default so newcomers get readable stack traces.
|
// R8: shrink + optimise + obfuscate, and drop unreferenced resources.
|
||||||
// Flip to true once the app stabilises.
|
// Only the JNI entry points need keeping (see proguard-rules.pro); the
|
||||||
isMinifyEnabled = false
|
// 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(
|
proguardFiles(
|
||||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||||
"proguard-rules.pro",
|
"proguard-rules.pro",
|
||||||
@@ -66,8 +70,9 @@ android {
|
|||||||
// the app un-optimised and makes Compose several times slower — so measuring
|
// the app un-optimised and makes Compose several times slower — so measuring
|
||||||
// UI "snappiness" on a debug build is misleading. This variant flips
|
// UI "snappiness" on a debug build is misleading. This variant flips
|
||||||
// debuggability off (the single biggest perf lever) while reusing the debug
|
// debuggability off (the single biggest perf lever) while reusing the debug
|
||||||
// signing key, so it still installs without a release keystore. R8/shrinking
|
// signing key, so it still installs without a release keystore. R8 stays off
|
||||||
// stays off to avoid needing JNI/Compose keep-rules for now.
|
// 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") {
|
create("staging") {
|
||||||
initWith(getByName("debug"))
|
initWith(getByName("debug"))
|
||||||
isDebuggable = false
|
isDebuggable = false
|
||||||
|
|||||||
Vendored
+19
-3
@@ -1,3 +1,19 @@
|
|||||||
# ProGuard/R8 rules for release builds. Minification is currently disabled in
|
# R8 rules for the release build (isMinifyEnabled = true in build.gradle.kts).
|
||||||
# build.gradle.kts (isMinifyEnabled = false), so this file is intentionally empty.
|
#
|
||||||
# Add keep-rules here if/when you enable shrinking and hit reflection issues.
|
# 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 : keep the sequencer alive while the app is backgrounded.
|
||||||
FOREGROUND_SERVICE_MEDIA_PLAYBACK : Android 14 requires a typed FGS.
|
FOREGROUND_SERVICE_MEDIA_PLAYBACK : Android 14 requires a typed FGS.
|
||||||
POST_NOTIFICATIONS : show the media transport notification (Android 13+).
|
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.RECORD_AUDIO" />
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
|
||||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||||
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
<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
|
<!-- Hardware we can *use* but do not *require* (so the app still installs on
|
||||||
devices without them). Code must always feature-detect at runtime. -->
|
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.software.midi" android:required="false" />
|
||||||
<uses-feature android:name="android.hardware.gamepad" 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" android:required="false" />
|
||||||
|
<uses-feature android:name="android.hardware.bluetooth_le" android:required="false" />
|
||||||
<uses-feature android:name="android.hardware.microphone" 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
|
<application
|
||||||
android:name=".SizzleApp"
|
android:name=".SizzleApp"
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
@@ -50,6 +70,53 @@
|
|||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
|
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
|
||||||
android:resource="@xml/usb_device_filter" />
|
android:resource="@xml/usb_device_filter" />
|
||||||
|
|
||||||
|
<!-- Open a .sng song handed over by another app (Mikro Seq's "Open in
|
||||||
|
Sizzle", a file manager, the share sheet). Senders rarely have a
|
||||||
|
type for .sng, so the generic types are accepted too; the content
|
||||||
|
is sniffed (io/SongIntents.kt) and the user confirms before the
|
||||||
|
current song is replaced. -->
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data android:scheme="content" />
|
||||||
|
<data android:scheme="file" />
|
||||||
|
<data android:mimeType="application/x-sizzle-song" />
|
||||||
|
<data android:mimeType="application/octet-stream" />
|
||||||
|
<data android:mimeType="text/plain" />
|
||||||
|
</intent-filter>
|
||||||
|
<!-- …any type, by the .sng extension (pathPattern needs a host; the
|
||||||
|
repeats cope with dots earlier in the path, which a single
|
||||||
|
non-greedy ".*" pattern would not match). -->
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data android:scheme="content" />
|
||||||
|
<data android:scheme="file" />
|
||||||
|
<data android:host="*" />
|
||||||
|
<data android:mimeType="*/*" />
|
||||||
|
<data android:pathPattern=".*\\.sng" />
|
||||||
|
<data android:pathPattern=".*\\..*\\.sng" />
|
||||||
|
<data android:pathPattern=".*\\..*\\..*\\.sng" />
|
||||||
|
</intent-filter>
|
||||||
|
<!-- …and the same by extension when the sender gave no type at all. -->
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data android:scheme="content" />
|
||||||
|
<data android:scheme="file" />
|
||||||
|
<data android:host="*" />
|
||||||
|
<data android:pathPattern=".*\\.sng" />
|
||||||
|
<data android:pathPattern=".*\\..*\\.sng" />
|
||||||
|
<data android:pathPattern=".*\\..*\\..*\\.sng" />
|
||||||
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.SEND" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data android:mimeType="application/x-sizzle-song" />
|
||||||
|
<data android:mimeType="application/octet-stream" />
|
||||||
|
<data android:mimeType="text/plain" />
|
||||||
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<!-- Exposes saved preset files (and zip bundles) as content:// URIs so they
|
<!-- Exposes saved preset files (and zip bundles) as content:// URIs so they
|
||||||
@@ -84,5 +151,14 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
|
<!-- Background MIDI sound module: a foreground service held while the
|
||||||
|
"Keep running as MIDI sound module" setting is on, so the cached-app
|
||||||
|
freezer never suspends Sizzle while another app plays it over MIDI.
|
||||||
|
mediaPlayback because that is what it does: it renders audio. -->
|
||||||
|
<service
|
||||||
|
android:name=".playback.SoundModuleService"
|
||||||
|
android:exported="false"
|
||||||
|
android:foregroundServiceType="mediaPlayback" />
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -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)
|
cmake_minimum_required(VERSION 3.22.1)
|
||||||
project(sizzle_native)
|
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
|
# 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.
|
# it here when `buildFeatures { prefab = true }` is set in build.gradle.kts.
|
||||||
find_package(oboe REQUIRED CONFIG)
|
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
|
target_link_libraries(sizzle_native
|
||||||
oboe::oboe
|
oboe::oboe
|
||||||
|
z
|
||||||
log)
|
log)
|
||||||
|
|
||||||
# Align ELF load segments to 16 KB so the library works on Android 15+ devices
|
# 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.
|
// Native Oboe (AAudio) output backend for Sizzletracker.
|
||||||
//
|
//
|
||||||
// Opens a low-latency mono float Oboe output stream. On each real-time data
|
// Opens a low-latency stereo float Oboe output stream. Each real-time data
|
||||||
// callback it calls back into Kotlin (NativeAudioBridge.renderAudio) to fill a
|
// callback renders straight from the shared C++ engine (core/, through the
|
||||||
// reused Java float[] from the shared AudioEngine.fillBlock, then copies that
|
// EngineHost that jni_engine.cpp owns): no JVM call on the audio thread, so no
|
||||||
// into Oboe's output buffer. This keeps ONE implementation of the synth/mixer
|
// garbage-collector pause can glitch it.
|
||||||
// (in Kotlin) while delivering audio through the lower-latency native path.
|
|
||||||
|
#include "host/EngineHost.hpp"
|
||||||
|
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
@@ -25,13 +26,11 @@
|
|||||||
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
|
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
|
||||||
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, 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 {
|
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_prevXRuns = 0; // last-seen underrun count, for adaptive sizing
|
||||||
int32_t g_sampleRate = 48000; // remembered so the stream can be reopened on disconnect
|
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
|
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
|
// the app deliberately shut down
|
||||||
|
|
||||||
// How glitch-resistant the output buffer starts (in device bursts). The buffer
|
// How glitch-resistant the output buffer starts (in device bursts). The buffer
|
||||||
// then grows adaptively (see onAudioReady) if underruns still occur. Profiling
|
// then grows adaptively (see onAudioReady) if underruns still occur. (Sized when
|
||||||
// showed the JVM render is fast on average (<1 ms) but spikes to 3-7 ms when a GC
|
// the render went through the JVM and its GC pauses; kept, the cost is latency only.)
|
||||||
// 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.
|
|
||||||
constexpr int32_t kInitialBursts = 8;
|
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 {
|
class SizzleCallback : public oboe::AudioStreamDataCallback {
|
||||||
public:
|
public:
|
||||||
@@ -76,19 +63,8 @@ public:
|
|||||||
stream->getBufferSizeInFrames() + stream->getFramesPerBurst());
|
stream->getBufferSizeInFrames() + stream->getFramesPerBurst());
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEnv *env = callbackEnv();
|
if (sizzle::host::EngineHost *host = sizzleHost()) host->render(out, numFrames);
|
||||||
if (!env || !g_callback || !g_renderMethod || !g_buffer) {
|
else for (int i = 0; i < numFrames * 2; ++i) out[i] = 0.0f; // stereo silence
|
||||||
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;
|
|
||||||
|
|
||||||
// Adaptive buffer sizing (timing path): a callback that renders slower than
|
// 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
|
// its deadline will drain the buffer; a couple in a row means we're about to
|
||||||
@@ -174,7 +150,7 @@ public:
|
|||||||
SizzleErrorCallback g_errorCallback;
|
SizzleErrorCallback g_errorCallback;
|
||||||
|
|
||||||
// Opens, buffers and starts the low-latency output stream. Used both at initial
|
// 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() {
|
bool openAndStartStream() {
|
||||||
oboe::AudioStreamBuilder builder;
|
oboe::AudioStreamBuilder builder;
|
||||||
builder.setDirection(oboe::Direction::Output)
|
builder.setDirection(oboe::Direction::Output)
|
||||||
@@ -200,56 +176,30 @@ bool openAndStartStream() {
|
|||||||
g_stream.reset();
|
g_stream.reset();
|
||||||
return false;
|
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_sampleRate, burst, g_stream->getBufferSizeInFrames(),
|
||||||
g_stream->getBufferCapacityInFrames(), g_frames);
|
g_stream->getBufferCapacityInFrames());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void * /*reserved*/) {
|
|
||||||
g_vm = vm;
|
|
||||||
return JNI_VERSION_1_6;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" JNIEXPORT jboolean JNICALL
|
extern "C" JNIEXPORT jboolean JNICALL
|
||||||
Java_cc_tiredsysadmin_android_sizzle_audio_NativeAudioBridge_nativeStart(
|
Java_cc_tiredsysadmin_android_sizzle_audio_NativeAudioBridge_nativeStart(
|
||||||
JNIEnv *env, jobject /*thiz*/, jobject callback, jint sampleRate, jint framesPerCallback) {
|
JNIEnv * /*env*/, jobject /*thiz*/, jint sampleRate) {
|
||||||
g_callback = env->NewGlobalRef(callback);
|
|
||||||
jclass cls = env->GetObjectClass(callback);
|
|
||||||
g_renderMethod = env->GetMethodID(cls, "renderAudio", "([FI)V");
|
|
||||||
g_prevXRuns = 0;
|
g_prevXRuns = 0;
|
||||||
g_sampleRate = sampleRate;
|
g_sampleRate = sampleRate;
|
||||||
g_wantRunning = true;
|
g_wantRunning = true;
|
||||||
|
return openAndStartStream() ? JNI_TRUE : JNI_FALSE;
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" JNIEXPORT void JNICALL
|
extern "C" JNIEXPORT void JNICALL
|
||||||
Java_cc_tiredsysadmin_android_sizzle_audio_NativeAudioBridge_nativeStop(
|
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
|
g_wantRunning = false; // stop the disconnect-recovery from reopening
|
||||||
if (g_stream) {
|
if (g_stream) {
|
||||||
g_stream->stop();
|
g_stream->stop();
|
||||||
g_stream->close();
|
g_stream->close();
|
||||||
g_stream.reset();
|
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;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package cc.tiredsysadmin.android.sizzle
|
|||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@@ -15,14 +16,19 @@ import androidx.activity.compose.setContent
|
|||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.lifecycle.viewmodel.initializer
|
import androidx.lifecycle.viewmodel.initializer
|
||||||
import androidx.annotation.OptIn
|
import androidx.annotation.OptIn
|
||||||
import androidx.lifecycle.viewmodel.viewModelFactory
|
import androidx.lifecycle.viewmodel.viewModelFactory
|
||||||
import androidx.media3.common.util.UnstableApi
|
import androidx.media3.common.util.UnstableApi
|
||||||
import cc.tiredsysadmin.android.sizzle.input.GamepadInput
|
import cc.tiredsysadmin.android.sizzle.input.GamepadInput
|
||||||
import cc.tiredsysadmin.android.sizzle.input.KeyboardInput
|
import cc.tiredsysadmin.android.sizzle.input.KeyboardInput
|
||||||
import cc.tiredsysadmin.android.sizzle.input.MidiInput
|
import cc.tiredsysadmin.android.sizzle.io.SongIntents
|
||||||
import cc.tiredsysadmin.android.sizzle.playback.PlaybackService
|
import cc.tiredsysadmin.android.sizzle.playback.PlaybackService
|
||||||
|
import cc.tiredsysadmin.android.sizzle.playback.SoundModuleService
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import cc.tiredsysadmin.android.sizzle.ui.AppViewModel
|
import cc.tiredsysadmin.android.sizzle.ui.AppViewModel
|
||||||
import cc.tiredsysadmin.android.sizzle.ui.SizzleApp as SizzleAppUi
|
import cc.tiredsysadmin.android.sizzle.ui.SizzleApp as SizzleAppUi
|
||||||
import cc.tiredsysadmin.android.sizzle.ui.theme.SizzleTheme
|
import cc.tiredsysadmin.android.sizzle.ui.theme.SizzleTheme
|
||||||
@@ -32,7 +38,8 @@ import cc.tiredsysadmin.android.sizzle.ui.theme.SizzleTheme
|
|||||||
* 1. build the [AppViewModel] wired to the app-wide singletons,
|
* 1. build the [AppViewModel] wired to the app-wide singletons,
|
||||||
* 2. host the Compose UI, themed by the ViewModel's current palette,
|
* 2. host the Compose UI, themed by the ViewModel's current palette,
|
||||||
* 3. forward hardware key / motion events into the keyboard & gamepad handlers,
|
* 3. forward hardware key / motion events into the keyboard & gamepad handlers,
|
||||||
* 4. start MIDI listening and the background playback service.
|
* 4. hold the MIDI ports and start the background services,
|
||||||
|
* 5. hand `.sng` files opened from other apps to the ViewModel.
|
||||||
*
|
*
|
||||||
* All four input methods converge on the same InputRouter -> ViewModel path, so
|
* All four input methods converge on the same InputRouter -> ViewModel path, so
|
||||||
* there is no per-input special-casing beyond the translation done here.
|
* there is no per-input special-casing beyond the translation done here.
|
||||||
@@ -44,7 +51,6 @@ class MainActivity : ComponentActivity() {
|
|||||||
// Handlers are app-wide singletons (shared with the Settings rebind UI).
|
// Handlers are app-wide singletons (shared with the Settings rebind UI).
|
||||||
private val keyboard: KeyboardInput get() = app.keyboardInput
|
private val keyboard: KeyboardInput get() = app.keyboardInput
|
||||||
private val gamepad: GamepadInput get() = app.gamepadInput
|
private val gamepad: GamepadInput get() = app.gamepadInput
|
||||||
private val midi: MidiInput get() = app.midiInput
|
|
||||||
|
|
||||||
private val viewModel: AppViewModel by lazy {
|
private val viewModel: AppViewModel by lazy {
|
||||||
ViewModelProvider(
|
ViewModelProvider(
|
||||||
@@ -77,16 +83,45 @@ class MainActivity : ComponentActivity() {
|
|||||||
SizzleTheme(palette = viewModel.palette) {
|
SizzleTheme(palette = viewModel.palette) {
|
||||||
SizzleAppUi(viewModel)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start MIDI listening (USB + BLE) and the MIDI clock here — bound to the
|
// Hold the MIDI ports (USB, Bluetooth, other apps' virtual devices) for the
|
||||||
// Activity's WHOLE lifetime (onCreate..onDestroy), not onStart/onStop — so a
|
// Activity's WHOLE lifetime (onCreate..onDestroy), not onStart/onStop, so a
|
||||||
// connected controller keeps driving the app while the screen is off. The
|
// controller keeps driving the app with the screen off. The PlaybackService
|
||||||
// audio engine already runs a continuous output stream via the started
|
// and the SoundModuleService hold their own references, so MIDI outlives
|
||||||
// PlaybackService, which keeps the process alive to receive those events in
|
// the Activity while either runs; the notes themselves are played by
|
||||||
// the background; closing the ports on onStop was the only reason input died.
|
// SizzleApp.soundModule, not by this Activity or its ViewModel.
|
||||||
midi.start()
|
app.acquireMidi(MIDI_OWNER)
|
||||||
app.midiClock.start()
|
handleOpenIntent(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNewIntent(intent: Intent) {
|
||||||
|
super.onNewIntent(intent)
|
||||||
|
handleOpenIntent(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
if (intent.action != Intent.ACTION_VIEW && intent.action != Intent.ACTION_SEND) return
|
||||||
|
// Consume it, so a configuration change or a re-delivered intent can't
|
||||||
|
// offer the same import twice.
|
||||||
|
setIntent(Intent(this, MainActivity::class.java))
|
||||||
|
lifecycleScope.launch {
|
||||||
|
val song = withContext(Dispatchers.IO) { SongIntents.read(this@MainActivity, intent) }
|
||||||
|
if (song.replaceNow) viewModel.replaceFromMikroSeq(song) else viewModel.offerIncomingSong(song)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// media3's MediaSessionService surface is still marked unstable; we pin the
|
// media3's MediaSessionService surface is still marked unstable; we pin the
|
||||||
@@ -98,6 +133,11 @@ class MainActivity : ComponentActivity() {
|
|||||||
// foreground — a plain startService() from a not-yet-foreground state
|
// foreground — a plain startService() from a not-yet-foreground state
|
||||||
// throws BackgroundServiceStartNotAllowedException on Android 12+.
|
// throws BackgroundServiceStartNotAllowedException on Android 12+.
|
||||||
runCatching { PlaybackService.start(this) }
|
runCatching { PlaybackService.start(this) }
|
||||||
|
// Sound-module mode: (re)start its foreground service while we are allowed
|
||||||
|
// to — a start from the background would be refused.
|
||||||
|
if (app.soundModuleEnabled.value) SoundModuleService.start(this)
|
||||||
|
// Pick up MIDI sources that appeared or whose app restarted while we were away.
|
||||||
|
app.refreshMidi()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
@@ -112,8 +152,9 @@ class MainActivity : ComponentActivity() {
|
|||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
// Release MIDI only when the Activity is actually torn down (task removed or
|
// Release MIDI only when the Activity is actually torn down (task removed or
|
||||||
// finishing), not merely backgrounded / screen-off.
|
// finishing), not merely backgrounded / screen-off.
|
||||||
midi.stop()
|
// The PlaybackService / SoundModuleService keep their own references, so
|
||||||
app.midiClock.stop()
|
// MIDI stays open while either runs.
|
||||||
|
app.releaseMidi(MIDI_OWNER)
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,4 +207,8 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
if (needed.isNotEmpty()) requestPermissions.launch(needed.toTypedArray())
|
if (needed.isNotEmpty()) requestPermissions.launch(needed.toTypedArray())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
const val MIDI_OWNER = "activity"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,19 +4,32 @@
|
|||||||
package cc.tiredsysadmin.android.sizzle
|
package cc.tiredsysadmin.android.sizzle
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
import cc.tiredsysadmin.android.sizzle.audio.AudioEngine
|
import cc.tiredsysadmin.android.sizzle.audio.AudioEngine
|
||||||
import cc.tiredsysadmin.android.sizzle.input.BindingStore
|
import cc.tiredsysadmin.android.sizzle.input.BindingStore
|
||||||
import cc.tiredsysadmin.android.sizzle.input.GamepadInput
|
import cc.tiredsysadmin.android.sizzle.input.GamepadInput
|
||||||
import cc.tiredsysadmin.android.sizzle.input.InputRouter
|
import cc.tiredsysadmin.android.sizzle.input.InputRouter
|
||||||
import cc.tiredsysadmin.android.sizzle.input.KeyboardInput
|
import cc.tiredsysadmin.android.sizzle.input.KeyboardInput
|
||||||
|
import cc.tiredsysadmin.android.sizzle.input.InputAction
|
||||||
import cc.tiredsysadmin.android.sizzle.input.MidiInput
|
import cc.tiredsysadmin.android.sizzle.input.MidiInput
|
||||||
|
import cc.tiredsysadmin.android.sizzle.input.MidiTrace
|
||||||
import cc.tiredsysadmin.android.sizzle.io.PresetLibrary
|
import cc.tiredsysadmin.android.sizzle.io.PresetLibrary
|
||||||
import cc.tiredsysadmin.android.sizzle.io.ProjectStore
|
import cc.tiredsysadmin.android.sizzle.io.ProjectStore
|
||||||
import cc.tiredsysadmin.android.sizzle.io.SettingsStore
|
import cc.tiredsysadmin.android.sizzle.io.SettingsStore
|
||||||
import cc.tiredsysadmin.android.sizzle.io.SongLibrary
|
import cc.tiredsysadmin.android.sizzle.io.SongLibrary
|
||||||
import cc.tiredsysadmin.android.sizzle.io.ThemeLibrary
|
import cc.tiredsysadmin.android.sizzle.io.ThemeLibrary
|
||||||
import cc.tiredsysadmin.android.sizzle.model.Project
|
import cc.tiredsysadmin.android.sizzle.model.Project
|
||||||
|
import cc.tiredsysadmin.android.sizzle.playback.MidiSoundModule
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import cc.tiredsysadmin.android.sizzle.playback.SoundModuleService
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.SupervisorJob
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,7 +48,7 @@ class SizzleApp : Application() {
|
|||||||
/** Neutral input bus shared by touch / keyboard / gamepad / MIDI. */
|
/** Neutral input bus shared by touch / keyboard / gamepad / MIDI. */
|
||||||
val inputRouter: InputRouter by lazy { InputRouter() }
|
val inputRouter: InputRouter by lazy { InputRouter() }
|
||||||
|
|
||||||
/** The real-time sound engine (started/stopped by the PlaybackService). */
|
/** The real-time sound engine (started/released through [acquireEngine]). */
|
||||||
val audioEngine: AudioEngine by lazy { AudioEngine() }
|
val audioEngine: AudioEngine by lazy { AudioEngine() }
|
||||||
|
|
||||||
// Input source handlers are singletons so their (re)bindable maps are shared
|
// Input source handlers are singletons so their (re)bindable maps are shared
|
||||||
@@ -43,7 +56,28 @@ class SizzleApp : Application() {
|
|||||||
// screen (which edits their bindings via MIDI-learn / gamepad rebind).
|
// screen (which edits their bindings via MIDI-learn / gamepad rebind).
|
||||||
val keyboardInput: KeyboardInput by lazy { KeyboardInput(inputRouter) }
|
val keyboardInput: KeyboardInput by lazy { KeyboardInput(inputRouter) }
|
||||||
val gamepadInput: GamepadInput by lazy { GamepadInput(inputRouter) }
|
val gamepadInput: GamepadInput by lazy { GamepadInput(inputRouter) }
|
||||||
val midiInput: MidiInput by lazy { MidiInput(this, 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. */
|
||||||
|
val soundModule: MidiSoundModule by lazy {
|
||||||
|
MidiSoundModule(object : MidiSoundModule.NoteSink {
|
||||||
|
override fun busNoteOn(channel: Int, note: Int, velocity: Int) {
|
||||||
|
if (MidiTrace.on) MidiTrace.log(
|
||||||
|
"engine ON ch=$channel ${MidiTrace.note(note)} v=$velocity -> " +
|
||||||
|
audioEngine.describeBusTargets(channel, note) +
|
||||||
|
if (audioEngine.transport.value.isPlaying) " [Sizzle transport PLAYING]" else "",
|
||||||
|
)
|
||||||
|
audioEngine.busNoteOn(channel, note, velocity)
|
||||||
|
}
|
||||||
|
override fun busNoteOff(channel: Int, note: Int) {
|
||||||
|
if (MidiTrace.on) MidiTrace.log("engine OFF ch=$channel ${MidiTrace.note(note)}")
|
||||||
|
audioEngine.busNoteOff(channel, note)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/** MIDI clock sync (send/receive) over USB + Bluetooth MIDI. */
|
/** MIDI clock sync (send/receive) over USB + Bluetooth MIDI. */
|
||||||
val midiClock: cc.tiredsysadmin.android.sizzle.input.MidiClock by lazy {
|
val midiClock: cc.tiredsysadmin.android.sizzle.input.MidiClock by lazy {
|
||||||
@@ -70,6 +104,12 @@ class SizzleApp : Application() {
|
|||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
// 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
|
// 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.
|
// UI read it, so a crash / process-death resumes where the user left off.
|
||||||
projectStore.restore(project)
|
projectStore.restore(project)
|
||||||
@@ -85,11 +125,116 @@ class SizzleApp : Application() {
|
|||||||
// single small read; blocking briefly at cold start keeps the input maps
|
// single small read; blocking briefly at cold start keeps the input maps
|
||||||
// authoritative from the first keypress rather than racing an async load.
|
// authoritative from the first keypress rather than racing an async load.
|
||||||
runBlocking { bindingStore.loadInto(keyboardInput, gamepadInput, midiInput) }
|
runBlocking { bindingStore.loadInto(keyboardInput, gamepadInput, midiInput) }
|
||||||
// Feed incoming MIDI real-time (clock / start / stop) to the clock sync module.
|
wireMidi()
|
||||||
midiInput.onRealtime = midiClock::handleRealtime
|
|
||||||
installCrashAutosave()
|
installCrashAutosave()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------ shared engine / MIDI lifetime
|
||||||
|
// The Activity, the media PlaybackService and the SoundModuleService can each
|
||||||
|
// outlive the others, so the engine and the MIDI ports are reference-counted by
|
||||||
|
// owner name: started by the first owner, released by the last. Main thread.
|
||||||
|
private val engineOwners = HashSet<String>()
|
||||||
|
private val midiOwners = HashSet<String>()
|
||||||
|
|
||||||
|
fun acquireEngine(owner: String) {
|
||||||
|
if (engineOwners.add(owner) && engineOwners.size == 1) audioEngine.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun releaseEngine(owner: String) {
|
||||||
|
if (engineOwners.remove(owner) && engineOwners.isEmpty()) audioEngine.release()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun acquireMidi(owner: String) {
|
||||||
|
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
|
||||||
|
* isn't open, e.g. after a source's app was reinstalled. */
|
||||||
|
fun refreshMidi() { if (midiOwners.isNotEmpty()) midiInput.refresh() }
|
||||||
|
|
||||||
|
fun releaseMidi(owner: String) {
|
||||||
|
if (midiOwners.remove(owner) && midiOwners.isEmpty()) { bleMidi.closeAll(); midiInput.stop(); midiClock.stop() }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MIDI plumbing that must work with no UI: real-time bytes to the clock
|
||||||
|
* follower, the follower driving the transport/tempo, the clock sender reading
|
||||||
|
* the transport, and each note the sound module plays mirrored onto the input
|
||||||
|
* bus so a visible UI can show it / punch it in (marked `sounded`, so the UI
|
||||||
|
* does not play it a second time). The clock toggles are restored here for the
|
||||||
|
* same reason; the ViewModel restores them again when it exists.
|
||||||
|
*/
|
||||||
|
private fun wireMidi() {
|
||||||
|
val main = Handler(Looper.getMainLooper())
|
||||||
|
soundModule.realtime = midiClock::handleRealtime
|
||||||
|
soundModule.noteListener = { on, channel, note, velocity ->
|
||||||
|
inputRouter.dispatch(
|
||||||
|
if (on) InputAction.NoteOn(note, velocity, channel, sounded = true)
|
||||||
|
else InputAction.NoteOff(note, channel, sounded = true),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
midiClock.playingProvider = { audioEngine.transport.value.isPlaying }
|
||||||
|
midiClock.bpmProvider = { project.tempoBpm }
|
||||||
|
midiClock.noteSource = { audioEngine.pollMidiOut() } // forward sequenced notes out
|
||||||
|
// As a sound module, Sizzle plays the notes another app sends; if that app's
|
||||||
|
// clock Start also started Sizzle's own song, the song would play along
|
||||||
|
// (doubled parts that the sender's mutes can't reach). So Start/Stop drive
|
||||||
|
// the transport only while sound-module mode is off. Tempo is still followed
|
||||||
|
// (tempo-synced LFOs, delays and arpeggiators use it).
|
||||||
|
midiClock.onReceiveStart = {
|
||||||
|
if (_soundModuleEnabled.value) {
|
||||||
|
if (MidiTrace.on) MidiTrace.log("clock Start ignored: sound-module mode is on")
|
||||||
|
} else {
|
||||||
|
if (MidiTrace.on) MidiTrace.log("clock Start -> Sizzle's own sequencer plays the loaded song")
|
||||||
|
main.post { if (!audioEngine.transport.value.isPlaying) audioEngine.play() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
midiClock.onReceiveStop = {
|
||||||
|
if (_soundModuleEnabled.value) {
|
||||||
|
if (MidiTrace.on) MidiTrace.log("clock Stop ignored: sound-module mode is on")
|
||||||
|
} else {
|
||||||
|
if (MidiTrace.on) MidiTrace.log("clock Stop -> Sizzle's own sequencer pauses")
|
||||||
|
main.post { audioEngine.pause() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// An armed master recording follows the external clock's Start/Stop in every
|
||||||
|
// mode (in sound-module mode the clock doesn't start Sizzle's own song).
|
||||||
|
midiClock.onTransport = { start ->
|
||||||
|
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); audioEngine.requestSync() } }
|
||||||
|
val s = runBlocking { settingsStore.load() }
|
||||||
|
midiClock.sendEnabled = s.sendMidiClock
|
||||||
|
audioEngine.midiOutEnabled = s.sendMidiClock
|
||||||
|
midiClock.receiveEnabled = s.receiveMidiClock
|
||||||
|
_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)
|
||||||
|
private val _soundModuleEnabled = MutableStateFlow(false)
|
||||||
|
|
||||||
|
/** "Keep running as MIDI sound module" (Settings). Held here, not in the
|
||||||
|
* ViewModel, because the notification's Stop action turns it off with no UI. */
|
||||||
|
val soundModuleEnabled: StateFlow<Boolean> = _soundModuleEnabled.asStateFlow()
|
||||||
|
|
||||||
|
/** Turn sound-module mode on or off: persist it and start / stop
|
||||||
|
* [SoundModuleService]. Turning it on must happen while the app is in the
|
||||||
|
* foreground (Android refuses a foreground-service start from the background);
|
||||||
|
* [MainActivity] retries on every resume, so a refused start heals itself. */
|
||||||
|
fun setSoundModuleEnabled(enabled: Boolean) {
|
||||||
|
_soundModuleEnabled.value = enabled
|
||||||
|
appScope.launch { settingsStore.saveSoundModule(enabled) }
|
||||||
|
if (enabled) SoundModuleService.start(this) else SoundModuleService.stop(this)
|
||||||
|
}
|
||||||
|
|
||||||
/** Flush an autosave of the current project on any uncaught exception, then let
|
/** Flush an autosave of the current project on any uncaught exception, then let
|
||||||
* the default handler crash/report as usual — so state survives a crash. */
|
* the default handler crash/report as usual — so state survives a crash. */
|
||||||
private fun installCrashAutosave() {
|
private fun installCrashAutosave() {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,296 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
package cc.tiredsysadmin.android.sizzle.audio
|
||||||
|
|
||||||
|
import kotlin.math.PI
|
||||||
|
import kotlin.math.exp
|
||||||
|
import kotlin.math.max
|
||||||
|
import kotlin.math.pow
|
||||||
|
import kotlin.math.sin
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Grain Cloud's built-in sources: ten short recordings synthesised here, so the
|
||||||
|
* app ships no audio files. Each is about six seconds at [RATE], mono, its pitched
|
||||||
|
* material on C (a note C4 plays a source at its own pitch). Deterministic: the same
|
||||||
|
* code makes the same sound on every device.
|
||||||
|
*
|
||||||
|
* ECHOFIELD's own factory sounds come from a generator outside its public
|
||||||
|
* repository; these are new sounds after its names (felt piano, bowed glass, music
|
||||||
|
* box …), not copies.
|
||||||
|
*
|
||||||
|
* Generated off the audio thread: [prewarm] at startup renders them all in the
|
||||||
|
* background (about a second of CPU); [get] never blocks and returns null until a
|
||||||
|
* sound is ready, so the audio thread can ask every block.
|
||||||
|
*/
|
||||||
|
object GrainSources {
|
||||||
|
|
||||||
|
const val RATE = 24_000
|
||||||
|
private const val SECONDS = 6.0
|
||||||
|
private val N = (RATE * SECONDS).toInt()
|
||||||
|
|
||||||
|
private val cache = java.util.concurrent.ConcurrentHashMap<String, SampleStore.Sample>()
|
||||||
|
@Volatile private var started = false
|
||||||
|
|
||||||
|
fun get(name: String): SampleStore.Sample? = cache[name]
|
||||||
|
|
||||||
|
/** Render every source on a background thread (once). */
|
||||||
|
fun prewarm() {
|
||||||
|
if (started) return
|
||||||
|
started = true
|
||||||
|
Thread({ prewarmBlocking() }, "sizzle-grain-sources").apply { priority = Thread.MIN_PRIORITY; isDaemon = true }.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Render every source now, on this thread (tests, or a caller already off the UI). */
|
||||||
|
fun prewarmBlocking() {
|
||||||
|
for ((name, make) in RECIPES) if (!cache.containsKey(name)) cache[name] = SampleStore.Sample(normalize(make()), RATE)
|
||||||
|
}
|
||||||
|
|
||||||
|
private val RECIPES: List<Pair<String, () -> FloatArray>> = listOf(
|
||||||
|
"Felt Piano" to ::feltPiano, "Bowed Glass" to ::bowedGlass, "Music Box" to ::musicBox,
|
||||||
|
"Warm Pad" to ::warmPad, "Strings" to ::strings, "Low Drone" to ::lowDrone,
|
||||||
|
"Rain Field" to ::rainField, "Kalimba" to ::kalimba, "Breath Choir" to ::breathChoir,
|
||||||
|
"Glass Tines" to ::glassTines,
|
||||||
|
)
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ helpers ---
|
||||||
|
private const val C4 = 261.6256
|
||||||
|
private fun hz(semisFromC4: Int) = C4 * 2.0.pow(semisFromC4 / 12.0)
|
||||||
|
private const val TAU = 2 * 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. */
|
||||||
|
private fun strike(out: FloatArray, t0: Double, f: Double, partials: Array<DoubleArray>, attack: Double, gain: Double) {
|
||||||
|
val start = (t0 * RATE).toInt()
|
||||||
|
for (p in partials) {
|
||||||
|
val fr = f * p[0]
|
||||||
|
if (fr > RATE * 0.45) continue
|
||||||
|
val w = TAU * fr / RATE
|
||||||
|
var ph = (p[0] * 1.7) % TAU
|
||||||
|
for (i in start until N) {
|
||||||
|
val t = (i - start).toDouble() / RATE
|
||||||
|
val env = (if (t < attack) t / attack else 1.0) * exp(-p[2] * t)
|
||||||
|
if (env < 1e-4 && t > attack) break
|
||||||
|
out[i] += (gain * p[1] * env * sin(ph)).toFloat()
|
||||||
|
ph += w
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A band-limited saw by its harmonics, with a slow vibrato. */
|
||||||
|
private fun saw(out: FloatArray, f: Double, gain: Double, vibHz: Double, vibCents: Double, phase: Double, ampEnv: (Double) -> Double) {
|
||||||
|
val maxK = max(1, ((RATE * 0.45) / f).toInt()).coerceAtMost(40)
|
||||||
|
val phs = DoubleArray(maxK) { phase * (it + 1) }
|
||||||
|
for (i in 0 until N) {
|
||||||
|
val t = i.toDouble() / RATE
|
||||||
|
val fm = f * 2.0.pow(vibCents * sin(TAU * vibHz * t + phase) / 1200.0)
|
||||||
|
var s = 0.0
|
||||||
|
for (k in 1..maxK) {
|
||||||
|
phs[k - 1] += TAU * fm * k / RATE
|
||||||
|
s += sin(phs[k - 1]) / k
|
||||||
|
}
|
||||||
|
out[i] += (gain * ampEnv(t) * s).toFloat()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class Rng(var s: Int) {
|
||||||
|
fun next(): Int { var x = s; x = x xor (x shl 13); x = x xor (x ushr 17); x = x xor (x shl 5); s = x; return x }
|
||||||
|
fun f(): Double = (next() ushr 8) / 16777216.0
|
||||||
|
fun b(): Double = f() * 2 - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A two-pole resonant band-pass (RBJ, constant peak gain) run over [x]. */
|
||||||
|
private fun bandpass(x: FloatArray, f: Double, q: Double): FloatArray {
|
||||||
|
val w = TAU * f / RATE
|
||||||
|
val alpha = sin(w) / (2 * q)
|
||||||
|
val a0 = 1 + alpha
|
||||||
|
val b0 = alpha / a0; val b2 = -alpha / a0
|
||||||
|
val a1 = -2 * kotlin.math.cos(w) / a0; val a2 = (1 - alpha) / a0
|
||||||
|
val y = FloatArray(x.size)
|
||||||
|
var x1 = 0.0; var x2 = 0.0; var y1 = 0.0; var y2 = 0.0
|
||||||
|
for (i in x.indices) {
|
||||||
|
val v = b0 * x[i] + b2 * x2 - a1 * y1 - a2 * y2
|
||||||
|
x2 = x1; x1 = x[i].toDouble(); y2 = y1; y1 = v
|
||||||
|
y[i] = v.toFloat()
|
||||||
|
}
|
||||||
|
return y
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun lowpass(x: FloatArray, f: Double) {
|
||||||
|
val a = 1 - exp(-TAU * f / RATE)
|
||||||
|
var z = 0.0
|
||||||
|
for (i in x.indices) { z += a * (x[i] - z); x[i] = z.toFloat() }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun normalize(x: FloatArray): FloatArray {
|
||||||
|
var pk = 1e-9f
|
||||||
|
for (v in x) pk = max(pk, kotlin.math.abs(v))
|
||||||
|
val g = 0.89f / pk
|
||||||
|
val fade = RATE / 50
|
||||||
|
for (i in x.indices) {
|
||||||
|
var e = 1f
|
||||||
|
if (i < fade) e = i.toFloat() / fade
|
||||||
|
if (i > x.size - fade) e = (x.size - i).toFloat() / fade
|
||||||
|
x[i] *= g * e
|
||||||
|
}
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ recipes ---
|
||||||
|
private val PENT = intArrayOf(0, 2, 4, 7, 9, 12, 14, 16, 19, 21, 24)
|
||||||
|
|
||||||
|
private fun feltPiano(): FloatArray {
|
||||||
|
val out = FloatArray(N)
|
||||||
|
val partials = Array(8) { k -> doubleArrayOf(k + 1.0 + 0.0008 * (k + 1) * (k + 1), 1.0 / (k + 1).toDouble().pow(1.6), 0.9 + 0.7 * k) }
|
||||||
|
val melody = intArrayOf(0, 7, 4, 11, 2, 9, 7, 16, 12, 4, 14, 7)
|
||||||
|
for ((n, st) in melody.withIndex()) strike(out, 0.05 + n * 0.48, hz(st), partials, 0.006, 0.6)
|
||||||
|
lowpass(out, 3200.0)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun bowedGlass(): FloatArray {
|
||||||
|
val out = FloatArray(N)
|
||||||
|
val ratios = doubleArrayOf(1.0, 2.32, 4.25, 6.63)
|
||||||
|
val levels = doubleArrayOf(1.0, 0.45, 0.22, 0.1)
|
||||||
|
for (k in ratios.indices) {
|
||||||
|
val f = hz(12) * ratios[k]
|
||||||
|
var ph = k * 0.9
|
||||||
|
for (i in 0 until N) {
|
||||||
|
val t = i.toDouble() / RATE
|
||||||
|
val env = (1 - exp(-t / 1.2)) * (0.85 + 0.15 * sin(TAU * 0.23 * t + k))
|
||||||
|
val vib = 1 + 0.0015 * sin(TAU * 4.6 * t)
|
||||||
|
ph += TAU * f * vib / RATE
|
||||||
|
out[i] += (levels[k] * env * sin(ph)).toFloat()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun musicBox(): FloatArray {
|
||||||
|
val out = FloatArray(N)
|
||||||
|
val partials = arrayOf(doubleArrayOf(1.0, 1.0, 1.4), doubleArrayOf(3.01, 0.32, 3.5), doubleArrayOf(5.4, 0.14, 6.0), doubleArrayOf(8.9, 0.05, 9.0))
|
||||||
|
val melody = intArrayOf(12, 16, 19, 24, 21, 19, 16, 14, 12, 19, 16, 24, 26, 24)
|
||||||
|
for ((n, st) in melody.withIndex()) strike(out, 0.04 + n * 0.41, hz(st), partials, 0.002, 0.5)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun kalimba(): FloatArray {
|
||||||
|
val out = FloatArray(N)
|
||||||
|
val partials = arrayOf(doubleArrayOf(1.0, 1.0, 1.1), doubleArrayOf(5.93, 0.22, 7.0), doubleArrayOf(13.4, 0.06, 14.0))
|
||||||
|
val rng = Rng(0x51A1)
|
||||||
|
var t = 0.03
|
||||||
|
while (t < SECONDS - 0.8) {
|
||||||
|
strike(out, t, hz(PENT[(rng.f() * 8).toInt()]), partials, 0.003, 0.55)
|
||||||
|
t += 0.28 + 0.3 * rng.f()
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun glassTines(): FloatArray {
|
||||||
|
val out = FloatArray(N)
|
||||||
|
val partials = arrayOf(doubleArrayOf(1.0, 1.0, 0.8), doubleArrayOf(2.756, 0.4, 1.6), doubleArrayOf(5.404, 0.18, 2.8), doubleArrayOf(8.93, 0.07, 4.0))
|
||||||
|
val rng = Rng(0x7123)
|
||||||
|
var t = 0.02
|
||||||
|
while (t < SECONDS - 0.6) {
|
||||||
|
strike(out, t, hz(12 + PENT[(rng.f() * 9).toInt()]), partials, 0.002, 0.4)
|
||||||
|
t += 0.17 + 0.25 * rng.f()
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun warmPad(): FloatArray {
|
||||||
|
val out = FloatArray(N)
|
||||||
|
val chord = intArrayOf(-12, 0, 4, 7, 11, 14)
|
||||||
|
for ((n, st) in chord.withIndex()) for (d in 0 until 2) {
|
||||||
|
val det = if (d == 0) -6.0 else 6.0
|
||||||
|
saw(out, hz(st) * 2.0.pow(det / 1200), 0.18, 0.2 + 0.05 * n, 4.0, n * 0.7 + d, { t -> (1 - exp(-t / 0.8)) })
|
||||||
|
}
|
||||||
|
// a slow opening low-pass: three passes at a cutoff that rises over the sound
|
||||||
|
val a = FloatArray(N); System.arraycopy(out, 0, a, 0, N)
|
||||||
|
var z1 = 0.0; var z2 = 0.0
|
||||||
|
for (i in 0 until N) {
|
||||||
|
val t = i.toDouble() / RATE
|
||||||
|
val fc = 500 + 1800 * (0.5 - 0.5 * kotlin.math.cos(TAU * t / SECONDS))
|
||||||
|
val k = 1 - exp(-TAU * fc / RATE)
|
||||||
|
z1 += k * (a[i] - z1); z2 += k * (z1 - z2)
|
||||||
|
out[i] = z2.toFloat()
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun strings(): FloatArray {
|
||||||
|
val out = FloatArray(N)
|
||||||
|
val voices = intArrayOf(-12, -5, 0, 4, 7)
|
||||||
|
for ((n, st) in voices.withIndex()) for (d in 0 until 3) {
|
||||||
|
val det = (d - 1) * 7.0
|
||||||
|
saw(out, hz(st) * 2.0.pow(det / 1200), 0.14, 5.1 + 0.4 * d, 9.0, n * 1.3 + d * 0.5,
|
||||||
|
{ t -> (1 - exp(-t / 0.45)) * (0.8 + 0.2 * sin(TAU * 0.3 * t + n)) })
|
||||||
|
}
|
||||||
|
lowpass(out, 2600.0); lowpass(out, 5000.0)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun lowDrone(): FloatArray {
|
||||||
|
val out = FloatArray(N)
|
||||||
|
val parts = arrayOf(doubleArrayOf(hz(-24), 1.0), doubleArrayOf(hz(-24) * 2.003, 0.5), doubleArrayOf(hz(-17), 0.55),
|
||||||
|
doubleArrayOf(hz(-17) * 2.0, 0.25), doubleArrayOf(hz(-12) * 1.002, 0.3), doubleArrayOf(hz(-24) * 3.0, 0.18))
|
||||||
|
for ((n, p) in parts.withIndex()) {
|
||||||
|
var ph = n * 1.1
|
||||||
|
for (i in 0 until N) {
|
||||||
|
val t = i.toDouble() / RATE
|
||||||
|
ph += TAU * p[0] / RATE
|
||||||
|
val am = 0.75 + 0.25 * sin(TAU * (0.11 + 0.07 * n) * t + n)
|
||||||
|
out[i] += (p[1] * am * (sin(ph) + 0.15 * sin(2 * ph))).toFloat()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun breathChoir(): FloatArray {
|
||||||
|
val rng = Rng(0x0B2E)
|
||||||
|
val noise = FloatArray(N) { rng.b().toFloat() }
|
||||||
|
// a voiced source under the breath: a soft buzz at C4 and its fifth
|
||||||
|
val buzz = FloatArray(N)
|
||||||
|
saw(buzz, hz(0), 0.25, 5.0, 8.0, 0.0, { t -> 1 - exp(-t / 0.6) })
|
||||||
|
saw(buzz, hz(7), 0.18, 4.6, 8.0, 1.0, { t -> 1 - exp(-t / 0.9) })
|
||||||
|
val src = FloatArray(N) { noise[it] * 0.6f + buzz[it] }
|
||||||
|
// "ah" formants drifting toward "oh"
|
||||||
|
val f1 = bandpass(src, 750.0, 6.0); val f2 = bandpass(src, 1150.0, 8.0); val f3 = bandpass(src, 2600.0, 10.0)
|
||||||
|
val g1 = bandpass(src, 500.0, 6.0); val g2 = bandpass(src, 900.0, 8.0)
|
||||||
|
val out = FloatArray(N)
|
||||||
|
for (i in 0 until N) {
|
||||||
|
val t = i.toDouble() / RATE
|
||||||
|
val m = 0.5 - 0.5 * kotlin.math.cos(TAU * t / SECONDS)
|
||||||
|
val swell = (1 - exp(-t / 0.7)) * (0.7 + 0.3 * sin(TAU * 0.4 * t))
|
||||||
|
out[i] = (swell * ((1 - m) * (f1[i] + 0.7 * f2[i]) + m * (g1[i] + 0.6 * g2[i]) + 0.3 * f3[i])).toFloat()
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun rainField(): FloatArray {
|
||||||
|
val out = FloatArray(N)
|
||||||
|
val rng = Rng(0x2A1F)
|
||||||
|
// the bed: soft filtered noise
|
||||||
|
var z = 0.0; var z2 = 0.0
|
||||||
|
for (i in 0 until N) {
|
||||||
|
z += 0.08 * (rng.b() - z); z2 += 0.3 * (z - z2)
|
||||||
|
out[i] = (0.5 * (z - 0.6 * z2)).toFloat()
|
||||||
|
}
|
||||||
|
// drops: short pitched blips at random
|
||||||
|
var t = 0.0
|
||||||
|
while (t < SECONDS - 0.1) {
|
||||||
|
val f = 900 + 3200 * rng.f()
|
||||||
|
val start = (t * RATE).toInt()
|
||||||
|
val a = 0.15 + 0.35 * rng.f()
|
||||||
|
var ph = 0.0
|
||||||
|
for (i in start until minOf(N, start + RATE / 10)) {
|
||||||
|
val tt = (i - start).toDouble() / RATE
|
||||||
|
ph += TAU * f * (1 + 0.6 * exp(-tt * 60)) / RATE
|
||||||
|
out[i] += (a * exp(-tt * 55) * sin(ph)).toFloat()
|
||||||
|
}
|
||||||
|
t += 0.01 + 0.08 * rng.f().pow(2.0)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,39 +4,23 @@
|
|||||||
package cc.tiredsysadmin.android.sizzle.audio
|
package cc.tiredsysadmin.android.sizzle.audio
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bridges the native Oboe (AAudio) output backend to the Kotlin [AudioEngine].
|
* 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 C++ side (see `src/main/cpp/native_audio.cpp`) opens a low-latency Oboe
|
* the JVM on the audio thread. If it can't start, [AudioEngine] falls back to an
|
||||||
* stream whose real-time data callback calls [renderAudio] via JNI, which simply
|
* AudioTrack loop that renders through [NativeEngine.nativeRender].
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
class NativeAudioBridge(private val engine: AudioEngine) {
|
class NativeAudioBridge {
|
||||||
|
fun start(sampleRate: Int): Boolean = if (NativeEngine.loaded) nativeStart(sampleRate) else false
|
||||||
/** 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
|
|
||||||
|
|
||||||
fun stop() {
|
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()
|
private external fun nativeStop()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val LIB_LOADED = runCatching { System.loadLibrary("sizzle_native") }.isSuccess
|
/** Whether the native library loaded on this build/device. */
|
||||||
|
fun isAvailable(): Boolean = NativeEngine.loaded
|
||||||
/** Whether the native Oboe backend is available on this build/device. */
|
|
||||||
fun isAvailable(): Boolean = LIB_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>()
|
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]
|
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
|
/** 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. */
|
* 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].
|
* Decode a WAV file (the common uncompressed formats) into a mono [Sample].
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Philip Bos (ECHOFIELD)
|
||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown (Kotlin port for Sizzle)
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
//
|
||||||
|
// Ported from ECHOFIELD FM-1 (https://github.com/Philip-Bos/echofield-fm1, commit 4734e97):
|
||||||
|
// app/params.c (the parameters, their ranges and defaults) and app/presets.c (the
|
||||||
|
// factory presets). The MIT licence text is in LICENSES/MIT.txt of this repository.
|
||||||
|
|
||||||
|
package cc.tiredsysadmin.android.sizzle.echofield
|
||||||
|
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.ParamSpec
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Grain Cloud's settings and factory presets, taken from ECHOFIELD's granular
|
||||||
|
* engine. Keys are ECHOFIELD's own parameter names.
|
||||||
|
*
|
||||||
|
* Left out (Sizzle has its own, or they need stereo): ECHOFIELD's effects (filter,
|
||||||
|
* drive, echo, reverb + shimmer, tape), WIDTH, the DRIFT ORACLE (it plays notes by
|
||||||
|
* itself while no key is held), LATCH and the performance effects. Kept as a
|
||||||
|
* setting: FREEZE. Added for Sizzle: SOURCE (a built-in sound or your own sample).
|
||||||
|
*/
|
||||||
|
object EchofieldDefs {
|
||||||
|
|
||||||
|
val MODES = listOf("Cloud", "Dust", "Tape", "Bloom", "Pulse", "Drift")
|
||||||
|
val WINDOWS = listOf("Auto", "Hann", "Tukey", "Perc", "Swell", "Gauss")
|
||||||
|
const val CUSTOM = "Custom"
|
||||||
|
|
||||||
|
/** The built-in sources (synthesised by Sizzle, see GrainSources), then your own. */
|
||||||
|
val SOURCES = listOf(
|
||||||
|
"Felt Piano", "Bowed Glass", "Music Box", "Warm Pad", "Strings",
|
||||||
|
"Low Drone", "Rain Field", "Kalimba", "Breath Choir", "Glass Tines", CUSTOM,
|
||||||
|
)
|
||||||
|
|
||||||
|
/** Where a custom sample's id and its file live: the same keys the SF2/XI loader
|
||||||
|
* uses, so the preset library, project bundles and startup rehydration carry it. */
|
||||||
|
const val SAMPLE_KEY = "sfSample"
|
||||||
|
|
||||||
|
val PARAMS: List<ParamSpec> by lazy {
|
||||||
|
listOf(
|
||||||
|
ParamSpec("source", "Source", choices = SOURCES),
|
||||||
|
ParamSpec("mode", "Mode", choices = MODES),
|
||||||
|
ParamSpec("position", "Position", 0.35f, 0f, 1f),
|
||||||
|
ParamSpec("texture", "Texture", 0.72f, 0f, 1f),
|
||||||
|
ParamSpec("scatter", "Scatter", 0.45f, 0f, 1f),
|
||||||
|
ParamSpec("drift", "Drift", 0.35f, 0f, 1f),
|
||||||
|
ParamSpec("motion", "Evolve", 0.35f, 0f, 1f),
|
||||||
|
ParamSpec("pitch", "Pitch", 0f, -24f, 24f, isInt = true),
|
||||||
|
ParamSpec("harmony", "Harmony", 0.30f, 0f, 1f),
|
||||||
|
ParamSpec("size_mul", "Size", 0f, -2f, 2f),
|
||||||
|
ParamSpec("dens_mul", "Density", 0f, -2f, 2f),
|
||||||
|
ParamSpec("scan", "Scan", 0f, -1f, 1f),
|
||||||
|
ParamSpec("reverse", "Reverse", 0.10f, 0f, 1f),
|
||||||
|
ParamSpec("pitch_rand", "Pitch Rnd", 0f, 0f, 12f),
|
||||||
|
ParamSpec("size_rand", "Size Rnd", 0.3f, 0f, 1f),
|
||||||
|
ParamSpec("window", "Envelope", choices = WINDOWS),
|
||||||
|
ParamSpec("grain_tone", "Tone", -0.1f, -1f, 1f),
|
||||||
|
ParamSpec("attack", "Attack", 0.15f, 0f, 1f),
|
||||||
|
ParamSpec("release", "Release", 0.45f, 0f, 1f),
|
||||||
|
ParamSpec("velo", "Velocity", 0.5f, 0f, 1f),
|
||||||
|
ParamSpec("start", "Start", 0f, 0f, 1f),
|
||||||
|
ParamSpec("end", "End", 1f, 0f, 1f),
|
||||||
|
ParamSpec("freeze", "Freeze", choices = listOf("Off", "On")),
|
||||||
|
ParamSpec("level", "Level", 0.75f, 0f, 1f),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class Preset(val name: String, val values: Map<String, String>)
|
||||||
|
|
||||||
|
/** ECHOFIELD's 14 factory presets (presets.c FACTORY) on Sizzle's built-in sources;
|
||||||
|
* their effect settings are left out with the effects. */
|
||||||
|
val FACTORY: List<Preset> by lazy {
|
||||||
|
fun p(name: String, source: String, mode: Int, vararg v: Pair<String, Float>): Preset {
|
||||||
|
val m = LinkedHashMap<String, String>()
|
||||||
|
for (spec in PARAMS) m[spec.key] = if (spec.isEnum) spec.choices[0] else spec.default.toString()
|
||||||
|
m["source"] = source
|
||||||
|
m["mode"] = MODES[mode]
|
||||||
|
for ((k, x) in v) m[k] = x.toString()
|
||||||
|
return Preset(name, m)
|
||||||
|
}
|
||||||
|
listOf(
|
||||||
|
p("Felt Clouds", "Felt Piano", 0, "texture" to 0.78f, "scatter" to 0.50f, "drift" to 0.35f, "motion" to 0.30f, "harmony" to 0.35f),
|
||||||
|
p("Glass Choir", "Bowed Glass", 3, "texture" to 0.70f, "scatter" to 0.40f, "drift" to 0.30f, "motion" to 0.35f, "harmony" to 0.50f),
|
||||||
|
p("Dust Lights", "Music Box", 1, "texture" to 0.45f, "scatter" to 0.70f, "drift" to 0.30f, "motion" to 0.40f, "harmony" to 0.30f),
|
||||||
|
p("Warm Tide", "Warm Pad", 5, "texture" to 0.70f, "scatter" to 0.45f, "drift" to 0.55f, "motion" to 0.40f, "harmony" to 0.25f),
|
||||||
|
p("Slow Tapes", "Strings", 2, "texture" to 0.60f, "scatter" to 0.25f, "drift" to 0.40f, "motion" to 0.35f, "harmony" to 0.15f),
|
||||||
|
p("Deep Water", "Low Drone", 0, "texture" to 0.85f, "scatter" to 0.40f, "drift" to 0.40f, "motion" to 0.25f, "harmony" to 0.40f),
|
||||||
|
p("Rain Cathedral", "Rain Field", 0, "texture" to 0.88f, "scatter" to 0.60f, "drift" to 0.40f, "motion" to 0.30f, "harmony" to 0.45f),
|
||||||
|
p("Kalimba Steps", "Kalimba", 4, "texture" to 0.40f, "scatter" to 0.60f, "drift" to 0.30f, "motion" to 0.30f, "harmony" to 0.20f),
|
||||||
|
p("Hymn", "Breath Choir", 0, "texture" to 0.85f, "scatter" to 0.45f, "drift" to 0.35f, "motion" to 0.30f, "harmony" to 0.40f),
|
||||||
|
p("Breath Choir", "Breath Choir", 3, "texture" to 0.75f, "scatter" to 0.50f, "drift" to 0.40f, "motion" to 0.40f, "harmony" to 0.35f),
|
||||||
|
p("Night Current", "Low Drone", 5, "texture" to 0.65f, "scatter" to 0.40f, "drift" to 0.60f, "motion" to 0.40f),
|
||||||
|
p("Glass Rain", "Glass Tines", 1, "texture" to 0.35f, "scatter" to 0.55f, "drift" to 0.20f, "motion" to 0.50f, "pitch" to 12f, "reverse" to 0.20f, "grain_tone" to 0.40f),
|
||||||
|
p("Broken Stars", "Kalimba", 3, "texture" to 0.60f, "scatter" to 0.70f, "drift" to 0.50f, "motion" to 0.50f),
|
||||||
|
p("Far Broadcast", "Rain Field", 2, "texture" to 0.50f, "scatter" to 0.20f, "drift" to 0.40f, "motion" to 0.40f),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,220 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Styves Goupil (FRASIL)
|
||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown (Kotlin port for Sizzle)
|
||||||
|
// 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).
|
||||||
|
//
|
||||||
|
// Ported from FRASIL 3.3 (https://github.com/styvesgoupil/frasil, commit e7a8fb2):
|
||||||
|
// engine/params.c (the drone's settings, their ranges, the 36 drone presets).
|
||||||
|
|
||||||
|
package cc.tiredsysadmin.android.sizzle.frasil
|
||||||
|
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.ParamSpec
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Morph Pad's settings and factory sounds, taken from FRASIL's drone (its
|
||||||
|
* CHOEUR / PARTIELS / SOUFFLE layers, MOTION and TIDE) and its 36 drone presets.
|
||||||
|
*
|
||||||
|
* Every slider is stored 0..1 exactly as FRASIL's 0..127 settings divided by 127;
|
||||||
|
* [engineFrom] turns them into the engine's units (FRASIL params.c
|
||||||
|
* `params_to_engine`). Three settings are choices (INTERVAL, TYPE, PITCH).
|
||||||
|
*
|
||||||
|
* Left out, because Sizzle's channels are mono or Sizzle has its own: SPREAD (the
|
||||||
|
* voices across the stereo field), SPACE (FRASIL's own reverb: put an Ambience on
|
||||||
|
* the channel instead), PRESSURE, TUNE, GLINT / BASS / LEAD and the master effects.
|
||||||
|
*
|
||||||
|
* Added for Sizzle: MORPH. FRASIL glides a whole scene to another over 1..120 s;
|
||||||
|
* here a pad morphs toward one of the factory sounds ([MORPH_TO]), by hand
|
||||||
|
* ([MORPH], an LFO can move it) and, with [MORPH_TIME], on its own while a note is
|
||||||
|
* held: each note starts at MORPH and arrives at the target after MORPH TIME.
|
||||||
|
*/
|
||||||
|
object FrasilDefs {
|
||||||
|
|
||||||
|
const val MORPH_TO = "morphTo"
|
||||||
|
const val MORPH = "morph"
|
||||||
|
const val MORPH_TIME = "mtime"
|
||||||
|
|
||||||
|
val INTERVALS = listOf("Unison", "-12", "+7", "+12")
|
||||||
|
private val INTERVAL_RATIO = floatArrayOf(1f, 0.5f, 1.4983071f, 2f)
|
||||||
|
val FILTER_TYPES = listOf("Low", "Band", "High")
|
||||||
|
val BREATH_PITCHES = listOf("-12", "Unison", "+12", "+19", "+24")
|
||||||
|
private val BREATH_RATIO = floatArrayOf(0.5f, 1f, 2f, 2.9966142f, 4f)
|
||||||
|
|
||||||
|
// ---- engine parameter indices (FrasilPatch arrays; all glide, as FRASIL's floats do) ----
|
||||||
|
const val CHOIR = 0
|
||||||
|
const val PARTIALS = 1
|
||||||
|
const val BREATH = 2
|
||||||
|
const val WARMTH = 3
|
||||||
|
const val DETUNE = 4
|
||||||
|
const val CUTOFF = 5
|
||||||
|
const val TILT = 6
|
||||||
|
const val ODD = 7
|
||||||
|
const val STRETCH = 8
|
||||||
|
const val RESONANCE = 9
|
||||||
|
const val COLOR = 10
|
||||||
|
const val ATTACK = 11
|
||||||
|
const val RELEASE = 12
|
||||||
|
const val MOTION = 13
|
||||||
|
const val MOTION_RATE = 14
|
||||||
|
const val TIDE = 15
|
||||||
|
const val TIDE_RATE = 16
|
||||||
|
const val TIMBRE = 17
|
||||||
|
const val SHAPE = 18
|
||||||
|
const val CH_RESO = 19
|
||||||
|
const val EVOLVE = 20
|
||||||
|
const val BEAT = 21
|
||||||
|
const val FORMANT = 22 // log2 of the harmonic, 0..3
|
||||||
|
const val PEAK = 23
|
||||||
|
const val GRAIN = 24
|
||||||
|
const val TONE = 25 // -1 dark .. 1 bright
|
||||||
|
const val AIR = 26
|
||||||
|
const val SOFT = 27
|
||||||
|
const val VELOCITY = 28
|
||||||
|
const val BODY = 29 // FRASIL's FULLNESS
|
||||||
|
const val INTERVAL = 30 // the centre saw's ratio
|
||||||
|
const val BR_PITCH = 31 // the resonators' ratio
|
||||||
|
const val N = 32
|
||||||
|
|
||||||
|
/** The slider/choice parameters, in editor order. Defaults: FRASIL's MIST. */
|
||||||
|
val PARAMS: List<ParamSpec> by lazy { listOf(
|
||||||
|
ParamSpec(MORPH_TO, "Morph To", choices = listOf("Off") + PRESET_NAMES()),
|
||||||
|
ParamSpec(MORPH, "Morph", 0f, 0f, 1f),
|
||||||
|
ParamSpec(MORPH_TIME, "Morph Time s", 0f, 0f, 120f),
|
||||||
|
ParamSpec("choir", "Choir", r(76)), ParamSpec("partials", "Partials", r(89)),
|
||||||
|
ParamSpec("breath", "Breath", r(32)), ParamSpec("timbre", "Timbre", r(64)),
|
||||||
|
ParamSpec("warmth", "Warmth", r(19)), ParamSpec("body", "Body", 1f),
|
||||||
|
ParamSpec("attack", "Attack", r(89)), ParamSpec("release", "Release", r(83)),
|
||||||
|
ParamSpec("velsens", "Velocity", r(38)),
|
||||||
|
ParamSpec("motion", "Motion", r(44)), ParamSpec("mrate", "Motion Rate", r(51)),
|
||||||
|
ParamSpec("tide", "Tide", r(25)), ParamSpec("tperiod", "Tide Speed", r(38)),
|
||||||
|
ParamSpec("detune", "Detune", r(51)), ParamSpec("cfilter", "Filter", r(44)),
|
||||||
|
ParamSpec("shape", "Shape", 0f), ParamSpec("interval", "Interval", choices = INTERVALS),
|
||||||
|
ParamSpec("creso", "Resonance", 0f), ParamSpec("ctype", "Filter Type", choices = FILTER_TYPES),
|
||||||
|
ParamSpec("soft", "Soft", 0f),
|
||||||
|
ParamSpec("tilt", "Tilt", r(57)), ParamSpec("odd", "Odd", r(25)),
|
||||||
|
ParamSpec("stretch", "Stretch", 0f), ParamSpec("evolve", "Evolve", 0f),
|
||||||
|
ParamSpec("beat", "Beat", 0f), ParamSpec("formant", "Formant", r(85)),
|
||||||
|
ParamSpec("peak", "Peak", 0f),
|
||||||
|
ParamSpec("bres", "Glass", r(70)), ParamSpec("color", "Color", 0f),
|
||||||
|
ParamSpec("grain", "Grain", 0f), ParamSpec("bpitch", "Pitch", choices = BREATH_PITCHES),
|
||||||
|
ParamSpec("btone", "Tone", r(64)), ParamSpec("air", "Air", 0f),
|
||||||
|
) }
|
||||||
|
|
||||||
|
|
||||||
|
private fun r(v: Int) = v / 127f
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A sound's engine values from its stored settings: [num] reads a slider (0..1,
|
||||||
|
* its default if absent), [choice] a choice's label. Returns the float array
|
||||||
|
* and the choir filter's TYPE (0 low, 1 band, 2 high).
|
||||||
|
*/
|
||||||
|
fun engineFrom(num: (String, Float) -> Float, choice: (String, String) -> String): Pair<FloatArray, Int> {
|
||||||
|
val e = FloatArray(N)
|
||||||
|
fun u(key: String, def: Float) = num(key, def).coerceIn(0f, 1f)
|
||||||
|
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", 0f)
|
||||||
|
e[RESONANCE] = u("bres", r(70)); e[COLOR] = u("color", 0f)
|
||||||
|
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", 0f); e[CH_RESO] = u("creso", 0f)
|
||||||
|
e[EVOLVE] = u("evolve", 0f); e[BEAT] = u("beat", 0f)
|
||||||
|
e[FORMANT] = 3f * u("formant", r(85)); e[PEAK] = u("peak", 0f)
|
||||||
|
e[GRAIN] = u("grain", 0f)
|
||||||
|
val tn = u("btone", r(64)) * 127f
|
||||||
|
e[TONE] = if (tn >= 126.5f) 1f else (tn - 64f) / 63f
|
||||||
|
e[AIR] = u("air", 0f); e[SOFT] = u("soft", 0f)
|
||||||
|
e[VELOCITY] = u("velsens", r(38)); e[BODY] = u("body", 1f)
|
||||||
|
e[INTERVAL] = INTERVAL_RATIO[INTERVALS.indexOf(choice("interval", INTERVALS[0])).coerceAtLeast(0)]
|
||||||
|
e[BR_PITCH] = BREATH_RATIO[BREATH_PITCHES.indexOf(choice("bpitch", BREATH_PITCHES[1])).let { if (it < 0) 1 else it }]
|
||||||
|
val type = FILTER_TYPES.indexOf(choice("ctype", FILTER_TYPES[0])).coerceAtLeast(0)
|
||||||
|
return e to type
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------- presets ---
|
||||||
|
|
||||||
|
class Preset(val name: String, val values: Map<String, String>)
|
||||||
|
|
||||||
|
/** FRASIL's 36 drone presets, each as the slot values it sets (params.c DRONE_PRESET). */
|
||||||
|
val FACTORY: List<Preset> by lazy {
|
||||||
|
RAW.map { (name, row) ->
|
||||||
|
val m = LinkedHashMap<String, String>()
|
||||||
|
for (c in COLS.indices) {
|
||||||
|
val key = COLS[c] ?: continue
|
||||||
|
m[key] = when (key) {
|
||||||
|
"interval" -> INTERVALS[row[c] % 4]
|
||||||
|
"ctype" -> FILTER_TYPES[row[c] % 3]
|
||||||
|
"bpitch" -> BREATH_PITCHES[row[c] % 5]
|
||||||
|
else -> (row[c] / 127f).toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Sizzle's own, not in FRASIL's preset: as FRASIL's defaults, no morph.
|
||||||
|
m["velsens"] = r(38).toString(); m["body"] = "1.0"
|
||||||
|
m[MORPH_TO] = "Off"; m[MORPH] = "0.0"; m[MORPH_TIME] = "0.0"
|
||||||
|
Preset(name, m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A factory sound's engine values by its name (MORPH TO's target), or null. */
|
||||||
|
fun factoryEngine(name: String): Pair<FloatArray, Int>? = engineByName[name]
|
||||||
|
|
||||||
|
private val engineByName: Map<String, Pair<FloatArray, Int>> by lazy {
|
||||||
|
FACTORY.associate { p ->
|
||||||
|
p.name to engineFrom({ k, d -> p.values[k]?.toFloatOrNull() ?: d }, { k, d -> p.values[k] ?: d })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
private val COLS: Array<String?> = arrayOf(
|
||||||
|
"choir", "partials", "breath", "warmth", "detune", "cfilter", "tilt", "odd", "stretch", "bres", "color",
|
||||||
|
null, "attack", "release", "motion", "mrate", "tide", "tperiod", "timbre", null, "shape", "interval",
|
||||||
|
"creso", "ctype", "evolve", "beat", "formant", "peak", "grain", "bpitch", "btone", "air", "soft",
|
||||||
|
)
|
||||||
|
|
||||||
|
private fun PRESET_NAMES(): List<String> = RAW.map { it.first }
|
||||||
|
|
||||||
|
private val RAW: List<Pair<String, IntArray>> by lazy {
|
||||||
|
listOf(
|
||||||
|
"Mist" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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" to intArrayOf(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),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,8 +37,10 @@ sealed interface InputAction {
|
|||||||
// routed to the mixer track(s) listening on it; it is -1 when the source has no
|
// routed to the mixer track(s) listening on it; it is -1 when the source has no
|
||||||
// channel of its own (physical / on-screen keyboard), which falls back to the
|
// channel of its own (physical / on-screen keyboard), which falls back to the
|
||||||
// on-screen keyboard's channel.
|
// on-screen keyboard's channel.
|
||||||
data class NoteOn(val pitch: Int, val velocity: Int, val channel: Int = -1) : InputAction
|
// [sounded] is true when the note was already played by the headless sound
|
||||||
data class NoteOff(val pitch: Int, val channel: Int = -1) : InputAction
|
// module (MIDI input): the UI only shows it / punches it in, never plays it again.
|
||||||
|
data class NoteOn(val pitch: Int, val velocity: Int, val channel: Int = -1, val sounded: Boolean = false) : InputAction
|
||||||
|
data class NoteOff(val pitch: Int, val channel: Int = -1, val sounded: Boolean = false) : InputAction
|
||||||
|
|
||||||
// ----- Transport -----
|
// ----- Transport -----
|
||||||
data object PlayPause : InputAction
|
data object PlayPause : InputAction
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
package cc.tiredsysadmin.android.sizzle.input
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turns a raw MIDI byte stream into whole messages. Pure Kotlin (no Android types)
|
||||||
|
* so it is unit-tested directly.
|
||||||
|
*
|
||||||
|
* One parser per source: it keeps running status (a channel message may omit its
|
||||||
|
* status byte when it repeats the previous one, which USB and serial gear do) and
|
||||||
|
* a message split across two `onSend` packets, and both are per-stream state.
|
||||||
|
* System Real-Time bytes (0xF8..0xFF) may sit anywhere, even inside another
|
||||||
|
* message, and go straight to [onRealtime]. SysEx (0xF0..0xF7) is skipped.
|
||||||
|
*
|
||||||
|
* Not thread-safe; Android delivers one port's packets on one thread.
|
||||||
|
*/
|
||||||
|
class MidiByteParser(
|
||||||
|
/** A complete channel message: status (0x80..0xEF) and its data bytes (0 when absent). */
|
||||||
|
private val onChannel: (status: Int, d1: Int, d2: Int) -> Unit,
|
||||||
|
/** A System Real-Time byte: clock 0xF8, Start 0xFA, Continue 0xFB, Stop 0xFC, … */
|
||||||
|
private val onRealtime: (status: Int) -> Unit,
|
||||||
|
) {
|
||||||
|
private var running = 0 // running status, 0 = none
|
||||||
|
private var need = 0 // data bytes the current message needs
|
||||||
|
private var got = 0
|
||||||
|
private var d1 = 0
|
||||||
|
private var inSysex = false
|
||||||
|
|
||||||
|
fun feed(data: ByteArray, offset: Int, count: Int) {
|
||||||
|
val end = (offset + count).coerceAtMost(data.size)
|
||||||
|
for (i in offset.coerceAtLeast(0) until end) byte(data[i].toInt() and 0xFF)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun byte(b: Int) {
|
||||||
|
when {
|
||||||
|
b >= 0xF8 -> onRealtime(b) // never disturbs running status
|
||||||
|
b == 0xF0 -> { inSysex = true; running = 0 }
|
||||||
|
b == 0xF7 -> inSysex = false
|
||||||
|
b >= 0xF1 -> { // system common: cancels running status; its data is ignored
|
||||||
|
inSysex = false; running = 0; need = 0
|
||||||
|
}
|
||||||
|
b >= 0x80 -> {
|
||||||
|
inSysex = false
|
||||||
|
running = b; got = 0
|
||||||
|
need = if ((b and 0xF0) == 0xC0 || (b and 0xF0) == 0xD0) 1 else 2
|
||||||
|
}
|
||||||
|
inSysex || running == 0 -> {} // stray data byte
|
||||||
|
else -> {
|
||||||
|
if (got == 0) d1 = b
|
||||||
|
got++
|
||||||
|
if (got >= need) {
|
||||||
|
onChannel(running, d1, if (need == 2) b else 0)
|
||||||
|
got = 0 // running status: the next data byte starts a new message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,10 @@ import android.media.midi.MidiManager
|
|||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import java.util.concurrent.CopyOnWriteArrayList
|
import java.util.concurrent.CopyOnWriteArrayList
|
||||||
|
import kotlinx.coroutines.channels.BufferOverflow
|
||||||
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
|
import kotlinx.coroutines.flow.SharedFlow
|
||||||
|
import kotlinx.coroutines.flow.asSharedFlow
|
||||||
import java.util.concurrent.locks.LockSupport
|
import java.util.concurrent.locks.LockSupport
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,30 +38,43 @@ class MidiClock(context: Context) {
|
|||||||
@Volatile var sendEnabled = false
|
@Volatile var sendEnabled = false
|
||||||
@Volatile var receiveEnabled = false
|
@Volatile var receiveEnabled = false
|
||||||
|
|
||||||
/** Live transport state for the send thread, supplied by the ViewModel. */
|
/** Live transport state for the send thread, wired up by [cc.tiredsysadmin.android.sizzle.SizzleApp]. */
|
||||||
var playingProvider: () -> Boolean = { false }
|
var playingProvider: () -> Boolean = { false }
|
||||||
var bpmProvider: () -> Float = { 120f }
|
var bpmProvider: () -> Float = { 120f }
|
||||||
|
|
||||||
/** Source of queued outgoing note messages (packed (status<<16)|(d1<<8)|d2), or -1
|
/** Source of queued outgoing note messages (packed (status<<16)|(d1<<8)|d2), or -1
|
||||||
* when empty — drained by the send thread while [sendEnabled]. Set by the ViewModel
|
* when empty — drained by the send thread while [sendEnabled]. Set by SizzleApp
|
||||||
* to the audio engine's queue, so Sizzle's sequenced notes reach external gear. */
|
* to the audio engine's queue, so Sizzle's sequenced notes reach external gear. */
|
||||||
var noteSource: (() -> Int)? = null
|
var noteSource: (() -> Int)? = null
|
||||||
|
|
||||||
/** Receive callbacks (invoked on the MIDI handler thread; the ViewModel hops to
|
/** Receive callbacks (invoked on the MIDI port's thread; SizzleApp hops to the
|
||||||
* the main thread as needed). */
|
* main thread). */
|
||||||
var onReceiveStart: (() -> Unit)? = null
|
var onReceiveStart: (() -> Unit)? = null
|
||||||
var onReceiveStop: (() -> Unit)? = null
|
var onReceiveStop: (() -> Unit)? = null
|
||||||
var onReceiveTempo: ((Float) -> Unit)? = null
|
var onReceiveTempo: ((Float) -> Unit)? = null
|
||||||
|
|
||||||
|
private val _followedTempo = MutableSharedFlow<Float>(
|
||||||
|
extraBufferCapacity = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST,
|
||||||
|
)
|
||||||
|
/** Each tempo taken from an external clock, after [onReceiveTempo] applied it, so
|
||||||
|
* the UI can redraw. Nothing is buffered for a UI that isn't collecting. */
|
||||||
|
val followedTempo: SharedFlow<Float> = _followedTempo.asSharedFlow()
|
||||||
|
|
||||||
private var thread: Thread? = null
|
private var thread: Thread? = null
|
||||||
@Volatile private var running = false
|
@Volatile private var running = false
|
||||||
|
|
||||||
|
private var callback: MidiManager.DeviceCallback? = null
|
||||||
|
|
||||||
|
/** Open every writable device and start the send thread. Idempotent. Main thread. */
|
||||||
fun start() {
|
fun start() {
|
||||||
val mm = midiManager ?: return
|
val mm = midiManager ?: return
|
||||||
mm.devices.forEach(::openDevice)
|
if (running) return
|
||||||
mm.registerDeviceCallback(object : MidiManager.DeviceCallback() {
|
val cb = object : MidiManager.DeviceCallback() {
|
||||||
override fun onDeviceAdded(device: MidiDeviceInfo) = openDevice(device)
|
override fun onDeviceAdded(device: MidiDeviceInfo) = openDevice(device)
|
||||||
}, handler)
|
}
|
||||||
|
callback = cb
|
||||||
|
allDevices(mm).forEach(::openDevice)
|
||||||
|
registerCallback(mm, cb)
|
||||||
running = true
|
running = true
|
||||||
thread = Thread({ sendLoop() }, "sizzle-midi-clock").apply {
|
thread = Thread({ sendLoop() }, "sizzle-midi-clock").apply {
|
||||||
priority = Thread.MAX_PRIORITY; isDaemon = true; start()
|
priority = Thread.MAX_PRIORITY; isDaemon = true; start()
|
||||||
@@ -65,12 +82,24 @@ class MidiClock(context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun stop() {
|
fun stop() {
|
||||||
|
callback?.let { cb -> runCatching { midiManager?.unregisterDeviceCallback(cb) } }
|
||||||
|
callback = null
|
||||||
running = false
|
running = false
|
||||||
thread?.join(200); thread = null
|
thread?.join(200); thread = null
|
||||||
outPorts.forEach { runCatching { it.close() } }
|
outPorts.forEach { runCatching { it.close() } }
|
||||||
outPorts.clear()
|
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) {
|
private fun openDevice(info: MidiDeviceInfo) {
|
||||||
if (info.inputPortCount == 0) return // need a port we can send TO
|
if (info.inputPortCount == 0) return // need a port we can send TO
|
||||||
midiManager?.openDevice(info, { device ->
|
midiManager?.openDevice(info, { device ->
|
||||||
@@ -132,7 +161,17 @@ class MidiClock(context: Context) {
|
|||||||
private var pulseAccum = 0.0
|
private var pulseAccum = 0.0
|
||||||
private var pulseCount = 0
|
private var pulseCount = 0
|
||||||
|
|
||||||
|
/** An external transport edge (Start / Continue = true, Stop = false), reported
|
||||||
|
* whether or not [receiveEnabled]: an armed master recording follows another
|
||||||
|
* app's or device's Start/Stop even when Sizzle doesn't follow its clock. Called
|
||||||
|
* on the MIDI port's thread. */
|
||||||
|
var onTransport: ((Boolean) -> Unit)? = null
|
||||||
|
|
||||||
fun handleRealtime(status: Int) {
|
fun handleRealtime(status: Int) {
|
||||||
|
when (status) {
|
||||||
|
0xFA, 0xFB -> onTransport?.invoke(true)
|
||||||
|
0xFC -> onTransport?.invoke(false)
|
||||||
|
}
|
||||||
if (!receiveEnabled) return
|
if (!receiveEnabled) return
|
||||||
when (status) {
|
when (status) {
|
||||||
0xFA, 0xFB -> { resetTempoEstimate(); onReceiveStart?.invoke() } // Start / Continue
|
0xFA, 0xFB -> { resetTempoEstimate(); onReceiveStart?.invoke() } // Start / Continue
|
||||||
@@ -152,7 +191,10 @@ class MidiClock(context: Context) {
|
|||||||
if (++pulseCount >= 24) {
|
if (++pulseCount >= 24) {
|
||||||
val avgNs = pulseAccum / pulseCount
|
val avgNs = pulseAccum / pulseCount
|
||||||
val bpm = (60_000_000_000.0 / (avgNs * 24.0)).toFloat()
|
val bpm = (60_000_000_000.0 / (avgNs * 24.0)).toFloat()
|
||||||
if (bpm.isFinite() && bpm in 20f..300f) onReceiveTempo?.invoke(bpm)
|
if (bpm.isFinite() && bpm in 20f..300f) {
|
||||||
|
onReceiveTempo?.invoke(bpm)
|
||||||
|
_followedTempo.tryEmit(bpm)
|
||||||
|
}
|
||||||
pulseAccum = 0.0; pulseCount = 0
|
pulseAccum = 0.0; pulseCount = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,100 +4,302 @@
|
|||||||
package cc.tiredsysadmin.android.sizzle.input
|
package cc.tiredsysadmin.android.sizzle.input
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.pm.ServiceInfo
|
||||||
|
import android.media.midi.MidiDevice
|
||||||
import android.media.midi.MidiDeviceInfo
|
import android.media.midi.MidiDeviceInfo
|
||||||
|
import android.media.midi.MidiDeviceStatus
|
||||||
import android.media.midi.MidiManager
|
import android.media.midi.MidiManager
|
||||||
import android.media.midi.MidiOutputPort
|
import android.media.midi.MidiOutputPort
|
||||||
import android.media.midi.MidiReceiver
|
import android.media.midi.MidiReceiver
|
||||||
|
import android.os.Build
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
|
import android.os.SystemClock
|
||||||
|
import android.util.Log
|
||||||
|
import cc.tiredsysadmin.android.sizzle.playback.MidiSoundModule
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
|
||||||
|
/** One MIDI source as the Setup screen lists it. [key] is stable across restarts
|
||||||
|
* (unlike Android's device id), so the on/off choice can be saved. */
|
||||||
|
data class MidiSource(val key: String, val name: String, val enabled: Boolean, val connected: Boolean)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bridges hardware MIDI (USB *and* Bluetooth — Android surfaces both through the
|
* Bridges hardware and virtual MIDI sources (USB, Bluetooth, and other apps'
|
||||||
* same [MidiManager]) into the app's [InputAction] stream.
|
* virtual devices such as Mikro Seq; Android lists all of them through the same
|
||||||
|
* [MidiManager]) into the app.
|
||||||
*
|
*
|
||||||
* MIDI note-on/off become live notes; MIDI Control Change (CC) messages are
|
* Every source that can send to us is listed in [sources]. Each is listened to
|
||||||
* matched against [ccBindings] so any knob/pad can drive navigation or transport.
|
* unless the user switched it off in Setup ([setEnabled]; the off-keys are
|
||||||
* Unmatched CCs are forwarded as [InputAction.RawControl] so the Settings screen
|
* persisted by the caller via [onDisabledChanged]), so a new controller or app
|
||||||
* can "learn" them.
|
* works with no setup.
|
||||||
*
|
*
|
||||||
* Note: this handles MIDI *input*. Sending MIDI out lives in the audio/midi
|
* Every open source gets its own [MidiByteParser] (running status is per stream).
|
||||||
* output module; both share the same [MidiManager].
|
* Notes, all-notes-off and real-time bytes go to the [module], the headless sound
|
||||||
|
* module that plays them on the engine whether or not the UI exists. Control
|
||||||
|
* Change (CC) messages the module does not consume are matched against
|
||||||
|
* [ccBindings] so any knob/pad can drive navigation or transport; unmatched CCs
|
||||||
|
* are forwarded as [InputAction.RawControl] so the Settings screen can "learn" them.
|
||||||
|
*
|
||||||
|
* Reconnecting: a virtual source's app can die and restart (crash, update, force
|
||||||
|
* stop, the system reclaiming it) without Android removing its device or telling
|
||||||
|
* its clients anything: our MidiDevice keeps pointing at the dead process and no
|
||||||
|
* callback fires (verified on Android 15). So every [PROBE_MS] a worker thread asks
|
||||||
|
* each open virtual source for an output port: a live one answers (the probe port
|
||||||
|
* is closed at once), a dead one fails, and that source is closed (releasing its
|
||||||
|
* held notes) and opened again, which makes Android rebind the app's MIDI service.
|
||||||
|
* A port-status report of "nobody has the output open" while we think we do is
|
||||||
|
* treated the same way. [refresh] (every Activity resume) probes at once and opens
|
||||||
|
* anything enabled that isn't open; [reconnect] (the Setup button) closes and
|
||||||
|
* reopens everything as a last resort. A source that goes away is
|
||||||
|
* closed and its held notes are released through [MidiSoundModule.sourceDisconnected].
|
||||||
|
*
|
||||||
|
* Note: this handles MIDI *input*. Sending MIDI out lives in [MidiClock].
|
||||||
|
* Main thread for everything except the parsers (each port's own thread).
|
||||||
*/
|
*/
|
||||||
class MidiInput(
|
class MidiInput(
|
||||||
context: Context,
|
context: Context,
|
||||||
private val router: InputRouter,
|
private val router: InputRouter,
|
||||||
|
private val module: MidiSoundModule,
|
||||||
/** CC number -> action id, editable from Settings (MIDI bindings section). */
|
/** CC number -> action id, editable from Settings (MIDI bindings section). */
|
||||||
var ccBindings: MutableMap<Int, String> = mutableMapOf(),
|
var ccBindings: MutableMap<Int, String> = mutableMapOf(),
|
||||||
) {
|
) {
|
||||||
/** Sink for MIDI System Real-Time status bytes (0xF8..0xFF), notably clock (0xF8)
|
|
||||||
* and Start/Continue/Stop (0xFA/0xFB/0xFC) — wired to [MidiClock] for clock sync. */
|
|
||||||
var onRealtime: ((Int) -> Unit)? = null
|
|
||||||
private val midiManager = context.getSystemService(Context.MIDI_SERVICE) as? MidiManager
|
private val midiManager = context.getSystemService(Context.MIDI_SERVICE) as? MidiManager
|
||||||
private val handler = Handler(Looper.getMainLooper())
|
private val handler = Handler(Looper.getMainLooper())
|
||||||
private val openPorts = mutableListOf<MidiOutputPort>()
|
|
||||||
|
|
||||||
/** Start listening. Opens every currently-attached input-capable device and
|
/** Every device that can send to us, by [MidiDeviceInfo.getId]. */
|
||||||
* watches for hot-plug events. Safe to call if the device has no MIDI. */
|
private val known = LinkedHashMap<Int, MidiDeviceInfo>()
|
||||||
|
/** Open sources by device id. */
|
||||||
|
private val open = HashMap<Int, Pair<MidiDevice, MidiOutputPort>>()
|
||||||
|
/** Device ids with an [MidiManager.openDevice] in flight. */
|
||||||
|
private val opening = HashSet<Int>()
|
||||||
|
private var callback: MidiManager.DeviceCallback? = null
|
||||||
|
/** When we last opened or closed each device id, to ignore the port-status
|
||||||
|
* echoes of our own actions (see [onStatus]). */
|
||||||
|
private val lastChange = HashMap<Int, Long>()
|
||||||
|
|
||||||
|
/** Keys of the sources the user switched off. Set before [start]. */
|
||||||
|
var disabledKeys: Set<String> = emptySet()
|
||||||
|
private set
|
||||||
|
|
||||||
|
/** Called with the new off-set when the user changes it, to persist it. */
|
||||||
|
var onDisabledChanged: ((Set<String>) -> Unit)? = null
|
||||||
|
|
||||||
|
private val _sources = MutableStateFlow<List<MidiSource>>(emptyList())
|
||||||
|
/** All sources that can send to us, for the Setup screen. */
|
||||||
|
val sources: StateFlow<List<MidiSource>> = _sources.asStateFlow()
|
||||||
|
|
||||||
|
fun restoreDisabled(keys: Set<String>) { disabledKeys = keys; publish() }
|
||||||
|
|
||||||
|
/** Start listening: open every enabled device that can send to us and watch for
|
||||||
|
* hot-plug and status events. Idempotent; safe if the device has no MIDI. */
|
||||||
fun start() {
|
fun start() {
|
||||||
val mm = midiManager ?: return
|
val mm = midiManager ?: return
|
||||||
mm.devices.forEach(::openDevice)
|
if (callback != null) return
|
||||||
mm.registerDeviceCallback(object : MidiManager.DeviceCallback() {
|
val cb = object : MidiManager.DeviceCallback() {
|
||||||
override fun onDeviceAdded(device: MidiDeviceInfo) = openDevice(device)
|
override fun onDeviceAdded(device: MidiDeviceInfo) = add(device)
|
||||||
}, handler)
|
override fun onDeviceRemoved(device: MidiDeviceInfo) {
|
||||||
|
known.remove(device.id)
|
||||||
|
closeDevice(device.id)
|
||||||
|
publish()
|
||||||
|
}
|
||||||
|
override fun onDeviceStatusChanged(status: MidiDeviceStatus) = onStatus(status)
|
||||||
|
}
|
||||||
|
callback = cb
|
||||||
|
allDevices(mm).forEach(::add)
|
||||||
|
registerCallback(mm, cb)
|
||||||
|
handler.postDelayed(probeTick, PROBE_MS)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Close every source (releasing their held notes). */
|
||||||
fun stop() {
|
fun stop() {
|
||||||
openPorts.forEach { runCatching { it.close() } }
|
callback?.let { cb -> runCatching { midiManager?.unregisterDeviceCallback(cb) } }
|
||||||
openPorts.clear()
|
callback = null
|
||||||
|
handler.removeCallbacks(probeTick)
|
||||||
|
open.keys.toList().forEach(::closeDevice)
|
||||||
|
opening.clear()
|
||||||
|
known.clear()
|
||||||
|
publish()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Pick up anything missed: new devices, and enabled ones that aren't open. */
|
||||||
|
fun refresh() {
|
||||||
|
val mm = midiManager ?: return
|
||||||
|
if (callback == null) return
|
||||||
|
allDevices(mm).forEach(::add)
|
||||||
|
probe()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Close and reopen every enabled source (Setup's Reconnect button). */
|
||||||
|
fun reconnect() {
|
||||||
|
if (callback == null) return
|
||||||
|
open.keys.toList().forEach(::closeDevice)
|
||||||
|
known.clear()
|
||||||
|
refresh()
|
||||||
|
publish()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Listen to the source with [key], or stop listening to it. */
|
||||||
|
fun setEnabled(key: String, enabled: Boolean) {
|
||||||
|
disabledKeys = if (enabled) disabledKeys - key else disabledKeys + key
|
||||||
|
onDisabledChanged?.invoke(disabledKeys)
|
||||||
|
for ((id, info) in known) {
|
||||||
|
if (keyOf(info) != key) continue
|
||||||
|
if (enabled) openDevice(info) else closeDevice(id)
|
||||||
|
}
|
||||||
|
publish()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun add(info: MidiDeviceInfo) {
|
||||||
|
// We want devices that can SEND to us (they expose output ports).
|
||||||
|
if (info.outputPortCount == 0) return
|
||||||
|
known[info.id] = info
|
||||||
|
if (keyOf(info) !in disabledKeys) openDevice(info)
|
||||||
|
publish()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Port status from Android. If nobody holds the output open while we believe we
|
||||||
|
* do, the app behind it restarted and our connection is dead: reopen it. */
|
||||||
|
private fun onStatus(status: MidiDeviceStatus) {
|
||||||
|
val info = status.deviceInfo
|
||||||
|
val id = info.id
|
||||||
|
if (id !in open || info.outputPortCount == 0) return
|
||||||
|
val sinceOwnChange = SystemClock.uptimeMillis() - (lastChange[id] ?: 0L)
|
||||||
|
if (sinceOwnChange < STATUS_SETTLE_MS) return
|
||||||
|
if (status.getOutputPortOpenCount(0) == 0) {
|
||||||
|
Log.i(TAG, "${nameOf(info)}: connection lost, reopening")
|
||||||
|
closeDevice(id)
|
||||||
|
openDevice(info)
|
||||||
|
publish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val probeTick = object : Runnable {
|
||||||
|
override fun run() {
|
||||||
|
if (callback == null) return
|
||||||
|
probe()
|
||||||
|
handler.postDelayed(this, PROBE_MS)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Off-main-thread liveness check of every open virtual source (see the class
|
||||||
|
* doc). A hung source app can't stall the UI this way. */
|
||||||
|
private fun probe() {
|
||||||
|
val targets = open.entries
|
||||||
|
.filter { (_, dp) -> dp.first.info.type == MidiDeviceInfo.TYPE_VIRTUAL }
|
||||||
|
.map { (id, dp) -> id to dp.first }
|
||||||
|
if (targets.isEmpty() || probing) return
|
||||||
|
probing = true
|
||||||
|
probeExecutor.execute {
|
||||||
|
val dead = targets.filter { (_, device) ->
|
||||||
|
val port = runCatching { device.openOutputPort(0) }.getOrNull()
|
||||||
|
port?.let { runCatching { it.close() } }
|
||||||
|
port == null
|
||||||
|
}
|
||||||
|
handler.post {
|
||||||
|
probing = false
|
||||||
|
for ((id, device) in dead) {
|
||||||
|
// Still the same connection? (It may have been closed or replaced meanwhile.)
|
||||||
|
if (open[id]?.first !== device) continue
|
||||||
|
val info = device.info
|
||||||
|
Log.i(TAG, "${nameOf(info)}: connection lost, reopening")
|
||||||
|
closeDevice(id)
|
||||||
|
openDevice(info)
|
||||||
|
}
|
||||||
|
if (dead.isNotEmpty()) publish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var probing = false
|
||||||
|
private val probeExecutor = java.util.concurrent.Executors.newSingleThreadExecutor { r ->
|
||||||
|
Thread(r, "sizzle-midi-probe").apply { isDaemon = true }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openDevice(info: MidiDeviceInfo) {
|
private fun openDevice(info: MidiDeviceInfo) {
|
||||||
// We want devices that can SEND to us (they expose output ports).
|
val id = info.id
|
||||||
if (info.outputPortCount == 0) return
|
if (id in open || id in opening) return
|
||||||
midiManager?.openDevice(info, { device ->
|
val mm = midiManager ?: return
|
||||||
val port = device?.openOutputPort(0) ?: return@openDevice
|
opening += id
|
||||||
port.connect(parser)
|
mm.openDevice(info, { device ->
|
||||||
openPorts += port
|
opening -= id
|
||||||
|
device ?: run { Log.w(TAG, "${nameOf(info)}: could not open"); publish(); return@openDevice }
|
||||||
|
// stop() ran, the device was opened twice, or the user switched it off
|
||||||
|
// while this was pending.
|
||||||
|
if (callback == null || id in open || keyOf(info) in disabledKeys) {
|
||||||
|
runCatching { device.close() }; return@openDevice
|
||||||
|
}
|
||||||
|
val port = device.openOutputPort(0)
|
||||||
|
?: run { runCatching { device.close() }; publish(); return@openDevice }
|
||||||
|
val parser = MidiByteParser(
|
||||||
|
onChannel = { status, d1, d2 ->
|
||||||
|
val consumed = module.onChannelMessage(id, status, d1, d2)
|
||||||
|
if (!consumed && (status and 0xF0) == 0xB0) handleCc(d1, d2)
|
||||||
|
},
|
||||||
|
onRealtime = module::onRealtime,
|
||||||
|
)
|
||||||
|
port.connect(object : MidiReceiver() {
|
||||||
|
override fun onSend(data: ByteArray, offset: Int, count: Int, timestamp: Long) {
|
||||||
|
if (MidiTrace.on) MidiTrace.packet(nameOf(info), data, offset, count, timestamp)
|
||||||
|
parser.feed(data, offset, count)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
open[id] = device to port
|
||||||
|
lastChange[id] = SystemClock.uptimeMillis()
|
||||||
|
module.sourceConnected(id)
|
||||||
|
Log.i(TAG, "${nameOf(info)}: listening")
|
||||||
|
publish()
|
||||||
}, handler)
|
}, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Parses the raw MIDI byte stream. MIDI status bytes have the high bit set;
|
private fun closeDevice(id: Int) {
|
||||||
* the low nibble is the channel, the high nibble the message type. */
|
val (device, port) = open.remove(id) ?: return
|
||||||
private val parser = object : MidiReceiver() {
|
lastChange[id] = SystemClock.uptimeMillis()
|
||||||
override fun onSend(data: ByteArray, offset: Int, count: Int, timestamp: Long) {
|
runCatching { port.close() }
|
||||||
var i = offset
|
runCatching { device.close() }
|
||||||
val end = offset + count
|
module.sourceDisconnected(id)
|
||||||
while (i < end) {
|
|
||||||
val status = data[i].toInt() and 0xFF
|
|
||||||
if (status < 0x80) { i++; continue } // skip stray data bytes
|
|
||||||
// System Real-Time (0xF8..0xFF) are single-byte and may be interleaved
|
|
||||||
// anywhere; forward them (clock / start / stop) and move on one byte.
|
|
||||||
if (status >= 0xF8) { onRealtime?.invoke(status); i++; continue }
|
|
||||||
val type = status and 0xF0
|
|
||||||
// Low nibble is the MIDI channel (0..15); expose it 1-based (1..16) so
|
|
||||||
// it matches the mixer channels' `midiChannel` for routing.
|
|
||||||
val channel = (status and 0x0F) + 1
|
|
||||||
when (type) {
|
|
||||||
0x90 -> { // Note On
|
|
||||||
val note = data.getOrZero(i + 1)
|
|
||||||
val vel = data.getOrZero(i + 2)
|
|
||||||
if (vel > 0) router.dispatch(InputAction.NoteOn(note, vel, channel))
|
|
||||||
else router.dispatch(InputAction.NoteOff(note, channel)) // vel 0 == note off
|
|
||||||
i += 3
|
|
||||||
}
|
}
|
||||||
0x80 -> { // Note Off
|
|
||||||
router.dispatch(InputAction.NoteOff(data.getOrZero(i + 1), channel)); i += 3
|
private fun publish() {
|
||||||
}
|
_sources.value = known.values
|
||||||
0xB0 -> { // Control Change
|
.map { MidiSource(keyOf(it), nameOf(it), keyOf(it) !in disabledKeys, it.id in open) }
|
||||||
val cc = data.getOrZero(i + 1)
|
.distinctBy { it.key }
|
||||||
val value = data.getOrZero(i + 2)
|
|
||||||
handleCc(cc, value); i += 3
|
|
||||||
}
|
|
||||||
0xC0, 0xD0 -> i += 2 // program change / channel pressure: 1 data byte
|
|
||||||
else -> i += 3
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION") // getDevices / the Handler overload: still the only way below API 33
|
||||||
|
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 keyOf(info: MidiDeviceInfo): String {
|
||||||
|
val p = info.properties
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
val service = if (Build.VERSION.SDK_INT >= 33) {
|
||||||
|
p.getParcelable(PROPERTY_SERVICE_INFO, ServiceInfo::class.java)
|
||||||
|
} else {
|
||||||
|
p.getParcelable(PROPERTY_SERVICE_INFO)
|
||||||
}
|
}
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
val bluetooth = p.getParcelable<android.os.Parcelable>(MidiDeviceInfo.PROPERTY_BLUETOOTH_DEVICE)
|
||||||
|
return MidiSourceKey.of(
|
||||||
|
type = info.type,
|
||||||
|
manufacturer = p.getString(MidiDeviceInfo.PROPERTY_MANUFACTURER),
|
||||||
|
product = p.getString(MidiDeviceInfo.PROPERTY_PRODUCT),
|
||||||
|
name = p.getString(MidiDeviceInfo.PROPERTY_NAME),
|
||||||
|
service = service?.let { "${it.packageName}/${it.name}" },
|
||||||
|
bluetooth = bluetooth?.toString(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun nameOf(info: MidiDeviceInfo): String = info.properties.let { p ->
|
||||||
|
MidiSourceKey.displayName(
|
||||||
|
p.getString(MidiDeviceInfo.PROPERTY_MANUFACTURER),
|
||||||
|
p.getString(MidiDeviceInfo.PROPERTY_PRODUCT),
|
||||||
|
p.getString(MidiDeviceInfo.PROPERTY_NAME),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleCc(cc: Int, value: Int) {
|
private fun handleCc(cc: Int, value: Int) {
|
||||||
@@ -136,6 +338,13 @@ class MidiInput(
|
|||||||
action?.let(router::dispatch)
|
action?.let(router::dispatch)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ByteArray.getOrZero(index: Int): Int =
|
private companion object {
|
||||||
if (index < size) this[index].toInt() and 0xFF else 0
|
const val TAG = "SizzleMidi"
|
||||||
|
/** MidiDeviceInfo.PROPERTY_SERVICE_INFO: set on virtual devices, but @hide in the SDK. */
|
||||||
|
const val PROPERTY_SERVICE_INFO = "service_info"
|
||||||
|
/** How often open virtual sources are checked for a dead app behind them. */
|
||||||
|
const val PROBE_MS = 3000L
|
||||||
|
/** Port-status events this soon after our own open/close are its echo. */
|
||||||
|
const val STATUS_SETTLE_MS = 1000L
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
package cc.tiredsysadmin.android.sizzle.input
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stable identity and display name for a MIDI source. Android's device id changes
|
||||||
|
* on every reconnect and reboot, so the user's on/off choice is keyed on what the
|
||||||
|
* device says about itself instead: its type, maker/product/name, the service
|
||||||
|
* that publishes it (virtual devices from other apps) or its Bluetooth address.
|
||||||
|
* Pure Kotlin, unit-tested.
|
||||||
|
*/
|
||||||
|
object MidiSourceKey {
|
||||||
|
|
||||||
|
fun of(
|
||||||
|
type: Int,
|
||||||
|
manufacturer: String?,
|
||||||
|
product: String?,
|
||||||
|
name: String?,
|
||||||
|
service: String?,
|
||||||
|
bluetooth: String?,
|
||||||
|
): String = listOf(type.toString(), manufacturer, product, name, service, bluetooth)
|
||||||
|
.joinToString("|") { it.orEmpty().replace("|", "/") }
|
||||||
|
|
||||||
|
/** What the device calls itself: its name, else its product ("Mikro Seq"),
|
||||||
|
* else its maker. */
|
||||||
|
fun displayName(manufacturer: String?, product: String?, name: String?): String =
|
||||||
|
listOf(name, product, manufacturer).firstOrNull { !it.isNullOrBlank() } ?: "MIDI device"
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
package cc.tiredsysadmin.android.sizzle.input
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional MIDI trace for checking what reaches Sizzle and what it plays. Off by
|
||||||
|
* default and free when off; switch it on from a computer:
|
||||||
|
*
|
||||||
|
* adb shell setprop log.tag.SizzleMidiTrace VERBOSE # on (takes effect at once)
|
||||||
|
* adb shell setprop log.tag.SizzleMidiTrace INFO # off
|
||||||
|
* adb logcat -s SizzleMidiTrace
|
||||||
|
*
|
||||||
|
* Logs every received packet (source, bytes, how late it arrived against its
|
||||||
|
* timestamp) and every note the sound module hands the engine with the mixer
|
||||||
|
* strips it reaches. Real-time bytes (clock) are left out of packet lines unless
|
||||||
|
* they come with other data, to keep the log readable.
|
||||||
|
*/
|
||||||
|
object MidiTrace {
|
||||||
|
const val TAG = "SizzleMidiTrace"
|
||||||
|
|
||||||
|
private var checkedAt = 0L
|
||||||
|
private var cached = false
|
||||||
|
|
||||||
|
/** Re-reads the property at most every 500 ms (setprop applies without a restart). */
|
||||||
|
val on: Boolean
|
||||||
|
get() {
|
||||||
|
val now = System.nanoTime()
|
||||||
|
if (now - checkedAt > 500_000_000L) {
|
||||||
|
cached = Log.isLoggable(TAG, Log.VERBOSE)
|
||||||
|
checkedAt = now
|
||||||
|
}
|
||||||
|
return cached
|
||||||
|
}
|
||||||
|
|
||||||
|
fun log(msg: String) { Log.v(TAG, msg) }
|
||||||
|
|
||||||
|
fun packet(source: String, data: ByteArray, offset: Int, count: Int, timestamp: Long) {
|
||||||
|
if (count == 1 && (data[offset].toInt() and 0xFF) == 0xF8) return // clock tick
|
||||||
|
val hex = (offset until offset + count).joinToString(" ") { "%02X".format(data[it]) }
|
||||||
|
val lateMs = if (timestamp > 0) (System.nanoTime() - timestamp) / 1_000_000.0 else Double.NaN
|
||||||
|
log("recv $source [$hex] ${describe(data, offset, count)} late=${"%.1f".format(lateMs)}ms")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun describe(data: ByteArray, offset: Int, count: Int): String {
|
||||||
|
val s = data[offset].toInt() and 0xFF
|
||||||
|
val d1 = if (count > 1) data[offset + 1].toInt() and 0x7F else 0
|
||||||
|
val d2 = if (count > 2) data[offset + 2].toInt() and 0x7F else 0
|
||||||
|
val ch = (s and 0x0F) + 1
|
||||||
|
return when (s and 0xF0) {
|
||||||
|
0x90 -> if (d2 > 0) "NoteOn ch=$ch ${note(d1)} v=$d2" else "NoteOn(v0=Off) ch=$ch ${note(d1)}"
|
||||||
|
0x80 -> "NoteOff ch=$ch ${note(d1)}"
|
||||||
|
0xB0 -> "CC ch=$ch #$d1=$d2"
|
||||||
|
0xC0 -> "Program ch=$ch $d1"
|
||||||
|
0xF0 -> when (s) { 0xFA -> "Start"; 0xFB -> "Continue"; 0xFC -> "Stop"; else -> "System %02X".format(s) }
|
||||||
|
else -> "status %02X".format(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val NAMES = arrayOf("C-", "C#", "D-", "D#", "E-", "F-", "F#", "G-", "G#", "A-", "A#", "B-")
|
||||||
|
|
||||||
|
/** "36(C-2)", in this app's naming (60 = C-4). */
|
||||||
|
fun note(n: Int): String = "$n(${NAMES[n % 12]}${n / 12 - 1})"
|
||||||
|
}
|
||||||
@@ -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,9 @@
|
|||||||
package cc.tiredsysadmin.android.sizzle.io
|
package cc.tiredsysadmin.android.sizzle.io
|
||||||
|
|
||||||
import cc.tiredsysadmin.android.sizzle.audio.SampleStore
|
import cc.tiredsysadmin.android.sizzle.audio.SampleStore
|
||||||
|
import cc.tiredsysadmin.android.sizzle.echofield.EchofieldDefs
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs
|
||||||
|
import cc.tiredsysadmin.android.sizzle.wavetable.WaveDefs
|
||||||
import cc.tiredsysadmin.android.sizzle.model.AmbiencePresets
|
import cc.tiredsysadmin.android.sizzle.model.AmbiencePresets
|
||||||
import cc.tiredsysadmin.android.sizzle.model.MixTightenerPresets
|
import cc.tiredsysadmin.android.sizzle.model.MixTightenerPresets
|
||||||
import cc.tiredsysadmin.android.sizzle.model.NesSynthPresets
|
import cc.tiredsysadmin.android.sizzle.model.NesSynthPresets
|
||||||
@@ -52,6 +55,15 @@ class PresetLibrary(private val baseDir: File) {
|
|||||||
seedType(ToolboxType.NES_SYNTH, NesSynthPresets.FACTORY.map { it.name }) { slot, name ->
|
seedType(ToolboxType.NES_SYNTH, NesSynthPresets.FACTORY.map { it.name }) { slot, name ->
|
||||||
NesSynthPresets.apply(slot, NesSynthPresets.FACTORY.first { it.name == name })
|
NesSynthPresets.apply(slot, NesSynthPresets.FACTORY.first { it.name == name })
|
||||||
}
|
}
|
||||||
|
seedType(ToolboxType.MORPH_PAD, FrasilDefs.FACTORY.map { it.name }) { slot, name ->
|
||||||
|
FrasilDefs.FACTORY.first { it.name == name }.values.forEach { (k, v) -> slot.set(k, v) }
|
||||||
|
}
|
||||||
|
seedType(ToolboxType.GRAIN_CLOUD, EchofieldDefs.FACTORY.map { it.name }) { slot, name ->
|
||||||
|
EchofieldDefs.FACTORY.first { it.name == name }.values.forEach { (k, v) -> slot.set(k, v) }
|
||||||
|
}
|
||||||
|
seedType(ToolboxType.WAVETABLE, WaveDefs.FACTORY.map { it.name }) { slot, name ->
|
||||||
|
WaveDefs.FACTORY.first { it.name == name }.values.forEach { (k, v) -> slot.set(k, v) }
|
||||||
|
}
|
||||||
seedType(ToolboxType.MIX_TIGHTENER, MixTightenerPresets.FACTORY.map { it.name }) { slot, name ->
|
seedType(ToolboxType.MIX_TIGHTENER, MixTightenerPresets.FACTORY.map { it.name }) { slot, name ->
|
||||||
MixTightenerPresets.apply(slot, MixTightenerPresets.FACTORY.first { it.name == name })
|
MixTightenerPresets.apply(slot, MixTightenerPresets.FACTORY.first { it.name == name })
|
||||||
}
|
}
|
||||||
@@ -139,6 +151,18 @@ class PresetLibrary(private val baseDir: File) {
|
|||||||
}
|
}
|
||||||
preset.writeText(exportSoundFont(slot, rel))
|
preset.writeText(exportSoundFont(slot, rel))
|
||||||
}
|
}
|
||||||
|
ToolboxType.GRAIN_CLOUD, ToolboxType.WAVETABLE -> {
|
||||||
|
// A custom grain source or wavetable travels with the preset as a WAV, like the SF2/XI
|
||||||
|
// loader's; the built-in sources need nothing.
|
||||||
|
val sample = SampleStore.get(slot.string("sfSample"))
|
||||||
|
if (sample != null) {
|
||||||
|
File(dir, "${safe}_sf.wav").writeBytes(SampleStore.encodeWav(sample))
|
||||||
|
slot.set("sfFile", "${safe}_sf.wav")
|
||||||
|
} else {
|
||||||
|
slot.values.remove("sfFile")
|
||||||
|
}
|
||||||
|
preset.writeText(PresetIo.export(slot))
|
||||||
|
}
|
||||||
else -> preset.writeText(PresetIo.export(slot))
|
else -> preset.writeText(PresetIo.export(slot))
|
||||||
}
|
}
|
||||||
return preset
|
return preset
|
||||||
@@ -161,7 +185,7 @@ class PresetLibrary(private val baseDir: File) {
|
|||||||
}
|
}
|
||||||
if (type == ToolboxType.SAMPLER) {
|
if (type == ToolboxType.SAMPLER) {
|
||||||
for (p in 0 until SamplerPads.COUNT) File(dir, "${base}_pad$p.wav").delete()
|
for (p in 0 until SamplerPads.COUNT) File(dir, "${base}_pad$p.wav").delete()
|
||||||
} else if (type == ToolboxType.SOUNDFONT) {
|
} else if (type == ToolboxType.SOUNDFONT || type == ToolboxType.GRAIN_CLOUD || type == ToolboxType.WAVETABLE) {
|
||||||
File(dir, "${base}_sf.wav").delete()
|
File(dir, "${base}_sf.wav").delete()
|
||||||
}
|
}
|
||||||
return preset.delete()
|
return preset.delete()
|
||||||
@@ -178,7 +202,7 @@ class PresetLibrary(private val baseDir: File) {
|
|||||||
project.toolbox.forEach { slot ->
|
project.toolbox.forEach { slot ->
|
||||||
when (slot.type) {
|
when (slot.type) {
|
||||||
ToolboxType.SAMPLER -> resolvePads(slot, typeDir(ToolboxType.SAMPLER))
|
ToolboxType.SAMPLER -> resolvePads(slot, typeDir(ToolboxType.SAMPLER))
|
||||||
ToolboxType.SOUNDFONT -> resolveSoundFont(slot, typeDir(ToolboxType.SOUNDFONT))
|
ToolboxType.SOUNDFONT, ToolboxType.GRAIN_CLOUD, ToolboxType.WAVETABLE -> resolveSoundFont(slot, typeDir(ToolboxType.SOUNDFONT))
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,7 +217,7 @@ class PresetLibrary(private val baseDir: File) {
|
|||||||
val dir = file.parentFile ?: typeDir(type)
|
val dir = file.parentFile ?: typeDir(type)
|
||||||
when (slot.type) {
|
when (slot.type) {
|
||||||
ToolboxType.SAMPLER -> resolvePads(slot, dir)
|
ToolboxType.SAMPLER -> resolvePads(slot, dir)
|
||||||
ToolboxType.SOUNDFONT -> resolveSoundFont(slot, dir)
|
ToolboxType.SOUNDFONT, ToolboxType.GRAIN_CLOUD, ToolboxType.WAVETABLE -> resolveSoundFont(slot, dir)
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
@@ -210,7 +234,7 @@ class PresetLibrary(private val baseDir: File) {
|
|||||||
val type = slot.type ?: return false
|
val type = slot.type ?: return false
|
||||||
when (type) {
|
when (type) {
|
||||||
ToolboxType.SAMPLER -> resolvePads(slot, typeDir(type))
|
ToolboxType.SAMPLER -> resolvePads(slot, typeDir(type))
|
||||||
ToolboxType.SOUNDFONT -> resolveSoundFont(slot, typeDir(type))
|
ToolboxType.SOUNDFONT, ToolboxType.GRAIN_CLOUD, ToolboxType.WAVETABLE -> resolveSoundFont(slot, typeDir(type))
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
save(slot, slot.name.ifBlank { type.displayName })
|
save(slot, slot.name.ifBlank { type.displayName })
|
||||||
@@ -251,7 +275,7 @@ class PresetLibrary(private val baseDir: File) {
|
|||||||
if (!PresetIo.import(slot, text)) return false
|
if (!PresetIo.import(slot, text)) return false
|
||||||
when (slot.type) {
|
when (slot.type) {
|
||||||
ToolboxType.SAMPLER -> resolvePads(slot, scratch)
|
ToolboxType.SAMPLER -> resolvePads(slot, scratch)
|
||||||
ToolboxType.SOUNDFONT -> resolveSoundFont(slot, scratch)
|
ToolboxType.SOUNDFONT, ToolboxType.GRAIN_CLOUD, ToolboxType.WAVETABLE -> resolveSoundFont(slot, scratch)
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
// Persist a self-contained copy into the real library folder.
|
// Persist a self-contained copy into the real library folder.
|
||||||
@@ -268,7 +292,9 @@ class PresetLibrary(private val baseDir: File) {
|
|||||||
fun bundleForShare(type: ToolboxType, name: String): File? {
|
fun bundleForShare(type: ToolboxType, name: String): File? {
|
||||||
val preset = File(typeDir(type), sanitize(name) + PRESET_EXT)
|
val preset = File(typeDir(type), sanitize(name) + PRESET_EXT)
|
||||||
if (!preset.exists()) return null
|
if (!preset.exists()) return null
|
||||||
if (type != ToolboxType.SAMPLER && type != ToolboxType.SOUNDFONT) return preset
|
if (type != ToolboxType.SAMPLER && type != ToolboxType.SOUNDFONT && type != ToolboxType.GRAIN_CLOUD &&
|
||||||
|
type != ToolboxType.WAVETABLE
|
||||||
|
) return preset
|
||||||
|
|
||||||
val bundles = File(baseDir, BUNDLE_DIR).apply { mkdirs() }
|
val bundles = File(baseDir, BUNDLE_DIR).apply { mkdirs() }
|
||||||
val zip = File(bundles, sanitize(name) + ".zip")
|
val zip = File(bundles, sanitize(name) + ".zip")
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ object ProjectBundleIo {
|
|||||||
ToolboxType.SAMPLER -> for (p in 0 until SamplerPads.COUNT) {
|
ToolboxType.SAMPLER -> for (p in 0 until SamplerPads.COUNT) {
|
||||||
idToPath[slot.string(SamplerPads.key(p))]?.let { slot.set("pad${p}File", it) }
|
idToPath[slot.string(SamplerPads.key(p))]?.let { slot.set("pad${p}File", it) }
|
||||||
}
|
}
|
||||||
ToolboxType.SOUNDFONT -> idToPath[slot.string("sfSample")]?.let { slot.set("sfFile", it) }
|
ToolboxType.SOUNDFONT, ToolboxType.GRAIN_CLOUD, ToolboxType.WAVETABLE -> idToPath[slot.string("sfSample")]?.let { slot.set("sfFile", it) }
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -127,7 +127,8 @@ object ProjectBundleIo {
|
|||||||
ToolboxType.SAMPLER -> for (p in 0 until SamplerPads.COUNT) {
|
ToolboxType.SAMPLER -> for (p in 0 until SamplerPads.COUNT) {
|
||||||
slot.string(SamplerPads.key(p)).takeIf { it.isNotBlank() }?.let { ids.add(it) }
|
slot.string(SamplerPads.key(p)).takeIf { it.isNotBlank() }?.let { ids.add(it) }
|
||||||
}
|
}
|
||||||
ToolboxType.SOUNDFONT -> slot.string("sfSample").takeIf { it.isNotBlank() }?.let { ids.add(it) }
|
ToolboxType.SOUNDFONT, ToolboxType.GRAIN_CLOUD, ToolboxType.WAVETABLE ->
|
||||||
|
slot.string("sfSample").takeIf { it.isNotBlank() }?.let { ids.add(it) }
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
package cc.tiredsysadmin.android.sizzle.io
|
package cc.tiredsysadmin.android.sizzle.io
|
||||||
|
|
||||||
import cc.tiredsysadmin.android.sizzle.model.Cell
|
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.Mixer
|
||||||
import cc.tiredsysadmin.android.sizzle.model.Pattern
|
import cc.tiredsysadmin.android.sizzle.model.Pattern
|
||||||
import cc.tiredsysadmin.android.sizzle.model.Project
|
import cc.tiredsysadmin.android.sizzle.model.Project
|
||||||
@@ -27,54 +28,98 @@ import cc.tiredsysadmin.android.sizzle.model.ToolboxType
|
|||||||
object ProjectIo {
|
object ProjectIo {
|
||||||
private const val HEADER = "SIZZLETRACKER-SNG 1"
|
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
|
// ------------------------------------------------------------------- write
|
||||||
fun save(project: Project): String = buildString {
|
/**
|
||||||
appendLine(HEADER)
|
* The whole project as `.sng` text.
|
||||||
appendLine("NAME=${project.name}")
|
*
|
||||||
appendLine("TEMPO=${project.tempoBpm}")
|
* This is the hot path of the UI → engine bridge, not just the file writer:
|
||||||
appendLine("SIG=${project.timeSignature.name}")
|
* `AudioEngine.syncNow` calls it after every edit and the engine diffs the text
|
||||||
appendLine("SCALE=${project.scale.name}")
|
* (see DEVELOPER_HANDOVER.md §5.4.2). So it builds into one pre-sized buffer and
|
||||||
appendLine("ROOT=${project.rootNote}")
|
* appends numbers straight into it instead of formatting a String per line —
|
||||||
appendLine("ACTIVE=${project.activePatternId}")
|
* 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 ->
|
project.patterns.forEach { p ->
|
||||||
appendLine("[PATTERN id=${p.id} name=${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) {
|
for (t in 0 until Pattern.TRACK_COUNT) {
|
||||||
|
val col = p.tracks[t]
|
||||||
for (line in 0 until p.length) {
|
for (line in 0 until p.length) {
|
||||||
val cell = p.cell(t, line)
|
val cell = col[line]
|
||||||
if (!cell.isEmpty) appendLine("$t,$line,${cell.note},${cell.velocity},${cell.channel}")
|
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 arr = project.arrangement
|
||||||
val mutes = arr.laneMuted.joinToString("") { if (it) "1" else "0" }
|
sb.append("[ARRANGEMENT bars=").append(arr.lengthBars)
|
||||||
appendLine("[ARRANGEMENT bars=${arr.lengthBars} loop=${arr.loopEnabled.b()} mutes=$mutes]")
|
.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
|
val usedBeats = arr.lastFilledBeat() + 1
|
||||||
for (lane in arr.slots.indices) {
|
for (lane in arr.slots.indices) {
|
||||||
|
val row = arr.slots[lane]
|
||||||
for (beat in 0 until usedBeats) {
|
for (beat in 0 until usedBeats) {
|
||||||
val pid = arr.slots[lane][beat]
|
val pid = row[beat]
|
||||||
if (pid >= 0) appendLine("$lane,$beat,$pid")
|
// >= 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) 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}]")
|
return sb.appendTail(project).toString()
|
||||||
appendLine("[REGION B en=${arr.regionB.enabled.b()} s=${arr.regionB.start} e=${arr.regionB.end} r=${arr.regionB.repeats}]")
|
}
|
||||||
|
|
||||||
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 ->
|
project.mixer.channels.forEach { ch ->
|
||||||
appendLine(
|
append(ch.index).append(',').append(ch.instrumentSlot)
|
||||||
"${ch.index},${ch.instrumentSlot},${ch.fxSlots.joinToString(",")}," +
|
for (fx in ch.fxSlots) append(',').append(fx)
|
||||||
"${ch.midiChannel},${ch.volume},${ch.mute.b()},${ch.solo.b()},${ch.limiter.b()}",
|
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 ->
|
project.toolbox.forEach { slot ->
|
||||||
if (!slot.isEmpty) {
|
if (slot.isEmpty) return@forEach
|
||||||
val params = slot.values.entries.joinToString(",") { "${it.key}=${it.value}" }
|
append(slot.index).append('=').append(slot.type!!.name).append(';').append(slot.name).append(';')
|
||||||
appendLine("${slot.index}=${slot.type!!.name};${slot.name};$params")
|
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
|
// -------------------------------------------------------------------- read
|
||||||
@@ -107,7 +152,7 @@ object ProjectIo {
|
|||||||
val attrs = parseAttrs(line)
|
val attrs = parseAttrs(line)
|
||||||
current = Pattern(
|
current = Pattern(
|
||||||
id = attrs["id"]?.toIntOrNull() ?: project.patterns.size,
|
id = attrs["id"]?.toIntOrNull() ?: project.patterns.size,
|
||||||
name = attrs["name"] ?: "PTN",
|
name = attrs["name"]?.let(::decodeName) ?: "PTN",
|
||||||
length = attrs["len"]?.toIntOrNull() ?: 16,
|
length = attrs["len"]?.toIntOrNull() ?: 16,
|
||||||
).also { project.patterns.add(it) }
|
).also { project.patterns.add(it) }
|
||||||
section = "PATTERN"
|
section = "PATTERN"
|
||||||
@@ -151,8 +196,6 @@ object ProjectIo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ----- small helpers -----
|
// ----- small helpers -----
|
||||||
private fun Boolean.b() = if (this) "1" else "0"
|
|
||||||
|
|
||||||
private fun parseAttrs(line: String): Map<String, String> =
|
private fun parseAttrs(line: String): Map<String, String> =
|
||||||
line.trim('[', ']').substringAfter(' ', "").split(' ')
|
line.trim('[', ']').substringAfter(' ', "").split(' ')
|
||||||
.mapNotNull { tok -> tok.split('=', limit = 2).takeIf { it.size == 2 }?.let { it[0] to it[1] } }
|
.mapNotNull { tok -> tok.split('=', limit = 2).takeIf { it.size == 2 }?.let { it[0] to it[1] } }
|
||||||
@@ -193,7 +236,7 @@ object ProjectIo {
|
|||||||
p.arrangement.set(lane, beat, pid)
|
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.enabled = a["en"] == "1"
|
||||||
region.start = a["s"]?.toIntOrNull() ?: 0
|
region.start = a["s"]?.toIntOrNull() ?: 0
|
||||||
region.end = a["e"]?.toIntOrNull() ?: 0
|
region.end = a["e"]?.toIntOrNull() ?: 0
|
||||||
@@ -230,4 +273,19 @@ object ProjectIo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Block names may contain spaces ("C1 muted" from a Mikro Seq import), but the
|
||||||
|
* `[PATTERN …]` header is split on whitespace: escape space, `%` and `]`. */
|
||||||
|
internal fun encodeName(name: String): String = buildString {
|
||||||
|
for (c in name) when (c) {
|
||||||
|
'%' -> append("%25"); ' ' -> append("%20"); ']' -> append("%5D")
|
||||||
|
'\t', '\n', '\r' -> append("%20")
|
||||||
|
else -> append(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Inverse of [encodeName]; anything that isn't one of its escapes (older files,
|
||||||
|
* a literal "50%") is kept as written. */
|
||||||
|
internal fun decodeName(text: String): String = text
|
||||||
|
.replace("%20", " ").replace("%5D", "]").replace("%25", "%")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import androidx.datastore.preferences.core.booleanPreferencesKey
|
|||||||
import androidx.datastore.preferences.core.edit
|
import androidx.datastore.preferences.core.edit
|
||||||
import androidx.datastore.preferences.core.intPreferencesKey
|
import androidx.datastore.preferences.core.intPreferencesKey
|
||||||
import androidx.datastore.preferences.core.stringPreferencesKey
|
import androidx.datastore.preferences.core.stringPreferencesKey
|
||||||
|
import androidx.datastore.preferences.core.stringSetPreferencesKey
|
||||||
import androidx.datastore.preferences.preferencesDataStore
|
import androidx.datastore.preferences.preferencesDataStore
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
|
|
||||||
@@ -29,10 +30,19 @@ data class AppSettings(
|
|||||||
val kbdOctave: Int = 3,
|
val kbdOctave: Int = 3,
|
||||||
/** Show the live VU meters inside the mixer volume faders. */
|
/** Show the live VU meters inside the mixer volume faders. */
|
||||||
val vuMeters: Boolean = true,
|
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). */
|
/** Send MIDI clock + start/stop to attached MIDI devices (drive external gear). */
|
||||||
val sendMidiClock: Boolean = false,
|
val sendMidiClock: Boolean = false,
|
||||||
/** Follow an external MIDI clock's tempo + start/stop. */
|
/** Follow an external MIDI clock's tempo + start/stop. */
|
||||||
val receiveMidiClock: Boolean = false,
|
val receiveMidiClock: Boolean = false,
|
||||||
|
/** Keep a foreground service up so incoming MIDI plays with the app in the
|
||||||
|
* background ("Keep running as MIDI sound module"). */
|
||||||
|
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(),
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,8 +65,15 @@ class SettingsStore(private val context: Context) {
|
|||||||
kbdChannel = prefs[KBD_CHANNEL] ?: 0,
|
kbdChannel = prefs[KBD_CHANNEL] ?: 0,
|
||||||
kbdOctave = prefs[KBD_OCTAVE] ?: 3,
|
kbdOctave = prefs[KBD_OCTAVE] ?: 3,
|
||||||
vuMeters = prefs[VU_METERS] ?: true,
|
vuMeters = prefs[VU_METERS] ?: true,
|
||||||
|
keepScreenOn = prefs[KEEP_SCREEN_ON] ?: false,
|
||||||
sendMidiClock = prefs[MIDI_CLOCK_SEND] ?: false,
|
sendMidiClock = prefs[MIDI_CLOCK_SEND] ?: false,
|
||||||
receiveMidiClock = prefs[MIDI_CLOCK_RECV] ?: 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('|'))
|
||||||
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +105,11 @@ class SettingsStore(private val context: Context) {
|
|||||||
context.settingsDataStore.edit { prefs -> prefs[VU_METERS] = enabled }
|
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. */
|
/** Persist the MIDI-clock send / receive toggles. */
|
||||||
suspend fun saveMidiClock(send: Boolean, receive: Boolean) {
|
suspend fun saveMidiClock(send: Boolean, receive: Boolean) {
|
||||||
context.settingsDataStore.edit { prefs ->
|
context.settingsDataStore.edit { prefs ->
|
||||||
@@ -96,6 +118,21 @@ class SettingsStore(private val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Persist the "Keep running as MIDI sound module" toggle. */
|
||||||
|
suspend fun saveSoundModule(enabled: Boolean) {
|
||||||
|
context.settingsDataStore.edit { prefs -> prefs[SOUND_MODULE] = enabled }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Persist the MIDI sources switched off in Setup. */
|
||||||
|
suspend fun saveMidiSourcesOff(keys: Set<String>) {
|
||||||
|
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 {
|
private companion object {
|
||||||
val PALETTE = stringPreferencesKey("palette")
|
val PALETTE = stringPreferencesKey("palette")
|
||||||
val RECORD_DIR = stringPreferencesKey("recordDirUri")
|
val RECORD_DIR = stringPreferencesKey("recordDirUri")
|
||||||
@@ -103,7 +140,11 @@ class SettingsStore(private val context: Context) {
|
|||||||
val KBD_CHANNEL = intPreferencesKey("kbdChannel")
|
val KBD_CHANNEL = intPreferencesKey("kbdChannel")
|
||||||
val KBD_OCTAVE = intPreferencesKey("kbdOctave")
|
val KBD_OCTAVE = intPreferencesKey("kbdOctave")
|
||||||
val VU_METERS = booleanPreferencesKey("vuMeters")
|
val VU_METERS = booleanPreferencesKey("vuMeters")
|
||||||
|
val KEEP_SCREEN_ON = booleanPreferencesKey("keepScreenOn")
|
||||||
val MIDI_CLOCK_SEND = booleanPreferencesKey("midiClockSend")
|
val MIDI_CLOCK_SEND = booleanPreferencesKey("midiClockSend")
|
||||||
val MIDI_CLOCK_RECV = booleanPreferencesKey("midiClockRecv")
|
val MIDI_CLOCK_RECV = booleanPreferencesKey("midiClockRecv")
|
||||||
|
val SOUND_MODULE = booleanPreferencesKey("soundModule")
|
||||||
|
val MIDI_SOURCES_OFF = stringSetPreferencesKey("midiSourcesOff")
|
||||||
|
val BLE_MIDI = stringSetPreferencesKey("bleMidiDevices")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,9 +54,19 @@ object SngFormat {
|
|||||||
|
|
||||||
appendLine("block ${block.name} ${block.length} ${project.timeSignature.beatsPerBar}")
|
appendLine("block ${block.name} ${block.length} ${project.timeSignature.beatsPerBar}")
|
||||||
|
|
||||||
|
// '#' = play this block, 'x' = release this lane, '.' = nothing. 'x' is
|
||||||
|
// an extension to the interchange format: a reader that only knows '#'
|
||||||
|
// sees a non-'#' character and treats it as empty, which loses the off
|
||||||
|
// marker but never mis-parses the roll.
|
||||||
val roll = buildString {
|
val roll = buildString {
|
||||||
for (beat in 0 until usedBeats) {
|
for (beat in 0 until usedBeats) {
|
||||||
append(if (arr.patternAt(block.id, beat) != Arrangement.EMPTY) '#' else '.')
|
append(
|
||||||
|
when (arr.patternAt(block.id, beat)) {
|
||||||
|
Arrangement.EMPTY -> '.'
|
||||||
|
Arrangement.NOTE_OFF -> 'x'
|
||||||
|
else -> '#'
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}.trimEnd('.')
|
}.trimEnd('.')
|
||||||
if (roll.isNotEmpty()) appendLine("roll $roll")
|
if (roll.isNotEmpty()) appendLine("roll $roll")
|
||||||
@@ -82,48 +92,92 @@ object SngFormat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------- read
|
// -------------------------------------------------------------------- read
|
||||||
/** Parse `.sng` [text] into the existing [project] (resetting its content). */
|
/** Cheap content sniff: does [text] look like a `.sng` at all? Used before
|
||||||
|
* anything is replaced, since `text/plain` intents can carry any text. */
|
||||||
|
fun looksLikeSng(text: String): Boolean =
|
||||||
|
Regex("(?m)^\\s*(version|bpm|sig|block)\\b").containsMatchIn(text)
|
||||||
|
|
||||||
|
/** Longest block accepted, matching the desktop tracker's bound (the file is
|
||||||
|
* untrusted; an absurd length would allocate millions of cells). */
|
||||||
|
const val MAX_BLOCK_LENGTH = 1024
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse `.sng` [text] into the existing [project] (resetting its content).
|
||||||
|
*
|
||||||
|
* Follows the desktop reader: `block <name...> <length> <numTracks>` (the name
|
||||||
|
* may contain spaces, the two trailing integers are read from the right),
|
||||||
|
* `track <name> <channel 0..15>`, step lines `tick note vel chan`, and `#`
|
||||||
|
* comments. `group`, `scale`, `root`, `kind` and `intro` are accepted and
|
||||||
|
* ignored (this app has no block groups, and scales are per song here);
|
||||||
|
* `loop` turns the arrangement loop on.
|
||||||
|
*
|
||||||
|
* This app has [Arrangement.LANE_COUNT] blocks of [Pattern.TRACK_COUNT]
|
||||||
|
* tracks. A track keeps its `Tn` slot when free, otherwise takes the next free
|
||||||
|
* one; tracks past the fourth are dropped. With more blocks than lanes, blocks
|
||||||
|
* that are on the roll win over ones that are not (Mikro Seq writes muted
|
||||||
|
* tracks into such off-roll blocks).
|
||||||
|
*/
|
||||||
fun importInto(project: Project, text: String): Project {
|
fun importInto(project: Project, text: String): Project {
|
||||||
// Clear blocks and arrangement (keep the 8 lane-blocks, wipe their cells).
|
// Clear blocks and arrangement (keep the 8 lane-blocks, wipe their cells).
|
||||||
project.patterns.forEach { p -> for (t in 0 until Pattern.TRACK_COUNT) p.tracks[t].forEach { it.clear() } }
|
project.patterns.forEach { p -> for (t in 0 until Pattern.TRACK_COUNT) p.tracks[t].forEach { it.clear() } }
|
||||||
for (lane in project.arrangement.slots.indices) project.arrangement.slots[lane].fill(Arrangement.EMPTY)
|
for (lane in project.arrangement.slots.indices) project.arrangement.slots[lane].fill(Arrangement.EMPTY)
|
||||||
project.arrangement.laneMuted.fill(false)
|
project.arrangement.laneMuted.fill(false)
|
||||||
|
|
||||||
var blockIndex = 0
|
val lines = text.lineSequence().map { it.trim() }
|
||||||
|
.filter { it.isNotEmpty() && !it.startsWith("#") }
|
||||||
|
.map { it.split(Regex("\\s+")) }
|
||||||
|
.toList()
|
||||||
|
val keep = blocksToKeep(lines, project.patterns.size)
|
||||||
|
|
||||||
|
var blockOrdinal = -1 // index of the block in the file
|
||||||
|
var nextPattern = 0 // next free pattern (lane) to fill
|
||||||
var current: Pattern? = null
|
var current: Pattern? = null
|
||||||
var track = 0
|
var track = -1
|
||||||
var trackChannel = 1
|
var trackChannel = 1
|
||||||
|
val usedTracks = BooleanArray(Pattern.TRACK_COUNT)
|
||||||
var maxRoll = 0
|
var maxRoll = 0
|
||||||
|
|
||||||
text.lineSequence().map { it.trim() }.filter { it.isNotEmpty() }.forEach { line ->
|
for (tok in lines) {
|
||||||
val tok = line.split(Regex("\\s+"))
|
|
||||||
when (tok[0]) {
|
when (tok[0]) {
|
||||||
"version" -> {}
|
"version", "group", "scale", "root", "kind", "intro" -> {}
|
||||||
"bpm" -> project.tempoBpm = tok.getOrNull(1)?.toFloatOrNull() ?: 120f
|
"bpm" -> tok.getOrNull(1)?.toFloatOrNull()?.takeIf { it.isFinite() }
|
||||||
|
?.let { project.tempoBpm = it.coerceIn(20f, 300f) }
|
||||||
"sig" -> project.timeSignature = when (tok.getOrNull(1)?.toIntOrNull()) {
|
"sig" -> project.timeSignature = when (tok.getOrNull(1)?.toIntOrNull()) {
|
||||||
3 -> TimeSignature.THREE_FOUR
|
3 -> TimeSignature.THREE_FOUR
|
||||||
5 -> TimeSignature.FIVE_FOUR
|
5 -> TimeSignature.FIVE_FOUR
|
||||||
else -> TimeSignature.FOUR_FOUR
|
else -> TimeSignature.FOUR_FOUR
|
||||||
}
|
}
|
||||||
|
"loop" -> if (tok.size >= 3) project.arrangement.loopEnabled = true
|
||||||
"block" -> {
|
"block" -> {
|
||||||
current = project.patterns.getOrNull(blockIndex)?.also { blk ->
|
blockOrdinal++
|
||||||
tok.getOrNull(1)?.let { blk.name = it }
|
current = if (blockOrdinal in keep) project.patterns.getOrNull(nextPattern++) else null
|
||||||
tok.getOrNull(2)?.toIntOrNull()?.let { blk.resize(it) }
|
current?.let { blk ->
|
||||||
|
val (name, length) = blockHeader(tok)
|
||||||
|
blk.name = name
|
||||||
|
length?.let { blk.resize(it.coerceIn(1, MAX_BLOCK_LENGTH)) }
|
||||||
}
|
}
|
||||||
blockIndex++
|
track = -1; trackChannel = 1
|
||||||
track = 0; trackChannel = 1
|
usedTracks.fill(false)
|
||||||
}
|
}
|
||||||
"roll" -> current?.let { blk ->
|
"roll" -> current?.let { blk ->
|
||||||
val roll = tok.getOrNull(1) ?: ""
|
val roll = tok.getOrNull(1) ?: ""
|
||||||
roll.forEachIndexed { beat, ch -> if (ch == '#') project.arrangement.set(blk.id, beat, blk.id) }
|
roll.forEachIndexed { beat, ch ->
|
||||||
|
when (ch) {
|
||||||
|
'#' -> project.arrangement.set(blk.id, beat, blk.id)
|
||||||
|
'x' -> project.arrangement.set(blk.id, beat, Arrangement.NOTE_OFF)
|
||||||
|
}
|
||||||
|
}
|
||||||
maxRoll = maxOf(maxRoll, roll.length)
|
maxRoll = maxOf(maxRoll, roll.length)
|
||||||
}
|
}
|
||||||
"track" -> {
|
"track" -> {
|
||||||
track = tok.getOrNull(1)?.filter { it.isDigit() }?.toIntOrNull()?.minus(1)?.coerceIn(0, Pattern.TRACK_COUNT - 1) ?: 0
|
val wanted = tok.getOrNull(1)?.filter { it.isDigit() }?.toIntOrNull()?.minus(1)
|
||||||
|
track = if (wanted != null && wanted in 0 until Pattern.TRACK_COUNT && !usedTracks[wanted]) wanted
|
||||||
|
else usedTracks.indexOfFirst { !it }
|
||||||
|
if (track >= 0) usedTracks[track] = true
|
||||||
trackChannel = tok.getOrNull(2)?.toIntOrNull()?.plus(1)?.coerceIn(1, 16) ?: 1
|
trackChannel = tok.getOrNull(2)?.toIntOrNull()?.plus(1)?.coerceIn(1, 16) ?: 1
|
||||||
}
|
}
|
||||||
"endblock" -> current = null
|
"endblock" -> { current = null; track = -1 }
|
||||||
else -> applyStep(project, current, track, trackChannel, tok)
|
else -> if (track >= 0) applyStep(project, current, track, trackChannel, tok)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Grow the canvas (in bars) if the imported roll is longer than the default.
|
// Grow the canvas (in bars) if the imported roll is longer than the default.
|
||||||
@@ -137,6 +191,33 @@ object SngFormat {
|
|||||||
return project
|
return project
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** `block <name...> <length> [<numTracks>]` -> (name, length). Two trailing
|
||||||
|
* integers are length and track count (desktop and Mikro Seq; this app's own
|
||||||
|
* exports write beats-per-bar there, equally ignored); one is the length. */
|
||||||
|
private fun blockHeader(tok: List<String>): Pair<String, Int?> {
|
||||||
|
val rest = tok.drop(1)
|
||||||
|
val trailing = rest.takeLastWhile { it.toIntOrNull() != null }.size.coerceAtMost(2)
|
||||||
|
val length = when (trailing) {
|
||||||
|
2 -> rest[rest.size - 2].toIntOrNull()
|
||||||
|
1 -> rest.last().toIntOrNull()
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
val name = rest.dropLast(trailing).joinToString(" ").ifEmpty { rest.firstOrNull() ?: "PTN" }
|
||||||
|
return name to length
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Which block ordinals get one of the [slots] patterns: all of them when they
|
||||||
|
* fit, otherwise on-roll blocks first, then the rest, in file order. */
|
||||||
|
private fun blocksToKeep(lines: List<List<String>>, slots: Int): Set<Int> {
|
||||||
|
val onRoll = ArrayList<Boolean>()
|
||||||
|
for (tok in lines) when (tok[0]) {
|
||||||
|
"block" -> onRoll += false
|
||||||
|
"roll" -> if (onRoll.isNotEmpty() && '#' in (tok.getOrNull(1) ?: "")) onRoll[onRoll.size - 1] = true
|
||||||
|
}
|
||||||
|
val order = onRoll.indices.filter { onRoll[it] } + onRoll.indices.filter { !onRoll[it] }
|
||||||
|
return order.take(slots).toSet()
|
||||||
|
}
|
||||||
|
|
||||||
private fun applyStep(project: Project, block: Pattern?, track: Int, trackChannel: Int, tok: List<String>) {
|
private fun applyStep(project: Project, block: Pattern?, track: Int, trackChannel: Int, tok: List<String>) {
|
||||||
val blk = block ?: return
|
val blk = block ?: return
|
||||||
val tick = tok.getOrNull(0)?.toIntOrNull() ?: return
|
val tick = tok.getOrNull(0)?.toIntOrNull() ?: return
|
||||||
|
|||||||
@@ -0,0 +1,123 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
package cc.tiredsysadmin.android.sizzle.io
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Build
|
||||||
|
import android.provider.OpenableColumns
|
||||||
|
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,
|
||||||
|
/** 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",
|
||||||
|
* a file manager, the share sheet). The manifest accepts:
|
||||||
|
*
|
||||||
|
* - `ACTION_VIEW` of a `content:` / `file:` URI typed `application/octet-stream`,
|
||||||
|
* `text/plain` or `application/x-sizzle-song`, or of any type whose path ends
|
||||||
|
* in `.sng`;
|
||||||
|
* - `ACTION_SEND` of those types, with the file in `EXTRA_STREAM` (or the clip
|
||||||
|
* data), or for `text/plain` the song text itself in `EXTRA_TEXT`.
|
||||||
|
*
|
||||||
|
* Because `text/plain` and `application/octet-stream` match far more than songs,
|
||||||
|
* nothing here trusts the type: [SngFormat.looksLikeSng] checks the content before
|
||||||
|
* the UI offers to import it. Size is capped, the file is untrusted input.
|
||||||
|
*/
|
||||||
|
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
|
||||||
|
Intent.ACTION_SEND -> streamExtra(intent) ?: intent.clipData?.takeIf { it.itemCount > 0 }?.getItemAt(0)?.uri
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
if (uri == null) {
|
||||||
|
val text = intent.getStringExtra(Intent.EXTRA_TEXT)
|
||||||
|
return when {
|
||||||
|
text == null -> IncomingSong("shared song", null, "Nothing to open: the other app sent no file.")
|
||||||
|
!SngFormat.looksLikeSng(text) -> IncomingSong("shared text", null, NOT_A_SONG)
|
||||||
|
else -> IncomingSong(intent.getStringExtra(Intent.EXTRA_SUBJECT) ?: "shared song", text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val name = displayName(context, uri)
|
||||||
|
val bytes = runCatching {
|
||||||
|
context.contentResolver.openInputStream(uri)?.use(::readCapped)
|
||||||
|
}.getOrElse { e ->
|
||||||
|
return IncomingSong(name, null, "Couldn't read $name: ${e.message ?: e.javaClass.simpleName}")
|
||||||
|
} ?: 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, replaceNow = isTrustedReplace(context, intent))
|
||||||
|
}
|
||||||
|
|
||||||
|
private const val NOT_A_SONG = "This doesn't look like a Sizzle .sng song, so nothing was imported."
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
private fun streamExtra(intent: Intent): Uri? =
|
||||||
|
if (Build.VERSION.SDK_INT >= 33) intent.getParcelableExtra(Intent.EXTRA_STREAM, Uri::class.java)
|
||||||
|
else intent.getParcelableExtra(Intent.EXTRA_STREAM) as? Uri
|
||||||
|
|
||||||
|
private fun displayName(context: Context, uri: Uri): String {
|
||||||
|
val fromProvider = runCatching {
|
||||||
|
context.contentResolver.query(uri, arrayOf(OpenableColumns.DISPLAY_NAME), null, null, null)
|
||||||
|
?.use { c -> if (c.moveToFirst()) c.getString(0) else null }
|
||||||
|
}.getOrNull()
|
||||||
|
return (fromProvider ?: uri.lastPathSegment ?: "song").substringAfterLast('/')
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun readCapped(input: InputStream): ByteArray {
|
||||||
|
val bytes = input.readNBytesCompat(MAX_BYTES + 1)
|
||||||
|
require(bytes.size <= MAX_BYTES) { "file is larger than ${MAX_BYTES / 1024 / 1024} MB" }
|
||||||
|
return bytes
|
||||||
|
}
|
||||||
|
|
||||||
|
// InputStream.readNBytes is API 33+; minSdk is 26.
|
||||||
|
private fun InputStream.readNBytesCompat(limit: Int): ByteArray {
|
||||||
|
val out = java.io.ByteArrayOutputStream()
|
||||||
|
val buf = ByteArray(16 * 1024)
|
||||||
|
while (out.size() < limit) {
|
||||||
|
val n = read(buf, 0, minOf(buf.size, limit - out.size()))
|
||||||
|
if (n < 0) break
|
||||||
|
out.write(buf, 0, n)
|
||||||
|
}
|
||||||
|
return out.toByteArray()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,7 +15,7 @@ package cc.tiredsysadmin.android.sizzle.model
|
|||||||
* the canvas width — the sequencer stops at [lastFilledBeat].
|
* the canvas width — the sequencer stops at [lastFilledBeat].
|
||||||
*/
|
*/
|
||||||
class Arrangement {
|
class Arrangement {
|
||||||
/** slots[lane][beat] = patternId, or [EMPTY]. */
|
/** slots[lane][beat] = patternId, [EMPTY], or [NOTE_OFF]. */
|
||||||
val slots: Array<IntArray> = Array(LANE_COUNT) { IntArray(MAX_BEATS) { EMPTY } }
|
val slots: Array<IntArray> = Array(LANE_COUNT) { IntArray(MAX_BEATS) { EMPTY } }
|
||||||
|
|
||||||
/** Per-lane mute. A muted lane's blocks are skipped by the sequencer (its notes
|
/** Per-lane mute. A muted lane's blocks are skipped by the sequencer (its notes
|
||||||
@@ -39,6 +39,9 @@ class Arrangement {
|
|||||||
fun patternAt(lane: Int, beat: Int): Int =
|
fun patternAt(lane: Int, beat: Int): Int =
|
||||||
if (beat in 0 until MAX_BEATS) slots[lane][beat] else EMPTY
|
if (beat in 0 until MAX_BEATS) slots[lane][beat] else EMPTY
|
||||||
|
|
||||||
|
/** Does this slot hold a real block (rather than nothing or a [NOTE_OFF] marker)? */
|
||||||
|
fun hasBlockAt(lane: Int, beat: Int): Boolean = patternAt(lane, beat) >= 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The highest beat index holding any non-empty cell across all lanes, or -1 if
|
* The highest beat index holding any non-empty cell across all lanes, or -1 if
|
||||||
* the arrangement is empty. Playback uses this to stop after the last filled
|
* the arrangement is empty. Playback uses this to stop after the last filled
|
||||||
@@ -67,6 +70,18 @@ class Arrangement {
|
|||||||
* supported signature (5/4 → 5 beats per bar). */
|
* supported signature (5/4 → 5 beats per bar). */
|
||||||
const val MAX_BEATS = MAX_BARS * 5
|
const val MAX_BEATS = MAX_BARS * 5
|
||||||
const val EMPTY = -1
|
const val EMPTY = -1
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A slot holding an "off" marker rather than a block. When the playhead
|
||||||
|
* reaches it, every track of that lane is released — the arrangement-level
|
||||||
|
* equivalent of a column of note-off cells, for cutting a held or looping
|
||||||
|
* instrument without editing the block that started it.
|
||||||
|
*
|
||||||
|
* It is NOT empty: it counts towards [lastFilledBeat] (playback runs up to
|
||||||
|
* it) and it breaks a contiguous run of block markers, so a block after an
|
||||||
|
* off marker restarts from its first beat.
|
||||||
|
*/
|
||||||
|
const val NOTE_OFF = -2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
|
|
||||||
package cc.tiredsysadmin.android.sizzle.model
|
package cc.tiredsysadmin.android.sizzle.model
|
||||||
|
|
||||||
|
import cc.tiredsysadmin.android.sizzle.echofield.EchofieldDefs
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs
|
||||||
|
import cc.tiredsysadmin.android.sizzle.wavetable.WaveDefs
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The third tab is a toolbox of 16 slots. Every slot can hold one instrument OR
|
* The third tab is a toolbox of 16 slots. Every slot can hold one instrument OR
|
||||||
* one effect. Rather than a separate class per device (which would be a lot of
|
* one effect. Rather than a separate class per device (which would be a lot of
|
||||||
@@ -45,7 +49,7 @@ enum class ToolboxType(
|
|||||||
// ---------- Instruments ----------
|
// ---------- Instruments ----------
|
||||||
// A classic 3-oscillator subtractive synth (Minimoog-style): oscillators →
|
// A classic 3-oscillator subtractive synth (Minimoog-style): oscillators →
|
||||||
// mixer → resonant filter (own contour) → amp (own envelope), with a tempo-synced
|
// 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,
|
// 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
|
// .sng type) and must stay stable for backward compatibility; only the user-facing
|
||||||
// displayName is generic.
|
// displayName is generic.
|
||||||
@@ -90,6 +94,10 @@ enum class ToolboxType(
|
|||||||
ToolboxKind.INSTRUMENT, "Sampler",
|
ToolboxKind.INSTRUMENT, "Sampler",
|
||||||
listOf(
|
listOf(
|
||||||
ParamSpec("volume", "Volume", 0.8f, 0f, 1f),
|
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
|
// 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
|
// [SamplerPads]) and stores its own sample id + slice as string params
|
||||||
// ("pad0", "pad0S", "pad0E", …). Edited by ui/toolbox/SamplerEditor.
|
// ("pad0", "pad0S", "pad0E", …). Edited by ui/toolbox/SamplerEditor.
|
||||||
@@ -113,6 +121,22 @@ 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
|
||||||
|
// 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 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 core/src/wavetable/WaveVoice inside SynthVoice; edited by WavetableEditor + the paged list.
|
||||||
|
WAVETABLE(ToolboxKind.INSTRUMENT, "Wavetable", WaveDefs.PARAMS),
|
||||||
|
|
||||||
// ---------- Effects ----------
|
// ---------- Effects ----------
|
||||||
ARPEGGIATOR(
|
ARPEGGIATOR(
|
||||||
ToolboxKind.EFFECT, "MIDI Arpeggiator",
|
ToolboxKind.EFFECT, "MIDI Arpeggiator",
|
||||||
@@ -197,7 +221,7 @@ enum class ToolboxType(
|
|||||||
ToolboxKind.EFFECT, "Ambience Reverb",
|
ToolboxKind.EFFECT, "Ambience Reverb",
|
||||||
// A mono port of the Ambience 16-channel FDN reverb (OTODESK): 7 algorithms,
|
// A mono port of the Ambience 16-channel FDN reverb (OTODESK): 7 algorithms,
|
||||||
// tempo-independent tunables and 21 factory spaces (seeded into the preset
|
// 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(
|
listOf(
|
||||||
ParamSpec("algo", "Algorithm", 0f, 0f, 6f, AmbiencePresets.ALGORITHMS),
|
ParamSpec("algo", "Algorithm", 0f, 0f, 6f, AmbiencePresets.ALGORITHMS),
|
||||||
ParamSpec("predelay", "Pre-Delay", 10f, 0f, 500f),
|
ParamSpec("predelay", "Pre-Delay", 10f, 0f, 500f),
|
||||||
@@ -225,7 +249,7 @@ enum class ToolboxType(
|
|||||||
// morphs the whole chain from transparent (0) to the full preset (1). Every
|
// 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
|
// per-band value is a hidden slot param set by the genre/instrument presets
|
||||||
// (see MixTightenerPresets); only Strength is user-facing. Rendered by
|
// (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)),
|
listOf(ParamSpec("strength", "Strength", 1f, 0f, 1f)),
|
||||||
),
|
),
|
||||||
TAPE_ENGINE(
|
TAPE_ENGINE(
|
||||||
@@ -234,7 +258,7 @@ enum class ToolboxType(
|
|||||||
// the pitch dives like a slowing tape (the 'speed' param is driven by that reel
|
// 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
|
// 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
|
// 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(
|
listOf(
|
||||||
ParamSpec("speed", "Speed", 1f, 0.25f, 1f),
|
ParamSpec("speed", "Speed", 1f, 0.25f, 1f),
|
||||||
ParamSpec("wow", "Wow", 0.15f, 0f, 1f),
|
ParamSpec("wow", "Wow", 0.15f, 0f, 1f),
|
||||||
@@ -248,7 +272,7 @@ enum class ToolboxType(
|
|||||||
// Stutters/repeats short grains read from a rolling buffer of the incoming
|
// 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
|
// 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
|
// 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.
|
// by ui/toolbox/GranularEditor.
|
||||||
listOf(ParamSpec("intensity", "Intensity", 0.3f, 0f, 1f)),
|
listOf(ParamSpec("intensity", "Intensity", 0.3f, 0f, 1f)),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,134 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
package cc.tiredsysadmin.android.sizzle.playback
|
||||||
|
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The headless multitimbral sound module: incoming MIDI → audio engine, with no UI
|
||||||
|
* in the path. It lives in [cc.tiredsysadmin.android.sizzle.SizzleApp] next to the
|
||||||
|
* engine, so it keeps working while the Activity and its ViewModel are gone and the
|
||||||
|
* [SoundModuleService] holds the process in the foreground.
|
||||||
|
*
|
||||||
|
* - Note On / Off on channel N play / release every mixer track listening on N
|
||||||
|
* ([NoteSink.busNoteOn] / [NoteSink.busNoteOff]).
|
||||||
|
* - All Notes Off (CC 123) and All Sound Off (CC 120) release what is held on
|
||||||
|
* that channel. Mikro Seq sends CC 123 on stop.
|
||||||
|
* - Real-time bytes (clock, Start, Stop) go to [realtime]; the app points it at
|
||||||
|
* the MIDI clock follower, which acts on them only while "Receive MIDI clock"
|
||||||
|
* is on.
|
||||||
|
* - Notes are tracked per source, so a source that disconnects mid-note
|
||||||
|
* ([sourceDisconnected]) has its held notes released instead of droning.
|
||||||
|
*
|
||||||
|
* The UI only observes: [noteListener] mirrors each note so the ViewModel can show
|
||||||
|
* held keys and punch notes into the grid, without sounding them again.
|
||||||
|
*
|
||||||
|
* Pure Kotlin, unit-tested. Thread-safe: each MIDI port delivers on its own
|
||||||
|
* thread, so every entry point takes one lock (uncontended in practice).
|
||||||
|
*/
|
||||||
|
class MidiSoundModule(private val sink: NoteSink) {
|
||||||
|
|
||||||
|
/** Where notes are played. [cc.tiredsysadmin.android.sizzle.audio.AudioEngine]
|
||||||
|
* in the app; a recorder in tests. */
|
||||||
|
interface NoteSink {
|
||||||
|
fun busNoteOn(channel: Int, note: Int, velocity: Int)
|
||||||
|
fun busNoteOff(channel: Int, note: Int)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Mirror of every note the module played or released (channel 1..16). */
|
||||||
|
@Volatile var noteListener: ((on: Boolean, channel: Int, note: Int, velocity: Int) -> Unit)? = null
|
||||||
|
|
||||||
|
/** MIDI System Real-Time bytes (0xF8..0xFF). */
|
||||||
|
@Volatile var realtime: ((Int) -> Unit)? = null
|
||||||
|
|
||||||
|
private val lock = Any()
|
||||||
|
/** source id -> held keys, key = (channel-1) * 128 + note. */
|
||||||
|
private val held = HashMap<Int, MutableSet<Int>>()
|
||||||
|
|
||||||
|
private val _sources = MutableStateFlow(0)
|
||||||
|
/** How many MIDI sources are open right now (shown in the notification). */
|
||||||
|
val sources: StateFlow<Int> = _sources.asStateFlow()
|
||||||
|
|
||||||
|
fun sourceConnected(source: Int) = synchronized(lock) {
|
||||||
|
held.getOrPut(source) { HashSet() }
|
||||||
|
_sources.value = held.size
|
||||||
|
}
|
||||||
|
|
||||||
|
/** [source] went away (unplugged, its app died, or we closed it): release its notes. */
|
||||||
|
fun sourceDisconnected(source: Int) = synchronized(lock) {
|
||||||
|
held.remove(source)?.let(::releaseKeys)
|
||||||
|
_sources.value = held.size
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One channel message from [source]. Returns true when the module consumed it
|
||||||
|
* (notes and the all-notes-off controls); other messages (CC bindings, program
|
||||||
|
* change, …) are left to the caller.
|
||||||
|
*/
|
||||||
|
fun onChannelMessage(source: Int, status: Int, d1: Int, d2: Int): Boolean {
|
||||||
|
val channel = (status and 0x0F) + 1
|
||||||
|
val note = d1 and 0x7F
|
||||||
|
return when (status and 0xF0) {
|
||||||
|
0x90 -> { if (d2 > 0) noteOn(source, channel, note, d2) else noteOff(source, channel, note); true }
|
||||||
|
0x80 -> { noteOff(source, channel, note); true }
|
||||||
|
0xB0 -> if (d1 == CC_ALL_NOTES_OFF || d1 == CC_ALL_SOUND_OFF) { channelOff(channel); true } else false
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onRealtime(status: Int) { realtime?.invoke(status) }
|
||||||
|
|
||||||
|
/** Release everything any source holds (panic, shutdown). */
|
||||||
|
fun releaseAll() = synchronized(lock) { held.values.forEach { releaseKeys(it); it.clear() } }
|
||||||
|
|
||||||
|
/** Held (channel, note) pairs per source, for tests and diagnostics. */
|
||||||
|
fun heldNotes(source: Int): Set<Pair<Int, Int>> = synchronized(lock) {
|
||||||
|
held[source].orEmpty().map { it / 128 + 1 to it % 128 }.toSet()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun noteOn(source: Int, channel: Int, note: Int, velocity: Int) = synchronized(lock) {
|
||||||
|
held.getOrPut(source) { HashSet() }.add(key(channel, note))
|
||||||
|
if (held.size != _sources.value) _sources.value = held.size
|
||||||
|
sink.busNoteOn(channel, note, velocity)
|
||||||
|
noteListener?.invoke(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.
|
||||||
|
private fun noteOff(source: Int, channel: Int, note: Int) = synchronized(lock) {
|
||||||
|
held[source]?.remove(key(channel, note))
|
||||||
|
sink.busNoteOff(channel, note)
|
||||||
|
noteListener?.invoke(false, channel, note, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** CC 123 / 120 on [channel]: a receiver releases the channel's notes whoever
|
||||||
|
* sent them, so this clears that channel across all sources. */
|
||||||
|
private fun channelOff(channel: Int) = synchronized(lock) {
|
||||||
|
for (keys in held.values) {
|
||||||
|
val it = keys.iterator()
|
||||||
|
while (it.hasNext()) {
|
||||||
|
val k = it.next()
|
||||||
|
if (k / 128 + 1 == channel) { release(k); it.remove() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun releaseKeys(keys: Set<Int>) = keys.forEach(::release)
|
||||||
|
|
||||||
|
private fun release(k: Int) {
|
||||||
|
val channel = k / 128 + 1
|
||||||
|
val note = k % 128
|
||||||
|
sink.busNoteOff(channel, note)
|
||||||
|
noteListener?.invoke(false, channel, note, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun key(channel: Int, note: Int) = (channel - 1) * 128 + note
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
const val CC_ALL_SOUND_OFF = 120
|
||||||
|
const val CC_ALL_NOTES_OFF = 123
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,13 +25,16 @@ import kotlinx.coroutines.launch
|
|||||||
@UnstableApi
|
@UnstableApi
|
||||||
class PlaybackService : MediaSessionService() {
|
class PlaybackService : MediaSessionService() {
|
||||||
|
|
||||||
private val engine get() = (application as SizzleApp).audioEngine
|
private val app get() = application as SizzleApp
|
||||||
|
private val engine get() = app.audioEngine
|
||||||
private var session: MediaSession? = null
|
private var session: MediaSession? = null
|
||||||
private val scope = CoroutineScope(Dispatchers.Main + SupervisorJob())
|
private val scope = CoroutineScope(Dispatchers.Main + SupervisorJob())
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
engine.start()
|
// Shared with the Activity and the SoundModuleService (reference-counted).
|
||||||
|
app.acquireEngine(OWNER)
|
||||||
|
app.acquireMidi(OWNER)
|
||||||
val player = EnginePlayer(engine)
|
val player = EnginePlayer(engine)
|
||||||
session = MediaSession.Builder(this, player).build()
|
session = MediaSession.Builder(this, player).build()
|
||||||
// Keep the session's reported state in sync with the engine (the on-screen
|
// Keep the session's reported state in sync with the engine (the on-screen
|
||||||
@@ -45,11 +48,14 @@ class PlaybackService : MediaSessionService() {
|
|||||||
scope.cancel()
|
scope.cancel()
|
||||||
session?.run { player.release(); release() }
|
session?.run { player.release(); release() }
|
||||||
session = null
|
session = null
|
||||||
engine.release()
|
app.releaseMidi(OWNER)
|
||||||
|
app.releaseEngine(OWNER)
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
private const val OWNER = "playback"
|
||||||
|
|
||||||
/** Start the service from a foreground context (safe: plain startService,
|
/** Start the service from a foreground context (safe: plain startService,
|
||||||
* MediaSessionService promotes itself to foreground when playback begins). */
|
* MediaSessionService promotes itself to foreground when playback begins). */
|
||||||
fun start(context: Context) {
|
fun start(context: Context) {
|
||||||
|
|||||||
@@ -0,0 +1,145 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
package cc.tiredsysadmin.android.sizzle.playback
|
||||||
|
|
||||||
|
import android.app.Notification
|
||||||
|
import android.app.NotificationChannel
|
||||||
|
import android.app.NotificationManager
|
||||||
|
import android.app.PendingIntent
|
||||||
|
import android.app.Service
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.pm.ServiceInfo
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.IBinder
|
||||||
|
import androidx.core.app.NotificationCompat
|
||||||
|
import androidx.core.app.ServiceCompat
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import cc.tiredsysadmin.android.sizzle.MainActivity
|
||||||
|
import cc.tiredsysadmin.android.sizzle.R
|
||||||
|
import cc.tiredsysadmin.android.sizzle.SizzleApp
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.SupervisorJob
|
||||||
|
import kotlinx.coroutines.cancel
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keeps Sizzle alive as a background MIDI sound module, like an iOS Inter-App
|
||||||
|
* Audio instrument: while it runs, another app (Mikro Seq, a DAW, a controller)
|
||||||
|
* can play Sizzle's mixer from the background even with Sizzle's own transport
|
||||||
|
* stopped.
|
||||||
|
*
|
||||||
|
* Why it exists: on Android 14+ the cached-app freezer suspends a backgrounded
|
||||||
|
* process within seconds unless it has a foreground service. The media
|
||||||
|
* [PlaybackService] is only in the foreground while the transport plays (media3
|
||||||
|
* drops foreground on pause), so on its own Sizzle stops answering MIDI as soon
|
||||||
|
* as it leaves the screen. This plain foreground service of type
|
||||||
|
* `mediaPlayback` (Sizzle does play audio) holds the process up instead.
|
||||||
|
*
|
||||||
|
* Trigger: the "Keep running as MIDI sound module" setting, not "a MIDI source is
|
||||||
|
* connected". Android lists every installed app's virtual MIDI device at all
|
||||||
|
* times, so "connected" would be true almost always; and a source plugged in
|
||||||
|
* while Sizzle is already in the background could not start a foreground service
|
||||||
|
* anyway (Android 12+ forbids that, and MIDI is not an exemption). So the user
|
||||||
|
* opts in, the service starts while Sizzle is on screen, and the notification
|
||||||
|
* shows how many sources are open and offers Stop.
|
||||||
|
*
|
||||||
|
* It owns a reference to the engine and the MIDI ports (see
|
||||||
|
* [SizzleApp.acquireEngine] / [SizzleApp.acquireMidi]), so they stay open after
|
||||||
|
* the Activity is destroyed. Routing itself is [MidiSoundModule].
|
||||||
|
*/
|
||||||
|
class SoundModuleService : Service() {
|
||||||
|
|
||||||
|
private val app get() = application as SizzleApp
|
||||||
|
private val scope = CoroutineScope(Dispatchers.Main + SupervisorJob())
|
||||||
|
|
||||||
|
override fun onCreate() {
|
||||||
|
super.onCreate()
|
||||||
|
createChannel()
|
||||||
|
ServiceCompat.startForeground(
|
||||||
|
this, NOTIFICATION_ID, buildNotification(app.soundModule.sources.value),
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK else 0,
|
||||||
|
)
|
||||||
|
app.acquireEngine(OWNER)
|
||||||
|
app.acquireMidi(OWNER)
|
||||||
|
scope.launch {
|
||||||
|
app.soundModule.sources.collect { n ->
|
||||||
|
getSystemService(NotificationManager::class.java)
|
||||||
|
?.notify(NOTIFICATION_ID, buildNotification(n))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
|
if (intent?.action == ACTION_STOP) app.setSoundModuleEnabled(false) // persists, stops us
|
||||||
|
// Not sticky: a restart after the system killed us would come from the
|
||||||
|
// background, where a foreground start is refused. The next time the user
|
||||||
|
// opens Sizzle, MainActivity starts the service again.
|
||||||
|
return START_NOT_STICKY
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBind(intent: Intent?): IBinder? = null
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
scope.cancel()
|
||||||
|
app.releaseMidi(OWNER) // closes the ports when no one else holds them
|
||||||
|
app.soundModule.releaseAll()
|
||||||
|
app.releaseEngine(OWNER)
|
||||||
|
super.onDestroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createChannel() {
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
|
||||||
|
val channel = NotificationChannel(CHANNEL_ID, "MIDI sound module", NotificationManager.IMPORTANCE_LOW)
|
||||||
|
.apply { description = "Shown while Sizzle keeps running to play incoming MIDI" }
|
||||||
|
getSystemService(NotificationManager::class.java)?.createNotificationChannel(channel)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildNotification(sources: Int): Notification {
|
||||||
|
val open = PendingIntent.getActivity(
|
||||||
|
this, 0, Intent(this, MainActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),
|
||||||
|
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,
|
||||||
|
)
|
||||||
|
val stop = PendingIntent.getService(
|
||||||
|
this, 1, Intent(this, SoundModuleService::class.java).setAction(ACTION_STOP),
|
||||||
|
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,
|
||||||
|
)
|
||||||
|
val text = when (sources) {
|
||||||
|
0 -> "Waiting for a MIDI source"
|
||||||
|
1 -> "Playing MIDI from 1 source"
|
||||||
|
else -> "Playing MIDI from $sources sources"
|
||||||
|
}
|
||||||
|
return NotificationCompat.Builder(this, CHANNEL_ID)
|
||||||
|
.setSmallIcon(R.drawable.ic_stat_sound_module)
|
||||||
|
.setContentTitle("Sizzle MIDI sound module")
|
||||||
|
.setContentText(text)
|
||||||
|
.setContentIntent(open)
|
||||||
|
.addAction(0, "Stop", stop)
|
||||||
|
.setOngoing(true)
|
||||||
|
.setOnlyAlertOnce(true)
|
||||||
|
.setSilent(true)
|
||||||
|
.setCategory(NotificationCompat.CATEGORY_SERVICE)
|
||||||
|
.setForegroundServiceBehavior(NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val OWNER = "sound-module"
|
||||||
|
private const val CHANNEL_ID = "sound_module"
|
||||||
|
private const val NOTIFICATION_ID = 0x51221E
|
||||||
|
private const val ACTION_STOP = "cc.tiredsysadmin.android.sizzle.action.STOP_SOUND_MODULE"
|
||||||
|
|
||||||
|
/** Start (or keep) the service. Only succeeds from the foreground. */
|
||||||
|
fun start(context: Context) {
|
||||||
|
runCatching {
|
||||||
|
ContextCompat.startForegroundService(context, Intent(context, SoundModuleService::class.java))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stop(context: Context) {
|
||||||
|
context.stopService(Intent(context, SoundModuleService::class.java))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -82,6 +82,32 @@ fun SizzleApp(vm: AppViewModel) {
|
|||||||
confirmButton = { TextButton(onClick = { vm.dismissNativeAudioError() }) { Text("OK") } },
|
confirmButton = { TextButton(onClick = { vm.dismissNativeAudioError() }) { Text("OK") } },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A .sng opened from another app (Mikro Seq's "Open in Sizzle", a file manager,
|
||||||
|
// the share sheet): ask before it replaces the current song, or say why not.
|
||||||
|
vm.incomingSong?.let { song ->
|
||||||
|
if (song.text == null) {
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = { vm.dismissIncomingSong() },
|
||||||
|
title = { Text("Open song") },
|
||||||
|
text = { Text(song.error ?: "Couldn't open ${song.name}.") },
|
||||||
|
confirmButton = { TextButton(onClick = { vm.dismissIncomingSong() }) { Text("OK") } },
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = { vm.dismissIncomingSong() },
|
||||||
|
title = { Text("Open ${song.name}?") },
|
||||||
|
text = {
|
||||||
|
Text(
|
||||||
|
"This replaces the patterns and arrangement of the current song " +
|
||||||
|
"(mixer and instruments stay). Save it first if you want to keep it.",
|
||||||
|
)
|
||||||
|
},
|
||||||
|
confirmButton = { TextButton(onClick = { vm.acceptIncomingSong() }) { Text("Replace") } },
|
||||||
|
dismissButton = { TextButton(onClick = { vm.dismissIncomingSong() }) { Text("Cancel") } },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The active tab's screen. */
|
/** The active tab's screen. */
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import cc.tiredsysadmin.android.sizzle.model.Pitch
|
|||||||
import cc.tiredsysadmin.android.sizzle.model.Project
|
import cc.tiredsysadmin.android.sizzle.model.Project
|
||||||
import cc.tiredsysadmin.android.sizzle.model.TimeSignature
|
import cc.tiredsysadmin.android.sizzle.model.TimeSignature
|
||||||
import cc.tiredsysadmin.android.sizzle.model.ToolboxSlot
|
import cc.tiredsysadmin.android.sizzle.model.ToolboxSlot
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.ToolboxType
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
@@ -43,6 +44,9 @@ import kotlinx.coroutines.launch
|
|||||||
*/
|
*/
|
||||||
/** Tab index of the Tracker tab (see [App]'s tab order). */
|
/** Tab index of the Tracker tab (see [App]'s tab order). */
|
||||||
private const val TAB_TRACKER = 0
|
private const val TAB_TRACKER = 0
|
||||||
|
/** Tab indices of the Mix and Toolbox tabs. */
|
||||||
|
const val TAB_MIX = 1
|
||||||
|
const val TAB_TOOLBOX = 2
|
||||||
|
|
||||||
/** Reserved prefix for a toolbox slot's MIDI-CC parameter bindings, stored in the
|
/** Reserved prefix for a toolbox slot's MIDI-CC parameter bindings, stored in the
|
||||||
* slot's value map (`midicc@<paramKey>` -> CC number) so they persist with the
|
* slot's value map (`midicc@<paramKey>` -> CC number) so they persist with the
|
||||||
@@ -113,6 +117,15 @@ class AppViewModel(
|
|||||||
/** Whether the mixer's fader VU meters are shown (Settings toggle). */
|
/** Whether the mixer's fader VU meters are shown (Settings toggle). */
|
||||||
var vuMeters by mutableStateOf(true); private set
|
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. */
|
/** Enable/disable the mixer fader VU meters and persist the choice. */
|
||||||
fun updateVuMeters(enabled: Boolean) {
|
fun updateVuMeters(enabled: Boolean) {
|
||||||
vuMeters = enabled
|
vuMeters = enabled
|
||||||
@@ -136,6 +149,74 @@ class AppViewModel(
|
|||||||
persistMidiClock(); touched()
|
persistMidiClock(); touched()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----- MIDI sound module (Settings) -----
|
||||||
|
private val sizzleApp get() = appContext as cc.tiredsysadmin.android.sizzle.SizzleApp
|
||||||
|
|
||||||
|
/** "Keep running as MIDI sound module": owned by SizzleApp because the
|
||||||
|
* notification's Stop action changes it with no UI around. */
|
||||||
|
val soundModuleMode: StateFlow<Boolean> get() = sizzleApp.soundModuleEnabled
|
||||||
|
|
||||||
|
fun updateSoundModuleMode(enabled: Boolean) = sizzleApp.setSoundModuleEnabled(enabled)
|
||||||
|
|
||||||
|
/** Every MIDI source that can send to Sizzle, with whether it is listened to. */
|
||||||
|
val midiInputSources: StateFlow<List<cc.tiredsysadmin.android.sizzle.input.MidiSource>>
|
||||||
|
get() = midiInput.sources
|
||||||
|
|
||||||
|
fun setMidiSourceEnabled(key: String, enabled: Boolean) = midiInput.setEnabled(key, enabled)
|
||||||
|
|
||||||
|
/** 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. */
|
||||||
|
fun acceptIncomingSong(): Boolean {
|
||||||
|
val song = incomingSong ?: return false
|
||||||
|
val text = song.text ?: return false.also { incomingSong = null }
|
||||||
|
incomingSong = null
|
||||||
|
engine.stop()
|
||||||
|
val ok = importSng(text)
|
||||||
|
if (ok) {
|
||||||
|
project.name = song.name.substringBeforeLast(".sng").ifBlank { "untitled" }
|
||||||
|
clearArrangementSelection()
|
||||||
|
selectTab(TAB_TRACKER)
|
||||||
|
} else {
|
||||||
|
incomingSong = cc.tiredsysadmin.android.sizzle.io.IncomingSong(
|
||||||
|
"song", null, "Couldn't import this file. It doesn't look like a valid .sng song.",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
private fun persistMidiClock() {
|
private fun persistMidiClock() {
|
||||||
viewModelScope.launch { settingsStore.saveMidiClock(sendMidiClock, receiveMidiClock) }
|
viewModelScope.launch { settingsStore.saveMidiClock(sendMidiClock, receiveMidiClock) }
|
||||||
}
|
}
|
||||||
@@ -185,6 +266,22 @@ class AppViewModel(
|
|||||||
// ------------------------------------------------------------- tab control
|
// ------------------------------------------------------------- tab control
|
||||||
fun selectTab(index: Int) { selectedTab = index.coerceIn(0, 3) }
|
fun selectTab(index: Int) { selectedTab = index.coerceIn(0, 3) }
|
||||||
|
|
||||||
|
/** A request for the Toolbox to open slot [index]'s settings, and the tab to go
|
||||||
|
* back to when that editor is closed (null: stay on the Toolbox). */
|
||||||
|
class SlotEditorRequest(val index: Int, val returnTab: Int?)
|
||||||
|
|
||||||
|
var slotEditorRequest by mutableStateOf<SlotEditorRequest?>(null); private set
|
||||||
|
|
||||||
|
/** Open toolbox slot [index]'s settings from elsewhere (the mixer's long-press):
|
||||||
|
* switch to the Toolbox with its editor open; closing it returns to [returnTab]. */
|
||||||
|
fun openSlotEditor(index: Int, returnTab: Int? = null) {
|
||||||
|
if (project.toolbox.getOrNull(index)?.isEmpty != false) return
|
||||||
|
slotEditorRequest = SlotEditorRequest(index, returnTab)
|
||||||
|
selectTab(TAB_TOOLBOX)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun consumeSlotEditorRequest() { slotEditorRequest = null }
|
||||||
|
|
||||||
// ----------------------------------------------------------- cursor & edit
|
// ----------------------------------------------------------- cursor & edit
|
||||||
fun focusCell(track: Int, line: Int, column: CellColumn) {
|
fun focusCell(track: Int, line: Int, column: CellColumn) {
|
||||||
val p = project.activePattern()
|
val p = project.activePattern()
|
||||||
@@ -547,10 +644,14 @@ class AppViewModel(
|
|||||||
InputAction.NoteOffCell -> noteOffFocused()
|
InputAction.NoteOffCell -> noteOffFocused()
|
||||||
is InputAction.NoteOn -> {
|
is InputAction.NoteOn -> {
|
||||||
markNoteOn(action.pitch)
|
markNoteOn(action.pitch)
|
||||||
// MIDI notes route to the mixer track(s) listening on their channel;
|
// MIDI notes were already played by the headless sound module
|
||||||
// a channel-less source (physical keyboard) plays the default synth.
|
// (SizzleApp.soundModule) on the mixer track(s) listening on their
|
||||||
|
// channel; here they are only shown and punched in. A channel-less
|
||||||
|
// source (physical keyboard) plays the default synth.
|
||||||
|
if (!action.sounded) {
|
||||||
if (action.channel >= 1) engine.busNoteOn(action.channel, action.pitch, action.velocity)
|
if (action.channel >= 1) engine.busNoteOn(action.channel, action.pitch, action.velocity)
|
||||||
else engine.liveNoteOn(action.pitch, action.velocity)
|
else engine.liveNoteOn(action.pitch, action.velocity)
|
||||||
|
}
|
||||||
// On the Tracker tab with punch-in armed, also enter the note into the
|
// On the Tracker tab with punch-in armed, also enter the note into the
|
||||||
// grid — recording its own velocity/channel so it plays back correctly.
|
// grid — recording its own velocity/channel so it plays back correctly.
|
||||||
if (selectedTab == TAB_TRACKER && punchInMode) {
|
if (selectedTab == TAB_TRACKER && punchInMode) {
|
||||||
@@ -560,9 +661,11 @@ class AppViewModel(
|
|||||||
}
|
}
|
||||||
is InputAction.NoteOff -> {
|
is InputAction.NoteOff -> {
|
||||||
markNoteOff(action.pitch)
|
markNoteOff(action.pitch)
|
||||||
|
if (!action.sounded) {
|
||||||
if (action.channel >= 1) engine.busNoteOff(action.channel, action.pitch)
|
if (action.channel >= 1) engine.busNoteOff(action.channel, action.pitch)
|
||||||
else engine.liveNoteOff(action.pitch)
|
else engine.liveNoteOff(action.pitch)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
InputAction.PlayPause -> playPause()
|
InputAction.PlayPause -> playPause()
|
||||||
InputAction.Stop -> stop()
|
InputAction.Stop -> stop()
|
||||||
InputAction.ToggleLoop -> { project.arrangement.loopEnabled = !project.arrangement.loopEnabled; touched() }
|
InputAction.ToggleLoop -> { project.arrangement.loopEnabled = !project.arrangement.loopEnabled; touched() }
|
||||||
@@ -615,6 +718,34 @@ class AppViewModel(
|
|||||||
touched()
|
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]. */
|
/** Remove the MIDI-CC binding for [slotIndex]'s [paramKey]. */
|
||||||
fun clearParamCc(slotIndex: Int, paramKey: String) {
|
fun clearParamCc(slotIndex: Int, paramKey: String) {
|
||||||
project.toolbox.getOrNull(slotIndex)?.values?.remove(ccKey(paramKey))
|
project.toolbox.getOrNull(slotIndex)?.values?.remove(ccKey(paramKey))
|
||||||
@@ -732,7 +863,8 @@ class AppViewModel(
|
|||||||
viewModelScope.launch { bindingStore.save(keyboardInput, gamepadInput, midiInput) }
|
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
|
/** Public hook so screens that mutate the model directly (e.g. dropdowns in
|
||||||
* the toolbar, mixer faders) can request a redraw. */
|
* the toolbar, mixer faders) can request a redraw. */
|
||||||
@@ -972,21 +1104,12 @@ class AppViewModel(
|
|||||||
kbdChannel = s.kbdChannel.coerceIn(0, Cell.MAX_CHANNEL)
|
kbdChannel = s.kbdChannel.coerceIn(0, Cell.MAX_CHANNEL)
|
||||||
kbdOctave = s.kbdOctave.coerceIn(0, 8)
|
kbdOctave = s.kbdOctave.coerceIn(0, 8)
|
||||||
vuMeters = s.vuMeters
|
vuMeters = s.vuMeters
|
||||||
|
keepScreenOn = s.keepScreenOn
|
||||||
|
|
||||||
// MIDI clock sync: feed the send thread live transport, follow an external
|
// MIDI clock sync: the transport/tempo follow and the send thread's
|
||||||
// clock into the transport/tempo, and restore the persisted toggles.
|
// providers are wired in SizzleApp (they must work with no UI); here we
|
||||||
midiClock.playingProvider = { engine.transport.value.isPlaying }
|
// restore the persisted toggles and redraw when a followed tempo lands.
|
||||||
midiClock.bpmProvider = { project.tempoBpm }
|
viewModelScope.launch { midiClock.followedTempo.collect { setTempo(it) } }
|
||||||
midiClock.noteSource = { engine.pollMidiOut() } // forward sequenced notes out
|
|
||||||
midiClock.onReceiveStart = {
|
|
||||||
viewModelScope.launch(Dispatchers.Main) { if (!engine.transport.value.isPlaying) engine.play() }
|
|
||||||
}
|
|
||||||
midiClock.onReceiveStop = {
|
|
||||||
viewModelScope.launch(Dispatchers.Main) { engine.pause() }
|
|
||||||
}
|
|
||||||
midiClock.onReceiveTempo = { bpm ->
|
|
||||||
viewModelScope.launch(Dispatchers.Main) { setTempo(bpm) }
|
|
||||||
}
|
|
||||||
sendMidiClock = s.sendMidiClock
|
sendMidiClock = s.sendMidiClock
|
||||||
midiClock.sendEnabled = s.sendMidiClock; engine.midiOutEnabled = s.sendMidiClock
|
midiClock.sendEnabled = s.sendMidiClock; engine.midiOutEnabled = s.sendMidiClock
|
||||||
receiveMidiClock = s.receiveMidiClock; midiClock.receiveEnabled = s.receiveMidiClock
|
receiveMidiClock = s.receiveMidiClock; midiClock.receiveEnabled = s.receiveMidiClock
|
||||||
@@ -1021,6 +1144,74 @@ class AppViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Give a Grain Cloud [slot] a source of its own from [bytes] (an uncompressed WAV,
|
||||||
|
* or an SF2/XI's sample). A copy is kept in the preset library's folder and the
|
||||||
|
* slot points at it by path (`sfFile`), so the source comes back after a restart
|
||||||
|
* without saving a preset. Switches SOURCE to "Custom".
|
||||||
|
*/
|
||||||
|
fun loadGrainSample(slot: cc.tiredsysadmin.android.sizzle.model.ToolboxSlot, bytes: ByteArray): Boolean {
|
||||||
|
val sample = cc.tiredsysadmin.android.sizzle.audio.SampleStore.decodeWav(bytes)
|
||||||
|
?: cc.tiredsysadmin.android.sizzle.audio.SoundFontLoader.load(bytes)?.sample
|
||||||
|
?: return false
|
||||||
|
setGrainSample(slot, sample)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Stop the recorder and make the take the Grain Cloud [slot]'s source. */
|
||||||
|
fun stopRecordingIntoGrain(slot: cc.tiredsysadmin.android.sizzle.model.ToolboxSlot) {
|
||||||
|
val sample = recorder.stop()
|
||||||
|
isRecording = false
|
||||||
|
if (sample != null) setGrainSample(slot, sample)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setGrainSample(
|
||||||
|
slot: cc.tiredsysadmin.android.sizzle.model.ToolboxSlot,
|
||||||
|
sample: cc.tiredsysadmin.android.sizzle.audio.SampleStore.Sample,
|
||||||
|
) {
|
||||||
|
storeSlotSample(slot, sample, cc.tiredsysadmin.android.sizzle.model.ToolboxType.GRAIN_CLOUD)
|
||||||
|
slot.set("source", cc.tiredsysadmin.android.sizzle.echofield.EchofieldDefs.CUSTOM)
|
||||||
|
touched()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Keep [sample] as [slot]'s own sound: a WAV copy in [type]'s preset folder, the
|
||||||
|
* slot pointing at it by id (`sfSample`) and path (`sfFile`). Returns the id. */
|
||||||
|
private fun storeSlotSample(
|
||||||
|
slot: cc.tiredsysadmin.android.sizzle.model.ToolboxSlot,
|
||||||
|
sample: cc.tiredsysadmin.android.sizzle.audio.SampleStore.Sample,
|
||||||
|
type: cc.tiredsysadmin.android.sizzle.model.ToolboxType,
|
||||||
|
): String {
|
||||||
|
val store = cc.tiredsysadmin.android.sizzle.audio.SampleStore
|
||||||
|
val dir = java.io.File(presetLibrary.typeDir(type), "sources").apply { mkdirs() }
|
||||||
|
val file = java.io.File(dir, "source-${System.currentTimeMillis()}.wav")
|
||||||
|
runCatching { file.writeBytes(store.encodeWav(sample)) }
|
||||||
|
val id = "file:" + file.absolutePath
|
||||||
|
store.put(id, sample)
|
||||||
|
slot.set("sfSample", id)
|
||||||
|
if (file.exists()) slot.set("sfFile", file.absolutePath)
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a wavetable WAV into Wavetable [slot]: Serum's (its `clm ` chunk gives the
|
||||||
|
* frame length), WaveEdit's (64 x 256) or any file of power-of-two frames. The
|
||||||
|
* table is built here (off the audio thread) and oscillator 1 switches to it.
|
||||||
|
*/
|
||||||
|
fun loadWavetable(slot: cc.tiredsysadmin.android.sizzle.model.ToolboxSlot, bytes: ByteArray): Boolean {
|
||||||
|
val tables = cc.tiredsysadmin.android.sizzle.wavetable.WaveTables
|
||||||
|
val defs = cc.tiredsysadmin.android.sizzle.wavetable.WaveDefs
|
||||||
|
val sample = cc.tiredsysadmin.android.sizzle.audio.SampleStore.decodeWav(bytes) ?: return false
|
||||||
|
if (sample.data.size < 64) return false
|
||||||
|
val frameLen = tables.detectFrameLength(bytes, sample.data.size)
|
||||||
|
val label = frameLen.toString().takeIf { it in defs.FRAME_SIZES } ?: defs.FRAME_SIZES[0]
|
||||||
|
val id = storeSlotSample(slot, sample, cc.tiredsysadmin.android.sizzle.model.ToolboxType.WAVETABLE)
|
||||||
|
slot.set("wtframe", label)
|
||||||
|
tables.buildForSample(id, label.toIntOrNull() ?: 0)
|
||||||
|
slot.set("o1table", tables.CUSTOM)
|
||||||
|
touched()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
/** Point an LFO slot at another device's parameter, capturing that param's
|
/** Point an LFO slot at another device's parameter, capturing that param's
|
||||||
* current value as the modulation centre. Pass targetSlotIndex < 0 to clear. */
|
* current value as the modulation centre. Pass targetSlotIndex < 0 to clear. */
|
||||||
fun setLfoTarget(
|
fun setLfoTarget(
|
||||||
@@ -1070,8 +1261,7 @@ class AppViewModel(
|
|||||||
* look like a `.sng` (so the caller can surface a popup) rather than silently
|
* look like a `.sng` (so the caller can surface a popup) rather than silently
|
||||||
* wiping the song with garbage. */
|
* wiping the song with garbage. */
|
||||||
fun importSng(text: String): Boolean {
|
fun importSng(text: String): Boolean {
|
||||||
val looksLikeSng = Regex("(?m)^\\s*(version|bpm|sig|block)\\b").containsMatchIn(text)
|
if (!cc.tiredsysadmin.android.sizzle.io.SngFormat.looksLikeSng(text)) return false
|
||||||
if (!looksLikeSng) return false
|
|
||||||
runCatching {
|
runCatching {
|
||||||
cc.tiredsysadmin.android.sizzle.io.SngFormat.importInto(project, text)
|
cc.tiredsysadmin.android.sizzle.io.SngFormat.importInto(project, text)
|
||||||
}.getOrElse { return false }
|
}.getOrElse { return false }
|
||||||
@@ -1215,6 +1405,32 @@ class AppViewModel(
|
|||||||
return ok
|
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. */
|
/** 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 {
|
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()
|
val isZip = bytes.size >= 2 && bytes[0] == 'P'.code.toByte() && bytes[1] == 'K'.code.toByte()
|
||||||
|
|||||||
@@ -53,11 +53,17 @@ fun Knob(
|
|||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
default: Float = min,
|
default: Float = min,
|
||||||
knobSize: Dp = 44.dp,
|
knobSize: Dp = 44.dp,
|
||||||
|
/** Arc colour; the theme's accent when null (device panels tint it by section). */
|
||||||
|
color: androidx.compose.ui.graphics.Color? = null,
|
||||||
|
/** Fill the arc from zero (12 o'clock for a symmetric range) instead of from [min]. */
|
||||||
|
bipolar: Boolean = false,
|
||||||
onChange: (Float) -> Unit,
|
onChange: (Float) -> Unit,
|
||||||
) {
|
) {
|
||||||
val c = LocalRetro.current
|
val c = LocalRetro.current
|
||||||
|
val arc = color ?: c.accent
|
||||||
val span = if (max > min) max - min else 1f
|
val span = if (max > min) max - min else 1f
|
||||||
val frac = ((value - min) / span).coerceIn(0f, 1f)
|
val frac = ((value - min) / span).coerceIn(0f, 1f)
|
||||||
|
val zero = ((0f - min) / span).coerceIn(0f, 1f)
|
||||||
// Latest value seen without restarting the drag gesture, so a relative drag starts
|
// Latest value seen without restarting the drag gesture, so a relative drag starts
|
||||||
// from wherever the knob currently sits.
|
// from wherever the knob currently sits.
|
||||||
val currentValue by rememberUpdatedState(value)
|
val currentValue by rememberUpdatedState(value)
|
||||||
@@ -104,7 +110,9 @@ fun Knob(
|
|||||||
style = androidx.compose.ui.graphics.drawscope.Stroke(width = stroke),
|
style = androidx.compose.ui.graphics.drawscope.Stroke(width = stroke),
|
||||||
)
|
)
|
||||||
drawArc(
|
drawArc(
|
||||||
color = c.accent, startAngle = start, sweepAngle = sweep * frac, useCenter = false,
|
color = arc,
|
||||||
|
startAngle = if (bipolar) start + sweep * zero else start,
|
||||||
|
sweepAngle = if (bipolar) sweep * (frac - zero) else sweep * frac, useCenter = false,
|
||||||
topLeft = Offset(cx - r, cy - r), size = androidx.compose.ui.geometry.Size(r * 2, r * 2),
|
topLeft = Offset(cx - r, cy - r), size = androidx.compose.ui.geometry.Size(r * 2, r * 2),
|
||||||
style = androidx.compose.ui.graphics.drawscope.Stroke(width = stroke),
|
style = androidx.compose.ui.graphics.drawscope.Stroke(width = stroke),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,9 +3,11 @@
|
|||||||
|
|
||||||
package cc.tiredsysadmin.android.sizzle.ui.components
|
package cc.tiredsysadmin.android.sizzle.ui.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.border
|
import androidx.compose.foundation.border
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.combinedClickable
|
||||||
import androidx.compose.foundation.gestures.awaitEachGesture
|
import androidx.compose.foundation.gestures.awaitEachGesture
|
||||||
import androidx.compose.foundation.gestures.awaitFirstDown
|
import androidx.compose.foundation.gestures.awaitFirstDown
|
||||||
import androidx.compose.foundation.gestures.waitForUpOrCancellation
|
import androidx.compose.foundation.gestures.waitForUpOrCancellation
|
||||||
@@ -27,7 +29,9 @@ import androidx.compose.runtime.setValue
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||||
import androidx.compose.ui.input.pointer.pointerInput
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
|
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||||
import androidx.compose.ui.text.font.FontFamily
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
@@ -142,6 +146,7 @@ private const val REPEAT_MIN_MS = 24L
|
|||||||
private const val REPEAT_DECAY = 0.80
|
private const val REPEAT_DECAY = 0.80
|
||||||
|
|
||||||
/** A labelled dropdown selector rendered as `LABEL:value ▾`. */
|
/** A labelled dropdown selector rendered as `LABEL:value ▾`. */
|
||||||
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun <T> RetroDropdown(
|
fun <T> RetroDropdown(
|
||||||
label: String,
|
label: String,
|
||||||
@@ -149,9 +154,13 @@ fun <T> RetroDropdown(
|
|||||||
selected: T,
|
selected: T,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
optionLabel: (T) -> String = { it.toString() },
|
optionLabel: (T) -> String = { it.toString() },
|
||||||
|
/** Optional long-press action (e.g. the mixer's "open this device's settings");
|
||||||
|
* a tap still opens the menu. */
|
||||||
|
onLongClick: (() -> Unit)? = null,
|
||||||
onSelect: (T) -> Unit,
|
onSelect: (T) -> Unit,
|
||||||
) {
|
) {
|
||||||
val c = LocalRetro.current
|
val c = LocalRetro.current
|
||||||
|
val haptics = LocalHapticFeedback.current
|
||||||
var open by remember { mutableStateOf(false) }
|
var open by remember { mutableStateOf(false) }
|
||||||
// Reserve the width of the longest option so the field never resizes as the
|
// Reserve the width of the longest option so the field never resizes as the
|
||||||
// selection changes — a common source of toolbar "jitter".
|
// selection changes — a common source of toolbar "jitter".
|
||||||
@@ -164,7 +173,13 @@ fun <T> RetroDropdown(
|
|||||||
Modifier
|
Modifier
|
||||||
.border(1.dp, c.grid, RectangleShape)
|
.border(1.dp, c.grid, RectangleShape)
|
||||||
.background(c.surface)
|
.background(c.surface)
|
||||||
.clickable { open = true }
|
.then(
|
||||||
|
if (onLongClick == null) Modifier.clickable { open = true }
|
||||||
|
else Modifier.combinedClickable(
|
||||||
|
onClick = { open = true },
|
||||||
|
onLongClick = { haptics.performHapticFeedback(HapticFeedbackType.LongPress); onLongClick() },
|
||||||
|
),
|
||||||
|
)
|
||||||
.padding(horizontal = 8.dp, vertical = 6.dp),
|
.padding(horizontal = 8.dp, vertical = 6.dp),
|
||||||
) {
|
) {
|
||||||
// Invisible sizer (longest option) fixes the width; the visible value
|
// Invisible sizer (longest option) fixes the width; the visible value
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ import cc.tiredsysadmin.android.sizzle.model.MixerChannel
|
|||||||
import cc.tiredsysadmin.android.sizzle.model.Pattern
|
import cc.tiredsysadmin.android.sizzle.model.Pattern
|
||||||
import cc.tiredsysadmin.android.sizzle.model.ToolboxKind
|
import cc.tiredsysadmin.android.sizzle.model.ToolboxKind
|
||||||
import cc.tiredsysadmin.android.sizzle.ui.AppViewModel
|
import cc.tiredsysadmin.android.sizzle.ui.AppViewModel
|
||||||
|
import cc.tiredsysadmin.android.sizzle.ui.TAB_MIX
|
||||||
import cc.tiredsysadmin.android.sizzle.ui.isLandscape
|
import cc.tiredsysadmin.android.sizzle.ui.isLandscape
|
||||||
import cc.tiredsysadmin.android.sizzle.ui.components.RepeatButton
|
import cc.tiredsysadmin.android.sizzle.ui.components.RepeatButton
|
||||||
import cc.tiredsysadmin.android.sizzle.ui.components.RetroButton
|
import cc.tiredsysadmin.android.sizzle.ui.components.RetroButton
|
||||||
@@ -147,7 +148,7 @@ private fun RecordToolbar(vm: AppViewModel) {
|
|||||||
val status = when {
|
val status = when {
|
||||||
recording -> "recording…"
|
recording -> "recording…"
|
||||||
vm.recordDirUri == null -> "pick a folder to record"
|
vm.recordDirUri == null -> "pick a folder to record"
|
||||||
vm.recordArmed -> "armed — starts on play"
|
vm.recordArmed -> "armed — starts on play or MIDI clock start"
|
||||||
vm.lastRecordingName != null -> "saved ${vm.lastRecordingName}"
|
vm.lastRecordingName != null -> "saved ${vm.lastRecordingName}"
|
||||||
else -> "master → WAV"
|
else -> "master → WAV"
|
||||||
}
|
}
|
||||||
@@ -215,6 +216,8 @@ private fun ColumnScope.ChannelRouting(vm: AppViewModel, channel: MixerChannel)
|
|||||||
options = listOf(-1) + instrumentSlots.map { it.index },
|
options = listOf(-1) + instrumentSlots.map { it.index },
|
||||||
selected = channel.instrumentSlot,
|
selected = channel.instrumentSlot,
|
||||||
optionLabel = { idx -> if (idx < 0) "—" else "${idx + 1}:${toolbox[idx].name}" },
|
optionLabel = { idx -> if (idx < 0) "—" else "${idx + 1}:${toolbox[idx].name}" },
|
||||||
|
// Long press: open the assigned instrument's settings in the Toolbox.
|
||||||
|
onLongClick = { if (channel.instrumentSlot >= 0) vm.openSlotEditor(channel.instrumentSlot, returnTab = TAB_MIX) },
|
||||||
onSelect = { channel.instrumentSlot = it; vm.bumpForToolbar() },
|
onSelect = { channel.instrumentSlot = it; vm.bumpForToolbar() },
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
)
|
)
|
||||||
@@ -226,6 +229,8 @@ private fun ColumnScope.ChannelRouting(vm: AppViewModel, channel: MixerChannel)
|
|||||||
options = listOf(-1) + effectSlots.map { it.index },
|
options = listOf(-1) + effectSlots.map { it.index },
|
||||||
selected = channel.fxSlots[fx],
|
selected = channel.fxSlots[fx],
|
||||||
optionLabel = { idx -> if (idx < 0) "—" else "${idx + 1}:${toolbox[idx].name}" },
|
optionLabel = { idx -> if (idx < 0) "—" else "${idx + 1}:${toolbox[idx].name}" },
|
||||||
|
// Long press: open this effect's settings in the Toolbox.
|
||||||
|
onLongClick = { if (channel.fxSlots[fx] >= 0) vm.openSlotEditor(channel.fxSlots[fx], returnTab = TAB_MIX) },
|
||||||
onSelect = { channel.fxSlots[fx] = it; vm.rebuildAudioRouting() },
|
onSelect = { channel.fxSlots[fx] = it; vm.rebuildAudioRouting() },
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import androidx.compose.foundation.layout.padding
|
|||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.material.icons.Icons
|
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.ChevronRight
|
||||||
import androidx.compose.material.icons.filled.Piano
|
import androidx.compose.material.icons.filled.Piano
|
||||||
import androidx.compose.material.icons.filled.ContentCopy
|
import androidx.compose.material.icons.filled.ContentCopy
|
||||||
@@ -52,6 +52,7 @@ import androidx.compose.material3.Switch
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
@@ -169,7 +170,7 @@ fun SettingsScreen(vm: AppViewModel) {
|
|||||||
@Composable
|
@Composable
|
||||||
private fun SubHeader(title: String, onBack: () -> Unit) {
|
private fun SubHeader(title: String, onBack: () -> Unit) {
|
||||||
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
|
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)
|
Text(title, style = MaterialTheme.typography.titleMedium, color = MaterialTheme.colorScheme.primary)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -503,7 +504,7 @@ private fun openUrl(context: Context, url: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** MIDI clock sync over USB + Bluetooth: drive external gear, or follow an external
|
/** MIDI clock sync over USB + Bluetooth: drive external gear, or follow an external
|
||||||
* clock. Both off by default. */
|
* clock. Both off by default. Also the background sound-module switch. */
|
||||||
@Composable
|
@Composable
|
||||||
private fun MidiSyncCard(vm: AppViewModel) {
|
private fun MidiSyncCard(vm: AppViewModel) {
|
||||||
@Suppress("UNUSED_VARIABLE") val rev = vm.revision
|
@Suppress("UNUSED_VARIABLE") val rev = vm.revision
|
||||||
@@ -517,9 +518,144 @@ private fun MidiSyncCard(vm: AppViewModel) {
|
|||||||
HorizontalDivider()
|
HorizontalDivider()
|
||||||
ToggleRow(
|
ToggleRow(
|
||||||
"Receive MIDI clock",
|
"Receive MIDI clock",
|
||||||
"Follow an external clock's tempo, and start/stop with it.",
|
"Follow an external clock's tempo, and start/stop Sizzle's own song with it " +
|
||||||
|
"(tempo only while Sizzle runs as a MIDI sound module).",
|
||||||
vm.receiveMidiClock,
|
vm.receiveMidiClock,
|
||||||
) { vm.updateReceiveMidiClock(it) }
|
) { vm.updateReceiveMidiClock(it) }
|
||||||
|
HorizontalDivider()
|
||||||
|
val module by vm.soundModuleMode.collectAsState()
|
||||||
|
ToggleRow(
|
||||||
|
"Keep running as MIDI sound module",
|
||||||
|
"Keep playing incoming MIDI with Sizzle in the background (another app can " +
|
||||||
|
"use it as its synth), with a notification while on. Sizzle's own song " +
|
||||||
|
"doesn't start from the other app's clock meanwhile.",
|
||||||
|
module,
|
||||||
|
) { vm.updateSoundModuleMode(it) }
|
||||||
|
HorizontalDivider()
|
||||||
|
MidiInputsList(vm)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The MIDI sources Sizzle can listen to (controllers, other apps' virtual ports),
|
||||||
|
* each with a switch, plus Reconnect for a source whose app restarted. */
|
||||||
|
@Composable
|
||||||
|
private fun MidiInputsList(vm: AppViewModel) {
|
||||||
|
val sources by vm.midiInputSources.collectAsState()
|
||||||
|
Row(
|
||||||
|
Modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
Column(Modifier.weight(1f)) {
|
||||||
|
Text("MIDI inputs", style = MaterialTheme.typography.bodyMedium)
|
||||||
|
Text(
|
||||||
|
"Sources Sizzle listens to. Each mixer track plays the notes on its MIDI channel.",
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
OutlinedButton(onClick = { vm.reconnectMidi() }) { Text("Reconnect") }
|
||||||
|
}
|
||||||
|
if (sources.isEmpty()) {
|
||||||
|
Text(
|
||||||
|
"No MIDI sources found.",
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
for (src in sources) {
|
||||||
|
ToggleRow(
|
||||||
|
src.name,
|
||||||
|
when {
|
||||||
|
!src.enabled -> "Off"
|
||||||
|
src.connected -> "Listening"
|
||||||
|
else -> "Not connected (tap Reconnect)"
|
||||||
|
},
|
||||||
|
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") }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -549,6 +685,12 @@ private fun InterfaceCard(vm: AppViewModel) {
|
|||||||
"Show live level meters inside the mixer volume faders.",
|
"Show live level meters inside the mixer volume faders.",
|
||||||
vm.vuMeters,
|
vm.vuMeters,
|
||||||
) { vm.updateVuMeters(it) }
|
) { 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) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import androidx.compose.ui.text.font.FontFamily
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import cc.tiredsysadmin.android.sizzle.model.DelayDivisions
|
import cc.tiredsysadmin.android.sizzle.model.DelayDivisions
|
||||||
import cc.tiredsysadmin.android.sizzle.model.ParamSpec
|
|
||||||
import cc.tiredsysadmin.android.sizzle.model.ToolboxSlot
|
import cc.tiredsysadmin.android.sizzle.model.ToolboxSlot
|
||||||
import cc.tiredsysadmin.android.sizzle.ui.AppViewModel
|
import cc.tiredsysadmin.android.sizzle.ui.AppViewModel
|
||||||
import cc.tiredsysadmin.android.sizzle.ui.theme.LocalRetro
|
import cc.tiredsysadmin.android.sizzle.ui.theme.LocalRetro
|
||||||
@@ -35,7 +34,7 @@ import cc.tiredsysadmin.android.sizzle.ui.theme.LocalRetro
|
|||||||
* The Tape Delay's custom editor: four tape heads side by side, each a vertical
|
* The Tape Delay's custom editor: four tape heads side by side, each a vertical
|
||||||
* tempo-synced division fader (hard-snapping to the [DelayDivisions] steps —
|
* tempo-synced division fader (hard-snapping to the [DelayDivisions] steps —
|
||||||
* 1/1 … 1/16 plus dotted and triplet values) with an on/off toggle above it, then
|
* 1/1 … 1/16 plus dotted and triplet values) with an on/off toggle above it, then
|
||||||
* the shared Feedback / Dry-Wet / Tape-Strength sliders below. Feedback is capped
|
* the shared Feedback / Dry-Wet / Tape-Strength knobs below. Feedback is capped
|
||||||
* below 1 in both the UI and the DSP, so it can never build a runaway loop.
|
* below 1 in both the UI and the DSP, so it can never build a runaway loop.
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
@@ -53,11 +52,10 @@ fun DelayEditor(vm: AppViewModel, slot: ToolboxSlot) {
|
|||||||
DelayHead(vm, slot, h, rev, Modifier.weight(1f))
|
DelayHead(vm, slot, h, rev, Modifier.weight(1f))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Common controls (left as plain sliders with sane defaults). Feedback's max
|
// Common controls. Feedback's max is the DSP's hard ceiling (its ParamSpec),
|
||||||
// is the DSP's hard ceiling, so a positive-feedback runaway is impossible.
|
// so a positive-feedback runaway is impossible.
|
||||||
ParamControl(vm, slot, ParamSpec("feedback", "Feedback", 0.4f, 0f, DelayDivisions.MAX_FEEDBACK))
|
PanelCard(vm, slot, Panel("Loop", Tone.OUT, listOf("feedback", "drywet", "tape"),
|
||||||
ParamControl(vm, slot, ParamSpec("drywet", "Dry/Wet", 0.35f, 0f, 1f))
|
labels = mapOf("drywet" to "Mix", "tape" to "Tape")))
|
||||||
ParamControl(vm, slot, ParamSpec("tape", "Tape Strength", 0.3f, 0f, 1f))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,141 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
package cc.tiredsysadmin.android.sizzle.ui.toolbox
|
||||||
|
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.ToolboxType
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How each device's controls are grouped into cards and tabs (see Panels.kt). The
|
||||||
|
* Synth, Sampler, SF2/XI loader, Tape Delay, Tape Engine, Mix Tightener and
|
||||||
|
* Granular Glitch have editors of their own and aren't listed. A device missing
|
||||||
|
* here gets one card holding all its parameters, so a new device still has an editor.
|
||||||
|
*/
|
||||||
|
object DeviceLayouts {
|
||||||
|
|
||||||
|
private val ADSR = Viz.Envelope("attack", "decay", "sustain", "release")
|
||||||
|
private val AR = Viz.Envelope("attack", null, null, "release")
|
||||||
|
|
||||||
|
fun pagesFor(type: ToolboxType): List<Page> = when (type) {
|
||||||
|
ToolboxType.WAVETABLE -> listOf(
|
||||||
|
// 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")),
|
||||||
|
)),
|
||||||
|
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("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")),
|
||||||
|
)),
|
||||||
|
Page("LFO", listOf(
|
||||||
|
Panel("LFO", Tone.MOD, listOf("lfowave", "lfodiv", "lfopos", "lfopitch", "lfocut"),
|
||||||
|
Viz.Lfo("lfowave"), labels = mapOf("lfodiv" to "Sync")),
|
||||||
|
)),
|
||||||
|
)
|
||||||
|
|
||||||
|
ToolboxType.MORPH_PAD -> listOf(
|
||||||
|
Page("Sound", listOf(
|
||||||
|
Panel("Layer mix", Tone.SOURCE, listOf("choir", "partials", "breath", "timbre", "warmth", "body")),
|
||||||
|
Panel("Envelope", Tone.ENV, listOf("attack", "release", "velsens"), AR),
|
||||||
|
)),
|
||||||
|
Page("Morph", listOf(
|
||||||
|
Panel("Morph", Tone.MOD, listOf(FrasilDefs.MORPH_TO, FrasilDefs.MORPH, FrasilDefs.MORPH_TIME),
|
||||||
|
labels = mapOf(FrasilDefs.MORPH_TIME to "Time")),
|
||||||
|
Panel("Motion", Tone.MOD, listOf("motion", "mrate", "tide", "tperiod"),
|
||||||
|
labels = mapOf("mrate" to "Rate", "tperiod" to "Tide Rate")),
|
||||||
|
)),
|
||||||
|
Page("Choir", listOf(
|
||||||
|
Panel("Choir voices", Tone.SOURCE, listOf("interval", "detune", "shape", "soft")),
|
||||||
|
Panel("Choir filter", Tone.FILTER, listOf("ctype", "cfilter", "creso"),
|
||||||
|
Viz.Filter("ctype", "cfilter", "creso"), labels = mapOf("cfilter" to "Cutoff", "ctype" to "Type")),
|
||||||
|
)),
|
||||||
|
Page("Partials", listOf(
|
||||||
|
Panel("Partials", Tone.SOURCE, listOf("tilt", "odd", "stretch", "evolve", "beat", "formant", "peak")),
|
||||||
|
)),
|
||||||
|
Page("Breath", listOf(
|
||||||
|
Panel("Breath", Tone.SOURCE, listOf("bpitch", "bres", "color", "grain", "btone", "air")),
|
||||||
|
)),
|
||||||
|
)
|
||||||
|
|
||||||
|
ToolboxType.GRAIN_CLOUD -> listOf(
|
||||||
|
Page("Cloud", listOf(
|
||||||
|
Panel("Cloud", Tone.SOURCE, listOf("source", "mode", "position", "texture", "scatter", "drift")),
|
||||||
|
Panel("Play", Tone.OUT, listOf("freeze", "motion", "pitch", "harmony", "level")),
|
||||||
|
)),
|
||||||
|
Page("Grains", listOf(
|
||||||
|
Panel("Grains", Tone.SOURCE, listOf("window", "size_mul", "dens_mul", "scan", "reverse", "grain_tone"),
|
||||||
|
labels = mapOf("window" to "Grain shape")),
|
||||||
|
Panel("Randomness", Tone.MOD, listOf("pitch_rand", "size_rand")),
|
||||||
|
)),
|
||||||
|
Page("Keys", listOf(
|
||||||
|
Panel("Note envelope", Tone.ENV, listOf("attack", "release", "velo"), AR),
|
||||||
|
Panel("Sample region", Tone.SOURCE, listOf("start", "end")),
|
||||||
|
)),
|
||||||
|
)
|
||||||
|
|
||||||
|
ToolboxType.AMBIENCE -> listOf(
|
||||||
|
Page("Space", listOf(
|
||||||
|
Panel("Space", Tone.SOURCE, listOf("algo", "predelay", "roomsize", "decay"), labels = mapOf("algo" to "Algorithm")),
|
||||||
|
Panel("Mix", Tone.OUT, listOf("wet", "dry")),
|
||||||
|
)),
|
||||||
|
Page("Tone", listOf(
|
||||||
|
Panel("Tone", Tone.FILTER, listOf("hfdamp", "lfabsorb", "diffusion")),
|
||||||
|
Panel("Character", Tone.SOURCE, listOf("erlevel", "saturation")),
|
||||||
|
Panel("Modulation", Tone.MOD, listOf("modamt", "modrate")),
|
||||||
|
)),
|
||||||
|
Page("Ducking", listOf(
|
||||||
|
Panel("Ducking", Tone.ENV, listOf("duckamt", "duckthresh", "duckattack", "duckrelease"),
|
||||||
|
labels = mapOf("duckamt" to "Amount", "duckattack" to "Attack", "duckrelease" to "Release")),
|
||||||
|
)),
|
||||||
|
)
|
||||||
|
|
||||||
|
ToolboxType.FILTER -> listOf(Page("Filter", listOf(
|
||||||
|
Panel("Filter", Tone.FILTER, listOf("type", "cutoff", "resonance", "warmth", "envamt"),
|
||||||
|
Viz.Filter("type", "cutoff", "resonance")),
|
||||||
|
Panel("Envelope", Tone.ENV, listOf("attack", "decay", "sustain", "release"), ADSR),
|
||||||
|
)))
|
||||||
|
|
||||||
|
ToolboxType.EQ10 -> listOf(Page("EQ", listOf(
|
||||||
|
Panel("Graphic EQ · dB", Tone.FILTER, (0 until 10).map { "band$it" },
|
||||||
|
faders = listOf("31", "63", "125", "250", "500", "1k", "2k", "4k", "8k", "16k"), faderScale = 12f),
|
||||||
|
)))
|
||||||
|
|
||||||
|
ToolboxType.BITCRUSHER -> listOf(Page("Crush", listOf(
|
||||||
|
Panel("Crusher", Tone.OUT, listOf("bits", "downsample", "drive")),
|
||||||
|
)))
|
||||||
|
|
||||||
|
ToolboxType.ARPEGGIATOR -> listOf(Page("Arp", listOf(
|
||||||
|
Panel("Pattern", Tone.MOD, listOf("mode", "resetbar", "octaves", "division"),
|
||||||
|
labels = mapOf("resetbar" to "Restart every bar", "division" to "Rate")),
|
||||||
|
)))
|
||||||
|
|
||||||
|
ToolboxType.TRANSPOSER -> listOf(Page("Transpose", listOf(
|
||||||
|
Panel("Transpose", Tone.SOURCE, listOf("octaves", "semitones")),
|
||||||
|
)))
|
||||||
|
|
||||||
|
ToolboxType.LFO -> listOf(Page("LFO", listOf(
|
||||||
|
Panel("LFO", Tone.MOD, listOf("wave", "depth", "phase", "division"), Viz.Lfo("wave"),
|
||||||
|
labels = mapOf("division" to "Rate")),
|
||||||
|
)))
|
||||||
|
|
||||||
|
else -> listOf(Page(type.displayName, listOf(Panel(type.displayName, Tone.SOURCE, type.params.map { it.key }))))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun osc(o: Int) = listOf("o${o}table", "o${o}pos", "o${o}level", "o${o}oct", "o${o}semi", "o${o}fine", "o${o}bend")
|
||||||
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
package cc.tiredsysadmin.android.sizzle.ui.toolbox
|
||||||
|
|
||||||
|
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.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
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.geometry.Size
|
||||||
|
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.audio.GrainSources
|
||||||
|
import cc.tiredsysadmin.android.sizzle.audio.SampleStore
|
||||||
|
import cc.tiredsysadmin.android.sizzle.echofield.EchofieldDefs
|
||||||
|
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
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Grain Cloud's source strip: load a WAV (or SF2/XI) or record one as the cloud's
|
||||||
|
* own source, and see the source with its START..END region lit. The settings
|
||||||
|
* themselves are the paged list below it (ToolboxScreen).
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
fun GrainCloudEditor(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
|
||||||
|
val bytes = runCatching { context.contentResolver.openInputStream(uri)?.use { readCapped(it) } }.getOrNull()
|
||||||
|
when {
|
||||||
|
bytes == null -> importError =
|
||||||
|
"Couldn't read the file, or it's larger than ${MAX_IMPORT_BYTES / (1024 * 1024)} MB."
|
||||||
|
!vm.loadGrainSample(slot, bytes) -> importError =
|
||||||
|
"Couldn't load this sound. Supported formats are uncompressed .wav, .sf2 and .xi."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
val start = slot.float("start", 0f)
|
||||||
|
val end = slot.float("end", 1f)
|
||||||
|
|
||||||
|
Column(Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
|
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
|
RetroButton("LOAD WAV") { picker.launch(arrayOf("*/*")) }
|
||||||
|
if (vm.isRecording) {
|
||||||
|
RetroButton("■ STOP REC", active = true) { vm.stopRecordingIntoGrain(slot) }
|
||||||
|
} else {
|
||||||
|
RetroButton("● RECORD") { vm.startRecording() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Text(
|
||||||
|
when {
|
||||||
|
sample == null && custom -> "Source: your own — load or record a sound."
|
||||||
|
sample == null -> "Source: $sourceName (preparing…)"
|
||||||
|
else -> "Source: ${if (custom) "your own" else sourceName} · " +
|
||||||
|
"%.1f s".format(sample.data.size.toFloat() / sample.sampleRate)
|
||||||
|
},
|
||||||
|
color = c.textDim, fontFamily = FontFamily.Monospace, fontSize = 10.sp,
|
||||||
|
)
|
||||||
|
if (sample != null) {
|
||||||
|
val peaks = remember(sample, sample.data.size) { computePeaks(sample.data, 300) }
|
||||||
|
Canvas(Modifier.fillMaxWidth().height(64.dp).background(c.surface)) {
|
||||||
|
val a = minOf(start, end) * size.width
|
||||||
|
val b = maxOf(start, end) * size.width
|
||||||
|
drawRect(c.accent.copy(alpha = 0.18f), Offset(a, 0f), Size(b - a, size.height))
|
||||||
|
val (mins, maxs) = peaks
|
||||||
|
val bw = size.width / mins.size
|
||||||
|
val mid = size.height / 2f
|
||||||
|
for (i in mins.indices) {
|
||||||
|
val x = i * bw
|
||||||
|
drawLine(c.text, Offset(x, mid - maxs[i] * mid), Offset(x, mid - mins[i] * mid), strokeWidth = 1f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
importError?.let { msg ->
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = { importError = null },
|
||||||
|
title = { Text("Import failed") },
|
||||||
|
text = { Text(msg) },
|
||||||
|
confirmButton = { TextButton(onClick = { importError = null }) { Text("OK") } },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,442 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
package cc.tiredsysadmin.android.sizzle.ui.toolbox
|
||||||
|
|
||||||
|
import androidx.compose.foundation.Canvas
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.border
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.gestures.detectDragGestures
|
||||||
|
import androidx.compose.foundation.gestures.detectTapGestures
|
||||||
|
import androidx.compose.foundation.horizontalScroll
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.geometry.Offset
|
||||||
|
import androidx.compose.ui.geometry.Size
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.graphics.Path
|
||||||
|
import androidx.compose.ui.graphics.RectangleShape
|
||||||
|
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||||
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.ParamSpec
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.TimeDivision
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.ToolboxSlot
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.ToolboxType
|
||||||
|
import cc.tiredsysadmin.android.sizzle.ui.AppViewModel
|
||||||
|
import cc.tiredsysadmin.android.sizzle.ui.components.Knob
|
||||||
|
import cc.tiredsysadmin.android.sizzle.ui.components.RetroDropdown
|
||||||
|
import cc.tiredsysadmin.android.sizzle.ui.theme.LocalRetro
|
||||||
|
import java.util.Locale
|
||||||
|
import kotlin.math.PI
|
||||||
|
import kotlin.math.abs
|
||||||
|
import kotlin.math.ceil
|
||||||
|
import kotlin.math.log10
|
||||||
|
import kotlin.math.pow
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
import kotlin.math.sin
|
||||||
|
import kotlin.math.sqrt
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Device panels: the generic instrument / effect editor. A device's parameters are
|
||||||
|
* grouped by what they do into titled cards ([Panel]), each tinted by its role
|
||||||
|
* ([Tone]: sound source, filter, envelope, modulation, output), with knobs for
|
||||||
|
* numbers, segmented switches for short choices, dropdowns for long ones, and a
|
||||||
|
* small live drawing where a picture says more than numbers (an envelope's shape,
|
||||||
|
* a filter's response, an LFO's wave). Devices with many cards split them into
|
||||||
|
* tabbed pages ([Page]). The layouts themselves live in DeviceLayouts.kt.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** A card's role, which picks its colour. */
|
||||||
|
enum class Tone { SOURCE, FILTER, ENV, MOD, OUT }
|
||||||
|
|
||||||
|
/** A live drawing at the top of a card, read from the slot's values by key. */
|
||||||
|
sealed interface Viz {
|
||||||
|
/** ADSR (or AR when [d]/[s] are null) from the four time / level keys. */
|
||||||
|
data class Envelope(val a: String, val d: String?, val s: String?, val r: String) : Viz
|
||||||
|
/** A resonant filter's magnitude response; [type]'s choice picks low / band / high. */
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One titled card of related controls. [labels] overrides a control's short label
|
||||||
|
* (otherwise derived from its [ParamSpec.label]). With [faders] set the card draws
|
||||||
|
* its keys as a bank of vertical bipolar faders captioned by [faders], showing
|
||||||
|
* value × [faderScale] (e.g. a graphic EQ in dB).
|
||||||
|
*/
|
||||||
|
class Panel(
|
||||||
|
val title: String,
|
||||||
|
val tone: Tone,
|
||||||
|
val keys: List<String>,
|
||||||
|
val viz: Viz? = null,
|
||||||
|
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. */
|
||||||
|
class Page(val title: String, val panels: List<Panel>)
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun toneColor(t: Tone): Color {
|
||||||
|
val c = LocalRetro.current
|
||||||
|
return when (t) {
|
||||||
|
Tone.SOURCE -> c.accent
|
||||||
|
Tone.FILTER -> c.playhead
|
||||||
|
Tone.ENV -> Color(0xFFF48FB1)
|
||||||
|
Tone.MOD -> Color(0xFFB39DFF)
|
||||||
|
Tone.OUT -> c.text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The last tab shown per (slot, device), so reopening an editor lands where you left. */
|
||||||
|
private val lastPage = HashMap<Pair<Int, ToolboxType>, Int>()
|
||||||
|
|
||||||
|
/** A device's [pages]: a tab strip when there's more than one, then that page's cards. */
|
||||||
|
@Composable
|
||||||
|
fun DevicePanels(vm: AppViewModel, slot: ToolboxSlot, pages: List<Page>) {
|
||||||
|
val rev = vm.revision
|
||||||
|
val type = slot.type ?: return
|
||||||
|
val memo = slot.index to type
|
||||||
|
var page by remember(slot.index, type) { mutableIntStateOf((lastPage[memo] ?: 0).coerceIn(0, pages.lastIndex)) }
|
||||||
|
Column(Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
|
if (pages.size > 1) PageTabs(pages, page) { page = it; lastPage[memo] = it }
|
||||||
|
for (p in pages[page.coerceIn(0, pages.lastIndex)].panels) PanelCard(vm, slot, p, rev)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun PageTabs(pages: List<Page>, selected: Int, onSelect: (Int) -> Unit) {
|
||||||
|
val c = LocalRetro.current
|
||||||
|
// 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 = 2.dp, vertical = 7.dp),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
|
Text(p.title.uppercase(), color = if (on) tone else c.textDim,
|
||||||
|
fontFamily = FontFamily.Monospace, fontSize = if (pages.size > 5) 10.sp else 12.sp,
|
||||||
|
maxLines = 1, softWrap = false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** One card: header, optional drawing, then choices and knobs (or a fader bank). */
|
||||||
|
@Composable
|
||||||
|
fun PanelCard(vm: AppViewModel, slot: ToolboxSlot, panel: Panel, rev: Int = vm.revision) {
|
||||||
|
@Suppress("UNUSED_PARAMETER") val ignored = rev
|
||||||
|
val c = LocalRetro.current
|
||||||
|
val type = slot.type ?: return
|
||||||
|
val tone = toneColor(panel.tone)
|
||||||
|
val byKey = remember(type) { type.params.associateBy { it.key } }
|
||||||
|
val specs = panel.keys.mapNotNull { byKey[it] }
|
||||||
|
|
||||||
|
Column(
|
||||||
|
Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.border(1.dp, tone.copy(alpha = 0.35f), RectangleShape)
|
||||||
|
.background(c.surface)
|
||||||
|
.padding(horizontal = 8.dp, vertical = 7.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(7.dp),
|
||||||
|
) {
|
||||||
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
|
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, 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (panel.faders != null) {
|
||||||
|
FaderBank(vm, slot, specs, panel, tone, rev)
|
||||||
|
return@Column
|
||||||
|
}
|
||||||
|
|
||||||
|
val enums = specs.filter { it.isEnum }
|
||||||
|
val knobs = specs.filter { !it.isEnum }
|
||||||
|
// Short choices as segmented switches, each on its own row; long ones as
|
||||||
|
// dropdowns, two to a row.
|
||||||
|
val (segmented, dropdowns) = enums.partition { isSegmentable(it) }
|
||||||
|
dropdowns.chunked(2).forEach { row ->
|
||||||
|
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
|
row.forEach { spec ->
|
||||||
|
RetroDropdown(
|
||||||
|
label = shortLabel(spec, panel).uppercase(),
|
||||||
|
options = spec.choices,
|
||||||
|
selected = slot.string(spec.key, spec.choices.first()).let { if (it in spec.choices) it else spec.choices.first() },
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
onSelect = { slot.set(spec.key, it); vm.bumpForToolbar() },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
segmented.forEach { Segmented(vm, slot, it, shortLabel(it, panel), tone, rev) }
|
||||||
|
|
||||||
|
if (knobs.isNotEmpty()) {
|
||||||
|
val n = knobs.size
|
||||||
|
val perRow = if (n <= 6) n else ceil(n / ceil(n / 6.0)).toInt()
|
||||||
|
val slots = maxOf(perRow, 4)
|
||||||
|
knobs.chunked(perRow).forEach { row ->
|
||||||
|
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, rev, Modifier.weight(1f)) }
|
||||||
|
if (pad > 0f) Spacer(Modifier.weight(pad))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------- controls
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
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,
|
||||||
|
valueText = formatParam(spec, value), modifier = modifier, default = spec.default,
|
||||||
|
color = tone, bipolar = spec.min < 0f && spec.max > 0f,
|
||||||
|
) { nv ->
|
||||||
|
slot.set(spec.key, if (spec.isInt) nv.roundToInt().toFloat() else nv)
|
||||||
|
vm.bumpForToolbar()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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, 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)) {
|
||||||
|
Text(label.uppercase(), color = c.textDim, fontFamily = FontFamily.Monospace, fontSize = 9.sp)
|
||||||
|
Row(Modifier.fillMaxWidth().border(1.dp, c.grid, RectangleShape)) {
|
||||||
|
spec.choices.forEach { ch ->
|
||||||
|
val on = ch == cur
|
||||||
|
Box(
|
||||||
|
Modifier
|
||||||
|
.weight(1f)
|
||||||
|
.height(30.dp)
|
||||||
|
.background(if (on) tone.copy(alpha = 0.25f) else Color.Transparent)
|
||||||
|
.border(0.5.dp, if (on) tone else c.grid.copy(alpha = 0.6f), RectangleShape)
|
||||||
|
.clickable { slot.set(spec.key, ch); vm.bumpForToolbar() },
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
|
Text(ch, color = if (on) tone else c.textDim, fontFamily = FontFamily.Monospace,
|
||||||
|
fontSize = 10.sp, maxLines = 1, textAlign = TextAlign.Center)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 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, 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)) {
|
||||||
|
specs.forEachIndexed { i, spec ->
|
||||||
|
val v = slot.float(spec.key, spec.default).coerceIn(spec.min, spec.max)
|
||||||
|
val span = spec.max - spec.min
|
||||||
|
fun setFrom(y: Float, h: Float) {
|
||||||
|
val f = (1f - y / h).coerceIn(0f, 1f)
|
||||||
|
slot.set(spec.key, spec.min + f * span); vm.bumpForToolbar()
|
||||||
|
}
|
||||||
|
Column(Modifier.weight(1f), horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.spacedBy(2.dp)) {
|
||||||
|
val shown = v * panel.faderScale
|
||||||
|
Text((if (shown > 0.05f) "+" else "") + String.format(Locale.US, "%.0f", shown),
|
||||||
|
color = c.text, fontFamily = FontFamily.Monospace, fontSize = 9.sp, maxLines = 1)
|
||||||
|
Canvas(
|
||||||
|
Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.height(140.dp)
|
||||||
|
.background(c.background)
|
||||||
|
.border(1.dp, c.grid, RectangleShape)
|
||||||
|
.pointerInput(spec.key, slot.index) {
|
||||||
|
detectTapGestures(
|
||||||
|
onDoubleTap = { slot.set(spec.key, spec.default); vm.bumpForToolbar() },
|
||||||
|
onTap = { off -> setFrom(off.y, size.height.toFloat()) },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.pointerInput(spec.key, slot.index) {
|
||||||
|
detectDragGestures { ch, _ -> ch.consume(); setFrom(ch.position.y, size.height.toFloat()) }
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
val zeroY = size.height * (1f - (0f - spec.min) / span)
|
||||||
|
val y = size.height * (1f - (v - spec.min) / span)
|
||||||
|
drawLine(c.grid, Offset(0f, zeroY), Offset(size.width, zeroY), strokeWidth = 1f)
|
||||||
|
drawRect(tone.copy(alpha = 0.45f), Offset(0f, minOf(y, zeroY)), Size(size.width, abs(zeroY - y)))
|
||||||
|
drawRect(tone, Offset(0f, y - 2f), Size(size.width, 4f))
|
||||||
|
}
|
||||||
|
Text(captions.getOrElse(i) { "" }, color = c.textDim, fontFamily = FontFamily.Monospace,
|
||||||
|
fontSize = 9.sp, maxLines = 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------- drawings
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
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()
|
||||||
|
when (viz) {
|
||||||
|
is Viz.Envelope -> {
|
||||||
|
// sqrt of each time against its range, so short times stay visible
|
||||||
|
val a = sqrt(frac(viz.a) ?: 0f) + 0.02f
|
||||||
|
val d = if (viz.d != null) sqrt(frac(viz.d) ?: 0f) + 0.02f else 0f
|
||||||
|
val s = if (viz.s != null) num(viz.s) ?: 1f else 1f
|
||||||
|
val r = sqrt(frac(viz.r) ?: 0f) + 0.02f
|
||||||
|
val hold = 0.45f
|
||||||
|
val k = w / (a + d + hold + r)
|
||||||
|
val sy = bottom - (bottom - top) * s
|
||||||
|
path.moveTo(0f, bottom)
|
||||||
|
path.lineTo(a * k, top)
|
||||||
|
path.lineTo((a + d) * k, sy)
|
||||||
|
path.lineTo((a + d + hold) * k, sy)
|
||||||
|
path.lineTo(w, bottom)
|
||||||
|
// key-up marker
|
||||||
|
drawLine(c.grid, Offset((a + d + hold) * k, top), Offset((a + d + hold) * k, bottom), strokeWidth = 1f)
|
||||||
|
}
|
||||||
|
is Viz.Filter -> {
|
||||||
|
val fc = frac(viz.cutoff) ?: 0.5f
|
||||||
|
val q = 0.6f + (frac(viz.reso) ?: 0f) * 9f
|
||||||
|
val kind = choice(viz.type).firstOrNull()?.uppercaseChar() ?: 'L'
|
||||||
|
val octaves = 10f
|
||||||
|
val n = 96
|
||||||
|
for (i in 0..n) {
|
||||||
|
val x = i / n.toFloat()
|
||||||
|
val r = 2.0.pow(((x - fc) * octaves).toDouble())
|
||||||
|
val den = sqrt((1 - r * r).pow(2) + (r / q).pow(2))
|
||||||
|
val mag = when (kind) { 'H' -> r * r / den; 'B' -> (r / q) / den; else -> 1 / den }
|
||||||
|
val db = (20 * log10(mag.coerceAtLeast(1e-4))).toFloat().coerceIn(-30f, 20f)
|
||||||
|
val y = top + (20f - db) / 50f * (bottom - top)
|
||||||
|
if (i == 0) path.moveTo(0f, y) else path.lineTo(x * w, y)
|
||||||
|
}
|
||||||
|
// 0 dB line and the cutoff marker
|
||||||
|
val zeroY = top + 20f / 50f * (bottom - top)
|
||||||
|
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
|
||||||
|
val sh = floatArrayOf(0.6f, -0.3f, 0.9f, -0.8f, 0.2f, -0.5f, 0.75f, -0.1f)
|
||||||
|
for (i in 0..n) {
|
||||||
|
val x = i / n.toFloat()
|
||||||
|
val p = (x * 2f) % 1f
|
||||||
|
val v = when {
|
||||||
|
name.startsWith("tri") -> 1f - 4f * abs(p - 0.5f)
|
||||||
|
name.startsWith("saw") -> 1f - 2f * p
|
||||||
|
name.startsWith("sq") -> if (p < 0.5f) 1f else -1f
|
||||||
|
name.startsWith("s&h") || name.startsWith("sample") -> sh[(x * 8).toInt().coerceAtMost(7)]
|
||||||
|
else -> sin(2 * PI * p).toFloat()
|
||||||
|
}
|
||||||
|
val y = (top + bottom) / 2f - v * (bottom - top) / 2f
|
||||||
|
if (i == 0) path.moveTo(0f, y) else path.lineTo(x * w, y)
|
||||||
|
}
|
||||||
|
drawLine(c.grid, Offset(0f, (top + bottom) / 2f), Offset(w, (top + bottom) / 2f), strokeWidth = 1f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (viz !is Viz.Lfo) {
|
||||||
|
val fill = Path().apply { addPath(path); lineTo(w, h); lineTo(0f, h); close() }
|
||||||
|
drawPath(fill, tone.copy(alpha = 0.15f))
|
||||||
|
}
|
||||||
|
drawPath(path, tone, style = Stroke(width = 3f))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------- labels and values
|
||||||
|
|
||||||
|
private val PREFIX = Regex("^(Osc\\s?\\d|Mod\\d?|LFO|Duck|F\\.)\\s+")
|
||||||
|
private val UNIT = Regex("\\s*\\((dB|ms|s)\\)|\\s+s$")
|
||||||
|
private val TIME_KEYS = setOf("attack", "decay", "release", "mattack", "mdecay", "mrelease", "fatk", "fdec", "frel")
|
||||||
|
private val DIVISION_KEYS = setOf("division", "lfodiv")
|
||||||
|
private val KEY_UNITS = mapOf("predelay" to "ms", "modrate" to "Hz", "mtime" to "s", "loopXfade" to "ms",
|
||||||
|
"pitch" to "st", "pitch_rand" to "st", "semitones" to "st", "o1semi" to "st", "o2semi" to "st",
|
||||||
|
"o1fine" to "ct", "o2fine" to "ct", "roomsize" to "×")
|
||||||
|
|
||||||
|
/** A control's knob caption: the panel's override, else its label without the
|
||||||
|
* section prefix ("Osc1 Level" → "Level", "LFO > Pitch" → "→ Pitch") or unit. */
|
||||||
|
internal fun shortLabel(spec: ParamSpec, panel: Panel): String =
|
||||||
|
panel.labels[spec.key] ?: spec.label.replace(UNIT, "").replace(PREFIX, "").replace(Regex("^.*>\\s*"), "→ ")
|
||||||
|
|
||||||
|
/** How a value reads under its knob: time in ms / s, 0..1 as %, divisions by name. */
|
||||||
|
internal fun formatParam(spec: ParamSpec, v: Float): String {
|
||||||
|
val unit = KEY_UNITS[spec.key]
|
||||||
|
?: when { "(dB)" in spec.label -> "dB"; "(ms)" in spec.label -> "ms"; else -> "" }
|
||||||
|
fun signed(s: String, x: Float) = if (spec.min < 0f && x > 0f) "+$s" else s
|
||||||
|
return when {
|
||||||
|
spec.key in DIVISION_KEYS -> TimeDivision.fromIndex(v.roundToInt()).label
|
||||||
|
spec.isInt -> signed("${v.roundToInt()}", v) + unit
|
||||||
|
spec.key in TIME_KEYS && spec.max > 1f ->
|
||||||
|
if (v < 1f) "${(v * 1000).roundToInt()}ms" else String.format(Locale.US, if (v < 10f) "%.2fs" else "%.1fs", v)
|
||||||
|
unit.isNotEmpty() -> {
|
||||||
|
val f = when { unit == "ms" || unit == "ct" || abs(v) >= 100f -> "%.0f"; unit == "Hz" || unit == "×" -> "%.2f"; else -> "%.1f" }
|
||||||
|
signed(String.format(Locale.US, f, v), v) + unit
|
||||||
|
}
|
||||||
|
spec.min == 0f && spec.max == 1f -> "${(v * 100).roundToInt()}%"
|
||||||
|
spec.min == -1f && spec.max == 1f -> signed("${(v * 100).roundToInt()}", v) + "%"
|
||||||
|
else -> signed(String.format(Locale.US, "%.2f", v), v)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
package cc.tiredsysadmin.android.sizzle.ui.toolbox
|
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.material3.Slider
|
|
||||||
import androidx.compose.material3.SliderDefaults
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.text.font.FontFamily
|
|
||||||
import androidx.compose.ui.unit.sp
|
|
||||||
import cc.tiredsysadmin.android.sizzle.model.ParamSpec
|
|
||||||
import cc.tiredsysadmin.android.sizzle.model.ToolboxSlot
|
|
||||||
import cc.tiredsysadmin.android.sizzle.ui.AppViewModel
|
|
||||||
import cc.tiredsysadmin.android.sizzle.ui.components.RetroDropdown
|
|
||||||
import cc.tiredsysadmin.android.sizzle.ui.theme.LocalRetro
|
|
||||||
import kotlin.math.roundToInt
|
|
||||||
import java.util.Locale
|
|
||||||
|
|
||||||
/**
|
|
||||||
* One editable parameter row. Enumerated params ([ParamSpec.isEnum]) render as a
|
|
||||||
* dropdown; numeric params render as a labelled slider. Reading and writing goes
|
|
||||||
* through the slot's string-typed value map so it stays serialization-friendly.
|
|
||||||
*/
|
|
||||||
@Composable
|
|
||||||
fun ParamControl(vm: AppViewModel, slot: ToolboxSlot, spec: ParamSpec) {
|
|
||||||
val c = LocalRetro.current
|
|
||||||
@Suppress("UNUSED_VARIABLE") val rev = vm.revision // subscribe so sliders/dropdowns refresh
|
|
||||||
if (spec.isEnum) {
|
|
||||||
RetroDropdown(
|
|
||||||
label = spec.label,
|
|
||||||
options = spec.choices,
|
|
||||||
selected = slot.string(spec.key, spec.choices.first()),
|
|
||||||
onSelect = { slot.set(spec.key, it); vm.bumpForToolbar() },
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
val value = slot.float(spec.key, spec.default)
|
|
||||||
// Integer params (e.g. bit depth, semitones, octaves) snap to whole values:
|
|
||||||
// the slider gets one discrete stop per integer, and writes rounded values.
|
|
||||||
val intSteps = if (spec.isInt) ((spec.max - spec.min).toInt() - 1).coerceAtLeast(0) else 0
|
|
||||||
Column(Modifier.fillMaxWidth()) {
|
|
||||||
Row {
|
|
||||||
Text("${spec.label}: ", color = c.textDim,
|
|
||||||
fontFamily = FontFamily.Monospace, fontSize = 11.sp)
|
|
||||||
Text(if (spec.isInt) value.roundToInt().toString() else formatValue(value), color = c.text,
|
|
||||||
fontFamily = FontFamily.Monospace, fontSize = 11.sp)
|
|
||||||
}
|
|
||||||
Slider(
|
|
||||||
value = value.coerceIn(spec.min, spec.max),
|
|
||||||
valueRange = spec.min..spec.max,
|
|
||||||
steps = intSteps,
|
|
||||||
onValueChange = {
|
|
||||||
val v = if (spec.isInt) it.roundToInt().toFloat() else it
|
|
||||||
slot.set(spec.key, v); vm.bumpForToolbar()
|
|
||||||
},
|
|
||||||
colors = SliderDefaults.colors(
|
|
||||||
thumbColor = c.accent, activeTrackColor = c.accent, inactiveTrackColor = c.grid,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun formatValue(v: Float): String =
|
|
||||||
if (v == v.toInt().toFloat()) v.toInt().toString() else String.format(Locale.US, "%.2f", v)
|
|
||||||
@@ -102,6 +102,24 @@ fun SamplerEditor(vm: AppViewModel, slot: ToolboxSlot, pad: Int, onSelectPad: (I
|
|||||||
}
|
}
|
||||||
|
|
||||||
Column(Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
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) -----
|
// ----- Selected pad + source buttons (act on the selected pad) -----
|
||||||
Text(
|
Text(
|
||||||
"Pad ${pad + 1} · ${Pitch.name(SamplerPads.noteFor(pad))}",
|
"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 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
|
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)
|
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()
|
path.close()
|
||||||
return path
|
return path
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import androidx.compose.material3.OutlinedTextField
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.DisposableEffect
|
import androidx.compose.runtime.DisposableEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableIntStateOf
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
@@ -48,11 +49,14 @@ import androidx.compose.runtime.rememberCoroutineScope
|
|||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||||
import androidx.compose.ui.input.pointer.pointerInput
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||||
import androidx.compose.ui.text.font.FontFamily
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
|
import androidx.compose.ui.unit.Dp
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.core.content.FileProvider
|
import androidx.core.content.FileProvider
|
||||||
@@ -73,8 +77,9 @@ import kotlinx.coroutines.launch
|
|||||||
*
|
*
|
||||||
* Bottom half: a stacked two-octave keyboard (one octave per row) for quick testing.
|
* Bottom half: a stacked two-octave keyboard (one octave per row) for quick testing.
|
||||||
*
|
*
|
||||||
* The parameter editor is generated automatically from the device's [ToolboxType]
|
* The parameter editor groups each device's controls into cards and tabs
|
||||||
* parameter list, so new devices need no bespoke UI.
|
* ([DevicePanels], laid out in [DeviceLayouts]); a device missing from the layouts
|
||||||
|
* still gets one card with all its parameters, so new devices need no bespoke UI.
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun ToolboxScreen(vm: AppViewModel) {
|
fun ToolboxScreen(vm: AppViewModel) {
|
||||||
@@ -84,20 +89,37 @@ fun ToolboxScreen(vm: AppViewModel) {
|
|||||||
var editing by remember { mutableStateOf<Int?>(null) }
|
var editing by remember { mutableStateOf<Int?>(null) }
|
||||||
var picking by remember { mutableStateOf<Int?>(null) }
|
var picking by remember { mutableStateOf<Int?>(null) }
|
||||||
var clearing by remember { mutableStateOf<Int?>(null) }
|
var clearing by remember { mutableStateOf<Int?>(null) }
|
||||||
|
// The tab to go back to when the open editor closes: set when another tab (the
|
||||||
|
// mixer's long-press) asked for it, so its settings feel like a pop-up over that tab.
|
||||||
|
var returnTab by remember { mutableStateOf<Int?>(null) }
|
||||||
|
|
||||||
|
vm.slotEditorRequest?.let { req ->
|
||||||
|
LaunchedEffect(req) {
|
||||||
|
picking = null; clearing = null
|
||||||
|
editing = req.index
|
||||||
|
returnTab = req.returnTab
|
||||||
|
vm.consumeSlotEditorRequest()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val closeEditor: () -> Unit = {
|
||||||
|
editing = null
|
||||||
|
returnTab?.let { vm.selectTab(it) }
|
||||||
|
returnTab = null
|
||||||
|
}
|
||||||
|
|
||||||
// Back closes an open device editor / picker / confirm before the app-level handler
|
// Back closes an open device editor / picker / confirm before the app-level handler
|
||||||
// switches tabs.
|
// switches tabs.
|
||||||
BackHandler(enabled = editing != null || picking != null || clearing != null) {
|
BackHandler(enabled = editing != null || picking != null || clearing != null) {
|
||||||
when {
|
when {
|
||||||
clearing != null -> clearing = null
|
clearing != null -> clearing = null
|
||||||
editing != null -> editing = null
|
editing != null -> closeEditor()
|
||||||
else -> picking = null
|
else -> picking = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shared tile gestures (index-based) so both layouts drive the same state.
|
// Shared tile gestures (index-based) so both layouts drive the same state.
|
||||||
// Single tap: pick a device for an empty tile, else open the filled tile's settings.
|
// Single tap: pick a device for an empty tile, else open the filled tile's settings.
|
||||||
val onTapTile: (Int) -> Unit = { i -> if (vm.project.toolbox[i].isEmpty) picking = i else editing = i }
|
val onTapTile: (Int) -> Unit = { i -> returnTab = null; if (vm.project.toolbox[i].isEmpty) picking = i else editing = i }
|
||||||
// Long press: clear a filled tile — but confirm first (it discards the device and
|
// Long press: clear a filled tile — but confirm first (it discards the device and
|
||||||
// its settings, and there's no undo). Long-pressing an empty tile does nothing.
|
// its settings, and there's no undo). Long-pressing an empty tile does nothing.
|
||||||
val onLongPressTile: (Int) -> Unit = { i -> if (!vm.project.toolbox[i].isEmpty) clearing = i }
|
val onLongPressTile: (Int) -> Unit = { i -> if (!vm.project.toolbox[i].isEmpty) clearing = i }
|
||||||
@@ -145,7 +167,7 @@ fun ToolboxScreen(vm: AppViewModel) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
editing?.let { index ->
|
editing?.let { index ->
|
||||||
ParamEditor(vm, vm.project.toolbox[index], onClose = { editing = null })
|
ParamEditor(vm, vm.project.toolbox[index], onClose = closeEditor)
|
||||||
}
|
}
|
||||||
clearing?.let { index ->
|
clearing?.let { index ->
|
||||||
val slot = vm.project.toolbox[index]
|
val slot = vm.project.toolbox[index]
|
||||||
@@ -294,7 +316,8 @@ private fun ParamEditor(vm: AppViewModel, slot: ToolboxSlot, onClose: () -> Unit
|
|||||||
// The SoundFont and synth editors pin an audition keyboard at the bottom (same as
|
// The SoundFont and synth editors pin an audition keyboard at the bottom (same as
|
||||||
// the toolbox / tracker keyboards), so their controls scroll in a weighted region
|
// the toolbox / tracker keyboards), so their controls scroll in a weighted region
|
||||||
// above the keyboard rather than the whole editor scrolling as one.
|
// above the keyboard rather than the whole editor scrolling as one.
|
||||||
val pinnedKeyboard = type == ToolboxType.SOUNDFONT || type == ToolboxType.NES_SYNTH
|
val pinnedKeyboard = type == ToolboxType.SOUNDFONT || type == ToolboxType.NES_SYNTH ||
|
||||||
|
type == ToolboxType.MORPH_PAD || type == ToolboxType.GRAIN_CLOUD || type == ToolboxType.WAVETABLE
|
||||||
// The Sampler pins its 16-pad grid at the bottom in that same region, so the
|
// The Sampler pins its 16-pad grid at the bottom in that same region, so the
|
||||||
// playable pads are the same height as the keyboards across every instrument editor.
|
// playable pads are the same height as the keyboards across every instrument editor.
|
||||||
val pinnedBottom = pinnedKeyboard || type == ToolboxType.SAMPLER
|
val pinnedBottom = pinnedKeyboard || type == ToolboxType.SAMPLER
|
||||||
@@ -303,12 +326,24 @@ private fun ParamEditor(vm: AppViewModel, slot: ToolboxSlot, onClose: () -> Unit
|
|||||||
// Whether the MIDI-learn popup (map controls to this device's parameters) is open.
|
// Whether the MIDI-learn popup (map controls to this device's parameters) is open.
|
||||||
var showMidiLearn by remember(slot.index) { mutableStateOf(false) }
|
var showMidiLearn by remember(slot.index) { mutableStateOf(false) }
|
||||||
|
|
||||||
Box(Modifier.fillMaxSize().background(c.background.copy(alpha = 0.96f))) {
|
// The playable part pinned beside the controls: the Sampler's pads, else an
|
||||||
Column(Modifier.fillMaxSize()) {
|
// 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()
|
||||||
|
|
||||||
|
// Header, presets and the device's own controls (scrolls on its own).
|
||||||
|
val controls: @Composable (Modifier) -> Unit = { mod ->
|
||||||
Column(
|
Column(
|
||||||
Modifier
|
Modifier
|
||||||
.weight(if (pinnedBottom) 1.7f else 1f)
|
.then(mod)
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(12.dp)
|
.padding(12.dp)
|
||||||
.verticalScroll(rememberScrollState()),
|
.verticalScroll(rememberScrollState()),
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
@@ -327,10 +362,10 @@ private fun ParamEditor(vm: AppViewModel, slot: ToolboxSlot, onClose: () -> Unit
|
|||||||
// Preset browser: load / save / import / share for this device.
|
// Preset browser: load / save / import / share for this device.
|
||||||
PresetBar(vm, slot)
|
PresetBar(vm, slot)
|
||||||
|
|
||||||
// The Sampler / SoundFont / Delay get bespoke editors; the reverb has so
|
// The Synth / Sampler / SoundFont / Delay / tape and glitch effects have
|
||||||
// many controls it's paged (swipeable sections with dot pagination); the
|
// bespoke editors; everything else is grouped cards ([DevicePanels]), with
|
||||||
// LFO adds a modulation-target picker; everything else uses the
|
// a source strip on top for the Grain Cloud and the LFO's
|
||||||
// auto-generated parameter list, laid out two-per-row to fit more.
|
// target picker below.
|
||||||
when (type) {
|
when (type) {
|
||||||
ToolboxType.NES_SYNTH -> NesSynthEditor(vm, slot)
|
ToolboxType.NES_SYNTH -> NesSynthEditor(vm, slot)
|
||||||
ToolboxType.MIX_TIGHTENER -> MixTightenerEditor(vm, slot)
|
ToolboxType.MIX_TIGHTENER -> MixTightenerEditor(vm, slot)
|
||||||
@@ -339,21 +374,32 @@ private fun ParamEditor(vm: AppViewModel, slot: ToolboxSlot, onClose: () -> Unit
|
|||||||
ToolboxType.SAMPLER -> SamplerEditor(vm, slot, samplerPad, onSelectPad = { samplerPad = it })
|
ToolboxType.SAMPLER -> SamplerEditor(vm, slot, samplerPad, onSelectPad = { samplerPad = it })
|
||||||
ToolboxType.SOUNDFONT -> SoundFontEditor(vm, slot)
|
ToolboxType.SOUNDFONT -> SoundFontEditor(vm, slot)
|
||||||
ToolboxType.DELAY -> DelayEditor(vm, slot)
|
ToolboxType.DELAY -> DelayEditor(vm, slot)
|
||||||
ToolboxType.AMBIENCE -> AmbiencePager(vm, slot)
|
ToolboxType.GRAIN_CLOUD -> {
|
||||||
|
GrainCloudEditor(vm, slot)
|
||||||
|
DevicePanels(vm, slot, DeviceLayouts.pagesFor(type))
|
||||||
|
}
|
||||||
ToolboxType.LFO -> {
|
ToolboxType.LFO -> {
|
||||||
ParamGrid(vm, slot, type.params)
|
DevicePanels(vm, slot, DeviceLayouts.pagesFor(type))
|
||||||
LfoTargetPicker(vm, slot)
|
LfoTargetPicker(vm, slot)
|
||||||
}
|
}
|
||||||
else -> ParamGrid(vm, slot, type.params)
|
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) {
|
if (pinnedBottom) {
|
||||||
Box(Modifier.fillMaxWidth().height(2.dp).background(c.accent)) // fixed divider
|
Box(Modifier.fillMaxWidth().height(2.dp).background(c.accent)) // fixed divider
|
||||||
if (type == ToolboxType.SAMPLER) {
|
pinned(Modifier.weight(1f))
|
||||||
SamplerPadBank(vm, slot, samplerPad, onSelect = { samplerPad = it }, Modifier.weight(1f))
|
|
||||||
} else {
|
|
||||||
SlotAuditionKeyboard(vm, slot, Modifier.weight(1f))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -378,6 +424,16 @@ private fun MidiLearnPopup(vm: AppViewModel, slot: ToolboxSlot, onClose: () -> U
|
|||||||
val type = slot.type ?: return
|
val type = slot.type ?: return
|
||||||
// Always disarm learn when the popup leaves the composition (closed / editor exited).
|
// Always disarm learn when the popup leaves the composition (closed / editor exited).
|
||||||
DisposableEffect(slot.index) { onDispose { vm.cancelParamLearn() } }
|
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(
|
Box(
|
||||||
Modifier.fillMaxSize().background(c.background.copy(alpha = 0.92f))
|
Modifier.fillMaxSize().background(c.background.copy(alpha = 0.92f))
|
||||||
@@ -396,10 +452,29 @@ private fun MidiLearnPopup(vm: AppViewModel, slot: ToolboxSlot, onClose: () -> U
|
|||||||
) {
|
) {
|
||||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
|
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
|
||||||
Text("MIDI LEARN — ${slot.name}", color = c.accent,
|
Text("MIDI LEARN — ${slot.name}", color = c.accent,
|
||||||
fontFamily = FontFamily.Monospace, fontSize = 14.sp)
|
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,
|
Text("DONE", color = c.textDim, fontFamily = FontFamily.Monospace, fontSize = 13.sp,
|
||||||
modifier = Modifier.pointerInput(Unit) { detectTapGestures { onClose() } })
|
modifier = Modifier.pointerInput(Unit) { detectTapGestures { onClose() } })
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Text(
|
Text(
|
||||||
"Tap LEARN, then move a knob/fader on your MIDI controller.",
|
"Tap LEARN, then move a knob/fader on your MIDI controller.",
|
||||||
color = c.textDim, fontFamily = FontFamily.Monospace, fontSize = 10.sp,
|
color = c.textDim, fontFamily = FontFamily.Monospace, fontSize = 10.sp,
|
||||||
@@ -437,85 +512,15 @@ private fun MidiLearnPopup(vm: AppViewModel, slot: ToolboxSlot, onClose: () -> U
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
importMessage?.let { msg ->
|
||||||
|
AlertDialog(
|
||||||
/** Lay a list of [params] out two-per-row so the editor fits more controls than a
|
onDismissRequest = { importMessage = null },
|
||||||
* single stacked column. Each [ParamControl] fills its half-width cell (an odd last
|
title = { Text("Import failed") },
|
||||||
* param gets an empty cell beside it). */
|
text = { Text(msg) },
|
||||||
@Composable
|
confirmButton = { TextButton(onClick = { importMessage = null }) { Text("OK") } },
|
||||||
internal fun ParamGrid(vm: AppViewModel, slot: ToolboxSlot, params: List<ParamSpec>) {
|
|
||||||
Column(Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
|
||||||
var i = 0
|
|
||||||
while (i < params.size) {
|
|
||||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
|
||||||
Box(Modifier.weight(1f)) { ParamControl(vm, slot, params[i]) }
|
|
||||||
if (i + 1 < params.size) {
|
|
||||||
Box(Modifier.weight(1f)) { ParamControl(vm, slot, params[i + 1]) }
|
|
||||||
} else {
|
|
||||||
Spacer(Modifier.weight(1f))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
i += 2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The reverb has ~17 controls — too many to stack. They're grouped into labelled
|
|
||||||
* sections shown one page at a time in a swipeable [HorizontalPager] with tappable
|
|
||||||
* dot pagination below. Each page uses the same two-column [ParamGrid]. Works the
|
|
||||||
* same in portrait and landscape (the editor overlay is full-width in both). */
|
|
||||||
@Composable
|
|
||||||
private fun AmbiencePager(vm: AppViewModel, slot: ToolboxSlot) {
|
|
||||||
val c = LocalRetro.current
|
|
||||||
val byKey = (slot.type ?: return).params.associateBy { it.key }
|
|
||||||
val pagerState = rememberPagerState(pageCount = { AMBIENCE_SECTIONS.size })
|
|
||||||
val scope = rememberCoroutineScope()
|
|
||||||
|
|
||||||
Column(Modifier.fillMaxWidth()) {
|
|
||||||
HorizontalPager(
|
|
||||||
state = pagerState,
|
|
||||||
modifier = Modifier.fillMaxWidth().height(210.dp),
|
|
||||||
pageSpacing = 12.dp,
|
|
||||||
) { page ->
|
|
||||||
val section = AMBIENCE_SECTIONS[page]
|
|
||||||
Column(Modifier.fillMaxSize(), verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
|
||||||
Text(
|
|
||||||
section.title, color = c.accent,
|
|
||||||
fontFamily = FontFamily.Monospace, fontSize = 12.sp,
|
|
||||||
)
|
|
||||||
ParamGrid(vm, slot, section.keys.mapNotNull { byKey[it] })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Dot pagination: tap a dot (or swipe the page) to jump to that section.
|
|
||||||
Row(
|
|
||||||
Modifier.fillMaxWidth().padding(top = 8.dp),
|
|
||||||
horizontalArrangement = Arrangement.Center,
|
|
||||||
) {
|
|
||||||
for (i in AMBIENCE_SECTIONS.indices) {
|
|
||||||
val active = i == pagerState.currentPage
|
|
||||||
Box(
|
|
||||||
Modifier
|
|
||||||
.padding(horizontal = 4.dp)
|
|
||||||
.size(if (active) 10.dp else 7.dp)
|
|
||||||
.background(if (active) c.accent else c.grid, CircleShape)
|
|
||||||
.clickable { scope.launch { pagerState.animateScrollToPage(i) } },
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Grouping of the reverb's parameters into swipeable sections. */
|
|
||||||
private class AmbienceSection(val title: String, val keys: List<String>)
|
|
||||||
|
|
||||||
private val AMBIENCE_SECTIONS = listOf(
|
|
||||||
AmbienceSection("Space", listOf("algo", "predelay", "roomsize", "decay")),
|
|
||||||
AmbienceSection("Tone", listOf("hfdamp", "lfabsorb", "diffusion")),
|
|
||||||
AmbienceSection("Modulation", listOf("modamt", "modrate")),
|
|
||||||
AmbienceSection("Character", listOf("erlevel", "saturation")),
|
|
||||||
AmbienceSection("Mix", listOf("wet", "dry")),
|
|
||||||
AmbienceSection("Ducking", listOf("duckamt", "duckthresh", "duckattack", "duckrelease")),
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The preset browser bar shown at the top of every device editor: a dropdown of
|
* The preset browser bar shown at the top of every device editor: a dropdown of
|
||||||
@@ -529,6 +534,7 @@ private val AMBIENCE_SECTIONS = listOf(
|
|||||||
private fun PresetBar(vm: AppViewModel, slot: ToolboxSlot) {
|
private fun PresetBar(vm: AppViewModel, slot: ToolboxSlot) {
|
||||||
val c = LocalRetro.current
|
val c = LocalRetro.current
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
val haptics = LocalHapticFeedback.current
|
||||||
@Suppress("UNUSED_VARIABLE") val rev = vm.revision // refresh the list after save/import
|
@Suppress("UNUSED_VARIABLE") val rev = vm.revision // refresh the list after save/import
|
||||||
val type = slot.type ?: return
|
val type = slot.type ?: return
|
||||||
|
|
||||||
@@ -586,6 +592,16 @@ private fun PresetBar(vm: AppViewModel, slot: ToolboxSlot) {
|
|||||||
RetroButton("DELETE", danger = true) { confirmDelete = current }
|
RetroButton("DELETE", danger = true) { confirmDelete = current }
|
||||||
Spacer(Modifier.width(20.dp))
|
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("SAVE") { showSave = true }
|
||||||
RetroButton("IMPORT") {
|
RetroButton("IMPORT") {
|
||||||
// Accept text presets and (for the Sampler) zip bundles.
|
// Accept text presets and (for the Sampler) zip bundles.
|
||||||
@@ -597,11 +613,6 @@ private fun PresetBar(vm: AppViewModel, slot: ToolboxSlot) {
|
|||||||
vm.presetShareFile(type, name)?.let { sharePresetFile(context, it) }
|
vm.presetShareFile(type, name)?.let { sharePresetFile(context, it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Text(
|
|
||||||
"Presets are plain text, saved per device under the app's storage. " +
|
|
||||||
"Sampler presets carry the sample (shared as a .zip bundle).",
|
|
||||||
color = c.textDim, fontFamily = FontFamily.Monospace, fontSize = 10.sp,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showSave) {
|
if (showSave) {
|
||||||
|
|||||||
@@ -0,0 +1,129 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
package cc.tiredsysadmin.android.sizzle.ui.toolbox
|
||||||
|
|
||||||
|
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.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.theme.LocalRetro
|
||||||
|
import cc.tiredsysadmin.android.sizzle.wavetable.WaveDefs
|
||||||
|
import cc.tiredsysadmin.android.sizzle.wavetable.WaveTables
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 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
|
||||||
|
var importError by remember(slot.index) { mutableStateOf<String?>(null) }
|
||||||
|
val picker = rememberLauncherForActivityResult(ActivityResultContracts.OpenDocument()) { uri ->
|
||||||
|
if (uri == null) return@rememberLauncherForActivityResult
|
||||||
|
val bytes = runCatching { context.contentResolver.openInputStream(uri)?.use { readCapped(it) } }.getOrNull()
|
||||||
|
when {
|
||||||
|
bytes == null -> importError =
|
||||||
|
"Couldn't read the file, or it's larger than ${MAX_IMPORT_BYTES / (1024 * 1024)} MB."
|
||||||
|
!vm.loadWavetable(slot, bytes) -> importError =
|
||||||
|
"Couldn't load this wavetable. Use an uncompressed .wav (Serum, WaveEdit, or frames of 256–2048 samples)."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 },
|
||||||
|
title = { Text("Import failed") },
|
||||||
|
text = { Text(msg) },
|
||||||
|
confirmButton = { TextButton(onClick = { importError = null }) { Text("OK") } },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -119,6 +119,9 @@ fun ArrangementRoll(vm: AppViewModel) {
|
|||||||
// Whether every cell in the selection is already filled (drives FILL vs CLEAR).
|
// Whether every cell in the selection is already filled (drives FILL vs CLEAR).
|
||||||
val selectionAllFilled = hasSelection &&
|
val selectionAllFilled = hasSelection &&
|
||||||
laneRange.all { lane -> beatRange.all { beat -> arr.patternAt(lane, beat) != ArrModel.EMPTY } }
|
laneRange.all { lane -> beatRange.all { beat -> arr.patternAt(lane, beat) != ArrModel.EMPTY } }
|
||||||
|
// …and whether they are all off markers (drives OFF vs CLEAR on that button).
|
||||||
|
val selectionAllOff = hasSelection &&
|
||||||
|
laneRange.all { lane -> beatRange.all { beat -> arr.patternAt(lane, beat) == ArrModel.NOTE_OFF } }
|
||||||
|
|
||||||
val rulerStyle = remember(c) { TextStyle(color = c.textDim, fontFamily = FontFamily.Monospace, fontSize = 9.sp) }
|
val rulerStyle = remember(c) { TextStyle(color = c.textDim, fontFamily = FontFamily.Monospace, fontSize = 9.sp) }
|
||||||
val regionAStyle = remember(c) { TextStyle(color = c.accent, fontFamily = FontFamily.Monospace, fontSize = 9.sp) }
|
val regionAStyle = remember(c) { TextStyle(color = c.accent, fontFamily = FontFamily.Monospace, fontSize = 9.sp) }
|
||||||
@@ -156,6 +159,18 @@ fun ArrangementRoll(vm: AppViewModel) {
|
|||||||
vm.bumpForToolbar()
|
vm.bumpForToolbar()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write (or clear) an off marker across the selection. Same toggle shape as
|
||||||
|
// FILL/CLEAR: a selection that is already all markers clears, anything else is
|
||||||
|
// overwritten with markers — so a block can be replaced by an off in one tap.
|
||||||
|
fun toggleSelectedOff() {
|
||||||
|
if (!hasSelection) return
|
||||||
|
val clear = selectionAllOff
|
||||||
|
for (lane in laneRange) for (beat in beatRange) {
|
||||||
|
arr.set(lane, beat, if (clear) ArrModel.EMPTY else ArrModel.NOTE_OFF)
|
||||||
|
}
|
||||||
|
vm.bumpForToolbar()
|
||||||
|
}
|
||||||
|
|
||||||
fun assignRegion(region: LoopRegion) {
|
fun assignRegion(region: LoopRegion) {
|
||||||
if (!hasSelection) return
|
if (!hasSelection) return
|
||||||
region.start = beatRange.first
|
region.start = beatRange.first
|
||||||
@@ -388,11 +403,15 @@ fun ArrangementRoll(vm: AppViewModel) {
|
|||||||
val laneY = rulerHeightPx + lane * laneH
|
val laneY = rulerHeightPx + lane * laneH
|
||||||
for (beat in firstBeat until lastBeat) {
|
for (beat in firstBeat until lastBeat) {
|
||||||
val x = beat * beatWidthPx
|
val x = beat * beatWidthPx
|
||||||
val filled = arr.patternAt(lane, beat) != ArrModel.EMPTY
|
val slot = arr.patternAt(lane, beat)
|
||||||
val onPlayhead = transport.isPlaying && beat == transport.currentBeat
|
val onPlayhead = transport.isPlaying && beat == transport.currentBeat
|
||||||
val inSel = selBeat0 >= 0 && lane in laneRange && beat in beatRange
|
val inSel = selBeat0 >= 0 && lane in laneRange && beat in beatRange
|
||||||
val fill = when {
|
val fill = when {
|
||||||
filled -> c.accent.copy(alpha = 0.85f)
|
// `danger` is the palette's red slot, which every
|
||||||
|
// scheme defines: an off marker stops the lane, so
|
||||||
|
// it should not read as another block.
|
||||||
|
slot == ArrModel.NOTE_OFF -> c.danger.copy(alpha = 0.85f)
|
||||||
|
slot != ArrModel.EMPTY -> c.accent.copy(alpha = 0.85f)
|
||||||
onPlayhead -> c.playhead.copy(alpha = 0.3f)
|
onPlayhead -> c.playhead.copy(alpha = 0.3f)
|
||||||
inSel -> c.bar
|
inSel -> c.bar
|
||||||
beat % beatsPerBar == 0 -> c.surface
|
beat % beatsPerBar == 0 -> c.surface
|
||||||
@@ -433,7 +452,9 @@ fun ArrangementRoll(vm: AppViewModel) {
|
|||||||
arr = arr,
|
arr = arr,
|
||||||
hasSelection = hasSelection,
|
hasSelection = hasSelection,
|
||||||
selectionAllFilled = selectionAllFilled,
|
selectionAllFilled = selectionAllFilled,
|
||||||
|
selectionAllOff = selectionAllOff,
|
||||||
onToggleCells = { toggleSelectedCells() },
|
onToggleCells = { toggleSelectedCells() },
|
||||||
|
onToggleOff = { toggleSelectedOff() },
|
||||||
onTapA = { if (arr.regionA.isValid) clearRegion(arr.regionA) else assignRegion(arr.regionA) },
|
onTapA = { if (arr.regionA.isValid) clearRegion(arr.regionA) else assignRegion(arr.regionA) },
|
||||||
onTapB = { if (arr.regionB.isValid) clearRegion(arr.regionB) else assignRegion(arr.regionB) },
|
onTapB = { if (arr.regionB.isValid) clearRegion(arr.regionB) else assignRegion(arr.regionB) },
|
||||||
)
|
)
|
||||||
@@ -446,7 +467,9 @@ private fun LoopToolbar(
|
|||||||
arr: ArrModel,
|
arr: ArrModel,
|
||||||
hasSelection: Boolean,
|
hasSelection: Boolean,
|
||||||
selectionAllFilled: Boolean,
|
selectionAllFilled: Boolean,
|
||||||
|
selectionAllOff: Boolean,
|
||||||
onToggleCells: () -> Unit,
|
onToggleCells: () -> Unit,
|
||||||
|
onToggleOff: () -> Unit,
|
||||||
onTapA: () -> Unit,
|
onTapA: () -> Unit,
|
||||||
onTapB: () -> Unit,
|
onTapB: () -> Unit,
|
||||||
) {
|
) {
|
||||||
@@ -466,6 +489,13 @@ private fun LoopToolbar(
|
|||||||
if (selectionAllFilled) "CLEAR" else "FILL",
|
if (selectionAllFilled) "CLEAR" else "FILL",
|
||||||
active = hasSelection, width = 72.dp, onClick = onToggleCells,
|
active = hasSelection, width = 72.dp, onClick = onToggleCells,
|
||||||
)
|
)
|
||||||
|
// Drops an "off" marker across the selection: the playhead reaching one
|
||||||
|
// releases every track of that lane, for cutting a held or looping
|
||||||
|
// instrument without editing the block that started it. Tapping it on a
|
||||||
|
// selection that is already all markers clears them — but the label stays
|
||||||
|
// "OFF" rather than flipping to CLEAR like FILL does, because a marker is
|
||||||
|
// also "filled", so both buttons would have read CLEAR at once.
|
||||||
|
RetroButton("OFF", active = hasSelection, width = 72.dp, onClick = onToggleOff)
|
||||||
RegionControl("A", arr.regionA, onTap = onTapA, vm = vm)
|
RegionControl("A", arr.regionA, onTap = onTapA, vm = vm)
|
||||||
RegionControl("B", arr.regionB, onTap = onTapB, vm = vm)
|
RegionControl("B", arr.regionB, onTap = onTapB, vm = vm)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
package cc.tiredsysadmin.android.sizzle.wavetable
|
||||||
|
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.ParamSpec
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.TimeDivision
|
||||||
|
|
||||||
|
/** The wavetable synth's settings, editor pages and factory presets. */
|
||||||
|
object WaveDefs {
|
||||||
|
|
||||||
|
val TABLES: List<String> = WaveTables.FACTORY_NAMES + WaveTables.CUSTOM
|
||||||
|
val FILTER_TYPES = listOf("Low", "Band", "High")
|
||||||
|
val LFO_WAVES = listOf("Sine", "Tri", "Saw", "Square", "S&H")
|
||||||
|
val FRAME_SIZES = listOf("Auto", "256", "512", "1024", "2048")
|
||||||
|
/** A custom table's WAV lives under the SF2/XI loader's keys, so presets, project
|
||||||
|
* bundles and startup rehydration carry it (see PresetLibrary). */
|
||||||
|
const val SAMPLE_KEY = "sfSample"
|
||||||
|
|
||||||
|
val PARAMS: List<ParamSpec> by lazy {
|
||||||
|
buildList {
|
||||||
|
for (o in 1..2) {
|
||||||
|
add(ParamSpec("o${o}table", "Osc$o Table", choices = TABLES))
|
||||||
|
add(ParamSpec("o${o}pos", "Osc$o Position", if (o == 1) 0f else 0.3f, 0f, 1f))
|
||||||
|
add(ParamSpec("o${o}oct", "Osc$o Oct", 0f, -2f, 2f, isInt = true))
|
||||||
|
add(ParamSpec("o${o}semi", "Osc$o Semi", 0f, -12f, 12f, isInt = true))
|
||||||
|
add(ParamSpec("o${o}fine", "Osc$o Fine", if (o == 1) 0f else 7f, -50f, 50f))
|
||||||
|
add(ParamSpec("o${o}level", "Osc$o Level", if (o == 1) 0.8f else 0f, 0f, 1f))
|
||||||
|
add(ParamSpec("o${o}bend", "Osc$o Bend", 0f, -1f, 1f))
|
||||||
|
}
|
||||||
|
add(ParamSpec("unison", "Unison", 1f, 1f, 4f, isInt = true))
|
||||||
|
add(ParamSpec("spread", "Spread", 0.3f, 0f, 1f))
|
||||||
|
add(ParamSpec("sub", "Sub", 0f, 0f, 1f))
|
||||||
|
add(ParamSpec("noise", "Noise", 0f, 0f, 1f))
|
||||||
|
add(ParamSpec("velsens", "Velocity", 0.5f, 0f, 1f))
|
||||||
|
add(ParamSpec("wtframe", "Frame Size", choices = FRAME_SIZES))
|
||||||
|
add(ParamSpec("ftype", "Filter", choices = FILTER_TYPES))
|
||||||
|
add(ParamSpec("cutoff", "Cutoff", 0.75f, 0f, 1f))
|
||||||
|
add(ParamSpec("reso", "Resonance", 0.15f, 0f, 1f))
|
||||||
|
add(ParamSpec("keytrack", "Key Track", 0.4f, 0f, 1f))
|
||||||
|
add(ParamSpec("fenv", "Env Amount", 0.2f, -1f, 1f))
|
||||||
|
add(ParamSpec("drive", "Drive", 0f, 0f, 1f))
|
||||||
|
add(ParamSpec("attack", "Attack", 0.01f, 0f, 5f))
|
||||||
|
add(ParamSpec("decay", "Decay", 0.3f, 0f, 5f))
|
||||||
|
add(ParamSpec("sustain", "Sustain", 0.8f, 0f, 1f))
|
||||||
|
add(ParamSpec("release", "Release", 0.4f, 0f, 8f))
|
||||||
|
add(ParamSpec("mattack", "Mod Attack", 0.5f, 0f, 10f))
|
||||||
|
add(ParamSpec("mdecay", "Mod Decay", 2f, 0f, 10f))
|
||||||
|
add(ParamSpec("msustain", "Mod Sustain", 0.5f, 0f, 1f))
|
||||||
|
add(ParamSpec("mrelease", "Mod Release", 1f, 0f, 10f))
|
||||||
|
add(ParamSpec("menvpos", "Env > Position", 0.3f, -1f, 1f))
|
||||||
|
add(ParamSpec("lfowave", "LFO Wave", choices = LFO_WAVES))
|
||||||
|
add(ParamSpec("lfodiv", "LFO Sync", 1f, 0f, (TimeDivision.entries.size - 1).toFloat(), isInt = true))
|
||||||
|
add(ParamSpec("lfopos", "LFO > Position", 0.15f, 0f, 1f))
|
||||||
|
add(ParamSpec("lfopitch", "LFO > Pitch", 0f, 0f, 1f))
|
||||||
|
add(ParamSpec("lfocut", "LFO > Cutoff", 0f, 0f, 1f))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class Preset(val name: String, val values: Map<String, String>)
|
||||||
|
|
||||||
|
val FACTORY: List<Preset> by lazy {
|
||||||
|
fun p(name: String, vararg v: Pair<String, Any>): Preset {
|
||||||
|
val m = LinkedHashMap<String, String>()
|
||||||
|
for (spec in PARAMS) m[spec.key] = if (spec.isEnum) spec.choices[0] else spec.default.toString()
|
||||||
|
for ((k, x) in v) m[k] = x.toString()
|
||||||
|
return Preset(name, m)
|
||||||
|
}
|
||||||
|
listOf(
|
||||||
|
p("Morph Lead", "o1table" to "Classic", "o1pos" to 0.4f, "menvpos" to 0.5f, "mattack" to 0.01f, "mdecay" to 0.8f, "msustain" to 0.2f,
|
||||||
|
"cutoff" to 0.8f, "reso" to 0.25f, "lfopitch" to 0.15f, "lfodiv" to 3, "release" to 0.25f),
|
||||||
|
p("Vowel Pad", "o1table" to "Vowels", "o1pos" to 0f, "o2table" to "Vowels", "o2pos" to 0.5f, "o2level" to 0.6f, "o2fine" to 9f,
|
||||||
|
"unison" to 3, "spread" to 0.4f, "attack" to 0.8f, "release" to 2.5f, "mattack" to 3f, "mdecay" to 4f, "msustain" to 0.7f,
|
||||||
|
"menvpos" to 0.6f, "lfopos" to 0.2f, "lfodiv" to 0, "cutoff" to 0.7f),
|
||||||
|
p("PWM Strings", "o1table" to "PWM", "o1pos" to 0.2f, "o2table" to "PWM", "o2pos" to 0.6f, "o2level" to 0.7f, "o2fine" to -8f,
|
||||||
|
"unison" to 2, "spread" to 0.5f, "attack" to 0.4f, "release" to 1.2f, "lfopos" to 0.4f, "lfodiv" to 1, "menvpos" to 0f,
|
||||||
|
"cutoff" to 0.65f, "reso" to 0.1f),
|
||||||
|
p("Sync Sweep", "o1table" to "Sync", "o1pos" to 0f, "menvpos" to 0.9f, "mattack" to 0f, "mdecay" to 0.6f, "msustain" to 0.1f,
|
||||||
|
"cutoff" to 0.85f, "fenv" to 0.3f, "decay" to 0.5f, "sustain" to 0.6f, "release" to 0.2f, "drive" to 0.3f),
|
||||||
|
p("FM Bells", "o1table" to "FM", "o1pos" to 0.6f, "menvpos" to -0.6f, "mattack" to 0f, "mdecay" to 1.5f, "msustain" to 0f,
|
||||||
|
"attack" to 0f, "decay" to 2.5f, "sustain" to 0f, "release" to 2f, "cutoff" to 0.9f, "keytrack" to 0.8f, "fenv" to 0f),
|
||||||
|
p("Glass Keys", "o1table" to "Glass", "o1pos" to 0.2f, "o2table" to "Classic", "o2pos" to 0f, "o2oct" to 1, "o2level" to 0.3f,
|
||||||
|
"attack" to 0.005f, "decay" to 1.2f, "sustain" to 0.3f, "release" to 1f, "menvpos" to 0.4f, "mdecay" to 1.2f, "msustain" to 0.2f,
|
||||||
|
"mattack" to 0f, "cutoff" to 0.75f),
|
||||||
|
p("Organ Drift", "o1table" to "Organ", "o1pos" to 0f, "lfopos" to 0.5f, "lfodiv" to 0, "lfowave" to "Tri", "attack" to 0.02f,
|
||||||
|
"sustain" to 1f, "release" to 0.15f, "menvpos" to 0f, "cutoff" to 0.9f, "reso" to 0f),
|
||||||
|
p("Fold Bass", "o1table" to "Fold", "o1pos" to 0.1f, "o1oct" to -1, "sub" to 0.5f, "menvpos" to 0.7f, "mattack" to 0f,
|
||||||
|
"mdecay" to 0.3f, "msustain" to 0f, "attack" to 0f, "decay" to 0.4f, "sustain" to 0.7f, "release" to 0.15f,
|
||||||
|
"cutoff" to 0.55f, "fenv" to 0.35f, "drive" to 0.4f),
|
||||||
|
p("Digital Grit", "o1table" to "Digital", "o1pos" to 0.3f, "o2table" to "Digital", "o2pos" to 0.9f, "o2level" to 0.5f,
|
||||||
|
"o2semi" to 7, "lfopos" to 0.6f, "lfowave" to "S&H", "lfodiv" to 4, "menvpos" to 0f, "cutoff" to 0.8f, "reso" to 0.3f),
|
||||||
|
p("Comb Choir", "o1table" to "Comb", "o1pos" to 0f, "unison" to 4, "spread" to 0.45f, "attack" to 1.2f, "release" to 3f,
|
||||||
|
"mattack" to 6f, "mdecay" to 6f, "msustain" to 1f, "menvpos" to 1f, "cutoff" to 0.7f, "lfocut" to 0.2f, "lfodiv" to 0),
|
||||||
|
p("Odd Even Pluck", "o1table" to "Odd Even", "o1pos" to 1f, "menvpos" to -1f, "mattack" to 0f, "mdecay" to 0.5f, "msustain" to 0f,
|
||||||
|
"attack" to 0f, "decay" to 0.6f, "sustain" to 0f, "release" to 0.4f, "cutoff" to 0.7f, "fenv" to 0.4f, "reso" to 0.3f),
|
||||||
|
p("Harmonic Rise", "o1table" to "Harmonic Sweep", "o1pos" to 0f, "o2table" to "Harmonic Sweep", "o2pos" to 0f, "o2level" to 0.6f,
|
||||||
|
"o2fine" to 10f, "unison" to 2, "spread" to 0.3f, "attack" to 2f, "release" to 3f, "mattack" to 5f, "mdecay" to 8f,
|
||||||
|
"msustain" to 1f, "menvpos" to 1f, "cutoff" to 0.85f, "reso" to 0.05f),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,333 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
package cc.tiredsysadmin.android.sizzle.wavetable
|
||||||
|
|
||||||
|
import cc.tiredsysadmin.android.sizzle.audio.SampleStore
|
||||||
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
import java.util.concurrent.Executors
|
||||||
|
import kotlin.math.PI
|
||||||
|
import kotlin.math.abs
|
||||||
|
import kotlin.math.cos
|
||||||
|
import kotlin.math.exp
|
||||||
|
import kotlin.math.floor
|
||||||
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
|
import kotlin.math.pow
|
||||||
|
import kotlin.math.round
|
||||||
|
import kotlin.math.sin
|
||||||
|
import kotlin.math.sqrt
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A wavetable ready to play: [frames] single cycles, each kept as band-limited
|
||||||
|
* copies, one per octave ("mip levels"). Level k holds at most `512 >> k`
|
||||||
|
* harmonics in a cycle of [size]`(k)` samples (at least four samples per top
|
||||||
|
* harmonic, so linear interpolation is clean); the top quarter of each level's
|
||||||
|
* harmonics is faded out with a raised cosine, so moving from one level to the next
|
||||||
|
* as the pitch rises is not heard as a step. The voice picks the level whose top
|
||||||
|
* harmonic stays under Nyquist.
|
||||||
|
*/
|
||||||
|
class WaveTable(val name: String, val frames: Int, /** [level][frame * size(level) + i] */ val data: Array<FloatArray>) {
|
||||||
|
fun size(level: Int) = SIZES[level]
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val MAX_HARMONICS = 512
|
||||||
|
const val LEVELS = 10
|
||||||
|
val SIZES = IntArray(LEVELS) { k -> max(64, 4 * (MAX_HARMONICS shr k)) }
|
||||||
|
/** Harmonics level k carries. */
|
||||||
|
fun harmonics(level: Int) = MAX_HARMONICS shr level
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The wavetable synth's tables: twelve factory tables made here from formulas (no
|
||||||
|
* audio files ship), and tables imported from WAV files (Serum's 2048-sample frames,
|
||||||
|
* WaveEdit's 256, or any power-of-two frame length).
|
||||||
|
*
|
||||||
|
* Everything is built off the audio thread: [prewarm] makes the factory set in the
|
||||||
|
* background at startup; an imported table is built when it is loaded, or — after a
|
||||||
|
* restart, when only its WAV comes back — on a worker the first time a voice asks
|
||||||
|
* ([forSample]). Lookups never block; a table that isn't ready yet is silent.
|
||||||
|
*
|
||||||
|
* All original work for Sizzle: the method (spectra, an inverse FFT per octave with
|
||||||
|
* a taper at the top) is the textbook way to band-limit a wavetable.
|
||||||
|
*/
|
||||||
|
object WaveTables {
|
||||||
|
|
||||||
|
const val FRAMES = 16
|
||||||
|
private const val GEN = 4096 // the cycle length the formulas are sampled at
|
||||||
|
|
||||||
|
val FACTORY_NAMES = listOf(
|
||||||
|
"Classic", "PWM", "Vowels", "Harmonic Sweep", "Sync", "FM",
|
||||||
|
"Organ", "Fold", "Digital", "Glass", "Odd Even", "Comb",
|
||||||
|
)
|
||||||
|
const val CUSTOM = "Custom"
|
||||||
|
|
||||||
|
private val cache = ConcurrentHashMap<String, WaveTable>()
|
||||||
|
private val building = ConcurrentHashMap.newKeySet<String>()
|
||||||
|
private val worker = Executors.newSingleThreadExecutor { r -> Thread(r, "sizzle-wavetables").apply { isDaemon = true; priority = Thread.MIN_PRIORITY } }
|
||||||
|
@Volatile private var started = false
|
||||||
|
|
||||||
|
fun factory(name: String): WaveTable? = cache[name]
|
||||||
|
|
||||||
|
/** The table built from the custom sample [id] cut in [frameLen]-sample frames (0: detect),
|
||||||
|
* or null while it is being built (it is then queued once). */
|
||||||
|
fun forSample(id: String, frameLen: Int): WaveTable? {
|
||||||
|
if (id.isEmpty()) return null
|
||||||
|
val key = "$id#$frameLen"
|
||||||
|
cache[key]?.let { return it }
|
||||||
|
if (building.add(key)) worker.execute {
|
||||||
|
SampleStore.get(id)?.let { s -> cache[key] = fromSamples(CUSTOM, s.data, frameLen) }
|
||||||
|
building.remove(key)
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Build a custom table now (the caller is off the audio thread) and cache it. */
|
||||||
|
fun buildForSample(id: String, frameLen: Int): WaveTable? {
|
||||||
|
val s = SampleStore.get(id) ?: return null
|
||||||
|
return fromSamples(CUSTOM, s.data, frameLen).also { cache["$id#$frameLen"] = it }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun prewarm() {
|
||||||
|
if (started) return
|
||||||
|
started = true
|
||||||
|
worker.execute { prewarmBlocking() }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun prewarmBlocking() {
|
||||||
|
for (n in FACTORY_NAMES) if (!cache.containsKey(n)) cache[n] = makeFactory(n)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------ building ---
|
||||||
|
|
||||||
|
/** A table from cycles given as time-domain samples ([cycles] of equal power-of-two length). */
|
||||||
|
private fun fromCycles(name: String, cycles: List<FloatArray>): WaveTable {
|
||||||
|
val spectra = cycles.map { spectrum(it) }
|
||||||
|
return fromSpectra(name, spectra)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** [spectra]: per frame, cosine and sine amplitudes of harmonics 1..512 (index h-1). */
|
||||||
|
private fun fromSpectra(name: String, spectra: List<Pair<FloatArray, FloatArray>>): WaveTable {
|
||||||
|
val nf = spectra.size
|
||||||
|
val data = Array(WaveTable.LEVELS) { k -> FloatArray(nf * WaveTable.SIZES[k]) }
|
||||||
|
for (k in 0 until WaveTable.LEVELS) {
|
||||||
|
val n = WaveTable.SIZES[k]
|
||||||
|
val hk = WaveTable.harmonics(k)
|
||||||
|
val re = DoubleArray(n); val im = DoubleArray(n)
|
||||||
|
for (f in 0 until nf) {
|
||||||
|
val (c, s) = spectra[f]
|
||||||
|
re.fill(0.0); im.fill(0.0)
|
||||||
|
for (h in 1..min(hk, c.size)) {
|
||||||
|
val taper = taper(h, hk)
|
||||||
|
if (taper <= 0.0) continue
|
||||||
|
re[h] = c[h - 1] * taper
|
||||||
|
im[h] = -s[h - 1] * taper
|
||||||
|
}
|
||||||
|
fft(re, im, inverse = true)
|
||||||
|
val base = f * n
|
||||||
|
for (i in 0 until n) data[k][base + i] = re[i].toFloat()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return WaveTable(name, nf, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The top quarter of a level's harmonics fades out (raised cosine). */
|
||||||
|
private fun taper(h: Int, hk: Int): Double {
|
||||||
|
if (hk <= 4) return if (h <= hk) 1.0 else 0.0
|
||||||
|
val a = 0.75 * hk
|
||||||
|
return when {
|
||||||
|
h <= a -> 1.0
|
||||||
|
h > hk -> 0.0
|
||||||
|
else -> 0.5 + 0.5 * cos(PI * (h - a) / (hk - a + 1))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Harmonics 1..512 of one cycle (any power-of-two length; others are resampled). */
|
||||||
|
private fun spectrum(cycle0: FloatArray): Pair<FloatArray, FloatArray> {
|
||||||
|
val cycle = if (Integer.bitCount(cycle0.size) == 1) cycle0 else resample(cycle0, 2048)
|
||||||
|
val m = cycle.size
|
||||||
|
val re = DoubleArray(m) { cycle[it].toDouble() }
|
||||||
|
val im = DoubleArray(m)
|
||||||
|
fft(re, im, inverse = false)
|
||||||
|
val hn = min(WaveTable.MAX_HARMONICS, m / 2 - 1)
|
||||||
|
val c = FloatArray(WaveTable.MAX_HARMONICS); val s = FloatArray(WaveTable.MAX_HARMONICS)
|
||||||
|
for (h in 1..hn) { c[h - 1] = (2.0 * re[h] / m).toFloat(); s[h - 1] = (-2.0 * im[h] / m).toFloat() }
|
||||||
|
return c to s
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun resample(x: FloatArray, n: Int): FloatArray = FloatArray(n) { i ->
|
||||||
|
val p = i.toDouble() * x.size / n
|
||||||
|
val j = p.toInt(); val fr = (p - j).toFloat()
|
||||||
|
x[j % x.size] + (x[(j + 1) % x.size] - x[j % x.size]) * fr
|
||||||
|
}
|
||||||
|
|
||||||
|
/** In-place radix-2 complex FFT; [inverse] uses e^{+i} and no 1/N (the synthesis sum). */
|
||||||
|
private fun fft(re: DoubleArray, im: DoubleArray, inverse: Boolean) {
|
||||||
|
val n = re.size
|
||||||
|
var j = 0
|
||||||
|
for (i in 1 until n) {
|
||||||
|
var bit = n shr 1
|
||||||
|
while (j and bit != 0) { j = j xor bit; bit = bit shr 1 }
|
||||||
|
j = j xor bit
|
||||||
|
if (i < j) { var t = re[i]; re[i] = re[j]; re[j] = t; t = im[i]; im[i] = im[j]; im[j] = t }
|
||||||
|
}
|
||||||
|
var len = 2
|
||||||
|
while (len <= n) {
|
||||||
|
val ang = 2 * PI / len * (if (inverse) 1 else -1)
|
||||||
|
val wr = cos(ang); val wi = sin(ang)
|
||||||
|
var i = 0
|
||||||
|
while (i < n) {
|
||||||
|
var cr = 1.0; var ci = 0.0
|
||||||
|
for (k in 0 until len / 2) {
|
||||||
|
val ar = re[i + k + len / 2] * cr - im[i + k + len / 2] * ci
|
||||||
|
val ai = re[i + k + len / 2] * ci + im[i + k + len / 2] * cr
|
||||||
|
re[i + k + len / 2] = re[i + k] - ar; im[i + k + len / 2] = im[i + k] - ai
|
||||||
|
re[i + k] += ar; im[i + k] += ai
|
||||||
|
val ncr = cr * wr - ci * wi; ci = cr * wi + ci * wr; cr = ncr
|
||||||
|
}
|
||||||
|
i += len
|
||||||
|
}
|
||||||
|
len = len shl 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------------------------- import ---
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The frame length of a wavetable WAV: Serum's `clm ` chunk ("<!>2048 …") when
|
||||||
|
* present, else WaveEdit's 64 x 256 layout, else 2048 or 256 if the length divides,
|
||||||
|
* else the whole file as one cycle (0).
|
||||||
|
*/
|
||||||
|
fun detectFrameLength(wavBytes: ByteArray, frames: Int): Int {
|
||||||
|
val clm = indexOf(wavBytes, "clm ".toByteArray())
|
||||||
|
if (clm >= 0) {
|
||||||
|
val text = String(wavBytes, clm + 8, min(32, wavBytes.size - clm - 8), Charsets.US_ASCII)
|
||||||
|
Regex("<!>(\\d{2,5})").find(text)?.groupValues?.get(1)?.toIntOrNull()?.let { if (it in 16..8192 && frames % it == 0) return it }
|
||||||
|
}
|
||||||
|
return guessFrameLength(frames)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun guessFrameLength(frames: Int): Int = when {
|
||||||
|
frames == 64 * 256 -> 256
|
||||||
|
frames % 2048 == 0 && frames / 2048 in 1..256 -> 2048
|
||||||
|
frames % 256 == 0 && frames / 256 in 1..256 -> 256
|
||||||
|
frames % 1024 == 0 && frames / 1024 in 1..256 -> 1024
|
||||||
|
frames % 512 == 0 && frames / 512 in 1..256 -> 512
|
||||||
|
else -> 0
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun indexOf(h: ByteArray, n: ByteArray): Int {
|
||||||
|
outer@ for (i in 0..h.size - n.size) { for (j in n.indices) if (h[i + j] != n[j]) continue@outer; return i }
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A table from a sample cut into [frameLen0]-sample cycles (0: detect; at most 256 frames). */
|
||||||
|
fun fromSamples(name: String, x: FloatArray, frameLen0: Int): WaveTable {
|
||||||
|
val frameLen = if (frameLen0 > 0) frameLen0 else guessFrameLength(x.size)
|
||||||
|
val cycles = if (frameLen <= 0 || x.size < frameLen) listOf(x.copyOf())
|
||||||
|
else {
|
||||||
|
val n = min(256, x.size / frameLen)
|
||||||
|
val step = (x.size / frameLen).toDouble() / n
|
||||||
|
List(n) { i -> val f = (i * step).toInt(); x.copyOfRange(f * frameLen, (f + 1) * frameLen) }
|
||||||
|
}
|
||||||
|
var pk = 1e-9f
|
||||||
|
for (c in cycles) for (v in c) pk = max(pk, abs(v))
|
||||||
|
val g = 1f / pk
|
||||||
|
return fromCycles(name, cycles.map { c -> FloatArray(c.size) { c[it] * g } })
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------- factory ---
|
||||||
|
|
||||||
|
private fun makeFactory(name: String): WaveTable {
|
||||||
|
val cycles = List(FRAMES) { f ->
|
||||||
|
val t = f / (FRAMES - 1.0)
|
||||||
|
val x = DoubleArray(GEN) { i -> sample(name, t, f, i.toDouble() / GEN) }
|
||||||
|
val dc = x.average()
|
||||||
|
var pk = 1e-9
|
||||||
|
for (i in x.indices) { x[i] -= dc; pk = max(pk, abs(x[i])) }
|
||||||
|
FloatArray(GEN) { (x[it] / pk).toFloat() }
|
||||||
|
}
|
||||||
|
return fromCycles(name, cycles)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun saw(p: Double) = 2 * (p - floor(p)) - 1
|
||||||
|
private fun pulse(p: Double, w: Double) = if (p - floor(p) < w) 1.0 else -1.0
|
||||||
|
private fun tri(p: Double) = 1 - 4 * abs((p - floor(p)) - 0.5)
|
||||||
|
private fun sine(p: Double) = sin(2 * PI * p)
|
||||||
|
|
||||||
|
/** Additive: harmonics 1..n with amplitude a(h), all sine phase. */
|
||||||
|
private inline fun additive(p: Double, n: Int, a: (Int) -> Double): Double {
|
||||||
|
var s = 0.0
|
||||||
|
for (h in 1..n) { val v = a(h); if (v != 0.0) s += v * sin(2 * PI * h * p) }
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
private val VOWELS = arrayOf( // formant centre frequencies (Hz): a, e, i, o, u
|
||||||
|
doubleArrayOf(800.0, 1150.0, 2900.0), doubleArrayOf(400.0, 1600.0, 2700.0), doubleArrayOf(300.0, 2300.0, 3000.0),
|
||||||
|
doubleArrayOf(450.0, 800.0, 2830.0), doubleArrayOf(325.0, 700.0, 2530.0),
|
||||||
|
)
|
||||||
|
private val DRAWBARS = arrayOf( // levels of harmonics 1, 2, 3, 4, 6, 8 (and the 16' sub as h1)
|
||||||
|
doubleArrayOf(8.0, 8.0, 8.0, 0.0, 0.0, 0.0), doubleArrayOf(8.0, 0.0, 8.0, 6.0, 0.0, 4.0),
|
||||||
|
doubleArrayOf(6.0, 8.0, 4.0, 8.0, 3.0, 2.0), doubleArrayOf(8.0, 3.0, 0.0, 8.0, 8.0, 8.0),
|
||||||
|
)
|
||||||
|
|
||||||
|
/** Glass: sparse prime and square-ish harmonics at seeded levels, a new set every
|
||||||
|
* four frames, crossfaded between. */
|
||||||
|
private val GLASS: Array<DoubleArray> by lazy {
|
||||||
|
val primes = setOf(1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37)
|
||||||
|
val squares = setOf(1, 2, 4, 6, 9, 12, 16, 20, 25, 30, 36)
|
||||||
|
val sets = Array(FRAMES / 4 + 2) { k ->
|
||||||
|
val rng = java.util.Random(0x61A55L + k)
|
||||||
|
val pick = if (k % 2 == 0) primes else squares
|
||||||
|
DoubleArray(40) { h -> if ((h + 1) in pick) 0.2 + 0.8 * rng.nextDouble() else 0.0 }
|
||||||
|
}
|
||||||
|
Array(FRAMES) { f ->
|
||||||
|
val k = f / 4; val fr = (f % 4) / 4.0
|
||||||
|
DoubleArray(40) { h -> sets[k][h] * (1 - fr) + sets[k + 1][h] * fr }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val CLASSIC: Array<(Double) -> Double> = arrayOf({ q -> sine(q) }, { q -> tri(q) }, { q -> saw(q) },
|
||||||
|
{ q -> pulse(q, 0.5) }, { q -> pulse(q, 0.25) })
|
||||||
|
|
||||||
|
private fun sample(name: String, t: Double, f: Int, p: Double): Double = when (name) {
|
||||||
|
"Classic" -> {
|
||||||
|
val x = t * 4; val i = min(3, x.toInt()); val fr = x - i
|
||||||
|
CLASSIC[i](p) * (1 - fr) + CLASSIC[i + 1](p) * fr
|
||||||
|
}
|
||||||
|
"PWM" -> pulse(p, 0.5 - 0.46 * t)
|
||||||
|
"Vowels" -> {
|
||||||
|
val x = t * 4; val i = min(3, x.toInt()); val fr = x - i
|
||||||
|
additive(p, 60) { h ->
|
||||||
|
val hz = h * 110.0
|
||||||
|
var a = 0.0
|
||||||
|
for (k in 0 until 3) {
|
||||||
|
val fc = VOWELS[i][k] * (1 - fr) + VOWELS[i + 1][k] * fr
|
||||||
|
val bw = 80.0 + 40.0 * k
|
||||||
|
a += exp(-((hz - fc) / bw).pow(2)) * (if (k == 0) 1.0 else 0.6)
|
||||||
|
}
|
||||||
|
(a + 0.02) / sqrt(h.toDouble())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"Harmonic Sweep" -> {
|
||||||
|
val n = 1.0 + 2.0.pow(t * 6)
|
||||||
|
additive(p, 65) { h -> if (h <= n) 1.0 / h else if (h - 1 < n) (n - (h - 1)) / h else 0.0 }
|
||||||
|
}
|
||||||
|
"Sync" -> saw(p * (1 + 7 * t)) * (1 - 0.3 * t * p)
|
||||||
|
"FM" -> sin(2 * PI * p + 7 * t * sin(2 * PI * p) + 1.5 * t * t * sin(4 * PI * p))
|
||||||
|
"Organ" -> {
|
||||||
|
val x = t * 3; val i = min(2, x.toInt()); val fr = x - i
|
||||||
|
val hs = intArrayOf(1, 2, 3, 4, 6, 8)
|
||||||
|
var s = 0.0
|
||||||
|
for (k in hs.indices) s += (DRAWBARS[i][k] * (1 - fr) + DRAWBARS[i + 1][k] * fr) / 8 * sine(hs[k] * p)
|
||||||
|
s
|
||||||
|
}
|
||||||
|
"Fold" -> sin((1 + 7 * t) * sin(2 * PI * p) * PI / 2)
|
||||||
|
"Digital" -> { val steps = 2.0.pow(6 - 5 * t); round(sine(p) * steps) / steps }
|
||||||
|
"Glass" -> additive(p, 40) { h -> GLASS[f][h - 1] / h.toDouble().pow(0.6) }
|
||||||
|
"Odd Even" -> additive(p, 64) { h -> if (h % 2 == 1) (1 - t) / h + t * 0.3 / h else t / h * (if (h == 2) 1.6 else 1.0) }
|
||||||
|
"Comb" -> additive(p, 64) { h -> abs(cos(PI * h * (0.02 + 0.23 * t))) / h }
|
||||||
|
else -> sine(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Status-bar icon for the MIDI sound-module notification: a beamed pair of
|
||||||
|
eighth notes. Status-bar icons must be a single opaque colour on transparent. -->
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFFFF"
|
||||||
|
android:pathData="M9,3v11.55A4,4 0,1 0,11 18V7h8v7.55A4,4 0,1 0,21 18V3H9z" />
|
||||||
|
</vector>
|
||||||
+6
@@ -1,6 +1,12 @@
|
|||||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// 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
|
package cc.tiredsysadmin.android.sizzle.audio
|
||||||
|
|
||||||
import cc.tiredsysadmin.android.sizzle.model.AmbiencePresets
|
import cc.tiredsysadmin.android.sizzle.model.AmbiencePresets
|
||||||
@@ -14,7 +14,7 @@ import org.junit.Test
|
|||||||
*/
|
*/
|
||||||
class ChannelArpTest {
|
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. */
|
/** The Up sequence over a chord × octaves is octave-major over the sorted notes. */
|
||||||
@Test fun upCyclesWholeChordAcrossOctaves() {
|
@Test fun upCyclesWholeChordAcrossOctaves() {
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
package cc.tiredsysadmin.android.sizzle.audio
|
||||||
|
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.Project
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertNotNull
|
||||||
|
import org.junit.Assert.assertNull
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Test
|
||||||
|
import java.io.File
|
||||||
|
import java.io.RandomAccessFile
|
||||||
|
import java.nio.file.Files
|
||||||
|
import java.util.concurrent.CountDownLatch
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
/** An armed master recording follows an external MIDI clock's Start/Stop, with its tail. */
|
||||||
|
class ClockRecordingTest {
|
||||||
|
|
||||||
|
private val fs = 48_000
|
||||||
|
private val block = 192
|
||||||
|
|
||||||
|
private fun engine(dir: File, tailBars: Int, done: (File) -> Unit) = ReferenceEngine(fs).apply {
|
||||||
|
setProject(Project().apply { tempoBpm = 120f })
|
||||||
|
recTempDir = dir
|
||||||
|
onRecordingComplete = { f, _ ->
|
||||||
|
val copy = File(dir, "take-${System.nanoTime()}.wav"); f.copyTo(copy); done(copy)
|
||||||
|
}
|
||||||
|
setRecordingArm(true, tailBars)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 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 ReferenceEngine.run(frames: Int) {
|
||||||
|
val out = FloatArray(block * 2)
|
||||||
|
repeat(frames / block) { i -> fillBlock(out, block); if (i % 25 == 24) Thread.sleep(10) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sample frames in a 16-bit stereo WAV written by [MasterRecorder] (header patched on close). */
|
||||||
|
private fun frames(f: File): Long = RandomAccessFile(f, "r").use { it.length() - 44 } / 4
|
||||||
|
|
||||||
|
@Test fun clockStartRecordsAndStopEndsAfterTheTail() {
|
||||||
|
val dir = Files.createTempDirectory("rec").toFile()
|
||||||
|
val latch = CountDownLatch(1)
|
||||||
|
var take: File? = null
|
||||||
|
val e = engine(dir, tailBars = 1) { take = it; latch.countDown() }
|
||||||
|
e.run(fs) // armed, no clock: nothing
|
||||||
|
assertNull(take)
|
||||||
|
e.externalClockStart()
|
||||||
|
e.run(fs * 2) // two seconds of "the other app playing"
|
||||||
|
e.externalClockStop()
|
||||||
|
e.run(fs * 3) // 1 bar of 4/4 at 120 BPM = 2 s of tail, then done
|
||||||
|
assertTrue("the take finished", latch.await(5, TimeUnit.SECONDS))
|
||||||
|
val n = frames(assertNotNull(take).let { take!! })
|
||||||
|
// 2 s of clock + 2 s of tail (to a block)
|
||||||
|
assertEquals((fs * 4).toDouble(), n.toDouble(), block * 2.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun notArmedRecordsNothing() {
|
||||||
|
val dir = Files.createTempDirectory("rec").toFile()
|
||||||
|
var take: File? = null
|
||||||
|
val e = engine(dir, tailBars = 0) { take = it }
|
||||||
|
e.setRecordingArm(false, 0)
|
||||||
|
e.externalClockStart(); e.run(fs); e.externalClockStop(); e.run(fs)
|
||||||
|
Thread.sleep(200)
|
||||||
|
assertNull(take)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun sizzlesStopEndsAClockTake() {
|
||||||
|
val dir = Files.createTempDirectory("rec").toFile()
|
||||||
|
val latch = CountDownLatch(1)
|
||||||
|
val e = engine(dir, tailBars = 0) { latch.countDown() }
|
||||||
|
e.externalClockStart(); e.run(fs)
|
||||||
|
e.stop() // the user stops in Sizzle
|
||||||
|
e.run(fs / 10)
|
||||||
|
assertTrue(latch.await(5, TimeUnit.SECONDS))
|
||||||
|
assertFalse(e.transport.value.isPlaying)
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
@@ -1,6 +1,12 @@
|
|||||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// 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
|
package cc.tiredsysadmin.android.sizzle.audio
|
||||||
|
|
||||||
import cc.tiredsysadmin.android.sizzle.model.DelayDivisions
|
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-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// 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
|
package cc.tiredsysadmin.android.sizzle.audio
|
||||||
|
|
||||||
import java.io.File
|
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-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// 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
|
package cc.tiredsysadmin.android.sizzle.audio
|
||||||
|
|
||||||
import kotlin.math.exp
|
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,
|
attack: Float = 0.002f, decay: Float = 0f, sustain: Float = 1f, release: Float = 0.02f,
|
||||||
loop: Boolean = false, crossfadeMs: Float = 0f,
|
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
|
// 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
|
// (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).
|
// 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
|
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. */
|
/** Enter the release stage: fade from the current level to 0 over the release time. */
|
||||||
fun noteOff() {
|
fun release() {
|
||||||
val sr = engineSampleRate.toFloat()
|
val sr = engineSampleRate.toFloat()
|
||||||
releaseInc = if (releaseSeconds <= 0f) 1f else env / (releaseSeconds * sr)
|
releaseInc = if (releaseSeconds <= 0f) 1f else env / (releaseSeconds * sr)
|
||||||
if (releaseInc <= 0f) releaseInc = 1f
|
if (releaseInc <= 0f) releaseInc = 1f
|
||||||
+25
@@ -1,8 +1,16 @@
|
|||||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// 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
|
package cc.tiredsysadmin.android.sizzle.audio
|
||||||
|
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilPatch
|
||||||
|
import cc.tiredsysadmin.android.sizzle.wavetable.WavePatch
|
||||||
import cc.tiredsysadmin.android.sizzle.model.SynthDefs
|
import cc.tiredsysadmin.android.sizzle.model.SynthDefs
|
||||||
import cc.tiredsysadmin.android.sizzle.model.TimeDivision
|
import cc.tiredsysadmin.android.sizzle.model.TimeDivision
|
||||||
import cc.tiredsysadmin.android.sizzle.model.ToolboxSlot
|
import cc.tiredsysadmin.android.sizzle.model.ToolboxSlot
|
||||||
@@ -41,6 +49,11 @@ class SynthPatch(
|
|||||||
val modSrc: IntArray, // index into MOD_SRC (0 == Off)
|
val modSrc: IntArray, // index into MOD_SRC (0 == Off)
|
||||||
val modDst: IntArray, // index into MOD_DST
|
val modDst: IntArray, // index into MOD_DST
|
||||||
val modAmt: FloatArray, // -1..1
|
val modAmt: FloatArray, // -1..1
|
||||||
|
/** Set for a Morph Pad slot: the voice then plays FRASIL's drone voice from this
|
||||||
|
* instead of the subtractive path (see [SynthVoice]); everything above is unused. */
|
||||||
|
val pad: FrasilPatch? = null,
|
||||||
|
/** Set for a Wavetable slot: the voice plays [WaveVoice] from this. */
|
||||||
|
val wave: WavePatch? = null,
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
const val OSC_COUNT = SynthDefs.OSC_COUNT
|
const val OSC_COUNT = SynthDefs.OSC_COUNT
|
||||||
@@ -96,5 +109,17 @@ class SynthPatch(
|
|||||||
|
|
||||||
/** A plain default patch (for generic live audition not tied to a synth slot). */
|
/** A plain default patch (for generic live audition not tied to a synth slot). */
|
||||||
val DEFAULT: SynthPatch = from(null, 120f)
|
val DEFAULT: SynthPatch = from(null, 120f)
|
||||||
|
|
||||||
|
/** A Morph Pad patch: the default synth fields, carrying [pad]. */
|
||||||
|
fun forPad(pad: FrasilPatch): SynthPatch = with(DEFAULT) {
|
||||||
|
SynthPatch(oscWave, oscOct, oscSemi, oscFine, oscLevel, noiseLevel, cutoff, resonance, keytrack,
|
||||||
|
filterEnvAmt, fA, fD, fS, fR, aA, aD, aS, aR, lfoWave, lfoHz, lfoPhase, modSrc, modDst, modAmt, pad)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A Wavetable patch: the default synth fields, carrying [wave]. */
|
||||||
|
fun forWave(wave: WavePatch): SynthPatch = with(DEFAULT) {
|
||||||
|
SynthPatch(oscWave, oscOct, oscSemi, oscFine, oscLevel, noiseLevel, cutoff, resonance, keytrack,
|
||||||
|
filterEnvAmt, fA, fD, fS, fR, aA, aD, aS, aR, lfoWave, lfoHz, lfoPhase, modSrc, modDst, modAmt, null, wave)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+56
-3
@@ -1,8 +1,16 @@
|
|||||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// 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
|
package cc.tiredsysadmin.android.sizzle.audio
|
||||||
|
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilVoice
|
||||||
|
import cc.tiredsysadmin.android.sizzle.wavetable.WaveVoice
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
import kotlin.math.exp
|
import kotlin.math.exp
|
||||||
import kotlin.math.sin
|
import kotlin.math.sin
|
||||||
@@ -71,15 +79,42 @@ class SynthVoice(private val sampleRate: Int) {
|
|||||||
private val ampEnv = Adsr()
|
private val ampEnv = Adsr()
|
||||||
private val filtEnv = Adsr()
|
private val filtEnv = Adsr()
|
||||||
|
|
||||||
val isActive: Boolean get() = ampEnv.active
|
// A Morph Pad note plays FRASIL's drone voice, a Wavetable note the wavetable
|
||||||
|
// voice, instead of the subtractive path. They live inside this class so every
|
||||||
|
// synth pool (sequencer, mix-bus, audition) plays them with no change to how
|
||||||
|
// voices are allocated, stolen or released. [mode]: MODE_SYNTH / _PAD / _WAVE.
|
||||||
|
private val pad = FrasilVoice(sampleRate)
|
||||||
|
private val wave = WaveVoice(sampleRate)
|
||||||
|
private var mode = MODE_SYNTH
|
||||||
|
|
||||||
|
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
|
/** Gate is still open (attack/decay/sustain) — the note is *held*. A voice in its
|
||||||
* release tail is still [isActive] but no longer gated; distinguishing the two
|
* release tail is still [isActive] but no longer gated; distinguishing the two
|
||||||
* lets a note-off target the held voice instead of one that's already ringing
|
* lets a note-off target the held voice instead of one that's already ringing
|
||||||
* out (which otherwise leaves the held note stuck under rapid re-tapping). */
|
* out (which otherwise leaves the held note stuck under rapid re-tapping). */
|
||||||
val isGated: Boolean get() = ampEnv.gateOpen
|
val isGated: Boolean get() = when (mode) { MODE_PAD -> pad.isGated; MODE_WAVE -> wave.isGated; else -> ampEnv.gateOpen }
|
||||||
|
|
||||||
/** Start (or steal-and-restart) this voice with the given [patch]. */
|
/** Start (or steal-and-restart) this voice with the given [patch]. */
|
||||||
fun noteOn(midi: Int, velocity: Int, patch: SynthPatch) {
|
fun noteOn(midi: Int, velocity: Int, patch: SynthPatch) {
|
||||||
|
val padPatch = patch.pad
|
||||||
|
val wavePatch = patch.wave
|
||||||
|
val want = if (padPatch != null) MODE_PAD else if (wavePatch != null) MODE_WAVE else MODE_SYNTH
|
||||||
|
if (want != mode) { // a slot switched kinds: the old engine stops
|
||||||
|
ampEnv.kill(); filtEnv.kill(); pad.kill(); wave.kill()
|
||||||
|
mode = want
|
||||||
|
}
|
||||||
|
if (padPatch != null) {
|
||||||
|
this.patch = patch
|
||||||
|
pitch = midi
|
||||||
|
pad.noteOn(midi, velocity / 127f, padPatch)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (wavePatch != null) {
|
||||||
|
this.patch = patch
|
||||||
|
pitch = midi
|
||||||
|
wave.noteOn(midi, velocity / 127f, wavePatch)
|
||||||
|
return
|
||||||
|
}
|
||||||
this.patch = patch
|
this.patch = patch
|
||||||
pitch = midi
|
pitch = midi
|
||||||
this.velocity = (velocity / 127f).coerceIn(0f, 1f)
|
this.velocity = (velocity / 127f).coerceIn(0f, 1f)
|
||||||
@@ -98,11 +133,15 @@ class SynthVoice(private val sampleRate: Int) {
|
|||||||
computeTuning()
|
computeTuning()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun noteOff() { ampEnv.gateOff(); filtEnv.gateOff() }
|
fun noteOff() {
|
||||||
|
when (mode) { MODE_PAD -> pad.noteOff(); MODE_WAVE -> wave.noteOff(); else -> { ampEnv.gateOff(); filtEnv.gateOff() } }
|
||||||
|
}
|
||||||
|
|
||||||
/** Hard stop with no release tail (transport stop / voice steal). */
|
/** Hard stop with no release tail (transport stop / voice steal). */
|
||||||
fun kill() {
|
fun kill() {
|
||||||
ampEnv.kill(); filtEnv.kill()
|
ampEnv.kill(); filtEnv.kill()
|
||||||
|
pad.kill()
|
||||||
|
wave.kill()
|
||||||
pitch = -1
|
pitch = -1
|
||||||
ownerTrack = -1
|
ownerTrack = -1
|
||||||
icB = 0f; icL = 0f
|
icB = 0f; icL = 0f
|
||||||
@@ -114,6 +153,15 @@ class SynthVoice(private val sampleRate: Int) {
|
|||||||
* turns (cutoff, levels, mod…) without clicking or retriggering. */
|
* turns (cutoff, levels, mod…) without clicking or retriggering. */
|
||||||
fun setPatch(p: SynthPatch) {
|
fun setPatch(p: SynthPatch) {
|
||||||
if (p === patch) return
|
if (p === patch) return
|
||||||
|
val padPatch = p.pad
|
||||||
|
val wavePatch = p.wave
|
||||||
|
if (mode != MODE_SYNTH || padPatch != null || wavePatch != null) {
|
||||||
|
// Only within the same kind: a pad note follows pad edits, a wavetable note
|
||||||
|
// wavetable edits; a slot switched between kinds takes effect on the next note.
|
||||||
|
if (mode == MODE_PAD && padPatch != null) { patch = p; pad.setPatch(padPatch) }
|
||||||
|
if (mode == MODE_WAVE && wavePatch != null) { patch = p; wave.setPatch(wavePatch) }
|
||||||
|
return
|
||||||
|
}
|
||||||
patch = p
|
patch = p
|
||||||
lfoInc = p.lfoHz.toDouble() / sampleRate
|
lfoInc = p.lfoHz.toDouble() / sampleRate
|
||||||
computeTuning()
|
computeTuning()
|
||||||
@@ -130,6 +178,8 @@ class SynthVoice(private val sampleRate: Int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun render(): Float {
|
fun render(): Float {
|
||||||
|
if (mode == MODE_PAD) return pad.render()
|
||||||
|
if (mode == MODE_WAVE) return wave.render()
|
||||||
if (!ampEnv.active) return 0f
|
if (!ampEnv.active) return 0f
|
||||||
val dt = 1f / sampleRate
|
val dt = 1f / sampleRate
|
||||||
val ampE = ampEnv.advance(dt)
|
val ampE = ampEnv.advance(dt)
|
||||||
@@ -321,6 +371,9 @@ class SynthVoice(private val sampleRate: Int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
private const val MODE_SYNTH = 0
|
||||||
|
private const val MODE_PAD = 1
|
||||||
|
private const val MODE_WAVE = 2
|
||||||
private const val OUT_GAIN = 0.5f
|
private const val OUT_GAIN = 0.5f
|
||||||
private const val CTRL_INTERVAL = 16 // samples between cutoff recomputes
|
private const val CTRL_INTERVAL = 16 // samples between cutoff recomputes
|
||||||
/** One-pole time constant for amp modulation. Long enough to band-limit a
|
/** One-pole time constant for amp modulation. Long enough to band-limit a
|
||||||
@@ -0,0 +1,708 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Philip Bos (ECHOFIELD)
|
||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown (Kotlin port for Sizzle)
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
//
|
||||||
|
// Ported from ECHOFIELD FM-1 (https://github.com/Philip-Bos/echofield-fm1, commit 4734e97):
|
||||||
|
// app/dsp/engine.c, its granular core (ef_window, compute_ctl, notes_track, note_pitch,
|
||||||
|
// 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
|
||||||
|
import cc.tiredsysadmin.android.sizzle.audio.SampleStore
|
||||||
|
import kotlin.math.abs
|
||||||
|
import kotlin.math.cos
|
||||||
|
import kotlin.math.exp
|
||||||
|
import kotlin.math.floor
|
||||||
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
|
import kotlin.math.pow
|
||||||
|
import kotlin.math.sin
|
||||||
|
import kotlin.math.sqrt
|
||||||
|
|
||||||
|
/** A parsed Grain Cloud slot: its smoothed settings' targets, the source to read,
|
||||||
|
* and the song's tempo (PULSE steps on it). Built off the hot path, per slot change. */
|
||||||
|
class GrainPatch(
|
||||||
|
val p: FloatArray,
|
||||||
|
/** The built-in source's name, or null for the custom sample [sampleId]. */
|
||||||
|
val sourceName: String?,
|
||||||
|
val sampleId: String,
|
||||||
|
val tempoBpm: Float,
|
||||||
|
) {
|
||||||
|
companion object {
|
||||||
|
fun from(slot: cc.tiredsysadmin.android.sizzle.model.ToolboxSlot?, tempoBpm: Float): GrainPatch {
|
||||||
|
val p = FloatArray(GrainCloud.P_COUNT)
|
||||||
|
fun f(i: Int, key: String, def: Float) { p[i] = slot?.float(key, def) ?: def }
|
||||||
|
f(GrainCloud.P_POSITION, "position", 0.35f); f(GrainCloud.P_TEXTURE, "texture", 0.72f)
|
||||||
|
f(GrainCloud.P_SCATTER, "scatter", 0.45f); f(GrainCloud.P_DRIFT, "drift", 0.35f)
|
||||||
|
f(GrainCloud.P_MOTION, "motion", 0.35f); f(GrainCloud.P_PITCH, "pitch", 0f)
|
||||||
|
f(GrainCloud.P_HARMONY, "harmony", 0.30f); f(GrainCloud.P_SIZE_MUL, "size_mul", 0f)
|
||||||
|
f(GrainCloud.P_DENS_MUL, "dens_mul", 0f); f(GrainCloud.P_SCAN, "scan", 0f)
|
||||||
|
f(GrainCloud.P_REVERSE, "reverse", 0.10f); f(GrainCloud.P_PITCH_RAND, "pitch_rand", 0f)
|
||||||
|
f(GrainCloud.P_SIZE_RAND, "size_rand", 0.3f); f(GrainCloud.P_GRAIN_TONE, "grain_tone", -0.1f)
|
||||||
|
f(GrainCloud.P_ATTACK, "attack", 0.15f); f(GrainCloud.P_RELEASE, "release", 0.45f)
|
||||||
|
f(GrainCloud.P_VELO, "velo", 0.5f); f(GrainCloud.P_START, "start", 0f); f(GrainCloud.P_END, "end", 1f)
|
||||||
|
f(GrainCloud.P_LEVEL, "level", 0.75f)
|
||||||
|
p[GrainCloud.P_MODE] = EchofieldDefs.MODES.indexOf(slot?.string("mode", "Cloud") ?: "Cloud").coerceAtLeast(0).toFloat()
|
||||||
|
p[GrainCloud.P_WINDOW] = EchofieldDefs.WINDOWS.indexOf(slot?.string("window", "Auto") ?: "Auto").coerceAtLeast(0).toFloat()
|
||||||
|
p[GrainCloud.P_FREEZE] = if (slot?.string("freeze", "Off") == "On") 1f else 0f
|
||||||
|
val src = slot?.string("source", EchofieldDefs.SOURCES[0]) ?: EchofieldDefs.SOURCES[0]
|
||||||
|
return GrainPatch(
|
||||||
|
p, if (src == EchofieldDefs.CUSTOM) null else src,
|
||||||
|
slot?.string(EchofieldDefs.SAMPLE_KEY, "") ?: "", tempoBpm,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One mixer channel's grain cloud: ECHOFIELD's granular engine. A note doesn't get a
|
||||||
|
* voice of its own; held notes (up to [MAX_NOTES]) are handed to new grains in turn,
|
||||||
|
* and a new note fires two grains at once so the key answers. One gate (ATTACK /
|
||||||
|
* RELEASE) opens while any note is held.
|
||||||
|
*
|
||||||
|
* Six modes shape the cloud: CLOUD (long grains melting into a pad), DUST (tiny
|
||||||
|
* specks, stutters, leaps), TAPE (three loop heads at three speeds), BLOOM (slow
|
||||||
|
* swells with overtones), PULSE (soft notes on a euclidean 16-step clock, on the
|
||||||
|
* song's tempo) and DRIFT (everything wanders). Up to [MAX_GRAINS] grains, each
|
||||||
|
* with a window, a reverse chance, a colour filter and its pitch drawn at birth;
|
||||||
|
* the level follows ECHOFIELD's auto-level, so density and source don't change it.
|
||||||
|
*
|
||||||
|
* Differences from ECHOFIELD: Sizzle's channels are mono (grains are not panned),
|
||||||
|
* the source is float PCM (no ADPCM blocks), the rate is Sizzle's, PULSE follows
|
||||||
|
* the song's tempo (no clock phase), and the effects, oracle and performance
|
||||||
|
* effects are not part of it. Control runs every [SUB] frames as in ECHOFIELD;
|
||||||
|
* [render] hands out a sample at a time. Allocation-free after construction.
|
||||||
|
*/
|
||||||
|
class GrainCloud(private val fs: Int) {
|
||||||
|
|
||||||
|
private val fsf = fs.toFloat()
|
||||||
|
private var patch: GrainPatch? = null
|
||||||
|
private val sm = FloatArray(P_COUNT)
|
||||||
|
private var smPrimed = false
|
||||||
|
private val smoothA = 1f - exp(-SUB / (0.04f * fs))
|
||||||
|
private val playK = 1f - 0.99f.pow(44100f / fs)
|
||||||
|
|
||||||
|
// grains
|
||||||
|
private val gOn = BooleanArray(MAX_GRAINS)
|
||||||
|
private val gWin = IntArray(MAX_GRAINS)
|
||||||
|
private val gRev = BooleanArray(MAX_GRAINS)
|
||||||
|
private val gTone = IntArray(MAX_GRAINS)
|
||||||
|
private val gPos = DoubleArray(MAX_GRAINS)
|
||||||
|
private val gInc = DoubleArray(MAX_GRAINS)
|
||||||
|
private val gLen = IntArray(MAX_GRAINS)
|
||||||
|
private val gAge = IntArray(MAX_GRAINS)
|
||||||
|
private val gDelay = IntArray(MAX_GRAINS)
|
||||||
|
private val gWph = FloatArray(MAX_GRAINS)
|
||||||
|
private val gWstep = FloatArray(MAX_GRAINS)
|
||||||
|
private val gAmp = FloatArray(MAX_GRAINS)
|
||||||
|
private val gToneA = FloatArray(MAX_GRAINS)
|
||||||
|
private val gZ = FloatArray(MAX_GRAINS)
|
||||||
|
private val gLoad = FloatArray(MAX_GRAINS)
|
||||||
|
private var loadNow = 0f
|
||||||
|
|
||||||
|
// the source and its swap fade
|
||||||
|
private var src: SampleStore.Sample? = null
|
||||||
|
private var fadeGain = 1f
|
||||||
|
|
||||||
|
// modes
|
||||||
|
private var rng = nextSeed()
|
||||||
|
private var spawnWait = 0f; private var scan = 0f
|
||||||
|
private var walkPos = 0f; private var walkPitch = 0f; private var walkV1 = 0f; private var walkV2 = 0f
|
||||||
|
private var walkSize = 0f
|
||||||
|
private var lfo1 = 0f; private var lfo2Cur = 0f; private var lfo2Tgt = 0f; private var lfo2T = 0f
|
||||||
|
private var tapeHead = 0f; private var tapeSpeed = 1f; private var tapeStop = 0f; private var tapeK = 0
|
||||||
|
private var stutterLeft = 0; private var stutterPos = 0f
|
||||||
|
private var pulseStep = 0; private var pulseRot = 0; private var pulseAcc = 0f
|
||||||
|
private val stepPos = FloatArray(16) { rndf() }
|
||||||
|
private val stepOct = IntArray(16)
|
||||||
|
private var env = 0f
|
||||||
|
private var playGain = 0f
|
||||||
|
private var agcMs = 0f
|
||||||
|
private var agcGain = 1f
|
||||||
|
|
||||||
|
// notes: those held now (owner: the tracker track, or -1 for live input)
|
||||||
|
private val noteNum = IntArray(MAX_NOTES)
|
||||||
|
private val noteVel = IntArray(MAX_NOTES)
|
||||||
|
private val noteOwner = IntArray(MAX_NOTES)
|
||||||
|
private var nNotes = 0
|
||||||
|
private var noteSeq = 0; private var noteSeqSeen = 0
|
||||||
|
// the notes grains are born on: the ones held, or while the release sounds the last ones held
|
||||||
|
private val heldNote = IntArray(MAX_NOTES)
|
||||||
|
private val heldVel = IntArray(MAX_NOTES)
|
||||||
|
private var heldN = 0
|
||||||
|
private var noteRr = 0
|
||||||
|
|
||||||
|
// control values (ECHOFIELD's ctl_t), recomputed each sub-block
|
||||||
|
private var cSize = 0f; private var cDensity = 0f; private var cJitter = 0f; private var cCenter = 0f
|
||||||
|
private var cScatter = 0f; private var cPitchRand = 0f; private var cRevProb = 0f; private var cAmp = 1f
|
||||||
|
private var cTone = 0f; private var cToneRand = 0f; private var cWin = 0; private var cClocked = false
|
||||||
|
private var cTape = false; private var cTapeSpeed = 1f
|
||||||
|
|
||||||
|
private val bus = FloatArray(SUB)
|
||||||
|
private var pos = SUB
|
||||||
|
|
||||||
|
/** Sounding: a note held, the gate's release still open, or a grain still playing. */
|
||||||
|
val isActive: Boolean
|
||||||
|
get() {
|
||||||
|
if (nNotes > 0 || env > 0.0005f || playGain > 0.0005f) return true
|
||||||
|
for (k in 0 until MAX_GRAINS) if (gOn[k]) return true
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setPatch(p: GrainPatch) { patch = p }
|
||||||
|
|
||||||
|
fun noteOn(note: Int, velocity: Int, owner: Int = -1) {
|
||||||
|
for (k in 0 until nNotes) 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++
|
||||||
|
}
|
||||||
|
|
||||||
|
fun noteOff(note: Int) {
|
||||||
|
var k = 0
|
||||||
|
while (k < nNotes) if (noteNum[k] == note) removeAt(k) else k++
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Let go of every note tracker track [owner] holds (its next note replaces them). */
|
||||||
|
fun releaseOwner(owner: Int) {
|
||||||
|
var k = 0
|
||||||
|
while (k < nNotes) if (noteOwner[k] == owner) removeAt(k) else k++
|
||||||
|
}
|
||||||
|
|
||||||
|
fun releaseAll() { nNotes = 0 }
|
||||||
|
|
||||||
|
/** Let go of the sequencer's notes ([owner] >= 0 or [OWNER_SEQ]), keeping live ones. */
|
||||||
|
fun releaseSequenced() {
|
||||||
|
var k = 0
|
||||||
|
while (k < nNotes) if (noteOwner[k] != OWNER_LIVE) removeAt(k) else k++
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Silence now: every grain off, no tail. */
|
||||||
|
fun kill() {
|
||||||
|
nNotes = 0; heldN = 0; env = 0f; playGain = 0f
|
||||||
|
gOn.fill(false); loadNow = 0f; pos = SUB
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun removeAt(k: Int) {
|
||||||
|
for (i in k until nNotes - 1) { noteNum[i] = noteNum[i + 1]; noteVel[i] = noteVel[i + 1]; noteOwner[i] = noteOwner[i + 1] }
|
||||||
|
nNotes--
|
||||||
|
}
|
||||||
|
|
||||||
|
fun render(): Float {
|
||||||
|
if (pos >= SUB) { block(); pos = 0 }
|
||||||
|
return bus[pos++]
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------- block ---
|
||||||
|
private fun block() {
|
||||||
|
val pt = patch
|
||||||
|
if (pt == null) { bus.fill(0f); return }
|
||||||
|
val dt = SUB / fsf
|
||||||
|
for (i in 0 until P_COUNT) {
|
||||||
|
val t = pt.p[i]
|
||||||
|
sm[i] = if (!smPrimed || i == P_MODE || i == P_WINDOW || i == P_FREEZE) t else sm[i] + (t - sm[i]) * smoothA
|
||||||
|
}
|
||||||
|
smPrimed = true
|
||||||
|
|
||||||
|
// a new source: fade out, swap, fade in
|
||||||
|
val want = (if (pt.sourceName != null) GrainSources.get(pt.sourceName) else SampleStore.get(pt.sampleId))
|
||||||
|
?.takeIf { it.data.size >= 512 }
|
||||||
|
if (want !== src) {
|
||||||
|
if (src == null || fadeGain <= 0f) {
|
||||||
|
src = want
|
||||||
|
gOn.fill(false); loadNow = 0f
|
||||||
|
tapeHead = 0f
|
||||||
|
fadeGain = 0f
|
||||||
|
} else {
|
||||||
|
fadeGain = max(0f, fadeGain - SUB / (0.02f * fsf))
|
||||||
|
}
|
||||||
|
} else if (fadeGain < 1f) {
|
||||||
|
fadeGain = min(1f, fadeGain + SUB / (0.02f * fsf))
|
||||||
|
}
|
||||||
|
|
||||||
|
// the gate: keys open it with their attack, release closes it
|
||||||
|
val atk = 0.005f * 800f.pow(sm[P_ATTACK])
|
||||||
|
val rel = 0.01f * 800f.pow(sm[P_RELEASE])
|
||||||
|
val envTarget = if (nNotes > 0) 1f else 0f
|
||||||
|
env += (envTarget - env) * min(1f, dt / (if (envTarget > env) atk else rel))
|
||||||
|
|
||||||
|
computeCtl(dt)
|
||||||
|
val s = src
|
||||||
|
if (cTape && s != null && !frozen()) {
|
||||||
|
val a = min(sm[P_START], sm[P_END]); val b = max(sm[P_START], sm[P_END])
|
||||||
|
val rlen = max(512f, (b - a) * s.data.size)
|
||||||
|
tapeHead += cTapeSpeed * SUB * (s.sampleRate / fsf) / rlen
|
||||||
|
tapeHead -= floor(tapeHead)
|
||||||
|
}
|
||||||
|
bus.fill(0f)
|
||||||
|
if (want === src) schedule()
|
||||||
|
renderGrains()
|
||||||
|
for (i in 0 until SUB) {
|
||||||
|
playGain += (env - playGain) * playK
|
||||||
|
bus[i] *= playGain * fadeGain
|
||||||
|
}
|
||||||
|
autoLevel()
|
||||||
|
val level = sm[P_LEVEL] * OUT_GAIN
|
||||||
|
for (i in 0 until SUB) {
|
||||||
|
val y = bus[i] * level
|
||||||
|
bus[i] = if (y.isFinite()) y else 0f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun frozen() = sm[P_FREEZE] >= 0.5f
|
||||||
|
|
||||||
|
private fun regionSeconds(): Float {
|
||||||
|
val s = src ?: return 1f
|
||||||
|
val a = min(sm[P_START], sm[P_END]); val b = max(sm[P_START], sm[P_END])
|
||||||
|
return (b - a) * s.data.size / s.sampleRate
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun computeCtl(dt: Float) {
|
||||||
|
val mode = sm[P_MODE].toInt()
|
||||||
|
val t = sm[P_TEXTURE]; val sc = sm[P_SCATTER]; val d = sm[P_DRIFT]; val m = sm[P_MOTION]
|
||||||
|
val sizeMul = 2f.pow(sm[P_SIZE_MUL]); val densMul = 2f.pow(sm[P_DENS_MUL])
|
||||||
|
if (!frozen()) {
|
||||||
|
lfo1 += dt * (0.03f + 0.3f * m)
|
||||||
|
if (lfo1 > 1f) lfo1 -= 1f
|
||||||
|
lfo2T += dt * (0.1f + 1.5f * m)
|
||||||
|
if (lfo2T >= 1f) { lfo2T -= 1f; lfo2Tgt = rndb() }
|
||||||
|
lfo2Cur += (lfo2Tgt - lfo2Cur) * min(1f, dt * (0.5f + 3f * m))
|
||||||
|
val wr = (if (mode == MODE_DRIFT) 0.25f + 1.2f * m else 0.08f + 0.4f * m) * dt
|
||||||
|
walkV1 += rndb() * wr * 2f - walkV1 * wr * 2f
|
||||||
|
walkPos = (walkPos + walkV1 * wr * 4f - walkPos * wr * 0.3f).coerceIn(-1f, 1f)
|
||||||
|
walkV2 += rndb() * wr * 2f - walkV2 * wr * 2f
|
||||||
|
walkPitch = (walkPitch + walkV2 * wr * 4f - walkPitch * wr * 0.3f).coerceIn(-1f, 1f)
|
||||||
|
walkSize += (rndb() - walkSize) * dt * 0.3f
|
||||||
|
if (src != null) {
|
||||||
|
scan += sm[P_SCAN] * dt / max(0.05f, abs(regionSeconds()))
|
||||||
|
scan -= floor(scan)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val lfo = sin(TWO_PI * lfo1)
|
||||||
|
val pos0 = sm[P_POSITION]
|
||||||
|
cJitter = 0.5f
|
||||||
|
cPitchRand = sm[P_PITCH_RAND] + 0.08f + d * 0.3f
|
||||||
|
cRevProb = sm[P_REVERSE]
|
||||||
|
cAmp = 1f
|
||||||
|
cTone = sm[P_GRAIN_TONE]
|
||||||
|
cToneRand = 0f
|
||||||
|
cWin = WIN_HANN
|
||||||
|
cClocked = false
|
||||||
|
cTape = false
|
||||||
|
cTapeSpeed = 1f
|
||||||
|
val wander = d * 0.3f * walkPos
|
||||||
|
when (mode) {
|
||||||
|
MODE_DUST -> {
|
||||||
|
cSize = 0.02f * (200f / 20f).pow(t)
|
||||||
|
cDensity = (6f + 24f * (1f - 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 = (sm[P_GRAIN_TONE] + 0.25f).coerceIn(-1f, 1f)
|
||||||
|
cToneRand = 0.3f
|
||||||
|
}
|
||||||
|
MODE_TAPE -> {
|
||||||
|
var target = semis(sm[P_PITCH]) * lerp(1f, 0.3f, t.pow(1.2f))
|
||||||
|
target *= 1f + 0.03f * m * lfo2Cur + 0.02f * d * walkPitch
|
||||||
|
if (!frozen() && tapeStop <= 0f && rndf() < m * 0.02f * dt) tapeStop = 1.6f
|
||||||
|
if (tapeStop > 0f) {
|
||||||
|
tapeStop -= dt
|
||||||
|
val ph = 1.6f - tapeStop
|
||||||
|
target *= if (ph < 0.8f) 1f - ph / 0.8f else (ph - 0.8f) / 0.8f
|
||||||
|
target = max(target, 0.02f)
|
||||||
|
}
|
||||||
|
tapeSpeed += (target - tapeSpeed) * min(1f, dt * 6f)
|
||||||
|
cTape = true
|
||||||
|
cTapeSpeed = tapeSpeed
|
||||||
|
cSize = 0.18f * (1f + t)
|
||||||
|
cDensity = 4f / cSize
|
||||||
|
cJitter = 0.15f
|
||||||
|
cCenter = tapeHead
|
||||||
|
cScatter = 0.002f + sc * 0.03f
|
||||||
|
cPitchRand = sm[P_PITCH_RAND]
|
||||||
|
}
|
||||||
|
MODE_BLOOM -> {
|
||||||
|
cSize = 0.6f * (2.5f / 0.6f).pow(t)
|
||||||
|
cDensity = (3f + 3f * t) / cSize * (1f + 0.5f * m * lfo2Cur)
|
||||||
|
cJitter = 0.9f
|
||||||
|
cCenter = pos0 + 0.2f * m * lfo + wander
|
||||||
|
cScatter = 0.08f + 0.5f * sc
|
||||||
|
cRevProb += 0.25f
|
||||||
|
cTone = (sm[P_GRAIN_TONE] + 0.15f).coerceIn(-1f, 1f)
|
||||||
|
cToneRand = 0.25f
|
||||||
|
cWin = if (rndf() < 0.5f) WIN_HANN else WIN_GAUSS
|
||||||
|
cAmp = 0.95f
|
||||||
|
}
|
||||||
|
MODE_PULSE -> {
|
||||||
|
cClocked = true
|
||||||
|
cSize = 0.06f * (1200f / 60f).pow(t)
|
||||||
|
cDensity = 0f
|
||||||
|
cCenter = pos0 + wander
|
||||||
|
cScatter = sc
|
||||||
|
cWin = if (t > 0.6f) WIN_HANN else WIN_PERC
|
||||||
|
cJitter = 0f
|
||||||
|
}
|
||||||
|
MODE_DRIFT -> {
|
||||||
|
cSize = 0.1f * 12f.pow(t) * (1f + 0.5f * walkSize)
|
||||||
|
cDensity = (2f + 4f * t) * (1f + 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
|
||||||
|
}
|
||||||
|
else -> { // CLOUD
|
||||||
|
cSize = 0.12f * (1500f / 120f).pow(t)
|
||||||
|
cDensity = (4f + 8f * t) / cSize * (1f + 0.4f * m * lfo2Cur)
|
||||||
|
cJitter = 0.4f + 0.6f * sc
|
||||||
|
cCenter = pos0 + 0.15f * m * lfo + wander
|
||||||
|
cScatter = 0.03f + 0.6f * sc.pow(1.3f)
|
||||||
|
cRevProb += sc * 0.1f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cSize *= sizeMul
|
||||||
|
cDensity *= densMul
|
||||||
|
val wsel = sm[P_WINDOW].toInt()
|
||||||
|
if (wsel > 0) cWin = wsel - 1
|
||||||
|
cRevProb = cRevProb.coerceIn(0f, 1f)
|
||||||
|
cSize = cSize.coerceIn(0.004f, 2.5f)
|
||||||
|
cDensity = cDensity.coerceIn(0f, 400f)
|
||||||
|
cScatter = cScatter.coerceIn(0f, 1f)
|
||||||
|
if (!cTape) { val cc = cCenter + scan; cCenter = cc - floor(cc) }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ grains ---
|
||||||
|
private fun notesTrack() {
|
||||||
|
if (nNotes == 0) return
|
||||||
|
for (k in 0 until nNotes) { heldNote[k] = noteNum[k] - 60; heldVel[k] = noteVel[k] }
|
||||||
|
heldN = nNotes
|
||||||
|
}
|
||||||
|
|
||||||
|
private var ampScale = 1f
|
||||||
|
private fun notePitch(): Float {
|
||||||
|
if (heldN == 0) return 0f
|
||||||
|
val k = (noteRr++ and 0x7FFFFFFF) % heldN
|
||||||
|
val velo = sm[P_VELO]
|
||||||
|
ampScale *= (1f - velo) + velo * heldVel[k] / 127f
|
||||||
|
return heldNote[k].toFloat()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun spawn(offset: Int, amp0: Float, extraPitch: Float, posOverride: Float) {
|
||||||
|
val s = src ?: return
|
||||||
|
val frames = s.data.size
|
||||||
|
var g = -1
|
||||||
|
var active = 0
|
||||||
|
for (i in 0 until MAX_GRAINS) if (gOn[i]) active++ else if (g < 0) g = i
|
||||||
|
if (g < 0 || active >= MAX_GRAINS) return
|
||||||
|
val ra = min(sm[P_START], sm[P_END]); val rb = max(sm[P_START], sm[P_END])
|
||||||
|
var rs = ra * frames; var re = rb * frames
|
||||||
|
if (re - rs < 512f) { re = min(frames - 1f, rs + 512f); rs = max(0f, re - 512f) }
|
||||||
|
re = min(re, frames - 2f)
|
||||||
|
val rlen = re - rs
|
||||||
|
if (rlen < 64f) return
|
||||||
|
|
||||||
|
val size = cSize * (1f + rndb() * sm[P_SIZE_RAND] * 0.7f * (if (cTape) 0.3f else 1f))
|
||||||
|
var len = (max(size, 0.003f) * fsf).toInt()
|
||||||
|
ampScale = amp0
|
||||||
|
val pitch = sm[P_PITCH] + notePitch()
|
||||||
|
var harm = 0f
|
||||||
|
if (rndf() < sm[P_HARMONY] * 0.65f) {
|
||||||
|
harm = HARMONY_IV[nextRand() and 7]
|
||||||
|
ampScale *= 0.7f
|
||||||
|
}
|
||||||
|
var step: Float
|
||||||
|
if (cTape) {
|
||||||
|
val head = tapeK
|
||||||
|
tapeK = (tapeK + 1) % 3
|
||||||
|
step = cTapeSpeed * TAPE_HR[head] * semis(harm + (pitch - sm[P_PITCH]))
|
||||||
|
ampScale *= TAPE_HA[head]
|
||||||
|
tapeGrainHead = head
|
||||||
|
} else {
|
||||||
|
val st = (pitch + harm + extraPitch + rndb() * cPitchRand + walkPitch * sm[P_DRIFT] * 2f).coerceIn(-48f, 36f)
|
||||||
|
step = semis(st)
|
||||||
|
}
|
||||||
|
step *= s.sampleRate / fsf
|
||||||
|
step = step.coerceIn(1f / 64f, STEP_MAX)
|
||||||
|
if (loadNow + 1f + step > LOAD_MAX) return
|
||||||
|
if (len < 64) len = 64
|
||||||
|
var span = len * step
|
||||||
|
if (span > rlen * 0.98f) { len = (rlen * 0.98f / step).toInt(); span = len * step }
|
||||||
|
if (len < 32) return
|
||||||
|
val rev = rndf() < cRevProb
|
||||||
|
var center = if (posOverride >= 0f) posOverride else cCenter + rndb() * cScatter * 0.5f
|
||||||
|
if (cTape) center = cCenter + tapeGrainHead / 3f + rndb() * cScatter
|
||||||
|
center -= floor(center)
|
||||||
|
val cpos = rs + center * rlen
|
||||||
|
val start = if (!rev) (cpos - span * 0.5f).coerceIn(rs, re - span) else (cpos + span * 0.5f).coerceIn(rs + span, re - 1f)
|
||||||
|
gPos[g] = max(start, 0f).toDouble()
|
||||||
|
gInc[g] = step.toDouble()
|
||||||
|
gRev[g] = rev
|
||||||
|
gLen[g] = len
|
||||||
|
gAge[g] = 0
|
||||||
|
gDelay[g] = offset
|
||||||
|
gWin[g] = cWin.coerceIn(0, WIN_COUNT - 1)
|
||||||
|
gWph[g] = 0f
|
||||||
|
gWstep[g] = WIN_N.toFloat() / len
|
||||||
|
gLoad[g] = 1f + step
|
||||||
|
val overlap = max(1f, cDensity * cSize)
|
||||||
|
gAmp[g] = (cAmp * ampScale * 0.75f / sqrt(overlap)).coerceIn(0f, 1.9f)
|
||||||
|
val tone = (cTone + rndb() * cToneRand).coerceIn(-1f, 1f)
|
||||||
|
when {
|
||||||
|
abs(tone) < 0.02f -> gTone[g] = 0
|
||||||
|
tone < 0f -> { gTone[g] = 1; gToneA[g] = onepole(min(18000f * 0.02f.pow(-tone), min(20000f, 0.45f * fsf))) }
|
||||||
|
else -> { gTone[g] = 2; gToneA[g] = onepole(150f * 30f.pow(tone)) }
|
||||||
|
}
|
||||||
|
gZ[g] = 0f
|
||||||
|
gOn[g] = true
|
||||||
|
loadNow += gLoad[g]
|
||||||
|
}
|
||||||
|
|
||||||
|
private var tapeGrainHead = 0
|
||||||
|
|
||||||
|
private fun renderGrains() {
|
||||||
|
val s = src ?: run { gOn.fill(false); loadNow = 0f; return }
|
||||||
|
val data = s.data
|
||||||
|
val last = data.size - 1
|
||||||
|
var load = 0f
|
||||||
|
for (k in 0 until MAX_GRAINS) {
|
||||||
|
if (!gOn[k]) continue
|
||||||
|
val w = WIN_TAB[gWin[k]]
|
||||||
|
var i = gDelay[k]
|
||||||
|
gDelay[k] = 0
|
||||||
|
var p = gPos[k]
|
||||||
|
val inc = gInc[k]
|
||||||
|
val rev = gRev[k]
|
||||||
|
val tone = gTone[k]
|
||||||
|
val ta = gToneA[k]
|
||||||
|
var z = gZ[k]
|
||||||
|
var wph = gWph[k]
|
||||||
|
val wstep = gWstep[k]
|
||||||
|
val amp = gAmp[k]
|
||||||
|
var left = gLen[k] - gAge[k]
|
||||||
|
if (left > SUB - i) left = SUB - i
|
||||||
|
gAge[k] += left
|
||||||
|
while (left > 0) {
|
||||||
|
val idx = p.toInt()
|
||||||
|
if (p < 0.0 || idx >= last) { gAge[k] = gLen[k]; break }
|
||||||
|
val fr = (p - idx).toFloat()
|
||||||
|
var x = data[idx] + (data[idx + 1] - data[idx]) * fr
|
||||||
|
if (tone != 0) { z += (x - z) * ta; x = if (tone == 1) z else x - z }
|
||||||
|
val wi = wph.toInt().coerceAtMost(WIN_N)
|
||||||
|
val wv = w[wi] + (w[wi + 1] - w[wi]) * (wph - wi)
|
||||||
|
bus[i] += x * wv * amp
|
||||||
|
p = if (rev) p - inc else p + inc
|
||||||
|
wph = min(wph + wstep, WIN_N.toFloat())
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun schedule() {
|
||||||
|
notesTrack()
|
||||||
|
if (src == null || (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, 1f, 0f, -1f); spawn(0, 0.8f, 0f, -1f) }
|
||||||
|
}
|
||||||
|
if (cClocked) {
|
||||||
|
// PULSE: on the song's tempo, its 1/16, 1/8 or 1/4, whichever is nearest ECHOFIELD's own pace
|
||||||
|
val own = 30f + 90f * sm[P_MOTION]
|
||||||
|
val ext = patch?.tempoBpm ?: 0f
|
||||||
|
var bpm = own
|
||||||
|
if (ext > 0f) {
|
||||||
|
var best = 1e9f
|
||||||
|
var dv = 1
|
||||||
|
while (dv <= 4) {
|
||||||
|
val r = ext / dv
|
||||||
|
val e = if (r > own) r / own else own / r
|
||||||
|
if (e < best) { best = e; bpm = r }
|
||||||
|
dv = dv shl 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val stepSamples = fsf * 60f / bpm / 4f
|
||||||
|
val kk = (5f + sm[P_DENS_MUL] * 2.5f + 0.5f).coerceIn(1f, 16f).toInt()
|
||||||
|
val pat = euclid(kk, 16, pulseRot)
|
||||||
|
for (i in 0 until SUB) {
|
||||||
|
pulseAcc -= 1f
|
||||||
|
if (pulseAcc <= 0f) {
|
||||||
|
val st = pulseStep
|
||||||
|
pulseAcc += stepSamples * (1f + (if (pulseStep and 1 == 1) 0.08f else -0.08f) * sm[P_DRIFT])
|
||||||
|
pulseStep = (pulseStep + 1) and 15
|
||||||
|
if (st == 0 && !frozen() && rndf() < sm[P_MOTION] * 0.35f) {
|
||||||
|
val j = (rndf() * 16f).toInt() and 15
|
||||||
|
stepPos[j] = rndf()
|
||||||
|
stepOct[j] = if (rndf() < sm[P_DRIFT] * 0.5f) (if (rndf() < 0.5f) 12 else 7) else 0
|
||||||
|
if (rndf() < sm[P_MOTION] * 0.3f) pulseRot = (pulseRot + 1) and 15
|
||||||
|
}
|
||||||
|
if ((pat shr st) and 1 == 1) {
|
||||||
|
var p = cCenter + (stepPos[st] - 0.5f) * cScatter
|
||||||
|
p -= floor(p)
|
||||||
|
spawn(i, if (st % 4 == 0) 1.1f else 0.77f, stepOct[st].toFloat(), p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (cDensity <= 0f) return
|
||||||
|
val mean = fsf / cDensity
|
||||||
|
val mode = sm[P_MODE].toInt()
|
||||||
|
for (i in 0 until SUB) {
|
||||||
|
spawnWait -= 1f
|
||||||
|
if (spawnWait > 0f) continue
|
||||||
|
spawnWait += mean * (1f - cJitter + cJitter * 2f * rndf())
|
||||||
|
if (spawnWait < 1f) spawnWait = 1f
|
||||||
|
when (mode) {
|
||||||
|
MODE_DUST -> {
|
||||||
|
if (stutterLeft > 0) { stutterLeft--; spawn(i, 1f, 0f, stutterPos); continue }
|
||||||
|
if (rndf() < sm[P_MOTION] * 0.05f) {
|
||||||
|
stutterLeft = 2 + (rndf() * 4f).toInt()
|
||||||
|
stutterPos = cCenter + rndb() * cScatter * 0.5f
|
||||||
|
stutterPos -= floor(stutterPos)
|
||||||
|
}
|
||||||
|
val sp = if (rndf() < sm[P_SCATTER] * 0.35f) DUST_LEAP[(rndf() * 5f).toInt() % 5] else 0f
|
||||||
|
spawn(i, 1f, sp, -1f)
|
||||||
|
}
|
||||||
|
MODE_BLOOM -> {
|
||||||
|
val r = rndf()
|
||||||
|
val k = if (r < 0.55f) 0 else if (r < 0.75f) 1 else if (r < 0.9f) 2 else 3
|
||||||
|
spawn(i, 0.5f + 0.5f * rndf(), BLOOM_PART[k], -1f)
|
||||||
|
}
|
||||||
|
else -> spawn(i, 1f, 0f, -1f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 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. */
|
||||||
|
private fun autoLevel() {
|
||||||
|
val blk = SUB / fsf
|
||||||
|
var ms = 0f
|
||||||
|
for (i in 0 until SUB) ms += bus[i] * bus[i]
|
||||||
|
ms /= SUB
|
||||||
|
val g0 = agcGain
|
||||||
|
agcMs += (ms - agcMs) * (1f - exp(-blk / 2.5f))
|
||||||
|
var target = agcGain
|
||||||
|
if (agcMs > 1e-6f) target = (AGC_TARGET / sqrt(agcMs)).coerceIn(0.5f, 4f)
|
||||||
|
if (env <= 0.5f && target > agcGain) target = agcGain
|
||||||
|
val tc = if (target < agcGain) 0.4f else 2.5f
|
||||||
|
agcGain += (target - agcGain) * (1f - exp(-blk / tc))
|
||||||
|
for (i in 0 until SUB) bus[i] *= g0 + (agcGain - g0) * i / SUB
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------- helpers ---
|
||||||
|
private fun onepole(hz: Float) = 1f - exp(-TWO_PI * hz / fsf)
|
||||||
|
|
||||||
|
private fun nextRand(): Int {
|
||||||
|
var x = rng
|
||||||
|
x = x xor (x shl 13); x = x xor (x ushr 17); x = x xor (x shl 5)
|
||||||
|
rng = x
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun rndf(): Float = (nextRand() ushr 8) * (1f / 16777216f)
|
||||||
|
private fun rndb(): Float = rndf() * 2f - 1f
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val P_POSITION = 0; const val P_TEXTURE = 1; const val P_SCATTER = 2; const val P_DRIFT = 3
|
||||||
|
const val P_MOTION = 4; const val P_PITCH = 5; const val P_HARMONY = 6; const val P_SIZE_MUL = 7
|
||||||
|
const val P_DENS_MUL = 8; const val P_SCAN = 9; const val P_REVERSE = 10; const val P_PITCH_RAND = 11
|
||||||
|
const val P_SIZE_RAND = 12; const val P_WINDOW = 13; const val P_GRAIN_TONE = 14; const val P_ATTACK = 15
|
||||||
|
const val P_RELEASE = 16; const val P_VELO = 17; const val P_START = 18; const val P_END = 19
|
||||||
|
const val P_MODE = 20; const val P_FREEZE = 21; const val P_LEVEL = 22
|
||||||
|
const val P_COUNT = 23
|
||||||
|
|
||||||
|
/** A note from live input (keys, MIDI); [OWNER_SEQ] one the sequencer played with no track (an arpeggio). */
|
||||||
|
const val OWNER_LIVE = -1
|
||||||
|
const val OWNER_SEQ = -2
|
||||||
|
|
||||||
|
const val SUB = 64
|
||||||
|
const val MAX_GRAINS = 32
|
||||||
|
const val MAX_NOTES = 8
|
||||||
|
private const val WIN_N = 256
|
||||||
|
private const val STEP_MAX = 4f
|
||||||
|
private const val LOAD_MAX = 56f
|
||||||
|
private const val AGC_TARGET = 0.126f
|
||||||
|
/** Brings the auto-levelled cloud to about the level of a Sizzle synth note. */
|
||||||
|
private const val OUT_GAIN = 1.0f
|
||||||
|
private const val TWO_PI = 6.2831853f
|
||||||
|
private const val PI = 3.14159265f
|
||||||
|
|
||||||
|
const val MODE_CLOUD = 0; const val MODE_DUST = 1; const val MODE_TAPE = 2
|
||||||
|
const val MODE_BLOOM = 3; const val MODE_PULSE = 4; const val MODE_DRIFT = 5
|
||||||
|
private const val WIN_HANN = 0; private const val WIN_TUKEY = 1; private const val WIN_PERC = 2
|
||||||
|
private const val WIN_SWELL = 3; private const val WIN_GAUSS = 4; private const val WIN_COUNT = 5
|
||||||
|
|
||||||
|
private val HARMONY_IV = floatArrayOf(12f, 12f, -12f, 7f, 19f, 24f, -5f, 7f)
|
||||||
|
private val TAPE_HR = floatArrayOf(1f, 0.5f, 2f)
|
||||||
|
private val TAPE_HA = floatArrayOf(1f, 0.8f, 0.4f)
|
||||||
|
private val DUST_LEAP = floatArrayOf(12f, 19f, 24f, 7f, -12f)
|
||||||
|
private val BLOOM_PART = floatArrayOf(0f, 12f, 7f, -12f)
|
||||||
|
|
||||||
|
/** The grain windows (ef_window), 0..1 over [WIN_N] + 2 points. */
|
||||||
|
fun window(w: Int, x0: Float): Float {
|
||||||
|
val x = x0.coerceIn(0f, 1f)
|
||||||
|
return when (w) {
|
||||||
|
WIN_TUKEY -> {
|
||||||
|
val a = 0.3f
|
||||||
|
when {
|
||||||
|
x < a * 0.5f -> 0.5f - 0.5f * cos(TWO_PI * x / a)
|
||||||
|
x > 1f - a * 0.5f -> 0.5f - 0.5f * cos(TWO_PI * (1f - x) / a)
|
||||||
|
else -> 1f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WIN_PERC -> {
|
||||||
|
val att = 0.03f
|
||||||
|
var v = if (x < att) sin(0.5f * PI * x / att) else exp(-5f * (x - att) / (1f - att))
|
||||||
|
if (x > 0.92f) v *= 0.5f + 0.5f * cos(PI * (x - 0.92f) / 0.08f)
|
||||||
|
v
|
||||||
|
}
|
||||||
|
WIN_SWELL -> window(WIN_PERC, 1f - x)
|
||||||
|
WIN_GAUSS -> {
|
||||||
|
val d = (x - 0.5f) / 0.16f
|
||||||
|
val g = exp(-0.5f * d * d)
|
||||||
|
val e = 0.00752f
|
||||||
|
((g - e) / (1f - e)).coerceIn(0f, 1f)
|
||||||
|
}
|
||||||
|
else -> 0.5f - 0.5f * cos(TWO_PI * x)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val WIN_TAB: Array<FloatArray> = Array(WIN_COUNT) { w ->
|
||||||
|
FloatArray(WIN_N + 2) { i -> window(w, i.toFloat() / WIN_N) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun euclid(k: Int, n: Int, rot: Int): Int {
|
||||||
|
var pat = 0
|
||||||
|
if (k <= 0) return 0
|
||||||
|
for (i in 0 until n) if ((i * k) % n < k) pat = pat or (1 shl ((i + rot) % n))
|
||||||
|
return pat
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun semis(st: Float): Float = 2f.pow(st / 12f)
|
||||||
|
private fun lerp(a: Float, b: Float, t: Float) = a + (b - a) * t
|
||||||
|
private fun flush(x: Float) = if (x > -1e-20f && x < 1e-20f) 0f else x
|
||||||
|
|
||||||
|
private var seeds = 0x1234567
|
||||||
|
private fun nextSeed(): Int {
|
||||||
|
seeds += 0x6D2B79F5
|
||||||
|
return if (seeds == 0) 0x1234567 else seeds
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
package cc.tiredsysadmin.android.sizzle.echofield
|
||||||
|
|
||||||
|
import cc.tiredsysadmin.android.sizzle.audio.GrainSources
|
||||||
|
import cc.tiredsysadmin.android.sizzle.audio.SampleStore
|
||||||
|
import cc.tiredsysadmin.android.sizzle.audio.SynthPatch
|
||||||
|
import cc.tiredsysadmin.android.sizzle.audio.SynthVoice
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.ToolboxSlot
|
||||||
|
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.assertTrue
|
||||||
|
import org.junit.BeforeClass
|
||||||
|
import org.junit.Test
|
||||||
|
import kotlin.math.PI
|
||||||
|
import kotlin.math.abs
|
||||||
|
import kotlin.math.sin
|
||||||
|
import kotlin.math.sqrt
|
||||||
|
|
||||||
|
class GrainCloudTest {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@JvmStatic @BeforeClass fun sources() = GrainSources.prewarmBlocking()
|
||||||
|
}
|
||||||
|
|
||||||
|
private val fs = 48_000
|
||||||
|
|
||||||
|
private fun slot(preset: String? = null, vararg extra: Pair<String, String>): ToolboxSlot =
|
||||||
|
ToolboxSlot(0).apply {
|
||||||
|
fill(ToolboxType.GRAIN_CLOUD)
|
||||||
|
preset?.let { n -> EchofieldDefs.FACTORY.first { it.name == n }.values.forEach { (k, v) -> set(k, v) } }
|
||||||
|
extra.forEach { (k, v) -> set(k, v) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun cloud(s: ToolboxSlot, tempo: Float = 120f) = GrainCloud(fs).apply { setPatch(GrainPatch.from(s, tempo)) }
|
||||||
|
|
||||||
|
private class Stats(val rms: Float, val peak: Float, val finite: Boolean)
|
||||||
|
|
||||||
|
private fun render(c: GrainCloud, frames: Int): Stats {
|
||||||
|
var sum = 0.0; var peak = 0f; var finite = true
|
||||||
|
repeat(frames) { val x = c.render(); if (!x.isFinite()) finite = false; sum += x * x; peak = maxOf(peak, abs(x)) }
|
||||||
|
return Stats(sqrt(sum / frames).toFloat(), peak, finite)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun builtInSourcesAreReady() {
|
||||||
|
for (name in EchofieldDefs.SOURCES.filter { it != EchofieldDefs.CUSTOM }) {
|
||||||
|
val s = assertNotNull(name, GrainSources.get(name)).let { GrainSources.get(name)!! }
|
||||||
|
assertEquals(name, GrainSources.RATE, s.sampleRate)
|
||||||
|
assertTrue(name, s.data.size >= GrainSources.RATE * 5)
|
||||||
|
assertTrue(name, s.data.all { it.isFinite() && abs(it) <= 0.9f })
|
||||||
|
assertTrue("$name not silent", s.data.maxOf { abs(it) } > 0.5f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun everyFactoryPresetPlaysAndFreesAfterRelease() {
|
||||||
|
assertEquals(14, EchofieldDefs.FACTORY.size)
|
||||||
|
for (p in EchofieldDefs.FACTORY) {
|
||||||
|
val c = cloud(slot(p.name))
|
||||||
|
c.noteOn(60, 100)
|
||||||
|
val held = render(c, fs * 4)
|
||||||
|
println("${p.name}: rms ${"%.3f".format(held.rms)} peak ${"%.3f".format(held.peak)}")
|
||||||
|
assertTrue("${p.name} finite", held.finite)
|
||||||
|
assertTrue("${p.name} sounds (rms ${held.rms})", held.rms > 0.01f)
|
||||||
|
assertTrue("${p.name} rms ${held.rms}", held.rms < 0.6f)
|
||||||
|
c.noteOff(60)
|
||||||
|
var frames = 0
|
||||||
|
while (c.isActive && frames < fs * 15) { c.render(); frames++ }
|
||||||
|
assertFalse("${p.name} frees after its release", c.isActive)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun grainsFollowTheNote() {
|
||||||
|
// a pure C4 sine as the source: A4 must come out at 440 Hz
|
||||||
|
val n = 48_000 * 4
|
||||||
|
SampleStore.put("test:sine", SampleStore.Sample(FloatArray(n) { (0.8 * sin(2 * PI * 261.6256 * it / 48_000)).toFloat() }, 48_000))
|
||||||
|
val c = cloud(slot(null, "source" to EchofieldDefs.CUSTOM, EchofieldDefs.SAMPLE_KEY to "test:sine",
|
||||||
|
"drift" to "0.0", "harmony" to "0.0", "reverse" to "0.0", "scatter" to "0.0", "grain_tone" to "0.0", "motion" to "0.0"))
|
||||||
|
c.noteOn(69, 127)
|
||||||
|
render(c, fs)
|
||||||
|
var prev = c.render(); var crossings = 0
|
||||||
|
repeat(fs * 2) { val x = c.render(); if (prev < 0f && x >= 0f) crossings++; prev = x }
|
||||||
|
assertEquals(440.0, crossings / 2.0, 6.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun aCloudIsAboutAsLoudAsASynthNote() {
|
||||||
|
val c = cloud(slot("Felt Clouds")).apply { noteOn(60, 100) }
|
||||||
|
render(c, fs * 3)
|
||||||
|
val cloud = render(c, fs).rms
|
||||||
|
val syn = SynthVoice(fs).apply { noteOn(60, 100, SynthPatch.DEFAULT) }
|
||||||
|
repeat(fs) { syn.render() }
|
||||||
|
var s = 0.0; repeat(fs) { val x = syn.render(); s += x * x }
|
||||||
|
val ratio = cloud / sqrt(s / fs).toFloat()
|
||||||
|
println("cloud/synth rms ratio $ratio")
|
||||||
|
assertTrue("cloud/synth level $ratio within -6..+6 dB", ratio in 0.5f..2f)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun ownersReleaseOnlyTheirNotes() {
|
||||||
|
val c = cloud(slot("Felt Clouds"))
|
||||||
|
c.noteOn(60, 100, owner = 3)
|
||||||
|
c.noteOn(64, 100, owner = GrainCloud.OWNER_LIVE)
|
||||||
|
c.noteOn(67, 100, owner = GrainCloud.OWNER_SEQ)
|
||||||
|
c.releaseOwner(3)
|
||||||
|
render(c, fs)
|
||||||
|
assertTrue(c.isActive)
|
||||||
|
c.releaseSequenced() // the arpeggio's note goes, the live one stays
|
||||||
|
render(c, fs * 2)
|
||||||
|
assertTrue("live note still held", c.isActive)
|
||||||
|
c.noteOff(64)
|
||||||
|
var frames = 0
|
||||||
|
while (c.isActive && frames < fs * 15) { c.render(); frames++ }
|
||||||
|
assertFalse(c.isActive)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun pulseModeFollowsTheTempo() {
|
||||||
|
val c = cloud(slot("Kalimba Steps"), tempo = 120f)
|
||||||
|
c.noteOn(60, 100)
|
||||||
|
val s = render(c, fs * 3)
|
||||||
|
assertTrue(s.finite && s.rms > 0.005f)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun cpuBudgetForFourDenseClouds() {
|
||||||
|
val clouds = Array(4) { cloud(slot("Glass Choir", "dens_mul" to "2.0", "size_mul" to "1.0")).apply { noteOn(48 + it * 5, 100) } }
|
||||||
|
repeat(fs) { for (c in clouds) c.render() }
|
||||||
|
val seconds = 2
|
||||||
|
val t0 = System.nanoTime()
|
||||||
|
repeat(fs * seconds) { for (c in clouds) c.render() }
|
||||||
|
val load = (System.nanoTime() - t0) / 1e9 / seconds
|
||||||
|
println("4 dense Grain Clouds: ${"%.1f".format(load * 100)} % of real time on this host")
|
||||||
|
assertTrue(load < 1.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Styves Goupil (FRASIL)
|
||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown (Kotlin port for Sizzle)
|
||||||
|
// 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).
|
||||||
|
|
||||||
|
// 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
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An immutable snapshot of a Morph Pad slot, parsed off the audio thread's hot path
|
||||||
|
* (once per slot change, like the synth's patch): the sound's engine values [a] and
|
||||||
|
* its filter type, and when MORPH TO names a factory sound, that sound's [b] to
|
||||||
|
* morph toward.
|
||||||
|
*/
|
||||||
|
class FrasilPatch(
|
||||||
|
val a: FloatArray,
|
||||||
|
val aType: Int,
|
||||||
|
val b: FloatArray?,
|
||||||
|
val bType: Int,
|
||||||
|
/** Where a note starts between [a] (0) and [b] (1). */
|
||||||
|
val morph: Float,
|
||||||
|
/** Seconds a held note takes from [morph] to [b]; 0 stays at [morph]. */
|
||||||
|
val morphTime: Float,
|
||||||
|
) {
|
||||||
|
companion object {
|
||||||
|
fun from(slot: ToolboxSlot?): FrasilPatch {
|
||||||
|
val (a, at) = FrasilDefs.engineFrom(
|
||||||
|
{ k, d -> slot?.float(k, d) ?: d },
|
||||||
|
{ k, d -> slot?.string(k, d) ?: d },
|
||||||
|
)
|
||||||
|
val target = slot?.string(FrasilDefs.MORPH_TO, "Off") ?: "Off"
|
||||||
|
val b = if (target == "Off") null else FrasilDefs.factoryEngine(target)
|
||||||
|
return FrasilPatch(
|
||||||
|
a, at, b?.first, b?.second ?: at,
|
||||||
|
morph = (slot?.float(FrasilDefs.MORPH, 0f) ?: 0f).coerceIn(0f, 1f),
|
||||||
|
morphTime = (slot?.float(FrasilDefs.MORPH_TIME, 0f) ?: 0f).coerceIn(0f, 120f),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val DEFAULT: FrasilPatch by lazy { from(null) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FRASIL's TIDE is one slow sine shared by every voice (a chord brightens and darkens
|
||||||
|
* together). Sizzle renders voice by voice, so the shared part is the time it runs
|
||||||
|
* on: the audio engine advances this clock once a block, and each voice reads its
|
||||||
|
* tide from it at its own TIDE SPEED. Audio thread only.
|
||||||
|
*/
|
||||||
|
object FrasilClock {
|
||||||
|
var seconds = 0.0
|
||||||
|
private set
|
||||||
|
|
||||||
|
fun advance(frames: Int, sampleRate: Int) { seconds += frames.toDouble() / sampleRate }
|
||||||
|
}
|
||||||
@@ -0,0 +1,673 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Styves Goupil (FRASIL)
|
||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown (Kotlin port for Sizzle)
|
||||||
|
// 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).
|
||||||
|
//
|
||||||
|
// Ported from FRASIL 3.3 (https://github.com/styvesgoupil/frasil, commit e7a8fb2):
|
||||||
|
// engine/dsp/frasil.c, its drone voice (voice_start, drift, voice_block, choir_run,
|
||||||
|
// 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
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.ATTACK
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.BEAT
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.BODY
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.BREATH
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.BR_PITCH
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.CHOIR
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.CH_RESO
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.COLOR
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.CUTOFF
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.DETUNE
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.EVOLVE
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.FORMANT
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.GRAIN
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.INTERVAL
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.MOTION
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.MOTION_RATE
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.ODD
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.PARTIALS
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.PEAK
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.RELEASE
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.RESONANCE
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.SHAPE
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.SOFT
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.STRETCH
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.TIDE
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.TIDE_RATE
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.TILT
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.TIMBRE
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.TONE
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.VELOCITY
|
||||||
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.WARMTH
|
||||||
|
import kotlin.math.cos
|
||||||
|
import kotlin.math.exp
|
||||||
|
import kotlin.math.floor
|
||||||
|
import kotlin.math.ln
|
||||||
|
import kotlin.math.pow
|
||||||
|
import kotlin.math.sin
|
||||||
|
import kotlin.math.sqrt
|
||||||
|
import kotlin.math.tan
|
||||||
|
import kotlin.math.tanh
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One note of the Morph Pad: FRASIL's drone voice, three layers summed and slowly
|
||||||
|
* drifting while the note is held.
|
||||||
|
*
|
||||||
|
* - CHOIR: three PolyBLEP saws (centre at INTERVAL, the sides detuned ±), SHAPE
|
||||||
|
* turns each toward a swaying pulse, SOFT integrates it toward a triangle or a
|
||||||
|
* sine; two one-pole low-passes, or with RESONANCE / TYPE a TPT state-variable
|
||||||
|
* filter, the cutoff in harmonics of the note.
|
||||||
|
* - PARTIALS: eight additive partials as "magic circle" oscillators, tilt, odd,
|
||||||
|
* stretch, a formant, each one's level and tuning drifting (EVOLVE), BEAT pulsing.
|
||||||
|
* - BREATH (FRASIL's SOUFFLE): noise or sparse grains through three resonators at
|
||||||
|
* the note times harmonic / odd / bell ratios, Q from air to glass.
|
||||||
|
*
|
||||||
|
* MOTION is an Ornstein-Uhlenbeck random walk per drifting thing (a step a block),
|
||||||
|
* TIDE one slow sine on the timbre ([FrasilClock]). Then, per voice, FRASIL's mix
|
||||||
|
* stages: a DC blocker, WARMTH (tanh) and the BODY high-pass.
|
||||||
|
*
|
||||||
|
* Differences from FRASIL, all because Sizzle's voices are mono and per note: the
|
||||||
|
* stereo buses are summed (centre + sides at -3 dB), there is no pan, no pressure,
|
||||||
|
* no voice shedding, the noise is the voice's own, warmth and the DC blocker run on
|
||||||
|
* each voice instead of the mix, every parameter glides toward its patch value per
|
||||||
|
* block (FRASIL glides them globally), and the partials' levels are always ramped
|
||||||
|
* over the block. Rendering is FRASIL's: a block of [BLOCK] frames sets the voice
|
||||||
|
* up, chunks of [CH] frames are computed at once and handed out a sample at a time
|
||||||
|
* by [render]. Allocation-free after construction.
|
||||||
|
*/
|
||||||
|
class FrasilVoice(private val fs: Int) {
|
||||||
|
|
||||||
|
private val invFs = 1f / fs
|
||||||
|
private val r44 = 44100f / fs // FRASIL's per-step constants were made at 44.1 kHz
|
||||||
|
private val nyq = 0.45f * fs
|
||||||
|
|
||||||
|
var note = -1; private set
|
||||||
|
private var gate = false
|
||||||
|
private var vel = 0f
|
||||||
|
private var env = 0f
|
||||||
|
private var lvl = 0f
|
||||||
|
private var patch: FrasilPatch = FrasilPatch.DEFAULT
|
||||||
|
private var prime = true
|
||||||
|
private val cur = FloatArray(FrasilDefs.N)
|
||||||
|
private var type = 0
|
||||||
|
private var ageFrames = 0L
|
||||||
|
private var tideV = 0f
|
||||||
|
private var rng: Int = nextSeed()
|
||||||
|
|
||||||
|
// drift, each about -1..1
|
||||||
|
private val ouC = FloatArray(3)
|
||||||
|
private var ouCut = 0f
|
||||||
|
private val ouPa = FloatArray(NP)
|
||||||
|
private val ouPf = FloatArray(NP)
|
||||||
|
private val ouR = FloatArray(NR)
|
||||||
|
|
||||||
|
// CHOIR
|
||||||
|
private val cph = FloatArray(3)
|
||||||
|
private val cdt = FloatArray(3)
|
||||||
|
private val cid = FloatArray(3)
|
||||||
|
private val cw = FloatArray(3)
|
||||||
|
private val cpw = FloatArray(3)
|
||||||
|
private var csh = 0f
|
||||||
|
private var sc0 = 0f; private var sc1 = 0f; private var sc2 = 1f
|
||||||
|
private var sp0 = 0f; private var sp1 = 0f; private var sp2 = 1f
|
||||||
|
private val clp = FloatArray(4)
|
||||||
|
private var ca = 0f
|
||||||
|
private var sa1 = 0f; private var sa2 = 0f; private var sa3 = 0f
|
||||||
|
private var cgain = 1f
|
||||||
|
private val cint = FloatArray(6)
|
||||||
|
private var csvf = false
|
||||||
|
|
||||||
|
// PARTIALS
|
||||||
|
private val px = FloatArray(NP); private val py = FloatArray(NP); private val pa = FloatArray(NP)
|
||||||
|
private val ps = FloatArray(NP); private val pc = FloatArray(NP)
|
||||||
|
private val pac = FloatArray(NP); private val pda = FloatArray(NP); private val pbt = FloatArray(NP)
|
||||||
|
private var np = 0
|
||||||
|
|
||||||
|
// BREATH
|
||||||
|
private val r1 = FloatArray(NR); private val r2 = FloatArray(NR)
|
||||||
|
private val rb1 = FloatArray(NR); private val rb2 = FloatArray(NR); private val rg = FloatArray(NR)
|
||||||
|
private var nlp = 0f
|
||||||
|
|
||||||
|
// the voice's output stages
|
||||||
|
private var dcState = 0f
|
||||||
|
private var thinState = 0f
|
||||||
|
private var ka = 0f; private var kr = 0f
|
||||||
|
private var dk = 1f; private var dmake = 1f; private var driveOn = false
|
||||||
|
private var thinA = 0f; private var thin = false
|
||||||
|
private val kdc = brK(0.0014f)
|
||||||
|
private val glideK = brK(0.2f)
|
||||||
|
private val tideK = 1f - exp(-BLOCK.toFloat() / (fs * TIDE_SMOOTH_S))
|
||||||
|
|
||||||
|
// chunk buffers
|
||||||
|
private val bc = FloatArray(CH); private val ba = FloatArray(CH); private val bb = FloatArray(CH)
|
||||||
|
private val x0 = FloatArray(CH); private val x1 = FloatArray(CH); private val xc = FloatArray(CH)
|
||||||
|
private val nz = FloatArray(CH)
|
||||||
|
private val out = FloatArray(CH)
|
||||||
|
private var pos = CH
|
||||||
|
private var chunk = 0
|
||||||
|
private var ending = false
|
||||||
|
|
||||||
|
val isActive: Boolean get() = note >= 0
|
||||||
|
val isGated: Boolean get() = note >= 0 && gate
|
||||||
|
|
||||||
|
/** Start [midi] at [velocity] (0..1). A voice still sounding goes on from where it
|
||||||
|
* is (FRASIL's same-note / steal rule: its phases continue, no click). */
|
||||||
|
fun noteOn(midi: Int, velocity: Float, p: FrasilPatch) {
|
||||||
|
val fresh = note < 0
|
||||||
|
note = midi
|
||||||
|
gate = true
|
||||||
|
vel = velocity.coerceIn(0f, 1f)
|
||||||
|
patch = p
|
||||||
|
ageFrames = 0
|
||||||
|
ending = false
|
||||||
|
chunk = 0 // the new pitch from the next chunk on
|
||||||
|
if (fresh) start()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun noteOff() { gate = false }
|
||||||
|
|
||||||
|
/** Silence now, no tail. */
|
||||||
|
fun kill() {
|
||||||
|
note = -1; gate = false; env = 0f; lvl = 0f; pos = CH; ending = false
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A gliding engine value now (a [FrasilDefs] index), for tests. */
|
||||||
|
internal fun valueForTest(i: Int): Float = cur[i]
|
||||||
|
|
||||||
|
/** Follow edits while sounding: the values glide there over ~25 ms. */
|
||||||
|
fun setPatch(p: FrasilPatch) { patch = p }
|
||||||
|
|
||||||
|
fun render(): Float {
|
||||||
|
if (pos >= CH) {
|
||||||
|
if (note < 0) return 0f
|
||||||
|
if (ending) { note = -1; ending = false; return 0f }
|
||||||
|
renderChunk()
|
||||||
|
pos = 0
|
||||||
|
}
|
||||||
|
return out[pos++]
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------- start ---
|
||||||
|
private fun start() {
|
||||||
|
env = 0f; lvl = 0f; pos = CH; prime = true
|
||||||
|
dcState = 0f; thinState = 0f; nlp = 0f
|
||||||
|
for (k in 0 until 3) {
|
||||||
|
cph[k] = urand()
|
||||||
|
cpw[k] = k * 0.33f
|
||||||
|
ouC[k] = randf() * 0.5f
|
||||||
|
}
|
||||||
|
clp.fill(0f); cint.fill(0f); csvf = false
|
||||||
|
for (k in 0 until NP) { // random phases: no peak where they all start together
|
||||||
|
val ph = urand() * TWO_PI
|
||||||
|
px[k] = cos(ph); py[k] = sin(ph)
|
||||||
|
ps[k] = 0f; pc[k] = 1f
|
||||||
|
ouPa[k] = randf() * 0.5f; ouPf[k] = randf() * 0.5f
|
||||||
|
pac[k] = 0f; pda[k] = 0f
|
||||||
|
pbt[k] = urand()
|
||||||
|
}
|
||||||
|
for (k in 0 until NR) { r1[k] = 0f; r2[k] = 0f; ouR[k] = randf() * 0.5f }
|
||||||
|
ouCut = randf() * 0.5f
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------- block ---
|
||||||
|
private fun block() {
|
||||||
|
val p = patch
|
||||||
|
val b = p.b
|
||||||
|
val m = if (b == null) 0f else morphPosition(p)
|
||||||
|
val gk = if (prime) 1f else glideK
|
||||||
|
for (i in 0 until FrasilDefs.N) {
|
||||||
|
val t = if (b == null) p.a[i] else p.a[i] + (b[i] - p.a[i]) * m
|
||||||
|
cur[i] += (t - cur[i]) * gk
|
||||||
|
}
|
||||||
|
type = if (b != null && m >= 0.5f) p.bType else p.aType
|
||||||
|
val period = 300f * (1f / 30f).pow(cur[TIDE_RATE])
|
||||||
|
val ph = FrasilClock.seconds / period
|
||||||
|
val tideT = sin(TWO_PI * (ph - floor(ph)).toFloat())
|
||||||
|
tideV = if (prime) tideT else tideV + (tideT - tideV) * tideK
|
||||||
|
val wasPrime = prime
|
||||||
|
prime = false
|
||||||
|
ageFrames += BLOCK
|
||||||
|
|
||||||
|
drift()
|
||||||
|
voiceBlock(wasPrime)
|
||||||
|
|
||||||
|
// envelope: a one-pole a chunk to the target, a third of the time a time constant
|
||||||
|
ka = 1f - exp(-CH * invFs * 3f / (0.005f * 6000f.pow(cur[ATTACK])))
|
||||||
|
kr = 1f - exp(-CH * invFs * 3f / (0.05f * 1200f.pow(cur[RELEASE])))
|
||||||
|
val full = cur[BODY]
|
||||||
|
dk = 1f + 5f * cur[WARMTH] * full
|
||||||
|
dmake = 1f / tanh(dk * 0.35f) * 0.35f
|
||||||
|
driveOn = cur[WARMTH] * full > 0.001f
|
||||||
|
thin = full < 0.995f
|
||||||
|
thinA = 1f - exp(-TWO_PI * 20f * 20f.pow(1f - full) * invFs)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Where this note is between the sound (0) and MORPH TO's (1): MORPH, then with
|
||||||
|
* MORPH TIME a smoothstep from there to 1 while the note is held. */
|
||||||
|
private fun morphPosition(p: FrasilPatch): Float {
|
||||||
|
if (p.morphTime <= 0f) return p.morph
|
||||||
|
val x = ((ageFrames.toFloat() * invFs) / p.morphTime).coerceIn(0f, 1f)
|
||||||
|
return p.morph + (1f - p.morph) * x * x * (3f - 2f * x)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** One Ornstein-Uhlenbeck step: back toward 0 by th, a kick of s (unit variance:
|
||||||
|
* three uniforms). */
|
||||||
|
private fun ou(x: Float, th: Float, s: Float): Float =
|
||||||
|
(x - th * x + s * (randf() + randf() + randf())).coerceIn(-1.5f, 1.5f)
|
||||||
|
|
||||||
|
private fun drift() {
|
||||||
|
val tau = 20f * 0.025f.pow(cur[MOTION_RATE]) // 20 s .. 0.5 s
|
||||||
|
val th = BLOCK * invFs / tau
|
||||||
|
val s = 0.6f * sqrt(2f * th)
|
||||||
|
val te = th * (1f + 3f * cur[EVOLVE])
|
||||||
|
val se = 0.6f * sqrt(2f * te)
|
||||||
|
for (k in 0 until 3) ouC[k] = ou(ouC[k], th, s)
|
||||||
|
for (k in 0 until NP) { ouPa[k] = ou(ouPa[k], te, se); ouPf[k] = ou(ouPf[k], th, s) }
|
||||||
|
for (k in 0 until NR) ouR[k] = ou(ouR[k], th, s)
|
||||||
|
ouCut = ou(ouCut, th, s)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun voiceBlock(fresh: Boolean) {
|
||||||
|
val c = cur
|
||||||
|
val f = 440f * 2f.pow((note - 69) / 12f)
|
||||||
|
val m = c[MOTION]
|
||||||
|
val mw = m * (1f + 2f * m) // MOTION's wander: twice as wide half-way, three times at the top
|
||||||
|
val bright = (c[TIMBRE] - 0.5f) + tideV * c[TIDE] * 0.5f
|
||||||
|
val full = c[BODY]
|
||||||
|
|
||||||
|
// CHOIR: the saws' tunings, SHAPE's widths, the low-pass, RESONANCE's state-variable
|
||||||
|
if (c[CHOIR] > 0.001f) {
|
||||||
|
val dc = c[DETUNE] * c[DETUNE] * 40f * (0.2f + 0.8f * full)
|
||||||
|
val sh = c[SHAPE]
|
||||||
|
val a = if (sh < 0.5f) 2f * sh else 1f
|
||||||
|
val w = if (sh < 0.5f) 0.5f else 0.5f - 0.8f * (sh - 0.5f)
|
||||||
|
val sw = if (sh > 0.5f) 0.03f + 0.18f * (sh - 0.5f) else 0.03f * a
|
||||||
|
for (j in 0 until 3) {
|
||||||
|
val cents = SIDE[j] * dc + mw * 7f * ouC[j]
|
||||||
|
cdt[j] = (f * (if (j == 0) c[INTERVAL] else 1f) * 2f.pow(cents / 1200f) * invFs).coerceIn(1e-6f, 0.45f)
|
||||||
|
cid[j] = 1f / cdt[j]
|
||||||
|
cpw[j] += PWR[j] * BLOCK * invFs
|
||||||
|
cpw[j] -= floor(cpw[j])
|
||||||
|
cw[j] = (w + sw * sin(TWO_PI * cpw[j]) + 0.1f * mw * ouC[j] * a).coerceIn(0.04f, 0.96f)
|
||||||
|
}
|
||||||
|
csh = a
|
||||||
|
val ce = (c[CUTOFF] + bright * 0.6f + mw * 0.2f * ouCut).coerceIn(0f, 1f)
|
||||||
|
val hc = 1f + 39f * ce * ce
|
||||||
|
val fc = (f * hc).coerceIn(20f, minOf(16000f, nyq))
|
||||||
|
ca = 1f - exp(-TWO_PI * fc * invFs)
|
||||||
|
val pv = (1f + a * a) / 3f - 2f * a * (1f / 3f - 2f * w * (1f - w)) // a saw minus a of it w on: its power
|
||||||
|
cgain = sqrt((1f / 3f) / (if (pv > 0.05f) pv else 0.05f))
|
||||||
|
if (c[CH_RESO] > 0.002f || type != 0) {
|
||||||
|
val g = tan(PI * fc * invFs)
|
||||||
|
val q = 0.5f * 40f.pow(c[CH_RESO])
|
||||||
|
val k = 1f / q
|
||||||
|
sa1 = 1f / (1f + g * (g + k)); sa2 = g * sa1; sa3 = g * sa2
|
||||||
|
when (type) {
|
||||||
|
1 -> { sc0 = 0f; sc1 = k * (1.4f + 0.12f * sqrt(hc)) * sqrt(q); sc2 = 0f } // band, peak at 1
|
||||||
|
2 -> { // high, made up
|
||||||
|
val mk = sqrt(0.75f * hc).coerceIn(1f, 4f)
|
||||||
|
sc0 = mk; sc1 = -k * mk; sc2 = -mk
|
||||||
|
}
|
||||||
|
else -> { sc0 = 0f; sc1 = 0f; sc2 = 1f }
|
||||||
|
}
|
||||||
|
cgain *= 1f / sqrt(1f + 0.22f * (q - 0.5f))
|
||||||
|
}
|
||||||
|
if (fresh) { sp0 = sc0; sp1 = sc1; sp2 = sc2 }
|
||||||
|
}
|
||||||
|
|
||||||
|
// PARTIALS: frequencies (stretched, drifting), amplitudes (tilt, odd, drift), levelled
|
||||||
|
if (c[PARTIALS] > 0.001f) {
|
||||||
|
val pe = (c[TILT] - bright * 0.7f).coerceIn(0f, 1f)
|
||||||
|
val pw = 0.3f + 2.7f * pe
|
||||||
|
val sx = 1f + 0.12f * c[STRETCH]
|
||||||
|
val fnp = 2f + 6f * full
|
||||||
|
var nmax = fnp.toInt()
|
||||||
|
var top = fnp - nmax
|
||||||
|
if (top > 0.001f) nmax++ else top = 1f
|
||||||
|
if (nmax > NP) nmax = NP
|
||||||
|
var sum2 = 0f
|
||||||
|
var n = 0
|
||||||
|
for (j in 0 until nmax) {
|
||||||
|
val fk = f * 2f.pow(sx * LOG2K[j] + mw * 5f * ouPf[j] / 1200f)
|
||||||
|
if (fk > minOf(15000f, nyq)) break
|
||||||
|
val w = TWO_PI * fk * invFs
|
||||||
|
// the oscillator: back to its phasor, renormalised, on with this block's step (a half-angle rotation)
|
||||||
|
val cw0 = cos(w); val sn = sin(w)
|
||||||
|
val q = sqrt(2f * (1f + cw0))
|
||||||
|
var x = px[j]
|
||||||
|
var y = (py[j] - x * ps[j]) * pc[j]
|
||||||
|
val gn = 1.5f - 0.5f * (x * x + y * y)
|
||||||
|
val shh = sn / q
|
||||||
|
val chh = (1f + cw0) / q
|
||||||
|
x *= gn; y *= gn
|
||||||
|
ps[j] = shh
|
||||||
|
pc[j] = q / (1f + cw0)
|
||||||
|
px[j] = x
|
||||||
|
py[j] = y * chh + x * shh
|
||||||
|
var a = 2f.pow(-pw * LOG2K[j] + 1.6f * (m + 2.5f * c[EVOLVE]) * ouPa[j])
|
||||||
|
if (j and 1 == 1) a *= 1f - c[ODD] // the even harmonics (2, 4 ...)
|
||||||
|
val pk = c[PEAK]
|
||||||
|
if (pk > 0.001f) { // the formant
|
||||||
|
val d = (sx * LOG2K[j] - c[FORMANT]) * (1.5f + 4f * pk)
|
||||||
|
val fl = 1f - 0.97f * pk
|
||||||
|
a *= fl + (1f + 7f * pk - fl) / (1f + d * d)
|
||||||
|
}
|
||||||
|
if (j + 1 == nmax) a *= top
|
||||||
|
pa[j] = a
|
||||||
|
sum2 += a * a
|
||||||
|
n++
|
||||||
|
}
|
||||||
|
np = n
|
||||||
|
val norm = 0.6f / sqrt(sum2 + 1e-9f)
|
||||||
|
for (j in 0 until n) pa[j] *= norm
|
||||||
|
if (c[BEAT] > 0.001f) { // BEAT: each one pulsing at its own pace
|
||||||
|
val bt = c[BEAT]
|
||||||
|
val dep = minOf(1f, bt * 1.4f)
|
||||||
|
val hz = 0.15f + 5f * bt * bt
|
||||||
|
for (j in 0 until n) {
|
||||||
|
pbt[j] += hz * BEAT_SPREAD[j] * BLOCK * invFs
|
||||||
|
pbt[j] -= floor(pbt[j])
|
||||||
|
pa[j] *= (1f - dep * (0.5f + 0.5f * sin(TWO_PI * pbt[j]))) / (1f - 0.5f * dep)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (j in 0 until n) pda[j] = (pa[j] - pac[j]) / BLOCK
|
||||||
|
for (j in n until NP) { pac[j] = 0f; pda[j] = 0f }
|
||||||
|
}
|
||||||
|
|
||||||
|
// BREATH: resonators at the note x ratios (COLOR between the sets), levelled so
|
||||||
|
// the loudness follows neither Q nor pitch: y = g x + b1 y1 - b2 y2
|
||||||
|
if (c[BREATH] > 0.001f) {
|
||||||
|
var col = c[COLOR].coerceIn(0f, 1f) * 2f
|
||||||
|
val lo = col < 1f
|
||||||
|
val ra = RATIO_L2[if (lo) 0 else 1]
|
||||||
|
val rb = RATIO_L2[if (lo) 1 else 2]
|
||||||
|
if (!lo) col -= 1f
|
||||||
|
val q = 2f * 300f.pow((c[RESONANCE] + mw * 0.1f * ouR[0]).coerceIn(0f, 1f))
|
||||||
|
val sb = (0.55f + bright * 0.8f).coerceIn(0.05f, 1f)
|
||||||
|
for (j in 0 until NR) {
|
||||||
|
val l2 = ra[j] + (rb[j] - ra[j]) * col + mw * 12f * ouR[j] / 1200f
|
||||||
|
val fr = (f * c[BR_PITCH] * 2f.pow(l2)).coerceIn(20f, minOf(16000f, nyq))
|
||||||
|
val r = exp(-PI * fr / q * invFs).toDouble()
|
||||||
|
val b1 = 2.0 * r * cos(TWO_PI * fr * invFs).toDouble()
|
||||||
|
val b2 = r * r
|
||||||
|
val ng = (1.0 + b2) / ((1.0 - b2) * ((1.0 + b2) * (1.0 + b2) - b1 * b1)) // the sum of h^2
|
||||||
|
rb1[j] = b1.toFloat(); rb2[j] = b2.toFloat()
|
||||||
|
rg[j] = (0.4 * sqrt(3.0 / ng)).toFloat() * (if (j == 0) 1f else sb * (if (j == 2) sb else 1f))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------- chunk ---
|
||||||
|
private fun renderChunk() {
|
||||||
|
if (chunk == 0) block()
|
||||||
|
chunk = (chunk + 1) % (BLOCK / CH)
|
||||||
|
val c = cur
|
||||||
|
env += ((if (gate) 1f else 0f) - env) * (if (gate) ka else kr)
|
||||||
|
val level = (1f - c[VELOCITY] + c[VELOCITY] * vel) * VOICE_G
|
||||||
|
val g1 = if (!gate && env < TAIL_END) 0f else level * env * env
|
||||||
|
var g = lvl
|
||||||
|
lvl = g1
|
||||||
|
val dg = (g1 - g) / CH
|
||||||
|
bc.fill(0f); ba.fill(0f); bb.fill(0f)
|
||||||
|
val 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) }
|
||||||
|
|
||||||
|
// a guard: a voice gone wild or not a number never reaches the mix; it starts again
|
||||||
|
val z = bc[CH - 1] + ba[CH - 1] + bb[CH - 1] + bc[CH / 2] + ba[CH / 2] + bb[CH / 2]
|
||||||
|
if (!(z > -1e4f && z < 1e4f)) {
|
||||||
|
bc.fill(0f); ba.fill(0f); bb.fill(0f)
|
||||||
|
start()
|
||||||
|
prime = false
|
||||||
|
}
|
||||||
|
|
||||||
|
var dcs = dcState
|
||||||
|
var th = thinState
|
||||||
|
for (i in 0 until CH) {
|
||||||
|
g += dg
|
||||||
|
var x = (bc[i] + SIDE_GAIN * (ba[i] + bb[i])) * g
|
||||||
|
dcs += kdc * (x - dcs)
|
||||||
|
x -= dcs
|
||||||
|
if (driveOn) x = tanh(x * dk) * dmake
|
||||||
|
if (thin) { th += thinA * (x - th); x -= th }
|
||||||
|
out[i] = x * OUT_GAIN
|
||||||
|
}
|
||||||
|
dcState = flush(dcs)
|
||||||
|
thinState = if (thin) flush(th) else 0f
|
||||||
|
if (g1 == 0f && !gate && env < TAIL_END) ending = true
|
||||||
|
}
|
||||||
|
|
||||||
|
/** CHOIR's saws into the two sides (left: centre + -detune, right: centre + +detune),
|
||||||
|
* then their filters into [ba] / [bb] at [g0]. */
|
||||||
|
private fun choirChunk(g0: Float) {
|
||||||
|
val svf = cur[CH_RESO] > 0.002f || type != 0
|
||||||
|
val sq = cur[SHAPE] > 0.002f
|
||||||
|
val soft = cur[SOFT] > 0.002f
|
||||||
|
if (svf != csvf) { // the other filter: the low-pass's state carried over
|
||||||
|
clp[0] = if (svf) 0f else clp[1]
|
||||||
|
clp[2] = if (svf) 0f else clp[3]
|
||||||
|
csvf = svf
|
||||||
|
}
|
||||||
|
val g = g0 * cgain
|
||||||
|
var p0 = cph[0]; var p1 = cph[1]; var p2 = cph[2]
|
||||||
|
val d0 = cdt[0]; val d1 = cdt[1]; val d2 = cdt[2]
|
||||||
|
val i0 = cid[0]; val i1 = cid[1]; val i2 = cid[2]
|
||||||
|
val sh = csh; val w0 = cw[0]; val w1 = cw[1]; val w2 = cw[2]
|
||||||
|
for (i in 0 until CH) {
|
||||||
|
p0 += d0; if (p0 >= 1f) p0 -= 1f
|
||||||
|
p1 += d1; if (p1 >= 1f) p1 -= 1f
|
||||||
|
p2 += d2; if (p2 >= 1f) p2 -= 1f
|
||||||
|
var s0 = 2f * p0 - 1f - blep(p0, d0, i0)
|
||||||
|
var s1 = 2f * p1 - 1f - blep(p1, d1, i1)
|
||||||
|
var s2 = 2f * p2 - 1f - blep(p2, d2, i2)
|
||||||
|
if (sq) { // each minus its share of itself a width on: a pulse
|
||||||
|
var q0 = p0 + w0; if (q0 >= 1f) q0 -= 1f
|
||||||
|
var q1 = p1 + w1; if (q1 >= 1f) q1 -= 1f
|
||||||
|
var q2 = p2 + w2; if (q2 >= 1f) q2 -= 1f
|
||||||
|
s0 -= sh * (2f * q0 - 1f - blep(q0, d0, i0))
|
||||||
|
s1 -= sh * (2f * q1 - 1f - blep(q1, d1, i1))
|
||||||
|
s2 -= sh * (2f * q2 - 1f - 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) {
|
||||||
|
// SOFT: integrated once (the square a triangle), then twice (near a sine), each saw at
|
||||||
|
// its own gain (its fundamental kept), a leak at a sixth of it; crossfaded by quarter turns
|
||||||
|
val kc = TWO_PI * d0; val ks = TWO_PI * d1
|
||||||
|
val lc = 1f - 0.15f * kc; val ls = 1f - 0.15f * ks
|
||||||
|
val u = cur[SOFT]
|
||||||
|
val a0: Float; val a1: Float; val a2: Float
|
||||||
|
if (u < 0.5f) { a0 = cos(PI * u); a1 = sin(PI * u); a2 = 0f }
|
||||||
|
else { a0 = 0f; a1 = cos(PI * (u - 0.5f)); a2 = sin(PI * (u - 0.5f)) }
|
||||||
|
val c1 = a1 * kc; val c2 = a2 * kc * kc; val e1 = a1 * ks; val e2 = a2 * ks * ks
|
||||||
|
var cA = cint[0]; var cB = cint[1]; var l1 = cint[2]; var l2 = cint[3]; var q1 = cint[4]; var q2 = cint[5]
|
||||||
|
for (j in 0 until CH) {
|
||||||
|
val vc = xc[j]; val vl = x0[j]; val 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
|
||||||
|
val 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 = 0f; cB = 0f; l1 = 0f; l2 = 0f; q1 = 0f; q2 = 0f
|
||||||
|
}
|
||||||
|
cint[0] = cA; cint[1] = cB; cint[2] = l1; cint[3] = l2; cint[4] = q1; cint[5] = q2
|
||||||
|
} else {
|
||||||
|
cint.fill(0f)
|
||||||
|
}
|
||||||
|
if (svf) { // the type's mix, gliding to sc over the chunk
|
||||||
|
val o0 = sp0 * g; val o1 = sp1 * g; val o2 = sp2 * g
|
||||||
|
val e0 = (sc0 - sp0) * g / CH; val e1 = (sc1 - sp1) * g / CH; val 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 {
|
||||||
|
val a = ca
|
||||||
|
var l1 = clp[0]; var l2 = clp[1]; var q1 = clp[2]; var q2 = clp[3]
|
||||||
|
for (i in 0 until CH) {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun svfRun(b: FloatArray, x: FloatArray, s: Int, o0i: Float, o1i: Float, o2i: Float,
|
||||||
|
e0: Float, e1: Float, e2: Float) {
|
||||||
|
var s1 = clp[s]; var s2 = clp[s + 1]
|
||||||
|
var o0 = o0i; var o1 = o1i; var o2 = o2i
|
||||||
|
val a1 = sa1; val a2 = sa2; val a3 = sa3
|
||||||
|
for (i in 0 until CH) {
|
||||||
|
val v = x[i] - s2
|
||||||
|
val t1 = a1 * s1 + a2 * v
|
||||||
|
val t2 = s2 + a2 * s1 + a3 * v
|
||||||
|
s1 = 2f * t1 - s1
|
||||||
|
s2 = 2f * t2 - s2
|
||||||
|
b[i] += o0 * x[i] + o1 * t1 + o2 * t2
|
||||||
|
o0 += e0; o1 += e1; o2 += e2
|
||||||
|
}
|
||||||
|
clp[s] = s1; clp[s + 1] = s2
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The fundamental in the centre; harmonics 2, 4, 6, 8 to one side, 3, 5, 7 to the other. */
|
||||||
|
private fun partialsChunk(g: Float) {
|
||||||
|
for (j in 0 until np) {
|
||||||
|
val bus = when (j) { 0 -> bc; 1, 3, 5, 7 -> ba; else -> bb }
|
||||||
|
var x = px[j]; var y = py[j]
|
||||||
|
val e = 2f * ps[j]
|
||||||
|
var a = pac[j] * g
|
||||||
|
val d = pda[j] * g
|
||||||
|
for (i in 0 until CH) {
|
||||||
|
x -= e * y
|
||||||
|
y += e * x
|
||||||
|
bus[i] += a * x
|
||||||
|
a += d
|
||||||
|
}
|
||||||
|
px[j] = x; py[j] = y
|
||||||
|
pac[j] += pda[j] * CH
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** BREATH's source for the chunk: a hiss (white, variance 1/3) or GRAIN's sparse
|
||||||
|
* grains (as loud on average); TONE darker (a low-pass) or brighter (a high-pass). */
|
||||||
|
private fun breathNoise() {
|
||||||
|
val grain = cur[GRAIN]
|
||||||
|
if (grain < 0.002f) {
|
||||||
|
for (i in 0 until CH) nz[i] = randf()
|
||||||
|
} else {
|
||||||
|
val p = 2f.pow(-13f * grain) * r44
|
||||||
|
val amp = minOf(16f, sqrt(1f / (3f * 0.5833f * p)))
|
||||||
|
val th = (p * 16777216f).toInt()
|
||||||
|
for (i in 0 until CH) {
|
||||||
|
val r = nextRand()
|
||||||
|
val a = amp * (0.5f + (r and 255) * (0.5f / 255f))
|
||||||
|
nz[i] = if ((r ushr 8) < th) (if (r and 256 != 0) a else -a) else 0f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val t = cur[TONE]
|
||||||
|
if (t < -0.01f) {
|
||||||
|
val fc = 16000f * (300f / 16000f).pow(-t)
|
||||||
|
val a = 1f - exp(-TWO_PI * minOf(fc, nyq) * invFs)
|
||||||
|
val gn = sqrt((2f - a) / a)
|
||||||
|
var l = nlp
|
||||||
|
for (i in 0 until CH) { l += a * (nz[i] - l); nz[i] = l * gn }
|
||||||
|
nlp = flush(l)
|
||||||
|
} else if (t > 0.01f) {
|
||||||
|
val fc = 20f * 150f.pow(t)
|
||||||
|
val a = 1f - exp(-TWO_PI * fc * invFs)
|
||||||
|
val gn = 1f / sqrt(1f + a / (2f - a) - 2f * a)
|
||||||
|
var l = nlp
|
||||||
|
for (i in 0 until CH) { l += a * (nz[i] - l); nz[i] = (nz[i] - l) * gn }
|
||||||
|
nlp = flush(l)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun souffleChunk(g: Float) {
|
||||||
|
val air = cur[AIR]
|
||||||
|
val ga = air * 0.7f * g
|
||||||
|
for (j in 0 until NR) {
|
||||||
|
val bus = when (j) { 0 -> bc; 1 -> ba; else -> bb }
|
||||||
|
var y1 = r1[j]; var y2 = r2[j]
|
||||||
|
val b1 = rb1[j]; val b2 = rb2[j]; val gg = rg[j] * g
|
||||||
|
val withAir = j == 0 && air > 0.001f
|
||||||
|
for (i in 0 until CH) {
|
||||||
|
val y = gg * nz[i] + b1 * y1 - b2 * y2
|
||||||
|
y2 = y1; y1 = y
|
||||||
|
bus[i] += if (withAir) y + ga * nz[i] else y
|
||||||
|
}
|
||||||
|
if (y1 > -1e-20f && y1 < 1e-20f && y2 > -1e-20f && y2 < 1e-20f) { y1 = 0f; y2 = 0f }
|
||||||
|
r1[j] = y1; r2[j] = y2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------- helpers ---
|
||||||
|
private fun brK(k: Float): Float = 1f - (1f - k).pow(r44)
|
||||||
|
|
||||||
|
/** 32-bit xorshift: the noise and the drift. */
|
||||||
|
private fun nextRand(): Int {
|
||||||
|
var x = rng
|
||||||
|
x = x xor (x shl 13)
|
||||||
|
x = x xor (x ushr 17)
|
||||||
|
x = x xor (x shl 5)
|
||||||
|
rng = x
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun randf(): Float = nextRand() * (1f / 2147483648f) // -1..1
|
||||||
|
private fun urand(): Float = (nextRand() ushr 8) * (1f / 16777216f) // 0..1
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val NP = 8
|
||||||
|
const val NR = 3
|
||||||
|
const val CH = 64
|
||||||
|
const val BLOCK = 256
|
||||||
|
private const val VOICE_G = 0.2f
|
||||||
|
private const val TAIL_END = 0.01f // a released voice ends here: its gain (env^2) 80 dB down
|
||||||
|
private const val SIDE_GAIN = 0.70710678f // the stereo sides summed into mono at -3 dB
|
||||||
|
/** Brings a held FRASIL voice to about the level of a Sizzle synth note. */
|
||||||
|
private const val OUT_GAIN = 2.2f
|
||||||
|
private const val TIDE_SMOOTH_S = 0.5f
|
||||||
|
private const val PI = 3.14159265f
|
||||||
|
private const val TWO_PI = 6.2831853f
|
||||||
|
private val SIDE = floatArrayOf(0f, -1f, 1f)
|
||||||
|
private val PWR = floatArrayOf(0.21f, 0.29f, 0.37f) // the widths' sways, Hz
|
||||||
|
private val LOG2K = floatArrayOf(0f, 1f, 1.5849625f, 2f, 2.3219281f, 2.5849625f, 2.8073549f, 3f)
|
||||||
|
private val BEAT_SPREAD = floatArrayOf(0.55f, 1.25f, 0.8f, 1.45f, 0.65f, 1.1f, 0.95f, 1.35f)
|
||||||
|
/** BREATH's ratios (log2), COLOR across them: harmonic, odd, bell (a free bar's modes). */
|
||||||
|
private val RATIO_L2: Array<FloatArray> = arrayOf(
|
||||||
|
floatArrayOf(1f, 2f, 3f), floatArrayOf(1f, 3f, 5f), floatArrayOf(1f, 2.756f, 5.404f),
|
||||||
|
).map { r -> FloatArray(NR) { (ln(r[it].toDouble()) / ln(2.0)).toFloat() } }.toTypedArray()
|
||||||
|
|
||||||
|
private var seeds = 0x2545F491
|
||||||
|
private fun nextSeed(): Int {
|
||||||
|
seeds += 0x6D2B79F5
|
||||||
|
return if (seeds == 0) 0x2545F491 else seeds
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A blep with the step's inverse. */
|
||||||
|
private fun blep(t0: Float, dt: Float, idt: Float): Float {
|
||||||
|
if (t0 < dt) { val t = t0 * idt; return t + t - t * t - 1f }
|
||||||
|
if (t0 > 1f - dt) { val t = (t0 - 1f) * idt; return t * t + t + t + 1f }
|
||||||
|
return 0f
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun flush(x: Float): Float = if (x > -1e-20f && x < 1e-20f) 0f else x
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
package cc.tiredsysadmin.android.sizzle.frasil
|
||||||
|
|
||||||
|
import cc.tiredsysadmin.android.sizzle.audio.SynthPatch
|
||||||
|
import cc.tiredsysadmin.android.sizzle.audio.SynthVoice
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.ToolboxSlot
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.ToolboxType
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Test
|
||||||
|
import kotlin.math.abs
|
||||||
|
import kotlin.math.sqrt
|
||||||
|
|
||||||
|
class FrasilVoiceTest {
|
||||||
|
|
||||||
|
private val fs = 48_000
|
||||||
|
|
||||||
|
private fun slot(preset: String? = null, vararg extra: Pair<String, String>): ToolboxSlot =
|
||||||
|
ToolboxSlot(0).apply {
|
||||||
|
fill(ToolboxType.MORPH_PAD)
|
||||||
|
preset?.let { n -> FrasilDefs.FACTORY.first { it.name == n }.values.forEach { (k, v) -> set(k, v) } }
|
||||||
|
extra.forEach { (k, v) -> set(k, v) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private class Stats(val rms: Float, val peak: Float, val finite: Boolean)
|
||||||
|
|
||||||
|
private fun render(v: FrasilVoice, frames: Int): Stats {
|
||||||
|
var sum = 0.0; var peak = 0f; var finite = true
|
||||||
|
repeat(frames) {
|
||||||
|
val x = v.render()
|
||||||
|
if (!x.isFinite()) finite = false
|
||||||
|
sum += x * x; peak = maxOf(peak, abs(x))
|
||||||
|
}
|
||||||
|
return Stats(sqrt(sum / frames).toFloat(), peak, finite)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun everyFactorySoundPlaysFiniteBoundedAndFreesAfterRelease() {
|
||||||
|
assertEquals(36, FrasilDefs.FACTORY.size)
|
||||||
|
for (p in FrasilDefs.FACTORY) {
|
||||||
|
val v = FrasilVoice(fs)
|
||||||
|
v.noteOn(48, 0.8f, FrasilPatch.from(slot(p.name)))
|
||||||
|
val held = render(v, fs * 3)
|
||||||
|
assertTrue("${p.name} finite", held.finite)
|
||||||
|
assertTrue("${p.name} sounds (rms ${held.rms})", held.rms > 0.003f)
|
||||||
|
// Sparse GRAIN clicks ring the resonators past the steady level (FRASIL's crackle);
|
||||||
|
// the master limiter takes those. The body of every sound stays well under.
|
||||||
|
assertTrue("${p.name} peak ${held.peak}", held.peak < 1.5f)
|
||||||
|
assertTrue("${p.name} rms ${held.rms}", held.rms < 0.5f)
|
||||||
|
println("${p.name}: rms ${"%.3f".format(held.rms)} peak ${"%.3f".format(held.peak)}")
|
||||||
|
v.noteOff()
|
||||||
|
// RELEASE tops out at 60 s (a time constant a third of it): the tail ends well inside 70 s.
|
||||||
|
var frames = 0
|
||||||
|
while (v.isActive && frames < fs * 70) { v.render(); frames++ }
|
||||||
|
assertFalse("${p.name} frees after its release", v.isActive)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun pitchFollowsTheNote() {
|
||||||
|
// STILL: partials alone, darkest tilt: nearly a sine at the note.
|
||||||
|
val v = FrasilVoice(fs)
|
||||||
|
v.noteOn(69, 1f, FrasilPatch.from(slot("Still", "motion" to "0.0")))
|
||||||
|
render(v, fs) // past the attack
|
||||||
|
var prev = v.render(); var crossings = 0; val n = fs * 2
|
||||||
|
repeat(n) { val x = v.render(); if (prev < 0f && x >= 0f) crossings++; prev = x }
|
||||||
|
assertEquals(440.0, crossings / 2.0, 3.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun morphTimeCarriesAHeldNoteToTheTarget() {
|
||||||
|
val glacier = FrasilDefs.factoryEngine("Glacier")!!.first
|
||||||
|
val v = FrasilVoice(fs)
|
||||||
|
v.noteOn(60, 1f, FrasilPatch.from(slot("Mist", FrasilDefs.MORPH_TO to "Glacier", FrasilDefs.MORPH_TIME to "1.0")))
|
||||||
|
render(v, fs / 100)
|
||||||
|
assertEquals(76 / 127f, v.valueForTest(FrasilDefs.CHOIR), 0.02f) // starts at Mist
|
||||||
|
render(v, fs + fs / 5)
|
||||||
|
assertEquals(glacier[FrasilDefs.CHOIR], v.valueForTest(FrasilDefs.CHOIR), 0.01f)
|
||||||
|
assertEquals(glacier[FrasilDefs.STRETCH], v.valueForTest(FrasilDefs.STRETCH), 0.01f)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun manualMorphSitsBetweenTheTwo() {
|
||||||
|
val glacier = FrasilDefs.factoryEngine("Glacier")!!.first
|
||||||
|
val v = FrasilVoice(fs)
|
||||||
|
v.noteOn(60, 1f, FrasilPatch.from(slot("Mist", FrasilDefs.MORPH_TO to "Glacier", FrasilDefs.MORPH to "0.5")))
|
||||||
|
render(v, fs / 2)
|
||||||
|
assertEquals((76 / 127f + glacier[FrasilDefs.CHOIR]) / 2f, v.valueForTest(FrasilDefs.CHOIR), 0.01f)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun aHeldPadIsAboutAsLoudAsASynthNote() {
|
||||||
|
val pad = SynthVoice(fs).apply { noteOn(60, 100, SynthPatch.forPad(FrasilPatch.from(slot("Mist")))) }
|
||||||
|
val syn = SynthVoice(fs).apply { noteOn(60, 100, SynthPatch.DEFAULT) }
|
||||||
|
fun rms(v: SynthVoice): Float {
|
||||||
|
repeat(fs * 2) { v.render() }
|
||||||
|
var s = 0.0; repeat(fs) { val x = v.render(); s += x * x }
|
||||||
|
return sqrt(s / fs).toFloat()
|
||||||
|
}
|
||||||
|
val ratio = rms(pad) / rms(syn)
|
||||||
|
println("pad/synth rms ratio $ratio")
|
||||||
|
assertTrue("pad/synth level ratio $ratio within -6..+6 dB", ratio in 0.5f..2f)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun synthVoicePlaysPadThenSynthAgain() {
|
||||||
|
val v = SynthVoice(fs)
|
||||||
|
v.noteOn(57, 100, SynthPatch.forPad(FrasilPatch.from(slot("Organ"))))
|
||||||
|
assertTrue(v.isActive && v.isGated)
|
||||||
|
var e = 0.0; repeat(fs) { val x = v.render(); e += x * x }
|
||||||
|
assertTrue(e > 0.0)
|
||||||
|
v.noteOff()
|
||||||
|
assertFalse(v.isGated)
|
||||||
|
v.noteOn(57, 100, SynthPatch.DEFAULT) // the slot became a synth
|
||||||
|
var e2 = 0.0; repeat(fs / 4) { val x = v.render(); e2 += x * x }
|
||||||
|
assertTrue(e2 > 0.0)
|
||||||
|
v.kill()
|
||||||
|
assertFalse(v.isActive)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun cpuBudgetForFullPolyphony() {
|
||||||
|
// 4 channels x 8 voices of the heaviest kind of sound (all three layers, SOFT, BEAT, a resonant filter).
|
||||||
|
val p = FrasilPatch.from(slot("Prism", "choir" to "1.0", "creso" to "0.5", "soft" to "0.5", "breath" to "0.8"))
|
||||||
|
val voices = Array(32) { FrasilVoice(fs).also { v -> v.noteOn(36 + it, 0.9f, p) } }
|
||||||
|
repeat(fs / 2) { for (v in voices) v.render() } // warm up the JIT
|
||||||
|
val seconds = 2
|
||||||
|
val t0 = System.nanoTime()
|
||||||
|
repeat(fs * seconds) { for (v in voices) v.render() }
|
||||||
|
val load = (System.nanoTime() - t0) / 1e9 / seconds
|
||||||
|
println("32 Morph Pad voices: ${"%.1f".format(load * 100)} % of real time on this host")
|
||||||
|
assertTrue("32 voices must render faster than real time on the host ($load)", load < 1.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
package cc.tiredsysadmin.android.sizzle.input
|
||||||
|
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class MidiByteParserTest {
|
||||||
|
|
||||||
|
private val channel = mutableListOf<Triple<Int, Int, Int>>()
|
||||||
|
private val realtime = mutableListOf<Int>()
|
||||||
|
private val parser = MidiByteParser({ s, a, b -> channel += Triple(s, a, b) }, { realtime += it })
|
||||||
|
|
||||||
|
private fun feed(vararg b: Int) {
|
||||||
|
val bytes = ByteArray(b.size) { b[it].toByte() }
|
||||||
|
parser.feed(bytes, 0, bytes.size)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun oneMessagePerPacket() {
|
||||||
|
feed(0x99, 36, 100)
|
||||||
|
feed(0x89, 36, 0)
|
||||||
|
assertEquals(listOf(Triple(0x99, 36, 100), Triple(0x89, 36, 0)), channel)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun runningStatus() {
|
||||||
|
feed(0x90, 60, 100, 64, 90, 60, 0)
|
||||||
|
assertEquals(listOf(Triple(0x90, 60, 100), Triple(0x90, 64, 90), Triple(0x90, 60, 0)), channel)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun messageSplitAcrossPackets() {
|
||||||
|
feed(0x90, 60)
|
||||||
|
feed(100)
|
||||||
|
assertEquals(listOf(Triple(0x90, 60, 100)), channel)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun realtimeInsideAMessageDoesNotBreakIt() {
|
||||||
|
feed(0x90, 0xF8, 60, 0xFA, 100, 0xFC)
|
||||||
|
assertEquals(listOf(Triple(0x90, 60, 100)), channel)
|
||||||
|
assertEquals(listOf(0xF8, 0xFA, 0xFC), realtime)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun oneDataByteMessagesAndSysexSkipped() {
|
||||||
|
feed(0xC2, 5, 0xF0, 0x7E, 0x01, 0x02, 0xF7, 0xB0, 123, 0)
|
||||||
|
assertEquals(listOf(Triple(0xC2, 5, 0), Triple(0xB0, 123, 0)), channel)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun strayDataBytesWithoutStatusAreIgnored() {
|
||||||
|
feed(60, 100, 0x80, 60, 0)
|
||||||
|
assertEquals(listOf(Triple(0x80, 60, 0)), channel)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun offsetAndCountAreHonoured() {
|
||||||
|
val bytes = byteArrayOf(0x00, 0x90.toByte(), 60, 100, 0x7F)
|
||||||
|
parser.feed(bytes, 1, 3)
|
||||||
|
assertEquals(listOf(Triple(0x90, 60, 100)), channel)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
package cc.tiredsysadmin.android.sizzle.input
|
||||||
|
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertNotEquals
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class MidiSourceKeyTest {
|
||||||
|
|
||||||
|
private val mikroSeq = MidiSourceKey.of(
|
||||||
|
2, "tiredsysadmin", "Mikro Seq", null,
|
||||||
|
"cc.tiredsysadmin.android.mikroseq/cc.tiredsysadmin.android.mikroseq.SeqMidiService", null,
|
||||||
|
)
|
||||||
|
|
||||||
|
@Test fun sameDeviceSameKeyRegardlessOfAndroidId() {
|
||||||
|
val again = MidiSourceKey.of(
|
||||||
|
2, "tiredsysadmin", "Mikro Seq", null,
|
||||||
|
"cc.tiredsysadmin.android.mikroseq/cc.tiredsysadmin.android.mikroseq.SeqMidiService", null,
|
||||||
|
)
|
||||||
|
assertEquals(mikroSeq, again)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun differentDevicesDiffer() {
|
||||||
|
val usb = MidiSourceKey.of(1, "Android", "USB Peripheral Port", "Android USB Peripheral Port", null, null)
|
||||||
|
val sunvox = MidiSourceKey.of(2, "NightRadio", "SunVox", null, "nightradio.sunvox/x.MidiService", null)
|
||||||
|
assertNotEquals(mikroSeq, usb)
|
||||||
|
assertNotEquals(mikroSeq, sunvox)
|
||||||
|
val bt1 = MidiSourceKey.of(3, null, null, "WIDI", null, "AA:BB")
|
||||||
|
val bt2 = MidiSourceKey.of(3, null, null, "WIDI", null, "AA:CC")
|
||||||
|
assertNotEquals(bt1, bt2)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun separatorInsideAFieldCannotForgeAnotherKey() {
|
||||||
|
assertNotEquals(
|
||||||
|
MidiSourceKey.of(1, "a|b", null, null, null, null),
|
||||||
|
MidiSourceKey.of(1, "a", "b", null, null, null),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun displayNamePrefersNameThenProductThenMaker() {
|
||||||
|
assertEquals("Android USB Peripheral Port",
|
||||||
|
MidiSourceKey.displayName("Android", "USB Peripheral Port", "Android USB Peripheral Port"))
|
||||||
|
assertEquals("Mikro Seq", MidiSourceKey.displayName("tiredsysadmin", "Mikro Seq", null))
|
||||||
|
assertEquals("tiredsysadmin", MidiSourceKey.displayName("tiredsysadmin", " ", ""))
|
||||||
|
assertEquals("MIDI device", MidiSourceKey.displayName(null, null, null))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
package cc.tiredsysadmin.android.sizzle.io
|
||||||
|
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.Arrangement
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.Project
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An arrangement "off" marker is stored as a negative sentinel in the same array as
|
||||||
|
* block ids, which makes it easy to drop on the way to disk — the project writer
|
||||||
|
* filtered slots with `pid >= 0`, so a marker saved silently and came back empty.
|
||||||
|
* These pin both formats.
|
||||||
|
*/
|
||||||
|
class ArrangementNoteOffTest {
|
||||||
|
|
||||||
|
private fun projectWithMarker(): Project = Project().apply {
|
||||||
|
arrangement.set(0, 0, 0) // a block on lane 0, beat 0
|
||||||
|
arrangement.set(0, 1, Arrangement.NOTE_OFF) // then an off marker
|
||||||
|
arrangement.set(0, 2, 0) // then the block again
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun markerSurvivesAProjectRoundTrip() {
|
||||||
|
val text = ProjectIo.save(projectWithMarker())
|
||||||
|
val back = Project().also { ProjectIo.loadInto(it, text) }
|
||||||
|
|
||||||
|
assertEquals("the block before the marker", 0, back.arrangement.patternAt(0, 0))
|
||||||
|
assertEquals("the marker itself", Arrangement.NOTE_OFF, back.arrangement.patternAt(0, 1))
|
||||||
|
assertEquals("the block after it", 0, back.arrangement.patternAt(0, 2))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun markerSurvivesAnSngRoundTrip() {
|
||||||
|
val text = SngFormat.export(projectWithMarker())
|
||||||
|
assertTrue("the roll should carry an 'x' for the marker", text.contains("roll #x#"))
|
||||||
|
|
||||||
|
val back = SngFormat.importInto(Project(), text)
|
||||||
|
assertEquals(0, back.arrangement.patternAt(0, 0))
|
||||||
|
assertEquals(Arrangement.NOTE_OFF, back.arrangement.patternAt(0, 1))
|
||||||
|
assertEquals(0, back.arrangement.patternAt(0, 2))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A reader that predates the marker sees a non-'#' character and reads empty —
|
||||||
|
* it loses the marker, but it must never mis-parse the beats around it. */
|
||||||
|
@Test fun anUnknownRollCharacterReadsAsEmpty() {
|
||||||
|
val legacy = """
|
||||||
|
version 1
|
||||||
|
bpm 120
|
||||||
|
sig 4 4
|
||||||
|
|
||||||
|
block A 4 4
|
||||||
|
roll #?#
|
||||||
|
endblock
|
||||||
|
""".trimIndent()
|
||||||
|
val p = SngFormat.importInto(Project(), legacy)
|
||||||
|
assertEquals(0, p.arrangement.patternAt(0, 0))
|
||||||
|
assertEquals(Arrangement.EMPTY, p.arrangement.patternAt(0, 1))
|
||||||
|
assertEquals("the beat after the unknown character still lands right",
|
||||||
|
0, p.arrangement.patternAt(0, 2))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The marker is not empty: playback has to run up to it, and it has to break a
|
||||||
|
* contiguous run so the block after it restarts from its own first beat. */
|
||||||
|
@Test fun markerIsFilledButIsNotABlock() {
|
||||||
|
val arr = Arrangement()
|
||||||
|
arr.set(0, 5, Arrangement.NOTE_OFF)
|
||||||
|
|
||||||
|
assertEquals("playback must reach the marker", 5, arr.lastFilledBeat())
|
||||||
|
assertFalse("but it is not a block", arr.hasBlockAt(0, 5))
|
||||||
|
assertTrue(arr.patternAt(0, 5) != Arrangement.EMPTY)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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"))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
// 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 org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
/** Block names with spaces survive the project save/load (the autosave). */
|
||||||
|
class ProjectIoNameTest {
|
||||||
|
|
||||||
|
@Test fun namesWithSpacesAndEscapesRoundTrip() {
|
||||||
|
val names = listOf("C1 muted", "50% ]x", "%20 literal", "plain")
|
||||||
|
val p = Project()
|
||||||
|
names.forEachIndexed { i, n -> p.patterns[i].name = n }
|
||||||
|
val back = ProjectIo.loadInto(Project(), ProjectIo.save(p))
|
||||||
|
assertEquals(names, back.patterns.take(names.size).map { it.name })
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun olderFilesWithoutEscapesLoadAsWritten() {
|
||||||
|
assertEquals("50%", ProjectIo.decodeName("50%"))
|
||||||
|
assertEquals("C1", ProjectIo.decodeName("C1"))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
package cc.tiredsysadmin.android.sizzle.io
|
||||||
|
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.Arrangement
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.Cell
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.Pitch
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.Project
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.TimeSignature
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Files exported by Mikro Seq (internal/seq/sizzle.go, its sample pattern) in 4/4
|
||||||
|
* and 3/4: `#` comments, `loop`, `group`, `scale`/`root`, block names with spaces
|
||||||
|
* ("C1 muted"), blocks off the roll, `OFF` notes and channel-10 drums.
|
||||||
|
*/
|
||||||
|
class SngMikroSeqImportTest {
|
||||||
|
|
||||||
|
private fun load(name: String): String =
|
||||||
|
javaClass.getResource("/mikroseq/$name")!!.readText()
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun fourFour() {
|
||||||
|
val text = load("sig44.sng")
|
||||||
|
assertTrue(SngFormat.looksLikeSng(text))
|
||||||
|
val p = SngFormat.importInto(Project(), text)
|
||||||
|
|
||||||
|
assertEquals(97f, p.tempoBpm, 0.001f)
|
||||||
|
assertEquals(TimeSignature.FOUR_FOUR, p.timeSignature)
|
||||||
|
assertTrue(p.arrangement.loopEnabled)
|
||||||
|
assertEquals(listOf("C1", "C1 muted", "C2", "C6"), p.patterns.take(4).map { it.name })
|
||||||
|
assertEquals(listOf(16, 16, 48, 64), p.patterns.take(4).map { it.length })
|
||||||
|
|
||||||
|
// C1: drums on channel 10 (file channel 9), T1 and T3 keep their slots.
|
||||||
|
val c1 = p.patterns[0]
|
||||||
|
assertEquals(Pitch.parse("C-2"), c1.cell(0, 0).note)
|
||||||
|
assertEquals(10, c1.cell(0, 0).channel)
|
||||||
|
assertEquals(0x6E, c1.cell(0, 0).velocity)
|
||||||
|
assertEquals(Cell.OFF, c1.cell(0, 1).note)
|
||||||
|
assertEquals(Pitch.parse("F#2"), c1.cell(2, 2).note)
|
||||||
|
|
||||||
|
// C2: the tied bass on T4, channel 1, with OFF tokens.
|
||||||
|
val c2 = p.patterns[2]
|
||||||
|
assertEquals(Pitch.parse("B-1"), c2.cell(3, 0).note)
|
||||||
|
assertEquals(1, c2.cell(3, 0).channel)
|
||||||
|
assertEquals(Pitch.parse("C#2"), c2.cell(3, 6).note)
|
||||||
|
assertEquals(Cell.OFF, c2.cell(3, 9).note)
|
||||||
|
|
||||||
|
// C6: lead on channel 3.
|
||||||
|
assertEquals(3, p.patterns[3].cell(0, 0).channel)
|
||||||
|
|
||||||
|
// The roll: 96 beats for C1, C2, C6; the muted block is not on it.
|
||||||
|
for (lane in listOf(0, 2, 3)) {
|
||||||
|
assertEquals(lane, p.arrangement.patternAt(lane, 0))
|
||||||
|
assertEquals(lane, p.arrangement.patternAt(lane, 95))
|
||||||
|
assertEquals(Arrangement.EMPTY, p.arrangement.patternAt(lane, 96))
|
||||||
|
}
|
||||||
|
assertEquals(Arrangement.EMPTY, p.arrangement.patternAt(1, 0))
|
||||||
|
assertTrue(p.arrangement.lengthBars >= 24)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun threeFour() {
|
||||||
|
val p = SngFormat.importInto(Project(), load("sig34.sng"))
|
||||||
|
|
||||||
|
assertEquals(TimeSignature.THREE_FOUR, p.timeSignature)
|
||||||
|
assertEquals(listOf("C1", "C1 muted", "C2", "C6"), p.patterns.take(4).map { it.name })
|
||||||
|
assertEquals(listOf(12, 12, 36, 48), p.patterns.take(4).map { it.length })
|
||||||
|
|
||||||
|
val c1 = p.patterns[0]
|
||||||
|
for (step in listOf(0, 3, 6, 9)) assertEquals(Pitch.parse("C-2"), c1.cell(0, step).note)
|
||||||
|
for (step in listOf(1, 4, 7, 10)) assertEquals(Cell.OFF, c1.cell(0, step).note)
|
||||||
|
assertEquals(Pitch.parse("D-2"), p.patterns[1].cell(1, 3).note) // muted T2
|
||||||
|
val c2 = p.patterns[2]
|
||||||
|
assertEquals(Pitch.parse("C#2"), c2.cell(3, 5).note)
|
||||||
|
assertEquals(Cell.OFF, c2.cell(3, 7).note)
|
||||||
|
assertEquals(Cell.OFF, c2.cell(3, 16).note)
|
||||||
|
|
||||||
|
assertEquals(2, p.arrangement.patternAt(2, 95))
|
||||||
|
assertEquals(Arrangement.EMPTY, p.arrangement.patternAt(2, 96))
|
||||||
|
assertTrue(p.arrangement.lengthBars >= 96 / 3)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun moreBlocksThanLanesKeepsTheOnesOnTheRoll() {
|
||||||
|
// 8 canvases, each with a live block on the roll and a muted one off it:
|
||||||
|
// 16 blocks for 8 lanes.
|
||||||
|
val text = buildString {
|
||||||
|
appendLine("version 1\nbpm 120\nsig 4 4")
|
||||||
|
for (c in 1..8) {
|
||||||
|
appendLine("block C$c 16 1\nroll ####\ntrack T1 0\n0 C-4 64 ..\nendblock")
|
||||||
|
appendLine("block C$c muted 16 1\ntrack T2 0\n0 D-4 64 ..\nendblock")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val p = SngFormat.importInto(Project(), text)
|
||||||
|
assertEquals((1..8).map { "C$it" }, p.patterns.map { it.name })
|
||||||
|
for (lane in 0 until 8) assertEquals(lane, p.arrangement.patternAt(lane, 0))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun trackNumbersBeyondFourTakeFreeSlotsAndExtraTracksAreDropped() {
|
||||||
|
val text = """
|
||||||
|
version 1
|
||||||
|
block A 16 6
|
||||||
|
track T1 0
|
||||||
|
0 C-4 .. ..
|
||||||
|
track T7 1
|
||||||
|
0 D-4 .. ..
|
||||||
|
track T2 2
|
||||||
|
0 E-4 .. ..
|
||||||
|
track T9 3
|
||||||
|
0 F-4 .. ..
|
||||||
|
track T12 4
|
||||||
|
0 G-4 .. ..
|
||||||
|
endblock
|
||||||
|
""".trimIndent()
|
||||||
|
val b = SngFormat.importInto(Project(), text).patterns[0]
|
||||||
|
assertEquals(Pitch.parse("C-4"), b.cell(0, 0).note)
|
||||||
|
assertEquals(Pitch.parse("D-4"), b.cell(1, 0).note) // T7 -> first free (2nd) slot
|
||||||
|
assertEquals(Pitch.parse("E-4"), b.cell(2, 0).note) // T2 taken -> next free
|
||||||
|
assertEquals(Pitch.parse("F-4"), b.cell(3, 0).note)
|
||||||
|
// T12 has no slot left: its G-4 is dropped rather than overwriting a track.
|
||||||
|
assertFalse((0 until 4).any { b.cell(it, 0).note == Pitch.parse("G-4") })
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun absurdBlockLengthIsBounded() {
|
||||||
|
val p = SngFormat.importInto(Project(), "version 1\nblock A 999999999 1\nendblock\n")
|
||||||
|
assertEquals(SngFormat.MAX_BLOCK_LENGTH, p.patterns[0].length)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun plainTextIsNotASong() {
|
||||||
|
assertFalse(SngFormat.looksLikeSng("shopping list\nmilk\neggs"))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
package cc.tiredsysadmin.android.sizzle.playback
|
||||||
|
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class MidiSoundModuleTest {
|
||||||
|
|
||||||
|
/** Records engine calls as "on ch note vel" / "off ch note". */
|
||||||
|
private val engine = mutableListOf<String>()
|
||||||
|
private val module = MidiSoundModule(object : MidiSoundModule.NoteSink {
|
||||||
|
override fun busNoteOn(channel: Int, note: Int, velocity: Int) { engine += "on $channel $note $velocity" }
|
||||||
|
override fun busNoteOff(channel: Int, note: Int) { engine += "off $channel $note" }
|
||||||
|
})
|
||||||
|
|
||||||
|
@Test fun noteOnOffRouteToTheMixerChannel() {
|
||||||
|
assertTrue(module.onChannelMessage(1, 0x99, 36, 110)) // channel 10: drums
|
||||||
|
assertTrue(module.onChannelMessage(1, 0x89, 36, 0))
|
||||||
|
assertTrue(module.onChannelMessage(1, 0x92, 60, 90)) // channel 3
|
||||||
|
assertTrue(module.onChannelMessage(1, 0x92, 60, 0)) // velocity 0 == note off
|
||||||
|
assertEquals(listOf("on 10 36 110", "off 10 36", "on 3 60 90", "off 3 60"), engine)
|
||||||
|
assertTrue(module.heldNotes(1).isEmpty())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun otherMessagesAreLeftToTheCaller() {
|
||||||
|
assertFalse(module.onChannelMessage(1, 0xB0, 7, 100)) // CC 7: bindings / learn
|
||||||
|
assertFalse(module.onChannelMessage(1, 0xC0, 3, 0)) // program change
|
||||||
|
assertTrue(engine.isEmpty())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun disconnectReleasesOnlyThatSourcesHeldNotes() {
|
||||||
|
module.sourceConnected(1); module.sourceConnected(2)
|
||||||
|
assertEquals(2, module.sources.value)
|
||||||
|
module.onChannelMessage(1, 0x90, 60, 100)
|
||||||
|
module.onChannelMessage(1, 0x99, 38, 100)
|
||||||
|
module.onChannelMessage(2, 0x91, 64, 100)
|
||||||
|
engine.clear()
|
||||||
|
|
||||||
|
module.sourceDisconnected(1)
|
||||||
|
|
||||||
|
assertEquals(setOf("off 1 60", "off 10 38"), engine.toSet())
|
||||||
|
assertEquals(1, module.sources.value)
|
||||||
|
assertEquals(setOf(2 to 64), module.heldNotes(2))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun allNotesOffReleasesTheChannelAcrossSources() {
|
||||||
|
module.onChannelMessage(1, 0x90, 60, 100)
|
||||||
|
module.onChannelMessage(2, 0x90, 62, 100)
|
||||||
|
module.onChannelMessage(1, 0x93, 70, 100)
|
||||||
|
engine.clear()
|
||||||
|
|
||||||
|
assertTrue(module.onChannelMessage(1, 0xB0, 123, 0))
|
||||||
|
|
||||||
|
assertEquals(setOf("off 1 60", "off 1 62"), engine.toSet())
|
||||||
|
assertEquals(setOf(4 to 70), module.heldNotes(1))
|
||||||
|
assertTrue(module.heldNotes(2).isEmpty())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun allSoundOffAlsoReleases() {
|
||||||
|
module.onChannelMessage(1, 0x90, 60, 100)
|
||||||
|
engine.clear()
|
||||||
|
assertTrue(module.onChannelMessage(1, 0xB0, 120, 0))
|
||||||
|
assertEquals(listOf("off 1 60"), engine)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun listenerMirrorsNotesSoTheUiNeedNotSoundThem() {
|
||||||
|
val seen = mutableListOf<String>()
|
||||||
|
module.noteListener = { on, ch, note, vel -> seen += "${if (on) "on" else "off"} $ch $note $vel" }
|
||||||
|
module.onChannelMessage(1, 0x90, 60, 100)
|
||||||
|
module.sourceDisconnected(1)
|
||||||
|
assertEquals(listOf("on 1 60 100", "off 1 60 0"), seen)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun realtimeIsForwarded() {
|
||||||
|
val rt = mutableListOf<Int>()
|
||||||
|
module.realtime = { rt += it }
|
||||||
|
module.onRealtime(0xFA); module.onRealtime(0xF8); module.onRealtime(0xFC)
|
||||||
|
assertEquals(listOf(0xFA, 0xF8, 0xFC), rt)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun releaseAllEmptiesEverySource() {
|
||||||
|
module.onChannelMessage(1, 0x90, 60, 100)
|
||||||
|
module.onChannelMessage(2, 0x95, 61, 100)
|
||||||
|
engine.clear()
|
||||||
|
module.releaseAll()
|
||||||
|
assertEquals(setOf("off 1 60", "off 6 61"), engine.toSet())
|
||||||
|
assertTrue(module.heldNotes(1).isEmpty() && module.heldNotes(2).isEmpty())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
package cc.tiredsysadmin.android.sizzle.ui.toolbox
|
||||||
|
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.ParamSpec
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.ToolboxType
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class DeviceLayoutsTest {
|
||||||
|
|
||||||
|
/** Devices with editors of their own; every other one is laid out by DeviceLayouts. */
|
||||||
|
private val bespoke = setOf(
|
||||||
|
ToolboxType.NES_SYNTH, ToolboxType.SAMPLER, ToolboxType.SOUNDFONT, ToolboxType.DELAY,
|
||||||
|
ToolboxType.TAPE_ENGINE, ToolboxType.MIX_TIGHTENER, ToolboxType.GRANULAR,
|
||||||
|
)
|
||||||
|
|
||||||
|
@Test fun everyParameterIsOnExactlyOneCard() {
|
||||||
|
for (type in ToolboxType.entries.filter { it !in bespoke }) {
|
||||||
|
val keys = DeviceLayouts.pagesFor(type).flatMap { p -> p.panels.flatMap { it.keys } }
|
||||||
|
val params = type.params.map { it.key }
|
||||||
|
assertEquals("$type: duplicated ${keys.groupBy { it }.filter { it.value.size > 1 }.keys}", keys.size, keys.toSet().size)
|
||||||
|
assertEquals("$type: missing ${params - keys.toSet()}, unknown ${keys - params.toSet()}", params.toSet(), keys.toSet())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun labelsAreShortEnoughForAKnob() {
|
||||||
|
for (type in ToolboxType.entries.filter { it !in bespoke }) {
|
||||||
|
val byKey = type.params.associateBy { it.key }
|
||||||
|
for (page in DeviceLayouts.pagesFor(type)) for (panel in page.panels) for (k in panel.keys) {
|
||||||
|
val spec = byKey.getValue(k)
|
||||||
|
if (spec.isEnum) continue
|
||||||
|
val l = shortLabel(spec, panel)
|
||||||
|
assertTrue("$type $k '$l'", l.length <= 11)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun valuesReadInTheirUnits() {
|
||||||
|
assertEquals("250ms", formatParam(ParamSpec("attack", "Attack", 0f, 0f, 2f), 0.25f))
|
||||||
|
assertEquals("1.50s", formatParam(ParamSpec("release", "Release", 0f, 0f, 3f), 1.5f))
|
||||||
|
assertEquals("45%", formatParam(ParamSpec("x", "X", 0f, 0f, 1f), 0.45f))
|
||||||
|
assertEquals("+20%", formatParam(ParamSpec("x", "X", 0f, -1f, 1f), 0.2f))
|
||||||
|
assertEquals("+7st", formatParam(ParamSpec("o1semi", "Osc1 Semi", 0f, -12f, 12f, isInt = true), 7f))
|
||||||
|
assertEquals("-4.0dB", formatParam(ParamSpec("wet", "Wet (dB)", 0f, -60f, 0f), -4f))
|
||||||
|
assertEquals("1/8", formatParam(ParamSpec("division", "Division", 3f, 0f, 6f, isInt = true), 3f))
|
||||||
|
assertEquals("→ Position", shortLabel(ParamSpec("lfopos", "LFO > Position"), Panel("LFO", Tone.MOD, emptyList())))
|
||||||
|
assertEquals("Level", shortLabel(ParamSpec("o2level", "Osc2 Level"), Panel("O", Tone.SOURCE, emptyList())))
|
||||||
|
assertEquals("Thresh", shortLabel(ParamSpec("duckthresh", "Duck Thresh (dB)"), Panel("D", Tone.ENV, emptyList())))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,296 @@
|
|||||||
|
// 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
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.ToolboxSlot
|
||||||
|
import kotlin.math.PI
|
||||||
|
import kotlin.math.ceil
|
||||||
|
import kotlin.math.floor
|
||||||
|
import kotlin.math.ln
|
||||||
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
|
import kotlin.math.pow
|
||||||
|
import kotlin.math.sin
|
||||||
|
import kotlin.math.sqrt
|
||||||
|
import kotlin.math.tan
|
||||||
|
import kotlin.math.tanh
|
||||||
|
|
||||||
|
/** A parsed Wavetable slot (built once per slot change, off the sample loop). */
|
||||||
|
class WavePatch(
|
||||||
|
val table: Array<String>, val pos: FloatArray, val semis: FloatArray, val level: FloatArray, val bend: FloatArray,
|
||||||
|
val unison: Int, val spread: Float, val sub: Float, val noise: Float, val velSens: Float,
|
||||||
|
val customId: String, val frameLen: Int,
|
||||||
|
val filterType: Int, val cutoff: Float, val reso: Float, val keytrack: Float, val fenv: Float, val drive: Float,
|
||||||
|
val a: Float, val d: Float, val s: Float, val r: Float,
|
||||||
|
val ma: Float, val md: Float, val ms: Float, val mr: Float, val menvPos: Float,
|
||||||
|
val lfoWave: Int, val lfoHz: Float, val lfoPos: Float, val lfoPitch: Float, val lfoCut: Float,
|
||||||
|
) {
|
||||||
|
companion object {
|
||||||
|
fun from(slot: ToolboxSlot?, tempoBpm: Float): WavePatch {
|
||||||
|
fun f(k: String, d: Float) = slot?.float(k, d) ?: d
|
||||||
|
fun c(k: String, choices: List<String>) = choices.indexOf(slot?.string(k, choices[0]) ?: choices[0]).coerceAtLeast(0)
|
||||||
|
val tables = Array(2) { o -> slot?.string("o${o + 1}table", WaveDefs.TABLES[0]) ?: WaveDefs.TABLES[0] }
|
||||||
|
val semis = FloatArray(2) { o ->
|
||||||
|
val n = o + 1
|
||||||
|
f("o${n}oct", 0f).toInt().coerceIn(-2, 2) * 12f + f("o${n}semi", 0f).toInt().coerceIn(-12, 12) +
|
||||||
|
f("o${n}fine", if (n == 1) 0f else 7f).coerceIn(-50f, 50f) / 100f
|
||||||
|
}
|
||||||
|
val frame = WaveDefs.FRAME_SIZES[c("wtframe", WaveDefs.FRAME_SIZES)].toIntOrNull() ?: 0
|
||||||
|
val beat = TimeDivision.fromIndex(f("lfodiv", 1f).toInt()).beatFraction.toFloat()
|
||||||
|
return WavePatch(
|
||||||
|
table = tables,
|
||||||
|
pos = FloatArray(2) { o -> f("o${o + 1}pos", if (o == 0) 0f else 0.3f).coerceIn(0f, 1f) },
|
||||||
|
semis = semis,
|
||||||
|
level = FloatArray(2) { o -> f("o${o + 1}level", if (o == 0) 0.8f else 0f).coerceIn(0f, 1f) },
|
||||||
|
bend = FloatArray(2) { o -> f("o${o + 1}bend", 0f).coerceIn(-1f, 1f) },
|
||||||
|
unison = f("unison", 1f).toInt().coerceIn(1, 4), spread = f("spread", 0.3f).coerceIn(0f, 1f),
|
||||||
|
sub = f("sub", 0f).coerceIn(0f, 1f), noise = f("noise", 0f).coerceIn(0f, 1f), velSens = f("velsens", 0.5f).coerceIn(0f, 1f),
|
||||||
|
customId = slot?.string(WaveDefs.SAMPLE_KEY, "") ?: "", frameLen = frame,
|
||||||
|
filterType = c("ftype", WaveDefs.FILTER_TYPES), cutoff = f("cutoff", 0.75f).coerceIn(0f, 1f),
|
||||||
|
reso = f("reso", 0.15f).coerceIn(0f, 1f), keytrack = f("keytrack", 0.4f).coerceIn(0f, 1f),
|
||||||
|
fenv = f("fenv", 0.2f).coerceIn(-1f, 1f), drive = f("drive", 0f).coerceIn(0f, 1f),
|
||||||
|
a = f("attack", 0.01f), d = f("decay", 0.3f), s = f("sustain", 0.8f).coerceIn(0f, 1f), r = f("release", 0.4f),
|
||||||
|
ma = f("mattack", 0.5f), md = f("mdecay", 2f), ms = f("msustain", 0.5f).coerceIn(0f, 1f), mr = f("mrelease", 1f),
|
||||||
|
menvPos = f("menvpos", 0.3f).coerceIn(-1f, 1f),
|
||||||
|
lfoWave = c("lfowave", WaveDefs.LFO_WAVES),
|
||||||
|
lfoHz = if (beat > 0f) (tempoBpm / 60f) / beat else 1f,
|
||||||
|
lfoPos = f("lfopos", 0.15f).coerceIn(0f, 1f), lfoPitch = f("lfopitch", 0f).coerceIn(0f, 1f),
|
||||||
|
lfoCut = f("lfocut", 0f).coerceIn(0f, 1f),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val DEFAULT: WavePatch by lazy { from(null, 120f) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One note of the wavetable synth:
|
||||||
|
*
|
||||||
|
* 2 wavetable oscillators (each: table, position through its frames, pitch, level,
|
||||||
|
* phase bend, up to 4 unison copies) + a sub sine + noise → drive → state-variable
|
||||||
|
* filter (low / band / high) → amp envelope
|
||||||
|
*
|
||||||
|
* A second envelope and a tempo-synced LFO move the table position, the cutoff and
|
||||||
|
* (LFO) the pitch. Every [CTRL] samples the voice re-reads its tables, positions and
|
||||||
|
* filter, and picks per oscillator the band-limited level whose top harmonic stays
|
||||||
|
* under Nyquist — counting how much BEND steepens the wave — so nothing aliases.
|
||||||
|
* Reads are linear within a cycle (each level keeps four samples per top harmonic)
|
||||||
|
* and linear between the two neighbouring frames.
|
||||||
|
*
|
||||||
|
* BEND is a two-segment phase warp (as in phase-distortion synthesis): the first
|
||||||
|
* half of the cycle is squeezed (bend > 0) or stretched (bend < 0), sharpening the
|
||||||
|
* wave without changing its pitch.
|
||||||
|
*/
|
||||||
|
class WaveVoice(private val fs: Int) {
|
||||||
|
|
||||||
|
private val fsf = fs.toFloat()
|
||||||
|
private var patch = WavePatch.DEFAULT
|
||||||
|
var note = -1; private set
|
||||||
|
private var vel = 0f
|
||||||
|
private var baseHz = 440f
|
||||||
|
|
||||||
|
private val amp = Env()
|
||||||
|
private val mod = Env()
|
||||||
|
|
||||||
|
// oscillators: [osc * MAX_UNISON + u]
|
||||||
|
private val phase = DoubleArray(2 * MAX_UNISON)
|
||||||
|
private val inc = DoubleArray(2 * MAX_UNISON)
|
||||||
|
private val oscTable = arrayOfNulls<WaveTable>(2)
|
||||||
|
private val oscLevel = IntArray(2)
|
||||||
|
private val oscFrame = FloatArray(2)
|
||||||
|
private val oscWarpM = FloatArray(2)
|
||||||
|
private var subPhase = 0.0
|
||||||
|
private var subInc = 0.0
|
||||||
|
|
||||||
|
// filter (topology-preserving SVF)
|
||||||
|
private var s1 = 0f; private var s2 = 0f
|
||||||
|
private var fa1 = 0f; private var fa2 = 0f; private var fa3 = 0f; private var fk = 1f
|
||||||
|
|
||||||
|
private var lfoPh = 0.0
|
||||||
|
private var lfoVal = 0f
|
||||||
|
private var shVal = 0f
|
||||||
|
private var ctrl = 0
|
||||||
|
private var rng = 0x6C8E9CF5
|
||||||
|
|
||||||
|
val isActive: Boolean get() = amp.active
|
||||||
|
val isGated: Boolean get() = amp.gate
|
||||||
|
|
||||||
|
fun noteOn(midi: Int, velocity: Float, p: WavePatch) {
|
||||||
|
val fresh = !amp.active
|
||||||
|
patch = p
|
||||||
|
note = midi
|
||||||
|
vel = velocity.coerceIn(0f, 1f)
|
||||||
|
baseHz = (440.0 * 2.0.pow((midi - 69) / 12.0)).toFloat()
|
||||||
|
amp.on(p.a, p.d, p.s, p.r)
|
||||||
|
mod.on(p.ma, p.md, p.ms, p.mr)
|
||||||
|
if (fresh) {
|
||||||
|
s1 = 0f; s2 = 0f; lfoPh = 0.0
|
||||||
|
for (i in phase.indices) phase[i] = if (i % MAX_UNISON == 0 && p.unison == 1) 0.0 else rand01().toDouble()
|
||||||
|
subPhase = 0.0
|
||||||
|
}
|
||||||
|
ctrl = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
fun noteOff() { amp.off(); mod.off() }
|
||||||
|
|
||||||
|
fun kill() { amp.kill(); mod.kill(); note = -1; s1 = 0f; s2 = 0f }
|
||||||
|
|
||||||
|
fun setPatch(p: WavePatch) { patch = p; amp.retime(p.a, p.d, p.s, p.r); mod.retime(p.ma, p.md, p.ms, p.mr) }
|
||||||
|
|
||||||
|
fun render(): Float {
|
||||||
|
if (!amp.active) return 0f
|
||||||
|
if (ctrl <= 0) { control(); ctrl = CTRL }
|
||||||
|
ctrl--
|
||||||
|
val p = patch
|
||||||
|
var mix = 0f
|
||||||
|
val uni = p.unison
|
||||||
|
val uniGain = 1f / sqrt(uni.toFloat())
|
||||||
|
for (o in 0 until 2) {
|
||||||
|
val t = oscTable[o] ?: continue
|
||||||
|
val lvl = p.level[o]
|
||||||
|
if (lvl <= 0.0001f) continue
|
||||||
|
val lv = oscLevel[o]
|
||||||
|
val size = t.size(lv)
|
||||||
|
val data = t.data[lv]
|
||||||
|
val fpos = oscFrame[o]
|
||||||
|
val f0 = fpos.toInt().coerceAtMost(t.frames - 1)
|
||||||
|
val f1 = min(f0 + 1, t.frames - 1)
|
||||||
|
val ff = fpos - f0
|
||||||
|
val b0 = f0 * size; val b1 = f1 * size
|
||||||
|
val mask = size - 1
|
||||||
|
val m = oscWarpM[o]
|
||||||
|
var acc = 0f
|
||||||
|
for (u in 0 until uni) {
|
||||||
|
val k = o * MAX_UNISON + u
|
||||||
|
var ph = phase[k] + inc[k]
|
||||||
|
if (ph >= 1.0) ph -= 1.0
|
||||||
|
phase[k] = ph
|
||||||
|
// BEND: the cycle's first part squeezed into half (m < 0.5) or stretched (m > 0.5)
|
||||||
|
val pw = if (m == 0.5f) ph.toFloat() else {
|
||||||
|
val q = ph.toFloat()
|
||||||
|
if (q < m) 0.5f * q / m else 0.5f + 0.5f * (q - m) / (1f - m)
|
||||||
|
}
|
||||||
|
val x = pw * size
|
||||||
|
val i0 = x.toInt() and mask
|
||||||
|
val i1 = (i0 + 1) and mask
|
||||||
|
val fr = x - x.toInt()
|
||||||
|
val a0 = data[b0 + i0] + (data[b0 + i1] - data[b0 + i0]) * fr
|
||||||
|
val a1 = data[b1 + i0] + (data[b1 + i1] - data[b1 + i0]) * fr
|
||||||
|
acc += a0 + (a1 - a0) * ff
|
||||||
|
}
|
||||||
|
mix += acc * uniGain * lvl
|
||||||
|
}
|
||||||
|
if (p.sub > 0.0001f) {
|
||||||
|
subPhase += subInc
|
||||||
|
if (subPhase >= 1.0) subPhase -= 1.0
|
||||||
|
mix += p.sub * sin(2.0 * PI * subPhase).toFloat()
|
||||||
|
}
|
||||||
|
if (p.noise > 0.0001f) mix += p.noise * 0.5f * (rand01() * 2f - 1f)
|
||||||
|
if (p.drive > 0.001f) { val g = 1f + 4f * p.drive; mix = tanh(mix * g) / tanh(g) }
|
||||||
|
|
||||||
|
// the state-variable filter (Zavalishin / Simper TPT form)
|
||||||
|
val v3 = mix - s2
|
||||||
|
val v1 = fa1 * s1 + fa2 * v3
|
||||||
|
val v2 = s2 + fa2 * s1 + fa3 * v3
|
||||||
|
s1 = 2f * v1 - s1
|
||||||
|
s2 = 2f * v2 - s2
|
||||||
|
val y = when (p.filterType) { 1 -> v1; 2 -> mix - fk * v1 - v2; else -> v2 }
|
||||||
|
|
||||||
|
val e = amp.next(1f / fsf)
|
||||||
|
mod.next(1f / fsf)
|
||||||
|
val out = y * e * (1f - p.velSens + p.velSens * vel) * OUT_GAIN
|
||||||
|
return if (out.isFinite()) out else { kill(); 0f }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun control() {
|
||||||
|
val p = patch
|
||||||
|
val dt = CTRL / fsf
|
||||||
|
// LFO
|
||||||
|
lfoPh += p.lfoHz * dt
|
||||||
|
if (lfoPh >= 1.0) { lfoPh -= floor(lfoPh); shVal = rand01() * 2f - 1f }
|
||||||
|
val ph = lfoPh.toFloat()
|
||||||
|
lfoVal = when (p.lfoWave) {
|
||||||
|
1 -> 1f - 4f * kotlin.math.abs(ph - 0.5f)
|
||||||
|
2 -> 2f * ph - 1f
|
||||||
|
3 -> if (ph < 0.5f) 1f else -1f
|
||||||
|
4 -> shVal
|
||||||
|
else -> sin(2f * PI.toFloat() * ph)
|
||||||
|
}
|
||||||
|
val menv = mod.level
|
||||||
|
val vibCents = p.lfoPitch * 50f * lfoVal // up to ±50 cents
|
||||||
|
for (o in 0 until 2) {
|
||||||
|
val t = if (p.table[o] == WaveTables.CUSTOM) WaveTables.forSample(p.customId, p.frameLen) else WaveTables.factory(p.table[o])
|
||||||
|
oscTable[o] = t
|
||||||
|
if (t == null) continue
|
||||||
|
val pos = (p.pos[o] + p.menvPos * menv + p.lfoPos * 0.5f * lfoVal).coerceIn(0f, 1f)
|
||||||
|
oscFrame[o] = pos * (t.frames - 1)
|
||||||
|
val b = p.bend[o]
|
||||||
|
val m = if (b >= 0f) 0.5f * (1f - 0.9f * b) else 0.5f * (1f + 0.9f * -b)
|
||||||
|
oscWarpM[o] = m
|
||||||
|
val slope = 0.5f / min(m, 1f - m)
|
||||||
|
val hz = baseHz * 2f.pow((p.semis[o] + vibCents / 100f) / 12f)
|
||||||
|
val uni = p.unison
|
||||||
|
var top = hz
|
||||||
|
for (u in 0 until uni) {
|
||||||
|
val cents = if (uni == 1) 0f else p.spread * 30f * (2f * u / (uni - 1) - 1f)
|
||||||
|
val f = hz * 2f.pow(cents / 1200f)
|
||||||
|
inc[o * MAX_UNISON + u] = (f / fsf).toDouble()
|
||||||
|
if (f > top) top = f
|
||||||
|
}
|
||||||
|
// the band-limited level: its top harmonic (times BEND's steepening) under 0.45 fs
|
||||||
|
val hmax = 0.45f * fsf / (top * slope)
|
||||||
|
oscLevel[o] = if (hmax >= WaveTable.MAX_HARMONICS) 0
|
||||||
|
else ceil(ln(WaveTable.MAX_HARMONICS / max(1f, hmax)) / LN2).toInt().coerceIn(0, WaveTable.LEVELS - 1)
|
||||||
|
}
|
||||||
|
subInc = (baseHz * 0.5f * 2f.pow(p.semis[0] / 12f) / fsf).toDouble()
|
||||||
|
// filter: cutoff 20 Hz .. 20 kHz on an exponential scale, key tracking around C4
|
||||||
|
val c = p.cutoff + p.keytrack * (note - 60) / 120f + p.fenv * menv * 0.6f + p.lfoCut * 0.3f * lfoVal
|
||||||
|
val fc = (20f * 1000f.pow(c.coerceIn(0f, 1f))).coerceAtMost(0.45f * fsf)
|
||||||
|
val g = tan(PI.toFloat() * fc / fsf)
|
||||||
|
fk = 2f - 1.96f * p.reso
|
||||||
|
fa1 = 1f / (1f + g * (g + fk)); fa2 = g * fa1; fa3 = g * fa2
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun rand01(): Float {
|
||||||
|
var x = rng
|
||||||
|
x = x xor (x shl 13); x = x xor (x ushr 17); x = x xor (x shl 5)
|
||||||
|
rng = x
|
||||||
|
return (x ushr 8) * (1f / 16777216f)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Linear ADSR, levels 0..1; a release reaches 0 in its time from any level. */
|
||||||
|
private class Env {
|
||||||
|
private var stage = 0 // 0 idle, 1 attack, 2 decay, 3 sustain, 4 release
|
||||||
|
var level = 0f; private set
|
||||||
|
private var a = 0.01f; private var d = 0.1f; private var s = 0.7f; private var r = 0.2f
|
||||||
|
val active get() = stage != 0
|
||||||
|
val gate get() = stage in 1..3
|
||||||
|
fun on(aa: Float, dd: Float, ss: Float, rr: Float) { retime(aa, dd, ss, rr); stage = 1 }
|
||||||
|
fun retime(aa: Float, dd: Float, ss: Float, rr: Float) { a = max(aa, 0.0005f); d = max(dd, 0.001f); s = ss; r = max(rr, 0.001f) }
|
||||||
|
fun off() { if (stage != 0) stage = 4 }
|
||||||
|
fun kill() { stage = 0; level = 0f }
|
||||||
|
fun next(dt: Float): Float {
|
||||||
|
when (stage) {
|
||||||
|
1 -> { level += dt / a; if (level >= 1f) { level = 1f; stage = 2 } }
|
||||||
|
2 -> { level -= dt / d * (1f - s); if (level <= s) { level = s; stage = 3 } }
|
||||||
|
4 -> { level -= dt / r; if (level <= 0f) { level = 0f; stage = 0 } }
|
||||||
|
}
|
||||||
|
return level
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val MAX_UNISON = 4
|
||||||
|
private const val CTRL = 16
|
||||||
|
private const val OUT_GAIN = 0.45f
|
||||||
|
private val LN2 = ln(2f)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,152 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
package cc.tiredsysadmin.android.sizzle.wavetable
|
||||||
|
|
||||||
|
import cc.tiredsysadmin.android.sizzle.audio.SampleStore
|
||||||
|
import cc.tiredsysadmin.android.sizzle.audio.SynthPatch
|
||||||
|
import cc.tiredsysadmin.android.sizzle.audio.SynthVoice
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.ToolboxSlot
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.ToolboxType
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.BeforeClass
|
||||||
|
import org.junit.Test
|
||||||
|
import kotlin.math.PI
|
||||||
|
import kotlin.math.abs
|
||||||
|
import kotlin.math.cos
|
||||||
|
import kotlin.math.round
|
||||||
|
import kotlin.math.sin
|
||||||
|
import kotlin.math.sqrt
|
||||||
|
|
||||||
|
class WavetableTest {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@JvmStatic @BeforeClass fun tables() = WaveTables.prewarmBlocking()
|
||||||
|
}
|
||||||
|
|
||||||
|
private val fs = 48_000
|
||||||
|
|
||||||
|
private fun slot(preset: String? = null, vararg extra: Pair<String, String>): ToolboxSlot =
|
||||||
|
ToolboxSlot(0).apply {
|
||||||
|
fill(ToolboxType.WAVETABLE)
|
||||||
|
preset?.let { n -> WaveDefs.FACTORY.first { it.name == n }.values.forEach { (k, v) -> set(k, v) } }
|
||||||
|
extra.forEach { (k, v) -> set(k, v) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun voice(s: ToolboxSlot, note: Int, vel: Float = 0.8f) =
|
||||||
|
WaveVoice(fs).apply { noteOn(note, vel, WavePatch.from(s, 120f)) }
|
||||||
|
|
||||||
|
/** |DFT|^2 of x (Hann-windowed) at bins 0..n/2. */
|
||||||
|
private fun power(x: FloatArray): DoubleArray {
|
||||||
|
val n = x.size
|
||||||
|
val w = DoubleArray(n) { x[it] * (0.5 - 0.5 * cos(2 * PI * it / n)) }
|
||||||
|
return DoubleArray(n / 2) { k ->
|
||||||
|
var re = 0.0; var im = 0.0
|
||||||
|
val a = 2 * PI * k / n
|
||||||
|
for (i in 0 until n) { re += w[i] * cos(a * i); im -= w[i] * sin(a * i) }
|
||||||
|
re * re + im * im
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun factoryTablesAreBuiltAndBandLimited() {
|
||||||
|
for (name in WaveTables.FACTORY_NAMES) {
|
||||||
|
val t = WaveTables.factory(name)!!
|
||||||
|
assertEquals(name, WaveTables.FRAMES, t.frames)
|
||||||
|
for (k in 0 until WaveTable.LEVELS) assertTrue(name, t.data[k].all { it.isFinite() && abs(it) < 2f })
|
||||||
|
// level 4 keeps 32 harmonics: nothing from harmonic 33 on, in any frame
|
||||||
|
val k = 4; val n = t.size(k)
|
||||||
|
for (f in 0 until t.frames) {
|
||||||
|
val x = FloatArray(n) { t.data[k][f * n + it] }
|
||||||
|
val p = DoubleArray(n / 2) { h ->
|
||||||
|
var re = 0.0; var im = 0.0
|
||||||
|
for (i in 0 until n) { re += x[i] * cos(2 * PI * h * i / n); im += x[i] * sin(2 * PI * h * i / n) }
|
||||||
|
re * re + im * im
|
||||||
|
}
|
||||||
|
val total = p.sum() + 1e-12
|
||||||
|
val above = p.drop(WaveTable.harmonics(k) + 1).sum()
|
||||||
|
assertTrue("$name frame $f above-band ${above / total}", above / total < 1e-6)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun aHighSawDoesNotAlias() {
|
||||||
|
// Classic at 0.5 is the saw; C7 (2093 Hz) has only 10 harmonics under Nyquist
|
||||||
|
val v = voice(slot(null, "o1table" to "Classic", "o1pos" to "0.5", "menvpos" to "0.0", "lfopos" to "0.0",
|
||||||
|
"cutoff" to "1.0", "reso" to "0.0", "keytrack" to "0.0", "fenv" to "0.0", "sustain" to "1.0"), 96)
|
||||||
|
repeat(fs / 10) { v.render() }
|
||||||
|
val n = 4096
|
||||||
|
val x = FloatArray(n) { v.render() }
|
||||||
|
val p = power(x)
|
||||||
|
val f0 = 440.0 * Math.pow(2.0, (96 - 69) / 12.0)
|
||||||
|
var harm = 0.0; var total = 0.0
|
||||||
|
for (k in p.indices) {
|
||||||
|
total += p[k]
|
||||||
|
val hz = k.toDouble() * fs / n
|
||||||
|
val h = round(hz / f0)
|
||||||
|
if (h >= 1 && abs(hz - h * f0) <= 4.0 * fs / n) harm += p[k]
|
||||||
|
}
|
||||||
|
val alias = 1 - harm / total
|
||||||
|
println("C7 saw: off-harmonic energy ${"%.2e".format(alias)}")
|
||||||
|
assertTrue("aliased energy $alias", alias < 1e-3)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun pitchFollowsTheNote() {
|
||||||
|
val v = voice(slot(null, "o1table" to "Classic", "o1pos" to "0.0", "menvpos" to "0.0", "lfopos" to "0.0", "cutoff" to "1.0", "sustain" to "1.0"), 69)
|
||||||
|
repeat(fs / 10) { v.render() }
|
||||||
|
var prev = v.render(); var crossings = 0
|
||||||
|
repeat(fs) { val x = v.render(); if (prev < 0f && x >= 0f) crossings++; prev = x }
|
||||||
|
assertEquals(440, crossings)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun serumAndWaveEditFrameLengthsAreDetected() {
|
||||||
|
val serum = FloatArray(4 * 2048) { sin(2 * PI * (it % 2048) / 2048.0).toFloat() * 0.5f }
|
||||||
|
val bytes = SampleStore.encodeWav(SampleStore.Sample(serum, 44100)) +
|
||||||
|
"clm ".toByteArray() + byteArrayOf(16, 0, 0, 0) + "<!>2048 01000000".toByteArray()
|
||||||
|
assertEquals(2048, WaveTables.detectFrameLength(bytes, serum.size))
|
||||||
|
assertEquals(256, WaveTables.guessFrameLength(64 * 256)) // WaveEdit
|
||||||
|
assertEquals(2048, WaveTables.guessFrameLength(16 * 2048))
|
||||||
|
val t = WaveTables.fromSamples("t", serum, 2048)
|
||||||
|
assertEquals(4, t.frames)
|
||||||
|
val n = t.size(0)
|
||||||
|
val peak = (0 until n).maxOf { abs(t.data[0][it]) }
|
||||||
|
assertEquals(1f, peak, 0.02f) // normalised
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun everyFactoryPresetPlaysAndFrees() {
|
||||||
|
assertEquals(12, WaveDefs.FACTORY.size)
|
||||||
|
for (p in WaveDefs.FACTORY) {
|
||||||
|
val v = voice(slot(p.name), 57)
|
||||||
|
var s = 0.0; var finite = true; var peak = 0f
|
||||||
|
repeat(fs * 2) { val x = v.render(); if (!x.isFinite()) finite = false; s += x * x; peak = maxOf(peak, abs(x)) }
|
||||||
|
val rms = sqrt(s / (fs * 2)).toFloat()
|
||||||
|
println("${p.name}: rms ${"%.3f".format(rms)} peak ${"%.3f".format(peak)}")
|
||||||
|
assertTrue(p.name, finite && rms > 0.01f && peak < 1.2f)
|
||||||
|
v.noteOff()
|
||||||
|
var frames = 0
|
||||||
|
while (v.isActive && frames < fs * 10) { v.render(); frames++ }
|
||||||
|
assertFalse("${p.name} frees", v.isActive)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun aWavetableNoteIsAboutAsLoudAsASynthNote() {
|
||||||
|
fun rms(v: SynthVoice): Float { repeat(fs / 2) { v.render() }; var s = 0.0; repeat(fs) { val x = v.render(); s += x * x }; return sqrt(s / fs).toFloat() }
|
||||||
|
val wt = SynthVoice(fs).apply { noteOn(60, 100, SynthPatch.forWave(WavePatch.from(slot("Morph Lead"), 120f))) }
|
||||||
|
val syn = SynthVoice(fs).apply { noteOn(60, 100, SynthPatch.DEFAULT) }
|
||||||
|
val ratio = rms(wt) / rms(syn)
|
||||||
|
println("wavetable/synth rms ratio $ratio")
|
||||||
|
assertTrue("ratio $ratio within -6..+6 dB", ratio in 0.5f..2f)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun cpuBudgetForFullPolyphony() {
|
||||||
|
val s = slot("Vowel Pad", "unison" to "4", "o2level" to "0.8")
|
||||||
|
val voices = Array(32) { voice(s, 40 + it) }
|
||||||
|
repeat(fs / 2) { for (v in voices) v.render() }
|
||||||
|
val t0 = System.nanoTime()
|
||||||
|
repeat(fs * 2) { for (v in voices) v.render() }
|
||||||
|
val load = (System.nanoTime() - t0) / 1e9 / 2
|
||||||
|
println("32 wavetable voices, 2 osc x 4 unison: ${"%.1f".format(load * 100)} % of real time on this host")
|
||||||
|
assertTrue(load < 1.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
# sizzletracker song
|
||||||
|
# exported from Mikro Seq: one block per canvas, all looping in parallel
|
||||||
|
version 1
|
||||||
|
bpm 97
|
||||||
|
sig 3 4
|
||||||
|
loop 0 23
|
||||||
|
|
||||||
|
group 0 Mikro Seq
|
||||||
|
block C1 12 2
|
||||||
|
scale Mel Minor
|
||||||
|
root D
|
||||||
|
roll ################################################################################################
|
||||||
|
track T1 9
|
||||||
|
0 C-2 6E ..
|
||||||
|
1 OFF .. ..
|
||||||
|
3 C-2 6E ..
|
||||||
|
4 OFF .. ..
|
||||||
|
6 C-2 6E ..
|
||||||
|
7 OFF .. ..
|
||||||
|
9 C-2 6E ..
|
||||||
|
10 OFF .. ..
|
||||||
|
track T3 9
|
||||||
|
2 F#2 46 ..
|
||||||
|
3 OFF .. ..
|
||||||
|
endblock
|
||||||
|
block C1 muted 12 1
|
||||||
|
scale Mel Minor
|
||||||
|
root D
|
||||||
|
track T2 9
|
||||||
|
3 D-2 64 ..
|
||||||
|
4 OFF .. ..
|
||||||
|
endblock
|
||||||
|
block C2 36 1
|
||||||
|
scale Mel Minor
|
||||||
|
root D
|
||||||
|
roll ################################################################################################
|
||||||
|
track T4 0
|
||||||
|
0 B-1 5A ..
|
||||||
|
5 C#2 5A ..
|
||||||
|
7 OFF .. ..
|
||||||
|
8 C#2 5A ..
|
||||||
|
9 D-2 5A ..
|
||||||
|
14 B-1 5A ..
|
||||||
|
16 OFF .. ..
|
||||||
|
17 B-1 5A ..
|
||||||
|
18 C#2 5A ..
|
||||||
|
23 D-2 5A ..
|
||||||
|
25 OFF .. ..
|
||||||
|
26 D-2 5A ..
|
||||||
|
27 B-1 5A ..
|
||||||
|
32 C#2 5A ..
|
||||||
|
34 OFF .. ..
|
||||||
|
35 C#2 5A ..
|
||||||
|
endblock
|
||||||
|
block C6 48 1
|
||||||
|
scale Mel Minor
|
||||||
|
root D
|
||||||
|
roll ################################################################################################
|
||||||
|
track T1 2
|
||||||
|
0 B-3 50 ..
|
||||||
|
1 D-4 40 ..
|
||||||
|
2 OFF .. ..
|
||||||
|
3 D-4 40 ..
|
||||||
|
4 OFF .. ..
|
||||||
|
5 F-4 50 ..
|
||||||
|
6 OFF .. ..
|
||||||
|
7 D-4 50 ..
|
||||||
|
8 D-4 40 ..
|
||||||
|
9 F-4 50 ..
|
||||||
|
10 D-4 40 ..
|
||||||
|
11 OFF .. ..
|
||||||
|
12 D-4 40 ..
|
||||||
|
13 OFF .. ..
|
||||||
|
14 E-4 50 ..
|
||||||
|
15 OFF .. ..
|
||||||
|
16 B-3 50 ..
|
||||||
|
17 D-4 40 ..
|
||||||
|
18 D-4 50 ..
|
||||||
|
19 D-4 40 ..
|
||||||
|
20 OFF .. ..
|
||||||
|
21 D-4 40 ..
|
||||||
|
22 OFF .. ..
|
||||||
|
23 D-4 50 ..
|
||||||
|
24 OFF .. ..
|
||||||
|
25 F-4 50 ..
|
||||||
|
26 D-4 40 ..
|
||||||
|
27 C#4 50 ..
|
||||||
|
28 D-4 40 ..
|
||||||
|
29 OFF .. ..
|
||||||
|
30 D-4 40 ..
|
||||||
|
31 OFF .. ..
|
||||||
|
32 B-3 50 ..
|
||||||
|
33 OFF .. ..
|
||||||
|
34 D-4 50 ..
|
||||||
|
35 D-4 40 ..
|
||||||
|
36 F-4 50 ..
|
||||||
|
37 D-4 40 ..
|
||||||
|
38 OFF .. ..
|
||||||
|
39 D-4 40 ..
|
||||||
|
40 OFF .. ..
|
||||||
|
41 F-4 50 ..
|
||||||
|
42 OFF .. ..
|
||||||
|
43 C#4 50 ..
|
||||||
|
44 D-4 40 ..
|
||||||
|
45 E-4 50 ..
|
||||||
|
46 D-4 40 ..
|
||||||
|
47 OFF .. ..
|
||||||
|
endblock
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
# sizzletracker song
|
||||||
|
# exported from Mikro Seq: one block per canvas, all looping in parallel
|
||||||
|
version 1
|
||||||
|
bpm 97
|
||||||
|
sig 4 4
|
||||||
|
loop 0 23
|
||||||
|
|
||||||
|
group 0 Mikro Seq
|
||||||
|
block C1 16 2
|
||||||
|
scale Mel Minor
|
||||||
|
root D
|
||||||
|
roll ################################################################################################
|
||||||
|
track T1 9
|
||||||
|
0 C-2 6E ..
|
||||||
|
1 OFF .. ..
|
||||||
|
4 C-2 6E ..
|
||||||
|
5 OFF .. ..
|
||||||
|
8 C-2 6E ..
|
||||||
|
9 OFF .. ..
|
||||||
|
12 C-2 6E ..
|
||||||
|
13 OFF .. ..
|
||||||
|
track T3 9
|
||||||
|
2 F#2 46 ..
|
||||||
|
3 OFF .. ..
|
||||||
|
endblock
|
||||||
|
block C1 muted 16 1
|
||||||
|
scale Mel Minor
|
||||||
|
root D
|
||||||
|
track T2 9
|
||||||
|
4 D-2 64 ..
|
||||||
|
5 OFF .. ..
|
||||||
|
endblock
|
||||||
|
block C2 48 1
|
||||||
|
scale Mel Minor
|
||||||
|
root D
|
||||||
|
roll ################################################################################################
|
||||||
|
track T4 0
|
||||||
|
0 B-1 5A ..
|
||||||
|
6 C#2 5A ..
|
||||||
|
9 OFF .. ..
|
||||||
|
10 C#2 5A ..
|
||||||
|
12 D-2 5A ..
|
||||||
|
18 B-1 5A ..
|
||||||
|
21 OFF .. ..
|
||||||
|
22 B-1 5A ..
|
||||||
|
24 C#2 5A ..
|
||||||
|
30 D-2 5A ..
|
||||||
|
33 OFF .. ..
|
||||||
|
34 D-2 5A ..
|
||||||
|
36 B-1 5A ..
|
||||||
|
42 C#2 5A ..
|
||||||
|
45 OFF .. ..
|
||||||
|
46 C#2 5A ..
|
||||||
|
endblock
|
||||||
|
block C6 64 1
|
||||||
|
scale Mel Minor
|
||||||
|
root D
|
||||||
|
roll ################################################################################################
|
||||||
|
track T1 2
|
||||||
|
0 B-3 50 ..
|
||||||
|
1 D-4 40 ..
|
||||||
|
2 OFF .. ..
|
||||||
|
3 D-4 50 ..
|
||||||
|
4 D-4 40 ..
|
||||||
|
5 OFF .. ..
|
||||||
|
6 F-4 50 ..
|
||||||
|
7 D-4 40 ..
|
||||||
|
8 OFF .. ..
|
||||||
|
9 D-4 50 ..
|
||||||
|
10 D-4 40 ..
|
||||||
|
11 OFF .. ..
|
||||||
|
12 F-4 50 ..
|
||||||
|
13 D-4 40 ..
|
||||||
|
14 OFF .. ..
|
||||||
|
15 C#4 50 ..
|
||||||
|
16 D-4 40 ..
|
||||||
|
17 OFF .. ..
|
||||||
|
18 E-4 50 ..
|
||||||
|
19 D-4 40 ..
|
||||||
|
20 OFF .. ..
|
||||||
|
21 B-3 50 ..
|
||||||
|
22 D-4 40 ..
|
||||||
|
23 OFF .. ..
|
||||||
|
24 D-4 50 ..
|
||||||
|
25 D-4 40 ..
|
||||||
|
26 OFF .. ..
|
||||||
|
27 F-4 50 ..
|
||||||
|
28 D-4 40 ..
|
||||||
|
29 OFF .. ..
|
||||||
|
30 D-4 50 ..
|
||||||
|
31 D-4 40 ..
|
||||||
|
32 OFF .. ..
|
||||||
|
33 F-4 50 ..
|
||||||
|
34 D-4 40 ..
|
||||||
|
35 OFF .. ..
|
||||||
|
36 C#4 50 ..
|
||||||
|
37 D-4 40 ..
|
||||||
|
38 OFF .. ..
|
||||||
|
39 E-4 50 ..
|
||||||
|
40 D-4 40 ..
|
||||||
|
41 OFF .. ..
|
||||||
|
42 B-3 50 ..
|
||||||
|
43 D-4 40 ..
|
||||||
|
44 OFF .. ..
|
||||||
|
45 D-4 50 ..
|
||||||
|
46 D-4 40 ..
|
||||||
|
47 OFF .. ..
|
||||||
|
48 F-4 50 ..
|
||||||
|
49 D-4 40 ..
|
||||||
|
50 OFF .. ..
|
||||||
|
51 D-4 50 ..
|
||||||
|
52 D-4 40 ..
|
||||||
|
53 OFF .. ..
|
||||||
|
54 F-4 50 ..
|
||||||
|
55 D-4 40 ..
|
||||||
|
56 OFF .. ..
|
||||||
|
57 C#4 50 ..
|
||||||
|
58 D-4 40 ..
|
||||||
|
59 OFF .. ..
|
||||||
|
60 E-4 50 ..
|
||||||
|
61 D-4 40 ..
|
||||||
|
62 OFF .. ..
|
||||||
|
endblock
|
||||||
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
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user