fix(export): correct UltraStar BPM scaling, time axis linear mapping, and metadata
This commit is contained in:
@ -2,6 +2,8 @@
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from unmix.export.ultrastar import export_ultrastar, parse_ultrastar
|
||||
from unmix.schema.meta import MetaDocument, SourceFileInfo
|
||||
from unmix.schema.tempo import TempoAnchor, TempoDocument
|
||||
@ -56,8 +58,10 @@ def test_ultrastar_writer_and_reader(tmp_path: Path):
|
||||
content = txt_path.read_text(encoding="utf-8")
|
||||
assert "#TITLE:Test Song" in content
|
||||
assert "#ARTIST:Test Artist" in content
|
||||
assert "#BPM:480.00" in content # 120 * 4 = 480
|
||||
assert "#BPM:120.00" in content
|
||||
assert "#GAP:500" in content # 0.5s = 500 ms
|
||||
assert "#LANGUAGE:German" in content
|
||||
assert "stems/vocals.wav" not in content
|
||||
assert "E" in content
|
||||
|
||||
# 5. Parse back using parse_ultrastar
|
||||
@ -72,10 +76,82 @@ def test_ultrastar_writer_and_reader(tmp_path: Path):
|
||||
assert len(line1) == 2
|
||||
assert line1[0].text == "Hal-"
|
||||
assert line1[0].midi == 60.0
|
||||
assert line1[0].start_sec == pytest.approx(0.5, abs=0.02)
|
||||
assert line1[0].end_sec == pytest.approx(1.0, abs=0.02)
|
||||
|
||||
assert line1[1].text == "lo "
|
||||
assert line1[1].midi == 62.0
|
||||
assert line1[1].start_sec == pytest.approx(1.0, abs=0.02)
|
||||
assert line1[1].end_sec == pytest.approx(2.0, abs=0.02)
|
||||
|
||||
line2 = parsed.lines[1]
|
||||
assert len(line2) == 1
|
||||
assert line2[0].text == "Welt"
|
||||
assert line2[0].midi == 64.0
|
||||
assert line2[0].start_sec == pytest.approx(3.0, abs=0.02)
|
||||
assert line2[0].end_sec == pytest.approx(4.5, abs=0.02)
|
||||
|
||||
|
||||
def test_ultrastar_metadata_and_language_english(tmp_path: Path):
|
||||
song_dir = tmp_path / "song_pkg"
|
||||
song_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
meta = MetaDocument(
|
||||
title="Chasing Cars",
|
||||
artist="Snow Patrol",
|
||||
language="en",
|
||||
duration_sec=269.0,
|
||||
source_file=SourceFileInfo(
|
||||
filename="Chasing_Cars.mp3", path="/tmp/Chasing_Cars.mp3", sha256="abc", size_bytes=100
|
||||
),
|
||||
created_at="2026-11-02T10:00:00Z",
|
||||
)
|
||||
(song_dir / "meta.json").write_text(meta.model_dump_json(indent=2))
|
||||
|
||||
# Tempo anchor starting at 65.34s (reproducing Chasing Cars test scenario)
|
||||
tempo = TempoDocument(anchors=[TempoAnchor(sec=65.34, beat=0.0, bpm=104.0)])
|
||||
(song_dir / "tempo.json").write_text(tempo.model_dump_json(indent=2))
|
||||
|
||||
# Vocals starting at 7.08s, ending at 258.7s
|
||||
vocals = VocalsDocument(
|
||||
lines=[
|
||||
VocalLine(
|
||||
start=7.08,
|
||||
end=10.0,
|
||||
syllables=[
|
||||
VocalSyllable(text="I'll ", start=7.08, end=8.0, midi=52.0),
|
||||
VocalSyllable(text="do ", start=8.0, end=9.0, midi=52.0),
|
||||
VocalSyllable(text="it ", start=9.0, end=10.0, midi=52.0),
|
||||
],
|
||||
),
|
||||
VocalLine(
|
||||
start=250.0,
|
||||
end=258.7,
|
||||
syllables=[
|
||||
VocalSyllable(text="cars", start=250.0, end=258.7, midi=50.0),
|
||||
],
|
||||
),
|
||||
]
|
||||
)
|
||||
(song_dir / "vocals.json").write_text(vocals.model_dump_json(indent=2))
|
||||
|
||||
txt_path = export_ultrastar(song_dir)
|
||||
content = txt_path.read_text(encoding="utf-8")
|
||||
|
||||
assert "#TITLE:Chasing Cars" in content
|
||||
assert "#ARTIST:Snow Patrol" in content
|
||||
assert "#LANGUAGE:English" in content
|
||||
assert "#MP3:Chasing_Cars.mp3" in content
|
||||
assert "#GAP:7080" in content
|
||||
assert "#BPM:104.00" in content
|
||||
|
||||
parsed = parse_ultrastar(txt_path)
|
||||
assert parsed.bpm == 104.0
|
||||
assert parsed.gap_ms == 7080.0
|
||||
# First note must be at 7.08s
|
||||
assert parsed.lines[0][0].start_sec == pytest.approx(7.08, abs=0.05)
|
||||
# Last note must be around 250.0s to 258.7s (NOT compressed to 52s!)
|
||||
# Quantization resolution at 104 BPM is 15 / 104 = 0.144s per tick
|
||||
last_note = parsed.lines[1][0]
|
||||
assert last_note.start_sec == pytest.approx(250.0, abs=0.15)
|
||||
assert last_note.end_sec == pytest.approx(258.7, abs=0.15)
|
||||
|
||||
Reference in New Issue
Block a user