コード例 #1
0
ファイル: make_leaves.py プロジェクト: Alwnikrotikz/abjad
def _make_leaf_on_pitch(
    pitch,
    duration,
    decrease_durations_monotonically=True,
    forbidden_written_duration=None,
    tie_rests=False,
    ):
    from abjad.tools import scoretools
    from abjad.tools import leaftools
    from abjad.tools import notetools
    from abjad.tools import resttools
    note_types = (numbers.Number, str, pitchtools.NamedPitch)
    chord_types = (tuple, list)
    rest_types = (type(None),)
    if isinstance(pitch, note_types):
        leaves = leaftools.make_tied_leaf(
            notetools.Note,
            duration,
            decrease_durations_monotonically=decrease_durations_monotonically,
            forbidden_written_duration=forbidden_written_duration,
            pitches=pitch,
            )
    elif isinstance(pitch, chord_types):
        leaves = leaftools.make_tied_leaf(
            scoretools.Chord,
            duration,
            decrease_durations_monotonically=decrease_durations_monotonically,
            forbidden_written_duration=forbidden_written_duration,
            pitches=pitch,
            )
    elif isinstance(pitch, rest_types):
        leaves = leaftools.make_tied_leaf(
            resttools.Rest,
            duration,
            decrease_durations_monotonically=decrease_durations_monotonically,
            forbidden_written_duration=forbidden_written_duration,
            pitches=None,
            tie_parts=tie_rests,
            )
    else:
        message = 'unknown pitch {!r}.'.format(pitch)
        raise ValueError(message)

    return leaves
コード例 #2
0
ファイル: make_notes.py プロジェクト: Alwnikrotikz/abjad
 def _make_unprolated_notes(
     pitches,
     durations,
     decrease_durations_monotonically=decrease_durations_monotonically,
     ):
     assert len(pitches) == len(durations)
     result = []
     for pitch, duration in zip(pitches, durations):
         result.extend(leaftools.make_tied_leaf(
             notetools.Note,
             duration,
             pitches=pitch,
             decrease_durations_monotonically=decrease_durations_monotonically,
             ))
     return result
コード例 #3
0
ファイル: make_rests.py プロジェクト: Alwnikrotikz/abjad
def make_rests(
    durations,
    decrease_durations_monotonically=True,
    tie_parts=False,
    ):
    r'''Make rests.

    Make rests and drecrease durations monotonically:

    ::

        >>> resttools.make_rests(
        ...     [(5, 16), (9, 16)], 
        ...     decrease_durations_monotonically=True,
        ...     )
        Selection(Rest('r4'), Rest('r16'), Rest('r2'), Rest('r16'))

    Makes rests and increase durations monotonically:

    ::

        >>> resttools.make_rests(
        ...     [(5, 16), (9, 16)], 
        ...     decrease_durations_monotonically=False,
        ...     )
        Selection(Rest('r16'), Rest('r4'), Rest('r16'), Rest('r2'))

    Make tied rests:

    ::

        >>> voice = Voice(resttools.make_rests(
        ...     [(5, 16), (9, 16)], 
        ...     tie_parts=True,
        ...     ))

    ..  doctest::

        >>> f(voice)
        \new Voice {
            r4 ~
            r16
            r2 ~
            r16
        }

    ::

        >>> show(voice) # doctest: +SKIP

    Returns list of rests.
    '''
    from abjad.tools import leaftools
    from abjad.tools import resttools

    # check input
    if isinstance(durations, (numbers.Number, tuple)):
        durations = [durations]

    # make rests
    result = []
    for duration in durations:
        rests = leaftools.make_tied_leaf(
            resttools.Rest,
            duration,
            pitches=None,
            decrease_durations_monotonically=decrease_durations_monotonically,
            tie_parts=tie_parts,
            )
        result.extend(rests)

    # return result
    result = selectiontools.Selection(result)
    return result
コード例 #4
0
def make_percussion_note(pitch, total_duration, max_note_duration=(1, 8)):
    r'''Makes short note with `max_note_duration` followed
    by rests together totaling `total_duration`.

    ..  container:: example

            >>> leaves = notetools.make_percussion_note(2, (1, 4), (1, 8))
            >>> staff = Staff(leaves)
            >>> show(staff) # doctest: +SKIP

        ..  doctest::

            >>> f(staff)
            \new Staff {
                d'8
                r8
            }

    ..  container:: example

            >>> leaves = notetools.make_percussion_note(2, (1, 64), (1, 8))
            >>> staff = Staff(leaves)
            >>> show(staff) # doctest: +SKIP

        ..  doctest::

            >>> f(staff)
            \new Staff {
                d'64
            }

    ..  container:: example

            >>> leaves = notetools.make_percussion_note(2, (5, 64), (1, 8))
            >>> staff = Staff(leaves)
            >>> show(staff) # doctest: +SKIP

        ..  doctest::

            >>> f(staff)
            \new Staff {
                d'16
                r64
            }

    ..  container:: example

            >>> leaves = notetools.make_percussion_note(2, (5, 4), (1, 8))
            >>> staff = Staff(leaves)
            >>> show(staff) # doctest: +SKIP

        ..  doctest::

            >>> f(staff)
            \new Staff {
                d'8
                r1 ~
                r8
            }

    Returns list of newly constructed note followed by zero or 
    more newly constructed rests.

    Durations of note and rests returned will sum to `total_duration`.

    Duration of note returned will be no greater than `max_note_duration`.

    Duration of rests returned will sum to note duration taken 
    from `total_duration`.

    Useful for percussion music where attack duration is negligible 
    and tied notes undesirable.
    '''
    from abjad.tools import notetools
    from abjad.tools import resttools
    from abjad.tools import selectiontools

    # check input
    total_duration = durationtools.Duration(total_duration)
    max_note_duration = durationtools.Duration(max_note_duration)

    # make note and rest
    if max_note_duration < total_duration:
        rest_duration = total_duration - max_note_duration
        rests = leaftools.make_tied_leaf(
            resttools.Rest,
            rest_duration,
            pitches=None,
            )
        notes = leaftools.make_tied_leaf(
            notetools.Note,
            max_note_duration,
            pitches=pitch,
            )
    else:
        notes = leaftools.make_tied_leaf(
            notetools.Note,
            total_duration,
            pitches=pitch,
            tie_parts=False,
            )
        if 1 < len(notes):
            new_notes = []
            new_notes.append(notes[0])
            for i in range(1, len(notes)):
                rest = resttools.Rest(notes[i])
                new_notes.append(rest)
            notes = new_notes
        rests = []

    # return list of percussion note followed by rest
    result = notes + rests
    result = selectiontools.Selection(result)
    return result