Exemplo n.º 1
0
    def test_12(self):
        # breathing: duration_generator automatically, midi_generator: InterpolationGroup(2 x RandomInterpolations)
        breathing_proportions = [3, 7, 3, 10, 3]
        breathing_break_points = [1.5, 0.2, 1.5]
        breathing = Breathe(quarter_duration=sum(breathing_proportions), proportions=breathing_proportions,
                            breakpoints=breathing_break_points)

        midi_generator = ValueGenerator()

        midi_generator.add_child(
            ValueGenerator(RandomInterpolation(start=[60, 62, 66, 68], end=[67, 69, 73, 75], seed=10), duration=10)
        )

        midi_generator.add_child(
            ValueGenerator(RandomInterpolation(start=[67, 69, 73, 75], end=[60, 62, 66, 68], seed=11), duration=10)
        )

        breathing.midi_generator = midi_generator
        copied = breathing.__deepcopy__()
        xml_path = path + 'test_12.xml'
        self.score.set_time_signatures(quarter_durations=breathing_proportions)
        copied.simple_format.to_stream_voice().add_to_score(self.score)

        self.score.max_division = 5
        self.score.write(xml_path)
        self.assertCompareFiles(xml_path)
Exemplo n.º 2
0
    def test_10(self):
        midi_generator = ValueGenerator()

        midi_generator.add_child(
            ValueGenerator(RandomInterpolation(start=[60, 62, 66, 68], end=[67, 69, 73, 75], seed=10), duration=10)
        )

        midi_generator.add_child(
            ValueGenerator(RandomInterpolation(start=[67, 69, 73, 75], end=[60, 62, 66, 68], seed=11), duration=10)
        )

        cfg = ChordField(
        )
        cf_1 = ChordField(
            quarter_duration=3,
            duration_generator=ValueGenerator(ArithmeticProgression(a1=0.5, an=1, correct_s=True))
        )
        cf_2 = ChordField(
            quarter_duration=6,
            duration_generator=ValueGenerator(ArithmeticProgression(a1=1, an=1, correct_s=True))
        )

        cfg.add_child(cf_1)
        cfg.add_child(cf_2)
        cfg.midi_generator = midi_generator
        cfg.__next__()
Exemplo n.º 3
0
 def test_3(self):
     ri = RandomInterpolation(start=[60, 62, 66, 68],
                              end=[67, 69, 73, 75],
                              duration=13,
                              seed=10)
     test_case = [ri.__call__(x) for x in range(0, 13)]
     expected = [60, 68, 67, 62, 66, 69, 67, 68, 66, 73, 69, 68, 73]
     self.assertEqual(expected, test_case)
Exemplo n.º 4
0
 def test_2(self):
     ri = RandomInterpolation(start=[1, 2, 3],
                              end=[7, 7, 7],
                              periodicity=1,
                              duration=20,
                              seed=12)
     test_case = [ri.__call__(x) for x in range(0, 20)]
     expected = [2, 3, 2, 1, 3, 2, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 7, 7]
     self.assertEqual(expected, test_case)
Exemplo n.º 5
0
    def test_8(self):
        # fields: midi_generators
        # group: duration_generator with __call__ RandomInterpolation
        # output of fields not group

        cfg = ChordField(
            duration_generator=ValueGenerator(
                RandomInterpolation(start=[0.25, 0.25, 0.5], end=[0.5, 0.75, 1], seed=20)))

        cf_1 = ChordField(
            quarter_duration=3,
            midi_generator=ValueGenerator(cycle([60, 61, 64, 66])))
        cf_2 = ChordField(
            quarter_duration=6,
            midi_generator=ValueGenerator(cycle([72, 73, 74, 73, 72])),
            long_ending_mode='self_extend')

        cfg.add_child(cf_1)
        cfg.add_child(cf_2)

        xml_path = path + 'test_8.xml'
        simple_format = SimpleFormat()
        simple_format.extend(cf_1.simple_format)
        simple_format.extend(cf_2.simple_format)
        simple_format.to_stream_voice().add_to_score(self.score)
        self.score.write(xml_path)
        self.assertCompareFiles(xml_path)
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    def test_5(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.multi = (self.fm.multi[0], self.fm.multi[1] + 1)
        fm.midi_generator.midi_range = (62, 62 + 11)
        fm.midi_generator.microtone = 4
        fm.add_layer()
        fm.quantize_children(grid_size=1)
        selected_nodes = fm.get_children()[2:5]

        proportions = (1, 10, 1, 7, 1)
        breakpoints = (1, Fraction(1, 7), 1)
        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 = 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(
                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_5.xml'
        partwise.write(xml_path)
        self.assertCompareFiles(xml_path)
Exemplo n.º 8
0
    def test_11(self):
        cfg = ChordField(
            duration_generator=ValueGenerator(
                RandomInterpolation(start=[0.25, 0.25, 0.5], end=[0.5, 0.75, 1], seed=20)))
        cf_1 = ChordField(
            quarter_duration=3,
            midi_generator=ValueGenerator(cycle([60, 61, 64, 66])))
        cf_2 = ChordField(
            quarter_duration=6,
            midi_generator=ValueGenerator(cycle([72, 73, 74, 73, 72])),
            long_ending_mode='self_extend')

        cfg.add_child(cf_1)
        cfg.add_child(cf_2)
        xml_path = path + 'test_11.xml'
        copied = cfg.__deepcopy__()
        copied.simple_format.to_stream_voice().add_to_score(self.score)
        self.score.write(xml_path)
        self.assertCompareFiles(xml_path)
Exemplo n.º 9
0
    def test_3(self):
        def get_children_midis(node):
            copy = node.__deepcopy__()
            copy.midi_generator.midi_range = node.midi_generator.midi_range
            copy.add_layer()

            output = [child.chord.midis[0].value for child in copy.get_children()]
            return output

        self.fm.multi = (self.fm.multi[0], self.fm.multi[1] + 1)
        self.fm.midi_generator.midi_range = (60, 72)
        self.fm.add_layer()
        self.fm.quantize_children(grid_size=1)
        proportions = (1, 3, 1, 3, 1)
        breakpoints = (1, Fraction(1, 7), 1)
        selected_nodes = self.fm.get_children()[:2]
        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 = get_children_midis(node)
            next_node = node.next_sibling
            if next_node:
                end_chord = get_children_midis(next_node)
            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 = self.fm.get_score(show_fractal_orders=True, layer_number=self.fm.number_of_layers)
        score.max_division = 7
        xml_path = path + '_test_3.xml'
        score.write(xml_path)
        self.assertCompareFiles(xml_path)
Exemplo n.º 10
0
    def test_3(self):
        # node.chord_fields are part of a group
        cfg = ChordField(
            duration_generator=ValueGenerator(RandomInterpolation(start=[0.25, 0.25], end=[0.75, 1], seed=20)))
        cf_1 = ChordField(
            midi_generator=ValueGenerator(cycle([60])))
        cf_2 = ChordField(
            midi_generator=ValueGenerator(cycle([72])),
            long_ending_mode='cut')

        cfg.add_child(cf_1)
        cfg.add_child(cf_2)

        fm = FractalMusic(quarter_duration=20, tempo=80)
        fm.add_layer()
        fm.get_children()[0].chord_field = cf_1
        fm.get_children()[1].chord_field = cf_2
        score = fm.get_score(show_fractal_orders=True)
        xml_path = path + 'test_3.xml'
        score.write(xml_path)
        self.assertCompareFiles(xml_path)
Exemplo n.º 11
0
        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