-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement role extraction target and part graph (closes #34) #86
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
8 commits
Select commit
Hold shift + click to select a range
90e6d47
feat: implement role extraction domain model and part graph
seonghobae 3dfff0c
fix: resolve docstring and line length linting errors in role extractโฆ
seonghobae fdb3266
fix: resolve mypy errors by correctly typing ManualOverride and Reheaโฆ
seonghobae 6aee7da
fix(roles): remove unused pytest import to fix ruff check
seonghobae 9be4236
fix(roles): address code review feedback
seonghobae 66b46f9
fix(analysis): resolve CodeRabbit review comments
seonghobae 0f2f91a
fix: resolve E501 line too long error in extractor.py
seonghobae d51665a
style: format tests/test_roles.py with ruff
seonghobae 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
23 changes: 23 additions & 0 deletions
23
services/analysis-engine/src/bandscope_analysis/roles/__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 |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| """Role extraction and part graphing module.""" | ||
|
|
||
| from .extractor import RoleExtractor | ||
| from .model import ( | ||
| CueAnchorKind, | ||
| PartGraphNode, | ||
| RehearsalPriority, | ||
| RehearsalRole, | ||
| RoleExtractionResult, | ||
| RoleType, | ||
| SectionRoleTopology, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "RoleType", | ||
| "RehearsalPriority", | ||
| "CueAnchorKind", | ||
| "RehearsalRole", | ||
| "PartGraphNode", | ||
| "SectionRoleTopology", | ||
| "RoleExtractionResult", | ||
| "RoleExtractor", | ||
| ] |
190 changes: 190 additions & 0 deletions
190
services/analysis-engine/src/bandscope_analysis/roles/extractor.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,190 @@ | ||
| """Role extractor implementation.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| from typing import Any | ||
|
|
||
| from .model import ( | ||
| CueAnchorKind, | ||
| PartGraphNode, | ||
| RehearsalPriority, | ||
| RehearsalRole, | ||
| RoleExtractionResult, | ||
| RoleType, | ||
| SectionRoleTopology, | ||
| ) | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class RoleExtractor: | ||
| """Extracts roles and builds the part graph for song sections.""" | ||
|
|
||
| def __init__(self) -> None: | ||
| """Initialize the role extractor.""" | ||
| pass | ||
|
|
||
| def extract( | ||
| self, | ||
| sections: list[Any], | ||
| _audio_features: dict[str, Any] | None = None, | ||
| ) -> RoleExtractionResult: | ||
| """Extract roles and their topology per section. | ||
|
|
||
| Args: | ||
| sections: List of section dicts (must contain 'id'). | ||
| _audio_features: Optional audio features to inform extraction. | ||
|
|
||
| Returns: | ||
| RoleExtractionResult containing topologies and notes. | ||
| """ | ||
| topologies: list[SectionRoleTopology] = [] | ||
|
|
||
| # Simple mock implementation for testing/demonstration purposes | ||
| for i, section in enumerate(sections): | ||
| if not isinstance(section, dict): | ||
| logger.warning( | ||
| "Invalid section format at index %d; expected dict, got %s", | ||
| i, | ||
| type(section).__name__, | ||
| ) | ||
| section_id = f"section-{i}" | ||
| else: | ||
| section_id = section.get("id", f"section-{i}") | ||
|
|
||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| # Create a mock bass role | ||
| bass_role: RehearsalRole = { | ||
| "id": "bass-guitar", | ||
| "name": "Bass Guitar", | ||
| "roleType": RoleType.INSTRUMENT, | ||
| "harmony": {"chord": "C#m7", "functionLabel": "vi pedal anchor", "source": "model"}, | ||
| "cue": { | ||
| "kind": CueAnchorKind.TRANSITION, | ||
| "value": "Hold through the pickup before the downbeat.", | ||
| }, | ||
| "range": {"lowestNote": "C#2", "highestNote": "E3"}, | ||
| "confidence": { | ||
| "level": "medium", | ||
| "source": "model", | ||
| "notes": "Watch the slide into the turnaround.", | ||
| }, | ||
| "rehearsalPriority": RehearsalPriority.HIGH, | ||
| "simplification": "Stay on roots if the chorus entrance gets muddy.", | ||
| "setupNote": "Keep the attack short so the verse breathes.", | ||
| "manualOverrides": [], | ||
| } | ||
|
|
||
| keys_role: RehearsalRole = { | ||
| "id": "keys-right", | ||
| "name": "Keyboard 1 Right Hand", | ||
| "roleType": RoleType.HAND, | ||
| "harmony": { | ||
| "chord": "Emaj7", | ||
| "functionLabel": "Imaj7 color", | ||
| "source": "model", | ||
| }, | ||
| "cue": { | ||
| "kind": CueAnchorKind.COUNT, | ||
| "value": "Enter on beat 2 after the pickup.", | ||
| }, | ||
| "range": {"lowestNote": "B3", "highestNote": "G#5"}, | ||
| "confidence": { | ||
| "level": "medium", | ||
| "source": "model", | ||
| "notes": "Top note voicing may need a quick ear check.", | ||
| }, | ||
| "rehearsalPriority": RehearsalPriority.HIGH, | ||
| "simplification": "Drop top extension if the chorus turnaround feels busy.", | ||
| "setupNote": "Keep the patch bright enough to stay over the guitars.", | ||
| "manualOverrides": [], | ||
| } | ||
|
|
||
| vocal_role: RehearsalRole = { | ||
| "id": "lead-vocal", | ||
| "name": "Lead Vocal", | ||
| "roleType": RoleType.VOCAL, | ||
| "harmony": { | ||
| "chord": "C#m7", | ||
| "functionLabel": "vi melodic pull", | ||
| "source": "model", | ||
| }, | ||
| "cue": {"kind": CueAnchorKind.LYRIC, "value": "city lights"}, | ||
| "range": {"lowestNote": "G#3", "highestNote": "C#5"}, | ||
| "confidence": { | ||
| "level": "high", | ||
| "source": "user", | ||
| "notes": "Singer confirmed the pickup phrasing in rehearsal notes.", | ||
| }, | ||
| "rehearsalPriority": RehearsalPriority.MEDIUM, | ||
| "simplification": "Keep sustained note centered; skip ad-lib on first pass.", | ||
| "setupNote": "Watch the breath before the last line of the verse.", | ||
| "manualOverrides": [ | ||
| { | ||
| "field": "harmony", | ||
| "value": { | ||
| "chord": "C#m11", | ||
| "functionLabel": "vi suspended lift", | ||
| "source": "user", | ||
| }, | ||
| "source": "user", | ||
| } | ||
| ], | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| active_roles = [bass_role] | ||
|
|
||
| # Simple part graph for bass | ||
| part_graph: list[PartGraphNode] = [ | ||
| {"role_id": "bass-guitar", "is_active": True, "handoff_to": [], "handoff_from": []} | ||
| ] | ||
|
|
||
| if i == 0: | ||
| active_roles.extend([keys_role, vocal_role]) | ||
| part_graph.extend( | ||
| [ | ||
| { | ||
| "role_id": "keys-right", | ||
| "is_active": True, | ||
| "handoff_to": [], | ||
| "handoff_from": [], | ||
| }, | ||
| { | ||
| "role_id": "lead-vocal", | ||
| "is_active": True, | ||
| "handoff_to": [], | ||
| "handoff_from": [], | ||
| }, | ||
| ] | ||
| ) | ||
| part_graph[0]["handoff_to"].append("lead-vocal") | ||
| part_graph[2]["handoff_from"].append("bass-guitar") | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| else: | ||
| part_graph.extend( | ||
| [ | ||
| { | ||
| "role_id": "keys-right", | ||
| "is_active": False, | ||
| "handoff_to": [], | ||
| "handoff_from": [], | ||
| }, | ||
| { | ||
| "role_id": "lead-vocal", | ||
| "is_active": False, | ||
| "handoff_to": [], | ||
| "handoff_from": [], | ||
| }, | ||
| ] | ||
| ) | ||
|
|
||
| topology: SectionRoleTopology = { | ||
| "section_id": section_id, | ||
| "active_roles": active_roles, | ||
| "part_graph": part_graph, | ||
| } | ||
| topologies.append(topology) | ||
|
|
||
| return { | ||
| "topologies": topologies, | ||
| "extraction_notes": "Extracted roles and computed handoffs.", | ||
| } | ||
Oops, something went wrong.
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.