Support sus4 chords in root-finding algorithm - #1988
Closed
p2rez wants to merge 1 commit into
Closed
Conversation
Add sus4 chord detection to _findRoot's rootnessFunction. When no note
in the chord has both a third and fifth above it (indicating a sus4 chord),
apply a bonus to notes that have a fourth and fifth above them.
Fixes: chord.Chord('F B- C E-').root() now correctly returns F instead of C.
Resolves cuthbertLab#1650
Member
|
tests do not cover more difficult cases. unwieldy 2-part sol (thanks for AI attempt) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1650.
Note: This contribution was developed with AI assistance (Claude/Anthropic), as declared per the contributing guidelines.
Problem
chord.Chord('F B- C E-').root() incorrectly returned C instead of F. The _findRoot method's rootnessFunction only scored notes based on thirds, fifths, sevenths, etc. above them, but gave no credit for a fourth, so sus4 chord roots were never correctly identified.
Solution
Added sus4 chord detection to _findRoot. Before scoring, we check whether any note in the chord has both a third and fifth above it. If none do (indicating a sus4 chord), we apply a bonus to notes that have both a fourth and fifth above them, giving sus4 roots the same base score as notes with a third above them in regular chords.
This avoids incorrectly boosting notes in chords that happen to have an eleventh (like C11 = C E G B- D F), where C has both a third and fifth above it, so the sus4 path is not triggered.
Tests
Added testSus4RootFinding in test/test_chord.py covering:
Basic sus4 seventh chord from the issue (F B- C E- → F)
Simple sus4 triad (C F G → C)
sus4 with seventh (C F G B- → C)
Regression: regular major, minor, dominant seventh still correct
Regression: C11 chord still returns C, not F
All 27 tests pass.