コード例 #1
0
ファイル: make_leaves.py プロジェクト: ajyoon/abjad
def _make_leaf_on_pitch(
    pitch,
    duration,
    decrease_durations_monotonically=True,
    forbidden_written_duration=None,
    use_multimeasure_rests=False,
    use_messiaen_style_ties=False,
    ):
    from abjad.tools import scoretools
    note_prototype = (
        numbers.Number,
        str,
        pitchtools.NamedPitch,
        pitchtools.PitchClass,
        )
    chord_prototype = (tuple, list)
    rest_prototype = (type(None),)
    if isinstance(pitch, note_prototype):
        leaves = scoretools.make_tied_leaf(
            scoretools.Note,
            duration,
            decrease_durations_monotonically=decrease_durations_monotonically,
            forbidden_written_duration=forbidden_written_duration,
            pitches=pitch,
            use_messiaen_style_ties=use_messiaen_style_ties,
            )
    elif isinstance(pitch, chord_prototype):
        leaves = scoretools.make_tied_leaf(
            scoretools.Chord,
            duration,
            decrease_durations_monotonically=decrease_durations_monotonically,
            forbidden_written_duration=forbidden_written_duration,
            pitches=pitch,
            use_messiaen_style_ties=use_messiaen_style_ties,
            )
    elif isinstance(pitch, rest_prototype) and not use_multimeasure_rests:
        leaves = scoretools.make_tied_leaf(
            scoretools.Rest,
            duration,
            decrease_durations_monotonically=decrease_durations_monotonically,
            forbidden_written_duration=forbidden_written_duration,
            pitches=None,
            use_messiaen_style_ties=use_messiaen_style_ties,
            )
    elif isinstance(pitch, rest_prototype) and use_multimeasure_rests:
        multimeasure_rest = scoretools.MultimeasureRest((1))
        multiplier = durationtools.Multiplier(duration)
        attach(multiplier, multimeasure_rest)
        leaves = (
            multimeasure_rest,
            )
    else:
        message = 'unknown pitch {!r}.'
        message = message.format(pitch)
        raise ValueError(message)
    return leaves
コード例 #2
0
ファイル: make_leaves.py プロジェクト: quesebifurcan/abjad
def _make_leaf_on_pitch(
    pitch,
    duration,
    decrease_durations_monotonically=True,
    forbidden_written_duration=None,
    use_multimeasure_rests=False,
    use_messiaen_style_ties=False,
):
    from abjad.tools import scoretools
    note_prototype = (
        numbers.Number,
        str,
        pitchtools.NamedPitch,
        pitchtools.PitchClass,
    )
    chord_prototype = (tuple, list)
    rest_prototype = (type(None), )
    if isinstance(pitch, note_prototype):
        leaves = scoretools.make_tied_leaf(
            scoretools.Note,
            duration,
            decrease_durations_monotonically=decrease_durations_monotonically,
            forbidden_written_duration=forbidden_written_duration,
            pitches=pitch,
            use_messiaen_style_ties=use_messiaen_style_ties,
        )
    elif isinstance(pitch, chord_prototype):
        leaves = scoretools.make_tied_leaf(
            scoretools.Chord,
            duration,
            decrease_durations_monotonically=decrease_durations_monotonically,
            forbidden_written_duration=forbidden_written_duration,
            pitches=pitch,
            use_messiaen_style_ties=use_messiaen_style_ties,
        )
    elif isinstance(pitch, rest_prototype) and not use_multimeasure_rests:
        leaves = scoretools.make_tied_leaf(
            scoretools.Rest,
            duration,
            decrease_durations_monotonically=decrease_durations_monotonically,
            forbidden_written_duration=forbidden_written_duration,
            pitches=None,
            use_messiaen_style_ties=use_messiaen_style_ties,
        )
    elif isinstance(pitch, rest_prototype) and use_multimeasure_rests:
        multimeasure_rest = scoretools.MultimeasureRest((1))
        multiplier = durationtools.Multiplier(duration)
        attach(multiplier, multimeasure_rest)
        leaves = (multimeasure_rest, )
    else:
        message = 'unknown pitch {!r}.'
        message = message.format(pitch)
        raise ValueError(message)
    return leaves
コード例 #3
0
ファイル: make_leaves.py プロジェクト: adorsk/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 scoretools
    from abjad.tools import scoretools
    from abjad.tools import scoretools
    note_types = (numbers.Number, str, pitchtools.NamedPitch)
    chord_types = (tuple, list)
    rest_types = (type(None),)
    if isinstance(pitch, note_types):
        leaves = scoretools.make_tied_leaf(
            scoretools.Note,
            duration,
            decrease_durations_monotonically=decrease_durations_monotonically,
            forbidden_written_duration=forbidden_written_duration,
            pitches=pitch,
            )
    elif isinstance(pitch, chord_types):
        leaves = scoretools.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 = scoretools.make_tied_leaf(
            scoretools.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}.'
        message = message.format(pitch)
        raise ValueError(message)

    return leaves
