Exemple #1
0
    def special_action_1(self):
        """
        Long accented single note on A or B with trailing dim hairpin
        :return: str - image path
        """
        self.refresh_lily()
        # Find pitch
        pitch_set = note.extend_pitches_through_range([9, 11],
                                                      self.lowest_note,
                                                      self.highest_note)
        weighted_pitch_set = []
        i = 0
        while i < len(pitch_set):
            weighted_pitch_set.append((pitch_set[i], 10 / (i + 1)))
            i += 1
        use_pitch = rand.weighted_rand(weighted_pitch_set, 'discreet')
        # Find length
        use_length = rand.weighted_rand([(5, 2), (13, 8), (25, 1)],
                                        do_round=True)
        # Find dynamic
        use_dynamic = rand.weighted_rand([(9, 1), (8, 7), (4, 5), (0, 1)],
                                         do_round=True)
        self.note_array.create_note(use_pitch, use_length, dynamic=use_dynamic)
        self.note_array.list[-1].add_articulation(1)
        if self.sustained_playing:
            self.note_array.create_spanner(0,
                                           spanner_type='dim',
                                           apply_type='start')

        if len(self.clef_list) > 1:
            self.note_array.auto_build_clefs(self.clef_list, self.clef_list[0],
                                             self.clef_change_tolerance)
        self.score.note_array = self.note_array
        if self.instrument_name == 'Flute' or self.instrument_name == 'Alto Flute':
            self.note_array.auto_build_octave_spanners()
        output_ly_file = lilypond_file.LilypondFile(self.score)
        output_file_name = self.instrument_name + '_' + str(
            config.FileNameIndex)
        output_png = output_ly_file.save_and_render(output_file_name,
                                                    view_image=False,
                                                    autocrop=True,
                                                    delete_ly=False)
        config.FileNameIndex += 1
        return output_png
