diff --git a/CHANGELOG.md b/CHANGELOG.md index 8be99b1..13b4051 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,19 @@ 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). +## 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 diff --git a/app/src/main/java/cc/tiredsysadmin/android/sizzle/echofield/EchofieldDefs.kt b/app/src/main/java/cc/tiredsysadmin/android/sizzle/echofield/EchofieldDefs.kt index ef89c4f..4039081 100644 --- a/app/src/main/java/cc/tiredsysadmin/android/sizzle/echofield/EchofieldDefs.kt +++ b/app/src/main/java/cc/tiredsysadmin/android/sizzle/echofield/EchofieldDefs.kt @@ -64,15 +64,6 @@ object EchofieldDefs { ) } - /** The editor's pages: (title, keys). */ - val SECTIONS: List>> = listOf( - "Cloud" to listOf("source", "mode", "position", "texture", "scatter", "drift"), - "Play" to listOf("motion", "pitch", "harmony", "freeze", "level"), - "Grain" to listOf("size_mul", "dens_mul", "scan", "reverse", "window", "grain_tone"), - "Random" to listOf("pitch_rand", "size_rand"), - "Keys" to listOf("attack", "release", "velo"), - "Region" to listOf("start", "end"), - ) class Preset(val name: String, val values: Map) diff --git a/app/src/main/java/cc/tiredsysadmin/android/sizzle/frasil/FrasilDefs.kt b/app/src/main/java/cc/tiredsysadmin/android/sizzle/frasil/FrasilDefs.kt index b2e70bb..68efac0 100644 --- a/app/src/main/java/cc/tiredsysadmin/android/sizzle/frasil/FrasilDefs.kt +++ b/app/src/main/java/cc/tiredsysadmin/android/sizzle/frasil/FrasilDefs.kt @@ -102,16 +102,6 @@ object FrasilDefs { ParamSpec("btone", "Tone", r(64)), ParamSpec("air", "Air", 0f), ) } - /** The editor's pages: (title, keys). */ - val SECTIONS: List>> = listOf( - "Morph" to listOf(MORPH_TO, MORPH, MORPH_TIME), - "Layers" to listOf("choir", "partials", "breath", "timbre", "warmth", "body"), - "Shape" to listOf("attack", "release", "velsens"), - "Motion" to listOf("motion", "mrate", "tide", "tperiod"), - "Choir" to listOf("detune", "cfilter", "shape", "interval", "creso", "ctype", "soft"), - "Partials" to listOf("tilt", "odd", "stretch", "evolve", "beat", "formant", "peak"), - "Breath" to listOf("bres", "color", "grain", "bpitch", "btone", "air"), - ) private fun r(v: Int) = v / 127f diff --git a/app/src/main/java/cc/tiredsysadmin/android/sizzle/ui/components/Knob.kt b/app/src/main/java/cc/tiredsysadmin/android/sizzle/ui/components/Knob.kt index 21f6177..7415ffb 100644 --- a/app/src/main/java/cc/tiredsysadmin/android/sizzle/ui/components/Knob.kt +++ b/app/src/main/java/cc/tiredsysadmin/android/sizzle/ui/components/Knob.kt @@ -53,11 +53,17 @@ fun Knob( modifier: Modifier = Modifier, default: Float = min, 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, ) { val c = LocalRetro.current + val arc = color ?: c.accent val span = if (max > min) max - min else 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 // from wherever the knob currently sits. val currentValue by rememberUpdatedState(value) @@ -104,7 +110,9 @@ fun Knob( style = androidx.compose.ui.graphics.drawscope.Stroke(width = stroke), ) 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), style = androidx.compose.ui.graphics.drawscope.Stroke(width = stroke), ) diff --git a/app/src/main/java/cc/tiredsysadmin/android/sizzle/ui/toolbox/DelayEditor.kt b/app/src/main/java/cc/tiredsysadmin/android/sizzle/ui/toolbox/DelayEditor.kt index 9e9eb07..20df022 100644 --- a/app/src/main/java/cc/tiredsysadmin/android/sizzle/ui/toolbox/DelayEditor.kt +++ b/app/src/main/java/cc/tiredsysadmin/android/sizzle/ui/toolbox/DelayEditor.kt @@ -26,7 +26,6 @@ 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.DelayDivisions -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.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 * 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 - * 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. */ @Composable @@ -53,11 +52,10 @@ fun DelayEditor(vm: AppViewModel, slot: ToolboxSlot) { DelayHead(vm, slot, h, rev, Modifier.weight(1f)) } } - // Common controls (left as plain sliders with sane defaults). Feedback's max - // is the DSP's hard ceiling, so a positive-feedback runaway is impossible. - ParamControl(vm, slot, ParamSpec("feedback", "Feedback", 0.4f, 0f, DelayDivisions.MAX_FEEDBACK)) - ParamControl(vm, slot, ParamSpec("drywet", "Dry/Wet", 0.35f, 0f, 1f)) - ParamControl(vm, slot, ParamSpec("tape", "Tape Strength", 0.3f, 0f, 1f)) + // Common controls. Feedback's max is the DSP's hard ceiling (its ParamSpec), + // so a positive-feedback runaway is impossible. + PanelCard(vm, slot, Panel("Loop", Tone.OUT, listOf("feedback", "drywet", "tape"), + labels = mapOf("drywet" to "Mix", "tape" to "Tape"))) } } diff --git a/app/src/main/java/cc/tiredsysadmin/android/sizzle/ui/toolbox/DeviceLayouts.kt b/app/src/main/java/cc/tiredsysadmin/android/sizzle/ui/toolbox/DeviceLayouts.kt new file mode 100644 index 0000000..1d92442 --- /dev/null +++ b/app/src/main/java/cc/tiredsysadmin/android/sizzle/ui/toolbox/DeviceLayouts.kt @@ -0,0 +1,134 @@ +// 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 = when (type) { + ToolboxType.WAVETABLE -> listOf( + Page("Osc", listOf( + Panel("Oscillator 1", Tone.SOURCE, osc(1)), + Panel("Oscillator 2", Tone.SOURCE, osc(2)), + )), + Page("Voice", listOf( + Panel("Voice", Tone.SOURCE, listOf("unison", "spread", "sub", "noise", "velsens")), + Panel("Table import", Tone.OUT, listOf("wtframe")), + )), + Page("Filter", listOf( + Panel("Filter", Tone.FILTER, listOf("ftype", "cutoff", "reso", "keytrack", "fenv", "drive"), + Viz.Filter("ftype", "cutoff", "reso"), labels = mapOf("ftype" to "Type", "fenv" to "Env Amt")), + )), + Page("Env", listOf( + Panel("Amp envelope", Tone.ENV, listOf("attack", "decay", "sustain", "release"), ADSR), + 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") +} diff --git a/app/src/main/java/cc/tiredsysadmin/android/sizzle/ui/toolbox/Panels.kt b/app/src/main/java/cc/tiredsysadmin/android/sizzle/ui/toolbox/Panels.kt new file mode 100644 index 0000000..90b689e --- /dev/null +++ b/app/src/main/java/cc/tiredsysadmin/android/sizzle/ui/toolbox/Panels.kt @@ -0,0 +1,425 @@ +// 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 +} + +/** + * 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, + val viz: Viz? = null, + val labels: Map = emptyMap(), + val faders: List? = null, + val faderScale: Float = 1f, +) + +/** A tab of cards. */ +class Page(val title: String, val panels: List) + +@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, 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) { + 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, selected: Int, onSelect: (Int) -> Unit) { + val c = LocalRetro.current + Row( + Modifier.fillMaxWidth().horizontalScroll(rememberScrollState()), + horizontalArrangement = Arrangement.spacedBy(4.dp), + ) { + pages.forEachIndexed { i, p -> + val on = i == selected + val tone = toneColor(p.panels.first().tone) + Box( + Modifier + .border(1.dp, if (on) tone else c.grid, RectangleShape) + .background(if (on) tone.copy(alpha = 0.22f) else c.surface) + .clickable { onSelect(i) } + .padding(horizontal = 12.dp, vertical = 7.dp), + ) { + Text(p.title.uppercase(), color = if (on) tone else c.textDim, + fontFamily = FontFamily.Monospace, fontSize = 12.sp) + } + } + } +} + +/** 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) + } + panel.viz?.let { VizCanvas(slot, it, byKey, tone) } + + if (panel.faders != null) { + FaderBank(vm, slot, specs, panel, tone) + 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) } + + 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, 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, modifier: Modifier) { + 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) { + 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, panel: Panel, tone: Color) { + 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, tone: Color) { + 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)) { + 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.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) + } +} diff --git a/app/src/main/java/cc/tiredsysadmin/android/sizzle/ui/toolbox/ParamControl.kt b/app/src/main/java/cc/tiredsysadmin/android/sizzle/ui/toolbox/ParamControl.kt deleted file mode 100644 index 4f26331..0000000 --- a/app/src/main/java/cc/tiredsysadmin/android/sizzle/ui/toolbox/ParamControl.kt +++ /dev/null @@ -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) diff --git a/app/src/main/java/cc/tiredsysadmin/android/sizzle/ui/toolbox/ToolboxScreen.kt b/app/src/main/java/cc/tiredsysadmin/android/sizzle/ui/toolbox/ToolboxScreen.kt index fdcd655..c2984a2 100644 --- a/app/src/main/java/cc/tiredsysadmin/android/sizzle/ui/toolbox/ToolboxScreen.kt +++ b/app/src/main/java/cc/tiredsysadmin/android/sizzle/ui/toolbox/ToolboxScreen.kt @@ -58,9 +58,6 @@ import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.core.content.FileProvider -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.ParamSpec import cc.tiredsysadmin.android.sizzle.model.ToolboxSlot import cc.tiredsysadmin.android.sizzle.model.ToolboxType @@ -78,8 +75,9 @@ import kotlinx.coroutines.launch * * 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] - * parameter list, so new devices need no bespoke UI. + * The parameter editor groups each device's controls into cards and tabs + * ([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 fun ToolboxScreen(vm: AppViewModel) { @@ -350,10 +348,10 @@ private fun ParamEditor(vm: AppViewModel, slot: ToolboxSlot, onClose: () -> Unit // Preset browser: load / save / import / share for this device. PresetBar(vm, slot) - // The Sampler / SoundFont / Delay get bespoke editors; the reverb has so - // many controls it's paged (swipeable sections with dot pagination); the - // LFO adds a modulation-target picker; everything else uses the - // auto-generated parameter list, laid out two-per-row to fit more. + // The Synth / Sampler / SoundFont / Delay / tape and glitch effects have + // bespoke editors; everything else is grouped cards ([DevicePanels]), with + // a source strip on top for the Wavetable and Grain Cloud and the LFO's + // target picker below. when (type) { ToolboxType.NES_SYNTH -> NesSynthEditor(vm, slot) ToolboxType.MIX_TIGHTENER -> MixTightenerEditor(vm, slot) @@ -362,21 +360,19 @@ private fun ParamEditor(vm: AppViewModel, slot: ToolboxSlot, onClose: () -> Unit ToolboxType.SAMPLER -> SamplerEditor(vm, slot, samplerPad, onSelectPad = { samplerPad = it }) ToolboxType.SOUNDFONT -> SoundFontEditor(vm, slot) ToolboxType.DELAY -> DelayEditor(vm, slot) - ToolboxType.AMBIENCE -> AmbiencePager(vm, slot) - ToolboxType.MORPH_PAD -> SectionPager(vm, slot, FrasilDefs.SECTIONS, 300.dp) ToolboxType.WAVETABLE -> { WavetableEditor(vm, slot) - SectionPager(vm, slot, WaveDefs.SECTIONS, 300.dp) + DevicePanels(vm, slot, DeviceLayouts.pagesFor(type)) } ToolboxType.GRAIN_CLOUD -> { GrainCloudEditor(vm, slot) - SectionPager(vm, slot, EchofieldDefs.SECTIONS, 300.dp) + DevicePanels(vm, slot, DeviceLayouts.pagesFor(type)) } ToolboxType.LFO -> { - ParamGrid(vm, slot, type.params) + DevicePanels(vm, slot, DeviceLayouts.pagesFor(type)) LfoTargetPicker(vm, slot) } - else -> ParamGrid(vm, slot, type.params) + else -> DevicePanels(vm, slot, DeviceLayouts.pagesFor(type)) } } @@ -471,89 +467,6 @@ private fun MidiLearnPopup(vm: AppViewModel, slot: ToolboxSlot, onClose: () -> U } } -/** Lay a list of [params] out two-per-row so the editor fits more controls than a - * single stacked column. Each [ParamControl] fills its half-width cell (an odd last - * param gets an empty cell beside it). */ -@Composable -internal fun ParamGrid(vm: AppViewModel, slot: ToolboxSlot, params: List) { - 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) = - SectionPager(vm, slot, AMBIENCE_SECTIONS.map { it.title to it.keys }, 210.dp) - -/** A device's parameters as swipeable pages of (title, keys), with dot pagination. */ -@Composable -internal fun SectionPager(vm: AppViewModel, slot: ToolboxSlot, sections: List>>, height: Dp) { - val c = LocalRetro.current - val byKey = (slot.type ?: return).params.associateBy { it.key } - val pagerState = rememberPagerState(pageCount = { sections.size }) - val scope = rememberCoroutineScope() - - Column(Modifier.fillMaxWidth()) { - HorizontalPager( - state = pagerState, - modifier = Modifier.fillMaxWidth().height(height), - pageSpacing = 12.dp, - ) { page -> - val (title, keys) = sections[page] - Column(Modifier.fillMaxSize(), verticalArrangement = Arrangement.spacedBy(6.dp)) { - Text( - title, color = c.accent, - fontFamily = FontFamily.Monospace, fontSize = 12.sp, - ) - ParamGrid(vm, slot, 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 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) - -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 presets saved for this device type, plus Save (to the app's on-disk preset @@ -634,11 +547,6 @@ private fun PresetBar(vm: AppViewModel, slot: ToolboxSlot) { 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) { diff --git a/app/src/main/java/cc/tiredsysadmin/android/sizzle/wavetable/WaveDefs.kt b/app/src/main/java/cc/tiredsysadmin/android/sizzle/wavetable/WaveDefs.kt index d35c78e..661d7eb 100644 --- a/app/src/main/java/cc/tiredsysadmin/android/sizzle/wavetable/WaveDefs.kt +++ b/app/src/main/java/cc/tiredsysadmin/android/sizzle/wavetable/WaveDefs.kt @@ -57,15 +57,6 @@ object WaveDefs { } } - val SECTIONS: List>> = listOf( - "Osc 1" to listOf("o1table", "o1pos", "o1oct", "o1semi", "o1fine", "o1level", "o1bend"), - "Osc 2" to listOf("o2table", "o2pos", "o2oct", "o2semi", "o2fine", "o2level", "o2bend"), - "Voice" to listOf("unison", "spread", "sub", "noise", "velsens", "wtframe"), - "Filter" to listOf("ftype", "cutoff", "reso", "keytrack", "fenv", "drive"), - "Amp Env" to listOf("attack", "decay", "sustain", "release"), - "Mod Env" to listOf("mattack", "mdecay", "msustain", "mrelease", "menvpos"), - "LFO" to listOf("lfowave", "lfodiv", "lfopos", "lfopitch", "lfocut"), - ) class Preset(val name: String, val values: Map) diff --git a/app/src/test/java/cc/tiredsysadmin/android/sizzle/ui/toolbox/DeviceLayoutsTest.kt b/app/src/test/java/cc/tiredsysadmin/android/sizzle/ui/toolbox/DeviceLayoutsTest.kt new file mode 100644 index 0000000..7cd886b --- /dev/null +++ b/app/src/test/java/cc/tiredsysadmin/android/sizzle/ui/toolbox/DeviceLayoutsTest.kt @@ -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()))) + } +} diff --git a/docs/DEVELOPER_HANDOVER.md b/docs/DEVELOPER_HANDOVER.md index 11c3e84..1b82b99 100644 --- a/docs/DEVELOPER_HANDOVER.md +++ b/docs/DEVELOPER_HANDOVER.md @@ -225,17 +225,17 @@ cc.tiredsysadmin.android.sizzle │ └── AudioEngine.kt Oboe/AudioTrack + sample-accurate sequencer + voice/FX mixing │ ├── frasil/ MPL-2.0 (not GPL): the Morph Pad, ported from FRASIL (see §5.7) -│ ├── FrasilDefs.kt Its settings, editor pages, engine-unit mapping, the 36 drone presets +│ ├── FrasilDefs.kt Its settings, engine-unit mapping, the 36 drone presets │ ├── FrasilPatch.kt Parsed slot snapshot (+ morph target); FrasilClock (the shared TIDE time) │ └── FrasilVoice.kt One pad note: choir + partials + breath, drift, tide, warmth │ ├── wavetable/ The Wavetable synth (Sizzle's own, GPL; see §5.9) │ ├── WaveTables.kt Band-limited tables: FFT, one mip level per octave, 12 generated tables, WAV import -│ ├── WaveDefs.kt Its settings, editor pages, 12 factory presets +│ ├── WaveDefs.kt Its settings, 12 factory presets │ └── WaveVoice.kt WavePatch + one note: 2 table oscillators, bend, unison, sub, SVF, 2 envelopes, LFO │ ├── echofield/ MIT: the Grain Cloud, ported from ECHOFIELD (see §5.8) -│ ├── EchofieldDefs.kt Its settings, editor pages, 14 factory presets, the source list +│ ├── EchofieldDefs.kt Its settings, 14 factory presets, the source list │ └── GrainCloud.kt GrainPatch + one channel's cloud: modes, scheduler, grains, gate, auto-level │ ├── cpp/native_audio.cpp Low-latency Oboe stream; RT callback pulls audio via JNI @@ -323,6 +323,32 @@ enum entry that lists its `ParamSpec`s. A `ToolboxSlot` stores the chosen type + a `name -> value` string map. The parameter editor UI and the preset text format are both **generated** from that list. See §6 to add a new device. +### 5.4.0 The generic device editor: cards, tones, tabs (0.35.0) + +Every device without a bespoke editor is drawn by `DevicePanels` +(`ui/toolbox/Panels.kt`) from a layout in `DeviceLayouts.pagesFor(type)`: a list of +`Page`s (tabs, shown only when there are several), each a list of `Panel`s (cards). +A panel names its parameter keys, a `Tone` (SOURCE / FILTER / ENV / MOD / OUT, which +picks the card and knob colour), an optional `Viz` (envelope, filter response or +LFO wave, read live from the slot) and optional short-label overrides. Inside a +card, choices come first (a segmented switch when the choices are short, else a +dropdown), then knobs, up to six to a row. A panel with `faders` draws its keys +as vertical bipolar faders instead (the graphic EQ). + +Why: the old editor was two columns of horizontal sliders, hard to scan and easy +to scroll past; grouping by function with a picture per group is how hardware +synth pages read. Why tabs and not the old swipe pager: the pager had a fixed +height, which clipped long sections, and swiping fought the knobs' vertical +drags; tabs let each page take its natural height inside the editor's scroll. + +Labels and values are derived, not written per device: `shortLabel` strips a +section prefix and unit from `ParamSpec.label` ("Osc1 Level" → "Level", "LFO > +Pitch" → "→ Pitch"), and `formatParam` picks the unit (time keys in ms / s, "(dB)" +labels in dB, 0..1 as %, TimeDivision indices by name, plus a small key → unit +table). `DeviceLayoutsTest` checks that every parameter of every laid-out device +is on exactly one card and that knob labels stay short. A device missing from +`DeviceLayouts` falls back to one card with all its parameters. + ### 5.4.1 Opening a device's settings from another tab The Toolbox owns its editor state (`editing` in `ToolboxScreen`). Other screens ask @@ -598,8 +624,12 @@ of real time on a desktop JVM. - **MIDI effect** (arp/transpose/LFO-style): hook into the sequencer instead of the signal path (see `advanceArps` / `applyLfos` in `AudioEngine`). The Toolbox picker, parameter editor, and preset save/load all work automatically -from the `ParamSpec` list. A device with many parameters can ship a bespoke -editor (see `ui/toolbox/DelayEditor.kt`, `SamplerEditor.kt`). +from the `ParamSpec` list (the editor then shows one card with every parameter). +3. Group its controls: add a case to `DeviceLayouts.pagesFor` (cards, tones, + drawings; see §5.4.0) and add the type to nothing else — `DeviceLayoutsTest` + fails if a parameter is missing or listed twice. A device that needs a custom + gesture can ship a bespoke editor instead (see `ui/toolbox/DelayEditor.kt`, + `SamplerEditor.kt`) and join the test's `bespoke` set. ### Add a new input gesture/control 1. Add a case to `InputAction`. diff --git a/docs/USER_GUIDE.md b/docs/USER_GUIDE.md index 74afd44..a445d6c 100644 --- a/docs/USER_GUIDE.md +++ b/docs/USER_GUIDE.md @@ -224,6 +224,14 @@ an instrument (**INS**) or effect (**EFF**). The keyboard pinned at the bottom of the Toolbox auditions the current device. +**Device editors.** Controls are grouped into cards by what they do, each with its +own colour: amber for the sound source, green for the filter, pink for envelopes, +violet for modulation, white for output and mix. Bigger devices split their cards +into tabs along the top (Wavetable: OSC · VOICE · FILTER · ENV · LFO). Drag a knob +up or down to turn it, double‑tap it to reset; short choices are switches you tap. +Envelope, filter and LFO cards draw their shape and follow the knobs as you turn +them. The 10‑Band EQ is a row of vertical faders (double‑tap one to flatten it). + ### Instruments **Synth** — a three‑oscillator subtractive synth (Minimoog‑style): three diff --git a/versions.properties b/versions.properties index 2b7cc02..16cb062 100644 --- a/versions.properties +++ b/versions.properties @@ -8,8 +8,8 @@ # or polish. android.versionCode is monotonic and bumps by 1 on every release, # because F-Droid and the Android package manager order installs by it alone. -android.versionName = 0.34.0 -android.versionCode = 65 +android.versionName = 0.35.0 +android.versionCode = 66 # No desktop builds exist yet. These lines are the agreed slots so a port starts # with a version instead of inventing one; `-` means "not built on this