class Test(XMLTestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_single_syllabic(self): xml_path = path.parent.joinpath(path.stem + '_single_syllabic.xml') sf = SimpleFormat(quarter_durations=4) sf.chords[0].add_lyric('one', syllabic='single') sf.to_stream_voice().add_to_score(self.score) self.score.write(xml_path) self.assertCompareFiles(xml_path) def test_multi_syllabic(self): xml_path = path.parent.joinpath(path.stem + '_multi_syllabic.xml') sf = SimpleFormat(quarter_durations=[1, 1, 1, 1]) sf.chords[0].add_lyric('non', syllabic='begin') sf.chords[1].add_lyric('syl', syllabic='middle') sf.chords[2].add_lyric('la', syllabic='middle') sf.chords[3].add_lyric('bic', syllabic='end') sf.to_stream_voice().add_to_score(self.score) self.score.write(xml_path) self.assertCompareFiles(xml_path) def test_extend(self): xml_path = path.parent.joinpath(path.stem + '_extend.xml') sf = SimpleFormat(quarter_durations=[1, 1, 1, 1]) sf.chords[0].add_lyric('one', syllabic='single', extend='start') # sf.chords[1].add_lyric(extend='continue') sf.chords[3].add_lyric('two', syllabic='single') sf.to_stream_voice().add_to_score(self.score) self.score.finish() partwise = self.score.to_partwise() partwise.write(xml_path) self.assertCompareFiles(xml_path) def test_melismatic(self): xml_path = path.parent.joinpath(path.stem + '_melismatic.xml') sf = SimpleFormat(quarter_durations=[0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1]) sf.chords[0].add_lyric('mar', syllabic='begin') sf.chords[3].add_lyric('a', syllabic='middle') sf.chords[-1].add_lyric('thon', syllabic='end') sf.to_stream_voice().add_to_score(self.score) self.score.finish() partwise = self.score.to_partwise() partwise.write(xml_path) self.assertCompareFiles(xml_path) def test_simple(self): xml_path = path.parent.joinpath(path.stem + '_simple.xml') sf = SimpleFormat(quarter_durations=[0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1]) sf.chords[0].add_lyric(1) sf.chords[3].add_lyric(2) sf.chords[-1].add_lyric(3) sf.to_stream_voice().add_to_score(self.score) self.score.finish() partwise = self.score.to_partwise() partwise.write(xml_path) self.assertCompareFiles(xml_path)
def generate_score(modules): score = TreeScoreTimewise() for index, module in enumerate(modules): module.get_simple_format( layer=module.number_of_layers ).to_stream_voice().add_to_score(score=score, part_number=index + 1) score.finish() partwise = score.to_partwise() return partwise
class Test(TestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_1(self): sf = SimpleFormat() for clef in ALL_CLEFS: if clef not in [SUPER_HIGH_TREBLE_CLEF, SUPER_LOW_BASS_CLEF]: for midi in clef.optimal_range: if not midi: if clef.optimal_range.index(midi) == 0: midi = G(0) else: midi = C(8) sf.add_chord(TreeChord(quarter_duration=2, midis=[midi])) sf.chords[-2].add_clef(clef) xml = path + '_test_1.xml' sf.to_stream_voice().add_to_score(self.score) self.score.finish() self.score.to_partwise() self.score.write(xml)
class Test(TestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_1(self): sf = SimpleFormat( quarter_durations=[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10]) v = sf.to_stream_voice(1) v.add_to_score(self.score) self.score.finish() partwise = self.score.to_partwise() result_path = path + '_test_1' partwise.write(path=result_path) TestScore().assert_template(result_path=result_path)
class Test(TestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() sf = SimpleFormat(quarter_durations=30 * [4]) v = sf.to_stream_voice(1) v.add_to_score(self.score) def test_1(self): self.score.page_style.orientation = 'landscape' for index, measure in enumerate( self.score.get_children_by_type(TreeMeasure)): if index % 4 == 0: measure.add_system_break() result_path = path + '_test_1' self.score.finish() partwise = self.score.to_partwise() partwise.write(path=result_path) # self.score.write(path=result_path) TestScore().assert_template(result_path=result_path)
class Test(TestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() self.score.page_style.format = 'portrait' def test_1(self): sf = SimpleFormat(quarter_durations=(1.5, 0.5, 1.5)) v = sf.to_stream_voice(1) self.score.set_time_signatures(times={1: (7, 8)}) v.add_to_score(self.score) xml_path = path + '_test_1.xml' self.score.finish() self.score.to_partwise() self.score.write(xml_path) TestScore().assert_template(xml_path) def test_2(self): sf = SimpleFormat(quarter_durations=(0.25, 0.25)) v = sf.to_stream_voice(1) v.add_to_score(self.score) xml_path = path + '_test_2.xml' self.score.finish() self.score.to_partwise() self.score.write(xml_path) TestScore().assert_template(xml_path) def test_3(self): sf = SimpleFormat(quarter_durations=(0.25, 0.125, 0.125, 0.25, 0.25)) v = sf.to_stream_voice(1) v.add_to_score(self.score) xml_path = path + '_test_3.xml' self.score.finish() self.score.to_partwise() self.score.write(xml_path) # TestScore().assert_template(xml_path) def test_iter_permutations(self): input_list = [1, 2, 3] actual = list(permutations(input_list)) expected = [(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)] self.assertEqual(expected, actual) def test_iter_permutations_duplicates(self): input_list = [1, 1, 2] actual = list(dict.fromkeys(list(permutations(input_list)))) expected = [(1, 1, 2), (1, 2, 1), (2, 1, 1)] self.assertEqual(expected, actual) def test_32_groups(self): actual = _generate_test_note_groups(32) expected = {1: [[1, 1, 1, 1, 1, 1, 1, 1]], 2: [[2, 1, 1, 1, 1, 1, 1], [1, 2, 1, 1, 1, 1, 1], [1, 1, 2, 1, 1, 1, 1], [1, 1, 1, 2, 1, 1, 1], [1, 1, 1, 1, 2, 1, 1], [1, 1, 1, 1, 1, 2, 1], [1, 1, 1, 1, 1, 1, 2]], 3: [[2, 2, 1, 1, 1, 1], [2, 1, 2, 1, 1, 1], [2, 1, 1, 2, 1, 1], [2, 1, 1, 1, 2, 1], [2, 1, 1, 1, 1, 2], [1, 2, 2, 1, 1, 1], [1, 2, 1, 2, 1, 1], [1, 2, 1, 1, 2, 1], [1, 2, 1, 1, 1, 2], [1, 1, 2, 2, 1, 1], [1, 1, 2, 1, 2, 1], [1, 1, 2, 1, 1, 2], [1, 1, 1, 2, 2, 1], [1, 1, 1, 2, 1, 2], [1, 1, 1, 1, 2, 2]], 4: [[2, 2, 3, 1], [2, 2, 1, 3], [2, 3, 2, 1], [2, 3, 1, 2], [2, 1, 2, 3], [2, 1, 3, 2], [3, 2, 2, 1], [3, 2, 1, 2], [3, 1, 2, 2], [1, 2, 2, 3], [1, 2, 3, 2], [1, 3, 2, 2]], 5: [[2, 3, 1, 1, 1], [2, 1, 3, 1, 1], [2, 1, 1, 3, 1], [2, 1, 1, 1, 3], [3, 2, 1, 1, 1], [3, 1, 2, 1, 1], [3, 1, 1, 2, 1], [3, 1, 1, 1, 2], [1, 2, 3, 1, 1], [1, 2, 1, 3, 1], [1, 2, 1, 1, 3], [1, 3, 2, 1, 1], [1, 3, 1, 2, 1], [1, 3, 1, 1, 2], [1, 1, 2, 3, 1], [1, 1, 2, 1, 3], [1, 1, 3, 2, 1], [1, 1, 3, 1, 2], [1, 1, 1, 2, 3], [1, 1, 1, 3, 2]], 6: [[2, 4, 1, 1], [2, 1, 4, 1], [2, 1, 1, 4], [4, 2, 1, 1], [4, 1, 2, 1], [4, 1, 1, 2], [1, 2, 4, 1], [1, 2, 1, 4], [1, 4, 2, 1], [1, 4, 1, 2], [1, 1, 2, 4], [1, 1, 4, 2]], 7: [[2, 5, 1], [2, 1, 5], [5, 2, 1], [5, 1, 2], [1, 2, 5], [1, 5, 2]], 8: [[3, 1, 1, 1, 1, 1], [1, 3, 1, 1, 1, 1], [1, 1, 3, 1, 1, 1], [1, 1, 1, 3, 1, 1], [1, 1, 1, 1, 3, 1], [1, 1, 1, 1, 1, 3]], 9: [[3, 3, 1, 1], [3, 1, 3, 1], [3, 1, 1, 3], [1, 3, 3, 1], [1, 3, 1, 3], [1, 1, 3, 3]], 10: [[3, 4, 1], [3, 1, 4], [4, 3, 1], [4, 1, 3], [1, 3, 4], [1, 4, 3]], 11: [[4, 1, 1, 1, 1], [1, 4, 1, 1, 1], [1, 1, 4, 1, 1], [1, 1, 1, 4, 1], [1, 1, 1, 1, 4]], 12: [[5, 1, 1, 1], [1, 5, 1, 1], [1, 1, 5, 1], [1, 1, 1, 5]], 13: [[6, 1, 1], [1, 6, 1], [1, 1, 6]], 14: [[7, 1], [1, 7]], 15: [[3, 3, 2], [3, 2, 3], [2, 3, 3]] } self.assertEqual(expected, actual) def test_get_32_groups(self): keys = [1, 2] actual = get_32_groups(keys) expected = [[1, 1, 1, 1, 1, 1, 1, 1], [2, 1, 1, 1, 1, 1, 1], [1, 2, 1, 1, 1, 1, 1], [1, 1, 2, 1, 1, 1, 1], [1, 1, 1, 2, 1, 1, 1], [1, 1, 1, 1, 2, 1, 1], [1, 1, 1, 1, 1, 2, 1], [1, 1, 1, 1, 1, 1, 2]] self.assertEqual(expected, actual) def test_convert_groups(self): keys = [1, 2] actual = convert_note_groups_to_quarter_durations(get_32_groups(keys), 32) expected = [[0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125], [0.25, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125], [0.125, 0.25, 0.125, 0.125, 0.125, 0.125, 0.125], [0.125, 0.125, 0.25, 0.125, 0.125, 0.125, 0.125], [0.125, 0.125, 0.125, 0.25, 0.125, 0.125, 0.125], [0.125, 0.125, 0.125, 0.125, 0.25, 0.125, 0.125], [0.125, 0.125, 0.125, 0.125, 0.125, 0.25, 0.125], [0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.25]] self.assertEqual(expected, actual) def test_set_break_beam(self): sf = SimpleFormat(quarter_durations=[4]) sf.to_stream_voice().add_to_score(self.score) self.score.break_beam_32 = True actual = self.score.break_beam_32 self.assertTrue(actual) part = self.score.get_measure(1).get_part(1) actual = part.break_beam_32 self.assertTrue(actual) actual = self.score.get_measure(1).get_part(1).tree_part_staves[1].tree_part_voices[1].break_beam_32 self.assertTrue(actual) def test_32_first_group(self): self.score.set_time_signatures(times={1: (1, 4)}) self.score.break_beam_32 = True keys = [1] all_durations = flatten(convert_note_groups_to_quarter_durations(get_32_groups(keys), 32)) sf = SimpleFormat(quarter_durations=all_durations) sf.to_stream_voice().add_to_score(self.score) xml_path = path + '_32_first_group.xml' self.score.finish() self.score.to_partwise() self.score.write(xml_path) TestScore().assert_template(xml_path) def test_all_possible_32ths(self): self.score.break_beam_32 = True self.score.set_time_signatures(times={1: (1, 4)}) keys = list(range(1, 16)) all_durations = flatten(convert_note_groups_to_quarter_durations(get_32_groups(keys), 32)) sf = SimpleFormat(quarter_durations=all_durations) sf.to_stream_voice().add_to_score(self.score) xml_path = path + '_all_possible_32s.xml' self.score.finish() self.score.to_partwise() self.score.write(xml_path) TestScore().assert_template(xml_path) def test_beam_break_with_quantization(self): quarter_durations = [Fraction(2, 1), Fraction(1, 1), Fraction(3, 2), Fraction(5, 2), Fraction(1, 1), Fraction(2, 1), Fraction(3, 1), Fraction(1, 1), Fraction(3, 2), Fraction(1, 2), Fraction(4, 15), Fraction(2, 5), Fraction(1, 3), Fraction(8, 15), Fraction(8, 45), Fraction(2, 9), Fraction(4, 15), Fraction(16, 75), Fraction(8, 25), Fraction(4, 15), Fraction(3, 5), Fraction(1, 2), Fraction(2, 5), Fraction(1, 2), Fraction(1, 3), Fraction(2, 5), Fraction(4, 15), Fraction(16, 75), Fraction(4, 15), Fraction(8, 25), Fraction(8, 15), Fraction(2, 3)] self.score.break_beam_32 = True self.score.forbidden_divisions = [5, 6, 7] sf = SimpleFormat(quarter_durations=quarter_durations) sf.to_stream_voice().add_to_score(self.score) xml_path = path + '_beam_break_with_quantization.xml' self.score.finish() self.score.to_partwise() self.score.write(xml_path) TestScore().assert_template(xml_path) def test_all_possible_16ths(self): self.score.set_time_signatures(times={1: (1, 4)}) keys = list(range(1, 5)) all_durations = flatten(convert_note_groups_to_quarter_durations(get_16_groups(keys), 16)) sf = SimpleFormat(quarter_durations=all_durations) sf.to_stream_voice().add_to_score(self.score) xml_path = path + '_all_possible_16ths.xml' self.score.finish() self.score.to_partwise() self.score.write(xml_path) TestScore().assert_template(xml_path)