class Test(XMLTestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_1(self): simple_format = SimpleFormat(quarter_durations=4) simple_format.to_stream_voice().add_to_score(self.score) self.score.add_measure() m2 = self.score.get_measure(2) self.score.finish() actual = m2.to_string() expected = """<measure number="2"> <part id="p1"> <attributes> <divisions>1</divisions> </attributes> <note> <rest/> <duration>4</duration> <voice>1</voice> <type>whole</type> </note> </part> </measure> """ self.assertEqual(expected, actual)
class TestTreeTimewise(TestCase): def setUp(self): self.score = TreeScoreTimewise() self.score.add_measure() self.score.add_part() def test_score(self): result_path = path + '_test_score' self.score.write(result_path) TestScore().assert_template(result_path=result_path) def test_add_note(self): self.score.add_chord(1, 1, TreeChord(0, 1)) self.score.add_chord(1, 1, TreeChord(0, quarter_duration=1)) self.score.add_chord(1, 1, TreeChord(61, quarter_duration=2)) self.score.finish() result_path = path + '_test_add_note' self.score.write(path=result_path) TestScore().assert_template(result_path=result_path) def test_add_chord(self): self.score.add_chord(1, 1, TreeChord((60, 61), quarter_duration=4)) self.score.finish() # print(self.score.to_string()) # self.score.write(path=path) def test_4(self): self.score.tuplet_line_width = 2.4 sf = SimpleFormat(quarter_durations=[0.2, 0.8]) sf.to_stream_voice().add_to_score(self.score) xml_path = path + '_test_4.xml' self.score.write(xml_path) TestScore().assert_template(result_path=xml_path)
class Test(TestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() self.score.add_measure(TreeMeasure(time=(1, 4))) def test_1(self): sf = SimpleFormat(quarter_durations=[1, 0, 1]) sf.chords[0].add_tie('start') sf.chords[1].add_tie('stop') v = sf.to_stream_voice(1) v.add_to_score(self.score) self.score.fill_with_rest() self.score.preliminary_adjoin_rests() self.score.add_beats() self.score.quantize() chord = self.score.get_measure(2).get_part(1).get_staff(1).get_voice( 1).chords[0] chord.remove_from_score() result_path = path + '_test_1' # with self.assertWarns(UserWarning): # self.score.write(path=result_path) self.score.write(path=result_path) TestScore().assert_template(result_path=result_path)
class Test(XMLTestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_1(self): self.score.add_measure() self.score.add_part() self.score.get_measure(1).get_part(1).add_chord( TreeChord(quarter_duration=4, midis=60)) xml_path = path + '_test_1.xml' self.score.write(path=xml_path) self.assertCompareFiles(xml_path) def test_2(self): self.score.add_measure() self.score.add_part() self.score.get_measure(1).get_part(1).add_chord(TreeChord( quarter_duration=4, midis=60), voice_number=2) xml_path = path + '_test_2.xml' self.score.write(path=xml_path) self.assertCompareFiles(xml_path) def test_3(self): self.score.add_measure() self.score.add_part() self.score.get_measure(1).get_part(1).add_chord(TreeChord( quarter_duration=4, midis=70), voice_number=2) self.score.get_measure(1).get_part(1).add_chord(TreeChord( quarter_duration=4, midis=60), voice_number=4) xml_path = path + '_test_3.xml' self.score.write(path=xml_path) self.assertCompareFiles(xml_path) def test_4(self): self.score.add_measure() self.score.add_part() self.score.get_measure(1).get_part(1).add_chord(TreeChord( quarter_duration=4, midis=70), staff_number=2) xml_path = path + '_test_4.xml' self.score.write(path=xml_path) self.assertCompareFiles(xml_path) def test_5(self): self.score.add_measure() self.score.add_part() self.score.get_measure(1).get_part(1).add_chord(TreeChord( quarter_duration=4, midis=60), staff_number=1) self.score.get_measure(1).get_part(1).add_chord(TreeChord( quarter_duration=4, midis=70), staff_number=2) xml_path = path + '_test_5.xml' self.score.write(path=xml_path) self.assertCompareFiles(xml_path)
class Test(TestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_1(self): self.score.add_measure() self.score.add_part() self.score.get_measure(1).get_part(1).add_metronome( beat_unit='quarter', per_minute=60, relative_y=15) result_path = path + '_test_1' self.score.write(path=result_path) TestScore().assert_template(result_path=result_path)
class Test(TestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_1(self): self.score.add_measure(TreeMeasure(time=(1, 4))) sf = SimpleFormat( quarter_durations=[Fraction(4, 6), Fraction(1, 6), Fraction(1, 6)]) v = sf.to_stream_voice(1) v.add_to_score(self.score) result_path = path + '_test_1' self.score.write(path=result_path) TestScore().assert_template(result_path=result_path)
class Test(XMLTestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() # # def test_(self): # # c = self.score.add_child(Credit(page=1)) # c.add_child(CreditType('title')) # c.add_child(CreditWords('TEST', default_x=598, default_y=1600, font_size=24, justify='center', valign='top')) # # c = self.score.add_child(Credit(page=1)) # c.add_child(CreditType('composer')) # c.add_child(CreditWords('me', default_x=1089, default_y=1550, font_size=12, justify='right', valign='top')) # # c = self.score.add_child(Credit(page=1)) # c.add_child(CreditType('arranger')) # c.add_child(CreditWords('TEST', default_x=1089, default_y=1500, font_size=12, justify='right', valign='top')) # # c = self.score.add_child(Credit(page=1)) # c.add_child(CreditType('subtitle')) # c.add_child(CreditWords('BLA', default_x=598, default_y=1550, font_size=18, justify='center', valign='top')) # # result_path = path + '_test_1' # # self.score.write(path=result_path) # TestScore().assert_template(result_path=result_path) def test_title_subtitle_composer(self): self.score.add_measure() self.score.add_part() xml_path = path.parent.joinpath(path.stem + '_title_subtitle_composer.xml') self.score.add_title("TITLE") self.score.add_subtitle("SUBTITLE") self.score.add_composer("blablabla 2019") self.score.write(path=xml_path) self.assertCompareFiles(xml_path) def test_page_number(self): sf = SimpleFormat(quarter_durations=[1000]) sf.to_stream_voice().add_to_score(self.score) xml_path = path.parent.joinpath(path.stem + '_page_number.xml') self.score.add_page_number(2) self.score.add_page_number(3) self.score.write(path=xml_path) self.assertCompareFiles(xml_path)
class Test(TestCase): def setUp(self): self.score = TreeScoreTimewise() self.score.add_part() def test_1(self): self.score.add_measure().time = (3, 4) self.score.add_measure().time = (2, 4) self.score.add_measure().time = (2, 4) self.score.add_measure().time = (2, 4) self.score.get_measure(4).time.force_show = True self.score.add_measure().time = (3, 8) self.score.finish() result_path = path + '_test_1' self.score.write(path=result_path) TestScore().assert_template(result_path=result_path)
class Test(TestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_1(self): simpleformat = SimpleFormat(midis=list(range(60, 68))) voice = simpleformat.to_stream_voice(2) self.score.add_part() self.score.add_measure() voice.add_to_score(self.score, 1) result_path = path + '_test_1' # self.score.accidental_mode = 'modern' self.score.write(result_path) TestScore().assert_template(result_path=result_path) def test_2(self): simpleformat = SimpleFormat(midis=list(range(60, 68)), quarter_durations=[1.2] * 8) voice = simpleformat.to_stream_voice(1) self.score.add_part() self.score.add_measure() voice.add_to_score(self.score, 1) result_path = path + '_test_2' self.score.write(result_path) TestScore().assert_template(result_path=result_path) def test_3(self): sf = SimpleFormat(midis=[(60, 61, 67)], quarter_durations=7) voice = sf.to_stream_voice(1) voice.add_to_score(self.score, 1) result_path = path + '_test_3' self.score.write(result_path) TestScore().assert_template(result_path=result_path) def test_4(self): midis = list(range(60, 80)) sf = SimpleFormat(midis=midis) for chord in sf.chords: l = chord.add_child(Lyric()) l.add_child(Text(str(chord.midis[0].value))) voice = sf.to_stream_voice(1) voice.add_to_score(self.score, 1) result_path = path + '_test_4' self.score.write(result_path) TestScore().assert_template(result_path=result_path)
class Test(XMLTestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_1(self): instrument = TreeInstrument(name='banjo', abbreviation='bjo', number=2) instrument.standard_clefs = ALTO_CLEF sf = SimpleFormat(quarter_durations=[1, 2, 3, 1, 2, 3, 1, 2, 3]) score = TreeScoreTimewise() sf.to_stream_voice(2).add_to_score(score) sf.transpose(5) sf.to_stream_voice(1).add_to_score(score) score.get_score_parts()[0].instrument = instrument xml_path = path + '_test_1.xml' score.write(xml_path) self.assertCompareFiles(xml_path) def test_2(self): sf = SimpleFormat(quarter_durations=[1, 2, 3, 1, 2, 3, 1, 2, 3], midis=9 * [60 - 5]) score = TreeScoreTimewise() for part_number in range(1, 5): sf.to_stream_voice().add_to_score(score, part_number=part_number) score_parts = score.get_score_parts() score_parts[0].instrument = Violin(1) score_parts[1].instrument = Violin(1) score_parts[2].instrument = Viola() score_parts[3].instrument = Cello() xml_path = path + '_test_2.xml' score.write(xml_path) self.assertCompareFiles(xml_path) def test_3(self): self.score.add_instrument(Violin(1)) self.score.add_instrument(Violin(2)) self.score.add_instrument(Piano()) xml_path = path + '_test_3.xml' self.score.add_measure() self.score.write(xml_path) self.assertCompareFiles(xml_path)
def test_split_quantize(self): s = TreeScoreTimewise() m = TreeMeasure(time=(3, 4)) s.add_measure(m) s.add_part() # m.add_child(p) chord1 = s.add_chord(1, 1, TreeChord((71, 72), quarter_duration=1.3)) l1 = Lyric() l1.add_child(Text('bla')) chord1.add_child(l1) s.add_chord(1, 1, TreeChord((60, 63, 65), quarter_duration=0.6)) s.add_chord(1, 1, TreeChord(60, quarter_duration=1.1)) s.finish() # print(s.to_string()) s.write(path=path) result = '''<part id="one">
class Test(TestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_1(self): self.score.add_measure(TreeMeasure(time=(5, 4))) sf = SimpleFormat(quarter_durations=[5]) v = sf.to_stream_voice(1) v.add_to_score(self.score) self.score.finish() output = [] for measure in self.score.get_children_by_type(TreeMeasure): for part in measure.get_children_by_type(TreePart): for beat in part.get_beats(): output.append([ch.quarter_duration for ch in beat.chords]) result = [[Fraction(3, 1)], [], [], [Fraction(2, 1)], []] self.assertEqual(output, result)
class Test(TestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_1(self): self.score.add_measure() self.score.add_part() self.score.add_chord(1, 1, TreeChord()) self.score.add_chord(1, 1, TreeChord(quarter_duration=0)) result_path = path + '_test_1' self.score.write(path=result_path) TestScore().assert_template(result_path=result_path) def test_2(self): sf = SimpleFormat(quarter_durations=[0.75, 0.25, 1, 0.5, 4]) sf.chords[1].set_manual_type('16th') sf.chords[1].quarter_duration = 0 sf.chords[0].set_manual_type('eighth') sf.chords[0].set_manual_dots(1) sf.chords[0].quarter_duration = 0 sf.chords[2].set_manual_type('quarter') sf.chords[2].quarter_duration = 0 sf.chords[3].set_manual_type('eighth') sf.chords[3].quarter_duration = 0 sf.to_stream_voice().add_to_score(self.score) xml_path = path + 'test_2.xml' self.score.write(xml_path) TestScore().assert_template(result_path=xml_path) def test_3(self): sf = SimpleFormat(quarter_durations=[4]) sf.chords[0].add_grace_chords( [TreeChord(60), TreeChord(63), TreeChord(68)]) sf.chords[0].add_grace_chords( [TreeChord(61), TreeChord(66)], mode='post') sf.to_stream_voice().add_to_score(self.score) xml_path = path + 'test_3.xml' self.score.write(xml_path) TestScore().assert_template(result_path=xml_path)
class TestGrouping(TestCase): def setUp(self): self.score = TreeScoreTimewise() self.score.add_part() def test_grouping(self): self.make_measure(1, (3, 4)) self.make_measure(2, (6, 8)) # for measure in self.score.get_children_by_type(TreeMeasure): # measure.get_part(1).group_beams() self.score.finish() self.score.write(path=path) def make_measure(self, number, time_signature=(4, 4)): self.score.add_measure(TreeMeasure(time=time_signature)) for i in range(time_signature[0] * 8 // time_signature[1]): self.score.add_chord(number, 1, TreeChord(60, quarter_duration=0.5))
class Test(TestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_1(self): self.score.add_measure(TreeMeasure(time=(5, 8))) # sf = SimpleFormat(durations=[1.8, 0.2, 0.5]) sf = SimpleFormat(quarter_durations=[2.5]) v = sf.to_stream_voice(1) v.add_to_score(self.score) result_path = path + '_test_1' self.score.finish() self.score.write(path=result_path) TestScore().assert_template(result_path=result_path) def test_2(self): self.score.add_measure(TreeMeasure(time=(5, 8))) # sf = SimpleFormat(durations=[1.8, 0.2, 0.5]) sf = SimpleFormat(quarter_durations=[ Fraction(1, 7), Fraction(6, 7), Fraction(1, 14), Fraction(3, 14), Fraction(10, 14), Fraction(1, 2) ]) v = sf.to_stream_voice(1) v.add_to_score(self.score, part_number=1, first_measure=1) v = sf.to_stream_voice(1) v.add_to_score(self.score, part_number=2, first_measure=1) self.score.get_score_parts()[1].max_division = 7 result_path = path + '_test_2' self.score.finish() self.score.write(path=result_path) TestScore().assert_template(result_path=result_path)
class Test(TestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_1(self): simpleformat = SimpleFormat(quarter_durations=4) voice = simpleformat.to_stream_voice(2) self.score.add_part() self.score.add_measure() p = self.score.get_measure(1).get_part(1) remaining_chords = voice.add_to_part(p) result = '''<part id="p1"> <attributes> <divisions>1</divisions> </attributes> <note> <pitch> <step>B</step> <octave>4</octave> </pitch> <duration>4</duration> <voice>2</voice> <type>whole</type> </note> <backup> <duration>4</duration> </backup> <note> <rest/> <duration>4</duration> <voice>1</voice> <type>whole</type> </note> </part> ''' self.assertEqual(p.to_string(), result) self.assertEqual(remaining_chords, None) def test_2(self): simpleformat = SimpleFormat(quarter_durations=7) voice = simpleformat.to_stream_voice(2) self.score.add_part() self.score.add_measure() p = self.score.get_measure(1).get_part(1) remaining_chords = voice.add_to_part(p) result = '''<part id="p1"> <attributes> <divisions>1</divisions> </attributes> <note> <pitch> <step>B</step> <octave>4</octave> </pitch> <duration>4</duration> <tie type="start"/> <voice>2</voice> <type>whole</type> <notations> <tied number="1" type="start"/> </notations> </note> <backup> <duration>4</duration> </backup> <note> <rest/> <duration>4</duration> <voice>1</voice> <type>whole</type> </note> </part> ''' self.assertEqual(p.to_string(), result) chord = remaining_chords[0] self.assertEqual(chord.quarter_duration, 3) self.assertEqual(chord.get_children_by_type(Tie)[0].type, 'stop') def test_3(self): simpleformat = SimpleFormat(quarter_durations=3) voice = simpleformat.to_stream_voice(2) self.score.add_part() self.score.add_measure() p = self.score.get_measure(1).get_part(1) remaining_chords = voice.add_to_part(p) result = '''<part id="p1"> <attributes> <divisions>1</divisions> </attributes> <note> <pitch> <step>B</step> <octave>4</octave> </pitch> <duration>3</duration> <voice>2</voice> <type>half</type> <dot/> </note> <note> <rest/> <duration>1</duration> <voice>2</voice> <type>quarter</type> </note> <backup> <duration>4</duration> </backup> <note> <rest/> <duration>4</duration> <voice>1</voice> <type>whole</type> </note> </part> ''' self.assertEqual(p.to_string(), result) def test_4(self): simpleformat = SimpleFormat(quarter_durations=7, midis=0) voice = simpleformat.to_stream_voice(2) self.score.add_part() self.score.add_measure() p = self.score.get_measure(1).get_part(1) remaining_chords = voice.add_to_part(p) result = '''<part id="p1"> <attributes> <divisions>1</divisions> </attributes> <note> <rest/> <duration>4</duration> <voice>2</voice> <type>whole</type> </note> <backup> <duration>4</duration> </backup> <note> <rest/> <duration>4</duration> <voice>1</voice> <type>whole</type> </note> </part> ''' self.assertEqual(p.to_string(), result) self.assertEqual(remaining_chords[0].midis[0].value, 0) self.assertEqual(remaining_chords[0].get_children_by_type(Tie), []) def test_5(self): simpleformat = SimpleFormat(quarter_durations=3, midis=0) voice = simpleformat.to_stream_voice(2) self.score.add_part() self.score.add_measure() p = self.score.get_measure(1).get_part(1) voice.add_to_part(p) result = '''<part id="p1"> <attributes> <divisions>1</divisions> </attributes> <note> <rest/> <duration>4</duration> <voice>2</voice> <type>whole</type> </note> <backup> <duration>4</duration> </backup> <note> <rest/> <duration>4</duration> <voice>1</voice> <type>whole</type> </note> </part> ''' self.assertEqual(p.to_string(), result)
class Test(XMLTestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_1(self): measure = self.score.add_measure() self.score.add_part() chord = TreeChord(quarter_duration=4, midis=[60]) measure.get_part(1).add_chord(chord) measure.get_part(1).staves = 2 chord.staff_number = 1 xml_path = path + '_test_1.xml' self.score.write(xml_path) self.assertCompareFiles(xml_path) def test_2(self): measure = self.score.add_measure() self.score.add_part() chord = TreeChord(quarter_duration=4, midis=[60]) measure.get_part(1).add_chord(chord) chord.staff_number = 2 measure.get_part(1).staves = 2 xml_path = path + '_test_2.xml' self.score.write(xml_path) self.assertCompareFiles(xml_path) def test_3(self): sf = SimpleFormat(quarter_durations=[0.25, 2.25, 0.5, 1, 2, Fraction(1, 3), Fraction(4, 3), Fraction(1, 3), 1]) for index, chord in enumerate(sf.chords): if index in [1, 6]: chord.staff_number = 2 sf.to_stream_voice(1).add_to_score(self.score, part_number=1) all_parts = [part for m in self.score.get_children_by_type(TreeMeasure) for part in m.get_children_by_type(TreePart)] for part in all_parts: part.staves = 2 xml_path = path + '_test_3.xml' self.score.write(xml_path) self.assertCompareFiles(xml_path) def test_4(self): sf = SimpleFormat(4) sf.to_stream_voice(1).add_to_score(self.score, part_number=1) score_part = self.score.get_score_parts()[0] score_part.number_of_staves = 2 xml_path = path + '_test_4.xml' self.score.write(xml_path) self.assertCompareFiles(xml_path) def test_5(self): sf = SimpleFormat(4) sf.to_stream_voice(1).add_to_score(self.score, part_number=1) score_part = self.score.get_score_parts()[0] score_part.number_of_staves = 2 clef = BASS_CLEF.__deepcopy__() clef.number = 2 self.score.get_measure(1).get_part(1).add_clef(clef) xml_path = path + '_test_5.xml' self.score.write(xml_path) self.assertCompareFiles(xml_path) def test_6(self): r_sf = SimpleFormat(quarter_durations=[4]) l_sf = SimpleFormat(quarter_durations=[4], midis=[60]) r_sf.to_stream_voice().add_to_score(self.score, part_number=1, staff_number=1) l_sf.to_stream_voice().add_to_score(self.score, part_number=1, staff_number=2) xml_path = path + '_test_6.xml' self.score.write(xml_path) self.assertCompareFiles(xml_path) def test_7(self): r_sf = SimpleFormat( quarter_durations=[0.25, 2.25, 0.5, 1, 2, Fraction(1, 3), Fraction(4, 3), Fraction(1, 3), 1]) l_sf = SimpleFormat(quarter_durations=[4, 5], midis=[72, 75]) r_sf.to_stream_voice().add_to_score(self.score, part_number=1, staff_number=1) l_sf.to_stream_voice().add_to_score(self.score, part_number=1, staff_number=2) xml_path = path + '_test_7.xml' self.score.write(xml_path) self.assertCompareFiles(xml_path) def test_8(self): r_sf = SimpleFormat( quarter_durations=[0.25, 2.25, 0.5, 1, 2, Fraction(1, 3), Fraction(4, 3), Fraction(1, 3), 1]) l_sf = SimpleFormat(quarter_durations=[4, 5], midis=[50, 55]) r_sf.to_stream_voice().add_to_score(self.score, part_number=1, staff_number=1) l_sf.to_stream_voice().add_to_score(self.score, part_number=1, staff_number=2) clef = BASS_CLEF.__deepcopy__() clef.number = 2 self.score.get_measure(1).get_part(1).add_clef(clef) xml_path = path + '_test_8.xml' self.score.write(xml_path) self.assertCompareFiles(xml_path) def test_9(self): r_sf = SimpleFormat( quarter_durations=[0.25, 2.25, 0.5, 1, 2, Fraction(1, 3), Fraction(4, 3), Fraction(1, 3), 1], midis=[60, 61, 62, 63]) l_sf = SimpleFormat(quarter_durations=[4, 5], midis=[50, 55]) r_sf.chords[1].manual_staff_number = 2 r_sf.to_stream_voice().add_to_score(self.score, part_number=1, staff_number=1) l_sf.to_stream_voice().add_to_score(self.score, part_number=1, staff_number=2) clef = BASS_CLEF.__deepcopy__() clef.number = 2 self.score.get_measure(1).get_part(1).add_clef(clef) xml_path = path + '_test_9.xml' self.score.write(xml_path) self.assertCompareFiles(xml_path) def test_10(self): # chord clef r_sf = SimpleFormat( quarter_durations=[4, 4], midis=[60, 61]) l_sf = SimpleFormat(quarter_durations=[4, 4], midis=[50, 55]) l_sf.chords[0].add_clef(BASS_CLEF) r_sf.to_stream_voice().add_to_score(self.score, part_number=1, staff_number=1) l_sf.to_stream_voice().add_to_score(self.score, part_number=1, staff_number=2) xml_path = path + '_test_10.xml' self.score.write(xml_path) self.assertCompareFiles(xml_path) def test_11(self): r_sf = SimpleFormat( quarter_durations=[0.25, 2.25, 0.5, 1, 2, Fraction(1, 3), Fraction(4, 3), Fraction(1, 3), 1], midis=[60, 61, 54, 63]) l_sf = SimpleFormat(quarter_durations=[4, 5], midis=[72, 53]) r_sf.chords[1].manual_staff_number = 2 r_sf.auto_clef() l_sf.auto_clef() r_sf.to_stream_voice().add_to_score(self.score, part_number=1, staff_number=1) l_sf.to_stream_voice().add_to_score(self.score, part_number=1, staff_number=2) xml_path = path + '_test_11.xml' self.score.write(xml_path) self.assertCompareFiles(xml_path) def test_12(self): r_sf_2 = SimpleFormat( quarter_durations=[0.25, 2.25, 0.5, 1, 2, Fraction(1, 3), Fraction(4, 3), Fraction(1, 3), 1], midis=[60, 61, 54, 63]) r_sf_1 = SimpleFormat( quarter_durations=[0.25, 2.25, 0.5, 1, 2, Fraction(1, 3), Fraction(4, 3), Fraction(1, 3), 1], midis=[70, 71, 64, 73]) l_sf_1 = SimpleFormat(quarter_durations=[4, 5], midis=[50, 35]) l_sf_2 = SimpleFormat(quarter_durations=[5, 4], midis=[44, 60]) r_sf_2.auto_clef() r_sf_1.auto_clef() l_sf_1.auto_clef() l_sf_2.auto_clef() r_sf_1.to_stream_voice(2).add_to_score(self.score, part_number=1, staff_number=1) r_sf_2.to_stream_voice(1).add_to_score(self.score, part_number=1, staff_number=1) l_sf_1.to_stream_voice(2).add_to_score(self.score, part_number=1, staff_number=2) l_sf_2.to_stream_voice(1).add_to_score(self.score, part_number=1, staff_number=2) xml_path = path + '_test_12.xml' self.score.write(xml_path) self.assertCompareFiles(xml_path) def test_13(self): # accidental r_sf = SimpleFormat(quarter_durations=[4, 4, 4, 4], midis=[61, 63, 64, 67]) l_sf = SimpleFormat(quarter_durations=[4, 4, 4, 4], midis=[60, 64, 63, 64]) r_sf.to_stream_voice().add_to_score(self.score, part_number=1, staff_number=1) l_sf.to_stream_voice().add_to_score(self.score, part_number=1, staff_number=2) xml_path = path + '_test_13.xml' self.score.write(xml_path) self.assertCompareFiles(xml_path)
class Test(XMLTestCase): def setUp(self): self.score = TreeScoreTimewise() self.score.add_measure() self.score.add_part() def test_1(self): midis = [61, 61, 62, 60, 63, 64, 65, 61] for midi in midis: self.score.add_chord(1, 1, TreeChord(midi, quarter_duration=0.5)) self.score.get_measure(1).get_part(1) self.score.finish() result_path = path + '_test_1' self.score.write(path=result_path) TestScore().assert_template(result_path=result_path) def test_2(self): midis = [ 60.0, 60.5, 61.0, 62.5, 64.0, 66.0, 68.0, 69.5, 71.0, 71.5, 72.0, 71.5, 71.0, 69.5, 68.0, 66.0, 64.0, 62.5, 61.0, 60.5 ] measure_number = 1 for midi in midis: chord = TreeChord(midi, quarter_duration=0.5) chord.add_lyric(midi) self.score.add_chord(measure_number, 1, chord) remaining_duration = self.score.get_measure( measure_number).get_part(1).get_staff(1).get_voice( 1).remaining_duration if remaining_duration == 0: self.score.add_measure() measure_number += 1 self.score.accidental_mode = 'modern' result_path = path + '_test_2' self.score.write(path=result_path) TestScore().assert_template(result_path=result_path) def test_3(self): midis = [(61.0, 63), 61.0, 0, 62.0, 61, 61, 61, (62, 61)] measure_number = 1 for midi in midis: chord = TreeChord(midi, quarter_duration=0.5) chord.add_lyric([m.value for m in chord.midis]) self.score.add_chord(measure_number, 1, chord) remaining_duration = self.score.get_measure( measure_number).get_part(1).get_staff(1).get_voice( 1).remaining_duration if remaining_duration == 0: self.score.add_measure() measure_number += 1 self.score.accidental_mode = 'modern' result_path = path + '_test_3' self.score.write(path=result_path) TestScore().assert_template(result_path=result_path) def test_4(self): simpleformat = SimpleFormat(midis=list(range(60, 68))) voice = simpleformat.to_stream_voice(2) voice.add_to_score(self.score) xml_path = path + '_test_4.xml' self.score.accidental_mode = 'modern' self.score.write(xml_path) self.assertCompareFiles(xml_path) def test_5(self): simpleformat = SimpleFormat(midis=[71.5, 71.5, 72, 72, 71.5, 71.5], quarter_durations=6 * [0.5]) voice = simpleformat.to_stream_voice(1) voice.add_to_score(self.score) result_path = path + '_test_5' self.score.accidental_mode = 'normal' self.score.write(result_path) TestScore().assert_template(result_path=result_path) def test_6(self): midis = [51.5, 51.5, 50.5, 48.5, 49.5, 48.5, 50.0, 50.0, 49.5, 49.0] durations = [ Fraction(255, 56), Fraction(6525, 3136), Fraction(6075, 3136), Fraction(2475, 3136), Fraction(2145, 3136), Fraction(2805, 3136), Fraction(1815, 3136), Fraction(65, 56), Fraction(2015, 1568), Fraction(1625, 1568) ] simpleformat = SimpleFormat(midis=midis, quarter_durations=durations) simpleformat.auto_clef() voice = simpleformat.to_stream_voice(1) voice.add_to_score(self.score) result_path = path + '_test_6' self.score.max_division = 7 self.score.accidental_mode = 'modern' self.score.write(result_path) TestScore().assert_template(result_path=result_path) def test_7(self): # todo update_accidental does not work ... class TestFlag3(TreeChordFlag3): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def implement(self, chord): split = chord.split(2, 2) split[0].to_rest() for ch in split: ch.update_type() ch.update_dot() return split xml_path = path + '_test_7.xml' sf = SimpleFormat(midis=[61], quarter_durations=[4]) sf.to_stream_voice().add_to_score(self.score, part_number=1) chord = sf.chords[0] chord.add_flag(TestFlag3()) sf.to_stream_voice().add_to_score(self.score, part_number=2) self.score.write(xml_path) def test_8(self): midis = [60 + factor * 0.5 for factor in range(0, 25)] simple_format = SimpleFormat(midis=midis + midis[-1::-1][1:]) for index, chord in enumerate(simple_format.chords): if index <= len(midis) - 1: chord.midis[0].accidental.mode = 'sharp' else: chord.midis[0].accidental.mode = 'flat' simple_format.to_stream_voice().add_to_score(self.score) xml_path = path + '_test_8.xml' self.score.write(xml_path) TestScore().assert_template(xml_path) def test_9(self): midis = [60, 61, 62, 63, 64, 61, 62, 61] simple_format = SimpleFormat(midis=midis) simple_format.to_stream_voice().add_to_score(self.score, part_number=1) for chord in simple_format.chords: chord.midis[0].accidental.force_show = True simple_format.to_stream_voice().add_to_score(self.score, part_number=2) for chord in simple_format.chords: chord.midis[0].accidental.force_hide = True simple_format.to_stream_voice().add_to_score(self.score, part_number=3) xml_path = path + '_test_9.xml' self.score.write(xml_path) TestScore().assert_template(xml_path)
class Test(TestCase): def setUp(self) -> None: self.score = TreeScoreTimewise() def test_1(self): sf = SimpleFormat(quarter_durations=[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]) for index, chord in enumerate(sf.chords): chord.add_lyric(index + 1) v = sf.to_stream_voice(1) v.add_to_score(self.score, part_number=2) sf = SimpleFormat(quarter_durations=[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]) v = sf.to_stream_voice(1) v.add_to_score(self.score) self.score.fill_with_rest() self.score.preliminary_adjoin_rests() self.score.add_beats() for measure in self.score.get_children_by_type(TreeMeasure): part = measure.get_part(2) for beat in part.get_beats(): beat.max_division = 7 result_path = path + '_test_1' # with self.assertWarns(UserWarning): # self.score.write(path=result_path) self.score.write(path=result_path) TestScore().assert_template(result_path=result_path) def test_2(self): self.score.add_measure(TreeMeasure(time=(3, 4))) sf = SimpleFormat(quarter_durations=[0.5, 0.6, 0.7, 0.8]) for index, chord in enumerate(sf.chords): chord.add_lyric(index + 1) v = sf.to_stream_voice(1) v.add_to_score(self.score) sf = SimpleFormat(quarter_durations=[0.5, 0.6, 0.7, 0.8]) for index, chord in enumerate(sf.chords): chord.add_lyric(index + 1) v = sf.to_stream_voice(1) v.add_to_score(self.score, part_number=2) self.score.fill_with_rest() self.score.preliminary_adjoin_rests() self.score.add_beats() for measure in self.score.get_children_by_type(TreeMeasure): part = measure.get_part(2) for beat in part.get_beats(): beat.max_division = 7 self.score.quantize() result_path = path + '_test_2' # with self.assertWarns(UserWarning): # self.score.write(path=result_path) self.score.write(path=result_path) TestScore().assert_template(result_path=result_path) def test_3(self): random.seed(3) durations = [] while sum(durations) <= 16: duration = random.randrange(0, 2) + (random.random() / 2.) durations.append(Fraction(duration).limit_denominator(100)) def add_to_score(part=1): sf = SimpleFormat(quarter_durations=durations) dynamics = itertools.cycle(['pppp', 'ppp', 'pp', 'p', 'mp', 'mf', 'f', 'ff', 'fff']) for index, chord in enumerate(sf.chords): chord.add_lyric(index + 1) d = chord.add_dynamics(dynamics.__next__())[0] d.relative_y = -20 d.halign = 'center' v = sf.to_stream_voice(1) v.add_to_score(self.score, part) add_to_score(1) add_to_score(2) add_to_score(3) add_to_score(4) add_to_score(5) add_to_score(6) add_to_score(7) add_to_score(8) self.score.get_score_parts()[0].max_division = 8 self.score.get_score_parts()[1].max_division = 7 self.score.get_score_parts()[2].max_division = 6 self.score.get_score_parts()[3].max_division = 5 self.score.get_score_parts()[4].max_division = 4 self.score.get_score_parts()[5].max_division = 3 self.score.get_score_parts()[6].max_division = 2 self.score.get_score_parts()[7].max_division = 1 result_path = path + '_test_3' self.score.write(path=result_path) TestScore().assert_template(result_path=result_path) def test_4(self): sf = SimpleFormat( quarter_durations=[Fraction(3, 10), Fraction(3, 10), Fraction(3, 10), Fraction(3, 10), Fraction(3, 10), Fraction(3, 2), Fraction(1, 2), Fraction(1, 3)]) xml_path = path + '_test_4.xml' sf.to_stream_voice().add_to_score(self.score) self.score.write(xml_path) TestScore().assert_template(result_path=xml_path) def test_5(self): self.score.set_time_signatures( [Fraction(3, 2)]) sf = SimpleFormat(quarter_durations=[0.666, 0.333, 0.5]) xml_path = path + '_test_5.xml' sf.to_stream_voice().add_to_score(self.score) self.score.get_score_parts()[0].max_division = 1 self.score.write(xml_path)