コード例 #1
0
class Test(TestCase):
    def setUp(self) -> None:
        self.score = TreeScoreTimewise()

    def test_1(self):
        # sf = SimpleFormat(durations=[4, 4, 2, 1, 1.5, 1.8, 0.2, 0.4, 0.5, 1])
        sf = SimpleFormat(quarter_durations=[4, 4])

        for chord in sf.chords:
            # chord.add_flag(PizzFlag())
            chord.add_flag(PercussionFlag1())
        v = sf.to_stream_voice()
        self.score.set_time_signatures([4, 3, 1])
        v.add_to_score(self.score)
        result_path = path + '_test_1'

        # self.score.fill_with_rest()
        # self.score.add_beats()
        # self.score.quantize()
        # 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():
        #             new_chords = []
        #             for chord in beat.chords:
        #                 if chord.is_tied_to_previous:
        #                     chord.to_rest()
        #                     new_chords.append(chord)
        #
        #                 elif chord.position_in_beat == 0:
        #                     split = [chord]
        #                     if chord.quarter_duration == 1:
        #                         split = chord.split(1, 1)
        #                     elif chord.quarter_duration == 2:
        #                         split = chord.split(1, 3)
        #                     elif chord.quarter_duration == 3:
        #                         split = chord.split(1, 5)
        #                     elif chord.quarter_duration == 4:
        #                         split = chord.split(1, 7)
        #                     elif chord.quarter_duration == 6:
        #                         split = chord.split(1, 11)
        #                     else:
        #                         pass
        #                     try:
        #                         split[1].to_rest()
        #                     except IndexError:
        #                         pass
        #                     new_chords.extend(split)
        #                 else:
        #                     new_chords.append(chord)
        #             beat._chords = new_chords

        self.score.write(path=result_path)
コード例 #2
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)
コード例 #3
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)
コード例 #4
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)
コード例 #5
0
class Test(TestCase):
    def setUp(self) -> None:
        self.score = TreeScoreTimewise()

    def test_1(self):
        sf = SimpleFormat(quarter_durations=[1, 2, 3, 2, 1])
        sf.chords[1].add_child(Notehead('square'))
        sf.chords[2].add_child(Notehead('diamond'))
        sf.to_stream_voice().add_to_score(self.score)
        xml_path = path + '_test_1.xml'
        self.score.write(xml_path)
        TestScore().assert_template(xml_path)

    def test_2(self):
        sf = SimpleFormat(midis=[(60, 62, 63)], quarter_durations=[4])
        sf.chords[0].add_child(Notehead('diamond'))
        sf.to_stream_voice().add_to_score(self.score)
        xml_path = path + '_test_2.xml'
        self.score.write(xml_path)
        TestScore().assert_template(xml_path)

    def test_3(self):
        sf = SimpleFormat(midis=[(60, 62, 63)], quarter_durations=[4])
        sf.chords[0].midis[0].notehead = Notehead('diamond')
        sf.chords[0].midis[1].notehead = Notehead('square')
        sf.chords[0].midis[2].notehead = Notehead('normal')
        sf.to_stream_voice().add_to_score(self.score)
        xml_path = path + '_test_3.xml'
        self.score.write(xml_path)
        TestScore().assert_template(xml_path)

    def test_4(self):
        sf = SimpleFormat()
        for notehead in TypeNoteheadValue._PERMITTED:
            sf.add_chord(TreeChord(quarter_duration=1))
            sf.chords[-1].midis[0].notehead = Notehead(notehead)
            sf.chords[-1].add_words(notehead)
            sf.add_chord(TreeChord(quarter_duration=2))
            sf.chords[-1].midis[0].notehead = Notehead(notehead)
        self.score.set_time_signatures(times={1: (3, 4)})
        sf.to_stream_voice().add_to_score(self.score)
        xml_path = path + '_test_4.xml'
        self.score.write(xml_path)
        TestScore().assert_template(xml_path)
コード例 #6
0
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)
コード例 #7
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)
コード例 #8
0
class Test(TestCase):
    def setUp(self) -> None:
        self.score = TreeScoreTimewise()

    def test_1(self):
        sf = SimpleFormat(quarter_durations=[4], midis=[(60, 65)])
        chord = sf.chords[0]
        notations = chord.add_child(Notations())
        technical = notations.add_child(Technical())
        harmonic = technical.add_child(Harmonic())
        harmonic.add_child(Artificial())
        harmonic.add_child(TouchingPitch())

        sf.to_stream_voice().add_to_score(self.score)

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

    def test_2(self):
        sf = SimpleFormat(quarter_durations=[1.5, 2, 3, 2.33, 3.66], midis=5 * [60])
        for chord in sf.chords:
            chord.add_harmonic(5)
        sf.to_stream_voice().add_to_score(self.score)

        xml_path = path + '_test_2.xml'
        self.score.write(xml_path)

    def test_3(self):
        midis = {
            'flat': [Midi(value, accidental=Accidental('flat', force_show=True)) for value in range(60, 72)],
            'sharp': [Midi(value, accidental=Accidental('sharp', force_show=True)) for value in range(60, 72)]
        }
        sf = SimpleFormat(midis=midis['flat'] + midis['sharp'])
        for chord in sf.chords:
            chord.add_harmonic(5)
        self.score.set_time_signatures(times={1: [12, 4]})
        sf.to_stream_voice().add_to_score(self.score)

        xml_path = path + '_test_3.xml'
        self.score.write(xml_path)
