Example #1
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)
Example #2
0
 def test_1(self):
     self.fm.split(1, 2)
     score = TreeScoreTimewise()
     self.fm.get_score(score)
     xml_path = path + '_test_1.xml'
     score.write(xml_path)
     self.assertCompareFiles(xml_path)
Example #3
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)
Example #4
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)
Example #5
0
 def test_2(self):
     self.fm.split(1, 2)[1].chord.to_rest()
     score = TreeScoreTimewise()
     self.fm.get_score(score)
     xml_path = path + '_test_2.xml'
     score.write(xml_path)
     self.assertCompareFiles(xml_path)
Example #6
0
    def test_1(self):
        fm = self.fm
        fm.add_layer()

        fm.add_layer(lambda n: True if n.fractal_order > 1 else False)
        fm.add_layer(lambda n: True if n.fractal_order > 1 else False)
        fm.add_layer(lambda n: True if n.fractal_order > 1 else False)
        # for node in fm.traverse():
        #     node.chord.add_words(node.midi_generator.midi_range)
        fm.add_layer(lambda n: True if n.fractal_order > 1 else False)

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

        score = TreeScoreTimewise()
        score = fm.get_score(score=score, show_fractal_orders=False)

        text_path = path + '_test_1.txt'
        fm.write_infos(text_path)
        self.assertCompareFiles(actual_file_path=text_path)

        xml_path = path + '_test_1.xml'
        score.write(path=xml_path)
        self.assertCompareFiles(actual_file_path=xml_path)
Example #7
0
 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__()
Example #8
0
 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])
Example #9
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
Example #10
0
    def test_1(self):
        section_score_1 = TreeScoreTimewise()
        sf = SimpleFormat(quarter_durations=[1, 3, 2])
        section_score_1.set_time_signatures(
            quarter_durations=sf.quarter_duration, barline_style='light-light')
        sf.to_stream_voice().add_to_score(section_score_1)

        section_score_2 = TreeScoreTimewise()
        sf = SimpleFormat(quarter_durations=[2, 1, 3])
        section_score_2.set_time_signatures(
            quarter_durations=sf.quarter_duration, barline_style='heavy')
        sf.to_stream_voice().add_to_score(section_score_2)

        self.main_score.extend(section_score_1)
        self.main_score.extend(section_score_2)

        xml_path = path + '_test_1.xml'
        self.main_score.write(path=xml_path)
        TestScore().assert_template(result_path=xml_path)
Example #11
0
 def setUp(self) -> None:
     self.score = TreeScoreTimewise()
     sf = SimpleFormat(quarter_durations=[4])
     sf.to_stream_voice().add_to_score(self.score, part_number=1)
     sf.to_stream_voice().add_to_score(self.score, part_number=2)
     sf.to_stream_voice().add_to_score(self.score, part_number=3)
     sf.to_stream_voice().add_to_score(self.score, part_number=4)
     self.score.get_score_parts()[0].instrument = Violin(1)
     self.score.get_score_parts()[1].instrument = Violin(2)
     self.score.get_score_parts()[2].instrument = Viola()
     self.score.get_score_parts()[3].instrument = Cello()
Example #12
0
    def test_1(self):
        score = TreeScoreTimewise()

        sf = SimpleFormat(midis=[(60, 64, 68, 73)], quarter_durations=[4])
        sf.to_stream_voice().add_to_score(score=score)

        sf.chords[0].inverse()
        sf.to_stream_voice().add_to_score(score=score, part_number=2)

        xml_path = path + '.xml'
        score.write(xml_path)
        TestScore().assert_template(xml_path)
Example #13
0
    def setUp(self) -> None:
        self.score = TreeScoreTimewise()
        sf = SimpleFormat(quarter_durations=[1, 1])
        v = sf.to_stream_voice(1)
        v.add_to_score(self.score, part_number=1, first_measure=1)

        sf = SimpleFormat(quarter_durations=[1, 1])
        v = sf.to_stream_voice(2)
        v.add_to_score(self.score, part_number=1, first_measure=1)

        sf = SimpleFormat(quarter_durations=[1, 1])
        v = sf.to_stream_voice(1)
        v.add_to_score(self.score, part_number=2, first_measure=2)
Example #14
0
    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)
Example #15
0
    def test_3(self):
        for leaf in self.fm.traverse_leaves():
            leaf.chord.add_words(leaf.fractal_order)

        copied = self.fm.__deepcopy__()
        copied.get_simple_format().to_stream_voice().add_to_score(self.score)
        xml_path = path + '_test_3.xml'
        self.score.write(xml_path)
        expected_path = path + '_test_3_expected.xml'
        expected_score = TreeScoreTimewise()
        self.fm.get_simple_format().to_stream_voice().add_to_score(
            expected_score)
        expected_score.write(expected_path)
        self.assertCompareFiles(xml_path, expected_path)
Example #16
0
    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)
Example #17
0
    def test_2(self):
        # needed because of wrong system breaks
        section_score = TreeScoreTimewise()
        sf = SimpleFormat(quarter_durations=2 * [5, 4, 3, 2, 1])
        section_score.set_time_signatures(
            quarter_durations=sf.quarter_duration, barline_style='light-light')
        sf.to_stream_voice().add_to_score(section_score)
        # section_xml_path = path + '_test_2_section.xml'
        # section_score.write(path=section_xml_path)

        self.main_score.extend(section_score)
        main_xml_path = path + '_test_2_main.xml'
        self.main_score.write(path=main_xml_path)

        TestScore().assert_template(result_path=main_xml_path)
