Skip to content

chore: replace hard-coded -1 sentinels with named constexpr constants#295

Merged
webern merged 1 commit into
mainfrom
claude/untitled-session-5o3jgm
Jul 4, 2026
Merged

chore: replace hard-coded -1 sentinels with named constexpr constants#295
webern merged 1 commit into
mainfrom
claude/untitled-session-5o3jgm

Conversation

@webern

@webern webern commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Human Summary

Seems pretty mechanical and straightforward. I haven't read every line but I see that it added a few sentinel constants and wired them into the codebase.

Summary

The mx::api layer used hard-coded -1 (and -1.0) literals as "unspecified" sentinels, e.g. staffIndex{-1} in KeyData.h. This change gives those sentinels names, defined in ApiCommon.h next to the existing constants:

  • INDEX_UNSPECIFIED - staff/part indices and staff numbers (e.g. KeyData::staffIndex, PartGroupData::firstPartIndex, PartSymbolData::topStaff)
  • NUMBER_LEVEL_UNSPECIFIED - MusicXML number attributes (e.g. SpannerStart::numberLevel, wedges, tuplets, curves, PartGroupData::number)
  • VALUE_UNSPECIFIED - other absent-able ints (e.g. DirectionData::voice, midi bank/channel/program, BeatsPerMinute::beatsPerMinute, EncodingDate)
  • DOUBLE_UNSPECIFIED - absent-able doubles (e.g. StaffData::staffSize, SoundData::tempo, DefaultsData::scalingMillimeters, MeasureData::width)

The constants equal the old literals, so this is non-breaking and there is no behavior change. The api headers and the impl translation layer now use the names wherever the literal carried this sentinel meaning; unrelated -1s (musical alter values, arithmetic, mx::core internals) are untouched. Comments that documented "-1 means unspecified" now name the constant instead.

This is deliberately the lightweight named-constant version; moving these fields to std::optional is a separate breaking change tracked in #249.

Testing

  • make fmt and make check pass
  • make test passes: 4458 assertions in 346 test cases, examples run
  • No behavior change expected: constants are constexpr and equal to the old literals

References

…tants

Adds INDEX_UNSPECIFIED, NUMBER_LEVEL_UNSPECIFIED, VALUE_UNSPECIFIED, and
DOUBLE_UNSPECIFIED to ApiCommon.h and uses them in place of the hard-coded
-1 / -1.0 sentinel literals across the mx::api headers and the mx::impl
translation layer. No behavior change; the constants equal the old
literals. Closes #282.
@webern webern added the ai Issues opened by, or through, a coding agent. label Jul 4, 2026 — with Claude
@webern webern marked this pull request as ready for review July 4, 2026 07:38
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

Coverage report

Core-dev coverage src/private/mx/core/

Metric Coverage Covered / Total
Lines 77.8% 28487 / 36624
Functions 74.3% 6349 / 8550
Branches 50.6% 22632 / 44725

API coverage src/private/mx/{api,impl,utility}/

Metric Coverage Covered / Total
Lines 78.7% 6117 / 7776
Functions 64.3% 2091 / 3252
Branches 47.9% 5206 / 10866

Core HTML report | API HTML report

Commit 49f6a7270c5b29db9f4962ef3769e4db5ecd2d52.

@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

gen-quality gen/

gen-quality: 84.5 / 100   (floor 84.5, +0.0)

  structure     86.5  x0.50   [fn 90.5 / file 82.6]
  cyclomatic    88.4  x0.25
  cognitive     76.6  x0.25

  409 functions across 31 files, 7702 lines (largest file 1044)
  max cc 56  max cognitive 44  max fn loc 152

Worst offenders (top 5 per axis; full lists in score.json):
  cyclomatic gen/xsd/analyze.py:311     report                             56
  cyclomatic gen/plates/build.py:956    _validate_config_against_ir        35
  cyclomatic gen/press/context.py:145   plate_context                      34
  cyclomatic gen/__main__.py:46         _ir                                23
  cyclomatic gen/tests/test_ir.py:102   _check_references                  20
  cognitive  gen/xsd/analyze.py:311     report                             44
  cognitive  gen/ir/resolve.py:119      flat_elements                      40
  cognitive  gen/tests/test_ir.py:102   _check_references                  38
  cognitive  gen/press/context.py:145   plate_context                      37
  cognitive  gen/xsd/analyze.py:207     _sccs                              37
  size       gen/xsd/analyze.py:311     report                             152
  size       gen/press/context.py:145   plate_context                      96
  size       gen/plates/build.py:533    _value_plate                       89
  size       gen/plates/build.py:956    _validate_config_against_ir        89
  size       gen/ir/resolve.py:119      flat_elements                      78

Commit 49f6a7270c5b29db9f4962ef3769e4db5ecd2d52.

@webern webern merged commit 8e5accb into main Jul 4, 2026
7 checks passed
@webern webern deleted the claude/untitled-session-5o3jgm branch July 4, 2026 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai Issues opened by, or through, a coding agent.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sentinel values should have constexpr names.

1 participant