FAILURE MAP
← Case archive

FA-81541 / MIDI event timing / Open access

Strength-weighted grid quantisation: notes always pulled back to the previous grid line · case 01

A note just before the beat is dragged back almost a full grid step instead of forward to the beat.

Verified by executionVariant 1 · 8 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The target grid line is the floor of the position rather than the nearest line.

VERIFIED REPAIR

Restore the nearest grid line step so that it reads `(2 * t + grid) // (2 * grid)`.

Unsuccessful approach: Rounding exact halves down pulls notes midway between lines backward, against the stipulated later-line rule.

Case contract

Input [ticks, grid, strength] with grid > 0 and strength 0..100 percent. Each tick moves toward its nearest grid line (exact halves go to the later line) by strength percent of the distance, with the displacement truncated toward zero. Invalid parameters return None.

Why this case matters

MIDI sequencers, file readers and synth drivers depend on exact event ordering and tick/time arithmetic.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    if not isinstance(x, list) or len(x) != 3:
        return None
    ticks, grid, strength = x
    if grid <= 0 or not 0 <= strength <= 100:
        return None
    out = []
    for t in ticks:
        target = t // grid * grid
        move = (target - t) * strength
        step = abs(move) // 100
        out.append(t + step if move >= 0 else t - step)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([[0, 10, 50, 110, 120], 120, 100], [0, 0, 0, 120, 120]), ([[60, 180], 120, 100], [120, 240]), ([[59, 61], 120, 100], [0, 120]), ([[5, 115], 120, 0], [5, 115]), ([[5], 120, 101], None), ([[5], 0, 50], None), ([[5], 120, -1], None), ([[45, 75], 30, 100], [60, 90])], [([[0, 10, 50, 110, 120], 120, 100], [0, 0, 0, 120, 120]), ([[60, 180], 120, 100], [120, 240]), ([[59, 61], 120, 100], [0, 120]), ([[10, 110], 120, 50], [5, 115]), ([[10, 110], 120, 75], [3, 117]), ([[5], 120, -1], None), ([[45, 75], 30, 100], [60, 90]), ([[125], 120, 99], [121])], [([[60, 180], 120, 100], [120, 240]), ([[59, 61], 120, 100], [0, 120]), ([[10, 110], 120, 50], [5, 115]), ([[10, 110], 120, 75], [3, 117]), ([[7, 113], 120, 33], [5, 115]), ([[5, 115], 120, 100], [0, 120]), ([[239, 241], 240, 50], [239, 241]), ([[45, 75], 30, 100], [60, 90])], [([[60, 180], 120, 100], [120, 240]), ([[10, 110], 120, 50], [5, 115]), ([[10, 110], 120, 75], [3, 117]), ([[7, 113], 120, 33], [5, 115]), ([[5, 115], 120, 100], [0, 120]), ([[239, 241], 240, 50], [239, 241]), ([[1, 2, 3, 4], 3, 50], [1, 2, 3, 4]), ([[45, 75], 30, 100], [60, 90])], [([[60, 180], 120, 100], [120, 240]), ([[10, 110], 120, 75], [3, 117]), ([[5, 115], 120, 100], [0, 120]), ([[239, 241], 240, 50], [239, 241]), ([[1, 2, 3, 4], 3, 50], [1, 2, 3, 4]), ([[45, 75], 30, 100], [60, 90]), ([[44, 76], 30, 90], [32, 88]), ([[1000, 1030], 120, 80], [968, 1070])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
oracle 0[0, 0, 0, 0, 120][0, 0, 0, 120, 120]Failed
oracle 1[0, 120][120, 240]Failed
oracle 2[0, 0][0, 120]Failed
oracle 3[5, 115][5, 115]Passed
oracle 4NoneNonePassed
oracle 5NoneNonePassed
oracle 6NoneNonePassed
oracle 7[30, 60][60, 90]Failed

SHA-256 / b1fb816d5f11c61fd68837a31394ea9390465f9a0809b87830511961a763e526

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    if not isinstance(x, list) or len(x) != 3:
        return None
    ticks, grid, strength = x
    if grid <= 0 or not 0 <= strength <= 100:
        return None
    out = []
    for t in ticks:
        target = (2 * t + grid - 1) // (2 * grid) * grid
        move = (target - t) * strength
        step = abs(move) // 100
        out.append(t + step if move >= 0 else t - step)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([[0, 10, 50, 110, 120], 120, 100], [0, 0, 0, 120, 120]), ([[60, 180], 120, 100], [120, 240]), ([[59, 61], 120, 100], [0, 120]), ([[5, 115], 120, 0], [5, 115]), ([[5], 120, 101], None), ([[5], 0, 50], None), ([[5], 120, -1], None), ([[45, 75], 30, 100], [60, 90])], [([[0, 10, 50, 110, 120], 120, 100], [0, 0, 0, 120, 120]), ([[60, 180], 120, 100], [120, 240]), ([[59, 61], 120, 100], [0, 120]), ([[10, 110], 120, 50], [5, 115]), ([[10, 110], 120, 75], [3, 117]), ([[5], 120, -1], None), ([[45, 75], 30, 100], [60, 90]), ([[125], 120, 99], [121])], [([[60, 180], 120, 100], [120, 240]), ([[59, 61], 120, 100], [0, 120]), ([[10, 110], 120, 50], [5, 115]), ([[10, 110], 120, 75], [3, 117]), ([[7, 113], 120, 33], [5, 115]), ([[5, 115], 120, 100], [0, 120]), ([[239, 241], 240, 50], [239, 241]), ([[45, 75], 30, 100], [60, 90])], [([[60, 180], 120, 100], [120, 240]), ([[10, 110], 120, 50], [5, 115]), ([[10, 110], 120, 75], [3, 117]), ([[7, 113], 120, 33], [5, 115]), ([[5, 115], 120, 100], [0, 120]), ([[239, 241], 240, 50], [239, 241]), ([[1, 2, 3, 4], 3, 50], [1, 2, 3, 4]), ([[45, 75], 30, 100], [60, 90])], [([[60, 180], 120, 100], [120, 240]), ([[10, 110], 120, 75], [3, 117]), ([[5, 115], 120, 100], [0, 120]), ([[239, 241], 240, 50], [239, 241]), ([[1, 2, 3, 4], 3, 50], [1, 2, 3, 4]), ([[45, 75], 30, 100], [60, 90]), ([[44, 76], 30, 90], [32, 88]), ([[1000, 1030], 120, 80], [968, 1070])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
oracle 0[0, 0, 0, 120, 120][0, 0, 0, 120, 120]Passed
oracle 1[0, 120][120, 240]Failed
oracle 2[0, 120][0, 120]Passed
oracle 3[5, 115][5, 115]Passed
oracle 4NoneNonePassed
oracle 5NoneNonePassed
oracle 6NoneNonePassed
oracle 7[30, 60][60, 90]Failed

SHA-256 / f290e396a23acdf9bd3316455f2e41ba4ca9b1be018cc0c5ed12d0814de0bdd2

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    if not isinstance(x, list) or len(x) != 3:
        return None
    ticks, grid, strength = x
    if grid <= 0 or not 0 <= strength <= 100:
        return None
    out = []
    for t in ticks:
        target = (2 * t + grid) // (2 * grid) * grid
        move = (target - t) * strength
        step = abs(move) // 100
        out.append(t + step if move >= 0 else t - step)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([[0, 10, 50, 110, 120], 120, 100], [0, 0, 0, 120, 120]), ([[60, 180], 120, 100], [120, 240]), ([[59, 61], 120, 100], [0, 120]), ([[5, 115], 120, 0], [5, 115]), ([[5], 120, 101], None), ([[5], 0, 50], None), ([[5], 120, -1], None), ([[45, 75], 30, 100], [60, 90])], [([[0, 10, 50, 110, 120], 120, 100], [0, 0, 0, 120, 120]), ([[60, 180], 120, 100], [120, 240]), ([[59, 61], 120, 100], [0, 120]), ([[10, 110], 120, 50], [5, 115]), ([[10, 110], 120, 75], [3, 117]), ([[5], 120, -1], None), ([[45, 75], 30, 100], [60, 90]), ([[125], 120, 99], [121])], [([[60, 180], 120, 100], [120, 240]), ([[59, 61], 120, 100], [0, 120]), ([[10, 110], 120, 50], [5, 115]), ([[10, 110], 120, 75], [3, 117]), ([[7, 113], 120, 33], [5, 115]), ([[5, 115], 120, 100], [0, 120]), ([[239, 241], 240, 50], [239, 241]), ([[45, 75], 30, 100], [60, 90])], [([[60, 180], 120, 100], [120, 240]), ([[10, 110], 120, 50], [5, 115]), ([[10, 110], 120, 75], [3, 117]), ([[7, 113], 120, 33], [5, 115]), ([[5, 115], 120, 100], [0, 120]), ([[239, 241], 240, 50], [239, 241]), ([[1, 2, 3, 4], 3, 50], [1, 2, 3, 4]), ([[45, 75], 30, 100], [60, 90])], [([[60, 180], 120, 100], [120, 240]), ([[10, 110], 120, 75], [3, 117]), ([[5, 115], 120, 100], [0, 120]), ([[239, 241], 240, 50], [239, 241]), ([[1, 2, 3, 4], 3, 50], [1, 2, 3, 4]), ([[45, 75], 30, 100], [60, 90]), ([[44, 76], 30, 90], [32, 88]), ([[1000, 1030], 120, 80], [968, 1070])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
oracle 0[0, 0, 0, 120, 120][0, 0, 0, 120, 120]Passed
oracle 1[120, 240][120, 240]Passed
oracle 2[0, 120][0, 120]Passed
oracle 3[5, 115][5, 115]Passed
oracle 4NoneNonePassed
oracle 5NoneNonePassed
oracle 6NoneNonePassed
oracle 7[60, 90][60, 90]Passed

SHA-256 / f1cf38bca8c29a41bd96d025960cdda4cb29fc09cfa4bbc9258e86c52a9ce015

Verification & scope

A deterministic bounded teaching model with a stipulated toy contract; it is not a complete Standard MIDI File or MIDI 1.0/2.0 implementation. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:50:03.848456+00:00.

Case digest / db4ef79c80c8847716b7ac8fbb8b2591ab8af95470be1452c79a42b05efb853b