def test_archipel_util_get_pitches_04():

    pitches = get_pitches(2, 1)

    assert pitches[:100] == (8, -5, 2, 21, -13, 13, 12, 6, 16, 3, 10, 17, -5,
    2, 21, -13, 13, -12, 8, 16, 15, -2, 5, 6, -10, 21, -13, 25, -12, 8, -5, 15,
    -2, 5, 6, -8, 21, -1, 37, -12, -4, 7, -22, -14, 17, 18, -8, 27, -1, 37,
    -12, -4, 7, 2, 21, 17, 18, 16, 15, -2, 25, 0, 8, 7, 2, 21, 11, 18, 16, 15,
    -2, -7, 12, -16, -5, 14, 21, -1, 25, -8, 15, 22, -7, 6, -16, -5, 14, 21,
    -13, 13, -24, 3, -14, 17, 18, -20, 19, -10, -3, -13)
Exemplo n.º 2
0
def apply_pitches_according_to_pitch_indicators(score, closure):
    known_pitches = {}
    for leaf in componenttools.iterate_timeline_forward_in_expr(score):
        if isinstance(leaf, Note):
            pitch_indicator = leaf.get_annotation('pitch')
            if pitch_indicator is None:
                continue
            #print(leaf, leaf._parentage.parent._parentage.parent._parentage.parent, pitch_indicator)
            trope_index = leaf.get_annotation('trope')
            add_pitch_to_known_tropes = False
            if trope_index is not None:
                if trope_index in closure.known_tropes.keys():
                    leaf.pitch = closure.known_tropes[trope_index]
                    #print('continuing ...\n')
                    continue
                else:
                    add_pitch_to_known_tropes = True

            pitch_class_type, index_of_transposition = pitch_indicator
            try:
                pitches = known_pitches[pitch_indicator]
            except KeyError:
                #pitch_class_type, index_of_transposition = pitch_indicator
                pitches = get_pitches(pitch_class_type, index_of_transposition)
                known_pitches[pitch_indicator] = pitches

            if pitch_class_type == 'sargasso':
                pitch_index = closure.cur_sargasso_pitch_index
            elif pitch_class_type == 'serration':
                pitch_index = closure.cur_serration_pitch_index
            elif pitch_class_type == 'marimba descent':
                pitch_index = closure.cur_marimba_descent_pitch_index
            elif pitch_class_type == 1:
                pitch_index = closure.cur_pitch_1_index
            elif pitch_class_type == 2:
                pitch_index = closure.cur_pitch_2_index
            # other pitch class sequences repeat indefinitely
            else:
                pitch_index = 0

            chord_count = leaf.get_annotation('chord_count', default=1)
            if 2 <= chord_count:
                chord = Chord(leaf)
                componenttools.replace([leaf], [chord])
                leaf = chord

            if chord_count == 1:
                leaf.pitch = pitches[pitch_index]
            else:
                leaf.pitches = pitches[pitch_index:pitch_index+chord_count]

            if add_pitch_to_known_tropes:
                if isinstance(leaf, Note):
                    closure.known_tropes[trope_index] = leaf.pitch
                elif isinstance(leaf, Chord):
                    closure.known_tropes[trope_index] = leaf.pitches
                else:
                    raise ValueError

            if pitch_class_type == 'sargasso':
                closure.cur_sargasso_pitch_index += chord_count
            elif pitch_class_type == 'serration':
                closure.cur_serration_pitch_index += chord_count
            elif pitch_class_type == 'marimba descent':
                closure.cur_marimba_descent_pitch_index += chord_count
            elif pitch_class_type == 1:
                closure.cur_pitch_1_index += chord_count
            elif pitch_class_type == 2:
                closure.cur_pitch_2_index += chord_count
            # other pitch class types repeat indefinitely
            else:
                pass
            #print(closure + '\n')

        elif isinstance(leaf, Chord):
            raise NotImplementedError
# -*- coding: utf-8 -*-
import abjad
from archipel.etc.implementation.utilities import get_pitches
from archipel.etc.implementation.utilities import keep_pdf


