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 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | 439x 439x 439x 439x 439x 439x 439x 439x 439x 1715x 383x 383x 723x 434x 434x 225x 472x 160x 409x 40x 69x 160x 6x 6x 6x 8x 10x 8x 6x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 315x 19x 315x 315x 61x 61x 30x 15x 30x 30x 61x 61x 122x 345x 241x 345x 345x 345x 345x 345x 254x 61x 61x 241x 49x 49x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 116x 116x 61x 61x 61x 61x 61x 241x 241x 241x 58x 58x 58x 58x 58x 183x 1x 1x 1x 1x 1x 1x 1x 182x 13x 13x 169x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 9x 97x 106x 63x 14x 14x 14x 1x 1x 13x 13x 13x 13x 13x 61x 61x 61x 5x 5x 61x 61x 163x 61x 61x 61x 106x 61x 61x 61x 61x 61x 61x 58x 58x 61x 61x 61x 1x 1x 61x 2x 61x 61x 61x 61x 280x 308x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 392x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 61x 59x 38x 3x 3x 132x 36x 11x 61x 439x 106x 106x 954x 954x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 13x 13x 13x 56x 13x 13x 4x 4x 4x 4x 4x 4x 13x | import {
createEmptyJSON,
DEFAULT_BPM,
LRX_TICKS_PER_BEAT,
type BeMusicEvent,
type BeMusicJSON,
type ChartDiagnostic,
type LRXBGACue,
type LRXEventExtensions,
type LRXExtensions,
} from '@be-music/chart-source';
import { countDistinctValues, createBmsonValueKeyTable, encodeBmsonKey, resolveBmsonKeyBase } from './bmson-keys.ts';
import { createBmsonPositionResolver, createMeasureLengthsFromBmsonLines } from './bmson.ts';
import { sortAndNormalizeEvents } from './event-utils.ts';
import { decodeLRXText, readLRXElements, type LRXElement } from './lrx-xml.ts';
/**
* LRX, the chart format of plugout4 -ARCADE EDITION- (lavalse, 2012): a chart is `NN.lrs` (notes and sounds), the
* header `NN.lrh` beside it, and the BGA file the header names (`_movie.lrm` by default), all UTF-16 XML. See
* docs/format-compat.md, "LRX".
*/
export interface LRXSourceFiles<T> {
/** The `.lrs` file: `information`, `sound` and `n` elements. */
lrs: T;
/** The `.lrh` file beside it, when there is one. */
lrh?: T;
/** The BGA file named by {@link resolveLRXMoviePath}, when there is one. */
lrm?: T;
}
const DEFAULT_MOVIE_PATH = '_movie.lrm';
/** plugout's note constructor leaves `c` at 999 (no effect) when the attribute is missing. */
const MISSING_CHANNEL = 999;
const DEFAULT_RANK = 2;
/** Lane channel → BMS lane, for every lane type but 9 keys: scratches `0` / `10`, keys `1`–`7` / `11`–`17`. */
const BEAT_LANES: ReadonlyMap<number, string> = new Map([
[0, '16'],
[1, '11'],
[2, '12'],
[3, '13'],
[4, '14'],
[5, '15'],
[6, '18'],
[7, '19'],
[10, '26'],
[11, '21'],
[12, '22'],
[13, '23'],
[14, '24'],
[15, '25'],
[16, '28'],
[17, '29'],
]);
/** 9 keys (`lanetype` 4): keys `1`–`9` on the PMS-STD lanes. */
const NINE_KEY_LANES: ReadonlyMap<number, string> = new Map([
[1, '11'],
[2, '12'],
[3, '13'],
[4, '14'],
[5, '15'],
[6, '22'],
[7, '23'],
[8, '24'],
[9, '25'],
]);
const KNOWN_LANE_TYPES = new Set([0, 1, 2, 3, 4]);
/** `lanetype` 5 / 6 add the 2P scratch to a single-play chart; Be-Music plays them as double play. */
const DOUBLE_SCRATCH_LANE_TYPES = new Set([5, 6]);
/** BGA channel → BMS BGA channel: base, two layers, POOR. */
const BGA_CHANNELS: ReadonlyMap<number, string> = new Map([
[200, '04'],
[201, '07'],
[202, '0A'],
[299, '06'],
]);
/** BGA channel → plugout's BGA slot: the base, four layers, and the POOR image. */
const BGA_SLOTS: ReadonlyMap<number, number> = new Map([
[200, 0],
[201, 1],
[202, 2],
[203, 3],
[204, 4],
[299, 5],
]);
/** `wcstol`: leading digits with an optional sign; anything unreadable is 0. */
function readInt(value: string | undefined): number | undefined {
if (value === undefined) return undefined;
const parsed = Number.parseInt(value.trim(), 10);
return Number.isFinite(parsed) ? parsed : 0;
}
/** `wcstod`: a leading decimal number; anything unreadable is 0. */
function readFloat(value: string | undefined): number | undefined {
if (value === undefined) return undefined;
const parsed = Number.parseFloat(value.trim());
return Number.isFinite(parsed) ? parsed : 0;
}
/** plugout reads a flag as on when its first character is `1`. */
function readFlag(value: string | undefined): boolean {
return value?.startsWith('1') === true;
}
function readString(value: string | undefined): string | undefined {
return value === undefined || value.length === 0 ? undefined : value;
}
function informationOf(elements: readonly LRXElement[]): Map<string, string> | undefined {
// plugout reads every `information` element in turn, so a later one overrides an earlier one field by field.
let merged: Map<string, string> | undefined;
for (const element of elements) {
if (element.name !== 'information') continue;
merged ??= new Map();
for (const [key, value] of element.attributes) merged.set(key, value);
}
return merged;
}
/** The `.lrh` path of an `.lrs` path: plugout swaps the extension. */
export function resolveLRXHeaderPath(lrsPath: string): string {
const dot = lrsPath.lastIndexOf('.');
const slash = Math.max(lrsPath.lastIndexOf('/'), lrsPath.lastIndexOf('\\'));
return `${dot > slash ? lrsPath.slice(0, dot) : lrsPath}.lrh`;
}
/**
* The BGA file of a chart, relative to its folder: the `.lrh` `moviepath`, else the `.lrs` one, else `_movie.lrm`.
* plugout reads it from the chart's folder (and tries `../` for the media it names, not for the file itself).
*/
export function resolveLRXMoviePath(lrs: Uint8Array, lrh?: Uint8Array): string {
const moviePathOf = (bytes: Uint8Array): string | undefined =>
readString(informationOf(readLRXElements(decodeLRXText(bytes), 'information'))?.get('moviepath'));
return (lrh ? moviePathOf(lrh) : undefined) ?? moviePathOf(lrs) ?? DEFAULT_MOVIE_PATH;
}
/** Parses an LRX chart from its decoded files. */
export function parseLRXBytes(files: LRXSourceFiles<Uint8Array>): BeMusicJSON {
return parseLRX({
lrs: decodeLRXText(files.lrs),
...(files.lrh ? { lrh: decodeLRXText(files.lrh) } : {}),
...(files.lrm ? { lrm: decodeLRXText(files.lrm) } : {}),
});
}
interface LRXNote {
channel: number;
start: number;
end: number;
value: number;
attributes: Map<string, string>;
order: number;
}
/** Parses an LRX chart from the text of its files. */
export function parseLRX(files: LRXSourceFiles<string>): BeMusicJSON {
const json = createEmptyJSON('lrx');
const diagnostics: ChartDiagnostic[] = [];
const lrx: LRXExtensions = {};
json.lrx = lrx;
const sequence = readLRXElements(files.lrs);
const header = files.lrh !== undefined ? informationOf(readLRXElements(files.lrh)) : undefined;
const movie = files.lrm !== undefined ? readLRXElements(files.lrm) : [];
const sequenceInformation = informationOf(sequence);
applyHeader(json, lrx, header);
const movieInformation = informationOf(movie);
const movieArtist = readString(movieInformation?.get('artist_movie'));
if (movieArtist !== undefined) lrx.movieArtist = movieArtist;
lrx.moviePath =
readString(header?.get('moviepath')) ?? readString(sequenceInformation?.get('moviepath')) ?? DEFAULT_MOVIE_PATH;
// Judge rank and TOTAL come from the `.lrs` only; plugout never reads the `.lrh` copies.
json.metadata.rank = readInt(sequenceInformation?.get('rank')) ?? DEFAULT_RANK;
const total = readInt(sequenceInformation?.get('total'));
if (total !== undefined && total > 0) json.metadata.total = total;
const sounds = new Map<number, string>();
for (const element of sequence) {
if (element.name !== 'sound') continue;
const id = readInt(element.attributes.get('id')) ?? 0;
const filename = element.attributes.get('filename');
if (id >= 0 && filename) sounds.set(id, filename);
}
// `image` and `movie` share one id table in plugout.
const images = new Map<number, string>();
for (const element of movie) {
if (element.name !== 'image' && element.name !== 'movie') continue;
const id = readInt(element.attributes.get('id')) ?? 0;
const filename = element.attributes.get('filename');
if (id >= 0 && filename) images.set(id, filename);
}
const notes: LRXNote[] = [];
for (const elements of [sequence, movie]) {
for (const element of elements) {
if (element.name !== 'n') continue;
const channel = readInt(element.attributes.get('c')) ?? MISSING_CHANNEL;
const start = Math.max(0, readFloat(element.attributes.get('s')) ?? 0);
const written = readFloat(element.attributes.get('e'));
// An end at or before the start is no length (plugout clamps `e` to `s`).
const end = written !== undefined && written > start ? written : start;
const value = readFloat(element.attributes.get('p')) ?? 0;
notes.push({ channel, start, end, value, attributes: element.attributes, order: notes.length });
}
}
notes.sort((left, right) => left.start - right.start || left.order - right.order);
const barTicks: number[] = [];
for (const note of notes) {
if (note.channel !== 300) continue;
const tick = Math.round(note.start);
if (tick !== barTicks.at(-1)) barTicks.push(tick);
}
// The measures follow the bar lines, which can sit anywhere; a measure before the first bar line starts at tick 0.
const lines = barTicks.length > 0 && barTicks[0] !== 0 ? [0, ...barTicks] : barTicks;
if (lines.length > 0) lrx.barTicks = lines;
const toPosition = createBmsonPositionResolver(LRX_TICKS_PER_BEAT, lines);
const measures = createMeasureLengthsFromBmsonLines(lines, LRX_TICKS_PER_BEAT);
if (measures.length > 0) json.measures = measures;
const laneMap = resolveLaneMap(lrx.laneType, notes, diagnostics);
const events: BeMusicEvent[] = [];
const unsupportedChannels = new Set<number>();
const bpmTicks: number[] = [];
const bpmValues: number[] = [];
const stopTicks: number[] = [];
const stopUnits: number[] = [];
let bpm: number | undefined;
let soundCount = 0;
let imageCount = 0;
const pushEvent = (note: LRXNote, channel: string, value: string, extension?: LRXEventExtensions): void => {
const { measure, position } = toPosition(note.start);
events.push({ measure, position, channel, value, ...(extension ? { lrx: extension } : {}) });
};
const soundEvents: Array<{ note: LRXNote; channel: string; extension?: LRXEventExtensions }> = [];
const bgaEvents: Array<{ note: LRXNote; channel: string }> = [];
const bgaCues: Array<{ note: LRXNote; slot: number; id: number }> = [];
/** The lanes a judged note has reached so far, in chart order. */
const judgedLanes = new Set<string>();
for (let index = 0; index < notes.length; index++) {
const note = notes[index]!;
const { channel } = note;
if (channel === 301) {
bpmTicks.push(note.start);
bpmValues.push(note.value);
// A tick's last BPM note wins; plugout's first BPM note is also the chart's starting tempo.
if (bpm === undefined) json.metadata.bpm = note.value;
bpm = note.value;
continue;
}
if (channel === 302) {
// STOP in milliseconds, converted to BMS units (1/192 measure) at the BPM in force on its tick.
let tempo = bpm ?? json.metadata.bpm;
for (let ahead = index + 1; ahead < notes.length && notes[ahead]!.start === note.start; ahead++) {
Eif (notes[ahead]!.channel === 301) tempo = notes[ahead]!.value;
}
Eif (note.value > 0 && tempo > 0) {
stopTicks.push(note.start);
stopUnits.push(((note.value / 1000) * tempo * 48) / 60);
}
continue;
}
if (channel === 309) {
lrx.endTick = note.start;
continue;
}
if (channel >= 0 && channel < 200) {
const id = Math.trunc(note.value);
Iif (id < 0) continue;
soundCount = Math.max(soundCount, id + 1);
const extension = readSoundExtension(note);
const lane = channel < 20 ? laneMap.get(channel) : undefined;
if (channel < 20 && lane === undefined) unsupportedChannels.add(channel);
// A lane note with `dmg="0"` is an autoplayed background note; a chain note sits in the background too. Both keep
// their lane (`lane`): a chain note follows the lane's preceding note, and a hidden note becomes the lane's sound.
// A chain note with no note before it on its lane is judged as plugout judges it: the lane's judge cursor starts
// on it, though its note count leaves it out (0x43c000, 0x43c071).
const leadingChain =
extension?.chain === true && lane !== undefined && extension.damage !== 0 && !judgedLanes.has(lane);
const background = lane === undefined || extension?.damage === 0 || (extension?.chain === true && !leadingChain);
if (background && lane !== undefined) extension!.lane = lane;
if (!background && lane !== undefined) judgedLanes.add(lane);
// plugout's BGM group holds only the BGM columns' notes that keep a non-zero `dmg`; a background sound outside it
// plays at the keysound volume.
const bgmGroup = channel >= 100 && extension?.damage !== 0;
const backgroundExtension: LRXEventExtensions | undefined =
background && !bgmGroup ? { ...extension, keyVolume: true } : extension;
if (!background && note.end > note.start) {
soundEvents.push({ note, channel: lane, extension: { ...extension, length: note.end - note.start } });
} else {
soundEvents.push({
note,
channel: background ? '01' : lane,
...(backgroundExtension ? { extension: backgroundExtension } : {}),
});
}
continue;
}
if (channel >= 200 && channel < 300) {
const id = Math.trunc(note.value);
const slot = BGA_SLOTS.get(channel);
// plugout draws the base, layers 201–204 and the POOR image (0x443c95); the other layers it never shows.
if (slot === undefined) {
unsupportedChannels.add(channel);
continue;
}
Iif (id < 0) continue;
imageCount = Math.max(imageCount, id + 1);
bgaCues.push({ note, slot, id });
const bgaChannel = BGA_CHANNELS.get(channel);
if (bgaChannel !== undefined) bgaEvents.push({ note, channel: bgaChannel });
}
// 300 (bar lines) became the measures; 303–308 and 310 up do nothing in plugout.
}
for (const id of sounds.keys()) soundCount = Math.max(soundCount, id + 1);
for (const id of images.keys()) imageCount = Math.max(imageCount, id + 1);
if (bpm === undefined) {
const fallback = lrx.startBPM ?? lrx.baseBPM;
json.metadata.bpm = fallback !== undefined && fallback > 0 ? fallback : DEFAULT_BPM;
}
// Keys are `id + 1`, since `00` is no object in BMS; past 1,295 ids the chart moves to base-62 keys.
const keyBase = resolveBmsonKeyBase([
soundCount,
imageCount,
countDistinctValues(bpmValues),
countDistinctValues(stopUnits),
]);
if (keyBase === 62) json.bms.base = 62;
const keyOf = (id: number): string => encodeBmsonKey(id + 1, keyBase)!;
for (const [id, filename] of sounds) json.resources.wav[keyOf(id)] = filename;
for (const [id, filename] of images) json.resources.bmp[keyOf(id)] = filename;
for (const { note, channel, extension } of soundEvents)
pushEvent(note, channel, keyOf(Math.trunc(note.value)), extension);
for (const { note, channel } of bgaEvents) pushEvent(note, channel, keyOf(Math.trunc(note.value)));
const bga = bgaCues.map(({ note, slot, id }) => readBGACue(note, slot, id, keyOf(id)));
// The BMS BGA channels carry the plain images; a chart that moves, crops or chains them, or uses layer 203 / 204,
// keeps every cue with its transform.
if (bga.some((cue) => cue.slot === 3 || cue.slot === 4 || cue.src || cue.dst || cue.chain)) lrx.bga = bga;
const bpmKeys = createBmsonValueKeyTable(bpmValues, keyBase);
Object.assign(json.resources.bpm, bpmKeys.table);
bpmTicks.forEach((tick, index) => {
const { measure, position } = toPosition(tick);
events.push({ measure, position, channel: '08', value: bpmKeys.keys[index]! });
});
const stopKeys = createBmsonValueKeyTable(stopUnits, keyBase);
Object.assign(json.resources.stop, stopKeys.table);
stopTicks.forEach((tick, index) => {
const { measure, position } = toPosition(tick);
events.push({ measure, position, channel: '09', value: stopKeys.keys[index]! });
});
for (const channel of [...unsupportedChannels].sort((left, right) => left - right)) {
diagnostics.push({
code: 'unsupported-channel',
message:
channel < 20
? `LRX lane ${channel} is not a lane of this lane type; its notes play in the background`
: `LRX BGA layer ${channel} is not supported; its images are not shown`,
subject: String(channel),
position: { kind: 'field', path: 'lrs.n.c' },
});
}
if (diagnostics.length > 0) json.diagnostics = diagnostics;
json.events = sortAndNormalizeEvents(events, keyBase);
return json;
}
function applyHeader(json: BeMusicJSON, lrx: LRXExtensions, header: Map<string, string> | undefined): void {
if (!header) return;
const text = (key: string) => readString(header.get(key));
const number = (key: string) => readInt(header.get(key));
json.metadata.title = text('title');
json.metadata.subtitle = text('subtitle');
json.metadata.genre = text('genre');
json.metadata.artist = text('artist_song');
const sequenceArtist = text('artist_sequence');
if (sequenceArtist !== undefined) json.metadata.extras.SUBARTIST = sequenceArtist;
const titleImage = text('titleimage');
if (titleImage !== undefined) json.metadata.titleImage = titleImage;
const backImage = text('backimage');
if (backImage !== undefined) json.metadata.backBMP = backImage;
const banner = text('bannerimage');
if (banner !== undefined) json.metadata.banner = banner;
const level = number('lrslevel');
if (level !== undefined) json.metadata.playLevel = level;
const category = number('category');
// The five official difficulties line up with BMS #DIFFICULTY 1–5; edit and remix charts have no counterpart.
if (category !== undefined && category >= 0 && category <= 4) json.metadata.difficulty = category + 1;
const assign = <K extends keyof LRXExtensions>(key: K, value: LRXExtensions[K] | undefined): void => {
if (value !== undefined) lrx[key] = value;
};
assign('laneType', number('lanetype'));
assign('category', category);
assign('level', level);
assign('bmsLevel', number('bmslevel'));
assign('sequenceTitle', text('sequencetitle'));
assign('sequenceArtist', sequenceArtist);
assign('minBPM', number('minbpm'));
assign('maxBPM', number('maxbpm'));
assign('baseBPM', number('basebpm'));
assign('startBPM', number('startbpm'));
assign('labelImage', text('labelimage'));
assign('phase', number('phase'));
assign('unlock', number('unlock'));
assign('songId', number('songid'));
}
/**
* The lane table of the chart. A known `lanetype` picks it; without one (no `.lrh`, or a value plugout does not
* define) a chart with notes on keys 8 or 9 and nothing past them reads as 9 keys, any other as the beat layout.
*/
function resolveLaneMap(
laneType: number | undefined,
notes: readonly LRXNote[],
diagnostics: ChartDiagnostic[],
): ReadonlyMap<number, string> {
if (laneType === 4) return NINE_KEY_LANES;
if (laneType !== undefined && KNOWN_LANE_TYPES.has(laneType)) return BEAT_LANES;
if (laneType !== undefined) {
diagnostics.push({
code: 'unsupported-lane-type',
message: DOUBLE_SCRATCH_LANE_TYPES.has(laneType)
? `LRX lanetype ${laneType} (single play with both scratches) plays as double play`
: `LRX lanetype ${laneType} is unknown; the lanes in use decide the mode`,
subject: String(laneType),
position: { kind: 'field', path: 'lrh.information.lanetype' },
});
if (DOUBLE_SCRATCH_LANE_TYPES.has(laneType)) return BEAT_LANES;
}
const lanes = new Set(notes.filter((note) => note.channel >= 0 && note.channel < 20).map((note) => note.channel));
const nineKeys =
(lanes.has(8) || lanes.has(9)) && [0, ...Array.from({ length: 10 }, (_, i) => 10 + i)].every((c) => !lanes.has(c));
return nineKeys ? NINE_KEY_LANES : BEAT_LANES;
}
const SOUND_DEFAULTS = { vol: 127, pan: 64, frq: 44100, atk: 0, rls: 0, ost: 0, len: -1, dmg: 100, rcv: 100 } as const;
/** The sound and note attributes of a note on channels 0–199 that differ from plugout's defaults. */
function readSoundExtension(note: LRXNote): LRXEventExtensions | undefined {
const extension: LRXEventExtensions = {};
const read = (key: keyof typeof SOUND_DEFAULTS): number | undefined => {
const value = readInt(note.attributes.get(key));
return value === undefined || value === SOUND_DEFAULTS[key] ? undefined : value;
};
const volume = read('vol');
if (volume !== undefined) extension.volume = volume;
const pan = read('pan');
if (pan !== undefined) extension.pan = pan;
const frequency = read('frq');
// `frq="0"` plays at the sample's own rate, as the default does.
if (frequency !== undefined && frequency !== 0) extension.frequency = frequency;
const attack = read('atk');
if (attack !== undefined) extension.attackMs = attack;
const release = read('rls');
if (release !== undefined) extension.releaseMs = release;
const offset = read('ost');
if (offset !== undefined) extension.offsetMs = offset;
const length = read('len');
if (length !== undefined && length >= 0) extension.lengthMs = length;
const damage = read('dmg');
if (damage !== undefined) extension.damage = damage;
const recover = read('rcv');
if (recover !== undefined) extension.recover = recover;
if (readFlag(note.attributes.get('rev'))) extension.reverse = true;
if (readFlag(note.attributes.get('cn'))) extension.chain = true;
return Object.keys(extension).length > 0 ? extension : undefined;
}
/**
* A BGA note with its transform, read as plugout reads it (0x4656c2): `sx` brings the source rectangle; `dx` brings
* the destination and with it the colour, blend, rotation, centre and easing, which plugout reads only then.
*/
function readBGACue(note: LRXNote, slot: number, id: number, key: string): LRXBGACue {
const cue: LRXBGACue = { slot, tick: note.start, image: id, key };
if (note.end > note.start) cue.endTick = note.end;
if (readFlag(note.attributes.get('cn'))) cue.chain = true;
const int = (name: string, fallback: number): number => readInt(note.attributes.get(name)) ?? fallback;
if (note.attributes.has('sx')) cue.src = [int('sx', 0), int('sy', 0), int('sw', 0), int('sh', 0)];
if (note.attributes.has('dx')) {
cue.dst = [int('dx', 0), int('dy', 0), int('dw', 0), int('dh', 0)];
cue.color = [int('a', 255), int('r', 255), int('g', 255), int('b', 255)];
cue.blend = int('bld', 0);
cue.rotation = int('rot', 0);
cue.center = int('ctr', 0);
cue.accel = int('acc', 0);
}
return cue;
}
|