Exemplo n.º 1
0
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)
Exemplo n.º 2
0
class Test(TestCase):
    def setUp(self) -> None:
        self.score = TreeScoreTimewise()

    def test_1(self):
        sf = SimpleFormat(quarter_durations=[7])
        v = sf.to_stream_voice()
        v.add_to_score(self.score)
        result_path = path + '_test_1'
        self.score.write(path=result_path)

    def test_2(self):
        sf = SimpleFormat(quarter_durations=[12.5])
        v = sf.to_stream_voice()
        v.add_to_score(self.score)
        result_path = path + '_test_2'
        self.score.write(path=result_path)

    def test_3(self):
        # sf = SimpleFormat(durations=[Fraction(4) + Fraction(1, 2), Fraction(1, 2)])
        sf = SimpleFormat(quarter_durations=[
            Fraction(4, 1) +
            Fraction(5, 7), Fraction(5, 7)
        ])
        # sf = SimpleFormat(durations=[Fraction(4, 1) + Fraction(5, 7), Fraction(2, 7)])
        v = sf.to_stream_voice()
        v.add_to_score(self.score)

        self.score.finish()
        # print([chord.quarter_duration for chord in self.score.get_measure(2).get_part(1).chords])
        # print([chord.tie_types for chord in self.score.get_measure(2).get_part(1).chords])
        result_path = path + '_test_3'
        self.score.write(path=result_path)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
    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">
Exemplo n.º 8
0
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)
Exemplo n.º 9
0
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)
Exemplo n.º 10
0
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))
Exemplo n.º 11
0
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)
Exemplo n.º 12
0
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)
Exemplo n.º 13
0
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)
Exemplo n.º 14
0
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)
Exemplo n.º 15
0
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)