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 | 13x 13x 597x 597x 597x 597x 512x 512x 512x 512x 512x 191x 84x 84x 268x 268x 268x 84x 3x 3x 84x 101x 101x 84x 84x 110x 110x 53x 110x 110x 84x 61x 60x 61x 60x 60x 512x 512x 2048x 2048x 2048x 73452x 73235x 217x 217x 2048x 512x 512x 512x 512x 512x 1398x 1398x | import {
normalizeChannel,
normalizeObjectKey,
resolveBMSBase,
type BeMusicEvent,
type BeMusicJSON,
} from '@be-music/chart-source';
import { sortEvents } from './index.ts';
export interface BGACue {
seconds: number;
key?: string;
}
export interface BGATimelines {
base: BGACue[];
layer: BGACue[];
layer2: BGACue[];
poor: BGACue[];
}
export interface BGATimingResolver {
eventToSeconds: (event: BeMusicEvent) => number;
beatToSeconds: (beat: number) => number;
}
/**
* Whether black pixels of a layer image (`07` / `0A`) are drawn transparent: BMS keys them out, while the bmson spec
* draws them black ("Unlike BMS Layer Channel #xxx07"). A slot listed in `resources.bmpSourceFormat` follows its own
* format's rule (a BMS stage's image in a NONSTOP chart stitched as bmson is still keyed out).
*/
export function keysOutBGALayerBlack(
json: Pick<BeMusicJSON, 'sourceFormat'> & { resources?: Pick<BeMusicJSON['resources'], 'bmpSourceFormat'> },
bmpKey?: string,
): boolean {
const slotFormat = bmpKey === undefined ? undefined : json.resources?.bmpSourceFormat?.[bmpKey];
return (slotFormat ?? json.sourceFormat) !== 'bmson';
}
const BGA_BASE_CHANNEL = '04';
const BGA_POOR_CHANNEL = '06';
const BGA_LAYER_CHANNEL = '07';
const BGA_LAYER2_CHANNEL = '0A';
export function buildBGATimelines(chart: BeMusicJSON, resolver: BGATimingResolver): BGATimelines {
const idBase = resolveBMSBase(chart);
const sortedEvents = sortEvents(chart.events);
const timelines: BGATimelines = {
base: buildBmsBGATimeline(sortedEvents, resolver, BGA_BASE_CHANNEL, idBase, chart.sourceFormat === 'bmson'),
poor: buildBmsBGATimeline(sortedEvents, resolver, BGA_POOR_CHANNEL, idBase, chart.sourceFormat === 'bmson'),
layer: buildBmsBGATimeline(sortedEvents, resolver, BGA_LAYER_CHANNEL, idBase, chart.sourceFormat === 'bmson'),
layer2: buildBmsBGATimeline(sortedEvents, resolver, BGA_LAYER2_CHANNEL, idBase, chart.sourceFormat === 'bmson'),
};
const bgaSection = chart.bmson.bga;
if (bgaSection.events.length > 0 || bgaSection.layerEvents.length > 0 || bgaSection.poorEvents.length > 0) {
const headerById = new Map(bgaSection.header.map((entry) => [entry.id, entry.name]));
const resolution =
chart.bmson.info?.resolution && chart.bmson.info.resolution > 0 ? chart.bmson.info.resolution : 240;
const toCue = (entry: { y: number; id: number }): BGACue => {
const beat = entry.y / resolution;
const seconds = resolver.beatToSeconds(beat);
return { seconds, key: entry.id === 0 ? undefined : headerById.get(entry.id) };
};
// beatoraja reads an omitted id as Java's default 0 and resolves it against the header; an unresolved id leaves the
// timeline's BGA unset (-1), so the event changes nothing (BMSONDecoder, TimeLine).
const omittedIdCue = (entry: { y: number }): BGACue | undefined => {
const key = headerById.get(0);
return key === undefined ? undefined : { seconds: resolver.beatToSeconds(entry.y / resolution), key };
};
for (const event of bgaSection.events) {
const cue = event.id === undefined ? omittedIdCue(event) : toCue({ y: event.y, id: event.id });
if (cue) timelines.base.push(cue);
}
const sequenceIds = new Set((bgaSection.sequences ?? []).map((entry) => entry.id));
for (const event of bgaSection.layerEvents) {
const cue = toCue({ y: event.y, id: event.id ?? 0 });
if (
event.idSet !== undefined ||
event.condition !== undefined ||
event.interval !== undefined ||
sequenceIds.has(event.id ?? 0)
)
cue.key = undefined;
timelines.layer.push(cue);
// A conditional MISS selection replaces the old POOR definition even after its sequence ends.
// Ordinary image-only layers keep the independent standard bmson POOR channel unchanged.
if (event.condition === 'miss') timelines.poor.push({ seconds: cue.seconds, key: undefined });
}
for (const event of bgaSection.poorEvents) {
if (event.id === undefined && !sequenceIds.has(0) && !headerById.has(0)) continue;
const cue = event.id === undefined ? omittedIdCue(event) : toCue({ y: event.y, id: event.id });
Iif (!cue) {
// A sequence 0 drives the POOR plane through the sequence program; clear the plain image cue.
timelines.poor.push({ seconds: resolver.beatToSeconds(event.y / resolution), key: undefined });
continue;
}
Iif (sequenceIds.has(event.id ?? 0)) cue.key = undefined;
timelines.poor.push(cue);
}
}
sortBGATimelines(timelines);
return timelines;
}
export function buildBmsBGATimeline(
events: ReadonlyArray<BeMusicEvent>,
resolver: Pick<BGATimingResolver, 'eventToSeconds'>,
channel: string,
base: 36 | 62 = 36,
allowLongKeys = false,
): BGACue[] {
const normalized = normalizeChannel(channel);
const timeline: BGACue[] = [];
for (const event of events) {
if (normalizeChannel(event.channel) !== normalized) {
continue;
}
const key = normalizeObjectKey(event.value, base, allowLongKeys);
timeline.push({
seconds: resolver.eventToSeconds(event),
key: key === '00' ? undefined : key,
});
}
return timeline;
}
function sortBGATimelines(timelines: BGATimelines): void {
const sortBySeconds = (left: BGACue, right: BGACue): number => left.seconds - right.seconds;
timelines.base.sort(sortBySeconds);
timelines.layer.sort(sortBySeconds);
timelines.layer2.sort(sortBySeconds);
timelines.poor.sort(sortBySeconds);
}
/** How a BMS chart displays its miss image: replace, overlay, or hide. */
export type PoorBGAMode = 0 | 1 | 2;
/** Parses `#POORBGA`; missing, invalid and out-of-range values use the normal replacement mode. */
export function resolvePoorBGAMode(value: string | undefined): PoorBGAMode {
const parsed = value === undefined ? 0 : Number.parseInt(value.trim(), 10);
return parsed === 1 || parsed === 2 ? parsed : 0;
}
|