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 | 9x 60x 6x 6x 6x 60x 60x 60x 60x 13x 13x 13x 13x 13x 51x 51x 5x 5x 13x 38x 38x 13x 13x 13x 13x 2x 11x 8x 3x 9x 2x 2x 2x 7x 13x 60x 33x 3x 3x 3x 3x 3x 3x 3x 22x 3x 33x 33x 33x 30x 3x 3x 3x 3x 3x 6x 2x 2x 1x 1x 1x 1x 2x 1x 1x 8x 8x 1x 1x 10x 10x 2x 2x 2x 2x 22x 22x 2x 19x 19x 2x 3x 3x 2x 2x 2x 8x 8x 2x 6x 6x 2x 8x 8x 3x 5x 5x 2x 3x 3x 3x 3x 3x 30x 6x 6x 6x 6x 24x 21x 21x 21x 21x 33x | import type { LR2SplitObject } from './lr2-sp-to-dp.ts';
/** A native object for the merges: its chart position decides "the same row", and a PMS mine cannot become BGM. */
export interface LR2MergeObject extends LR2SplitObject {
position: number;
mine?: boolean;
}
/**
* LR2 beta3 SP TO DP on a double-play or nine-key chart: DPtoSP (0x4ae8d0) merges a 10/14KEY chart onto the 1P side
* and PMStoSP (0x4af080) folds a 9KEY chart onto seven keys, as reconstructed by OpenLR2 (583a3850, `LR2f.cpp`
* L25091-L25450). Both consume the native object order after LN pairing (a hold's head carries its end; tails are
* op 50+ and stay put) and return one op per object: a lane op, `1` for a note moved to the background, or `-1` for a
* PMS mine that could not move (dropped).
*/
/** The minimum gap a merged note keeps from a note on its lane: half a beat at the current BPM, at least 125 ms. */
function minimumGap(bpm: number): number {
return bpm <= 0 || Math.trunc(30000 / bpm) < 125 ? 125 : Math.trunc(30000 / bpm);
}
/** DPtoSP: each 2P object moves to its 1P lane, or the nearest free one, or to the background. */
export function mergeLR2DPToSP(
source: readonly LR2MergeObject[],
options: { initialBPM: number; keymode: 10 | 14 },
): number[] {
const objects = source.map((object) => ({ ...object }));
const highest = options.keymode / 2 + 10;
let mingap = minimumGap(options.initialBPM);
for (let i = 0; i < objects.length; i++) {
const object = objects[i]!;
const op = object.op;
Iif (op === 3 || op === 8) {
mingap = Math.max(125, Math.trunc(30000 / object.value));
continue;
}
if (op < 20 || op > 29) continue;
const newop = op - 10;
let sameLane = false;
let sameTime = false;
const occupied = Array<boolean>(10).fill(false);
const scan = (other: LR2MergeObject): void => {
if (other.op >= 10 && other.op <= 19) occupied[other.op - 10] = true;
if (other.op === newop) {
sameLane = true;
Eif (other.position === object.position) sameTime = true;
}
};
for (let prev = i - 1; prev >= 0; prev--) {
scan(objects[prev]!);
if (object.timeMs - objects[prev]!.timeMs >= mingap) break;
}
for (let next = i + 1; next < objects.length; next++) {
scan(objects[next]!);
Eif (objects[next]!.timeMs - object.timeMs >= mingap) break;
}
if (op === 20) {
Iif (!sameTime) object.op = op - 10;
} else if (!sameLane) {
object.op = op - 10;
} else {
for (let j = 1; j < 8; j++) {
// The source keeps these conditions apart: a lane above in range is the only candidate when it is in range.
if (newop + j >= 11 && newop + j <= highest) {
Eif (!occupied[newop + j - 10]) {
object.op = newop + j;
break;
}
} else Iif (newop - j >= 11 && newop - j <= highest && !occupied[newop - j - 10]) {
object.op = newop - j;
break;
}
}
}
if (object.op >= 20 && object.op <= 29) object.op = 1;
}
return objects.map((object) => object.op);
}
/** PMStoSP: each measure's nine lanes are shifted or compacted onto seven, lanes 8 and 9 moved into gaps. */
export function mergeLR2PMSToSP(source: readonly LR2MergeObject[], options: { initialBPM: number }): number[] {
const objects = source.map((object) => ({ ...object, mine: object.mine === true }));
let mingap = minimumGap(options.initialBPM);
let prev = 0;
let left = 9;
let right = 1;
let measureLaneCount = 0;
let used = Array<boolean>(10).fill(false);
const shift = (from: number, to: number, predicate: (op: number) => boolean, delta: number): void => {
for (let j = from; j < to; j++) if (predicate(objects[j]!.op)) objects[j]!.op += delta;
};
for (let i = 0; i < objects.length; i++) {
const op = objects[i]!.op;
Iif (op === 3 || op === 8) {
mingap = Math.max(125, Math.trunc(30000 / objects[i]!.value));
} else if (op === 2 && measureLaneCount > 0) {
const count = used.filter((lane, index) => index >= 1 && index <= 9 && lane).length;
const firstEmpty = (from: number, to: number): number => {
for (let lane = from; lane < to; lane++) if (!used[lane]) return lane;
throw new RangeError('PMS TO SP found no empty lane.');
};
Iif (right <= 7) {
// Nothing to fold.
} else Iif (right === 8 && left >= 2) {
shift(prev, i, (value) => value >= 12 && value <= 19, -1);
} else if (right === 9 && left >= 3) {
shift(prev, i, (value) => value >= 13 && value <= 19, -2);
} else Iif (right === 9 && left === 2 && count <= 7) {
const empty = firstEmpty(2, 9);
shift(prev, i, (value) => empty + 10 < value && value <= 19, -1);
shift(prev, i, (value) => value >= 11 && value <= 19, -1);
} else if (left === 1 && count <= 7) {
Iif (right === 8) {
const empty = firstEmpty(1, 9);
shift(prev, i, (value) => 10 + empty < value && value <= 19, -1);
} else {
const emptyLeft = firstEmpty(1, 9);
let emptyRight = -1;
for (let lane = 9; lane > 1; lane--)
if (!used[lane]) {
emptyRight = lane;
break;
}
shift(prev, i, (value) => emptyLeft + 10 < value && value <= 19, -1);
shift(prev, i, (value) => emptyRight + 9 < value && value <= 19, -1);
}
} else {
Iif (left === 2) shift(prev, i, (value) => value >= 12 && value <= 19, -1);
for (let j = prev; j < i; j++) {
const object = objects[j]!;
if (object.op !== 18 && object.op !== 19) continue;
const newLane = 14 + (object.op - 18);
let sameLane = false;
const occupied = Array<boolean>(10).fill(false);
const scan = (other: LR2MergeObject): void => {
if (other.op >= 10 && other.op <= 19) occupied[other.op - 10] = true;
if (other.op === newLane) sameLane = true;
};
for (let x = j - 1; x >= 0; x--) {
scan(objects[x]!);
if (object.timeMs - objects[x]!.timeMs >= mingap) break;
}
for (let next = j + 1; next < objects.length; next++) {
scan(objects[next]!);
if (objects[next]!.timeMs - object.timeMs >= mingap) break;
}
Iif (!sameLane) object.op = newLane;
else {
// Every other lane first, then the lanes between; the source's own search.
let moved = false;
for (let k = 1; k < 5 && !moved; k++) {
let lane = newLane + k * 2;
if (lane >= 11 && lane <= 17) {
Iif (!occupied[lane - 10]) {
object.op = lane;
moved = true;
}
} else {
lane = newLane - k * 2;
Iif (lane >= 11 && lane <= 17 && !occupied[lane - 10]) {
object.op = lane;
moved = true;
}
}
}
for (let k = 1; k < 5 && !moved; k++) {
let lane = newLane + k * 2 - 1;
if (lane >= 11 && lane <= 17) {
Iif (!occupied[lane - 10]) {
object.op = lane;
moved = true;
}
} else {
lane = newLane - k * 2 + 1;
Iif (lane >= 11 && lane <= 17 && !occupied[lane - 10]) {
object.op = lane;
moved = true;
}
}
}
}
Eif (object.op === 18 || object.op === 19) object.op = object.mine ? -1 : 1;
}
}
measureLaneCount = 0;
prev = i;
left = 9;
right = 1;
used = Array<boolean>(10).fill(false);
} else if (op === 2) {
left = 9;
right = 1;
prev = i;
used = Array<boolean>(10).fill(false);
} else if (op >= 11 && op <= 19) {
used[op - 10] = true;
measureLaneCount++;
left = Math.min(left, op - 10);
right = Math.max(right, op - 10);
}
}
return objects.map((object) => object.op);
}
|