@@ -2,10 +2,21 @@ from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from generator.arrange.generate import arrange_document
|
||||
from generator.score import normalize_score_document
|
||||
|
||||
|
||||
class CompactScoreJsonTests(unittest.TestCase):
|
||||
def chord_symbols(self, measure: dict) -> list[str]:
|
||||
return [
|
||||
note["chord_symbol"]
|
||||
for note in measure["voices"][0]["notes"]
|
||||
if isinstance(note.get("chord_symbol"), str) and note["chord_symbol"]
|
||||
]
|
||||
|
||||
def measure_notes(self, measure: dict) -> list[dict]:
|
||||
return measure["voices"][0]["notes"]
|
||||
|
||||
def test_compact_json_normalizes_notation_tokens(self) -> None:
|
||||
document = normalize_score_document({
|
||||
"title": "Compact Tune",
|
||||
@@ -33,6 +44,49 @@ class CompactScoreJsonTests(unittest.TestCase):
|
||||
self.assertTrue(first_note["tie_to_next"])
|
||||
self.assertTrue(second_measure_first_note["tie_from_previous"])
|
||||
|
||||
def test_compact_json_marks_optional_chords(self) -> None:
|
||||
document = normalize_score_document({
|
||||
"title": "Optional Turnaround",
|
||||
"key": "Eb",
|
||||
"time": "4/4",
|
||||
"measures": [
|
||||
"[(F-7)] r:2 [(Bb7)] r:2",
|
||||
],
|
||||
})
|
||||
|
||||
notes = document["staves"][0]["measures"][0]["voices"][0]["notes"]
|
||||
|
||||
self.assertEqual(notes[0]["chord_symbol"], "F-7")
|
||||
self.assertTrue(notes[0]["chord_optional"])
|
||||
self.assertEqual(notes[1]["chord_symbol"], "Bb7")
|
||||
self.assertTrue(notes[1]["chord_optional"])
|
||||
|
||||
def test_arrangements_omit_optional_turnaround_from_final_ending(self) -> None:
|
||||
document = normalize_score_document({
|
||||
"title": "Optional Turnaround",
|
||||
"key": "Eb",
|
||||
"time": "4/4",
|
||||
"measures": [
|
||||
"[Ebmaj7] C4:1",
|
||||
"[Ab7] D4:1",
|
||||
"[Ebmaj7] E4:1",
|
||||
"[(F-7)] r:2 [(Bb7)] r:2",
|
||||
],
|
||||
})
|
||||
|
||||
for part_type in ("acoustic", "electric", "vocal"):
|
||||
arranged = arrange_document(document, part_type)
|
||||
measures = arranged["staves"][0]["measures"]
|
||||
non_final_turnaround = measures[7]
|
||||
final_turnaround = measures[-1]
|
||||
|
||||
self.assertEqual(self.chord_symbols(non_final_turnaround), ["F-7", "Bb7"])
|
||||
self.assertEqual(self.chord_symbols(final_turnaround), [])
|
||||
self.assertFalse(any("chord_optional" in note for measure in measures for note in self.measure_notes(measure)))
|
||||
|
||||
if part_type in {"acoustic", "electric"}:
|
||||
self.assertTrue(all(note["kind"] == "rest" for note in self.measure_notes(final_turnaround)))
|
||||
|
||||
def test_compact_json_normalizes_pitch_groups_and_tuplets(self) -> None:
|
||||
document = normalize_score_document({
|
||||
"title": "Practice",
|
||||
|
||||
Reference in New Issue
Block a user