コード例 #9
0
class Test(TestCase):
    def setUp(self) -> None:
        self.score = TreeScoreTimewise()

    def test_1(self):
        sf = SimpleFormat(quarter_durations=[4, 4, 3, 2, 3, 4, 5, 6, 1, 2])
        self.score.set_time_signatures(quarter_durations=sf.quarter_duration)

        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)

    def test_2(self):
        sf = SimpleFormat(quarter_durations=[4, 4, 3, 2, 3, 4, 5, 6, 1, 2])
        self.score.set_time_signatures(times={1: (3, 4), 5: (2, 4)})

        v = sf.to_stream_voice(1)
        v.add_to_score(self.score)

        result_path = path + '_test_2'
        self.score.write(path=result_path)
        TestScore().assert_template(result_path=result_path)

    def test_3(self):
        sf = SimpleFormat(quarter_durations=[4, 4, 3, 2, 3, 4, 5, 6, 1, 2])
        self.score.set_time_signatures(quarter_durations=[8, 3, 5, 4, 11, 3])

        v = sf.to_stream_voice(1)
        v.add_to_score(self.score)

        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=[4, 4, 3, 2, 3, 4, 5, 6, 1, 2])
        self.score.set_time_signatures(quarter_durations=[8, 3, 5, 4, 11, 3],
                                       times={1: (3, 4)})

        v = sf.to_stream_voice(1)
        v.add_to_score(self.score)

        result_path = path + '_test_4'
        self.score.write(path=result_path)
        TestScore().assert_template(result_path=result_path)
コード例 #10
0
class Test(TestCase):
    def setUp(self) -> None:
        self.score = TreeScoreTimewise()

    def test_1(self):
        xml_path = path + '_test_1.xml'
        durations = [2, 1, 0.5, 0.25, 0.25, 4, 2, 3]
        sf = SimpleFormat(quarter_durations=durations)
        for chord in sf.chords:
            chord.add_flag(PercussionFlag1())

        sf.to_stream_voice().add_to_score(self.score)
        self.score.write(xml_path)
        TestScore().assert_template(xml_path)

    def test_2(self):
        xml_path = path + '_test_2.xml'
        durations = [2]
        sf = SimpleFormat(quarter_durations=durations)

        for chord in sf.chords:
            chord.add_flag(XFlag1())

        sf.to_stream_voice().add_to_score(self.score, part_number=1)

        self.score.write(xml_path)
        TestScore().assert_template(xml_path)

    def test_3(self):
        xml_path = path + '_test_3.xml'
        durations = [5]
        sf = SimpleFormat(quarter_durations=durations)

        for chord in sf.chords:
            chord.add_flag(XFlag1())

        sf.to_stream_voice().add_to_score(self.score, part_number=1)

        self.score.write(xml_path)
        TestScore().assert_template(xml_path)

    def test_4(self):
        xml_path = path + '_test_4.xml'
        durations = [2, 1, 0.5, 0.25, 0.25, 4, 2, 3]
        sf = SimpleFormat(quarter_durations=durations)
        sf.to_stream_voice().add_to_score(self.score, part_number=1)

        for chord in sf.chords:
            chord.add_flag(XFlag1())

        sf.to_stream_voice().add_to_score(self.score, part_number=2)

        self.score.write(xml_path)
        TestScore().assert_template(xml_path)

    def test_5(self):
        # todo: see template
        xml_path = path + '_test_5.xml'
        durations = [3.5]
        self.score.set_time_signatures(quarter_durations=[3.5])
        sf = SimpleFormat(quarter_durations=durations)
        sf.to_stream_voice().add_to_score(self.score, part_number=1)

        for chord in sf.chords:
            chord.add_flag(XFlag1())

        sf.to_stream_voice().add_to_score(self.score, part_number=2)

        self.score.write(xml_path)
        # TestScore().assert_template(xml_path)

    def test_6(self):
        self.maxDiff = None
        xml_path = path + '_test_6.xml'
        durations = 5 * [3.5]
        sf = SimpleFormat(quarter_durations=durations)
        sf.to_stream_voice().add_to_score(self.score, part_number=1)

        slur_type = cycle([None, 'tie', 'dashed'])
        for chord in sf.chords:
            type = slur_type.__next__()
            chord.add_flag(XFlag1(slur=type))
            chord.add_words(str(type))

        sf.to_stream_voice().add_to_score(self.score, part_number=2)

        self.score.write(xml_path)
        TestScore().assert_template(xml_path)

    def test_7(self):
        xml_path = path + "_test_7.xml"
        sf = SimpleFormat(midis=[60, 63], quarter_durations=[2, 5.33, 2.666])
        sf.chords[1].add_flag(BeatwiseFlag1())
        # sf.chords[1].add_flag(TreeFingerTremoloFlag(tremolo_chord=TreeChord(midis=57)))
        # sf.chords[1].add_flag(FingerTremoloFlag(tremolo_chord=TreeChord(midis=57)))
        sf.to_stream_voice().add_to_score(self.score)

        self.score.write(xml_path)
        TestScore().assert_template(xml_path)

    def test_8(self):
        xml_path = path + "_test_8.xml"
        sf = SimpleFormat(midis=[60, 63], quarter_durations=[2, 5.33, 2.666])
        sf.chords[1].add_flag(XFlag1(slur='dashed'))
        # sf.chords[1].add_flag(TreeFingerTremoloFlag(tremolo_chord=TreeChord(midis=57)))
        # sf.chords[1].add_flag(FingerTremoloFlag(tremolo_chord=TreeChord(midis=57)))
        sf.to_stream_voice().add_to_score(self.score)

        self.score.write(xml_path)
        TestScore().assert_template(xml_path)

    def test_9(self):
        xml_path = path + "_test_9.xml"
        sf = SimpleFormat(midis=[60, 63], quarter_durations=[2, 5.33, 2.666])
        sf.chords[1].add_flag(FingerTremoloFlag1(tremolo_chord=TreeChord(midis=57), mode='modern'))
        sf.to_stream_voice().add_to_score(self.score)

        self.score.write(xml_path)
        TestScore().assert_template(xml_path)

    def test_10(self):
        xml_path = path + "_test_10.xml"
        sf = SimpleFormat(midis=[84, 84, 84], quarter_durations=[2, 5.33, 2.666])
        sf.to_stream_voice(1).add_to_score(self.score, first_measure=1)

        sf = SimpleFormat(midis=[60, 63], quarter_durations=[2, 5.33, 2.666])
        sf.chords[1].add_flag(FingerTremoloFlag1(tremolo_chord=TreeChord(midis=68), mode='modern'))
        sf.to_stream_voice(2).add_to_score(self.score, first_measure=1)

        self.score.write(xml_path)
        TestScore().assert_template(xml_path)

    def test_11(self):
        xml_path = path + "_test_11.xml"
        sf = SimpleFormat(midis=[60, 60, 60, 60, 60, 60, 60],
                          quarter_durations=[Fraction(3, 2), Fraction(3, 2), Fraction(1, 2), Fraction(1, 2), 1, Fraction(1, 2),
                                             Fraction(3, 2)])
        for ch in sf.chords:
            ch.add_flag(FingerTremoloFlag1(TreeChord(midis=[63]), mode='modern'))
        sf.to_stream_voice(1).add_to_score(self.score, first_measure=1)

        self.score.write(xml_path)
        TestScore().assert_template(xml_path)

    def test_12(self):
        xml_path = path + "_test_12.xml"
        sf = SimpleFormat(midis=[60, 60, 60, 60],
                          quarter_durations=[1, 1, 1, 1])
        for ch in sf.chords:
            ch.add_flag(FingerTremoloFlag1(TreeChord(midis=[63]), mode='modern'))
        sf.to_stream_voice(1).add_to_score(self.score, first_measure=1)
        self.score.accidental_mode = 'modern'
        self.score.write(xml_path)
        TestScore().assert_template(xml_path)

    def test_13(self):
        xml_path = path + "_test_13.xml"
        sf = SimpleFormat(midis=[60, 60, 60, 60],
                          quarter_durations=[1, 1, 1, 1])
        for ch in sf.chords:
            ch.add_flag(FingerTremoloFlag1(TreeChord(midis=[63]), mode='conventional'))
        sf.to_stream_voice(1).add_to_score(self.score, first_measure=1)
        self.score.accidental_mode = 'modern'
        self.score.write(xml_path)
        TestScore().assert_template(xml_path)

    def test_14(self):
        xml_path = path + "_test_14.xml"
        sf = SimpleFormat(midis=[60, 60, 60, 60],
                          quarter_durations=[2, 2, 2, 2])
        for ch in sf.chords:
            ch.add_flag(FingerTremoloFlag1(TreeChord(midis=[63]), mode='conventional'))
        sf.to_stream_voice(1).add_to_score(self.score, first_measure=1)
        self.score.accidental_mode = 'modern'
        self.score.write(xml_path)
        TestScore().assert_template(xml_path)

    def test_15(self):
        xml_path = path + "_test_15.xml"
        sf = SimpleFormat(midis=[60],
                          quarter_durations=[0.5])
        for ch in sf.chords:
            ch.add_flag(FingerTremoloFlag1(TreeChord(midis=[63]), mode='conventional'))
        sf.to_stream_voice(1).add_to_score(self.score, first_measure=1)
        self.score.accidental_mode = 'modern'
        self.score.write(xml_path)
        TestScore().assert_template(xml_path)

    def test_16(self):
        xml_path = path + "_test_16.xml"
        sf = SimpleFormat(midis=[60],
                          quarter_durations=[1.5])
        for ch in sf.chords:
            ch.add_flag(FingerTremoloFlag1(TreeChord(midis=[63]), mode='conventional'))
        sf.to_stream_voice(1).add_to_score(self.score, first_measure=1)
        self.score.accidental_mode = 'modern'
        self.score.write(xml_path)
        TestScore().assert_template(xml_path)

    def test_17(self):
        xml_path = path + "_test_17.xml"
        sf = SimpleFormat(midis=[60, 61, 62, 63, 64],
                          quarter_durations=[1.5, 1, 2, 2.5, 1])
        for ch in sf.chords:
            ch.add_flag(FingerTremoloFlag1(TreeChord(midis=[67]), mode='conventional'))
        sf.to_stream_voice(1).add_to_score(self.score, first_measure=1)
        self.score.accidental_mode = 'modern'
        self.score.write(xml_path)
        # TestScore().assert_template(xml_path)

    def test_18(self):
        xml_path = path + "_test_18.xml"
        sf = SimpleFormat(midis=[60, 61, 62],
                          quarter_durations=[5, 5.5, 2.5])
        for ch in sf.chords:
            ch.add_flag(GlissFlag1())
        sf.to_stream_voice(1).add_to_score(self.score, first_measure=1)
        self.score.accidental_mode = 'modern'
        self.score.write(xml_path)
        # TestScore().assert_template(xml_path)

    def test_19(self):
        xml_path = path + "_test_19.xml"
        sf = SimpleFormat(quarter_durations=[1.5])
        self.score.set_time_signatures(quarter_durations=[1.5])
        for ch in sf.chords:
            ch.add_flag(BeatwiseFlag1(slur='tie'))
        sf.to_stream_voice().add_to_score(self.score)

        self.score.write(xml_path)
        # TestScore().assert_template(xml_path)

    def test_20(self):
        xml_path = path + "_test_20.xml"
        sf = SimpleFormat(quarter_durations=[3])
        self.score.set_time_signatures(quarter_durations=[3])
        for ch in sf.chords:
            ch.add_flag(PercussionFlag1(minimum_duration=0.5))
        sf.to_stream_voice().add_to_score(self.score)
        self.score.write(xml_path)
        TestScore().assert_template(xml_path)

    def test_21(self):
        xml_path = path + "_test_21.xml"
        sf = SimpleFormat(quarter_durations=[2, 2])
        sf.chords[0].add_flag(PercussionFlag1(minimum_duration=0.5))
        sf.to_stream_voice().add_to_score(self.score)
        self.score.write(xml_path)
        TestScore().assert_template(xml_path)
コード例 #11
0
import os

from musicscore.musicstream.streamvoice import SimpleFormat
from musicscore.musictree.treescoretimewise import TreeScoreTimewise
path = str(os.path.abspath(__file__).split('.')[0])
xml_path = path + '.xml'
score = TreeScoreTimewise()
quarter_durations = [1, 1-0.01, 0.01]
sf = SimpleFormat(quarter_durations=quarter_durations)
score.set_time_signatures(round(sum(quarter_durations)))
sf.to_stream_voice().add_to_score(score)
#
# score.update_measures()
# score.fill_with_rest()
# # score.preliminary_adjoin_rests()
# # score.add_beats()
# # score.quantize()
# print([float(chord.quarter_duration) for chord in score.get_measure(1).get_part(1).chords])
score.write(xml_path)
コード例 #12
0
class Test(TestCase):
    def setUp(self) -> None:
        self.score = TreeScoreTimewise()

    def test_1(self):
        # chord_generator with matching quarter_duration
        field = ChordField(
            quarter_duration=11,
            chord_generator=ValueGenerator(
                iter(
                    SimpleFormat(
                        quarter_durations=[3, 2, 1, 2, 3, 4, 5]).chords)))
        self.score.set_time_signatures(
            quarter_durations=field.quarter_duration)
        field.simple_format.to_stream_voice().add_to_score(self.score)

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

    def test_2(self):
        # chord_generator with too long quarter_duration:  mode : None
        field = ChordField(
            quarter_duration=10,
            chord_generator=ValueGenerator(
                iter(
                    SimpleFormat(
                        quarter_durations=[3, 2, 1, 2, 3, 4, 5]).chords)))
        with self.assertRaises(LongEndingError):
            list(field)

    def test_3(self):
        # chord_generator with too long quarter_duration:  mode : self_extend
        field = ChordField(
            quarter_duration=10,
            chord_generator=ValueGenerator(
                iter(
                    SimpleFormat(
                        quarter_durations=[3, 2, 1, 2, 3, 4, 5]).chords)),
            long_ending_mode='self_extend')
        sf = field.simple_format
        self.score.set_time_signatures(
            quarter_durations=field.quarter_duration)
        sf.to_stream_voice().add_to_score(self.score)

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

    def test_4(self):
        # chord_generator with too long quarter_duration:  mode : cut
        field = ChordField(
            quarter_duration=10,
            chord_generator=ValueGenerator(
                iter(
                    SimpleFormat(
                        quarter_durations=[3, 2, 1, 2, 3, 4, 5]).chords)),
            long_ending_mode='cut')
        sf = field.simple_format
        self.score.set_time_signatures(
            quarter_durations=field.quarter_duration)
        sf.to_stream_voice().add_to_score(self.score)

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

    def test_5(self):
        # chord_generator with too long quarter_duration:  mode : omit
        field = ChordField(
            quarter_duration=10,
            chord_generator=ValueGenerator(
                iter(
                    SimpleFormat(
                        quarter_durations=[3, 2, 1, 2, 3, 4, 5]).chords)),
            long_ending_mode='omit')
        sf = field.simple_format
        self.score.set_time_signatures(
            quarter_durations=field.quarter_duration)
        sf.to_stream_voice().add_to_score(self.score)

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

    def test_6(self):
        # chord_generator with too long quarter_duration:  mode : omit
        field = ChordField(
            quarter_duration=10,
            chord_generator=ValueGenerator(
                iter(
                    SimpleFormat(
                        quarter_durations=[3, 2, 1, 2, 3, 4, 5]).chords)),
            long_ending_mode='omit_and_add_rest')
        sf = field.simple_format
        self.score.set_time_signatures(
            quarter_durations=field.quarter_duration)
        sf.to_stream_voice().add_to_score(self.score)

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

    def test_7(self):
        # chord_generator with too long quarter_duration:  mode : omit
        field = ChordField(
            quarter_duration=10,
            chord_generator=ValueGenerator(
                iter(
                    SimpleFormat(
                        quarter_durations=[3, 2, 1, 2, 3, 4, 5]).chords)),
            long_ending_mode='omit_and_stretch')
        sf = field.simple_format
        self.score.set_time_signatures(
            quarter_durations=field.quarter_duration)
        sf.to_stream_voice().add_to_score(self.score)

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

    def test_8(self):
        # chord_generator with too short quarter_duration:  mode : None
        field = ChordField(
            quarter_duration=10,
            chord_generator=ValueGenerator(
                iter(SimpleFormat(quarter_durations=[3, 2]).chords)))
        with self.assertRaises(ShortEndingError):
            list(field)

    def test_9(self):
        # chord_generator with too short quarter_duration:  mode : self_shrink
        field = ChordField(
            quarter_duration=10,
            chord_generator=ValueGenerator(
                iter(SimpleFormat(quarter_durations=[3, 2]).chords)),
            short_ending_mode='self_shrink')
        sf = field.simple_format
        self.score.set_time_signatures(
            quarter_durations=field.quarter_duration)
        sf.to_stream_voice().add_to_score(self.score)

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

    def test_10(self):
        # chord_generator with too short quarter_duration:  mode : stretch
        field = ChordField(
            quarter_duration=10,
            chord_generator=ValueGenerator(
                iter(SimpleFormat(quarter_durations=[3, 2]).chords)),
            short_ending_mode='stretch')
        sf = field.simple_format
        self.score.set_time_signatures(
            quarter_durations=field.quarter_duration)
        sf.to_stream_voice().add_to_score(self.score)

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

    def test_11(self):
        # chord_generator with too short quarter_duration:  mode : rest
        field = ChordField(
            quarter_duration=10,
            chord_generator=ValueGenerator(
                iter(SimpleFormat(quarter_durations=[3, 2]).chords)),
            short_ending_mode='add_rest')
        sf = field.simple_format
        self.score.set_time_signatures(
            quarter_durations=field.quarter_duration)
        sf.to_stream_voice().add_to_score(self.score)

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

    def test_12(self):
        field = ChordField(quarter_duration=10,
                           duration_generator=ValueGenerator(cycle([1])),
                           midi_generator=ValueGenerator(cycle([71])))
        sf = field.simple_format
        self.score.set_time_signatures(
            quarter_durations=field.quarter_duration)
        sf.to_stream_voice().add_to_score(self.score)
        xml_path = path + '_test_12.xml'
        self.score.write(xml_path)
        self.assertCompareFiles(xml_path)

    def test_13(self):
        field = ChordField(quarter_duration=10,
                           duration_generator=ValueGenerator(
                               Random(pool=[0.2, 0.4, 0.8, 1.2, 1.6, 2],
                                      periodicity=3,
                                      seed=20)),
                           midi_generator=ValueGenerator(cycle([71])),
                           long_ending_mode='self_extend')
        sf = field.simple_format
        self.score.set_time_signatures(
            quarter_durations=ceil(field.quarter_duration))
        sf.to_stream_voice().add_to_score(self.score)
        xml_path = path + '_test_13.xml'
        self.score.write(xml_path)
        self.assertCompareFiles(xml_path)

    def test_14(self):
        field = ChordField(quarter_duration=10,
                           duration_generator=ValueGenerator(
                               duration_generator(first_duration=1,
                                                  delta=0.2)),
                           midi_generator=ValueGenerator(cycle([71])),
                           long_ending_mode='omit_and_add_rest')
        sf = field.simple_format
        self.score.set_time_signatures(
            quarter_durations=ceil(field.quarter_duration))
        sf.to_stream_voice().add_to_score(self.score)
        xml_path = path + '_test_14.xml'
        self.score.write(xml_path)
        self.assertCompareFiles(xml_path)

    def test_15(self):
        field = ChordField(quarter_duration=10,
                           duration_generator=ValueGenerator(
                               Random(pool=[0.2, 0.4, 0.8, 1.2, 1.6, 2],
                                      periodicity=3,
                                      seed=20)),
                           midi_generator=ValueGenerator(
                               Interpolation(start=84,
                                             end=60,
                                             key=lambda x: int(x))),
                           long_ending_mode='self_extend')
        sf = field.simple_format
        self.score.set_time_signatures(
            quarter_durations=ceil(field.quarter_duration))
        sf.to_stream_voice().add_to_score(self.score)
        xml_path = path + '_test_15.xml'
        self.score.write(xml_path)
        self.assertCompareFiles(xml_path)

    def test_16(self):
        field = ChordField(quarter_duration=10,
                           duration_generator=ValueGenerator(
                               ArithmeticProgression(a1=0.2,
                                                     an=2,
                                                     correct_s=True)),
                           midi_generator=ValueGenerator(
                               Interpolation(
                                   start=84,
                                   end=60,
                                   key=lambda midi: round(midi * 2) / 2)),
                           short_ending_mode=None)

        sf = field.simple_format
        self.score.set_time_signatures(
            quarter_durations=ceil(field.quarter_duration))
        sf.to_stream_voice().add_to_score(self.score)
        xml_path = path + '_test_16.xml'
        self.score.write(xml_path)
        self.assertCompareFiles(xml_path)

    def test_17(self):
        parent_field = ChordField()
        child_field_1 = ChordField(quarter_duration=5,
                                   duration_generator=ValueGenerator(cycle(
                                       [1])),
                                   midi_generator=ValueGenerator(cycle([60])))
        child_field_2 = ChordField(quarter_duration=10,
                                   duration_generator=ValueGenerator(cycle(
                                       [2])),
                                   midi_generator=ValueGenerator(cycle([61])))
        parent_field.add_child(child_field_1)
        parent_field.add_child(child_field_2)

        sf = parent_field.simple_format
        self.score.set_time_signatures(
            quarter_durations=ceil(parent_field.quarter_duration))
        sf.to_stream_voice().add_to_score(self.score)
        xml_path = path + '_test_17.xml'
        self.score.write(xml_path)
        self.assertCompareFiles(xml_path)
コード例 #13
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)
コード例 #14
0
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)
コード例 #15
0
class Test(TestCase):
    def setUp(self) -> None:
        self.score = TreeScoreTimewise()

    def make_t(self, *args):
        sf = SimpleFormat(quarter_durations=[1, 1, 1, 1], midis=[0, 0, 0, 0])
        for i in range(3):
            sf.chords[i].is_adjoinable = args[i]
        v = sf.to_stream_voice(1)
        v.add_to_score(self.score)
        self.score.add_subtitle(
            str([chord.is_adjoinable for chord in sf.chords]))

    def test_1(self):
        self.make_t(False, False, False)
        result_path = path + '_test_1'
        self.score.write(path=result_path)
        TestScore().assert_template(result_path=result_path)

    def test_2(self):
        self.make_t(False, False, True)
        result_path = path + '_test_2'
        self.score.write(path=result_path)
        TestScore().assert_template(result_path=result_path)

    def test_3(self):
        self.make_t(False, True, False)
        result_path = path + '_test_3'
        self.score.write(path=result_path)
        TestScore().assert_template(result_path=result_path)

    def test_4(self):
        self.make_t(False, True, True)
        result_path = path + '_test_4'
        self.score.write(path=result_path)
        TestScore().assert_template(result_path=result_path)

    def test_5(self):
        self.make_t(True, False, False)
        result_path = path + '_test_5'
        self.score.write(path=result_path)
        TestScore().assert_template(result_path=result_path)

    def test_6(self):
        self.make_t(True, False, True)
        result_path = path + '_test_6'
        self.score.write(path=result_path)
        TestScore().assert_template(result_path=result_path)

    def test_7(self):
        self.make_t(True, True, False)
        result_path = path + '_test_7'
        self.score.write(path=result_path)
        TestScore().assert_template(result_path=result_path)

    def test_8(self):
        self.make_t(True, True, True)
        result_path = path + '_test_8'
        self.score.write(path=result_path)
        TestScore().assert_template(result_path=result_path)

    def test_9(self):
        sf = SimpleFormat(quarter_durations=[0.2, 0.8, 1, 1],
                          midis=[0, 0, 0, 60])
        sf.to_stream_voice().add_to_score(self.score)
        result_path = path + '_test_9'
        self.score.write(path=result_path)
        # TestScore().assert_template(result_path=result_path)

    def test_10(self):
        sf = SimpleFormat(quarter_durations=[0.5, 2.5], midis=[60, 0])
        self.score.set_time_signatures(quarter_durations=[3])
        sf.to_stream_voice().add_to_score(self.score)
        result_path = path + '_test_10'
        self.score.write(path=result_path)
コード例 #16
0
class Test(TestCase):
    def setUp(self) -> None:
        self.score = TreeScoreTimewise()

    def test_1(self):
        # fields: midi_generators
        # group: no generators
        cfg = ChordField()
        cf_1 = ChordField(quarter_duration=3,
                          midi_generator=ValueGenerator(cycle([60, 61, 64, 66])),
                          duration_generator=ValueGenerator(cycle([1]))
                          )
        cf_2 = ChordField(quarter_duration=6,
                          midi_generator=ValueGenerator(cycle([72, 73, 74, 73, 72])),
                          duration_generator=ValueGenerator(cycle([1]))
                          )
        cfg.add_child(cf_1)
        cfg.add_child(cf_2)
        xml_path = path + 'test_1.xml'
        cfg.simple_format.to_stream_voice().add_to_score(self.score)
        self.score.write(xml_path)
        self.assertCompareFiles(xml_path)

    def test_2(self):
        # fields: midi_generators
        # group: duration_generator with __next__
        cfg = ChordField(
            duration_generator=ValueGenerator(Random(pool=[0.2, 0.4, 0.8, 1.6], seed=10))
        )
        cf_1 = ChordField(quarter_duration=3,
                          midi_generator=ValueGenerator(cycle([60, 61, 64, 66])),
                          long_ending_mode='self_extend'
                          )
        cf_2 = ChordField(quarter_duration=6,
                          midi_generator=ValueGenerator(cycle([72, 73, 74, 73, 72])),
                          long_ending_mode='self_extend')

        # cfg = ChordFieldGroup(duration_generator=Random(pool=[0.2, 0.4, 0.8, 1.6], seed=10))
        cfg.add_child(cf_1)
        cfg.add_child(cf_2)
        simple_format = cfg.simple_format
        self.score.set_time_signatures(quarter_durations=ceil(cfg.quarter_duration))
        xml_path = path + 'test_2.xml'
        simple_format.to_stream_voice().add_to_score(self.score)
        self.score.write(xml_path)
        self.assertCompareFiles(xml_path)

    def test_3(self):
        # fields: both with midi_generators, one duration_generator
        # group: duration_generator with __next__ (Random)
        cfg = ChordField(
            duration_generator=ValueGenerator(Random(pool=[0.2, 0.4, 0.8, 1.6], seed=10))
        )

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

        cfg.add_child(cf_1)
        cfg.add_child(cf_2)
        sf_1 = cf_1.simple_format
        sf_2 = cf_2.simple_format
        sf = SimpleFormat()
        sf.extend(sf_1)
        sf.extend(sf_2)
        xml_path = path + 'test_3.xml'
        # cfg.simple_format.to_stream_voice().add_to_score(self.score)
        sf.to_stream_voice().add_to_score(self.score)
        self.score.write(xml_path)
        self.assertCompareFiles(xml_path)

    def test_4(self):
        # fields: midi_generators, first one with ending_mode 'post'
        # group: duration_generator with __next__ (Arithmetic Progression)
        cfg = ChordField(
            duration_generator=ValueGenerator(ArithmeticProgression(a1=0.3, an=1.5, correct_s=True))
        )

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

                          )
        cfg.add_child(cf_1)
        cfg.add_child(cf_2)
        sf = SimpleFormat()
        sf.extend(cf_1.simple_format)
        sf.extend(cf_2.simple_format)
        xml_path = path + 'test_4.xml'
        sf.to_stream_voice().add_to_score(self.score)
        self.score.write(xml_path)
        self.assertCompareFiles(xml_path)

    def test_5(self):
        # breathing manually
        times = [3, 7, 3, 10, 3]
        cf_1 = ChordField(quarter_duration=times[0],
                          midi_generator=ValueGenerator(cycle([72, 73, 74, 73, 72])))
        cf_2 = ChordField(quarter_duration=times[1],
                          midi_generator=ValueGenerator(cycle([72, 73, 74, 73, 72])))
        cf_3 = ChordField(quarter_duration=times[2],
                          midi_generator=ValueGenerator(cycle([72, 73, 74, 73, 72])))
        cf_4 = ChordField(quarter_duration=times[3],
                          midi_generator=ValueGenerator(cycle([72, 73, 74, 73, 72])))
        cf_5 = ChordField(quarter_duration=times[4],
                          midi_generator=ValueGenerator(cycle([72, 73, 74, 73, 72])))
        points = [1.5, 0.2, 1.5]
        cf_1.duration_generator = ValueGenerator(ArithmeticProgression(a1=points[0], an=points[0], correct_s=True))
        cf_2.duration_generator = ValueGenerator(ArithmeticProgression(a1=points[0], an=points[1], correct_s=True))
        cf_3.duration_generator = ValueGenerator(ArithmeticProgression(a1=points[1], an=points[1], correct_s=True))
        cf_4.duration_generator = ValueGenerator(ArithmeticProgression(a1=points[1], an=points[0], correct_s=True))
        cf_5.duration_generator = ValueGenerator(ArithmeticProgression(a1=points[0], an=points[0], correct_s=True))
        cfg = ChordField()
        cfg.add_child(cf_1)
        cfg.add_child(cf_2)
        cfg.add_child(cf_3)
        cfg.add_child(cf_4)
        cfg.add_child(cf_5)
        #
        # for fractal_tree in cfg.children:
        #     print(fractal_tree.duration_generator.generator.parameters_dict)
        #     values = [float(chord.quarter_duration) for chord in list(fractal_tree)]
        #     print(values)
        #     print(sum(values))

        xml_path = path + 'test_5.xml'
        self.score.set_time_signatures(quarter_durations=times)
        cfg.simple_format.to_stream_voice().add_to_score(self.score, part_number=1)

        self.score.max_division = 5
        self.score.write(xml_path)
        self.assertCompareFiles(xml_path)

    def test_6(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
        xml_path = path + 'test_6.xml'
        self.score.set_time_signatures(quarter_durations=breathing_proportions)
        breathing.simple_format.to_stream_voice().add_to_score(self.score)

        self.score.max_division = 5
        self.score.write(xml_path)
        self.assertCompareFiles(xml_path)

    def test_7(self):
        # fields: midi_generators
        # group: duration_generator with __call__ RandomInterpolation
        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_7.xml'
        cfg.simple_format.to_stream_voice().add_to_score(self.score)
        self.score.write(xml_path)
        self.assertCompareFiles(xml_path)

    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)

    def test_9(self):
        # fields: duration_generators
        # group: midi_generator
        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 = ValueGenerator(cycle([60]))
        simple_format = cfg.simple_format
        self.score.set_time_signatures(quarter_durations=ceil(cfg.quarter_duration))
        xml_path = path + 'test_9.xml'
        simple_format.to_stream_voice().add_to_score(self.score)
        self.score.write(xml_path)
        self.assertCompareFiles(xml_path)

    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__()

    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)

    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)

    def test_13(self):
        proportions = (1, 3, 1, 5, 1)
        breakpoints = (1, Fraction(1, 7), 1)
        breathe = Breathe(proportions=proportions, breakpoints=breakpoints, quarter_duration=20)
        expected = 20
        actual = breathe.quarter_duration
        self.assertEqual(expected, actual)

    def test_14(self):
        proportions = (1, 3, 1, 5, 1)
        breakpoints = (1, Fraction(1, 7), 1)
        breathe = Breathe(proportions=proportions, breakpoints=breakpoints, quarter_duration=20, quantize=1)
        expected = [2, 5, 2, 9, 2]
        actual = [child.quarter_duration for child in breathe.children]
        self.assertEqual(expected, actual)

    def test_15(self):
        field = ChordField()
        child_1 = field.add_child(ChordField(
            midi_generator=ValueGenerator(cycle([71])),
            duration_generator=ValueGenerator(cycle([1])),
            quarter_duration=1))
        child_2 = field.add_child(ChordField(
            midi_generator=ValueGenerator(cycle([71])),
            duration_generator=ValueGenerator(cycle([1])),
            quarter_duration=1))
        actual = field.chords
        expected = child_1.chords + child_2.chords
        self.assertEqual(expected, actual)
