+3
-12
@@ -8,14 +8,12 @@ from generator.score import load_json, measure_notes
|
||||
from generator.transposition import TARGET_KEYS
|
||||
from generator.model import fraction, pitch_name
|
||||
|
||||
|
||||
def _arranged_staff(document: dict[str, Any]) -> dict[str, Any]:
|
||||
staves = document.get("staves")
|
||||
if not isinstance(staves, list) or not staves or not isinstance(staves[0], dict):
|
||||
raise ValueError("generated score document must contain an arranged staff")
|
||||
return staves[0]
|
||||
|
||||
|
||||
def _measure_summary(staff: dict[str, Any], measure: dict[str, Any], measure_number: int) -> dict[str, Any]:
|
||||
notes = measure_notes(measure)
|
||||
summary: dict[str, Any] = {
|
||||
@@ -28,14 +26,13 @@ def _measure_summary(staff: dict[str, Any], measure: dict[str, Any], measure_num
|
||||
if staff.get("arrangement_part_type") == "vocal":
|
||||
summary["vocal_skeleton"] = [
|
||||
f'{fraction(note["onset"])}+{fraction(note["duration"])} '
|
||||
+ note['written']['type'] + '.'*note['written'].get('dots',0)
|
||||
+ ' ' + note['kind'] + ' ' + ','.join(pitch_name(p)+str(p['octave']) for p in note['pitches'])
|
||||
+ ' ' + note.get('lyric','')
|
||||
+ note['written']['type'] + '.' * note['written'].get('dots', 0)
|
||||
+ ' ' + note['kind'] + ' ' + ','.join(pitch_name(p) + str(p['octave']) for p in note['pitches'])
|
||||
+ ' ' + note.get('lyric', '')
|
||||
for note in notes
|
||||
]
|
||||
return summary
|
||||
|
||||
|
||||
def performance_document_summary(document: dict[str, Any]) -> dict[str, Any]:
|
||||
metadata = document.get("metadata")
|
||||
if not isinstance(metadata, dict):
|
||||
@@ -63,14 +60,12 @@ def performance_document_summary(document: dict[str, Any]) -> dict[str, Any]:
|
||||
"measures": measure_summaries,
|
||||
}
|
||||
|
||||
|
||||
def performance_tree_summary(root: Path) -> dict[str, Any]:
|
||||
return {
|
||||
path.name: performance_document_summary(load_json(path))
|
||||
for path in sorted(root.glob("*.json"))
|
||||
}
|
||||
|
||||
|
||||
def validate_expected_performance_summary(expected_path: Path, generated_songs_dir: Path) -> None:
|
||||
if not expected_path.exists():
|
||||
raise ValueError(f"missing generator compatibility summary: {expected_path}")
|
||||
@@ -79,20 +74,17 @@ def validate_expected_performance_summary(expected_path: Path, generated_songs_d
|
||||
actual = performance_tree_summary(generated_songs_dir)
|
||||
if actual == expected:
|
||||
return
|
||||
|
||||
expected_names = set(expected.keys()) if isinstance(expected, dict) else set()
|
||||
actual_names = set(actual.keys())
|
||||
missing = sorted(expected_names - actual_names)
|
||||
extra = sorted(actual_names - expected_names)
|
||||
if missing or extra:
|
||||
raise ValueError(f"performance generator drift: missing={missing}, extra={extra}")
|
||||
|
||||
for name in sorted(actual_names):
|
||||
if actual[name] != expected[name]:
|
||||
raise ValueError(f"performance generator drift in {name}; update generator logic or refresh the expected summary intentionally")
|
||||
raise ValueError("performance generator drift")
|
||||
|
||||
|
||||
def validate_practice_variants(generated_practice_dir: Path) -> None:
|
||||
if not generated_practice_dir.exists():
|
||||
return
|
||||
@@ -105,7 +97,6 @@ def validate_practice_variants(generated_practice_dir: Path) -> None:
|
||||
continue
|
||||
if json_names != expected_names:
|
||||
raise ValueError(f"melody practice generator drift in {exercise_dir}: expected {sorted(expected_names)}, found {sorted(json_names)}")
|
||||
|
||||
chord_root = generated_practice_dir / "chord"
|
||||
if chord_root.exists():
|
||||
for exercise_dir in sorted(path for path in chord_root.rglob("*") if path.is_dir()):
|
||||
|
||||
Reference in New Issue
Block a user