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 | 125x 125x 125x 125x 125x 125x 36x 34x 27x 25x 125x 125x 88x 84x 80x 80x 80x 1354x 80x 80x 100x 3334x 88x 80x 26x 634x 136x 136x 136x 136x 1918x 1918x 136x 136x 136x 136x 1918x 136x 136x 1454x 136x 136x 136x 136x 136x 136x 136x 136x 1918x 1918x 1782x 1918x 1918x 1918x 1918x 136x 988x 867x 988x 1918x 136x 136x 1782x 1782x 1782x 136x 136x 183x 125x 1735x 2105x 1902x 1615x 116x 1735x 3790x 1185x 1095x 469x 469x 436x 436x 626x 125x 3250x | import { PLAY_MODE_LAYOUTS, findPlayModeLane, type ChartPlayVariant, type PlayKeyTone } from '@be-music/chart-model';
import {
resolveSideKeySlot as resolveCoreSideKeySlot,
resolveSideRelativeLaneIndex,
resolveWheelLaneDirection,
} from '@be-music/player-engine/lanes';
import type { BeMusicLaneKind } from './types.ts';
/** Lanes sit edge to edge, and in double play the 2P bank butts straight onto the 1P bank. */
const FALLBACK_LANE_GAP = 0;
const FALLBACK_DP_SIDE_GAP = 0;
const FALLBACK_SCRATCH_LANE_WEIGHT = 1.55;
/**
* Fixed lane widths for the That-Which-Must-Not-Be-Named families (5 / 7 / 10 / 14 KEY), in design px. The proportions follow the arcade
* cabinet — the scratch lane about 1.7x a white key, black keys about 0.8x — scaled so a 7K side is exactly the 194 px
* span. Every mode uses the same widths, so a 5K or DP chart never stretches its lanes sideways; the playfield just
* gets narrower or wider.
*/
export const _____LANE_WIDTHS = { scratch: 41, white: 24, black: 19 } as const;
/**
* Gap between the 1P and 2P banks in That-Which-Must-Not-Be-Named double play (10 / 14 KEY), in design px. The arcade cabinet splits the two
* sides by about 0.31 of a side's width (the turntable housings sit between them); on the 194 px 7K side that is 60 px.
* Keyboard double play (48 KEY) keeps its banks together.
*/
export const _____DP_SIDE_GAP = 60;
/**
* A note's height as a share of its lane's width. On the arcade cabinet a white key's note is about 7 px tall in a 32 px
* lane, a black key's 5 px in 25 px: about 0.21 either way, so a wider lane draws a thicker note.
*/
export const NOTE_HEIGHT_LANE_RATIO = 0.21;
/**
* The height to draw a note at in a lane `laneWidth` wide: {@link NOTE_HEIGHT_LANE_RATIO} of it, rounded to whole px
* and at least 2 px. The note still stands on its bottom edge, the judgement position.
*/
export function noteHeightForLane(laneWidth: number): number {
if (!Number.isFinite(laneWidth) || laneWidth <= 0) return 2;
return Math.max(2, Math.round(laneWidth * NOTE_HEIGHT_LANE_RATIO));
}
/** The width of the playfield's first white-key lane, which every note takes its height from; `undefined` without one. */
export function findWhiteLaneWidth(
lanes: readonly { readonly kind: BeMusicLaneKind; readonly w: number }[],
): number | undefined {
return lanes.find((lane) => lane.kind === 'white')?.w;
}
/**
* The height of a note in a lane `laneWidth` wide ({@link noteHeightForLane}). Every note — a black key's, a scratch's or
* a wheel's — takes a white key's height when `whiteLaneWidth` is known ({@link findWhiteLaneWidth}), so the notes of
* one playfield are all as tall as each other however wide their lanes are; without a white lane a note takes its own
* lane's share.
*/
export function resolveNoteHeight(laneWidth: number, whiteLaneWidth?: number): number {
return noteHeightForLane(whiteLaneWidth ?? laneWidth);
}
export interface FixedLaneWidths {
scratch: number;
/** Odd-numbered keys (1 / 3 / 5 / 7). */
white: number;
/** Even-numbered keys (2 / 4 / 6). */
black: number;
}
/** Left edge and per-side width of the skinless playfield, mirroring LR2's default 7K skin. */
const FALLBACK_PLAYFIELD_SPAN = { x: 33, w: 194 } as const;
/**
* Keyboard modes run 26 lanes per side (24 keys and the wheel), which the 7K span squeezes to 7 px each. Like the keyboard cabinet, they take
* the screen width instead: 24 KEY fills the column left of the BGA monitor (its frame still clears the rails), and
* 48 KEY spreads both banks across the whole page.
*/
const KEYBOARD_PLAYFIELD_SPANS: Record<'24' | '48', { x: number; w: number }> = {
'24': { x: 12, w: 252 },
'48': { x: 12, w: 308 },
};
export interface FallbackLaneLayoutRect {
channel: string | undefined;
x: number;
w: number;
isScratch: boolean;
side: '1P' | '2P';
}
export interface ResolveFallbackLaneLayoutOptions {
channels?: readonly string[];
laneCount?: number;
playVariant?: ChartPlayVariant;
x: number;
w: number;
gap?: number;
sideGap?: number;
/**
* Keep one side at the requested width and let additional DP-side lanes extend the fallback playfield horizontally.
*/
preserveSideWidth?: boolean;
/**
* Give every lane a fixed width by kind (scratch / white key / black key) instead of sharing `w` out. `w` and
* `preserveSideWidth` are then ignored: the playfield is as wide as its lanes.
*/
fixedWidths?: FixedLaneWidths;
}
/**
* Left edge and per-side width the skinless playfield uses for a chart's play variant (see
* {@link resolveSkinlessLaneLayout}).
*/
export function resolveFallbackPlayfieldSpan(playVariant?: ChartPlayVariant): { x: number; w: number } {
if (playVariant?.startsWith('generic-')) return KEYBOARD_PLAYFIELD_SPANS['48'];
return playVariant === '24' || playVariant === '48' ? KEYBOARD_PLAYFIELD_SPANS[playVariant] : FALLBACK_PLAYFIELD_SPAN;
}
export interface SkinlessLaneLayout {
lanes: FallbackLaneLayoutRect[];
/** Left edge of the leftmost lane. */
left: number;
/** Right edge of the rightmost lane (never left of one side's span). */
right: number;
}
/**
* Lane rects for the skinless / built-in playfield: the variant's span, with double play extending one side's width to
* the right. Every built-in skin and the core lane renderer share this, so chrome and notes line up.
*/
export function resolveSkinlessLaneLayout(
channels: readonly string[] | undefined,
laneCount: number | undefined,
playVariant?: ChartPlayVariant,
): SkinlessLaneLayout {
const span = resolveFallbackPlayfieldSpan(playVariant);
const fixedWidths = uses____LaneWidths(playVariant) ? _____LANE_WIDTHS : undefined;
const lanes = resolveFallbackLaneLayout({
channels,
laneCount,
playVariant,
x: span.x,
w: span.w,
preserveSideWidth: shouldPreserveFallbackSideWidth(channels, playVariant),
fixedWidths,
sideGap: fixedWidths ? _____DP_SIDE_GAP : undefined,
});
const lanesRight = Math.max(span.x, ...lanes.map((lane) => lane.x + lane.w));
// Fixed-width lanes define the playfield; shared-out lanes keep at least one side's span.
const right = fixedWidths ? lanesRight : Math.max(span.x + span.w, lanesRight);
return { lanes, left: span.x, right };
}
/** Whether `playVariant` is an That-Which-Must-Not-Be-Named family (5 / 7 / 10 / 14 KEY), whose lanes use {@link _____LANE_WIDTHS}. */
export function uses____LaneWidths(playVariant?: ChartPlayVariant): boolean {
return playVariant === '5' || playVariant === '7' || playVariant === '10' || playVariant === '14';
}
export function isScratchLaneForVariant(channel: string, playVariant?: ChartPlayVariant): boolean {
return resolveCoreSideKeySlot(channel, playVariant) === 0;
}
export function shouldPreserveFallbackSideWidth(
channels: readonly string[] | undefined,
playVariant?: ChartPlayVariant,
): boolean {
if (playVariant?.startsWith('generic-')) return false;
if (playVariant === '10' || playVariant === '14') {
return true;
}
return playVariant !== '9' && channels?.some((channel) => channel.startsWith('2')) === true;
}
export function resolveFallbackLaneLayout(options: ResolveFallbackLaneLayoutOptions): FallbackLaneLayoutRect[] {
const fallbackLaneCount = Math.max(1, Math.trunc(options.laneCount ?? 8));
const channels =
options.channels && options.channels.length > 0
? [...options.channels]
: (Array.from({ length: fallbackLaneCount }) as Array<string | undefined>);
const gap = Math.max(0, options.gap ?? FALLBACK_LANE_GAP);
const scratchFlags = channels.map((channel) =>
channel === undefined ? false : isScratchLaneForVariant(channel, options.playVariant),
);
const sideFlags = channels.map((channel) => resolveFallbackLaneSide(channel, options.playVariant));
const displayOrder = resolveFallbackLaneDisplayOrder(channels, scratchFlags, options.playVariant);
const hasBothSides = sideFlags.includes('1P') && sideFlags.includes('2P');
const sideGap = Math.max(0, options.sideGap ?? (hasBothSides ? FALLBACK_DP_SIDE_GAP : 0));
// The keyboard modes' wheel lanes stand in for the scratch on the outer edge, so they are as wide as one.
const laneWeights = channels.map((channel, index) =>
scratchFlags[index] ||
(channel !== undefined && resolveWheelLaneDirection(channel, options.playVariant) !== undefined)
? FALLBACK_SCRATCH_LANE_WEIGHT
: 1,
);
const referenceLaneCount = options.preserveSideWidth ? Math.max(1, Math.ceil(channels.length / 2)) : channels.length;
const referenceWeights = laneWeights.slice(0, referenceLaneCount);
const referenceWeight = referenceWeights.reduce((sum, weight) => sum + weight, 0);
const totalInterLaneGap = resolveTotalInterLaneGap(displayOrder, sideFlags, gap, sideGap);
const referenceInterLaneGap = options.preserveSideWidth
? gap * Math.max(0, referenceLaneCount - 1)
: totalInterLaneGap;
const availableWidth = Math.max(0, options.w - referenceInterLaneGap);
const unit = referenceWeight > 0 ? availableWidth / referenceWeight : 0;
const rects: FallbackLaneLayoutRect[] = Array.from({ length: channels.length });
let x = options.x;
let priorSide: '1P' | '2P' | undefined;
const fixedWidths = options.fixedWidths;
for (const index of displayOrder) {
const side = sideFlags[index]!;
if (priorSide !== undefined) {
x += priorSide === side ? gap : sideGap;
}
const w = fixedWidths
? resolveFixedLaneWidth(fixedWidths, channels[index], scratchFlags[index]!, options.playVariant)
: unit * laneWeights[index]!;
rects[index] = { channel: channels[index], x, w, isScratch: scratchFlags[index]!, side };
x += w;
priorSide = side;
}
return rects;
}
function resolveFixedLaneWidth(
widths: FixedLaneWidths,
channel: string | undefined,
isScratch: boolean,
playVariant: ChartPlayVariant | undefined,
): number {
if (isScratch) return widths.scratch;
const slot = channel === undefined ? -1 : resolveCoreSideKeySlot(channel, playVariant);
return slot > 0 && slot % 2 === 0 ? widths.black : widths.white;
}
function resolveFallbackLaneSide(channel: string | undefined, playVariant?: ChartPlayVariant): '1P' | '2P' {
return playVariant !== '9' && !playVariant?.startsWith('generic-') && channel?.startsWith('2') === true ? '2P' : '1P';
}
function resolveTotalInterLaneGap(
displayOrder: readonly number[],
sideFlags: ReadonlyArray<'1P' | '2P'>,
gap: number,
sideGap: number,
): number {
let total = 0;
for (let i = 1; i < displayOrder.length; i += 1) {
const previous = sideFlags[displayOrder[i - 1]!]!;
const next = sideFlags[displayOrder[i]!]!;
total += previous === next ? gap : sideGap;
}
return total;
}
function resolveFallbackLaneDisplayOrder(
channels: ReadonlyArray<string | undefined>,
scratchFlags: ReadonlyArray<boolean>,
playVariant?: ChartPlayVariant,
): number[] {
if (playVariant === '9' || playVariant?.startsWith('generic-')) {
return channels.map((_, index) => index);
}
return channels
.map((channel, index) => ({
index,
side: channel?.startsWith('2') === true ? 1 : 0,
// The scratch, and the keyboard modes' wheel, sit on the outer edge: left of the 1P keys, right of the 2P keys.
scratchOrder:
scratchFlags[index] || (channel !== undefined && resolveWheelLaneDirection(channel, playVariant) !== undefined)
? channel?.startsWith('2') === true
? 1
: -1
: 0,
slot: channel === undefined ? index : resolveCoreSideKeySlot(channel, playVariant),
}))
.sort((a, b) => {
if (a.side !== b.side) return a.side - b.side;
if (a.scratchOrder !== b.scratchOrder) return a.scratchOrder - b.scratchOrder;
if (a.slot !== b.slot) return a.slot - b.slot;
return a.index - b.index;
})
.map((entry) => entry.index);
}
/**
* Visual class of a lane. `laneIndex` is the LR2 lane id (0 / 10 = scratch, 1..9 / 11..19 = keys, -1 when the lane has
* no LR2 rect): That-Which-Must-Not-Be-Named / pop'n keys alternate by it, odd keys white and even keys black, as the play-mode table's key
* tones do. The 24 / 48-key keyboard modes take the table's piano colours instead, repeating every octave, and their
* wheel lanes (`1P` / `1Q`, `2P` / `2Q`) are `'wheel-up'` / `'wheel-down'`.
*/
export function resolveBeMusicLaneKind(
channel: string,
laneIndex: number,
playVariant: ChartPlayVariant | undefined,
): BeMusicLaneKind {
if (playVariant?.startsWith('generic-')) return 'white';
if (isScratchLaneForVariant(channel, playVariant)) return 'scratch';
if (playVariant === '24' || playVariant === '48') {
const lane = findPlayModeLane(playVariant, channel);
if (lane?.kind === 'wheel-up' || lane?.kind === 'wheel-down') return lane.kind;
// A key's colour repeats every octave (12 keys), so a lane outside the layout takes that of its octave twin.
const slot = resolveSideRelativeLaneIndex(channel, playVariant);
return KEYBOARD_KEY_TONES_BY_SLOT.get(((((slot - 1) % 12) + 12) % 12) + 1) ?? 'white';
}
return (laneIndex % 10) % 2 === 0 ? 'black' : 'white';
}
/** Piano colour of each keyboard-mode key number (1..24), from the play-mode table. */
const KEYBOARD_KEY_TONES_BY_SLOT: ReadonlyMap<number, PlayKeyTone> = new Map(
PLAY_MODE_LAYOUTS['24'].lanes.flatMap((lane) => (lane.tone === undefined ? [] : [[lane.slot, lane.tone] as const])),
);
|