Mix: long-press an instrument or FX slot to open its settings (0.33.0)

The mixer's INSTRUMENT and FX dropdowns take a long-press (with a haptic
tick) that opens that toolbox slot's editor via a view-model request; the
Toolbox consumes it and returns to the Mix tab on CLOSE or Back. A tap
still opens the slot menu.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Reactorcoremeltdown
2026-11-13 09:55:50 +01:00
co-authored by Claude Opus 5.5
parent c8d760ed17
commit 3088912264
8 changed files with 81 additions and 6 deletions
@@ -43,6 +43,9 @@ import kotlinx.coroutines.launch
*/
/** Tab index of the Tracker tab (see [App]'s tab order). */
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
* slot's value map (`midicc@<paramKey>` -> CC number) so they persist with the
@@ -236,6 +239,22 @@ class AppViewModel(
// ------------------------------------------------------------- tab control
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
fun focusCell(track: Int, line: Int, column: CellColumn) {
val p = project.activePattern()
@@ -3,9 +3,11 @@
package cc.tiredsysadmin.android.sizzle.ui.components
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.waitForUpOrCancellation
@@ -27,7 +29,9 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
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.style.TextOverflow
import androidx.compose.ui.unit.Dp
@@ -142,6 +146,7 @@ private const val REPEAT_MIN_MS = 24L
private const val REPEAT_DECAY = 0.80
/** A labelled dropdown selector rendered as `LABEL:value ▾`. */
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun <T> RetroDropdown(
label: String,
@@ -149,9 +154,13 @@ fun <T> RetroDropdown(
selected: T,
modifier: Modifier = Modifier,
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,
) {
val c = LocalRetro.current
val haptics = LocalHapticFeedback.current
var open by remember { mutableStateOf(false) }
// Reserve the width of the longest option so the field never resizes as the
// selection changes — a common source of toolbar "jitter".
@@ -164,7 +173,13 @@ fun <T> RetroDropdown(
Modifier
.border(1.dp, c.grid, RectangleShape)
.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),
) {
// 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.ToolboxKind
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.components.RepeatButton
import cc.tiredsysadmin.android.sizzle.ui.components.RetroButton
@@ -215,6 +216,8 @@ private fun ColumnScope.ChannelRouting(vm: AppViewModel, channel: MixerChannel)
options = listOf(-1) + instrumentSlots.map { it.index },
selected = channel.instrumentSlot,
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() },
modifier = Modifier.fillMaxWidth(),
)
@@ -226,6 +229,8 @@ private fun ColumnScope.ChannelRouting(vm: AppViewModel, channel: MixerChannel)
options = listOf(-1) + effectSlots.map { it.index },
selected = channel.fxSlots[fx],
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() },
modifier = Modifier.fillMaxWidth(),
)
@@ -39,6 +39,7 @@ import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
@@ -88,20 +89,37 @@ fun ToolboxScreen(vm: AppViewModel) {
var editing by remember { mutableStateOf<Int?>(null) }
var picking 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
// switches tabs.
BackHandler(enabled = editing != null || picking != null || clearing != null) {
when {
clearing != null -> clearing = null
editing != null -> editing = null
editing != null -> closeEditor()
else -> picking = null
}
}
// 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.
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
// 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 }
@@ -149,7 +167,7 @@ fun ToolboxScreen(vm: AppViewModel) {
)
}
editing?.let { index ->
ParamEditor(vm, vm.project.toolbox[index], onClose = { editing = null })
ParamEditor(vm, vm.project.toolbox[index], onClose = closeEditor)
}
clearing?.let { index ->
val slot = vm.project.toolbox[index]