MIDI trace, spaced block names survive save/load, clearer clock-receive text (v0.29.1)

- input/MidiTrace: optional (setprop log.tag.SizzleMidiTrace VERBOSE) log of
  every received packet with lateness and every note handed to the engine
  with the mixer strips it reaches; flags Sizzle's own transport playing and
  clock Start/Stop acting on it. AudioEngine.describeBusTargets backs it.
- ProjectIo percent-encodes spaces/%/] in [PATTERN name=...], so "C1 muted"
  no longer comes back as "C1"; old files load unchanged.
- "Receive MIDI clock" explains that it starts Sizzle's own song, which then
  plays along with incoming notes (the cause of "mutes don't work / only C2"
  reports when used as a sound module with an imported Mikro Seq song).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Reactorcoremeltdown
2026-11-12 23:00:39 +01:00
co-authored by Claude Opus 5.5
parent df64af8c9b
commit 3c248028c9
10 changed files with 184 additions and 10 deletions
+12
View File
@@ -4,6 +4,18 @@ Sizzletracker for Android (`cc.tiredsysadmin.android.sizzle`). One entry per
version in `versions.properties`; versions before 0.28.0 are described in the git version in `versions.properties`; versions before 0.28.0 are described in the git
log (one commit per version). log (one commit per version).
## 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) ## 0.29.0 (versionCode 58)
- **MIDI inputs list** (Setup → MIDI Sync): every MIDI source Sizzle can hear - **MIDI inputs list** (Setup → MIDI Sync): every MIDI source Sizzle can hear
@@ -13,6 +13,7 @@ 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.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
@@ -61,9 +62,18 @@ class SizzleApp : Application() {
* engine, so it keeps playing incoming notes with no Activity or ViewModel. */ * engine, so it keeps playing incoming notes with no Activity or ViewModel. */
val soundModule: MidiSoundModule by lazy { val soundModule: MidiSoundModule by lazy {
MidiSoundModule(object : MidiSoundModule.NoteSink { MidiSoundModule(object : MidiSoundModule.NoteSink {
override fun busNoteOn(channel: Int, note: Int, velocity: Int) = 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) audioEngine.busNoteOn(channel, note, velocity)
override fun busNoteOff(channel: Int, note: Int) = audioEngine.busNoteOff(channel, note) }
override fun busNoteOff(channel: Int, note: Int) {
if (MidiTrace.on) MidiTrace.log("engine OFF ch=$channel ${MidiTrace.note(note)}")
audioEngine.busNoteOff(channel, note)
}
}) })
} }
@@ -158,8 +168,14 @@ class SizzleApp : Application() {
midiClock.playingProvider = { audioEngine.transport.value.isPlaying } midiClock.playingProvider = { audioEngine.transport.value.isPlaying }
midiClock.bpmProvider = { project.tempoBpm } midiClock.bpmProvider = { project.tempoBpm }
midiClock.noteSource = { audioEngine.pollMidiOut() } // forward sequenced notes out midiClock.noteSource = { audioEngine.pollMidiOut() } // forward sequenced notes out
midiClock.onReceiveStart = { main.post { if (!audioEngine.transport.value.isPlaying) audioEngine.play() } } midiClock.onReceiveStart = {
midiClock.onReceiveStop = { main.post { audioEngine.pause() } } 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 (MidiTrace.on) MidiTrace.log("clock Stop -> Sizzle's own sequencer pauses")
main.post { audioEngine.pause() }
}
midiClock.onReceiveTempo = { bpm -> main.post { project.tempoBpm = bpm.coerceIn(20f, 300f) } } midiClock.onReceiveTempo = { bpm -> main.post { project.tempoBpm = bpm.coerceIn(20f, 300f) } }
val s = runBlocking { settingsStore.load() } val s = runBlocking { settingsStore.load() }
midiClock.sendEnabled = s.sendMidiClock midiClock.sendEnabled = s.sendMidiClock
@@ -1327,6 +1327,27 @@ class AudioEngine(
return pool[base].also { it.kill() } return pool[base].also { it.kill() }
} }
/** For the MIDI trace only: what [busNoteOn] would do with [midi] on
* [midiChannel], e.g. "strip2 SAMPLER pad2 | strip4 NES_SYNTH" or "no strip". */
fun describeBusTargets(midiChannel: Int, midi: Int): String {
val proj = project ?: return "no project"
val parts = ArrayList<String>()
for (ch in 0 until Pattern.TRACK_COUNT) {
if (proj.mixer.channels[ch].midiChannel != midiChannel) continue
val slot = proj.toolbox.getOrNull(proj.mixer.channels[ch].instrumentSlot)
val type = slot?.type
parts += "strip${ch + 1} " + when {
type == null -> "no instrument (silent)"
type == ToolboxType.SAMPLER -> {
val pad = SamplerPads.padFor(midi)
if (voiceSample(slot, midi) != null) "SAMPLER pad${pad + 1}" else "SAMPLER pad${pad + 1} empty (silent)"
}
else -> type.name + if (voiceSample(slot, midi) == null && type == ToolboxType.SOUNDFONT) " no sample" else ""
}
}
return if (parts.isEmpty()) "no strip on channel $midiChannel" else parts.joinToString(" | ")
}
/** Release [midi] on every mixer channel listening on [midiChannel]. */ /** Release [midi] on every mixer channel listening on [midiChannel]. */
fun busNoteOff(midiChannel: Int, midi: Int) { fun busNoteOff(midiChannel: Int, midi: Int) {
val proj = project ?: return val proj = project ?: return
@@ -240,8 +240,10 @@ class MidiInput(
onRealtime = module::onRealtime, onRealtime = module::onRealtime,
) )
port.connect(object : MidiReceiver() { port.connect(object : MidiReceiver() {
override fun onSend(data: ByteArray, offset: Int, count: Int, timestamp: Long) = 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) parser.feed(data, offset, count)
}
}) })
open[id] = device to port open[id] = device to port
lastChange[id] = SystemClock.uptimeMillis() lastChange[id] = SystemClock.uptimeMillis()
@@ -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})"
}
@@ -38,7 +38,7 @@ object ProjectIo {
appendLine("ACTIVE=${project.activePatternId}") appendLine("ACTIVE=${project.activePatternId}")
project.patterns.forEach { p -> project.patterns.forEach { p ->
appendLine("[PATTERN id=${p.id} name=${p.name} len=${p.length}]") appendLine("[PATTERN id=${p.id} name=${encodeName(p.name)} len=${p.length}]")
for (t in 0 until Pattern.TRACK_COUNT) { for (t in 0 until Pattern.TRACK_COUNT) {
for (line in 0 until p.length) { for (line in 0 until p.length) {
val cell = p.cell(t, line) val cell = p.cell(t, line)
@@ -109,7 +109,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"
@@ -232,4 +232,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", "%")
} }
@@ -518,7 +518,8 @@ 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. " +
"Its song then plays along with any notes the other app sends.",
vm.receiveMidiClock, vm.receiveMidiClock,
) { vm.updateReceiveMidiClock(it) } ) { vm.updateReceiveMidiClock(it) }
HorizontalDivider() HorizontalDivider()
@@ -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"))
}
}
+16
View File
@@ -207,6 +207,7 @@ cc.tiredsysadmin.android.sizzle
│ ├── MidiByteParser.kt MIDI byte stream -> messages (running status, split packets, realtime, SysEx) │ ├── MidiByteParser.kt MIDI byte stream -> messages (running status, split packets, realtime, SysEx)
│ ├── MidiClock.kt MIDI clock send / follow │ ├── MidiClock.kt MIDI clock send / follow
│ ├── MidiSourceKey.kt Stable key + display name for a MIDI source (persisted on/off choice) │ ├── MidiSourceKey.kt Stable key + display name for a MIDI source (persisted on/off choice)
│ ├── MidiTrace.kt Optional receive/engine trace (setprop log.tag.SizzleMidiTrace VERBOSE)
│ └── MidiInput.kt Lists/opens MIDI sources (USB, BLE, other apps' virtual ports), reconnects dead ones -> MidiSoundModule / CC bindings │ └── MidiInput.kt Lists/opens MIDI sources (USB, BLE, other apps' virtual ports), reconnects dead ones -> MidiSoundModule / CC bindings
│ │
├── audio/ The real-time sound engine (own thread) ├── audio/ The real-time sound engine (own thread)
@@ -368,6 +369,21 @@ one is treated as dead too (events within 1 s of our own open/close are ignored)
USB and Bluetooth sources are not probed: Android reports their removal. USB and Bluetooth sources are not probed: Android reports their removal.
`MidiInput` logs connects/reconnects under the `SizzleMidi` tag. `MidiInput` logs connects/reconnects under the `SizzleMidi` tag.
**Tracing (0.29.1).** `input/MidiTrace` logs, when switched on with
`adb shell setprop log.tag.SizzleMidiTrace VERBOSE` (re-read every 500 ms, free
when off), every received packet (`recv <source> [bytes] <decoded> late=…ms`), each
note handed to the engine with the strips it reaches (`AudioEngine.describeBusTargets`:
"strip1 SAMPLER pad3", "no strip on channel 10", "pad empty (silent)") and a
`[Sizzle transport PLAYING]` flag, and clock Start/Stop acting on the transport.
Mikro Seq's debug builds log what they send under `MidiOut`, so
`adb logcat -s MidiOut SizzleMidiTrace` lines the two up. Checked this way on the
Android 15 emulator (Mikro Seq 0.13.0): 666 note messages, sent = received byte for
byte and in order, median 0.6 ms late; 243 notes over 20 s all balanced; muting a
Mikro Seq track stops its notes at the sender. The trap found: with "Receive MIDI
clock" on, Mikro Seq's Start also starts Sizzle's *own* sequencer, so a song
imported from Mikro Seq plays along with the live notes, and Mikro Seq's mutes can't
reach it.
**Verifying.** With the setting on and the app backgrounded, `adb shell dumpsys **Verifying.** With the setting on and the app backgrounded, `adb shell dumpsys
activity processes` must not show `isFrozen=true` for the Sizzle process, and activity processes` must not show `isFrozen=true` for the Sizzle process, and
another app's notes must keep sounding. Opening a virtual port binds the other another app's notes must keep sounding. Opening a virtual port binds the other
+2 -2
View File
@@ -8,8 +8,8 @@
# or polish. android.versionCode is monotonic and bumps by 1 on every release, # 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. # because F-Droid and the Android package manager order installs by it alone.
android.versionName = 0.29.0 android.versionName = 0.29.1
android.versionCode = 58 android.versionCode = 59
# No desktop builds exist yet. These lines are the agreed slots so a port starts # 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 # with a version instead of inventing one; `-` means "not built on this