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:
Reactorcoremeltdown
2026-11-03 22:42:55 +01:00
co-authored by Claude Opus 5
parent 68e9ed8b41
commit bcec71597d
8 changed files with 188 additions and 22 deletions
@@ -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)
}
}