Music XML
ci / checks (push) Successful in 42m24s

This commit is contained in:
khodowany
2026-09-10 22:01:18 -05:00
parent ea4e0bbba1
commit f84717990b
47 changed files with 16739 additions and 8391 deletions
+10 -8
View File
@@ -2,7 +2,8 @@ from __future__ import annotations
from pathlib import Path
from generator.score import copy_source_voice, load_json, make_arranged_document, make_measure, slugify, source_staff, write_json
from generator.score import copy_source_voice, make_arranged_document, make_measure, reidentify, slugify, source_staff, write_json
from generator.musicxml import load_musicxml
from generator.transposition import TARGET_KEYS, transpose_document
@@ -19,10 +20,10 @@ def practice_document(document: dict) -> dict:
measure,
voice["notes"],
section_label=str(measure.get("section_label", "")),
tuplets=voice["tuplets"],
)
output_measure["voices"][0]["id"] = str(voice.get("id", output_measure["voices"][0]["id"]))
measures.append(output_measure)
tuplets = reidentify(measures, staff.get('tuplets', []))
return make_arranged_document(
document,
staff,
@@ -31,15 +32,17 @@ def practice_document(document: dict) -> dict:
role="vocal",
arrangement_part_type="practice",
measures=measures,
tuplets=tuplets,
octave_shifts=staff.get('octave_shifts', []),
)
def key_file_name(key: str) -> str:
return key.lower().replace("#", "sharp").replace("b", "b") + ".json"
return slugify(key.replace("#", "sharp")) + ".json"
def generate_chord_practice(source_path: Path, source_root: Path, output_dir: Path) -> int:
document = practice_document(load_json(source_path))
document = practice_document(load_musicxml(source_path))
metadata = document.get("metadata", {})
key = str(metadata.get("key_signature", "C") if isinstance(metadata, dict) else "C")
relative = source_path.relative_to(source_root)
@@ -50,7 +53,7 @@ def generate_chord_practice(source_path: Path, source_root: Path, output_dir: Pa
def generate_melody_practice(source_path: Path, source_root: Path, output_dir: Path) -> int:
base_document = practice_document(load_json(source_path))
base_document = practice_document(load_musicxml(source_path))
relative = source_path.relative_to(source_root)
lesson_group = relative.parent.name
exercise_id = slugify(source_path.stem)
@@ -67,11 +70,10 @@ def generate_practice_scores(source_dir: Path, output_dir: Path) -> int:
count = 0
chord_root = source_dir / "chord"
if chord_root.exists():
for path in sorted(chord_root.rglob("*.json")):
for path in sorted(chord_root.rglob("*.musicxml")):
count += generate_chord_practice(path, chord_root, output_dir)
melody_root = source_dir / "melody"
if melody_root.exists():
for path in sorted(melody_root.rglob("*.json")):
for path in sorted(melody_root.rglob("*.musicxml")):
count += generate_melody_practice(path, melody_root, output_dir)
return count