コード例 #4
0
def _make_leaf_on_pitch(
    pitch,
    duration,
    decrease_durations_monotonically=True,
    forbidden_written_duration=None,
):
    from abjad.tools import scoretools
    note_types = (numbers.Number, str, pitchtools.NamedPitch)
    chord_types = (tuple, list)
    rest_types = (type(None), )
    if isinstance(pitch, note_types):
        leaves = scoretools.make_tied_leaf(
            scoretools.Note,
            duration,
            decrease_durations_monotonically=decrease_durations_monotonically,
            forbidden_written_duration=forbidden_written_duration,
            pitches=pitch,
        )
    elif isinstance(pitch, chord_types):
        leaves = scoretools.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 = scoretools.make_tied_leaf(
            scoretools.Rest,
            duration,
            decrease_durations_monotonically=decrease_durations_monotonically,
            forbidden_written_duration=forbidden_written_duration,
            pitches=None,
        )
    else:
        message = 'unknown pitch {!r}.'
        message = message.format(pitch)
        raise ValueError(message)

    return leaves
コード例 #5
0
ファイル: make_notes.py プロジェクト: jefftrevino/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(scoretools.make_tied_leaf(
             scoretools.Note,
             duration,
             pitches=pitch,
             decrease_durations_monotonically=decrease_durations_monotonically,
             ))
     return result
コード例 #6
0
 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(
             scoretools.make_tied_leaf(
                 scoretools.Note,
                 duration,
                 pitches=pitch,
                 decrease_durations_monotonically=
                 decrease_durations_monotonically,
             ))
     return result
コード例 #7
0
ファイル: make_percussion_note.py プロジェクト: adorsk/abjad
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 = scoretools.make_percussion_note(2, (1, 4), (1, 8))
            >>> staff = Staff(leaves)
            >>> show(staff) # doctest: +SKIP

        ..  doctest::

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

    ..  container:: example

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

        ..  doctest::

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

    ..  container:: example

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

        ..  doctest::

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

    ..  container:: example

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

        ..  doctest::

            >>> print format(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 scoretools
    from abjad.tools import scoretools
    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 = scoretools.make_tied_leaf(
            scoretools.Rest,
            rest_duration,
            pitches=None,
            )
        notes = scoretools.make_tied_leaf(
            scoretools.Note,
            max_note_duration,
            pitches=pitch,
            )
    else:
        notes = scoretools.make_tied_leaf(
            scoretools.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 = scoretools.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
コード例 #8
0
ファイル: make_rests.py プロジェクト: adorsk/abjad
def make_rests(
    durations,
    decrease_durations_monotonically=True,
    tie_parts=False,
    ):
    r'''Make rests.

    Make rests and drecrease durations monotonically:

    ::

        >>> scoretools.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:

    ::

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

    Make tied rests:

    ::

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

    ..  doctest::

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

    ::

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

    Returns list of rests.
    '''
    from abjad.tools import scoretools
    from abjad.tools import scoretools

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

    # make rests
    result = []
    for duration in durations:
        rests = scoretools.make_tied_leaf(
            scoretools.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
コード例 #9
0
def make_rests(
    durations,
    decrease_durations_monotonically=True,
    tie_parts=False,
):
    r'''Make rests.

    Make rests and drecrease durations monotonically:

    ::

        >>> scoretools.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:

    ::

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

    Make tied rests:

    ::

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

    ..  doctest::

        >>> print(format(voice))
        \new Voice {
            r4
            r16
            r2
            r16
        }

    ::

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

    Returns list of rests.
    '''
    from abjad.tools import scoretools
    from abjad.tools import scoretools

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

    # make rests
    result = []
    for duration in durations:
        rests = scoretools.make_tied_leaf(
            scoretools.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
コード例 #10
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 = scoretools.make_percussion_note(2, (1, 4), (1, 8))
            >>> staff = Staff(leaves)
            >>> show(staff) # doctest: +SKIP

        ..  doctest::

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

    ..  container:: example

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

        ..  doctest::

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

    ..  container:: example

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

        ..  doctest::

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

    ..  container:: example

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

        ..  doctest::

            >>> print(format(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 scoretools
    from abjad.tools import scoretools
    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 = scoretools.make_tied_leaf(
            scoretools.Rest,
            rest_duration,
            pitches=None,
        )
        notes = scoretools.make_tied_leaf(
            scoretools.Note,
            max_note_duration,
            pitches=pitch,
        )
    else:
        notes = scoretools.make_tied_leaf(
            scoretools.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 = scoretools.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