-
Notifications
You must be signed in to change notification settings - Fork 0
feat(analysis-engine): add capo and tuning detection heuristics #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,5 @@ apps/desktop/src-tauri/target/ | |
| *.pyc | ||
| *.pyo | ||
| *.egg-info/ | ||
| registered_agents.json | ||
| task_agent_mapping.json | ||
6 changes: 5 additions & 1 deletion
6
services/analysis-engine/src/bandscope_analysis/chords/__init__.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,5 @@ | ||
| """Chord analysis placeholders.""" | ||
| """Chord analysis and parsing.""" | ||
|
|
||
| from .capo import detect_capo_and_tuning | ||
|
|
||
| __all__ = ["detect_capo_and_tuning"] |
32 changes: 32 additions & 0 deletions
32
services/analysis-engine/src/bandscope_analysis/chords/capo.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| """Capo and tuning detection heuristics.""" | ||
|
|
||
|
|
||
| def detect_capo_and_tuning(chords: list[str]) -> dict[str, str | int | None]: | ||
| """ | ||
| Detect the most likely capo position and tuning based on a list of chords. | ||
|
|
||
| This is a basic heuristic that looks for common open chord shapes. | ||
|
|
||
| Args: | ||
| chords: A list of chord symbols (e.g., ['G', 'D', 'Em', 'C']). | ||
|
|
||
| Returns: | ||
| A dictionary containing 'capo' (int or None) and 'tuning' (str). | ||
| """ | ||
| if not chords: | ||
| return {"capo": None, "tuning": "Standard"} | ||
|
|
||
| chords_set = set(chords) | ||
|
|
||
| # Check for drop D indicators | ||
| if "D5" in chords_set: | ||
| return {"capo": 0, "tuning": "Drop D"} | ||
|
|
||
| # If we see Eb, Bb, Fm, Ab, a capo on 1st fret (playing D, A, Em, G shapes) is very common | ||
| flat_keys = {"Eb", "Bb", "Fm", "Ab"} | ||
|
|
||
| if len(chords_set.intersection(flat_keys)) >= 2: | ||
| return {"capo": 1, "tuning": "Standard"} | ||
|
|
||
| # Default fallback | ||
| return {"capo": 0, "tuning": "Standard"} | ||
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
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
29 changes: 29 additions & 0 deletions
29
services/analysis-engine/src/bandscope_analysis/roles/tuning.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| """Tuning and setup note heuristics based on role and chords.""" | ||
|
|
||
| from bandscope_analysis.chords.capo import detect_capo_and_tuning | ||
|
|
||
|
|
||
| def get_setup_note(role_name: str, chords: list[str]) -> str | None: | ||
| """ | ||
| Generate a setup note (like Capo fret) for a given role based on the chords. | ||
|
|
||
| Args: | ||
| role_name: The name of the role (e.g., 'Acoustic Guitar', 'Bass Guitar'). | ||
| chords: A list of chords for the song or section. | ||
|
|
||
| Returns: | ||
| A setup string, or None if no specific setup is needed. | ||
| """ | ||
| role_lower = role_name.lower() | ||
|
|
||
| # Capo only makes sense for guitars usually | ||
| if "guitar" in role_lower and "bass" not in role_lower: | ||
| result = detect_capo_and_tuning(chords) | ||
| tuning = result["tuning"] | ||
|
|
||
| if isinstance(result["capo"], int) and result["capo"] > 0: | ||
| return f"Setup: {tuning} tuning, Capo {result['capo']}" | ||
| elif tuning != "Standard": | ||
| return f"Setup: {tuning} tuning" | ||
|
|
||
| return None |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| """Tests for chord analysis heuristics.""" | ||
|
|
||
| from bandscope_analysis.chords.capo import detect_capo_and_tuning | ||
|
|
||
|
|
||
| def test_detect_capo_standard(): | ||
| """Test standard tuning and no capo.""" | ||
| result = detect_capo_and_tuning(["G", "D", "Em", "C"]) | ||
| assert result["capo"] == 0 | ||
| assert result["tuning"] == "Standard" | ||
|
|
||
|
|
||
| def test_detect_capo_fret1(): | ||
| """Test capo detection for flat keys.""" | ||
| result = detect_capo_and_tuning(["Eb", "Bb", "Fm", "Ab"]) | ||
| assert result["capo"] == 1 | ||
| assert result["tuning"] == "Standard" | ||
|
|
||
|
|
||
| def test_detect_capo_empty(): | ||
| """Test empty chord list.""" | ||
| result = detect_capo_and_tuning([]) | ||
| assert result["capo"] is None | ||
| assert result["tuning"] == "Standard" | ||
|
|
||
|
|
||
| def test_detect_drop_d(): | ||
| """Test drop D tuning.""" | ||
| result = detect_capo_and_tuning(["D5", "G5", "A5"]) | ||
| assert result["capo"] == 0 | ||
| assert result["tuning"] == "Drop D" | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| """Tests for role tuning heuristics.""" | ||
|
|
||
| from bandscope_analysis.roles.tuning import get_setup_note | ||
|
|
||
|
|
||
| def test_get_setup_note_acoustic_guitar(): | ||
| """Test setup note for acoustic guitar with flat keys.""" | ||
| # Should suggest Capo 1 | ||
| note = get_setup_note("Acoustic Guitar", ["Eb", "Bb", "Fm", "Ab"]) | ||
| assert note == "Setup: Standard tuning, Capo 1" | ||
|
|
||
|
|
||
| def test_get_setup_note_bass_guitar(): | ||
| """Test that bass guitar ignores capo.""" | ||
| note = get_setup_note("Bass Guitar", ["Eb", "Bb", "Fm", "Ab"]) | ||
| assert note is None | ||
|
|
||
|
|
||
| def test_get_setup_note_keys(): | ||
| """Test that keys ignore capo.""" | ||
| note = get_setup_note("Keyboard", ["Eb", "Bb", "Fm", "Ab"]) | ||
| assert note is None | ||
|
|
||
|
|
||
| def test_get_setup_note_standard(): | ||
| """Test guitar in standard tuning, no capo.""" | ||
| note = get_setup_note("Electric Guitar", ["G", "D", "Em", "C"]) | ||
| assert note is None | ||
|
|
||
|
|
||
| def test_get_setup_note_drop_d(): | ||
| """Test drop D tuning detection.""" | ||
| note = get_setup_note("Electric Guitar", ["D5", "G5", "A5"]) | ||
| assert note == "Setup: Drop D tuning" | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.