toMidi

fun toMidi(loopCount: Int = 1): ByteArray

Converts this SSEQ sequence file to a Standard MIDI File (SMF).

The returned byte array is a complete, self-contained MIDI file that can be written directly to disk or passed to a MIDI player. The file uses 48 ticks per quarter note and is SMF Type 0 (single track) when only the primary track is active, or SMF Type 1 (multiple tracks) when additional tracks were opened by the sequence via the OPEN TRACK (0x93) command.

Conversion behaviour mirrors the sseq2mid reference implementation by loveemu:

  • Notes are emitted as note-on / note-off (velocity 0) pairs.

  • Tempo changes map to SMF meta event 0x51.

  • Pan, volume, expression and other continuous controllers map to the corresponding MIDI CC numbers.

  • Program changes use bank-select CCs (0 / 32) plus a program-change message.

  • Tempo changes map to SMF meta event 0x51.

  • JUMP backward loops are repeated loopCount times (default 1 = play once, no repeat).

Return

A byte array containing the full SMF file.

Parameters

loopCount

Number of times to traverse each JUMP backward loop (minimum 1). Use 1 (default) to play the sequence once straight through; use 2 to hear one loop repetition; and so on.

Throws

IllegalArgumentException

if data does not contain a valid SSEQ file.