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 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | 443x 443x 1566155x 1566155x 7x 1566148x 443x 220071x 33574x 186497x 186497x 101658x 101658x 101658x 84839x 110284x 110284x 18926x 18926x 18926x 18926x 18926x 91358x 91358x 1591x 1591x 184x 184x 1199x 1199x 210x 210x 21x 21x 27x 27x 6x 6x 4x 4x 21x 21x 21x 217x 217x 217x 217x 3327x 3327x 3327x 2954x 2954x 2954x 187x 187x 187x 33251x 33251x 33251x 8374x 8374x 8374x 344x 344x 344x 16478x 16478x 16478x 16478x 48x 48x 48x 70x 70x 70x 18058x 18058x 18058x 22x 22x 22x 36x 36x 36x 2769x 2769x 2769x 1671x 1671x 1671x 1671x 1671x 71x 71x 71x 45x 71x 72x 72x 72x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 38x 8x 8x 217x 217x 217x 216x 216x 216x 1x 18926x 4948x 4948x 53x 4948x 264x 264x 116x 116x 19x 19x 185x 185x 64x 64x 119x 119x 66x 66x 2x 2x 66x 87x 87x 84x 84x 1916x 1916x 4122x 4122x 63x 63x 6873x 4537x 2336x 6873x 6015x 6015x 2336x 2336x 3x 2333x 10575x 10575x 10575x | import { normalizeObjectKey, type BeMusicJSON } from '@be-music/chart-source';
const INDEXED_HEADER_COMMAND =
/^(WAV|BMP|BPM|STOP|TEXT|SONG|EXRANK|ARGB|CHANGEOPTION|EXWAV|EXBMP|BGA|SCROLL|SPEED|SWBGA)([0-9A-Za-z]{2})$/;
type IndexedHeaderDirective =
| 'WAV'
| 'BMP'
| 'BPM'
| 'STOP'
| 'TEXT'
| 'SONG'
| 'EXRANK'
| 'ARGB'
| 'CHANGEOPTION'
| 'EXWAV'
| 'EXBMP'
| 'BGA'
| 'SCROLL'
| 'SPEED'
| 'SWBGA';
const EXBPM_HEADER_COMMAND = /^EXBPM([0-9A-Za-z]{2})$/;
/**
* Maps a header alias onto its canonical command, so file order, control flow, fingerprints and output all see one
* definition. `#EXBPMxx` is nanasi's alias of `#BPMxx`, added to dodge a BMSC bug that confused `#BPMxx` with `#BPM`
* (https://hitkey.nekokan.dyndns.info/cmds.htm#EXBPMXX).
*/
export function resolveHeaderCommandAlias(
command: string,
commandRaw: string,
): { readonly command: string; readonly commandRaw: string } {
const exBPM = command.match(EXBPM_HEADER_COMMAND);
if (exBPM) {
return { command: `BPM${exBPM[1]!}`, commandRaw: `BPM${commandRaw.slice('EXBPM'.length)}` };
}
return { command, commandRaw };
}
/** Header commands whose lines add up instead of replacing each other, so file order never makes one override another. */
const REPEATABLE_HEADER_COMMANDS: ReadonlySet<string> = new Set(['STP', 'WAVCMD', 'OPTION']);
/**
* Which definition a header line sets, for the file-order rule: the command, plus the normalized object key of an
* indexed header (`WAV01`). `undefined` for repeatable headers.
*/
export function resolveHeaderDefinitionKey(command: string, commandRaw: string, base: 36 | 62): string | undefined {
if (REPEATABLE_HEADER_COMMANDS.has(command)) {
return undefined;
}
const indexed = command.match(INDEXED_HEADER_COMMAND);
if (indexed) {
const directive = indexed[1]!;
const keyRaw = base === 62 ? commandRaw.slice(directive.length) : indexed[2]!;
// #WAV and #EXWAV define one slot, as nanasigroove stores them in one table (#1197).
return `${directive === 'EXWAV' ? 'WAV' : directive}${normalizeObjectKey(keyRaw, base)}`;
}
return command;
}
export function pushHeaderLine(
json: BeMusicJSON,
command: string,
commandRaw: string,
value: string,
base: 36 | 62,
): void {
const objectCommand = command.match(INDEXED_HEADER_COMMAND);
if (objectCommand) {
const directive = objectCommand[1] as IndexedHeaderDirective;
// For base-62 charts, lift the key from the case-preserved `commandRaw`; the trailing 2 chars hold the
// lowercase-aware ID. `commandRaw[directive.length...]` falls back to the uppercased form for base-36 (where case
// folding is intended).
const keyRaw = base === 62 ? commandRaw.slice(directive.length) : objectCommand[2]!;
const key = normalizeObjectKey(keyRaw, base);
applyIndexedHeaderLine(json, directive, key, value);
return;
}
const numericValue = Number.parseFloat(value);
switch (command) {
case 'TITLE':
json.metadata.title = value;
return;
case 'SUBTITLE':
json.metadata.subtitle = value;
return;
case 'ARTIST':
json.metadata.artist = value;
return;
case 'GENRE':
json.metadata.genre = value;
return;
case 'COMMENT':
json.metadata.comment = value;
return;
case 'STAGEFILE':
json.metadata.stageFile = value;
return;
case 'BACKBMP':
json.metadata.backBMP = value;
return;
case 'BANNER':
json.metadata.banner = value;
return;
case 'PREVIEW':
Eif (value.length > 0) {
json.bms.preview = value;
}
return;
case 'PLAYLEVEL':
{
const playLevelValue = parsePlayLevelValue(value);
Eif (playLevelValue !== undefined) {
json.metadata.playLevel = playLevelValue;
}
}
return;
case 'RANK':
Eif (Number.isFinite(numericValue)) {
json.metadata.rank = numericValue;
}
return;
case 'TOTAL':
Eif (Number.isFinite(numericValue)) {
json.metadata.total = numericValue;
}
return;
case 'DIFFICULTY':
Eif (Number.isFinite(numericValue)) {
json.metadata.difficulty = numericValue;
}
return;
case 'BPM':
Eif (Number.isFinite(numericValue) && numericValue !== 0) {
json.metadata.bpm = numericValue;
}
return;
case 'LNTYPE':
Eif (Number.isFinite(numericValue) && numericValue > 0) {
json.bms.lnType = Math.floor(numericValue);
}
return;
case 'LNMODE':
Eif (Number.isFinite(numericValue) && numericValue > 0) {
json.bms.lnMode = Math.floor(numericValue);
}
return;
case 'LNOBJ':
Eif (value.length > 0) {
// `#LNOBJ` carries an object-ID payload — preserve case for `#BASE 62` charts so the LN-end marker matches its
// case-sensitive `#WAVxx` counterpart.
const normalizedValue = normalizeObjectKey(value, base);
json.bms.lnObjs = [...(json.bms.lnObjs ?? []), normalizedValue];
}
return;
case 'VOLWAV':
Eif (Number.isFinite(numericValue) && numericValue >= 0) {
json.bms.volWAV = numericValue;
}
return;
case 'DEFEXRANK':
Eif (Number.isFinite(numericValue)) {
json.bms.defExRank = numericValue;
}
return;
case 'PLAYER':
Eif (Number.isFinite(numericValue) && numericValue > 0) {
json.bms.player = Math.floor(numericValue);
}
return;
case 'PATH_WAV':
Eif (value.length > 0) {
json.bms.pathWAV = value;
}
return;
case 'BASEBPM':
Eif (Number.isFinite(numericValue) && numericValue > 0) {
json.bms.baseBPM = numericValue;
}
return;
case 'STP':
Eif (value.length > 0) {
json.bms.stp.push(value);
}
return;
case 'OPTION':
Eif (value.length > 0) {
const declarations = (json.bms.options ??= json.bms.option ? [json.bms.option] : []);
declarations.push(value);
json.bms.option = value;
}
return;
case 'WAVCMD':
Eif (value.length > 0) {
// BMS spec — `#WAVCMD pp xx vv` declares per-slot WAV playback overrides (pitch / volume / loop). Real charts
// emit ONE line per `(parameter, slot)` pair, so we collect every line into `wavCmds`. The legacy single-string
// `wavCmd` field is preserved for the first occurrence so older consumers that only read the head value keep
// compiling.
json.bms.wavCmds.push(value);
if (typeof json.bms.wavCmd !== 'string') {
json.bms.wavCmd = value;
}
}
return;
case 'POORBGA':
Eif (value.length > 0) {
json.bms.poorBGA = value;
}
return;
case 'VIDEOFILE':
Eif (value.length > 0) {
json.bms.videoFile = value;
}
return;
case 'MIDIFILE':
Eif (value.length > 0) {
json.bms.midiFile = value;
}
return;
case 'MATERIALS':
Eif (value.length > 0) {
json.bms.materials = value;
}
return;
case 'DIVIDEPROP':
Eif (value.length > 0) {
json.bms.divideProp = value;
}
return;
case 'CHARSET':
Eif (value.length > 0) {
json.bms.charset = value;
}
return;
case 'BASE':
// `#BASE 62` is the beatoraja base-62 ID extension. The base was already resolved during pre-scan
// (`detectBMSBase`) and stamped onto `json.bms.base` before this header reaches us; swallow the directive here so
// it doesn't leak into `metadata.extras`.
return;
default:
Eif (value.length > 0) {
json.metadata.extras[command] = value;
}
}
}
function parsePlayLevelValue(value: string): number | string | undefined {
const trimmed = value.trim();
Iif (trimmed.length === 0) {
return undefined;
}
if (/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)$/.test(trimmed)) {
const parsed = Number.parseFloat(trimmed);
Eif (Number.isFinite(parsed)) {
return parsed;
}
}
return trimmed;
}
function applyIndexedHeaderLine(
json: BeMusicJSON,
directive: IndexedHeaderDirective,
key: string,
value: string,
): void {
switch (directive) {
case 'WAV':
applyIndexedStringValue(json.resources.wav, key, value);
// nanasigroove keeps #WAV and #EXWAV in one table, so a later #WAV replaces the slot's EXWAV (#1197).
if (value.length > 0 && key in json.bms.exWAV && !json.bms.exWAVOverridden?.includes(key))
(json.bms.exWAVOverridden ??= []).push(key);
return;
case 'BMP':
applyIndexedStringValue(json.resources.bmp, key, value);
return;
case 'TEXT':
applyIndexedStringValue(json.resources.text, key, value);
return;
case 'SONG':
applyIndexedStringValue(json.bms.songText, key, value);
return;
case 'EXRANK':
applyIndexedStringValue(json.bms.exRank, key, value);
return;
case 'ARGB':
applyIndexedStringValue(json.bms.argb, key, value);
return;
case 'CHANGEOPTION':
applyIndexedStringValue(json.bms.changeOption, key, value);
return;
case 'EXWAV':
applyIndexedStringValue(json.bms.exWAV, key, value);
if (value.length > 0 && json.bms.exWAVOverridden !== undefined) {
json.bms.exWAVOverridden = json.bms.exWAVOverridden.filter((slot) => slot !== key);
if (json.bms.exWAVOverridden.length === 0) delete json.bms.exWAVOverridden;
}
return;
case 'EXBMP':
applyIndexedStringValue(json.bms.exBMP, key, value);
return;
case 'BGA':
applyIndexedStringValue(json.bms.bga, key, value);
return;
case 'SCROLL': {
applyIndexedNumberValue(json.bms.scroll, key, value);
return;
}
case 'SPEED': {
applyIndexedNumberValue(json.bms.speed, key, value);
return;
}
case 'SWBGA':
applyIndexedStringValue(json.bms.swBGA, key, value);
return;
case 'BPM':
case 'STOP': {
if (directive === 'BPM') {
applyIndexedNumberValue(json.resources.bpm, key, value);
} else {
applyStopValue(json.resources.stop, key, value);
}
return;
}
}
}
function applyIndexedStringValue(values: Record<string, string>, key: string, value: string): void {
Eif (value.length > 0) {
values[key] = value;
}
}
/**
* `#STOPxx`. LR2 stores only a value above 0 (OpenLR2 L26324-26331), so a zero or negative definition never replaces
* a positive one made earlier: `#STOP01 96` then `#STOP01 -5` keeps 96.
*/
function applyStopValue(values: Record<string, number>, key: string, value: string): void {
// LR2 reads a decimal integer (atol) before deciding whether to replace the slot.
const numericValue = Math.max(-0x80000000, Math.min(0x7fffffff, Number.parseInt(value, 10) || 0));
if (!Number.isFinite(numericValue) || (numericValue <= 0 && (values[key] ?? 0) > 0)) {
return;
}
values[key] = numericValue;
}
function applyIndexedNumberValue(values: Record<string, number>, key: string, value: string): void {
const numericValue = Number.parseFloat(value);
Eif (Number.isFinite(numericValue)) {
values[key] = numericValue;
}
}
|