for type_of_pitch_material in (1, 2):
    for index_of_transposition in range(12):
        pitches = get_pitches(type_of_pitch_material, index_of_transposition)
        pitches = tuple(pitches)
        notes = notetools.make_notes(pitches, [(1, 4)])
        score, t, b = scoretools.make_piano_sketch_score_from_leaves(notes)
        lilypond_file = lilypondfiletools.make_basic_lilypond_file(score)
        lilypond_file.global_staff_size = 16
        lilypond_file.default_paper_size = 'letter', 'portrait'
        title = "l'archipel type %s pitches t%s"
        title %= (type_of_pitch_material, index_of_transposition)
        lilypond_file.header_block.title = title
        lilypond_file.layout_block.indent = 0
        lilypond_file.paper_block.system_system_spacing = \
            layouttools.make_spacing_vector(0, 0, 12, 0)
        lilypond_file.paper_block.markup_system_spacing = \
            layouttools.make_spacing_vector(0, 0, 12, 0)
        lilypond_file.paper_block.top_margin = 12
        score.override.stem.transparent = True
        score.override.rest.transparent = True
        name = 'archipel-type-%s-pitches-t%s'
        name %= (type_of_pitch_material, index_of_transposition)
        keep_pdf(lilypond_file, name)
def test_archipel_util_get_pitches_01():

    pitches = get_pitches(1, 1)

    assert pitches == (8, 17, 16, 2, 10, 12, 21, -5, 15, 25, 6, -13, -12, 21, 7, -14, 37, 18, 11, 15, 17, 16, 2, 8, 6, -1, 15, 25, -8, 14, -16, 17, -3, 19, -14, -12, -10, 20, 29, -20, 7, -2, 12, 33, -1, 15, 25, 18, 10, 12, 21, -5, 3, 13, 6, -1, 20, 5, 4, -10, 37, 6, -13, 27, 17, -8, -22, -4, 12, 9, -5, -26, -20, 2, -4, 5, 9, 7, -2, -12, 30, -1, 15, 25, 7, 10, -12, 21, -1, 15, 25, 6, -10, 8, 5, 28, 3, 13, 6, -13, 8, 17, 16, -10, -2, -12, 21, 7, 5, -8, -22, -4, -24, 9, -5, -14, 25, 18, -1, 15, 21, 19, 10, 0, 30, -1, 27, 37, 4, 14, 8, 17, -1, -21, -11, 6, 14, 20, 29, 16, -5, -2, 0, 33)
def test_archipel_util_get_pitches_03():

    pitches = get_pitches(2, 0)

    assert pitches[:100] == (-5, 6, 13, 8, 10, 12, -13, 17, 3, 2, 21, 16, 6, 13, 8, 10, 12, -13, -5, 15, -10, 21, 16, 5, 25, 8, -2, -12, -13, -5, 6, -10, 21, 16, 5, 27, -4, -14, -12, -1, 7, 18, 37, 21, -8, 17, 27, -22, -14, -12, -1, 7, 18, 25, 8, 16, 17, 15, 2, 21, 0, 11, 7, 18, 25, 8, -2, 17, 15, 2, 21, -8, -1, -5, 6, 25, -16, 22, 12, 15, 14, 21, -8, -7, -5, 6, 25, -16, -14, -24, -13, -10, -3, -20, 17, 3, 18, 13, 8, -14)
def test_archipel_util_get_pitches_02():

    pitches = get_pitches(1, 0)

    assert pitches == (-5, 16, 3, 13, 21, -13, 8, 6, -10, -12, 5, -2, -1, -4, 18, 21, 0, 17, -2, 2, 16, 15, 25, 7, -7, 22, 14, 12, 15, 25, -5, -8, -16, 18, -3, -13, -11, 7, -20, -21, 6, 9, -1, 20, -14, -22, 12, -7, 21, -13, 8, 6, -10, -24, 5, -2, 7, 4, 15, 25, -12, 17, -14, -22, -8, 27, 37, -5, -13, -16, 6, 9, 3, 13, 7, -20, -4, 18, 9, -1, 29, -2, 2, -12, 6, 21, -1, 20, -2, -10, 12, 5, 25, -5, 28, 15, 2, 12, 17, 10, -5, 16, 3, 13, 21, -1, 20, 18, -8, 15, 25, -5, -13, -4, 18, 21, 0, 5, -14, 2, 8, 30, 21, -1, 17, -14, 14, -24, 27, 37, 19, 4, 22, 14, -12, 29, -11, 7, 4, -21, 6, 33, -1, 20)