Exemple #1
0
 def test_3(self):
     fm = FractalMusic(duration=100)
     fm.add_layer()
     try:
         fm.tempo = 60
     except (ChildTempoIsAlreadySet, TempoIsAlreadySet) as err:
         self.fail(err + "was raised!")
Exemple #2
0
    def test_1(self):
        fm = FractalMusic(tempo=60,
                          proportions=[1, 2, 3, 4],
                          tree_permutation_order=[3, 1, 4, 2],
                          quarter_duration=100)
        fm.midi_generator.midi_range = [60, 79]
        fm.add_layer()
        partial_fm = fm.get_leaves()[3]
        partial_fm.add_layer()
        for leaf in partial_fm.traverse():
            leaf.chord.add_lyric(leaf.fractal_order)
            leaf.chord.add_words(leaf.midi_generator.midi_range)
            # leaf.chord.add_words(leaf.midi_generator.directions, relative_y=30)
        # print([leaf.fractal_order for leaf in partial_fm.traverse_leaves()])
        score = TreeScoreTimewise()
        v = partial_fm.get_simple_format(0).to_stream_voice(1)
        v.add_to_score(score, 1)

        v = partial_fm.get_simple_format().__deepcopy__().to_stream_voice(1)
        v.add_to_score(score, 2)

        partial_fm.reduce_children(
            condition=lambda child: child.fractal_order > 2)
        v = partial_fm.get_simple_format().__deepcopy__().to_stream_voice(1)
        v.add_to_score(score, 3)

        xml_path = path + '_test_1.xml'
        score.write(xml_path)
        self.assertCompareFiles(actual_file_path=xml_path)
Exemple #3
0
 def test_4(self):
     fm = FractalMusic(duration=100)
     fm.add_layer()
     fm.get_children()[0].tempo = 72
     fm.set_none_tempi(90)
     self.assertEqual([child.tempo for child in fm.get_children()],
                      [72, 90., 90])
Exemple #4
0
    def test_10(self):
        fm = FractalMusic(proportions=[1, 2, 3],
                          tree_permutation_order=[3, 1, 2])
        fm.tempo = 60
        fm.duration = 10
        fm.midi_generator.midi_range = (60, 72)
        fm.permute_directions = True
        fm.midi_generator.set_directions(-1, 1, -1)

        fm.add_layer()

        for node in fm.traverse():
            node.chord.add_lyric(node.midi_generator.directions)
            node.chord.add_words(node.children_generated_midis, relative_y=30)
            node.chord.add_words(node.midi_generator.midi_range, relative_y=60)

        fm.add_layer()

        score = TreeScoreTimewise()
        score.accidental_mode = 'modern'
        score = fm.get_score(score)
        score.page_style.staff_distance = 150
        xml_path = path + '_test_10.xml'
        score.write(xml_path)
        self.assertCompareFiles(xml_path)
Exemple #5
0
    def test_9(self):
        fm = FractalMusic(proportions=[1, 2, 3, 4, 5, 6, 7],
                          tree_permutation_order=[3, 6, 2, 5, 1, 7, 4])

        fm.multi = (7, 4)
        fm.tempo = 60
        fm.quarter_duration = 70

        fm.midi_generator.microtone = 4
        # fm.quantize_leaves(0.5)
        fm.midi_generator.directions = [1, -1, 1, -1, 1, -1, 1]

        fm.midi_generator.midi_range = [36, 56]
        fm.add_layer()

        fm.reduce_children(lambda child: child.fractal_order > 4)
        fm.quantize_leaves(0.5)
        fm.get_children()[3].add_layer()
        fm.get_children()[3].reduce_children(
            lambda child: child.fractal_order > 4)
        for node in fm.traverse():
            node.chord.add_words(node.midi_value)
        text_path = path + '_test_9.txt'
        fm.write_infos(text_path)
        self.assertCompareFiles(actual_file_path=text_path)

        score = fm.get_score()
        xml_path = path + '_test_9.xml'
        score.write(xml_path)
        self.assertCompareFiles(actual_file_path=xml_path)
