FAILURE MAP
← Case archive

FA-80866 / Music interval and transposition theory / Open access

Key-aware MIDI note spelling: octave label one too high · case 01

Middle C is labelled C5 and every other key also reports an octave one too high.

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

ROOT CAUSE

The octave label is the plain quotient by twelve, forgetting that key 0 belongs to octave -1.

VERIFIED REPAIR

Restore the octave origin step so that it reads `octave = m // 12 - 1`.

Unsuccessful approach: Clamping the lowest octave to 0 relabels keys 0..11 as octave 0 instead of octave -1.

Case contract

Input [midi, fifths] with midi 0..127 and fifths -7..7. Use flat names when fifths < 0, sharp names otherwise; in keys with at least six sharps pitch class 5 is E#, with seven sharps pitch class 0 is B# of the previous octave, and with at least six flats pitch class 11 is Cb of the next octave. Octave -1 starts at key 0. Invalid input returns None.

Why this case matters

Pitch spelling and interval arithmetic decide the notes that notation, transposition and analysis tools display or play.

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) != 2:
        return None
    m, f = x
    if not isinstance(m, int) or m < 0 or m > 127:
        return None
    if not isinstance(f, int) or f < -7 or f > 7:
        return None
    sharps = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
    flats = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B']
    table = flats if f < 0 else sharps
    pc = m % 12
    octave = m // 12
    name = table[pc]
    if f >= 6 and pc == 5:
        name = 'E#'
    if f == 7 and pc == 0:
        name = 'B#'
        octave -= 1
    if f <= -6 and pc == 11:
        name = 'Cb'
        octave += 1
    return name + str(octave)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([60, 0], 'C4'), ([61, -1], 'Db4'), ([0, 0], 'C-1'), ([128, 0], None), ([-1, 0], None), ([60, 8], None), ([60, -8], None), ([5, 6], 'E#-1')], [([60, 0], 'C4'), ([61, 0], 'C#4'), ([61, -1], 'Db4'), ([61, 1], 'C#4'), ([70, -2], 'Bb4'), ([1, -3], 'Db-1'), ([60, -8], None), ([0, 7], 'B#-2')], [([61, -1], 'Db4'), ([61, 1], 'C#4'), ([70, -2], 'Bb4'), ([70, 2], 'A#4'), ([65, 6], 'E#4'), ([65, 5], 'F4'), ([0, 0], 'C-1'), ([11, 0], 'B-1')], [([61, 1], 'C#4'), ([70, 2], 'A#4'), ([65, 6], 'E#4'), ([65, 5], 'F4'), ([65, 7], 'E#4'), ([65, -6], 'F4'), ([1, -3], 'Db-1'), ([5, 6], 'E#-1')], [([70, -2], 'Bb4'), ([65, 6], 'E#4'), ([65, 7], 'E#4'), ([65, -6], 'F4'), ([60, 7], 'B#3'), ([48, 7], 'B#2'), ([11, 0], 'B-1'), ([0, 7], 'B#-2')]]
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 0C5C4Failed
oracle 1Db5Db4Failed
oracle 2C0C-1Failed
oracle 3NoneNonePassed
oracle 4NoneNonePassed
oracle 5NoneNonePassed
oracle 6NoneNonePassed
oracle 7E#0E#-1Failed

