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 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | 38x 38x 38x 339x 352x 352x 70x 70x 70x 211x 211x 211x 211x 70x 78x 39x 39x 39x 39x 39x 39x 34x 6x 6x 28x 39x 39x 16x 9x 9x 9x 9x 21x 6x 12x 12x 12x 10x 10x 10x 56x 52x 10x 10x 65x 10x 62x 62x 10x 60x 10x 60x 1x 1x 59x 10x | import { createBeatAtSecondsResolverFromTimingResolver, type ResolvedChart } from '@be-music/chart-model';
import type { TimedLandmineNote, TimedPlayableNote } from '../playable-notes.ts';
import type { BeatorajaGaugeCategory } from '../ruleset/definitions.ts';
import type { PracticeGaugePick } from '../ruleset/practice-gauge.ts';
import type { RulesetNoteCounts } from '../ruleset/facts.ts';
import { moveNotesToBackground } from './background-notes.ts';
import { withChartOverrides } from './resolved-chart-overrides.ts';
/**
* PRACTICE, beatoraja 0.8.9's mode (`PracticeConfiguration.PracticeProperty`), under every judge ruleset (#933): the
* range played and the play rules set for it, read under the judge ruleset (`PracticeRules`). Its frequency is the
* play's tempo and its lane options are the play's own.
*/
export interface PlayPractice {
/** Where the range starts (beatoraja's `START TIME`), in chart milliseconds: the Be-Music player's first bar picked. */
startMs: number;
/**
* Where the range ends (beatoraja's `END TIME`), in chart milliseconds: the line closing the last bar picked; absent
* is the source default, the chart's last timeline + 1000.
*/
endMs?: number;
/**
* `GAUGE TYPE`: one of the judge ruleset's `resolvePracticeGaugeTypes`, or another source's qualified with it
* (`beatoraja:ASSIST-EASY`), which plays on that source's gauge and TOTAL reading.
*/
gauge: PracticeGaugePick;
/** `GAUGE CATEGORY` (beatoraja only); absent uses the play mode's. */
gaugeCategory?: BeatorajaGaugeCategory;
/** `GAUGE VALUE`. */
startGauge: number;
/** `JUDGERANK`, a judgerank percent read on the ruleset's own table; absent keeps the chart's. */
judgeRank?: number;
/** `TOTAL`; absent keeps the chart's. */
total?: number;
/**
* How many bars before the range the play starts, as a rest before its first note (0 starts at the range's head):
* the bars are played with no judged note. Absent is 1, as it was before it was a setting.
*/
restBarsBefore?: number;
/** How many bars after the range the play ends, as a rest after its last note (0 ends at the range's end); absent is 1. */
restBarsAfter?: number;
/**
* Keeps a long note that started before the range and ends in it, instead of moving it to the background with the
* rest of what lies outside (`applyPracticeRange`): the play starts early enough to play it from its head
* (`resolvePracticePlayWindow`). A Be-Music extension: beatoraja's `PracticeModifier` drops it. Absent is `false`.
*/
carriedLongNotes?: boolean;
/**
* Plays the range again in place each time it ends, until the play is interrupted (#949): once the play's end (the
* head of the bar after the one `END TIME` lies in, `resolvePracticePlayWindow`) is reached and judged, or its gauge
* empties, the play goes back to its start (the head of the bar before the range's) with the score, combo and gauge of the practice settings, as a seek there does (`restartPractice`).
* With an `END TIME` the loop is seamless: the play goes back the moment it reaches its end, carrying the time it
* overshot, without waiting for the last notes' judgment, and the next round's notes come down the lane before it
* (`resolvePracticeLoopShift`), as if the chart went on that way.
* Absent, the play ends there as any other does.
*/
loop?: boolean;
}
/** The range `PracticeModifier` keeps, in milliseconds, after the source's limits on the two times. */
export function resolvePracticeRange(practice: PlayPractice, chartEndMs: number): { startMs: number; endMs: number } {
const startMs = Math.max(0, Math.trunc(practice.startMs));
const endMs = Math.max(startMs + 1000, Math.trunc(practice.endMs ?? chartEndMs + 1000));
return { startMs, endMs };
}
/** The most bars {@link resolvePracticePlayWindow} walks, against a chart whose bar heads stop moving forwards. */
const MAX_PRACTICE_BARS = 100_000;
/**
* The chart millisecond bar `measure` starts at, whole as PRACTICE's times are (the bars picked start there): the
* resolved chart's bar line there (its `#xxx02` measure lengths or bmson lines), timed through its BPM changes and the
* stops before it. A bar past the chart's last measure is a 4/4 bar.
*/
function barHeadMs(chart: Pick<ResolvedChart, 'beatResolver' | 'timing'>, measure: number): number {
const seconds = chart.timing.beatToSeconds(chart.beatResolver.measureToBeat(measure, 0));
return Math.max(0, Math.floor(seconds * 1000 + 1e-6));
}
/** The bar chart millisecond `ms` lies in: the last bar starting at or before it. */
function barIndexAt(chart: Pick<ResolvedChart, 'beatResolver' | 'timing'>, ms: number): number {
let measure = 0;
let next = barHeadMs(chart, 1);
while (measure < MAX_PRACTICE_BARS && next <= ms) {
const after = barHeadMs(chart, measure + 2);
measure += 1;
// A bar head that stops moving forwards (a zero tempo) ends the walk.
Iif (after <= next) break;
next = after;
}
return measure;
}
/** `bars` as a whole number of rest bars: 1 when absent, never negative. */
function restBarCount(bars: number | undefined): number {
return bars === undefined || !Number.isFinite(bars) ? 1 : Math.max(0, Math.trunc(bars));
}
/**
* Where a PRACTICE play starts and ends, in chart seconds, measured in bars (#954): it starts `restBarsBefore` bars
* (1 by default) before the one the range starts in (the chart's start when that reaches past the first bar), and ends
* at the head of the bar `restBarsAfter` bars after the one its `END TIME` lies in, so a range snapped to bar lines
* plays that many whole bars on either side; 0 starts and ends at the range itself. The first round
* (`firstStartSeconds`) starts a bar before the range even with no rest before it. Without an `END TIME` (to the
* chart's end) one bar of rest ends 1000 ms past the range's end whatever the tempo, as before. Rest in bars is Be-Music's
* policy (#1191): beatoraja pads by time, from `max(starttime - 1000, 0)` to `endtime + 1000` ms (`BMSPlayer`
* L586-L587 [V]), so a slow bar rests longer than its second and a stop inside a rest bar lengthens it. With `carriedFromMs` (a long note kept from before the range) the bars before are
* counted from the bar that long note starts in.
*/
export function resolvePracticePlayWindow(
chart: Pick<ResolvedChart, 'beatResolver' | 'timing'>,
practice: Pick<PlayPractice, 'endMs' | 'restBarsBefore' | 'restBarsAfter'>,
range: { startMs: number; endMs: number },
carriedFromMs?: number,
): { startSeconds: number; endSeconds: number; firstStartSeconds: number } {
const before = restBarCount(practice.restBarsBefore);
const after = restBarCount(practice.restBarsAfter);
// A long note kept from before the range (`carriedLongNotes`) is played from its head: the bar it starts in leads.
const leadMs =
carriedFromMs !== undefined && carriedFromMs < range.startMs ? Math.max(0, carriedFromMs) : range.startMs;
const startBar = barIndexAt(chart, leadMs);
const startSeconds =
before === 0
? leadMs === range.startMs
? range.startMs / 1000
: barHeadMs(chart, startBar) / 1000
: barHeadMs(chart, Math.max(0, startBar - before)) / 1000;
let endMs: number;
if (after === 0) endMs = range.endMs;
else if (practice.endMs === undefined) {
endMs = range.endMs + 1000;
if (after > 1) endMs = Math.max(endMs, barHeadMs(chart, barIndexAt(chart, range.endMs) + after));
} else endMs = Math.max(range.endMs, barHeadMs(chart, barIndexAt(chart, range.endMs) + after));
// The first round starts a bar before the range at least, so its notes come down the lane instead of starting on the
// judgement line; the loop goes back to `startSeconds`.
const firstStartSeconds = before >= 1 ? startSeconds : barHeadMs(chart, Math.max(0, startBar - 1)) / 1000;
return {
startSeconds: Math.min(startSeconds, range.startMs / 1000),
endSeconds: endMs / 1000,
firstStartSeconds: Math.min(firstStartSeconds, range.startMs / 1000),
};
}
/**
* How far a seamless PRACTICE loop (a looping play of picked bars, whatever its rest bars) moves the play back each
* time, in chart seconds and beats: from the loop's start to the play's end (the range's end, or the end of the rest
* bars after it). `undefined` when the loop is not seamless (no loop, or the whole chart to its end).
*/
export function resolvePracticeLoopShift(
chart: Pick<ResolvedChart, 'timing'>,
practice: Pick<PlayPractice, 'loop' | 'endMs' | 'restBarsAfter'>,
window: { startSeconds: number; endSeconds: number },
): { seconds: number; beats: number } | undefined {
if (!isSeamlessPracticeLoop(practice)) return undefined;
const seconds = window.endSeconds - window.startSeconds;
Iif (!(seconds > 0)) return undefined;
const beatAt = createBeatAtSecondsResolverFromTimingResolver(chart.timing);
return { seconds, beats: beatAt(window.endSeconds) - beatAt(window.startSeconds) };
}
/**
* Whether a PRACTICE play loops seamlessly ({@link PlayPractice.loop}): it loops a range with an `END TIME`, and goes
* back the moment it reaches its end, the time it overshot carried over.
*/
export function isSeamlessPracticeLoop(practice: Pick<PlayPractice, 'loop' | 'endMs'> | undefined): boolean {
return practice?.loop === true && practice.endMs !== undefined;
}
/**
* What a seamless PRACTICE loop shows past the range's end: the range's notes once more, `shift` later, as the next
* round brings them down the lane, so they do not appear out of nowhere when the play goes back. They are drawn only:
* the judge never sees them. Each stands for its note (its lane follows any later change to the note's channel) and
* keeps its own judged and visibility marks.
*/
export function createPracticeLoopPreviewNotes(
notes: readonly TimedPlayableNote[],
shift: { seconds: number; beats: number },
): TimedPlayableNote[] {
return notes.map((note) => {
const preview = Object.create(note) as TimedPlayableNote;
Object.defineProperties(preview, {
beat: { value: note.beat + shift.beats, enumerable: true },
seconds: { value: note.seconds + shift.seconds, enumerable: true },
...(note.endBeat !== undefined ? { endBeat: { value: note.endBeat + shift.beats, enumerable: true } } : {}),
...(note.endSeconds !== undefined
? { endSeconds: { value: note.endSeconds + shift.seconds, enumerable: true } }
: {}),
judged: { value: false, writable: true, enumerable: true },
visibleUntilBeat: { value: undefined, writable: true, enumerable: true },
});
return preview;
});
}
/**
* `PracticeModifier`: move every judged object outside `[start, end)` to the background. A long note leaves with
* either end outside, since moving one end moves its pair, unless `carriedLongNotes` keeps one held into the range from
* before it (its head before `start`, its end in the range). Returns the scorable note counts from before, which the
* PRACTICE TOTAL scales against.
*/
export function applyPracticeRange(
source: ResolvedChart,
notes: TimedPlayableNote[],
mines: TimedLandmineNote[],
range: { startMs: number; endMs: number },
carriedLongNotes = false,
): {
chart: ResolvedChart;
sourceNotes: RulesetNoteCounts;
changedObjectCount: number;
/** Where the earliest long note kept from before the range starts (`carriedLongNotes`), in chart milliseconds. */
carriedFromMs?: number;
} {
const long = { 1: 0, 2: 0, 3: 0 };
let normal = 0;
for (const note of notes) {
if (note.endSeconds !== undefined && note.endSeconds > note.seconds) long[note.longNoteMode ?? source.lnMode] += 1;
else normal += 1;
}
const sourceNotes: RulesetNoteCounts = { normal, long };
const before = notes.length + mines.length;
// TimeLine times are whole milliseconds.
const msOf = (seconds: number): number => Math.floor(seconds * 1000 + 1e-6);
const outside = (seconds: number): boolean => {
const ms = msOf(seconds);
return ms < range.startMs || ms >= range.endMs;
};
// A long note held into the range from before it: its head before the range's start, its end in the range.
const carried = (object: TimedPlayableNote | TimedLandmineNote): boolean =>
carriedLongNotes &&
'endSeconds' in object &&
object.endSeconds !== undefined &&
object.endSeconds > object.seconds &&
msOf(object.seconds) < range.startMs &&
!outside(object.endSeconds);
let carriedFromMs: number | undefined;
const sampleTriggers = moveNotesToBackground(source, notes, mines, (object) => {
if (carried(object)) {
carriedFromMs = Math.min(carriedFromMs ?? Number.POSITIVE_INFINITY, msOf(object.seconds));
return false;
}
return (
outside(object.seconds) ||
('endSeconds' in object && object.endSeconds !== undefined && outside(object.endSeconds))
);
});
return {
chart: withChartOverrides(source, { sampleTriggers }),
sourceNotes,
changedObjectCount: before - notes.length - mines.length,
...(carriedFromMs !== undefined ? { carriedFromMs } : {}),
};
}
|