Generation

This commit is contained in:
khodowany
2026-09-26 10:12:51 -05:00
parent 9fd5abd075
commit 1d5f3a9372
20 changed files with 681 additions and 155 deletions
+4 -3
View File
@@ -73,7 +73,7 @@ class PartGenerationTests(unittest.TestCase):
source = tests.test_musicxml.parse(tests.test_musicxml.xml_score(xml_harmony() + xml_harmony('F') + tests.test_musicxml.xml_note(duration=duration, kind=kind, extra='<dot/>' if duration == 3 else ''), attributes, implicit=implicit))
measure = source['staves'][0]['measures'][0]
plan = generator.accompaniment.plan_section([measure], tests.rhythm_fixtures.library(), electric=False)
events = generator.accompaniment.realize(measure, plan.acoustic[0], None)
events = generator.accompaniment.realize(measure, plan.acoustic_upper[0], None)
self.assertEqual(sum(generator.model.fraction(n['duration']) for n in events), duration)
sounding = [n for n in events if n['kind'] == 'note']
self.assertTrue(sounding)
@@ -115,7 +115,7 @@ class PartGenerationTests(unittest.TestCase):
self.assertEqual(prepared, before)
self.assertEqual(source, original)
def test_melody_written_pitch_rhythm_rests_and_cross_bar_ties_are_preserved(self):
content = xml_harmony() + xml_harmony('F', offset=3)
content = ''
content += tests.test_musicxml.xml_note(duration=2, kind='quarter', alter=1, extra='<tie type="start"/>')
content += tests.test_musicxml.xml_note(duration=6, kind='half', alter=1, extra='<dot/><tie type="stop"/><tie type="start"/>')
root = xml.etree.ElementTree.fromstring(tests.test_musicxml.xml_score(content, divisions=2))
@@ -142,7 +142,8 @@ class PartGenerationTests(unittest.TestCase):
self.assertEqual(generated[key], original[key])
self.assertEqual(len(generated['pitches']), len(original['pitches']))
for pitch, tone in zip(original['pitches'], generated['pitches']):
self.assertEqual(generator.model.pitch_number(tone), generator.model.pitch_number(pitch))
octave = 12 if part == 'electric' and builder is generator.arrange.generate.arrange_document else 0
self.assertEqual(generator.model.pitch_number(tone), generator.model.pitch_number(pitch) + octave)
self.assertEqual(tone['written'], pitch['written'])
for key in ('tie_from', 'tie_to'):
self.assertEqual(key in tone, key in pitch)