Skip to content

fix: clamp harmony inversion to valid range when quality changes#482

Draft
FelipeDefensor wants to merge 2 commits into
devfrom
fix/468-harmony-inversion-crash
Draft

fix: clamp harmony inversion to valid range when quality changes#482
FelipeDefensor wants to merge 2 commits into
devfrom
fix/468-harmony-inversion-crash

Conversation

@FelipeDefensor

Copy link
Copy Markdown
Collaborator

Summary

  • Clamps the stored inversion value to the maximum supported by the new chord quality before constructing music21.harmony.ChordSymbol and before calling to_roman_numeral().
  • Uses the existing get_inversion_amount(quality) helper from tilia.timelines.harmony.constants.

Test plan

  • Create a harmony component and set quality to "dominant seventh" (3rd inversion supported).
  • Set inversion to 3rd.
  • Change quality to a triad (e.g. major) — no crash, inversion is silently clamped to 2nd.

Closes #468

When the chord quality is changed to one with fewer available
inversions (e.g. from dominant-seventh to major triad), music21
raised ChordException if the stored inversion exceeded the new
maximum. Clamping the inversion via get_inversion_amount() before
constructing ChordSymbol and to_roman_numeral() prevents the crash.

Closes #468.
The previous fix clamped inversion when constructing ChordSymbol and
when calling to_roman_numeral(), but letter_symbol_label still appended
'/&<interval>' using the unclamped stored value. So after switching
from dominant-seventh + 3rd inversion to a triad, the rendered label
read 'C/&7' even though a triad has no 3rd inversion.

Extracts clamping into a clamped_inversion property and uses it in all
three rendering paths so the display stays consistent.
@FelipeDefensor FelipeDefensor force-pushed the fix/468-harmony-inversion-crash branch from f885f8e to 47c22bb Compare May 6, 2026 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant