@xromdev/notation 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notation.js","sourceRoot":"","sources":["../src/notation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,2EAA2E;AAC3E,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AACpC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC;AACnC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,iBAAiB,GAAG,iBAAiB,CAAC;AACnE,iDAAiD;AACjD,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,YAAoB,EAAU,EAAE,CAAC,YAAY,GAAG,iBAAiB,CAAC;AAE1F;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAC7B,YAAoB;AACpB;;;;GAIG;AACH,SAAkB;IAElB,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,IAAI,GAAG,CAAC,iBAAiB,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC;QACjD,IAAI,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,YAAY,GAAG,IAAI,KAAK,CAAC,EAAE,CAAC;YACxD,OAAO,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI,EAAE,SAAS,EAAE,CAAC;QACnD,CAAC;IACH,CAAC;IACD,KAAK,MAAM,SAAS,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAU,EAAE,CAAC;QACpD,MAAM,IAAI,GAAG,CAAC,iBAAiB,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC;QACjD,IAAI,YAAY,GAAG,IAAI,KAAK,CAAC;YAAE,OAAO,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI,EAAE,SAAS,EAAE,CAAC;IAClF,CAAC;IACD,OAAO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ACnC,MAAM,GAAG,GAAG,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;YAClD,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;YACnC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;QACrC,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC1B,CAAC","sourcesContent":["/**\n * Ticks read as NOTATION: note values, dots, ties and bar lines.\n *\n * Nothing here quantises, because nothing has to: one tick is exactly a\n * sixty-fourth note (a sixteenth of a quarter), so every note given already\n * sits on the grid notation is written on. That is what makes music read out\n * of a game cartridge writable at all — the usual failure of notation built\n * from MIDI is a performance that lands a few milliseconds off the beat, and\n * a sound driver gives no performance, only the integers it counts. Anything\n * else has to be quantised to sixty-fourths before it comes here.\n *\n * The rules were made on Battletoads (NES), whose driver counts in exactly\n * these ticks, and checked by ear on its twenty tracks; the examples in these\n * comments are the bars that decided them.\n *\n * Durations come out as VexFlow codes (`w h q 8 16 32 64`), pitches as VexFlow\n * keys (`c#/4`) — the shortest names there are, and what a renderer reads.\n */\n\n/** Engine ticks in a quarter note. The driver's own grid, not a choice. */\nexport const TICKS_PER_QUARTER = 16;\nexport const BEATS_PER_MEASURE = 4;\n/**\n * A bar of 4/4, which is what all but one track is written in and what every\n * caller gets by default.\n *\n * Not a constant of the music: Volkmire's Inferno Race is in 2/4, and its\n * sections — the change to D major among them — start on odd multiples of half\n * a 4/4 bar, so no 64-tick bar line can hold them. So everything here takes the\n * bar length it is barring to, and `MEASURE_TICKS` is only the default.\n */\nexport const MEASURE_TICKS = TICKS_PER_QUARTER * BEATS_PER_MEASURE;\n/** Quarters in a bar of `measureTicks` ticks. */\nexport const beatsIn = (measureTicks: number): number => measureTicks / TICKS_PER_QUARTER;\n\n/**\n * A bar of so many ticks as a time signature.\n *\n * In the note value that measures it WHOLE: 64 ticks are 4/4 and 32 are 2/4,\n * but an opening bar of 38 is no number of quarters — it is 19 thirty-seconds,\n * and 19/32 is what a reader is shown.\n */\nexport function timeSignatureOf(\n measureTicks: number,\n /**\n * The note value a bar is counted in, when the reading names one: 2 writes a\n * bar of 128 ticks as 4/2 rather than 8/4. Left out — or not dividing the bar,\n * as an opening bar of its own length may not — it is chosen as below.\n */\n beatValue?: number\n): { beats: number; beatValue: number } {\n if (beatValue) {\n const beat = (TICKS_PER_QUARTER * 4) / beatValue;\n if (Number.isInteger(beat) && measureTicks % beat === 0) {\n return { beats: measureTicks / beat, beatValue };\n }\n }\n for (const beatValue of [4, 8, 16, 32, 64] as const) {\n const beat = (TICKS_PER_QUARTER * 4) / beatValue;\n if (measureTicks % beat === 0) return { beats: measureTicks / beat, beatValue };\n }\n return { beats: measureTicks, beatValue: 64 };\n}\n\n/**\n * Where the bar lines of a piece fall: every bar `measureTicks` long, except\n * the first.\n *\n * The opening bar has its own length because a pickup written as a bar of rests\n * is a lie about the music: Volkmire's Inferno Race opens with a run and a held\n * note that together are six ticks longer than two of its 2/4 bars, and a\n * reader meets that as one bar of 19/32 and then 2/4 throughout, rather than as\n * a bar of rests, a bar line through the run, and a note tied over it.\n *\n * `firstBarTicks` equal to `measureTicks` is the ordinary case, and then the\n * grid is the plain multiples every other piece uses.\n *\n * `oddBars` are bars later in the piece with a length of their own — a bar of\n * 2/4 in a piece in 4/4. Arctic Caverns has one: after six bars of 4/4 the bass\n * runs up E F# G A B C D E in 32 ticks, and everything after that run, every\n * section and the loop's end, sits half a bar past the 4/4 grid.\n */\nexport interface BarGrid {\n measureTicks: number;\n firstBarTicks: number;\n /** Bars after the first with their own length, by bar index, in order. */\n oddBars?: readonly OddBar[];\n}\n\n/** A bar after the first whose length is not the metre's — see `BarGrid`. */\nexport interface OddBar {\n /** The bar's index, from 0 — never the first bar, which has `firstBarTicks`. */\n bar: number;\n ticks: number;\n}\n\nexport const barGrid = (\n measureTicks = MEASURE_TICKS,\n firstBarTicks = measureTicks,\n oddBars: readonly OddBar[] = []\n): BarGrid => ({\n measureTicks,\n firstBarTicks,\n ...(oddBars.length ? { oddBars: [...oddBars].sort((a, b) => a.bar - b.bar) } : {}),\n});\n\nconst oddBarsOf = (grid: BarGrid): readonly OddBar[] =>\n (grid.oddBars ?? []).filter((odd) => odd.bar >= 1);\n\n/** The tick a bar begins on. */\nexport const barStartOf = (grid: BarGrid, index: number): number => {\n if (index <= 0) return 0;\n let start = grid.firstBarTicks + (index - 1) * grid.measureTicks;\n for (const odd of oddBarsOf(grid)) {\n if (odd.bar >= index) break;\n start += odd.ticks - grid.measureTicks;\n }\n return start;\n};\n\n/** How long a bar is: the first and any odd bar have their own length, the rest the metre's. */\nexport const barTicksOf = (grid: BarGrid, index: number): number =>\n index === 0\n ? grid.firstBarTicks\n : (oddBarsOf(grid).find((odd) => odd.bar === index)?.ticks ?? grid.measureTicks);\n\n/** Which bar a tick falls in. Ticks before the piece belong to its first bar. */\nexport const barAt = (grid: BarGrid, tick: number): number => {\n if (tick < grid.firstBarTicks) return 0;\n let bar = 1;\n let start = grid.firstBarTicks;\n for (const odd of oddBarsOf(grid)) {\n const oddStart = start + (odd.bar - bar) * grid.measureTicks;\n if (tick < oddStart) break;\n if (tick < oddStart + odd.ticks) return odd.bar;\n bar = odd.bar + 1;\n start = oddStart + odd.ticks;\n }\n return bar + Math.floor((tick - start) / grid.measureTicks);\n};\n\n/** How many bars a piece of `totalTicks` takes, the last one counted however little it holds. */\nexport const barCountOf = (grid: BarGrid, totalTicks: number): number =>\n totalTicks <= grid.firstBarTicks ? 1 : barAt(grid, totalTicks - 1) + 1;\n\n/** One writable note value: how long it is, what it is called, how many dots. */\nexport interface NoteValue {\n ticks: number;\n /** VexFlow duration code. */\n duration: string;\n dots: number;\n}\n\n/** Longest first — `decompose` takes the first that fits its own grid. */\nconst VALUES: readonly NoteValue[] = [\n { ticks: 64, duration: 'w', dots: 0 },\n { ticks: 56, duration: 'h', dots: 2 },\n { ticks: 48, duration: 'h', dots: 1 },\n { ticks: 32, duration: 'h', dots: 0 },\n { ticks: 28, duration: 'q', dots: 2 },\n { ticks: 24, duration: 'q', dots: 1 },\n { ticks: 16, duration: 'q', dots: 0 },\n { ticks: 14, duration: '8', dots: 2 },\n { ticks: 12, duration: '8', dots: 1 },\n { ticks: 8, duration: '8', dots: 0 },\n // Seven ticks are one head, not a dotted sixteenth tied to a sixty-fourth: Level Complete, pulse 2,\n // where the two heads stood so close the tie vanished and one B3 read as struck twice.\n { ticks: 7, duration: '16', dots: 2 },\n { ticks: 6, duration: '16', dots: 1 },\n { ticks: 4, duration: '16', dots: 0 },\n { ticks: 3, duration: '32', dots: 1 },\n { ticks: 2, duration: '32', dots: 0 },\n { ticks: 1, duration: '64', dots: 0 },\n];\n\n/** What one written head costs. Dominates everything else: a tie is the ugliest thing on a staff. */\nconst PIECE_COST = 100;\n/** A value begun off its own grid — a syncopation. Worth avoiding, never worth a tie. */\nconst OFF_GRID_COST = 10;\n/** A value that hides beat three, the middle of a 4/4 bar. The last tie-break. */\nconst HIDES_MIDDLE_COST = 1;\n\nfunction pieceCost(value: NoteValue, pos: number, measureTicks: number): number {\n // A dotted value sits on the grid of the value it dots: two thirds of its length with one dot,\n // four sevenths with two.\n const grid = (value.ticks * 2 ** value.dots) / (2 ** (value.dots + 1) - 1);\n const half = measureTicks / 2;\n const hidesMiddle = pos % measureTicks !== 0 && pos < half && pos + value.ticks > half;\n return (\n PIECE_COST + (pos % grid === 0 ? 0 : OFF_GRID_COST) + (hidesMiddle ? HIDES_MIDDLE_COST : 0)\n );\n}\n\ninterface Spelling {\n cost: number;\n pieces: NoteValue[];\n /** Heads begun off their own grid. */\n offGrid: number;\n}\n\nconst decomposeCache = new Map<number, Spelling>();\n\n/**\n * A length as a sum of writable note values, from a position in the bar.\n *\n * The FEWEST heads, and only then the tidiest. The first version was greedy and\n * took a value only when it started on its own grid, which reads well in a\n * rulebook and terribly on a staff: four ticks from the second thirty-second of\n * a beat came out as a dotted thirty-second tied to a sixty-fourth — a\n * sixteenth written as two heads, which nobody writes. Here the head count is\n * minimised outright (a sixteenth begun off the beat is a syncopation, and a\n * syncopation is one head), and starting on the grid and keeping beat three\n * visible only break ties between spellings with the same count.\n */\nexport function decompose(\n position: number,\n length: number,\n measureTicks = MEASURE_TICKS\n): NoteValue[] {\n return solve(\n ((position % measureTicks) + measureTicks) % measureTicks,\n length,\n measureTicks\n ).pieces.slice();\n}\n\nfunction solve(pos: number, left: number, measureTicks: number): Spelling {\n if (left <= 0) return { cost: 0, pieces: [], offGrid: 0 };\n const key = (measureTicks * 4096 + pos) * 4096 + left;\n const cached = decomposeCache.get(key);\n if (cached) return cached;\n\n let best: Spelling | null = null;\n // Longest first, and only a strictly cheaper spelling replaces one found\n // earlier — so among equals the long value comes first.\n for (const value of VALUES) {\n if (value.ticks > left) continue;\n const rest = solve((pos + value.ticks) % measureTicks, left - value.ticks, measureTicks);\n const own = pieceCost(value, pos, measureTicks);\n const cost = own + rest.cost;\n if (!best || cost < best.cost) {\n const offGrid = rest.offGrid + (own - PIECE_COST >= OFF_GRID_COST ? 1 : 0);\n best = { cost, pieces: [value, ...rest.pieces], offGrid };\n }\n }\n decomposeCache.set(key, best!);\n return best!;\n}\n\n/** A note of one voice, in the integers the ROM holds. */\nexport interface TickNote {\n /** Ticks from the start of the piece. */\n start: number;\n ticks: number;\n /** MIDI number. */\n midi: number;\n}\n\n/**\n * One head of a tuplet: three notes written in the time of two.\n *\n * `num` heads in the time of `occupied`, and the bracket is drawn over the run\n * from `first` to `last` — VexFlow needs the group, not the single head.\n */\nexport interface TupletSpan {\n num: number;\n occupied: number;\n first: boolean;\n last: boolean;\n}\n\n/** One head or rest on the staff — already a writable value. */\nexport interface StaffItem {\n start: number;\n ticks: number;\n /** null is a rest. */\n midi: number | null;\n duration: string;\n dots: number;\n /** Set on each head of a tuplet — see `tupletGroups`. */\n tuplet?: TupletSpan;\n /**\n * Still the same sounding note as the head before it / after it.\n *\n * A tie is the difference between one note and two, and one crossing a bar\n * line is drawn as two half curves that meet at it.\n */\n tieStart: boolean;\n tieStop: boolean;\n}\n\nexport interface StaffMeasure {\n /** Bar number from the start of the piece, counting from 0. */\n index: number;\n /** Tick the bar starts on. */\n start: number;\n items: StaffItem[];\n}\n\n/**\n * A voice's notes as a continuous ribbon: rests where it is silent, cut at\n * every bar line, and every piece already a writable value.\n *\n * Monophonic by construction — the driver walks one stream per channel — so an\n * overlap can only mean the previous note is still counted as sounding, and the\n * cursor simply moves on rather than stacking a chord that the hardware cannot\n * play.\n */\n/**\n * The divisions a tuplet may fill: a written value, so the bracket spans\n * something a reader can name. Three heads in the time of two.\n */\nconst TUPLET_TOTALS = [8, 16, 32, 64];\n\n/** One head of a tuplet, with the value it is written as. */\ninterface TupletHead {\n span: TupletSpan;\n value: NoteValue;\n}\n\n/**\n * Where the music divides a written value into THREE.\n *\n * One tick is a sixty-fourth, so a third of anything is not a whole number and\n * the driver cannot hold a true triplet: it writes the nearest integers it can,\n * and the give-away is a run of three that sums to a written value and divides\n * as evenly as integers allow without dividing evenly. A quarter triplet is\n * 10+11+11 of the half's 32 ticks; a sixteenth triplet is 2+3+3 of the\n * eighth's 8. Spelt by `decompose` instead, each of those becomes two heads\n * under a tie, and a bar of them is unreadable — which is how this was found.\n *\n * The rule is deliberately narrow, and it is checked against the ROM rather\n * than reasoned about: over all twenty tracks it fires exactly twice — title\n * music's bar 39, where pulse 1, pulse 2, the triangle and the drums all take\n * it together, and Clinger Winger's drums, once a bar for five bars. Nothing\n * else in the cartridge matches, so nothing else is re-spelt.\n *\n * Even thirds are NOT tuplets: three heads of the same written value need no\n * bracket, and the ROM has none inside these totals anyway.\n */\nexport function tupletGroups(\n notes: readonly TickNote[],\n grid: BarGrid = barGrid()\n): Map<number, TupletHead> {\n const out = new Map<number, TupletHead>();\n for (let at = 0; at + 2 < notes.length; at++) {\n const run = notes.slice(at, at + 3);\n const ticks = run[0].ticks + run[1].ticks + run[2].ticks;\n if (!TUPLET_TOTALS.includes(ticks)) continue;\n // Adjacent, and inside one bar: a bracket cannot cross a bar line.\n if (\n run.some(\n (note, index) => index > 0 && run[index - 1].start + run[index - 1].ticks !== note.start\n )\n )\n continue;\n const bar = barAt(grid, run[0].start);\n if (run[0].start - barStartOf(grid, bar) > barTicksOf(grid, bar) - ticks) continue;\n const lengths = run.map((note) => note.ticks);\n if (Math.max(...lengths) - Math.min(...lengths) > 1) continue;\n if (lengths.some((length) => length * 3 === ticks)) continue;\n // Three in the time of two, so each head is written as half the division.\n const value = VALUES.find((candidate) => candidate.ticks === ticks / 2 && candidate.dots === 0);\n if (!value) continue;\n run.forEach((_, index) =>\n out.set(at + index, {\n value,\n span: { num: 3, occupied: 2, first: index === 0, last: index === 2 },\n })\n );\n at += 2;\n }\n return out;\n}\n\n/**\n * Spans an exact tuplet may fill, in ticks, in the order they are tried: the beat first, then\n * shorter, then longer. A bracket over a beat reads better than two over its halves — unless one\n * half needs none (`plainHalf`).\n */\nconst TUPLET_SPANS = [16, 8, 4, 32, 64];\n/** How many notes a tuplet may divide its span into — every count that is not a power of two. */\nconst TUPLET_COUNTS = [3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15];\n/**\n * Each count with the parts its step may be split into: whole steps for every count first, then\n * halves, then quarters — Alien 3 opens a 9:8 of thirty-seconds with four sixty-fourths. A grid\n * that whole steps of some count already write is read as that count: six sixteenths in a quarter\n * are a sextuplet, not a triplet of eighths split in two.\n */\nconst TUPLET_GRIDS: readonly (readonly [number, number])[] = [1, 2, 4].flatMap((split) =>\n TUPLET_COUNTS.map((num) => [num, split] as const)\n);\n/** How close a start must be to a tuplet's grid, in ticks, to stand on it. */\nconst ON_GRID = 1e-6;\n\n/** The notes a tuplet of `num` is written in the time of: the largest power of two below it. */\nexport const tupletOccupied = (num: number): number => 2 ** Math.floor(Math.log2(num - 1e-9));\n\n/** One exact tuplet run: notes `from`..`to` (exclusive) of the ordered list, and its items. */\ninterface TupletRun {\n to: number;\n start: number;\n span: number;\n items: StaffItem[];\n}\n\nconst near = (value: number) => Math.abs(value - Math.round(value)) < ON_GRID;\n\n/**\n * Tuplets of any count, read from notes whose starts and ends divide a written value exactly.\n *\n * A sound driver counts whole ticks, and its triplets are 10 + 11 + 11 (`tupletGroups`). Music from\n * anywhere else can say what it means: five notes from 0 to 16, each 3.2 ticks — a quintuplet of\n * sixteenths in a quarter. A run is read as a tuplet of `num` in the time of `tupletOccupied(num)`\n * when every start and end in it falls on its grid of `span / num`, the run fills `span` from a\n * point that span may start on, and at least one of its edges is off the grid of whole ticks — so a\n * line of ordinary values is never re-read. Inside, notes may be any whole number of the grid's\n * steps — a quarter and an eighth in an eighth triplet — or of a half or a quarter of a step, and\n * the steps no note takes are rests.\n *\n * Whole-tick music never has one: no span here divides by three, five or seven into whole ticks.\n */\nfunction exactTuplets(notes: readonly TickNote[], grid: BarGrid): Map<number, TupletRun> {\n const runs = new Map<number, TupletRun>();\n for (let from = 0; from < notes.length; from++) {\n const begin = notes[from].start;\n const bar = barAt(grid, begin + ON_GRID);\n const barStart = barStartOf(grid, bar);\n const barEnd = barStart + barTicksOf(grid, bar);\n let found: TupletRun | null = null;\n for (const span of TUPLET_SPANS) {\n if (found) break;\n // On the grid the span itself keeps — a beat for anything a beat or longer.\n const step = Math.min(span, TICKS_PER_QUARTER);\n for (let start = Math.floor((begin - barStart) / step) * step + barStart; start <= begin + ON_GRID && !found; start += step) {\n if (start + span > barEnd + ON_GRID) break;\n for (const [num, split] of TUPLET_GRIDS) {\n const cells = num * split;\n const unit = span / cells;\n const run: TickNote[] = [];\n for (let j = from; j < notes.length && notes[j].start < start + span - ON_GRID; j++) run.push(notes[j]);\n if (!run.length || Math.abs(run[0].start - begin) > ON_GRID) continue;\n // An earlier note that reaches into the span leaves it no clean start.\n if (from > 0 && notes[from - 1].start + notes[from - 1].ticks > start + ON_GRID) continue;\n const steps = run.map((note) => [(note.start - start) / unit, (note.start + note.ticks - start) / unit]);\n if (!steps.every(([a, b]) => near(a) && near(b) && b <= cells + ON_GRID && a >= -ON_GRID)) continue;\n const edges = run.flatMap((note) => [note.start, note.start + note.ticks]);\n if (edges.every((edge) => near(edge))) continue;\n // A half of the span that ordinary values write on their own wants a shorter bracket: a\n // sixteenth triplet and an eighth are a triplet over the first half, not a sextuplet.\n const plainHalf = (lo: number, hi: number) =>\n run\n .filter((note) => note.start < hi - ON_GRID && note.start + note.ticks > lo + ON_GRID)\n .every(\n (note) =>\n note.start >= lo - ON_GRID &&\n note.start + note.ticks <= hi + ON_GRID &&\n near(note.start) &&\n near(note.start + note.ticks)\n );\n if (span > 4 && (plainHalf(start, start + span / 2) || plainHalf(start + span / 2, start + span))) continue;\n // The pieces: notes and the steps between them, each a value one head writes.\n const occupied = tupletOccupied(num);\n const written = span / occupied / split;\n const pieces: { from: number; length: number; midi: number | null; at?: number }[] = [];\n let at = 0;\n for (let k = 0; k < run.length; k++) {\n const a = Math.round(steps[k][0]);\n const b = Math.round(steps[k][1]);\n if (a < at) break;\n if (a > at) pieces.push({ from: at, length: a - at, midi: null });\n pieces.push({ from: a, length: b - a, midi: run[k].midi, at: run[k].start });\n at = b;\n }\n if (at < cells) pieces.push({ from: at, length: cells - at, midi: null });\n const values = pieces.map((piece) =>\n VALUES.find((value) => Math.abs(value.ticks - piece.length * written) < ON_GRID)\n );\n if (pieces.reduce((sum, piece) => sum + piece.length, 0) !== cells || values.some((value) => !value)) continue;\n // Each piece from where it starts — a note's own start, so its marks find it — to the next.\n const starts = pieces.map((piece, index) =>\n piece.at !== undefined ? piece.at : index === 0 ? start : start + Math.round(piece.from * unit * 1e9) / 1e9\n );\n const items = pieces.map((piece, index): StaffItem => {\n const pieceStart = starts[index];\n const pieceEnd = index + 1 < pieces.length ? starts[index + 1] : start + span;\n return {\n start: pieceStart,\n ticks: pieceEnd - pieceStart,\n midi: piece.midi,\n duration: values[index]!.duration,\n dots: values[index]!.dots,\n tieStart: false,\n tieStop: false,\n tuplet: { num, occupied, first: index === 0, last: index === pieces.length - 1 },\n };\n });\n found = { to: from + run.length, start, span, items };\n break;\n }\n }\n }\n if (found) {\n runs.set(from, found);\n from = found.to - 1;\n }\n }\n return runs;\n}\n\n/**\n * The exact tuplets, a run on the same grid that carries on to the beat read as one: two\n * sixteenth triplets that fill a quarter are a sextuplet, as a reader writes six in a beat. Not\n * past the beat — twelve in a half is four triplets.\n */\nfunction exactTupletsByBeat(notes: readonly TickNote[], grid: BarGrid): Map<number, TupletRun> {\n const runs = exactTuplets(notes, grid);\n const merged = new Map<number, TupletRun>();\n const ordered = [...runs.entries()].sort((a, b) => a[0] - b[0]);\n for (let i = 0; i < ordered.length; i++) {\n const [from, run] = ordered[i];\n const next = ordered[i + 1];\n const num = run.items[0].tuplet!.num;\n const double = num * 2;\n if (\n next &&\n run.span * 2 <= TICKS_PER_QUARTER &&\n (run.start - barStartOf(grid, barAt(grid, run.start + ON_GRID))) % (run.span * 2) === 0 &&\n TUPLET_COUNTS.includes(double) &&\n next[0] === run.to &&\n Math.abs(next[1].start - (run.start + run.span)) < ON_GRID &&\n next[1].span === run.span &&\n next[1].items[0].tuplet!.num === num\n ) {\n const items = [...run.items, ...next[1].items].map((item, index, all) => ({\n ...item,\n tuplet: { num: double, occupied: tupletOccupied(double), first: index === 0, last: index === all.length - 1 },\n }));\n // The written value stays: the bracket counts the same steps, twice as many of them.\n merged.set(from, { to: next[1].to, start: run.start, span: run.span * 2, items });\n i++;\n continue;\n }\n merged.set(from, run);\n }\n return merged;\n}\n\nexport function staffItems(\n notes: readonly TickNote[],\n totalTicks: number,\n grid: BarGrid = barGrid()\n): StaffItem[] {\n const items: StaffItem[] = [];\n const ordered = [...notes].sort((a, b) => a.start - b.start);\n let cursor = 0;\n\n const push = (start: number, length: number, midi: number | null) => {\n // Off the tick grid and in no tuplet — a run that does not fill its bracket: the nearest ticks.\n let position = Math.round(start);\n let left = Math.round(start + length) - position;\n let first = true;\n while (left > 0) {\n const bar = barAt(grid, position);\n const barStart = barStartOf(grid, bar);\n const barTicks = barTicksOf(grid, bar);\n const chunk = Math.min(left, barStart + barTicks - position);\n const carriesOn = chunk < left;\n\n const pieces = decompose(position - barStart, chunk, barTicks);\n let at = position;\n pieces.forEach((piece, index) => {\n items.push({\n start: at,\n ticks: piece.ticks,\n midi,\n duration: piece.duration,\n dots: piece.dots,\n // A head is tied to the one before it when it is a continuation:\n // of an earlier bar's remainder, or of the piece beside it.\n tieStop: midi !== null && (!first || index > 0),\n tieStart: midi !== null && (carriesOn || index < pieces.length - 1),\n });\n at += piece.ticks;\n });\n\n position += chunk;\n left -= chunk;\n first = false;\n }\n };\n\n const tuplets = tupletGroups(ordered, grid);\n // Exact tuplets only where some note is off the whole-tick grid: whole-tick music has none.\n const exact = ordered.some((note) => !Number.isInteger(note.start) || !Number.isInteger(note.ticks))\n ? exactTupletsByBeat(ordered, grid)\n : null;\n let skipTo = -1;\n\n ordered.forEach((note, index) => {\n if (index < skipTo) return;\n const run = exact?.get(index);\n if (run) {\n if (run.start > cursor) push(cursor, run.start - cursor, null);\n items.push(...run.items);\n cursor = run.start + run.span;\n skipTo = run.to;\n return;\n }\n if (note.start > cursor) push(cursor, note.start - cursor, null);\n cursor = Math.max(cursor, note.start);\n\n const length = Math.min(note.ticks, Math.max(0, totalTicks - cursor));\n if (length <= 0) return;\n\n // A tuplet head is written whole, at the value the bracket says: its ticks\n // are not a written value and `decompose` would tie it into scraps.\n const head = tuplets.get(index);\n if (head) {\n items.push({\n start: cursor,\n ticks: length,\n midi: note.midi,\n duration: head.value.duration,\n dots: 0,\n tieStart: false,\n tieStop: false,\n tuplet: head.span,\n });\n cursor += length;\n return;\n }\n\n push(cursor, length, note.midi);\n cursor += length;\n });\n\n if (cursor < totalTicks) push(cursor, totalTicks - cursor, null);\n return items;\n}\n\n/**\n * The ribbon cut into bars, each one filled to the bar line.\n *\n * A bar short of its four beats is not a bar — a formatter given one spaces it\n * as though the missing time did not exist, and the staff stops lining up with\n * the music beside it — so whatever is left at the end is padded with rests.\n */\nexport function staffMeasures(\n items: readonly StaffItem[],\n totalTicks: number,\n grid: BarGrid = barGrid()\n): StaffMeasure[] {\n const count = Math.max(1, barCountOf(grid, totalTicks));\n const measures: StaffMeasure[] = [];\n // `staffItems` hands the ribbon over in order, and then each bar is the next\n // run of it: one walk instead of a filter over the whole piece per bar.\n let sorted = true;\n for (let at = 1; at < items.length && sorted; at++)\n sorted = items[at - 1].start <= items[at].start;\n let next = 0;\n\n for (let index = 0; index < count; index++) {\n const start = barStartOf(grid, index);\n const barTicks = barTicksOf(grid, index);\n let inBar: StaffItem[];\n if (sorted) {\n while (next < items.length && items[next].start < start) next++;\n inBar = [];\n while (next < items.length && items[next].start < start + barTicks) inBar.push(items[next++]);\n } else {\n inBar = items.filter((item) => item.start >= start && item.start < start + barTicks);\n }\n const filled = inBar.reduce((sum, item) => sum + item.ticks, 0);\n\n // Filled to within a hair is full: a tuplet's steps are sums of fractions.\n if (barTicks - filled > ON_GRID) {\n let at = start + filled;\n for (const piece of decompose(filled, barTicks - filled, barTicks)) {\n inBar.push({\n start: at,\n ticks: piece.ticks,\n midi: null,\n duration: piece.duration,\n dots: piece.dots,\n tieStart: false,\n tieStop: false,\n });\n at += piece.ticks;\n }\n }\n\n measures.push({ index, start, items: inBar });\n }\n return measures;\n}\n\nconst STEPS = ['c', 'c', 'd', 'd', 'e', 'f', 'f', 'g', 'g', 'a', 'a', 'b'];\nconst FLAT_STEPS = ['c', 'd', 'd', 'e', 'e', 'f', 'g', 'g', 'a', 'a', 'b', 'b'];\nconst BLACK = [false, true, false, true, false, false, true, false, true, false, true, false];\n/** The white keys with a flat spelling — B as C-flat, E as F-flat — by pitch class. */\nconst WHITE_FLATS: Readonly<Record<number, string>> = { 4: 'f', 11: 'c' };\n\n/**\n * A MIDI number as a VexFlow key — `c#/4` for 61, `db/4` in a key that flats D.\n *\n * A black key is spelt the way the KEY SIGNATURE has it when the signature\n * alters either of its letters, and as a sharp otherwise. A flat key spelt in\n * sharps prints D-sharp against a signature that flattens E — a sign on nearly\n * every note — which is what rat race looked like before flats could be written.\n * Spelling EVERY black key flat in a flat key was the next mistake: Volkmire's\n * Inferno, in E-flat, climbs F to F-sharp, and printing that as G-flat put a\n * flat on a note a reader took for a B-flat already in the key.\n *\n * Two white keys have a flat spelling of their own: B is C-flat and E is F-flat. They take it only\n * in a key that flattens that letter — six flats for C-flat. Rat race is in E-flat minor, whose\n * sixth degree is C-flat; written as B it printed a natural against the B-flat of the signature.\n */\nexport function staffKey(midi: number, key?: KeySignature): string {\n const index = ((midi % 12) + 12) % 12;\n const octave = Math.floor(midi / 12) - 1;\n const flatWhite = WHITE_FLATS[index];\n if (flatWhite && key?.accidental === 'b' && key.letters.includes(flatWhite)) {\n // C-flat sits in the octave above its B: C-flat 4 is B3.\n return `${flatWhite}b/${index === 11 ? octave + 1 : octave}`;\n }\n if (!BLACK[index]) return `${STEPS[index]}/${octave}`;\n const flat =\n (key?.accidental === 'b' && key.letters.includes(FLAT_STEPS[index])) ||\n (key?.spelt?.includes(FLAT_STEPS[index]) ?? false);\n return flat ? `${FLAT_STEPS[index]}b/${octave}` : `${STEPS[index]}#/${octave}`;\n}\n\n/** Letters by diatonic step, and the steps an interval of n semitones spans when spelt plainly. */\nconst LETTER_STEP: Readonly<Record<string, number>> = { c: 0, d: 1, e: 2, f: 3, g: 4, a: 5, b: 6 };\nconst PLAIN_STEPS = [0, 1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 6];\n\n/** The other spelling of a black key: `c#/4` ↔ `db/4`. Null for a white key. */\nfunction otherSpelling(midi: number, spelt: string): string | null {\n const index = ((midi % 12) + 12) % 12;\n if (!BLACK[index]) return null;\n const octave = Math.floor(midi / 12) - 1;\n return spelt.includes('#') ? `${FLAT_STEPS[index]}b/${octave}` : `${STEPS[index]}#/${octave}`;\n}\n\n/** Diatonic position of a VexFlow key: letter step plus seven a an octave. */\nconst stepOf = (key: string) => {\n const [name, octave] = key.split('/');\n return LETTER_STEP[name[0]] + 7 * Number(octave);\n};\n\n/**\n * The heads of a chord as VexFlow keys, each black key spelt so the chord reads as intervals do.\n *\n * `staffKey` spells one note against the key, and for a line that is right: Volkmire's Inferno, in\n * E-flat, climbs F to F-sharp. A chord is read the other way — by the intervals between its heads.\n * Paganini's Caprice 17, in E-flat, strikes E-flat with G-flat: written E-flat and F-sharp, that is\n * an augmented second where a minor third sounds. So for the black keys of a chord both spellings\n * are tried, and the one whose intervals span the letters their size asks for wins — a third across\n * three letters, a second across two; where the intervals cannot tell, `staffKey` decides. In the\n * order given.\n */\nexport function chordKeys(midis: readonly number[], key?: KeySignature): string[] {\n const plain = midis.map((midi) => staffKey(midi, key));\n const choices = midis.map((midi, i) => {\n const other = otherSpelling(midi, plain[i]);\n return other ? [plain[i], other] : [plain[i]];\n });\n const cost = (keys: readonly string[]) => {\n let wrong = 0;\n for (let i = 0; i < keys.length; i++) {\n for (let j = i + 1; j < keys.length; j++) {\n const [lo, hi] = midis[i] <= midis[j] ? [i, j] : [j, i];\n const semitones = midis[hi] - midis[lo];\n const steps = stepOf(keys[hi]) - stepOf(keys[lo]);\n const expected = PLAIN_STEPS[semitones % 12] + 7 * Math.floor(semitones / 12);\n if (steps !== expected) wrong++;\n }\n }\n return wrong;\n };\n let best = plain;\n let bestCost = cost(plain);\n const walk = (at: number, picked: string[]) => {\n if (at === choices.length) {\n const c = cost(picked);\n if (c < bestCost) {\n bestCost = c;\n best = picked.slice();\n }\n return;\n }\n for (const option of choices[at]) walk(at + 1, [...picked, option]);\n };\n if (choices.some((options) => options.length > 1)) walk(0, []);\n return best;\n}\n\n/** What a key signature does: which letters it alters, and which way. */\nexport interface KeySignature {\n /** `#` for a sharp key, `b` for a flat one. C has neither and no letters. */\n accidental: '#' | 'b';\n letters: readonly string[];\n /** Letters whose black key is written flat although the key leaves the letter alone — see `keyOf`. */\n spelt?: readonly string[];\n}\n\nconst SHARP_ORDER = ['f', 'c', 'g', 'd', 'a', 'e', 'b'];\nconst FLAT_ORDER = ['b', 'e', 'a', 'd', 'g', 'c', 'f'];\n/** Signed number of sharps (+) or flats (−) by VexFlow major key name. */\nconst KEY_ALTERATIONS: Readonly<Record<string, number>> = {\n C: 0,\n G: 1,\n D: 2,\n A: 3,\n E: 4,\n B: 5,\n 'F#': 6,\n 'C#': 7,\n F: -1,\n Bb: -2,\n Eb: -3,\n Ab: -4,\n Db: -5,\n Gb: -6,\n Cb: -7,\n};\n\n/**\n * A key signature by its VexFlow name (`G` one sharp, `Eb` three flats).\n * A name it does not know is C — written with every sign at its note rather\n * than guessed at.\n */\nexport function keyOf(name?: string): KeySignature {\n const [signature, ...flats] = (name ?? '').split('+');\n const count = signature ? (KEY_ALTERATIONS[signature] ?? 0) : 0;\n const key: KeySignature =\n count < 0\n ? { accidental: 'b', letters: FLAT_ORDER.slice(0, -count) }\n : { accidental: '#', letters: SHARP_ORDER.slice(0, count) };\n return flats.length ? { ...key, spelt: flats.map((flat) => flat[0].toLowerCase()) } : key;\n}\n\n/**\n * The signature part of a key name, the one VexFlow is given — `F` of `F+Db+Ab`.\n *\n * What follows a `+` is spelling, not signature: black keys to write as those flats although the\n * key does not flatten their letters. Turbo tunnel, in D minor with one flat, falls D, D-flat, C in\n * the bass; the rule for black keys wrote the middle chord as C-sharp and G-sharp.\n */\nexport const signatureName = (name?: string): string | undefined => name?.split('+')[0];\n\n/**\n * Treble or bass for a voice, from where it actually sits.\n *\n * The median rather than the mean: one low pickup note must not drag a melody\n * onto ledger lines below the bass staff. The boundary is middle C's octave —\n * a voice whose middle is below A3 spends more of its time under the treble\n * staff than in it.\n */\nexport function chooseClef(notes: readonly { midi: number }[]): 'treble' | 'bass' {\n if (notes.length === 0) return 'treble';\n const pitches = notes.map((note) => note.midi).sort((a, b) => a - b);\n const median = pitches[Math.floor(pitches.length / 2)];\n return median < 57 ? 'bass' : 'treble';\n}\n\n/**\n * How hard a voice is to read from a given bar line: its heads, plus one for\n * every head that starts off its own grid.\n *\n * The measureTicks `voicePhase` minimises. A run of ticks written as\n * one note on the beat costs 1. The syncopation counts as much as a tie, and\n * that is deliberate: `decompose` writes an off-beat run as ONE head, so by\n * heads alone every bar line would look equally good, and the search would\n * happily put the whole piece a sixteenth off the beat.\n */\nexport function notationCost(\n notes: readonly TickNote[],\n offset: number,\n measureTicks = MEASURE_TICKS\n): number {\n let pieces = 0;\n for (const note of notes) {\n // A tuplet's note is off the tick grid, and counts at the whole ticks nearest it: left out,\n // a voice of Alien 3's 9:8 figures was read from its few plain notes, which said 3 ticks late.\n const start = Math.round(note.start);\n // + 2 bars so a shift past the first note still lands on a positive tick.\n // Measured on the plain grid: what it weighs is the phase of a voice\n // against the beat, which the opening bar's own length does not change.\n let position = start - offset + measureTicks * 2;\n let left = Math.max(1, Math.round(note.start + note.ticks) - start);\n while (left > 0) {\n const inBar = position % measureTicks;\n const chunk = Math.min(left, measureTicks - inBar);\n pieces += spellingCost(inBar, chunk, measureTicks);\n position += chunk;\n left -= chunk;\n }\n }\n return pieces;\n}\n\n/**\n * `solve`'s heads plus off-grid heads for a run inside one bar, from a flat\n * table per bar length. `voicePhase` asks this for every piece of every note,\n * four times over, and a `Map` keyed by a number past 2^31 is the slow part of\n * that — so whole-tick runs are looked up by index instead.\n */\nconst costTables = new Map<number, Int32Array>();\n\nfunction spellingCost(inBar: number, chunk: number, measureTicks: number): number {\n if (\n !Number.isInteger(measureTicks) ||\n !Number.isInteger(inBar) ||\n !Number.isInteger(chunk) ||\n inBar < 0\n ) {\n const spelling = solve(inBar, chunk, measureTicks);\n return spelling.pieces.length + spelling.offGrid;\n }\n let table = costTables.get(measureTicks);\n if (!table) {\n table = new Int32Array(measureTicks * (measureTicks + 1));\n costTables.set(measureTicks, table);\n }\n const index = inBar * (measureTicks + 1) + chunk;\n let cost = table[index];\n if (cost === 0) {\n const spelling = solve(inBar, chunk, measureTicks);\n // Stored one up, so 0 can mean \"not worked out yet\".\n cost = spelling.pieces.length + spelling.offGrid + 1;\n table[index] = cost;\n }\n return cost - 1;\n}\n\n/**\n * How many ticks one channel is written behind the beat. Never more than\n * `MAX_PHASE`.\n *\n * The delay is AUTHORED, not the driver's. Nearly every track opens a channel\n * or two with an explicit `$80` rest one sixty-fourth long, and Intruder\n * Excluder puts a three-tick rest ahead of pulse 2's copy of pulse 1's bass\n * line — a two-tick echo, some 60ms, and audible as one. (An earlier version of\n * this comment called it the cost of setup commands; the stream dump says\n * otherwise.)\n *\n * On a staff, though, it is the difference between a quarter note and a chain\n * of tied scraps, so the notes are written on the beat and the delay is\n * STATED: a staff should label every voice it moved, and not move its playhead.\n * Longer echoes (Surf City's six ticks) are past `MAX_PHASE` and are written as\n * they sound.\n */\nexport const MAX_PHASE = 3;\n\nexport function voicePhase(\n notes: readonly TickNote[],\n offset: number,\n measureTicks = MEASURE_TICKS\n): number {\n let best = 0;\n let bestCost = Infinity;\n for (let phase = 0; phase <= MAX_PHASE; phase++) {\n const cost = notationCost(notes, offset + phase, measureTicks);\n if (cost < bestCost) {\n bestCost = cost;\n best = phase;\n }\n }\n return best;\n}\n\n/**\n * A voice moved `by` ticks along the staff's clock, cut at tick 0.\n *\n * Taking a channel's delay out can carry its first sliver before the music\n * starts: ragnarok's canyon opens the noise channel with a one-tick hit on\n * tick 0 and then plays everything a tick late. Refusing the phase for the sake\n * of that sliver — which is what a guard in `voicePhase` once did — left every\n * drum on an odd tick, and each of those gave the formatter a column of\n * its own: a gap between the first two sixteenths of pulse 1 in every bar. So\n * the phase is taken, and what lands before tick 0 is cut off there.\n */\nexport function shiftNotes<T extends TickNote>(notes: readonly T[], by: number): T[] {\n const out: T[] = [];\n for (const note of notes) {\n const start = note.start + by;\n const ticks = start < 0 ? note.ticks + start : note.ticks;\n if (ticks > 0) out.push({ ...note, start: Math.max(0, start), ticks });\n }\n return out;\n}\n\n/*\n * Where the bar line falls: at the track's FIRST TICK. There is no search.\n *\n * There used to be — a search tried all 64 bar lines and kept the one that\n * wrote the music with the fewest heads, on the reasoning a transcriber uses by\n * ear. It is blind to exactly the mistake that matters: this music repeats in\n * whole-bar patterns on a sixteenth grid, so a bar line an eighth or two off\n * writes it with almost the same number of heads. Ragnarok's canyon came out at\n * 17 (1060 heads) against 1 (1064), and every bar of the score opened two\n * eighths early — heard wrong at once, while the numbers called it a win. Nine\n * of the twenty tracks were moved off tick 0 that way, most by a margin under a\n * percent.\n *\n * Tick 0 is what the evidence says instead: every channel of a track starts\n * there, the repeat points sit on ticks 1..4 in most tracks, and the MusicXML\n * export has always barred from tick 0, and the two agree. A channel's own authored delay (at most `MAX_PHASE` ticks) is still\n * taken out per voice by `voicePhase`.\n */\n\n/**\n * Ticks to ADD to a piece's own clock to get the staff's, for a bar line\n * `offset` ticks in.\n *\n * Less than a bar, so a piece barred off its first tick gets a pickup bar\n * rather than notes before tick zero — and nothing at all for offset 0, which\n * is what every track uses: an empty bar in front of the music says the music\n * starts a bar late.\n */\nexport function staffShift(offset: number, measureTicks = MEASURE_TICKS): number {\n return (measureTicks - (offset % measureTicks)) % measureTicks;\n}\n\n/**\n * How a piece is barred: where its bar lines fall, and what its notes are moved\n * by to sit behind them.\n *\n * Two readings of the same pickup. Left alone it gets a bar of its own, padded\n * in front with rests, and the music starts part way into bar one. `merged`\n * instead makes the OPENING BAR longer by the pickup and moves nothing: the run\n * and the note it lands on are one bar of 19/32, and the metre takes over after\n * it. The second reads better whenever the pickup is not a whole phrase — a bar\n * line through the middle of a run is worse than an irregular first bar.\n */\nexport function barring(\n offset: number,\n measureTicks = MEASURE_TICKS,\n merged = false,\n /** Bars later in the piece with a length of their own — see `BarGrid`. */\n oddBars: readonly OddBar[] = []\n): { grid: BarGrid; shift: number } {\n const pickup = ((offset % measureTicks) + measureTicks) % measureTicks;\n return merged\n ? { grid: barGrid(measureTicks, measureTicks + pickup, oddBars), shift: 0 }\n : {\n grid: barGrid(measureTicks, measureTicks, oddBars),\n shift: staffShift(offset, measureTicks),\n };\n}\n\nexport type Clef = 'treble' | 'bass';\n\n/**\n * The outer LINES of each staff, as MIDI numbers: E4..F5 and G2..A3.\n *\n * Not the centres — what matters for room is where the ledger lines start.\n */\nexport const STAFF_SPAN: Record<Clef, readonly [number, number]> = {\n treble: [64, 77],\n bass: [43, 57],\n};\n\n/**\n * The pitch each staff is centred on: B4 on the treble, D3 on the bass. Kept\n * for callers that want the middle line; the clef is not chosen by it.\n */\nexport const CLEF_CENTRE: Record<Clef, number> = { treble: 71, bass: 50 };\n\n/**\n * How much better the other clef has to be before a bar switches, in semitones\n * of the ladder it saves.\n *\n * Without it a line hovering between the two staves changes clef every other\n * bar, which is unreadable in a way that ledger lines are not.\n */\nexport const CLEF_HYSTERESIS = 3;\n\n/**\n * How much better a clef change PART WAY through a bar has to be than the best\n * clef for the whole bar, in semitones of the ladder it saves.\n *\n * Higher than `CLEF_HYSTERESIS`, because a change inside a bar is louder. At 3,\n * a line that crosses between the staves on every beat changed clef inside\n * bar after bar — Ragnarok's canyon went treble, bass, treble, bass through\n * bars 5 to 9 — for ladders that were only a few rungs shorter. Measured over\n * the twenty tracks' voices: at 3, 92 changes inside bars; at 6, the bar that\n * drops an octave still splits and the see-saw is gone.\n */\nexport const CLEF_SPLIT_MARGIN = 6;\n\n/**\n * What a bar costs on one clef: the TALLEST ladder of ledger lines in it, with\n * the average as a tie-break.\n *\n * The tallest, not the average, and that is the whole rule. Averaging is what a\n * first version did, and it reads the bar as a crowd: a bar of eight low notes\n * and two very high ones votes for the low clef, and the two high notes then\n * get a fourteen-rung ladder that runs off the top of the strip. What decides\n * whether a bar can be READ is its worst excursion — one note an octave out is\n * two ledger lines and fine, one note two octaves out is unreadable however\n * many of its neighbours sit comfortably.\n *\n * Measured over the twenty tracks, choosing by the worst excursion instead of\n * the average halves the bars carrying a ladder over 18 semitones (37 → 17) and\n * takes fewer clef changes to do it (129 → 112).\n */\n/** How far a pitch sits off a staff, in semitones: 0 on it. */\nfunction outside(midi: number, clef: Clef): number {\n const [low, high] = STAFF_SPAN[clef];\n return Math.max(0, midi - high, low - midi);\n}\n\nfunction clefCost(pitches: readonly number[], clef: Clef): number {\n const worst = pitches.reduce((max, midi) => Math.max(max, outside(midi, clef)), 0);\n const mean = pitches.reduce((sum, midi) => sum + outside(midi, clef), 0) / pitches.length;\n // The average never outweighs a semitone of the worst ladder; it only settles\n // bars the worst excursion calls a draw.\n return worst + mean / 100;\n}\n\n/**\n * A clef per bar — a real score changes clef, and for this music it has to.\n *\n * These channels are not instruments with a range: one voice carries the bass\n * for eight bars and then a melody three octaves up, and on one fixed clef a\n * TENTH of all the notes in the cartridge land more than an octave off the\n * staff — a ladder of ledger lines, most of it clipped by the strip's edge.\n * Chosen per bar the same figure is 1.35%, at a cost of one clef change every\n * twelve bars. What a bar costs on each clef is `clefCost`.\n *\n * A bar with nothing in it keeps the running clef rather than voting: a rest is\n * not evidence about register, and letting silence switch the clef puts the\n * change in the wrong bar.\n *\n * A bar can also change clef PART WAY THROUGH, once, where the music drops or\n * climbs into the other register. Chosen for the bar as a whole, a register\n * change inside it is paid for by every note on the wrong side of it: bar 5 of\n * Ragnarok's canyon is eleven E4s and then five E3s, and the whole bar went to\n * the bass clef — eleven heads on ledger lines to spare five. A split is taken\n * when it beats the best whole-bar clef by `CLEF_SPLIT_MARGIN`, and only from\n * the clef the bar opens in, so a bar never carries two changes.\n */\nexport function clefPlan(bars: readonly (readonly BarNote[])[], start: Clef = 'treble'): BarClef[] {\n const plan: BarClef[] = [];\n let current: Clef | null = null;\n\n for (const notes of bars) {\n if (notes.length === 0) {\n plan.push({ clef: current ?? start });\n continue;\n }\n const pitches = notes.map((note) => note.midi);\n const bass = clefCost(pitches, 'bass');\n const treble = clefCost(pitches, 'treble');\n let want: Clef = bass <= treble ? 'bass' : 'treble';\n if (current && want !== current && Math.abs(bass - treble) < CLEF_HYSTERESIS) want = current;\n\n const from = current ?? start;\n const split = bestSplit(notes, from);\n if (split && split.cost + CLEF_SPLIT_MARGIN <= clefCost(pitches, want)) {\n current = otherClef(from);\n plan.push({ clef: from, change: { tick: split.tick, clef: current } });\n } else {\n current = want;\n plan.push({ clef: want });\n }\n }\n return plan;\n}\n\n/** A note as the clef reads it: the tick of the bar it starts on, and its pitch. */\nexport interface BarNote {\n tick: number;\n midi: number;\n}\n\n/** The clef one bar opens in, and the one change inside it, if it has one. */\nexport interface BarClef {\n clef: Clef;\n /** From this tick of the bar on, the staff reads in `change.clef`. */\n change?: { tick: number; clef: Clef };\n}\n\n/** The clef a note starting on `tick` of the bar is written in. */\nexport function clefAt(bar: BarClef, tick: number): Clef {\n return bar.change && tick >= bar.change.tick ? bar.change.clef : bar.clef;\n}\n\n/** The clef a bar hands on to the next one. */\nexport function clefAfter(bar: BarClef): Clef {\n return bar.change?.clef ?? bar.clef;\n}\n\nfunction otherClef(clef: Clef): Clef {\n return clef === 'treble' ? 'bass' : 'treble';\n}\n\n/**\n * The cheapest place to leave `from` for the other clef inside a bar, and what\n * the worse half of the bar then costs.\n *\n * Only at a note: the change goes in front of the first head it is for. Never\n * at the first one — a bar that is all in the other clef changes at its bar\n * line. On a tie the LATER place wins, so the clef stands next to the notes\n * that need it rather than in front of ones that were fine either way.\n */\nfunction bestSplit(notes: readonly BarNote[], from: Clef): { tick: number; cost: number } | null {\n // Each half's `clefCost` from running totals rather than a filter per place:\n // the worst ladder and the sum of the ladders before it, and from it on.\n const ordered = [...notes].sort((a, b) => a.tick - b.tick);\n const n = ordered.length;\n const to = otherClef(from);\n const worstBefore = new Float64Array(n + 1);\n const sumBefore = new Float64Array(n + 1);\n for (let i = 0; i < n; i++) {\n const out = outside(ordered[i].midi, from);\n worstBefore[i + 1] = Math.max(worstBefore[i], out);\n sumBefore[i + 1] = sumBefore[i] + out;\n }\n const worstAfter = new Float64Array(n + 1);\n const sumAfter = new Float64Array(n + 1);\n for (let i = n - 1; i >= 0; i--) {\n const out = outside(ordered[i].midi, to);\n worstAfter[i] = Math.max(worstAfter[i + 1], out);\n sumAfter[i] = sumAfter[i + 1] + out;\n }\n let best: { tick: number; cost: number } | null = null;\n // Never at the first note: from the first head that starts later on.\n for (let at = 1; at < n; at++) {\n if (ordered[at].tick === ordered[at - 1].tick) continue;\n const cost = Math.max(\n worstBefore[at] + sumBefore[at] / at / 100,\n worstAfter[at] + sumAfter[at] / (n - at) / 100\n );\n if (!best || cost <= best.cost) best = { tick: ordered[at].tick, cost };\n }\n return best;\n}\n\n/** A pitch's distance outside its staff, in DIATONIC steps — one ledger position each. */\nfunction stepsOutside(midi: number, clef: Clef): { above: number; below: number } {\n const [low, high] = STAFF_SPAN[clef];\n const semitones = (value: number) => Math.max(0, Math.round((value * 7) / 12));\n return { above: semitones(midi - high), below: semitones(low - midi) };\n}\n\n/**\n * How far this music reaches above and below the staff, in ledger positions.\n *\n * What it is FOR: a strip has a fixed amount of room around the staff, and\n * splitting it evenly suits almost no voice. A bass line spends the whole track\n * under the staff and a lead over it — measured across the twenty tracks, only\n * a third of the voices fit an even split, while the same room divided in\n * proportion to where the notes actually go fits nearly all of them. The staff\n * is put where the music needs it rather than in the middle.\n *\n * Read over the WHOLE piece, not the bars on screen: a staff that slid up and\n * down as the melody moved would be unreadable, and would take the bar lines\n * and the pinned clef with it.\n */\nexport function staffRoom(\n bars: readonly (readonly BarNote[])[],\n clefs: readonly BarClef[]\n): { above: number; below: number } {\n let above = 0;\n let below = 0;\n bars.forEach((notes, index) => {\n const bar = clefs[index] ?? { clef: 'treble' };\n for (const { tick, midi } of notes) {\n const out = stepsOutside(midi, clefAt(bar, tick));\n above = Math.max(above, out.above);\n below = Math.max(below, out.below);\n }\n });\n return { above, below };\n}\n"]}