Exemple #2
0
    def build_pitch_rules(self):
        # Build E, F#, B Sub-Network
        e_f_b_pitch_set = note.extend_pitches_through_range([4, 6, 11],
                                                            self.lowest_note,
                                                            self.highest_note)
        e_pn_1 = nodes.NoteBehavior(name='stay put - e',
                                    direction=0,
                                    interval_weights=[(0, 1)],
                                    pitch_set=e_f_b_pitch_set,
                                    count_intervals_by_slots=True)
        e_pn_2 = nodes.NoteBehavior(name='step up - e',
                                    direction=1,
                                    interval_weights=[(1, 1)],
                                    pitch_set=e_f_b_pitch_set,
                                    count_intervals_by_slots=True)
        e_pn_3 = nodes.NoteBehavior(name='step down - e',
                                    direction=-1,
                                    interval_weights=[(1, 1)],
                                    pitch_set=e_f_b_pitch_set,
                                    count_intervals_by_slots=True)
        e_pn_4 = nodes.NoteBehavior(name='skip up - e',
                                    direction=1,
                                    interval_weights=[(2, 4), (3, 2)],
                                    pitch_set=e_f_b_pitch_set,
                                    count_intervals_by_slots=True)
        e_pn_5 = nodes.NoteBehavior(name='skip down - e',
                                    direction=-1,
                                    interval_weights=[(2, 4), (3, 2)],
                                    pitch_set=e_f_b_pitch_set,
                                    count_intervals_by_slots=True)
        e_pn_6 = nodes.NoteBehavior(name='big leap up - e',
                                    direction=1,
                                    interval_weights=[(3, 10), (6, 1)],
                                    pitch_set=e_f_b_pitch_set,
                                    count_intervals_by_slots=True)
        e_pn_7 = nodes.NoteBehavior(name='big leap down - e',
                                    direction=-1,
                                    interval_weights=[(3, 10), (6, 1)],
                                    pitch_set=e_f_b_pitch_set,
                                    count_intervals_by_slots=True)
        e_pn_8 = nodes.NoteBehavior(name='rest - e', pitch_set=e_f_b_pitch_set)

        e_pn_1.add_link(e_pn_2, 2)
        e_pn_1.add_link(e_pn_3, 2)
        e_pn_1.add_link(e_pn_4, 2)
        e_pn_1.add_link(e_pn_5, 2)
        e_pn_1.add_link(e_pn_6, 1)
        e_pn_1.add_link(e_pn_7, 1)
        e_pn_2.add_link(e_pn_3, 10)
        e_pn_2.add_link(e_pn_1, 1)
        e_pn_2.add_link(e_pn_8, 2)
        e_pn_2.add_link(e_pn_2, 1)
        e_pn_2.add_link(e_pn_5, 2)
        e_pn_2.add_link(e_pn_7, 0.2)
        e_pn_3.add_link(e_pn_2, 10)
        e_pn_3.add_link(e_pn_1, 4)
        e_pn_3.add_link(e_pn_4, 3)
        e_pn_3.add_link(e_pn_6, 1)
        e_pn_3.add_link(e_pn_4, 3)
        e_pn_3.add_link(e_pn_8, 2)
        e_pn_4.add_link(e_pn_1, 3)
        e_pn_4.add_link(e_pn_3, 8), e_pn_4.add_link(e_pn_7, 1)
        e_pn_4.add_link(e_pn_8, 4)
        e_pn_5.add_link(e_pn_1, 4)
        e_pn_5.add_link(e_pn_2, 7)
        e_pn_5.add_link(e_pn_8, 2)
        e_pn_5.add_link(e_pn_6, 1)
        e_pn_6.add_link(e_pn_1, 8)
        e_pn_6.add_link(e_pn_3, 8)
        e_pn_6.add_link(e_pn_5, 6)
        e_pn_6.add_link(e_pn_7, 2)
        e_pn_6.add_link(e_pn_8, 4)
        e_pn_7.add_link(e_pn_1, 8)
        e_pn_7.add_link(e_pn_2, 4)
        e_pn_7.add_link(e_pn_4, 2)
        e_pn_7.add_link(e_pn_6, 2)
        e_pn_7.add_link(e_pn_8, 1)
        e_pn_8.add_link(e_pn_1, 5)
        e_pn_8.add_link(e_pn_2, 2)
        e_pn_8.add_link(e_pn_3, 2)
        e_pn_8.add_link(e_pn_4, 2)
        e_pn_8.add_link(e_pn_5, 2)
        e_pn_8.add_link(e_pn_6, 1)
        e_pn_8.add_link(e_pn_7, 1)

        # Build Hexatonic Sub-Network
        # h_pitch_set consists of E, G#, A, B, C#, D#
        h_pitch_set = note.extend_pitches_through_range([1, 3, 4, 8, 9, 11],
                                                        self.lowest_note,
                                                        self.highest_note)
        h_pn_1 = nodes.NoteBehavior(name='stay put - h',
                                    direction=0,
                                    interval_weights=[(0, 1)],
                                    pitch_set=h_pitch_set,
                                    count_intervals_by_slots=True)
        h_pn_2 = nodes.NoteBehavior(name='step up - h',
                                    direction=1,
                                    interval_weights=[(1, 1)],
                                    pitch_set=h_pitch_set,
                                    count_intervals_by_slots=True)
        h_pn_3 = nodes.NoteBehavior(name='step down - h',
                                    direction=-1,
                                    interval_weights=[(1, 1)],
                                    pitch_set=h_pitch_set,
                                    count_intervals_by_slots=True)
        h_pn_4 = nodes.NoteBehavior(name='skip up - h',
                                    direction=1,
                                    interval_weights=[(2, 5), (3, 2)],
                                    pitch_set=h_pitch_set,
                                    count_intervals_by_slots=True)
        h_pn_5 = nodes.NoteBehavior(name='skip down - h',
                                    direction=-1,
                                    interval_weights=[(2, 5), (3, 2)],
                                    pitch_set=h_pitch_set,
                                    count_intervals_by_slots=True)
        h_pn_6 = nodes.NoteBehavior(name='leap up - h',
                                    direction=1,
                                    interval_weights=[(3, 5), (6, 2)],
                                    pitch_set=h_pitch_set,
                                    count_intervals_by_slots=True)
        h_pn_7 = nodes.NoteBehavior(name='leap down - h',
                                    direction=-1,
                                    interval_weights=[(3, 5), (6, 2)],
                                    pitch_set=h_pitch_set,
                                    count_intervals_by_slots=True)
        h_pn_8 = nodes.NoteBehavior(name='rest - h', pitch_set=h_pitch_set)

        h_pn_1.add_link(h_pn_1, 1)
        h_pn_1.add_link(h_pn_2, 3)
        h_pn_1.add_link(h_pn_3, 6)
        h_pn_1.add_link(h_pn_4, 2)
        h_pn_1.add_link(h_pn_5, 2)
        h_pn_1.add_link(h_pn_6, 1)
        h_pn_1.add_link(h_pn_7, 1)
        h_pn_1.add_link(h_pn_8, 4)

        h_pn_2.add_link(h_pn_1, 3)
        h_pn_2.add_link(h_pn_2, 2)
        h_pn_2.add_link(h_pn_3, 6)
        h_pn_2.add_link(h_pn_4, 2)
        h_pn_2.add_link(h_pn_5, 4)
        h_pn_2.add_link(h_pn_6, 1)
        h_pn_2.add_link(h_pn_7, 1)
        h_pn_2.add_link(h_pn_8, 4)

        h_pn_3.add_link(h_pn_1, 3)
        h_pn_3.add_link(h_pn_2, 5)
        h_pn_3.add_link(h_pn_3, 1)
        h_pn_3.add_link(h_pn_4, 3)
        h_pn_3.add_link(h_pn_5, 4)
        h_pn_3.add_link(h_pn_6, 2)
        h_pn_3.add_link(h_pn_7, 1)
        h_pn_3.add_link(h_pn_8, 2)

        h_pn_4.add_link(h_pn_1, 3)
        h_pn_4.add_link(h_pn_2, 1)
        h_pn_4.add_link(h_pn_3, 5)
        h_pn_4.add_link(h_pn_4, 1)
        h_pn_4.add_link(h_pn_5, 6)
        h_pn_4.add_link(h_pn_7, 2)
        h_pn_4.add_link(h_pn_8, 3)

        h_pn_5.add_link(h_pn_1, 3)
        h_pn_5.add_link(h_pn_2, 5)
        h_pn_5.add_link(h_pn_3, 1)
        h_pn_5.add_link(h_pn_4, 5)
        h_pn_5.add_link(h_pn_5, 2)
        h_pn_5.add_link(h_pn_6, 1)
        h_pn_5.add_link(h_pn_8, 3)

        h_pn_6.add_link(h_pn_1, 1)
        h_pn_6.add_link(h_pn_2, 1)
        h_pn_6.add_link(h_pn_3, 5)
        h_pn_6.add_link(h_pn_4, 2)
        h_pn_6.add_link(h_pn_5, 4)
        h_pn_6.add_link(h_pn_7, 3)
        h_pn_6.add_link(h_pn_8, 7)

        h_pn_7.add_link(h_pn_1, 2)
        h_pn_7.add_link(h_pn_2, 5)
        h_pn_7.add_link(h_pn_3, 1)
        h_pn_7.add_link(h_pn_4, 3)
        h_pn_7.add_link(h_pn_5, 1)
        h_pn_7.add_link(h_pn_6, 3)
        h_pn_7.add_link(h_pn_8, 3)

        h_pn_8.add_link(h_pn_1, 2)
        h_pn_8.add_link(h_pn_2, 4)
        h_pn_8.add_link(h_pn_3, 4)
        h_pn_8.add_link(h_pn_4, 2)
        h_pn_8.add_link(h_pn_5, 2)
        h_pn_8.add_link(h_pn_6, 1)
        h_pn_8.add_link(h_pn_7, 1)

        # Build Chromatic Sub-Network
        # c_pitch_set is all possible notes between lowest and highest notes
        c_pitch_set = list(range(
            self.lowest_note,
            self.highest_note))  # Maybe later build in certain PC omissions?
        c_pn_1 = nodes.NoteBehavior(name='stay put - c',
                                    direction=0,
                                    interval_weights=[(0, 1)],
                                    pitch_set=c_pitch_set,
                                    count_intervals_by_slots=False)
        c_pn_2 = nodes.NoteBehavior(name='step up - c',
                                    direction=1,
                                    interval_weights=[(1, 4), (2, 4)],
                                    pitch_set=c_pitch_set,
                                    count_intervals_by_slots=False)
        c_pn_3 = nodes.NoteBehavior(name='step down - c',
                                    direction=-1,
                                    interval_weights=[(1, 4), (2, 4)],
                                    pitch_set=c_pitch_set,
                                    count_intervals_by_slots=False)
        c_pn_4 = nodes.NoteBehavior(name='skip up - c',
                                    direction=1,
                                    interval_weights=[(2, 5), (4, 4)],
                                    pitch_set=c_pitch_set,
                                    count_intervals_by_slots=False)
        c_pn_5 = nodes.NoteBehavior(name='skip down - c',
                                    direction=-1,
                                    interval_weights=[(2, 5), (4, 4)],
                                    pitch_set=c_pitch_set,
                                    count_intervals_by_slots=False)
        c_pn_6 = nodes.NoteBehavior(name='leap up - c',
                                    direction=1,
                                    interval_weights=[(4, 6), (7, 1)],
                                    pitch_set=c_pitch_set,
                                    count_intervals_by_slots=False)
        c_pn_7 = nodes.NoteBehavior(name='leap down - c',
                                    direction=-1,
                                    interval_weights=[(4, 6), (7, 1)],
                                    pitch_set=c_pitch_set,
                                    count_intervals_by_slots=False)
        c_pn_8 = nodes.NoteBehavior(name='rest - c', pitch_set=c_pitch_set)

        c_pn_1.add_link(c_pn_1, 1)
        c_pn_1.add_link(c_pn_2, 3)
        c_pn_1.add_link(c_pn_3, 6)
        c_pn_1.add_link(c_pn_4, 2)
        c_pn_1.add_link(c_pn_5, 2)
        c_pn_1.add_link(c_pn_6, 1)
        c_pn_1.add_link(c_pn_7, 1)
        c_pn_1.add_link(c_pn_8, 4)

        c_pn_2.add_link(c_pn_1, 3)
        c_pn_2.add_link(c_pn_2, 6)
        c_pn_2.add_link(c_pn_3, 9)
        c_pn_2.add_link(c_pn_4, 2)
        c_pn_2.add_link(c_pn_5, 4)
        c_pn_2.add_link(c_pn_6, 1)
        c_pn_2.add_link(c_pn_7, 1)
        c_pn_2.add_link(c_pn_8, 4)

        c_pn_3.add_link(c_pn_1, 3)
        c_pn_3.add_link(c_pn_2, 9)
        c_pn_3.add_link(c_pn_3, 6)
        c_pn_3.add_link(c_pn_4, 3)
        c_pn_3.add_link(c_pn_5, 4)
        c_pn_3.add_link(c_pn_6, 2)
        c_pn_3.add_link(c_pn_7, 1)
        c_pn_3.add_link(c_pn_8, 3)

        c_pn_4.add_link(c_pn_1, 3)
        c_pn_4.add_link(c_pn_2, 1)
        c_pn_4.add_link(c_pn_3, 5)
        c_pn_4.add_link(c_pn_4, 1)
        c_pn_4.add_link(c_pn_5, 6)
        c_pn_4.add_link(c_pn_7, 2)
        c_pn_4.add_link(c_pn_8, 5)

        c_pn_5.add_link(c_pn_1, 3)
        c_pn_5.add_link(c_pn_2, 5)
        c_pn_5.add_link(c_pn_3, 1)
        c_pn_5.add_link(c_pn_4, 5)
        c_pn_5.add_link(c_pn_5, 2)
        c_pn_5.add_link(c_pn_6, 1)
        c_pn_5.add_link(c_pn_8, 9)

        c_pn_6.add_link(c_pn_1, 1)
        c_pn_6.add_link(c_pn_2, 1)
        c_pn_6.add_link(c_pn_3, 5)
        c_pn_6.add_link(c_pn_4, 2)
        c_pn_6.add_link(c_pn_5, 4)
        c_pn_6.add_link(c_pn_7, 3)
        c_pn_6.add_link(c_pn_8, 7)

        c_pn_7.add_link(c_pn_1, 2)
        c_pn_7.add_link(c_pn_2, 5)
        c_pn_7.add_link(c_pn_3, 1)
        c_pn_7.add_link(c_pn_4, 3)
        c_pn_7.add_link(c_pn_5, 1)
        c_pn_7.add_link(c_pn_6, 3)
        c_pn_7.add_link(c_pn_8, 5)

        c_pn_8.add_link(c_pn_1, 2)
        c_pn_8.add_link(c_pn_2, 4)
        c_pn_8.add_link(c_pn_3, 4)
        c_pn_8.add_link(c_pn_4, 2)
        c_pn_8.add_link(c_pn_5, 2)
        c_pn_8.add_link(c_pn_6, 1)
        c_pn_8.add_link(c_pn_7, 1)

        # Add shared nodes
        s_jump_node_1 = nodes.Action('Jump to hexatonic pitch subnetwork')
        s_jump_node_1.add_link_to_self(
            [e_pn_1, e_pn_2, e_pn_3, e_pn_4, e_pn_5, e_pn_6, e_pn_7, e_pn_8],
            5)
        s_jump_node_1.add_link(
            [h_pn_1, h_pn_2, h_pn_3, h_pn_4, h_pn_5, h_pn_6, h_pn_7], 1)
        s_jump_node_2 = nodes.Action('Jump to chromatic pitch subnetwork')
        s_jump_node_2.add_link_to_self(
            [h_pn_1, h_pn_2, h_pn_3, h_pn_4, h_pn_5, h_pn_6, h_pn_7, h_pn_8],
            5)
        s_jump_node_2.add_link(
            [c_pn_1, c_pn_2, c_pn_3, c_pn_4, c_pn_5, c_pn_6, c_pn_7], 1)
        s_jump_node_3 = nodes.Action('Jump to E F# B pitch subnetwork')
        s_jump_node_3.add_link_to_self(
            [c_pn_1, c_pn_2, c_pn_3, c_pn_4, c_pn_5, c_pn_6, c_pn_7, c_pn_8],
            5)
        s_jump_node_3.add_link(
            [e_pn_1, e_pn_2, e_pn_3, e_pn_4, e_pn_5, e_pn_6, e_pn_7], 1)

        self.pitch_network.add_node([
            e_pn_1, e_pn_2, e_pn_3, e_pn_4, e_pn_5, e_pn_6, e_pn_7, e_pn_8,
            h_pn_1, h_pn_2, h_pn_3, h_pn_4, h_pn_5, h_pn_6, h_pn_7, h_pn_8,
            c_pn_1, c_pn_2, c_pn_3, c_pn_4, c_pn_5, c_pn_6, c_pn_7, c_pn_8,
            s_jump_node_1, s_jump_node_2, s_jump_node_3
        ])
    def build_pitch_rules(self):
        """
        Builds self.pitch_network
        :return: None
        """
        # Note that pitch, in percussion context, refers simply to staff spaces.
        # 'Pitch' network using only white keys since pitches here really refer to instruments
        pitch_set = note.extend_pitches_through_range([0, 2, 4, 5, 7, 9, 11], self.lowest_note, self.highest_note)
        pn_1 = nodes.NoteBehavior(name='stay put', direction=0, interval_weights=[(0, 1)],
                                  pitch_set=pitch_set, count_intervals_by_slots=True)
        pn_2 = nodes.NoteBehavior(name='step up', direction=1, interval_weights=[(1, 1)],
                                  pitch_set=pitch_set, count_intervals_by_slots=True)
        pn_3 = nodes.NoteBehavior(name='step down', direction=-1, interval_weights=[(1, 1)],
                                  pitch_set=pitch_set, count_intervals_by_slots=True)
        pn_4 = nodes.NoteBehavior(name='skip up', direction=1, interval_weights=[(2, 4), (3, 2)],
                                  pitch_set=pitch_set, count_intervals_by_slots=True)
        pn_5 = nodes.NoteBehavior(name='skip down', direction=-1, interval_weights=[(2, 4), (3, 2)],
                                  pitch_set=pitch_set, count_intervals_by_slots=True)
        pn_6 = nodes.NoteBehavior(name='big leap up', direction=1, interval_weights=[(4, 10), (8, 1)],
                                  pitch_set=pitch_set, count_intervals_by_slots=True)
        pn_7 = nodes.NoteBehavior(name='big leap down', direction=-1, interval_weights=[(4, 10), (8, 1)],
                                  pitch_set=pitch_set, count_intervals_by_slots=True)
        pn_8 = nodes.NoteBehavior(name='rest', pitch_set=pitch_set)

        pn_1.add_link(pn_2, 2)
        pn_1.add_link(pn_1, 8)
        pn_1.add_link(pn_3, 2)
        pn_1.add_link(pn_4, 2)
        pn_1.add_link(pn_5, 2)
        pn_1.add_link(pn_6, 1)
        pn_1.add_link(pn_7, 1)

        pn_2.add_link(pn_3, 10)
        pn_2.add_link(pn_1, 1)
        pn_2.add_link(pn_8, 2)
        pn_2.add_link(pn_2, 1)
        pn_2.add_link(pn_5, 2)
        pn_2.add_link(pn_7, 0.2)

        pn_3.add_link(pn_2, 10)
        pn_3.add_link(pn_1, 4)
        pn_3.add_link(pn_4, 3)
        pn_3.add_link(pn_6, 1)
        pn_3.add_link(pn_4, 3)
        pn_3.add_link(pn_8, 2)

        pn_4.add_link(pn_1, 3)
        pn_4.add_link(pn_3, 8)
        pn_4.add_link(pn_7, 1)
        pn_4.add_link(pn_8, 4)

        pn_5.add_link(pn_1, 4)
        pn_5.add_link(pn_2, 7)
        pn_5.add_link(pn_8, 2)
        pn_5.add_link(pn_6, 1)

        pn_6.add_link(pn_1, 8)
        pn_6.add_link(pn_3, 8)
        pn_6.add_link(pn_5, 6)
        pn_6.add_link(pn_7, 2)
        pn_6.add_link(pn_8, 4)

        pn_7.add_link(pn_1, 8)
        pn_7.add_link(pn_2, 4)
        pn_7.add_link(pn_4, 2)
        pn_7.add_link(pn_6, 2)
        pn_7.add_link(pn_8, 1)

        pn_8.add_link(pn_1, 5)
        pn_8.add_link(pn_2, 2)
        pn_8.add_link(pn_3, 2)
        pn_8.add_link(pn_4, 2)
        pn_8.add_link(pn_5, 2)
        pn_8.add_link(pn_6, 1)
        pn_8.add_link(pn_7, 1)

        self.pitch_network.add_node([pn_1, pn_2, pn_3, pn_4, pn_5, pn_6, pn_7, pn_8])