Exemple #6
0
    def test_7(self):
        fm = FractalMusic(tempo=60,
                          proportions=[1, 2, 3, 4],
                          tree_permutation_order=[3, 1, 4, 2],
                          quarter_duration=20)
        fm.midi_generator.midi_range = [60, 79]
        fm.add_layer()
        fm.chord.add_words(fm.midi_generator.midi_range)

        for child in fm.get_children():
            child.chord.add_lyric(child.fractal_order)
            child.chord.add_words(child.midi_generator.midi_range)

        for index, node in enumerate(fm.get_children()):
            node.midi_generator.midi_range = [60 - index, 72 - index]

        fm.add_layer()
        for leaf in fm.traverse_leaves():
            leaf.chord.add_lyric(leaf.fractal_order)

        score = TreeScoreTimewise()

        for layer_number in range(0, fm.number_of_layers + 1):
            simple_format = fm.get_simple_format(layer_number)

            v = simple_format.to_stream_voice(1)
            v.add_to_score(score, layer_number + 1)

        xml_path = path + '_test_7.xml'
        score.accidental_mode = 'normal'
        score.write(xml_path)
        self.assertCompareFiles(actual_file_path=xml_path)
Exemple #7
0
 def test_1(self):
     fm = FractalMusic(tempo=60, quarter_duration=10)
     fm.midi_generator.midi_range = [60, 72]
     fm.add_layer()
     fm.add_info('fractal_order')
     score = fm.get_score(layer_number=fm.number_of_layers)
     xml_path = path + '_test_1.xml'
     score.write(path=xml_path)
     self.assertCompareFiles(xml_path)
 def setUp(self) -> None:
     self.score = TreeScoreTimewise()
     fm = FractalMusic(tempo=60,
                       quarter_duration=10,
                       reading_direction='vertical')
     fm.add_layer()
     fm.add_layer()
     self.fm = fm.get_children()[1]
     self.deep_copied = self.fm.__deepcopy__()
    def test_6(self):
        def get_chord(node):
            output = fm.get_multi_chord_midis_with_range_factor(range_factor=1, microtone=4)
            transposition = node.midi_value - output[3]
            output = [midi + transposition for midi in output]
            return output

        fm = FractalMusic(proportions=(1, 2, 3, 4, 5, 6, 7), tree_permutation_order=(2, 6, 4, 1, 3, 7, 5),
                          quarter_duration=30, tempo=72)
        fm.midi_generator.midi_range = (62, 62 + 11)
        fm.midi_generator.microtone = 4
        fm.add_layer()
        fm.quantize_children(grid_size=1)

        def make_breathe(nodes, proportions, breakpoints):
            breath_quarter_duration = sum([node.quarter_duration for node in nodes])
            breathe = Breathe(proportions=proportions, breakpoints=breakpoints,
                              quarter_duration=breath_quarter_duration,
                              quantize=1)

            parent_chord_field = ChordField(duration_generator=breathe.duration_generator.__deepcopy__())
            for i in range(len(nodes)):
                node = selected_nodes[i]
                start_chord = get_chord(node)
                next_node = node.next_sibling
                if next_node:
                    end_chord = get_chord(next_node)
                else:
                    end_chord = start_chord

                chord_field = ChordField(
                    quarter_duration=node.quarter_duration,
                    midi_generator=ValueGenerator(RandomInterpolation(start=start_chord, end=end_chord, seed=10)),
                    long_ending_mode='self_extend',
                    short_ending_mode='self_shrink')
                parent_chord_field.add_child(chord_field)

            return parent_chord_field

        selected_nodes = fm.get_children()[2:5]
        # print(sum([node.quarter_duration for node in selected_nodes]))
        proportions = (1, 10, 1, 7, 1)
        breakpoints = (1, Fraction(1, 7), 1)
        breathe = make_breathe(nodes=selected_nodes, proportions=proportions,
                               breakpoints=breakpoints)
        # print(breathe.quarter_duration)
        fm.merge_children(2, 3, 2)
        # print(fm.get_children()[1].quarter_duration)
        fm.get_children()[1].simple_format = breathe.simple_format
        score = fm.get_score(show_fractal_orders=True, layer_number=fm.number_of_layers)
        score.max_division = 7
        score.finish()
        partwise = score.to_partwise()
        xml_path = path + '_test_6.xml'
        partwise.write(xml_path)
        self.assertCompareFiles(xml_path)
