Add an "off" block to the arrangement, with an OFF toolbar button (v0.27.0)
An arrangement slot can now hold Arrangement.NOTE_OFF instead of a block id.
When the playhead reaches one, every track of that lane is released — the
arrangement-level equivalent of a column of note-off cells, for cutting a held
pad or a looping sample without editing the block that started it.
The OFF button sits between FILL and the A/B region controls and writes markers
across the current selection, toggling them away if they are all markers
already. Its label stays "OFF" rather than flipping to CLEAR the way FILL does:
a marker is also "filled", so FILL already reads CLEAR for it, and two adjacent
CLEAR buttons was genuinely confusing on screen. Markers draw in the palette's
`danger` red so they never read as another block.
The note-off branch of triggerCell is factored out into releaseTrack(), so the
marker and a note-off cell release identically — including the whole mixer bus
rather than just that column's voices, which is the existing cell's documented
behaviour and not something worth diverging from here.
Two things the sentinel broke that are easy to miss:
- The project writer filtered arrangement slots with `pid >= 0`, so a marker
saved silently and came back empty. Both formats now carry it: .szg writes
the value as-is, and .sng gets an 'x' alongside '#'/'.'. 'x' is an extension
to the interchange format — a reader that only knows '#' treats it as empty,
losing the marker but never mis-parsing the roll.
- A marker is NOT empty, so the run walk-back in triggerArrangementLine would
have treated it as part of a contiguous run and played the following block
from the wrong beat. It is now a boundary (Arrangement.hasBlockAt), and a
block after a marker restarts from its first beat. It still counts towards
lastFilledBeat, so playback runs up to it.
Tests cover both round-trips, graceful degradation of an unknown roll
character, and the filled-but-not-a-block distinction. Checked on an emulator
that the button appears and toggles, the marker draws red and distinct from a
block, it survives a background/restore autosave cycle, and playback crosses it
without incident.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
68e9ed8b41
commit
bcec71597d
@@ -917,18 +917,7 @@ class AudioEngine(
|
||||
*/
|
||||
private fun triggerCell(proj: Project, lane: Int, track: Int, cell: cc.tiredsysadmin.android.sizzle.model.Cell) {
|
||||
val trackKey = lane * Pattern.TRACK_COUNT + track
|
||||
if (cell.isNoteOff) {
|
||||
// Release this track's outgoing MIDI note first (external gear).
|
||||
if (moutNote[trackKey] >= 0) { emitNoteOff(moutCh[trackKey], moutNote[trackKey]); moutNote[trackKey] = -1 }
|
||||
val ch = trackLastChannel[trackKey]
|
||||
if (ch < 0) return // this track hasn't played anything yet
|
||||
for (bus in 0 until Pattern.TRACK_COUNT) {
|
||||
if (proj.mixer.channels[bus].midiChannel != ch) continue
|
||||
arps[lane * Pattern.TRACK_COUNT + bus].stop()
|
||||
releaseBus(bus)
|
||||
}
|
||||
return
|
||||
}
|
||||
if (cell.isNoteOff) { releaseTrack(proj, lane, track); return }
|
||||
if (!cell.isPlayable) return
|
||||
// Remember the channel so a later note-off on this track releases it.
|
||||
trackLastChannel[trackKey] = cell.channel
|
||||
@@ -991,6 +980,34 @@ class AudioEngine(
|
||||
* it plays a new one. Only gated voices are touched (release tails ring out), and
|
||||
* matching by owner means sibling tracks' notes on a shared bus are left alone.
|
||||
* Array loops allocate no iterator — safe on the audio thread. */
|
||||
/**
|
||||
* Release one tracker track of one arrangement lane: its outgoing MIDI note, its
|
||||
* arpeggiator, and the mixer bus it last played on. This is what a note-off cell
|
||||
* does, lifted out so an arrangement [Arrangement.NOTE_OFF] marker can do the
|
||||
* same for every track of its lane.
|
||||
*
|
||||
* Releasing the whole bus (not just this track's voices) is deliberate and
|
||||
* matches the note-off cell it was factored from: a note-off is a "stop sounding"
|
||||
* instruction to the instrument, not to one column.
|
||||
*/
|
||||
private fun releaseTrack(proj: Project, lane: Int, track: Int) {
|
||||
val trackKey = lane * Pattern.TRACK_COUNT + track
|
||||
// Release this track's outgoing MIDI note first (external gear).
|
||||
if (moutNote[trackKey] >= 0) { emitNoteOff(moutCh[trackKey], moutNote[trackKey]); moutNote[trackKey] = -1 }
|
||||
val ch = trackLastChannel[trackKey]
|
||||
if (ch < 0) return // this track hasn't played anything yet
|
||||
for (bus in 0 until Pattern.TRACK_COUNT) {
|
||||
if (proj.mixer.channels[bus].midiChannel != ch) continue
|
||||
arps[lane * Pattern.TRACK_COUNT + bus].stop()
|
||||
releaseBus(bus)
|
||||
}
|
||||
}
|
||||
|
||||
/** Release every track of [lane] — an arrangement "off" marker reaching the playhead. */
|
||||
private fun releaseLane(proj: Project, lane: Int) {
|
||||
for (t in 0 until Pattern.TRACK_COUNT) releaseTrack(proj, lane, t)
|
||||
}
|
||||
|
||||
private fun releaseTrackVoices(trackKey: Int) {
|
||||
for (v in seqVoices) if (v.ownerTrack == trackKey && v.isGated) v.noteOff()
|
||||
for (v in sampleVoices) if (v.ownerTrack == trackKey && v.isGated) v.noteOff()
|
||||
@@ -1384,11 +1401,18 @@ class AudioEngine(
|
||||
if (arr.laneMuted[lane]) continue // muted MIDI lane — skip its blocks
|
||||
val p = arr.patternAt(lane, beat)
|
||||
if (p == Arrangement.EMPTY) continue
|
||||
if (p == Arrangement.NOTE_OFF) {
|
||||
// Fire once, on the first line of the beat and in the note-off
|
||||
// pass, so it lands before anything another lane starts here.
|
||||
if (pass == 0 && lineInBeat == 0) releaseLane(proj, lane)
|
||||
continue
|
||||
}
|
||||
val pat = proj.pattern(p) ?: continue
|
||||
// Walk back to the start of this block's contiguous run of markers so it
|
||||
// plays from beat 0 wherever the run begins.
|
||||
// plays from beat 0 wherever the run begins. An off marker is a boundary,
|
||||
// not part of the run — a block placed after one restarts from its start.
|
||||
var runStart = beat
|
||||
while (runStart > 0 && arr.patternAt(lane, runStart - 1) != Arrangement.EMPTY) runStart--
|
||||
while (runStart > 0 && arr.hasBlockAt(lane, runStart - 1)) runStart--
|
||||
val blockBeats = (pat.length / linesPerBeat).coerceAtLeast(1)
|
||||
val patLine = ((beat - runStart) % blockBeats) * linesPerBeat + lineInBeat
|
||||
// The edited block drives the tracker playhead (set once, in pass 0).
|
||||
|
||||
@@ -54,7 +54,9 @@ object ProjectIo {
|
||||
for (lane in arr.slots.indices) {
|
||||
for (beat in 0 until usedBeats) {
|
||||
val pid = arr.slots[lane][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) appendLine("$lane,$beat,$pid")
|
||||
}
|
||||
}
|
||||
appendLine("[REGION A en=${arr.regionA.enabled.b()} s=${arr.regionA.start} e=${arr.regionA.end} r=${arr.regionA.repeats}]")
|
||||
|
||||
@@ -54,9 +54,19 @@ object SngFormat {
|
||||
|
||||
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 {
|
||||
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('.')
|
||||
if (roll.isNotEmpty()) appendLine("roll $roll")
|
||||
@@ -115,7 +125,12 @@ object SngFormat {
|
||||
}
|
||||
"roll" -> current?.let { blk ->
|
||||
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)
|
||||
}
|
||||
"track" -> {
|
||||
|
||||
@@ -15,7 +15,7 @@ package cc.tiredsysadmin.android.sizzle.model
|
||||
* the canvas width — the sequencer stops at [lastFilledBeat].
|
||||
*/
|
||||
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 } }
|
||||
|
||||
/** 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 =
|
||||
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 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). */
|
||||
const val MAX_BEATS = MAX_BARS * 5
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -119,6 +119,9 @@ fun ArrangementRoll(vm: AppViewModel) {
|
||||
// Whether every cell in the selection is already filled (drives FILL vs CLEAR).
|
||||
val selectionAllFilled = hasSelection &&
|
||||
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 regionAStyle = remember(c) { TextStyle(color = c.accent, fontFamily = FontFamily.Monospace, fontSize = 9.sp) }
|
||||
@@ -156,6 +159,18 @@ fun ArrangementRoll(vm: AppViewModel) {
|
||||
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) {
|
||||
if (!hasSelection) return
|
||||
region.start = beatRange.first
|
||||
@@ -388,11 +403,15 @@ fun ArrangementRoll(vm: AppViewModel) {
|
||||
val laneY = rulerHeightPx + lane * laneH
|
||||
for (beat in firstBeat until lastBeat) {
|
||||
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 inSel = selBeat0 >= 0 && lane in laneRange && beat in beatRange
|
||||
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)
|
||||
inSel -> c.bar
|
||||
beat % beatsPerBar == 0 -> c.surface
|
||||
@@ -433,7 +452,9 @@ fun ArrangementRoll(vm: AppViewModel) {
|
||||
arr = arr,
|
||||
hasSelection = hasSelection,
|
||||
selectionAllFilled = selectionAllFilled,
|
||||
selectionAllOff = selectionAllOff,
|
||||
onToggleCells = { toggleSelectedCells() },
|
||||
onToggleOff = { toggleSelectedOff() },
|
||||
onTapA = { if (arr.regionA.isValid) clearRegion(arr.regionA) else assignRegion(arr.regionA) },
|
||||
onTapB = { if (arr.regionB.isValid) clearRegion(arr.regionB) else assignRegion(arr.regionB) },
|
||||
)
|
||||
@@ -446,7 +467,9 @@ private fun LoopToolbar(
|
||||
arr: ArrModel,
|
||||
hasSelection: Boolean,
|
||||
selectionAllFilled: Boolean,
|
||||
selectionAllOff: Boolean,
|
||||
onToggleCells: () -> Unit,
|
||||
onToggleOff: () -> Unit,
|
||||
onTapA: () -> Unit,
|
||||
onTapB: () -> Unit,
|
||||
) {
|
||||
@@ -466,6 +489,13 @@ private fun LoopToolbar(
|
||||
if (selectionAllFilled) "CLEAR" else "FILL",
|
||||
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("B", arr.regionB, onTap = onTapB, vm = vm)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user