Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | 262x 430x 205x 205x 205x 409x 409x 427x 409x 409x 6x 11x 6x 415x 403x 415x 214x 6x 6x 6x 6x 12x 12x 7x 7x 5x 6x 209x 209x 209x 208x 208x 208x 5x 5x 203x 208x 208x 208x 208x 29x 174x 2x 172x 209x 209x 209x 209x 417x 417x 207x 207x 207x 417x 417x 7x 417x 8x 8x 7x 7x 7x 209x | import type { NonstopPlanOptions, NonstopStagePlacement } from './plan.ts';
/** A tempo the BPM readouts show from `seconds` on. */
export interface NonstopTempoPoint {
seconds: number;
bpm: number;
}
/** What the readouts need from one stage chart. */
export interface NonstopStageReadoutInput {
/**
* The stage's tempo points in its own seconds, in order: the BPM it starts at (at 0) first, then each BPM change, as
* its readout shows it (`|BPM|`; LR2 reads a negative `#BPMxx` as `|trunc(BPM)|`).
*/
tempo: readonly NonstopTempoPoint[];
/** The header `#BPM`, when the chart has one. */
headerBPM?: number;
/** The header `#RANK`, when the chart has one. */
rank?: number;
/** Source units for a mixed-format NONSTOP stage; omitted by the legacy BMS stitch path. */
sourceFormat?: 'bms' | 'bmson';
bmsonJudgeRank?: number;
exRank?: number;
/**
* The stage's own `#EXRANKxx` changes (channel `A0`), at stitched seconds inside its window, in time order, with the
* `#EXRANKxx` value (`#DEFEXRANK` units).
*/
exRankChanges?: readonly { seconds: number; exRank: number }[];
/** Stitched seconds of the stage's first and last judged note heads, when it has any. */
noteHeads?: { first: number; last: number };
}
/**
* How a later stage's `#RANK` sets the judge windows: `'chart'` as a chart opening with that `#RANK` does, or
* `'lr2-nonstop'` by the table LR2's NONSTOP rank object reads (`LR2body.exe` 0x42be2f). Mixed bmson output also
* carries raw `judge_rank` (`'bmson'`) or BMS `#DEFEXRANK` (`'bms-exrank'`) values. `'bms-exrank-change'` is a stage's
* own `#EXRANKxx` change (channel `A0`, `#DEFEXRANK` units), which only the `lr2` ruleset applies, as for a chart alone.
*/
export type NonstopStageRankTable = 'chart' | 'lr2-nonstop' | 'bmson' | 'bms-exrank' | 'bms-exrank-change';
/** A later stage's `#RANK` taking over the judge windows from stitched `seconds` on. */
export interface NonstopStageRank {
seconds: number;
rank: number;
table: NonstopStageRankTable;
}
/** `#RANK` when a chart has none, as LR2 and the engine read it (NORMAL). */
const DEFAULT_RANK = 2;
function stageWindow(placements: readonly NonstopStagePlacement[], index: number): { start: number; end: number } {
return {
start: index === 0 ? Number.NEGATIVE_INFINITY : placements[index - 1]!.boundarySeconds,
end: index === placements.length - 1 ? Number.POSITIVE_INFINITY : placements[index]!.boundarySeconds,
};
}
/**
* The BPM readout timeline of a stitched NONSTOP chart, which itself runs at a constant 150 BPM: each stage's own BPM,
* scaled by its FIT rate, as LR2 shows it (`LR2body.exe` 0x4b0690 inserts each later stage's `#BPM` as a BPM object at
* its start, `val × freqSpeedMultiplier`, OpenLR2 `LR2f.cpp` L26257-L26273; the play loop's BPM object sets the readout,
* L12717-L12724).
*
* - `'intended'` (default): each stage's BPM over its own window, from the previous boundary to its own.
* - `'lr2'`: as LR2's event order gives it. A later stage's `#BPM` takes over at the stage's own time zero, which its cut
* moves before the previous boundary; a stage without `#BPM` keeps the previous BPM. A stage's BPM changes from its
* last-measure line on are dropped, except the last stage's (L26970-L26976).
*/
export function resolveNonstopTempo(
stages: readonly NonstopStageReadoutInput[],
placements: readonly NonstopStagePlacement[],
options: NonstopPlanOptions = {},
): NonstopTempoPoint[] {
const lr2 = options.placement === 'lr2';
const points: NonstopTempoPoint[] = [];
stages.forEach((stage, index) => {
const placement = placements[index];
Iif (placement === undefined) return;
const stitched = stage.tempo.map((point) => ({
seconds: placement.offsetSeconds + point.seconds / placement.rate,
bpm: point.bpm * placement.rate,
}));
const window = stageWindow(placements, index);
if (lr2) {
const own = index > 0 && stage.headerBPM === undefined ? stitched.slice(1) : stitched;
points.push(...own.filter((point) => point.seconds < window.end));
return;
}
// The BPM the stage is at when its window opens, then its changes inside the window.
const atStart = stitched.filter((point) => point.seconds <= window.start).at(-1);
if (atStart !== undefined) points.push({ seconds: window.start, bpm: atStart.bpm });
points.push(...stitched.filter((point) => point.seconds > window.start && point.seconds < window.end));
});
// Stable: on a tie the later stage's tempo comes last and shows.
return points.sort((left, right) => left.seconds - right.seconds);
}
/** The BPM a NONSTOP readout shows at stitched `seconds` ({@link resolveNonstopTempo}); the first one before it. */
export function nonstopBPMAt(tempo: readonly NonstopTempoPoint[], seconds: number): number | undefined {
let low = 0;
let high = tempo.length - 1;
let found = -1;
while (low <= high) {
const middle = (low + high) >> 1;
if (tempo[middle]!.seconds <= seconds) {
found = middle;
low = middle + 1;
} else {
high = middle - 1;
}
}
return tempo[Math.max(0, found)]?.bpm;
}
/**
* The judge rank changes of a stitched NONSTOP chart: the stitched chart opens with the first stage's `#RANK`, and LR2
* switches to each later stage's `#RANK` during the play. Its loader inserts the `#RANK` of a later stage as an object
* (op 1001) at the stage's start (OpenLR2 `LR2f.cpp` L26301-L26313), which the stage's cut then moves earlier with the
* rest of the stage, and the play loop sets the judge windows when it reaches it (L12831-L12877, `LR2body.exe`
* 0x42be2f, for both players).
*
* - `'lr2'`: as LR2 does it, including what looks like a bug: the change comes at the stage's own time zero, which can
* be well before the previous stage's last notes; a stage without `#RANK` keeps the rank in force; and the windows
* come from a table of their own, which differs from the one a chart opens with for VERY HARD (PGREAT ±12 / GREAT ±24 /
* GOOD ±60 ms instead of ±8 / ±24 / ±40) and HARD (±15 / ±30 / ±80 instead of ±15 / ±30 / ±60).
* - `'intended'` (default): each stage is judged with its own `#RANK`, with the windows a chart opening with that
* `#RANK` gets, and a stage without `#RANK` is NORMAL, as it would be alone. The change comes halfway between the
* previous stage's last note and the stage's first one, so the previous stage's last notes keep their rank even when
* they lie past the boundary or are hit late; without notes on either side, at the boundary.
*
* A stage's own `#EXRANKxx` changes (`exRankChanges`) follow as `'bms-exrank-change'`, at their own time with
* `'lr2'`; by default each holds from its time (or the stage's own switch, when it comes earlier) until the next stage
* switches, so it changes that stage's judging as it would the chart alone.
*/
export function resolveNonstopStageRanks(
stages: readonly Pick<
NonstopStageReadoutInput,
'rank' | 'noteHeads' | 'sourceFormat' | 'bmsonJudgeRank' | 'exRank' | 'exRankChanges'
>[],
placements: readonly NonstopStagePlacement[],
options: NonstopPlanOptions = {},
): NonstopStageRank[] {
const lr2 = options.placement === 'lr2';
// Each stage's switch, in stage order (the first stage has none: the chart opens with its rank).
const switches: (NonstopStageRank | undefined)[] = [undefined];
for (let index = 1; index < stages.length && index < placements.length; index += 1) {
const declared = stages[index]!.rank;
const rank = declared !== undefined && Number.isFinite(declared) ? Math.trunc(declared) : undefined;
if (lr2) {
switches.push(
rank !== undefined ? { seconds: placements[index]!.offsetSeconds, rank, table: 'lr2-nonstop' } : undefined,
);
continue;
}
const previousLast = stages[index - 1]!.noteHeads?.last;
const first = stages[index]!.noteHeads?.first;
const seconds =
previousLast !== undefined && first !== undefined
? (previousLast + first) / 2
: stageWindow(placements, index).start;
const stage = stages[index]!;
if (stage.sourceFormat === 'bmson') {
switches.push({
seconds,
rank: stage.bmsonJudgeRank !== undefined && stage.bmsonJudgeRank > 0 ? stage.bmsonJudgeRank : 100,
table: 'bmson',
});
} else if (stage.exRank !== undefined) {
switches.push({ seconds, rank: stage.exRank, table: 'bms-exrank' });
} else switches.push({ seconds, rank: rank ?? DEFAULT_RANK, table: 'chart' });
}
// Pushed stage by stage, each switch before the stage's own changes: the stable sort keeps a change after a switch at
// the same time.
const ranks: NonstopStageRank[] = [];
// Whether the ranks went in out of time order: sorting a list already in order would only cost time.
let unordered = false;
let last = Number.NEGATIVE_INFINITY;
for (let index = 0; index < switches.length; index += 1) {
const own = switches[index];
if (own !== undefined) {
ranks.push(own);
if (own.seconds < last) unordered = true;
last = own.seconds;
}
const changes = stages[index]?.exRankChanges;
if (changes === undefined || changes.length === 0) continue;
const next = lr2 ? undefined : switches[index + 1]?.seconds;
for (const change of changes) {
const seconds = lr2 || own === undefined ? change.seconds : Math.max(change.seconds, own.seconds);
if (next !== undefined && seconds >= next) continue;
ranks.push({ seconds, rank: change.exRank, table: 'bms-exrank-change' });
Iif (seconds < last) unordered = true;
last = seconds;
}
}
return unordered ? ranks.sort((left, right) => left.seconds - right.seconds) : ranks;
}
|