feat(chords): per-section harmony timeline#577
Open
seonghobae wants to merge 1 commit into
Open
Conversation
The rehearsal domain model mandates that harmony is modeled per section and forbids collapsing a song to one global chord answer, but the roles extractor still reduces everything to the single most-common chord. Add a section_harmony module that turns the ChordRecognizer's time-stamped chord segments into an overlap-weighted per-section chord timeline: - summarize_section_harmony(chord_segments, boundaries) returns one summary per section with main_chord, duration-sorted chord table, and chord_changes count. - Exact overlap weighting: a segment straddling a boundary contributes only its in-section portion to each side. - "N" (no-chord) never wins main_chord but stays in the table. - Safe failure: malformed segments/boundaries are skipped and empty inputs yield empty summaries; no exceptions escape. Pure stdlib. Tests cover boundary straddling with exact durations, duration-vs- count main chord selection, "N" exclusion, empty/no-overlap/ malformed inputs, and deterministic tie-breaking (100% line coverage of the new module). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RjGVapDZ3k7V7zKYk16P4C
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.
What
Adds
src/bandscope_analysis/chords/section_harmony.pyto the analysis engine:summarize_section_harmony(chord_segments, boundaries)turns theChordRecognizer's time-stamped chord segments into an overlap-weighted per-section chord timeline —{start_time, end_time, main_chord, chords: [{chord, duration}, ...] (desc by duration), chord_changes}per section.Why
docs/architecture/rehearsal-domain-model.mdmandates that harmony is modeled per section and forbids collapsing to one global chord answer — yetroles/extractor.pyreduces the whole song to the single most-common chord. This module provides the per-section building block the domain model requires.Design points
main_chordis the longest-total-duration non-"N"chord;"N"(no-chord) can appear in the duration table but never wins, and a chordless section yields"".mypy --strictclean, exported frombandscope_analysis.chords.Tests
tests/test_section_harmony.py— 11 tests, 100% line coverage of the new module:main_chordpicked by duration, not segment count"N"excluded frommain_chordbut listedGates:
ruff check+ruff format+mypy srcclean; full suitepytest -q→ 444 passed.🤖 Generated with Claude Code
https://claude.ai/code/session_01RjGVapDZ3k7V7zKYk16P4C