コード例 #17
0
class Test(TestCase):
    def setUp(self) -> None:
        self.score = TreeScoreTimewise()

    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)

    def test_2(self):
        def add_chord_field(child):
            child.chord_field = ChordField(duration_generator=ValueGenerator(ArithmeticProgression(a1=0.2, an=2)),
                                           midi_generator=ValueGenerator(
                                                Interpolation(start=child.midi_generator.midi_range[0],
                                                              end=child.midi_generator.midi_range[1],
                                                              duration=None,
                                                              key=lambda
                                                                  midi: round(midi * 2) / 2)),
                                           short_ending_mode='stretch')

        fm = FractalMusic(quarter_duration=20, tempo=80, proportions=[1, 2, 3, 4, 5],
                          tree_permutation_order=[3, 1, 5, 2, 4])
        fm.midi_generator.midi_range = [60, 84]
        fm.add_layer()
        sorted_children = sorted(fm.get_children(), key=lambda child: child.fractal_order)
        add_chord_field(sorted_children[-1])

        score = fm.get_score(show_fractal_orders=True)
        xml_path = path + '_test_2.xml'
        score.write(xml_path)
        self.assertCompareFiles(xml_path)

    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)

    def test_4(self):
        cf_1 = ChordField(
            quarter_duration=10,
            midi_generator=ValueGenerator(cycle([60, 61, 64, 66])),
            long_ending_mode='self_extend',
            short_ending_mode='self_shrink'
        )
        cf_2 = ChordField(
            quarter_duration=3,
            midi_generator=ValueGenerator(cycle([72, 73, 74, 73, 72])),
            long_ending_mode='self_extend',
            short_ending_mode='self_shrink'
        )

        breathe_unit = Fraction(1, 5)
        breathe_breakpoints = (5 * breathe_unit, breathe_unit, 5 * breathe_unit)
        breathe_proportions = [2, 4, 1, 7, 2]

        breathe = Breathe(proportions=breathe_proportions,
                          quarter_duration=13,
                          breakpoints=breathe_breakpoints)
        cfg = ChordField(duration_generator=breathe.duration_generator)
        cfg.add_child(cf_1)
        cfg.add_child(cf_2)

        simple_format = SimpleFormat()
        simple_format.extend(cf_1.simple_format)
        simple_format.extend(cf_2.simple_format)

        self.score.set_time_signatures(ceil(simple_format.quarter_duration))
        simple_format.to_stream_voice().add_to_score(self.score)
        xml_path = path + 'test_4.xml'
        self.score.write(xml_path)
        self.assertCompareFiles(xml_path)

    def test_5(self):
        # node.chord_fields are part of a breathe group
        fm = FractalMusic(quarter_duration=20, tempo=80)
        fm.add_layer()
        fm.quantize_children(grid_size=1)

        node_groups = slice_list(fm.get_children(), (2, 1))

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

        breathe_unit = Fraction(1, 5)
        breathe_breakpoints = (5 * breathe_unit, breathe_unit, 5 * breathe_unit)
        breathe_proportions = [2, 4, 1, 7, 2]

        breathe = Breathe(proportions=breathe_proportions,
                          quarter_duration=sum([node.chord.quarter_duration for node in node_groups[0]]),
                          breakpoints=breathe_breakpoints)

        cfg = ChordField(duration_generator=breathe.duration_generator)
        cfg.add_child(cf_1)
        cfg.add_child(cf_2)

        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_5.xml'
        score.write(xml_path)
        self.assertCompareFiles(xml_path)