@@ -10,6 +10,23 @@ from generator.playback import PlaybackUnavailable, compile_timeline, generate_t
|
||||
from tests.test_musicxml import notes, parse, xml_note, xml_score
|
||||
|
||||
class PlaybackTests(unittest.TestCase):
|
||||
def test_grace_steals_accumulate_at_both_ends_of_a_donor(self):
|
||||
grace = '<note><grace {}/><pitch><step>{}</step><octave>4</octave></pitch><type>eighth</type></note>'
|
||||
content = grace.format('steal-time-following="25"', 'D') + xml_note(duration=2, kind='half') + grace.format('steal-time-previous="25"', 'E') + xml_note('F', 2, 'half')
|
||||
result = compile_timeline(parse(xml_score(content)))
|
||||
self.assertEqual([(fraction(e['pitch']), fraction(e['onset']), fraction(e['duration'])) for e in result['events']], [(62, 0, Fraction(1, 2)), (60, Fraction(1, 2), 1), (64, Fraction(3, 2), Fraction(1, 2)), (65, 2, 2)])
|
||||
for percent in (50, 60):
|
||||
with self.subTest(percent=percent), self.assertRaisesRegex(PlaybackUnavailable, 'grace timing consumes'):
|
||||
compile_timeline(parse(xml_score(content.replace('"25"', f'"{percent}"'))))
|
||||
chord = content.replace(xml_note(duration=2, kind='half'), xml_note(duration=2, kind='half') + xml_note('G', 1, 'quarter', prefix='<chord/>'))
|
||||
with self.assertRaisesRegex(PlaybackUnavailable, 'chord tone'):
|
||||
compile_timeline(parse(xml_score(chord)))
|
||||
def test_grace_previous_and_make_time_preserve_their_timing(self):
|
||||
for mode, expected, total in [('steal-time-previous="25"', [(0, Fraction(3, 2)), (Fraction(3, 2), Fraction(1, 2)), (2, 2)], 4), ('make-time="1"', [(0, 2), (2, 1), (3, 2)], 5)]:
|
||||
grace = f'<note><grace {mode}/><pitch><step>D</step><octave>4</octave></pitch><type>eighth</type></note>'
|
||||
result = compile_timeline(parse(xml_score(xml_note(duration=2, kind='half') + grace + xml_note('E', 2, 'half'))))
|
||||
self.assertEqual([(fraction(e['onset']), fraction(e['duration'])) for e in result['events']], expected)
|
||||
self.assertEqual(fraction(result['duration']), total)
|
||||
def test_chords_and_trailing_rest(self):
|
||||
document = parse(xml_score(xml_note(duration=2, kind='half') + xml_note('E', 1, 'quarter', prefix='<chord/>') + '<note><rest/><duration>2</duration><type>half</type></note>'))
|
||||
result = compile_timeline(document)
|
||||
|
||||
Reference in New Issue
Block a user