Exemple #10
0
    def test_8(self):
        fm = FractalMusic(duration=100)
        fm.tempo = 72
        fm.add_layer()
        fm.add_layer()
        fm.add_layer()
        fm.set_none_tempi(60)

        self.assertEqual(fm.get_layer(2, key='tempo'),
                         [[72, 72, 72], [72, 72, 72], [72, 72, 72]])
Exemple #11
0
 def test_3(self):
     fm = FractalMusic(tempo=60, quarter_duration=10)
     fm.midi_generator.midi_range = [60, 72]
     fm.add_layer()
     fm.add_layer()
     fm.add_info('midi_value')
     score = fm.get_score()
     xml_path = path + '_test_3.xml'
     score.write(path=xml_path)
     self.assertCompareFiles(xml_path)
Exemple #12
0
 def test_1(self):
     fm = FractalMusic(proportions=[1, 2, 3], tree_permutation_order=[3, 1, 2], duration=12, tempo=72)
     fm.quarter_duration = round(fm.quarter_duration)
     fm.add_layer()
     quarter_durations = [float(leaf.quarter_duration) for leaf in fm.traverse_leaves()]
     # print(quarter_durations)
     # print(sum(quarter_durations))
     fm.quantize_leaves(grid_size=0.5)
     quarter_durations = [float(leaf.quarter_duration) for leaf in fm.traverse_leaves()]
     self.assertEqual(quarter_durations, [7.0, 2.5, 4.5])
Exemple #13
0
 def test_4(self):
     fm = FractalMusic(tempo=60, quarter_duration=10)
     fm.midi_generator.midi_range = [60, 72]
     fm.add_layer()
     fm.add_layer()
     fm.add_info((lambda node: int(node.midi_value) if int(node.midi_value) == node.midi_value else node.midi_values,
                  'above'))
     score = fm.get_score()
     xml_path = path + '_test_4.xml'
     score.write(path=xml_path)
     self.assertCompareFiles(xml_path)
Exemple #14
0
 def test_1(self):
     fm = FractalMusic(tempo=60, quarter_duration=10)
     fm.midi_generator.midi_range = [60, 72]
     fm.add_layer()
     for child in fm.get_children():
         child.add_gliss(grid=0.5, show_heads=True)
         child.chord_field.chords[0].add_articulation('accent')
     score = fm.get_score(show_fractal_orders=True,
                          layer_number=fm.number_of_layers)
     xml_path = path + '_test_1.xml'
     score.write(path=xml_path)
     self.assertCompareFiles(xml_path)
Exemple #15
0
 def test_4(self):
     fm = FractalMusic(duration=30)
     fm.add_layer()
     fm.get_children()[1].tempo = 72
     fm.set_none_tempi(80)
     fm.quantize_leaves(0.5)
     fm.add_layer()
     score = fm.get_root_score(layer_number=1, show_fractal_orders=True)
     xml_path = path + '_test_4.xml'
     score.write(path=xml_path)
     with self.assertRaises(SetTempoFirstException):
         fm.get_score()
Exemple #16
0
 def test_1(self):
     fm = FractalMusic(tempo=60,
                       quarter_duration=10,
                       proportions=(1, 2, 3),
                       tree_permutation_order=(3, 1, 2))
     fm.add_layer()
     midis = [B(4), A(4, 'b'), C(4, '#'), A(3), F(4)]
     fm.get_children()[0].add_layer()
     for leaf, midi in zip(fm.traverse_leaves(), midis):
         leaf.set_chord(TreeChord(midi))
     score = fm.get_score(show_fractal_orders=True)
     xml_path = path + '_test_.xml'
     score.write(path=xml_path)
