Chord Families

This commit is contained in:
khodowany
2026-10-06 03:18:02 -05:00
parent e71385dad1
commit 8423f3d788
14 changed files with 196 additions and 57 deletions
+12 -4
View File
@@ -12,7 +12,8 @@ STANDARD_TUNING = ((6, 40), (5, 45), (4, 50), (3, 55), (2, 59), (1, 64))
MIN_FRET = 1
MAX_FRET = 20
MAX_SINGLE_FRET = 12
MAX_FRET_SPAN = 3
PREFERRED_FRET_SPAN = 3
MAX_FRET_SPAN = 4
MAX_ANCHOR_FRET = 12
WRITTEN_GUITAR_OCTAVE_OFFSET = 12
@@ -21,10 +22,17 @@ class TabPosition(typing.NamedTuple):
fret: int
midi: int
def within_fret_span(positions) -> bool:
"""Count occupied fret positions inclusively: frets 1-3 fit, 1-4 do not."""
def fret_span(positions) -> int:
"""Inclusive occupied positions: frets 7-9 span three, 7-10 span four."""
frets = [position.fret for position in positions]
return not frets or max(frets) - min(frets) + 1 <= MAX_FRET_SPAN
return max(frets) - min(frets) + 1 if frets else 0
def span_penalty(positions) -> int:
"""Two tiers for legal grips; all one-to-three-fret shapes share tier zero."""
return int(fret_span(positions) > PREFERRED_FRET_SPAN)
def within_fret_span(positions) -> bool:
return fret_span(positions) <= MAX_FRET_SPAN
def has_fret_anchor(positions) -> bool:
return any(MIN_FRET <= position.fret <= MAX_ANCHOR_FRET for position in positions)