예제 #1
0
 def __init__(self, name='treble'):
     import abjad
     self._context = 'Staff'
     if isinstance(name, str):
         self._name = name
     elif isinstance(name, type(self)):
         self._name = name.name
     else:
         message = 'can not initialize clef: {!r}.'
         message = message.format(name)
         raise TypeError(message)
     middle_c_position = self._calculate_middle_c_position(self._name)
     middle_c_position = abjad.StaffPosition(middle_c_position)
     self._middle_c_position = middle_c_position
예제 #2
0
 def __init__(self, name='treble', hide=None):
     import abjad
     if isinstance(name, str):
         self._name = name
     elif isinstance(name, type(self)):
         self._name = name.name
     else:
         message = 'can not initialize clef: {!r}.'
         message = message.format(name)
         raise TypeError(message)
     if hide is not None:
         hide = bool(hide)
     self._hide = hide
     middle_c_position = self._calculate_middle_c_position(self._name)
     middle_c_position = abjad.StaffPosition(middle_c_position)
     self._middle_c_position = middle_c_position
def test_spannertools_OctavationSpanner_adjust_automatically_02():

    note = abjad.Note(31, (1, 4))
    container = abjad.Container([note])
    assert container[0].written_pitch.to_staff_position() == \
        abjad.StaffPosition(18)

    octavation_spanner = abjad.OctavationSpanner()
    abjad.attach(octavation_spanner, container[:])
    octavation_spanner.adjust_automatically(
        ottava_breakpoint=15,
        quindecisima_breakpoint=19,
    )

    assert format(container) == abjad.String.normalize(r"""
        {
            \ottava #1
            g'''4
            \ottava #0
        }
        """)

    assert abjad.inspect(container).is_well_formed()
예제 #4
0
    def to_staff_position(self, clef=None):
        r"""
        Changes named pitch to staff position.

        ..  container:: example

            Changes C#5 to absolute staff position:

            >>> abjad.NamedPitch('C#5').to_staff_position()
            StaffPosition(7)

            >>> abjad.NamedPitch('C#5').to_staff_position(clef='treble')
            StaffPosition(1)

            >>> abjad.NamedPitch('C#5').to_staff_position(clef='bass')
            StaffPosition(13)

        ..  container:: example

            Marks up absolute staff position of many pitches:

            >>> staff = abjad.Staff("g16 a b c' d' e' f' g' a' b' c'' d'' e'' f'' g'' a''")
            >>> for note in staff:
            ...     staff_position = note.written_pitch.to_staff_position()
            ...     markup = abjad.Markup(staff_position.number)
            ...     abjad.attach(markup, note)
            ...
            >>> abjad.override(staff).text_script.staff_padding = 5
            >>> abjad.show(staff) # doctest: +SKIP

            ..  docs::

                >>> abjad.f(staff)
                \new Staff
                \with
                {
                    \override TextScript.staff-padding = #5
                }
                {
                    g16
                    - \markup { -3 }
                    a16
                    - \markup { -2 }
                    b16
                    - \markup { -1 }
                    c'16
                    - \markup { 0 }
                    d'16
                    - \markup { 1 }
                    e'16
                    - \markup { 2 }
                    f'16
                    - \markup { 3 }
                    g'16
                    - \markup { 4 }
                    a'16
                    - \markup { 5 }
                    b'16
                    - \markup { 6 }
                    c''16
                    - \markup { 7 }
                    d''16
                    - \markup { 8 }
                    e''16
                    - \markup { 9 }
                    f''16
                    - \markup { 10 }
                    g''16
                    - \markup { 11 }
                    a''16
                    - \markup { 12 }
                }

        ..  container:: example

            Marks up treble staff position of many pitches:

            >>> staff = abjad.Staff("g16 a b c' d' e' f' g' a' b' c'' d'' e'' f'' g'' a''")
            >>> clef = abjad.Clef('treble')
            >>> for note in staff:
            ...     staff_position = note.written_pitch.to_staff_position(
            ...         clef=clef
            ...         )
            ...     markup = abjad.Markup(staff_position.number)
            ...     abjad.attach(markup, note)
            ...
            >>> abjad.override(staff).text_script.staff_padding = 5
            >>> abjad.show(staff) # doctest: +SKIP

            ..  docs::

                >>> abjad.f(staff)
                \new Staff
                \with
                {
                    \override TextScript.staff-padding = #5
                }
                {
                    g16
                    - \markup { -9 }
                    a16
                    - \markup { -8 }
                    b16
                    - \markup { -7 }
                    c'16
                    - \markup { -6 }
                    d'16
                    - \markup { -5 }
                    e'16
                    - \markup { -4 }
                    f'16
                    - \markup { -3 }
                    g'16
                    - \markup { -2 }
                    a'16
                    - \markup { -1 }
                    b'16
                    - \markup { 0 }
                    c''16
                    - \markup { 1 }
                    d''16
                    - \markup { 2 }
                    e''16
                    - \markup { 3 }
                    f''16
                    - \markup { 4 }
                    g''16
                    - \markup { 5 }
                    a''16
                    - \markup { 6 }
                }

        ..  container:: example

            Marks up bass staff position of many pitches:

            >>> staff = abjad.Staff("g,16 a, b, c d e f g a b c' d' e' f' g' a'")
            >>> clef = abjad.Clef('bass')
            >>> abjad.attach(clef, staff[0])
            >>> for note in staff:
            ...     staff_position = note.written_pitch.to_staff_position(
            ...         clef=clef
            ...         )
            ...     markup = abjad.Markup(staff_position.number)
            ...     abjad.attach(markup, note)
            ...
            >>> abjad.override(staff).text_script.staff_padding = 5
            >>> abjad.show(staff) # doctest: +SKIP

            ..  docs::

                >>> abjad.f(staff)
                \new Staff
                \with
                {
                    \override TextScript.staff-padding = #5
                }
                {
                    \clef "bass"
                    g,16
                    - \markup { -4 }
                    a,16
                    - \markup { -3 }
                    b,16
                    - \markup { -2 }
                    c16
                    - \markup { -1 }
                    d16
                    - \markup { 0 }
                    e16
                    - \markup { 1 }
                    f16
                    - \markup { 2 }
                    g16
                    - \markup { 3 }
                    a16
                    - \markup { 4 }
                    b16
                    - \markup { 5 }
                    c'16
                    - \markup { 6 }
                    d'16
                    - \markup { 7 }
                    e'16
                    - \markup { 8 }
                    f'16
                    - \markup { 9 }
                    g'16
                    - \markup { 10 }
                    a'16
                    - \markup { 11 }
                }

        Returns staff position.
        """
        import abjad
        staff_position_number = self._get_diatonic_pitch_number()
        if clef is not None:
            clef = abjad.Clef(clef)
            staff_position_number += clef.middle_c_position.number
        staff_position = abjad.StaffPosition(staff_position_number)
        return staff_position