Exemple #17
0
 def test_2(self):
     fm = FractalMusic(tempo=60, quarter_duration=10, multi=(1, 2))
     fm.midi_generator.midi_range = [60, 72]
     fm.add_layer()
     for child in fm.get_children():
         child.chord.add_articulation('accent')
         child.chord.add_dynamics('f')
     for child in fm.get_children():
         child.add_gliss()
     score = fm.get_score(show_fractal_orders=True,
                          layer_number=fm.number_of_layers)
     xml_path = path + '_test_2.xml'
     score.write(path=xml_path)
     self.assertCompareFiles(xml_path)
 def test_deep_copied_child_midi_values(self):
     fm = FractalMusic(proportions=[1, 2, 3, 4],
                       tree_permutation_order=[3, 1, 4, 2],
                       quarter_duration=20,
                       tempo=70)
     fm.midi_generator.midi_range = [36, 60]
     fm.add_layer()
     selected_node = fm.get_children()[0]
     copied_node = selected_node.__deepcopy__()
     copied_node.add_layer()
     actual = [node.midi_value for node in copied_node.get_children()]
     selected_node.add_layer()
     expected = [node.midi_value for node in selected_node.get_children()]
     self.assertEqual(expected, actual)
Exemple #19
0
    def test_change_midi_range_afterwards(self):

        fm = FractalMusic(proportions=[1, 2, 3],
                          tree_permutation_order=[3, 1, 2])
        fm.tempo = 60
        fm.duration = 10
        fm.midi_generator.midi_range = [40, 50]
        fm.add_layer()
        fm.add_layer()
        fm.reset_midis()
        fm.midi_generator.midi_range = [60, 70]
        expected = [62.0, 65.0, 60.0, 67.0, 69.0, 70.0, 67.0, 65.0, 69.0]
        actual = [l.midi_value for l in fm.traverse_leaves()]
        self.assertEqual(expected, actual)
