コード例 #1
0
def select(items=None):
    r"""
    Selects ``items`` or makes select expression.

    ..  container:: example

        Selects first two notes in staff:

        >>> staff = abjad.Staff("c'4 d' e' f'")
        >>> selection = abjad.select(staff[:2]).leaves(pitched=True)
        >>> for note in selection:
        ...     abjad.override(note).note_head.color = 'red'

        >>> abjad.show(staff) # doctest: +SKIP

        ..  docs::

            >>> abjad.f(staff)
            \new Staff
            {
                \once \override NoteHead.color = #red
                c'4
                \once \override NoteHead.color = #red
                d'4
                e'4
                f'4
            }

    ..  container:: example

        Returns selection agent:

        >>> abjad.select(staff)
        Selection([Staff("c'4 d'4 e'4 f'4")])

        >>> abjad.select()
        abjad.select()

    """
    import abjad

    if items is None:
        return abjad.Expression().select()
    return abjad.Selection(items=items)
コード例 #2
0
def iterate(client=None):
    r"""
    Makes iteration agent.

    ..  container:: example

        Iterates leaves:

        >>> staff = abjad.Staff("c'4 e'4 d'4 f'4")
        >>> abjad.show(staff) # doctest: +SKIP

        ..  docs::

            >>> abjad.f(staff)
            \new Staff
            {
                c'4
                e'4
                d'4
                f'4
            }

        >>> for leaf in abjad.iterate(staff).leaves():
        ...     leaf
        ...
        Note("c'4")
        Note("e'4")
        Note("d'4")
        Note("f'4")

    """
    import abjad

    if client is not None:
        return abjad.Iteration(client=client)
    expression = abjad.Expression()
    expression = expression.iterate()
    return expression
コード例 #3
0
ファイル: sequence.py プロジェクト: tchiwinpiti/abjad
def sequence(items=None, **keywords):
    r'''Makes sequence or sequence expression.

    ..  container:: example

        ..  container:: example

            Makes sequence:

            >>> abjad.sequence([1, 2, [3, [4]], 5])
            Sequence([1, 2, [3, [4]], 5])

        ..  container:: example expression

            Makes sequence expression:

            >>> expression = abjad.sequence()
            >>> expression([1, 2, [3, [4]], 5])
            Sequence([1, 2, [3, [4]], 5])

    ..  container:: example

        Flattens, reverses and slices sequence:

        ..  container:: example

            >>> sequence_ = abjad.sequence([1, 2, [3, [4]], 5])
            >>> sequence_
            Sequence([1, 2, [3, [4]], 5])

            >>> sequence_ = sequence_.flatten(depth=-1)
            >>> sequence_
            Sequence([1, 2, 3, 4, 5])

            >>> sequence_ = sequence_.reverse()
            >>> sequence_
            Sequence([5, 4, 3, 2, 1])

            >>> sequence_ = sequence_[-3:]
            >>> sequence_
            Sequence([3, 2, 1])

        ..  container:: example expression

            >>> expression = abjad.sequence()
            >>> expression = expression.flatten(depth=-1)
            >>> expression = expression.reverse()
            >>> expression = expression[-3:]
            >>> expression([1, 2, [3, [4]], 5])
            Sequence([3, 2, 1])

    Returns sequence when `items` is not none.

    Returns sequence expression when `items` is none.
    '''
    import abjad
    if items is not None:
        return abjad.Sequence(items=items, **keywords)
    else:
        expression = abjad.Expression()
        expression = expression.sequence(**keywords)
        return expression
コード例 #4
0
def label(client=None, deactivate=None, tag=None):
    r"""
    Makes label agent or label expression.

    ..  container:: example

        Labels logical ties with start offsets:

        >>> staff = abjad.Staff(r"\times 2/3 { c'4 d'4 e'4 ~ } e'4 ef'4")
        >>> abjad.label(staff).with_start_offsets(direction=abjad.Up)
        Duration(1, 1)

        >>> abjad.override(staff).text_script.staff_padding = 4
        >>> abjad.override(staff).tuplet_bracket.staff_padding = 0
        >>> abjad.show(staff) # doctest: +SKIP

        ..  docs::

            >>> abjad.f(staff)
            \new Staff
            \with
            {
                \override TextScript.staff-padding = #4
                \override TupletBracket.staff-padding = #0
            }
            {
                \times 2/3 {
                    c'4
                    ^ \markup { 0 }
                    d'4
                    ^ \markup { 1/6 }
                    e'4
                    ^ \markup { 1/3 }
                    ~
                }
                e'4
                ef'4
                ^ \markup { 3/4 }
            }

        See the ``Label`` API entry for many more examples.

    ..  container:: example expression

        Initializes positionally:

        >>> expression = abjad.label()
        >>> expression(staff)
        Label(client=<Staff{3}>)

        Initializes from keyword:

        >>> expression = abjad.label()
        >>> expression(client=staff)
        Label(client=<Staff{3}>)

        Makes label expression:

            >>> expression = abjad.label()
            >>> expression = expression.with_start_offsets()

        >>> staff = abjad.Staff(r"\times 2/3 { c'4 d'4 e'4 ~ } e'4 ef'4")
        >>> expression(staff)
        Duration(1, 1)

        >>> abjad.override(staff).text_script.staff_padding = 4
        >>> abjad.override(staff).tuplet_bracket.staff_padding = 0
        >>> abjad.show(staff) # doctest: +SKIP

        ..  docs::

            >>> abjad.f(staff)
            \new Staff
            \with
            {
                \override TextScript.staff-padding = #4
                \override TupletBracket.staff-padding = #0
            }
            {
                \times 2/3 {
                    c'4
                    ^ \markup { 0 }
                    d'4
                    ^ \markup { 1/6 }
                    e'4
                    ^ \markup { 1/3 }
                    ~
                }
                e'4
                ef'4
                ^ \markup { 3/4 }
            }

        See the ``Label`` API entry for many more examples.

    Returns label agent when ``client`` is not none.

    Returns label expression when ``client`` is none.
    """
    import abjad
    if client is not None:
        return abjad.Label(
            client=client,
            deactivate=deactivate,
            tag=tag,
        )
    expression = abjad.Expression()
    expression = expression.label(tag=tag)
    return expression