def list_ordered_named_pitch_pairs_from_expr_1_to_expr_2(expr_1, expr_2):
    '''List ordered named pitch pairs from `expr_1` to `expr_2`:

    ::

        >>> chord_1 = Chord([0, 1, 2], (1, 4))
        >>> chord_2 = Chord([3, 4], (1, 4))

    ::

        >>> for pair in pitchtools.list_ordered_named_pitch_pairs_from_expr_1_to_expr_2(
        ...     chord_1, chord_2):
        ...     pair
        (NamedPitch("c'"), NamedPitch("ef'"))
        (NamedPitch("c'"), NamedPitch("e'"))
        (NamedPitch("cs'"), NamedPitch("ef'"))
        (NamedPitch("cs'"), NamedPitch("e'"))
        (NamedPitch("d'"), NamedPitch("ef'"))
        (NamedPitch("d'"), NamedPitch("e'"))

    Returns generator.
    '''
    from abjad.tools import pitchtools

    pitches_1 = sorted(pitchtools.list_named_pitches_in_expr(expr_1))
    pitches_2 = sorted(pitchtools.list_named_pitches_in_expr(expr_2))
    for pair in sequencetools.yield_all_pairs_between_sequences(pitches_1, pitches_2):
        yield pair
def list_ordered_named_pitch_pairs_from_expr_1_to_expr_2(expr_1, expr_2):
    '''Lists ordered named pitch pairs from `expr_1` to `expr_2`.

    ::

        >>> chord_1 = Chord([0, 1, 2], (1, 4))
        >>> chord_2 = Chord([3, 4], (1, 4))

    ::

        >>> for pair in pitchtools.list_ordered_named_pitch_pairs_from_expr_1_to_expr_2(
        ...     chord_1, chord_2):
        ...     pair
        (NamedPitch("c'"), NamedPitch("ef'"))
        (NamedPitch("c'"), NamedPitch("e'"))
        (NamedPitch("cs'"), NamedPitch("ef'"))
        (NamedPitch("cs'"), NamedPitch("e'"))
        (NamedPitch("d'"), NamedPitch("ef'"))
        (NamedPitch("d'"), NamedPitch("e'"))

    Returns generator.
    '''
    from abjad.tools import pitchtools

    pitches_1 = sorted(pitchtools.list_named_pitches_in_expr(expr_1))
    pitches_2 = sorted(pitchtools.list_named_pitches_in_expr(expr_2))
    for pair in sequencetools.yield_all_pairs_between_sequences(pitches_1, pitches_2):
        yield pair
def test_sequencetools_yield_all_pairs_between_sequences_01():

    pairs = sequencetools.yield_all_pairs_between_sequences([1, 2, 3], [4, 5])
    pairs = list(pairs)

    assert pairs[0] == (1, 4)
    assert pairs[1] == (1, 5)
    assert pairs[2] == (2, 4)
    assert pairs[3] == (2, 5)
    assert pairs[4] == (3, 4)
    assert pairs[5] == (3, 5)
def iterate_leaf_pairs_in_expr(expr):
    r'''Iterate leaf pairs forward in `expr`:

    ::

        >>> score = Score([])
        >>> notes = [Note("c'8"), Note("d'8"), Note("e'8"), Note("f'8"), Note("g'4")]
        >>> score.append(Staff(notes))
        >>> notes = [Note(x, (1, 4)) for x in [-12, -15, -17]]
        >>> score.append(Staff(notes))
        >>> clef = contexttools.ClefMark('bass')
        >>> attach(clef, score[1])
        ClefMark('bass')(Staff{3})
        >>> show(score) # doctest: +SKIP

    ..  doctest::

        >>> f(score)
        \new Score <<
            \new Staff {
                c'8
                d'8
                e'8
                f'8
                g'4
            }
            \new Staff {
                \clef "bass"
                c4
                a,4
                g,4
            }
        >>

    ::

        >>> for pair in iterationtools.iterate_leaf_pairs_in_expr(score):
        ...        pair
        (Note("c'8"), Note('c4'))
        (Note("c'8"), Note("d'8"))
        (Note('c4'), Note("d'8"))
        (Note("d'8"), Note("e'8"))
        (Note("d'8"), Note('a,4'))
        (Note('c4'), Note("e'8"))
        (Note('c4'), Note('a,4'))
        (Note("e'8"), Note('a,4'))
        (Note("e'8"), Note("f'8"))
        (Note('a,4'), Note("f'8"))
        (Note("f'8"), Note("g'4"))
        (Note("f'8"), Note('g,4'))
        (Note('a,4'), Note("g'4"))
        (Note('a,4'), Note('g,4'))
        (Note("g'4"), Note('g,4'))

    Iterate leaf pairs left-to-right and top-to-bottom.

    Returns generator.
    '''
    from abjad.tools import iterationtools

    vertical_moments = iterationtools.iterate_vertical_moments_in_expr(expr)
    for moment_1, moment_2 in \
        sequencetools.iterate_sequence_pairwise_strict(vertical_moments):
        for pair in sequencetools.yield_all_unordered_pairs_of_sequence(
            moment_1.start_leaves):
            yield pair
        pairs = sequencetools.yield_all_pairs_between_sequences(
            moment_1.leaves, moment_2.start_leaves)
        for pair in pairs:
            yield pair
    else:
        for pair in sequencetools.yield_all_unordered_pairs_of_sequence(
            moment_2.start_leaves):
            yield pair
Beispiel #5
0
    def by_leaf_pair(self):
        r'''Iterate leaf pairs forward in `expr`:

        ::

            >>> score = Score([])
            >>> notes = [Note("c'8"), Note("d'8"), Note("e'8"),
            ...     Note("f'8"), Note("g'4")]
            >>> score.append(Staff(notes))
            >>> notes = [Note(x, (1, 4)) for x in [-12, -15, -17]]
            >>> score.append(Staff(notes))
            >>> clef = Clef('bass')
            >>> attach(clef, score[1])
            >>> show(score) # doctest: +SKIP

        ..  doctest::

            >>> print(format(score))
            \new Score <<
                \new Staff {
                    c'8
                    d'8
                    e'8
                    f'8
                    g'4
                }
                \new Staff {
                    \clef "bass"
                    c4
                    a,4
                    g,4
                }
            >>

        ::

            >>> for pair in iterate(score).by_leaf_pair():
            ...        pair
            (Note("c'8"), Note('c4'))
            (Note("c'8"), Note("d'8"))
            (Note('c4'), Note("d'8"))
            (Note("d'8"), Note("e'8"))
            (Note("d'8"), Note('a,4'))
            (Note('c4'), Note("e'8"))
            (Note('c4'), Note('a,4'))
            (Note("e'8"), Note('a,4'))
            (Note("e'8"), Note("f'8"))
            (Note('a,4'), Note("f'8"))
            (Note("f'8"), Note("g'4"))
            (Note("f'8"), Note('g,4'))
            (Note('a,4'), Note("g'4"))
            (Note('a,4'), Note('g,4'))
            (Note("g'4"), Note('g,4'))

        Iterate leaf pairs left-to-right and top-to-bottom.

        Returns generator.
        '''
        vertical_moments = self.by_vertical_moment()
        for moment_1, moment_2 in \
            sequencetools.iterate_sequence_nwise(vertical_moments):
            for pair in sequencetools.yield_all_unordered_pairs_of_sequence(
                moment_1.start_leaves):
                yield pair
            pairs = sequencetools.yield_all_pairs_between_sequences(
                moment_1.leaves, moment_2.start_leaves)
            for pair in pairs:
                yield pair
        else:
            for pair in sequencetools.yield_all_unordered_pairs_of_sequence(
                moment_2.start_leaves):
                yield pair
Beispiel #6
0
    def by_leaf_pair(self):
        r'''Iterate leaf pairs forward in `expr`:

        ::

            >>> score = Score([])
            >>> notes = [Note("c'8"), Note("d'8"), Note("e'8"),
            ...     Note("f'8"), Note("g'4")]
            >>> score.append(Staff(notes))
            >>> notes = [Note(x, (1, 4)) for x in [-12, -15, -17]]
            >>> score.append(Staff(notes))
            >>> clef = Clef('bass')
            >>> attach(clef, score[1])
            >>> show(score) # doctest: +SKIP

        ..  doctest::

            >>> print(format(score))
            \new Score <<
                \new Staff {
                    c'8
                    d'8
                    e'8
                    f'8
                    g'4
                }
                \new Staff {
                    \clef "bass"
                    c4
                    a,4
                    g,4
                }
            >>

        ::

            >>> for pair in iterate(score).by_leaf_pair():
            ...        pair
            (Note("c'8"), Note('c4'))
            (Note("c'8"), Note("d'8"))
            (Note('c4'), Note("d'8"))
            (Note("d'8"), Note("e'8"))
            (Note("d'8"), Note('a,4'))
            (Note('c4'), Note("e'8"))
            (Note('c4'), Note('a,4'))
            (Note("e'8"), Note('a,4'))
            (Note("e'8"), Note("f'8"))
            (Note('a,4'), Note("f'8"))
            (Note("f'8"), Note("g'4"))
            (Note("f'8"), Note('g,4'))
            (Note('a,4'), Note("g'4"))
            (Note('a,4'), Note('g,4'))
            (Note("g'4"), Note('g,4'))

        Iterate leaf pairs left-to-right and top-to-bottom.

        Returns generator.
        '''
        vertical_moments = self.by_vertical_moment()
        for moment_1, moment_2 in \
            sequencetools.iterate_sequence_nwise(vertical_moments):
            for pair in sequencetools.yield_all_unordered_pairs_of_sequence(
                    moment_1.start_leaves):
                yield pair
            pairs = sequencetools.yield_all_pairs_between_sequences(
                moment_1.leaves, moment_2.start_leaves)
            for pair in pairs:
                yield pair
        else:
            for pair in sequencetools.yield_all_unordered_pairs_of_sequence(
                    moment_2.start_leaves):
                yield pair