Example #18
0
 def test_3(self):
     xml_path = path + '_test_3.xml'
     score = TreeScoreTimewise()
     gw = GearWheels(wheels=[Wheel(3), Wheel(4), Wheel(5)])
     sfs = []
     for index, wheel in enumerate(gw.wheels):
         quarter_durations = xToD(wheel.get_position_values())
         midis = len(quarter_durations) * [60 + index]
         sf = SimpleFormat(quarter_durations=quarter_durations, midis=midis)
         sfs.append(sf)
         sf.to_stream_voice().add_to_score(score, part_number=index + 1)
     sf = SimpleFormat.sum(*sfs)
     sf.to_stream_voice().add_to_score(score,
                                       part_number=len(gw.wheels) + 1)
     score.write(xml_path)
     self.assertCompareFiles(xml_path)
Example #19
0
    def get_score_template(self):
        score = TreeScoreTimewise()
        score.tuplet_line_width = 2.4
        score.page_style.orientation = 'landscape'
        score.page_style.system_distance = 180
        score.page_style.staff_distance = 150
        score.page_style.top_system_distance = 150
        score.page_style.bottom_margin = 100

        score.add_title('module: {}'.format(self.name))
        rounded_duration = round(float(self.duration), 1)
        if rounded_duration == int(rounded_duration):
            rounded_duration = int(rounded_duration)

        clock = Timing.get_clock(rounded_duration, mode='msreduced')
        score.add_subtitle('duration: {}'.format(clock))
        score.accidental_mode = 'modern'
        return score
Example #20
0
    def test_17(self):
        self.fm_7.quarter_duration = 10
        score = TreeScoreTimewise()
        score.add_title('reduce sieve')
        score.page_style.orientation = 'portrait'
        score.set_time_signatures(barline_style='light-light',
                                  quarter_durations=self.fm_7.quarter_duration)
        for i in range(1, 8):
            fm = self.fm_7.__deepcopy__()
            fm.generate_children(number_of_children=i, mode='reduce_sieve')
            for leaf in fm.traverse_leaves():
                leaf.chord.add_lyric(leaf.fractal_order)
            sf = fm.get_simple_format(layer=fm.number_of_layers)
            sf.to_stream_voice().add_to_score(score, part_number=i)

        xml_path = path + '_test_17.xml'
        score.write(xml_path)
        self.assertCompareFiles(xml_path)
Example #21
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">
Example #22
0
    def test_1(self):

        self.fm.midi_generator.set_directions(1, 1, 1, 1)
        self.fm.add_layer()

        self.add_infos(self.fm)
        self.fm.add_layer()
        self.add_infos(self.fm)
        score = TreeScoreTimewise()
        score.page_style.staff_distance = 150

        for layer in range(self.fm.number_of_layers + 1):
            sf = self.fm.get_simple_format(layer=layer)
            v = sf.to_stream_voice(1)
            v.add_to_score(score, layer + 1)

        xml_path = path + '_test_1.xml'
        score.write(path=xml_path)
        self.assertCompareFiles(actual_file_path=xml_path)
Example #23
0
    def test_5(self):
        score = TreeScoreTimewise()

        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.midi_generator.microtone = 4
        fm.add_layer()

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

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

        fm.reduce_children(lambda child: child.fractal_order in [1])

        simple_format = fm.get_simple_format(1)
        v = simple_format.to_stream_voice(1)
        v.add_to_score(score, 2)

        fm.add_layer()

        for leaf in fm.traverse_leaves():
            leaf.chord.add_lyric(leaf.fractal_order)
            # leaf.chord.add_words(leaf.midi_generator.midi_range[1])

        simple_format = fm.get_simple_format(2)
        v = simple_format.to_stream_voice(1)
        v.add_to_score(score, 3)

        text_path = path + '_test_5.txt'
        fm.write_infos(text_path)
        self.assertCompareFiles(actual_file_path=text_path)

        xml_path = path + '_test_5.xml'
        score.max_division = 7
        score.write(xml_path)
        self.assertCompareFiles(actual_file_path=xml_path)
Example #24
0
    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)
Example #25
0
 def setUp(self) -> None:
     self.horn = NaturalHorn()
     self.score = TreeScoreTimewise()
Example #26
0
 def setUp(self) -> None:
     self.score = TreeScoreTimewise()
Example #27
0
from pathlib import Path

from musicscore.musicstream.streamvoice import SimpleFormat
from musicscore.musictree.treescoretimewise import TreeScoreTimewise
self_path = Path(__file__)

sf = SimpleFormat(midis=[60, 66, 64, 71], quarter_durations=[1, 2, 1.5, 3.5])

sf.chords[0].add_dynamics('ff')
sf.chords[0].add_articulation('staccato')
sf.chords[1].add_dynamics('pp')
sf.chords[1].add_slur('start')
sf.chords[-1].add_slur('stop')

score = TreeScoreTimewise()
sf.to_stream_voice().add_to_score(score)
xml_path = self_path.with_suffix('.xml')
score.write(path=xml_path)
Example #28
0
 def setUp(self) -> None:
     self.score = TreeScoreTimewise()
     self.sf = _generate_simple_format()
Example #29
0
 def setUp(self) -> None:
     self.sf = SimpleFormat([1, 2, 3, 4, 3, 2, 1])
     self.score = TreeScoreTimewise()
Example #30
0
 def setUp(self) -> None:
     self.score = TreeScoreTimewise()
     sf = SimpleFormat(
         quarter_durations=[4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4])
     v = sf.to_stream_voice(1)
     v.add_to_score(self.score)