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 | 393x 54432x 42x 42x 42x 42x 648x 470x 155042x 42x 393x 117x 117x 276x 117x 151632x 117x 276x 276x 254x 254x 233x 233x 233x 117x 117x 117x 117x 117x 117x 117x 117x 393x 393x 1296x 1x 151632x 117x 117x 151632x 80x 80x 11x 69x 41x 41x 28x 80x 151632x 151632x 117x 276x 276x 117x 117x 6x 6x 97x 97x 6x 6x 97x 97x 91x 91x 87x 87x 117x 117x 117x 117x 276x 276x 113x 43x 117x 22x 22x 22x 50x 50x 50x 37x 37x 22x 11x 19x 19x 14x 14x 11x 11x 10x 70x 29x 10x 117x 117x 117x 117x 117x 351x 351x 316x 316x 21x 21x 14x 21x 21x 21x 17x 71x 64x 17x 30x 30x 22x 17x 66x 66x 49x 21x 21x 351x 276x 276x 393x | /** LR2's post-decoder object; heads keep their hold endpoint in the caller, while tails use op 50+. */
export interface LR2SplitObject {
op: number;
value: number;
timeMs: number;
}
interface SoundSide {
id: number;
count: number;
side: -1 | 0 | 1;
}
/**
* LR2 beta3 SPtoDP (0x4b0250), DPsplit, DPsplitLane and DPsplitLaneScratch.
* Consume the native order, including op-2 measure markers and non-note rows.
* Loader families, playback time and the source assists are explicit inputs.
* Return one op per input object; no random draw, duplication or input mutation.
*/
export function splitLR2SPToDP(
source: readonly LR2SplitObject[],
options: { soundFamilies: readonly number[]; playLevel: number; assist1P?: boolean; assist2P?: boolean },
): number[] {
const objects = source.map((object) => ({ ...object }));
let previous: SoundSide[] = Array.from({ length: 1296 }, (_, id) => ({ id, count: 0, side: -1 }));
let repeat = 0;
let firstSide: 0 | 1 = 0;
let alternatingSide: 0 | 1 = 0;
let scratchSide: 0 | 1 = 0;
const family = (object: LR2SplitObject): number => options.soundFamilies[object.value] ?? 0;
const key = (op: number): boolean => (op >= 11 && op <= 17) || (op >= 21 && op <= 27);
const compare = (a: SoundSide, b: SoundSide): number => b.count - a.count || a.id - b.id;
for (let marker = 0; marker < objects.length; marker++) {
if (objects[marker]!.op !== 2) continue;
const start = marker + 1;
let end = start;
while (end < objects.length && objects[end]!.op !== 2) end++;
const counts = Array<number>(8).fill(0);
const current: SoundSide[] = Array.from({ length: 1296 }, (_, id) => ({ id, count: 0, side: -1 }));
for (let index = start; index < end; index++) {
const object = objects[index]!;
if (object.op < 10 || object.op > 17) continue;
counts[object.op - 10]!++;
if (object.op === 10) continue;
const sound = current[family(object)]!;
sound.count++;
sound.side = 0;
}
current.sort(compare);
const a = current[0]!,
b = current[1]!,
c = current[2]!;
const p = previous[0]!,
q = previous[1]!,
r = previous[2]!;
const continuing =
p.count > 0 &&
a.count > 0 &&
((a.id === p.id && (b.id === q.id || b.id === r.id || c.id === q.id || c.id === r.id)) ||
(a.id === q.id && b.id === p.id) ||
(b.id === p.id && q.id === 0));
repeat = continuing ? repeat + 1 : 0;
if (repeat === 4) {
for (const sound of previous) if (sound.side !== -1) sound.side = sound.side === 0 ? 1 : 0;
repeat = 0;
}
const previousById = new Map(previous.map((sound) => [sound.id, sound]));
const load = [0, 0];
for (const [index, sound] of current.entries()) {
if (sound.count === 0) continue;
const old = previousById.get(sound.id)!;
if (continuing && old.side !== -1 && index === 0) {
sound.side = old.side;
} else if (load[0] === 0 && load[1] === 0) {
sound.side = firstSide;
firstSide = firstSide === 0 ? 1 : 0;
} else sound.side = load[1]! < load[0]! ? 1 : 0;
load[sound.side]! += sound.count;
}
// The next measure remembers the family assignment BEFORE dense/mono/scratch corrections.
previous = current.map((sound) => ({ ...sound }));
const currentById = new Map(current.map((sound) => [sound.id, sound]));
for (let index = start; index < end; index++) {
const object = objects[index]!;
if (object.op >= 11 && object.op <= 17 && currentById.get(family(object))!.side === 1) object.op += 10;
}
const dominant = current[0]!;
if (
dominant.count >= 17 ||
(dominant.count >= 16 && options.playLevel <= 10) ||
(dominant.count >= 14 && options.playLevel <= 9) ||
(dominant.count >= 12 && options.playLevel <= 8)
) {
const lanes = new Set<number>();
for (let index = start; index < end; index++) {
const object = objects[index]!;
if (key(object.op) && family(object) === dominant.id) lanes.add(object.op % 10);
}
Eif (lanes.size > 3) {
for (let index = start; index < end; index++) {
const object = objects[index]!;
if (!key(object.op)) continue;
object.op = 10 + (object.op % 10);
if (family(object) === dominant.id) {
object.op += alternatingSide * 10;
alternatingSide = alternatingSide === 0 ? 1 : 0;
}
}
}
}
let left = 0,
right = 0,
scratches = 0;
for (let index = start; index < end; index++) {
const op = objects[index]!.op;
if (op >= 11 && op <= 17) left++;
else if (op >= 21 && op <= 27) right++;
else if (op === 10) scratches++;
}
if ((left > 0 && right === 0) || (left === 0 && right > 0)) {
const lanes = new Set<number>();
let total = 0;
for (let index = start; index < end; index++) {
const object = objects[index]!;
if (object.op >= 21 && object.op <= 27) object.op -= 10;
if (object.op >= 11 && object.op <= 17) {
lanes.add(object.op - 10);
total++;
}
}
if (lanes.size >= 4 || total === 1) {
for (let index = start; index < end; index++) {
const object = objects[index]!;
if (object.op < 11 || object.op > 17) continue;
object.op += alternatingSide * 10;
alternatingSide = alternatingSide === 0 ? 1 : 0;
}
repeat = 0;
} else if (lanes.size === 2 || lanes.size === 3) {
// RightLaneTo2P and Move3rdLaneTo2P both move the highest used lane here.
let last = 0;
for (let lane = 1; lane <= 7; lane++) if (counts[lane]! > 0) last = lane;
for (let index = start; index < end; index++) if (objects[index]!.op === 10 + last) objects[index]!.op += 10;
if (lanes.size === 2) repeat = 0;
}
}
let lastTime = -1,
lastScratchTime = -1;
let pending = -1,
oldPending = -1;
// Visiting the following measure marker flushes a pending scratch. There is
// no invented end-of-array flush when the native stream has no next marker.
for (let index = start; index < objects.length; index++) {
const object = objects[index]!;
if (object.timeMs > lastTime) {
lastTime = object.timeMs;
if (pending !== -1) {
const scratch = objects[pending]!;
if (lastScratchTime + 500 < scratch.timeMs && (scratches <= 3 || lastScratchTime === -1))
scratchSide = scratchSide === 0 ? 1 : 0;
lastScratchTime = scratch.timeMs;
if (scratchSide === 1) scratch.op += 10;
if (!(scratchSide === 0 ? options.assist1P : options.assist2P)) {
const move = (note: LR2SplitObject): void => {
if (scratchSide === 0 && note.op >= 12 && note.op <= 17) note.op += 10;
else if (scratchSide === 1 && note.op >= 21 && note.op <= 26) note.op -= 10;
};
for (let previous = pending; previous > 0; previous--) {
const note = objects[previous]!;
if (note.op === 2 || scratch.timeMs - note.timeMs >= 200) break;
move(note);
}
for (let next = pending; next < objects.length; next++) {
const note = objects[next]!;
if (note.op === 2 || note.timeMs - scratch.timeMs >= 200) break;
move(note);
}
}
pending = -1;
oldPending = -1;
}
}
if (object.op === 2) break;
if (object.op === 10) pending = oldPending = index;
if (key(object.op)) pending = oldPending;
}
}
return objects.map((object) => object.op);
}
|