SHA-256 / 3f6c38e806af7b7af57ee83e5b7d20c6bea839e4b61bcdebd0d73e2bd73b6391

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) != 2:
        return None
    m, f = x
    if not isinstance(m, int) or m < 0 or m > 127:
        return None
    if not isinstance(f, int) or f < -7 or f > 7:
        return None
    sharps = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
    flats = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B']
    table = flats if f < 0 else sharps
    pc = m % 12
    octave = m // 12 - 1 if m >= 12 else 0
    name = table[pc]
    if f >= 6 and pc == 5:
        name = 'E#'
    if f == 7 and pc == 0:
        name = 'B#'
        octave -= 1
    if f <= -6 and pc == 11:
        name = 'Cb'
        octave += 1
    return name + str(octave)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([60, 0], 'C4'), ([61, -1], 'Db4'), ([0, 0], 'C-1'), ([128, 0], None), ([-1, 0], None), ([60, 8], None), ([60, -8], None), ([5, 6], 'E#-1')], [([60, 0], 'C4'), ([61, 0], 'C#4'), ([61, -1], 'Db4'), ([61, 1], 'C#4'), ([70, -2], 'Bb4'), ([1, -3], 'Db-1'), ([60, -8], None), ([0, 7], 'B#-2')], [([61, -1], 'Db4'), ([61, 1], 'C#4'), ([70, -2], 'Bb4'), ([70, 2], 'A#4'), ([65, 6], 'E#4'), ([65, 5], 'F4'), ([0, 0], 'C-1'), ([11, 0], 'B-1')], [([61, 1], 'C#4'), ([70, 2], 'A#4'), ([65, 6], 'E#4'), ([65, 5], 'F4'), ([65, 7], 'E#4'), ([65, -6], 'F4'), ([1, -3], 'Db-1'), ([5, 6], 'E#-1')], [([70, -2], 'Bb4'), ([65, 6], 'E#4'), ([65, 7], 'E#4'), ([65, -6], 'F4'), ([60, 7], 'B#3'), ([48, 7], 'B#2'), ([11, 0], 'B-1'), ([0, 7], 'B#-2')]]
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 0C4C4Passed
oracle 1Db4Db4Passed
oracle 2C0C-1Failed
oracle 3NoneNonePassed
oracle 4NoneNonePassed
oracle 5NoneNonePassed
oracle 6NoneNonePassed
oracle 7E#0E#-1Failed

SHA-256 / 6c097453cba0af02a9dc791a3f53fb79a19d002448ad944086272e3da148a389

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) != 2:
        return None
    m, f = x
    if not isinstance(m, int) or m < 0 or m > 127:
        return None
    if not isinstance(f, int) or f < -7 or f > 7:
        return None
    sharps = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
    flats = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B']
    table = flats if f < 0 else sharps
    pc = m % 12
    octave = m // 12 - 1
    name = table[pc]
    if f >= 6 and pc == 5:
        name = 'E#'
    if f == 7 and pc == 0:
        name = 'B#'
        octave -= 1
    if f <= -6 and pc == 11:
        name = 'Cb'
        octave += 1
    return name + str(octave)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([60, 0], 'C4'), ([61, -1], 'Db4'), ([0, 0], 'C-1'), ([128, 0], None), ([-1, 0], None), ([60, 8], None), ([60, -8], None), ([5, 6], 'E#-1')], [([60, 0], 'C4'), ([61, 0], 'C#4'), ([61, -1], 'Db4'), ([61, 1], 'C#4'), ([70, -2], 'Bb4'), ([1, -3], 'Db-1'), ([60, -8], None), ([0, 7], 'B#-2')], [([61, -1], 'Db4'), ([61, 1], 'C#4'), ([70, -2], 'Bb4'), ([70, 2], 'A#4'), ([65, 6], 'E#4'), ([65, 5], 'F4'), ([0, 0], 'C-1'), ([11, 0], 'B-1')], [([61, 1], 'C#4'), ([70, 2], 'A#4'), ([65, 6], 'E#4'), ([65, 5], 'F4'), ([65, 7], 'E#4'), ([65, -6], 'F4'), ([1, -3], 'Db-1'), ([5, 6], 'E#-1')], [([70, -2], 'Bb4'), ([65, 6], 'E#4'), ([65, 7], 'E#4'), ([65, -6], 'F4'), ([60, 7], 'B#3'), ([48, 7], 'B#2'), ([11, 0], 'B-1'), ([0, 7], 'B#-2')]]
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 0C4C4Passed
oracle 1Db4Db4Passed
oracle 2C-1C-1Passed
oracle 3NoneNonePassed
oracle 4NoneNonePassed
oracle 5NoneNonePassed
oracle 6NoneNonePassed
oracle 7E#-1E#-1Passed

SHA-256 / 0d5df399688cd58e7509792537d612461a0b183c3ebf37648dd78d1e95ab9815

Verification & scope

A deterministic bounded teaching model with a stipulated toy contract; it is not a complete music notation or theory engine. 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:49:57.945110+00:00.

Case digest / a3f7172a9397041874cb1fc5e7ce787983b295acc10e4e42ba2e345711e88fec