Exemple #20
0
class Test(TestCase):
    def setUp(self) -> None:
        self.fm = FractalMusic(proportions=(1, 2, 3),
                               tree_permutation_order=(3, 1, 2))
        self.fm.duration = 10
        self.fm.tempo = 60
        self.fm.midi_generator.midi_range = [60, 67]
        self.fm.add_layer()
        self.score = TreeScoreTimewise()
        self.score.set_time_signatures(
            quarter_durations=[self.fm.quarter_duration])

    def test_1(self):

        sp = self.fm.get_children()[0].split(1, 1, 1, 1, 1)
        sp[0].chord.add_dynamics('pp')
        sp[0].chord.add_slur('start')
        sp[-1].chord.add_slur('stop')
        sf = self.fm.get_simple_format()
        v = sf.to_stream_voice(1)
        v.add_to_score(self.score, 1)

        xml_path = path + '_test_1.xml'
        self.score.write(path=xml_path)
        self.assertCompareFiles(actual_file_path=xml_path)

    def test_2(self):
        def add_repetition(node):
            node.chord.add_articulation('tenuto')
            duration = node.chord.quarter_duration
            lengths = int(duration) * [1]
            if len(lengths) > 1:
                diff = duration - int(duration)
                if diff > 0:
                    lengths[-1] += diff
                sp = node.split(lengths)
                sp[0].chord.add_slur('start')
                sp[-1].chord.add_slur('stop')

        for child in self.fm.get_children():
            add_repetition(child)

        sf = self.fm.get_simple_format()
        v = sf.to_stream_voice(1)
        v.add_to_score(self.score, 1)

        xml_path = path + '_test_2.xml'
        self.score.write(path=xml_path)
        self.assertCompareFiles(actual_file_path=xml_path)
    def test_4(self):
        # self.fm.multi = (self.fm.multi[0], self.fm.multi[1] + 1)
        def get_chord_stamp():
            node = fm.__copy__()
            node.midi_generator.midi_range = fm.midi_generator.midi_range
            node.midi_generator.microtone = 4
            node.add_layer()
            chord_midis = [child.midi_value for child in node.get_children()]
            output = [chord_midi - chord_midis[node.size // 2] for chord_midi in chord_midis]
            return output

        fm = FractalMusic(proportions=(1, 2, 3, 4, 5, 6, 7), tree_permutation_order=(2, 6, 4, 1, 3, 7, 5),
                          quarter_duration=30, tempo=80)
        fm.midi_generator.midi_range = (60, 72)
        fm.midi_generator.microtone = 4
        fm.add_layer()
        fm.quantize_children(grid_size=1)
        proportions = (1, 10, 1, 7, 1)
        breakpoints = (1, Fraction(1, 7), 1)
        selected_nodes = fm.get_children()[1:3]

        breath_quarter_duration = sum([node.quarter_duration for node in selected_nodes])
        breathe = Breathe(proportions=proportions, breakpoints=breakpoints, quarter_duration=breath_quarter_duration,
                          quantize=1)
        parent_chord_field = ChordField(duration_generator=breathe.duration_generator.__deepcopy__())
        for i in range(len(selected_nodes)):
            node = selected_nodes[i]
            start_chord = [stamp + node.midi_value for stamp in get_chord_stamp()]
            next_node = node.next_sibling
            if next_node:
                end_chord = [stamp + node.midi_value for stamp in get_chord_stamp()]
            else:
                end_chord = start_chord

            chord_field = ChordField(
                midi_generator=ValueGenerator(RandomInterpolation(start=start_chord, end=end_chord, seed=10)),
                long_ending_mode='self_extend',
                short_ending_mode='self_shrink')
            parent_chord_field.add_child(chord_field)

            node.chord_field = chord_field

        score = fm.get_score(show_fractal_orders=True, layer_number=fm.number_of_layers)
        score.max_division = 7
        score.finish()
        partwise = score.to_partwise()
        xml_path = path + '_test_4.xml'
        partwise.write(xml_path)
        self.assertCompareFiles(xml_path)
Exemple #22
0
 def test_6(self):
     fm = FractalMusic(reading_direction='vertical',
                       tempo=120,
                       value=1.5,
                       proportions=(1, 2, 3, 4, 5, 6, 7),
                       tree_permutation_order=(2, 6, 4, 1, 3, 7, 5),
                       multi=(1, 4))
     fm.midi_generator.midi_range = (62, 70)
     fm.add_layer()
     # fm.generate_children(number_of_children=1)
     fm.reduce_children(lambda child: child.fractal_order < 7)
     result = fm.get_children()[0].midi_generator.midi_range
     # not [62, 70] because of directions ([-1, ...])
     expected = [70, 62]
     self.assertEqual(expected, result)
class Test(TestCase):
    def setUp(self) -> None:
        self.score = TreeScoreTimewise()
        self.fm = FractalMusic(tempo=60, quarter_duration=10)

    def test_none_midi_values(self):
        self.fm.add_layer()
        actual = [node._midi_value for node in self.fm.traverse()]
        expected = 4 * [None]
        self.assertEqual(expected, actual)

    def test_none_midi_values_instrument_changed(self):
        self.fm.instrument = Cello()
        self.fm.add_layer()
        actual = [node._midi_value for node in self.fm.traverse()]
        expected = 4 * [None]
        self.assertEqual(expected, actual)
Exemple #24
0
    def test_3(self):
        fm = FractalMusic(tempo=60, quarter_duration=10, multi=(1, 3))
        fm.midi_generator.midi_range = [60, 72]
        fm.add_layer()
        for child in fm.get_children():
            for midi in child.chord.midis:
                midi.notehead = Notehead('diamond', filled='no')
        for child in fm.get_children():
            child.add_gliss()

        fm.get_children()[-1].chord_field.chords[-1].get_post_grace_chords(
        )[0].midis[0].notehead = Notehead('diamond', filled='no')
        score = fm.get_score(show_fractal_orders=True,
                             layer_number=fm.number_of_layers)
        xml_path = path + '_test_3.xml'
        score.write(path=xml_path)
        self.assertCompareFiles(xml_path)
Exemple #25
0
 def test_1(self):
     fm = FractalMusic(quarter_duration=20, tempo=80)
     fm.midi_generator.midi_range = [60, 84]
     fm.add_layer()
     sorted_children = sorted(fm.get_children(), key=lambda child: child.fractal_order)
     chord_field = ChordField(
         quarter_duration=10,
         duration_generator=ValueGenerator(ArithmeticProgression(a1=0.2, an=2)),
         midi_generator=ValueGenerator(Interpolation(start=84, end=60,
                                                     key=lambda midi: round(midi * 2) / 2)),
         short_ending_mode='add_rest'
     )
     sorted_children[-1].chord_field = chord_field
     score = fm.get_score(show_fractal_orders=True)
     xml_path = path + '_test_1.xml'
     score.write(xml_path)
     self.assertCompareFiles(xml_path)
Exemple #26
0
 def test_calculate_range_factor(self):
     fm = FractalMusic(proportions=(1, 2, 3, 4, 5, 6, 7),
                       tree_permutation_order=(2, 6, 4, 1, 3, 7, 5),
                       quarter_duration=30,
                       tempo=60)
     fm.midi_generator.midi_range = [60, 84]
     multi_chord_midi_range_interval = 11
     fm.add_layer()
     actual = [
         leaf.calculate_range_factor(multi_chord_midi_range_interval)
         for leaf in fm.traverse_leaves()
     ]
     expected = [
         -3.6666666666666665, -1.2222222222222223, -1.8333333333333333,
         11.0, 2.2, 1.1, 1.375
     ]
     self.assertEqual(expected, actual)
Exemple #27
0
class Test(TestCase):
    def setUp(self) -> None:
        self.fm = FractalMusic(tempo=60,
                               tree_permutation_order=[3, 1, 2],
                               proportions=[1, 2, 3],
                               quarter_duration=20)
        self.score = TreeScoreTimewise()

    def test_1(self):
        self.fm.add_layer()
        self.fm.add_layer()
        self.fm.add_layer()
        sf = self.fm.get_simple_format(layer=1)
        v = sf.to_stream_voice(1)
        v.add_to_score(self.score)
        xml_path = path + '_test_1.xml'
        self.score.write(xml_path)
        self.assertCompareFiles(xml_path)
Exemple #28
0
class Test(TestCase):
    def setUp(self) -> None:
        self.fm = FractalMusic(proportions=(1, 2, 3, 4, 5),
                               tree_permutation_order=(3, 5, 1, 2, 4))
        self.fm.duration = 10
        self.fm.midi_generator.midi_range = [60, 72]

    def test_1(self):
        fm = self.fm
        fm.add_layer()
        fm.tempo = 60
        for ch in fm.get_children():
            ch.chord.add_words(ch.fractal_order)

        score = TreeScoreTimewise()
        fm.get_simple_format().to_stream_voice().add_to_score(score)

        fm.merge_children(2, 1, 2)
        # print(fm.get_leaves(key=lambda leaf: leaf.index))
        # print(fm.get_leaves(key=lambda leaf: leaf.fractal_order))
        # print(fm.get_leaves(key=lambda leaf: round(float(leaf.value), 2)))
        # print(fm.get_leaves(key=lambda leaf: round(float(leaf.duration), 2)))
        # print(fm.get_leaves(key=lambda leaf: round(float(leaf.chord.quarter_duration), 2)))
        fm.get_simple_format().to_stream_voice().add_to_score(score,
                                                              part_number=2)
        xml_path = path + '_test_1.xml'
        score.write(xml_path)
        self.assertCompareFiles(xml_path)
        # # ft.add_layer()
        # # print(ft.get_leaves(key=lambda leaf: leaf.index))
        # # print(ft.get_leaves(key=lambda leaf: leaf.fractal_order))
        # # print(ft.get_leaves(key=lambda leaf: round(float(leaf.value), 2)))
        # ft.merge_children(1, 2, 2)
        # # print(ft.get_leaves(key=lambda leaf: leaf.index))
        # self.assertEqual(ft.get_leaves(key=lambda leaf: leaf.fractal_order), [3, 5, 2])
        # self.assertEqual(ft.get_leaves(key=lambda leaf: round(float(leaf.value), 2)), [2.0, 4.0, 4.0])

    def test_2(self):
        self.fm.duration = 20
        self.fm.add_layer()
        self.fm.get_children()[1].tempo = 72
        self.fm.set_none_tempi(60)
        with self.assertRaises(MergeTempoException):
            self.fm.merge_children(2, 1, 2)
class Test(TestCase):
    def setUp(self) -> None:
        self.fm = FractalMusic(proportions=[1, 2, 3],
                               tree_permutation_order=(3, 1, 2),
                               duration=10)

    def test_1(self):
        self.fm.midi_generator.set_directions(1, -1, -1)
        self.assertEqual([1, -1, -1], self.fm.midi_generator.directions)
        self.assertEqual([-1, -1, 1], self.fm.tree_directions)
        self.fm.add_layer()
        # for node in self.fm.get_children():
        #     print(node.name)
        #     print(node.multi)
        #     print(node.permutation_order)
        #
        # text_path = path + '_test_1.txt'
        #
        # self.fm.write_infos(text_path)
        directions = [
            leaf.midi_generator.directions
            for leaf in self.fm.traverse_leaves()
        ]

        self.assertEqual([[-1, -1, 1], [1, -1, -1], [-1, 1, -1]], directions)

    def test_2(self):
        self.fm.tree_directions = [1, 1, -1]
        self.fm.midi_generator.midi_range = [60, 70]
        self.fm.add_layer()
        directions = [
            leaf.midi_generator.directions
            for leaf in self.fm.traverse_leaves()
        ]
        self.fm.add_layer()
        midis = [leaf.midi_value for leaf in self.fm.traverse_leaves()]
        self.assertEqual([[1, 1, -1], [-1, 1, 1], [1, -1, 1]], directions)
        self.assertEqual(
            [60.0, 63.0, 70.0, 63.0, 60.0, 61.0, 65.0, 70.0, 63.0], midis)

    def test_3(self):
        self.fm.tree_directions = [1, 1, -1]
        self.fm.midi_generator.midi_range = [60, 70]
        self.fm.permute_directions = False
        self.fm.add_layer()
        self.fm.add_layer()
        midi_ranges = [[
            leaf.midi_generator.midi_range for leaf in child.get_leaves()
        ] for child in self.fm.get_children()]
        result = [[[60.0, 63.0], [63.0, 70.0], [70.0, 60.0]],
                  [[60.0, 62.0], [62.0, 63.0], [63.0, 61.0]],
                  [[63.0, 66.0], [66.0, 70.0], [70.0, 69.0]]]

        self.assertEqual(result, midi_ranges)
class Test(TestCase):
    def setUp(self) -> None:
        self.score = TreeScoreTimewise()
        self.fm = FractalMusic(tempo=60, quarter_duration=10)
        self.fm.midi_generator.midi_range = [60, 71]
        self.fm.add_layer()
        self.copied = self.fm.__deepcopy__()

    def test_1(self):
        xml_path = path + '_test_1.xml'
        self.fm.quantize_children(1)
        self.score.set_time_signatures([child.quarter_duration for child in self.fm.get_children()])

        self.copied.inverse_tree_directions()
        self.copied.quantize_children(1)
        self.fm.get_simple_format().to_stream_voice().add_to_score(score=self.score, staff_number=1)
        self.copied.get_simple_format().to_stream_voice().add_to_score(score=self.score, staff_number=2)
        self.score.write(xml_path)
        self.assertCompareFiles(xml_path)