Cubase-MCP-GAJ3T.MusicGen.R.../tests/integration/test_riffer_files.py

93 lines
3.4 KiB
Python

"""Retained generated originals: native XML read-back is not plugin load acceptance."""
from pathlib import Path
import pytest
from riff_groove_builder.articulations import compile_score
from riff_groove_builder.formats.agp import validate_riffer_file, write_riffer
from riff_groove_builder.profiles import load_profile_registry
from riff_groove_builder.schemas import (
ControlChangeEvent,
NoteOffEvent,
Part,
ProfileSelection,
Score,
)
ROOT = Path(__file__).resolve().parents[2]
pytestmark = pytest.mark.integration
@pytest.mark.parametrize("part", ["lead", "bass"])
def test_generated_original_fixture_and_retained_native_evidence(part: Part) -> None:
identifier = "ample.ame.4.0.1.riffer.v1" if part == "lead" else "ample.amr.4.1.0.riffer.v1"
profile = load_profile_registry().select([part], ProfileSelection(**{part: identifier}))[part]
low, high = (36, 84) if part == "lead" else (35, 74)
score = Score.model_validate(
{
"intent": {
"description": "Original native fixture verification.",
"parts": [part],
"tempo_bpm": 123.5,
"bars": 1,
"time_signature": {"numerator": 4, "denominator": 4},
"key": "C minor",
"seed": 17,
},
"start": {"numerator": 0},
"end": {"numerator": 4},
"tracks": [
{
"part": part,
"notes": [
{
"kind": "pitched",
"part": part,
"pitch": pitch,
"start": {"numerator": start},
"duration": {"numerator": 1},
"intensity": intensity,
"articulation": technique,
}
for pitch, start, intensity, technique in (
(low, 0, 0.0, "normal"),
(high, 0, 1.0, "normal"),
(low + 2, 2, 0.5, "palm_mute"),
)
],
}
],
}
)
plan = compile_score(score, {part: profile})
for tick, value in ((0, 0), (960, 120), (2880, 0)):
plan.tracks[0].events.append(
ControlChangeEvent(
tick=tick,
part=part,
channel=profile.channel,
priority=10,
sequence=100 + tick,
controller=1,
value=value,
)
)
plan.tracks[0].events.sort(key=lambda e: e.ordering_key)
for event in plan.tracks[0].events:
if isinstance(event, NoteOffEvent) and event.role == "musical_note":
event.velocity = 45
fixture = (
ROOT / "tests" / "fixtures" / "riffer" / f"original-{part}.{profile.summary.native_format}"
)
original = validate_riffer_file(fixture, plan, part, profile)
output = ROOT / ".test-artifacts" / "native-riffer-evidence-v1"
output.mkdir(parents=True, exist_ok=True)
path = output / fixture.name
if not path.exists():
write_riffer(path, plan, part, profile)
saved = validate_riffer_file(path, plan, part, profile)
assert saved == original
assert path.read_bytes() == fixture.read_bytes()
assert len(saved.notes) == 3 and len(saved.cc1) == 3