How to use the abjad.tools.scoretools function in abjad

To help you get started, we’ve selected a few abjad examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Abjad / abjad / trunk / abjad / tools / scoretools / make_leaves.py View on Github external
numerator = \
                mathtools.greatest_power_of_two_less_equal(denominator)
            multiplier = (numerator, denominator)
            ratio = 1 / durationtools.Duration(*multiplier)
            duration_group = [ratio * durationtools.Duration(duration) 
                for duration in duration_group]
            # make tuplet leaves
            tuplet_leaves = []
            for pitch, duration in zip(current_pitches, duration_group):
                leaves = _make_leaf_on_pitch(
                    pitch,
                    duration,
                    decrease_durations_monotonically=decrease_durations_monotonically,
                    )
                tuplet_leaves.extend(leaves)
            tuplet = scoretools.Tuplet(multiplier, tuplet_leaves)
            result.append(tuplet)

    result = selectiontools.Selection(result)
    return result
github Abjad / abjad / trunk / abjad / tools / scoretools / get_measure_that_stops_with_container.py View on Github external
def get_measure_that_stops_with_container(container):
    '''Get measure that stops with `container`.

    Returns measure or none.
    '''
    from abjad.tools import scoretools

    if isinstance(container, scoretools.Container):
        contents = container._get_descendants_stopping_with()
        contents = [x for x in contents if isinstance(x, scoretools.Measure)]
        if contents:
            return contents[0]
        raise MissingMeasureError
github Abjad / abjad / trunk / abjad / tools / scoretools / iterate_scores_backward_in_expr.py View on Github external
>>> scores = [score_1, score_2]

    ::

        >>> for score in scoretools.iterate_scores_backward_in_expr(scores):
        ...   score
        Score<<2>>
        Score<<1>>

    Ignore threads.

    Return generator.
    '''
    from abjad.tools import scoretools

    return scoretools.iterate_scores_in_expr(
        expr, reverse=True, start=start, stop=stop)
github Abjad / abjad / trunk / abjad / tools / scoretools / replace_contents_of_measures_in_expr.py View on Github external
Pads extra space at end of measures with spacer skip.

    Raises stop iteration if not enough measures.

    Returns measures iterated.
    '''
    from abjad.tools import marktools
    from abjad.tools import scoretools
    from abjad.tools.functiontools import attach

    # init return list
    result = []

    # get first measure and first time signature
    current_measure = scoretools.get_next_measure_from_component(expr)
    result.append(current_measure)
    current_time_signature = current_measure.time_signature
    # to avoide pychecker slice assignment error
    #del(current_measure[:])
    current_measure.__delitem__(slice(0, len(current_measure)))

    # iterate new contents
    while new_contents:

        # find candidate duration of new element plus current measure
        current_element = new_contents[0]
        multiplier = current_time_signature.implied_prolation
        preprolated_duration = current_element._preprolated_duration
        duration = multiplier * preprolated_duration
        candidate_duration = current_measure._get_duration() + duration
github Abjad / abjad / experimental / tools / musicexpressiontools / Interpreter.py View on Github external
def instantiate_score(self):
        score = self.score_specification.score_template()
        context = scoretools.Context(
            name='TimeSignatureContext',
            context_name='TimeSignatureContext',
            )
        score.insert(0, context)
        return score
github Abjad / abjad / trunk / abjad / tools / lilypondparsertools / LilyPondSyntacticalDefinition.py View on Github external
def p_simple_element__pitch__exclamations__questions__octave_check__optional_notemode_duration__optional_rest(self, p):
        'simple_element : pitch exclamations questions octave_check optional_notemode_duration optional_rest'
        if not p[6]:
            leaf = scoretools.Note(p[1], p[5].duration)
            leaf.note_head.is_forced = bool(p[2])
            leaf.note_head.is_cautionary = bool(p[3])
        else:
            leaf = scoretools.Rest(p[5].duration)
        if p[5].multiplier is not None:
            leaf.lilypond_duration_multiplier = p[5].multiplier
        # TODO: handle exclamations, questions, octave_check
        p[0] = leaf
github Abjad / abjad / abjad / tools / systemtools / UpdateManager.py View on Github external
from abjad.tools import scoretools
        from abjad.tools.topleveltools import iterate
        if isinstance(score_root, scoretools.Context):
            contexts = iterate(score_root).components(scoretools.Context)
            for context in contexts:
                for leaf_index, leaf in enumerate(iterate(context).leaves()):
                    leaf._leaf_index = leaf_index
                for measure_index, measure in enumerate(
                    iterate(context).components(scoretools.Measure)):
                    measure_number = measure_index + 1
                    measure._measure_number = measure_number
        else:
            for leaf_index, leaf in enumerate(iterate(score_root).leaves()):
                leaf._leaf_index = leaf_index
            for measure_index, measure in enumerate(
                iterate(score_root).components(scoretools.Measure)):
                measure_number = measure_index + 1
                measure._measure_number = measure_number
github Abjad / abjad / abjad / tools / instrumenttools / transpose_from_written_pitch_to_sounding_pitch.py View on Github external
..  docs::

            >>> f(staff)
            \new Staff {
                \set Staff.instrumentName = \markup { "Clarinet in B-flat" }
                \set Staff.shortInstrumentName = \markup { "Cl. in B-flat" }
                4
                c'4
                r4
                d'4
            }

    Returns none.
    '''
    from abjad.tools import instrumenttools
    prototype = (scoretools.Note, scoretools.Chord)
    for note_or_chord in iterate(argument).by_class(prototype):
        instrument = note_or_chord._get_effective(
            instrumenttools.Instrument)
        if not instrument:
            continue
        sounding_pitch = instrument.sounding_pitch_of_written_middle_c
        interval = pitchtools.NamedPitch('C4') - sounding_pitch
        if isinstance(note_or_chord, scoretools.Note):
            written_pitch = note_or_chord.written_pitch
            written_pitch = interval.transpose(written_pitch)
            note_or_chord.written_pitch = written_pitch
        elif isinstance(note_or_chord, scoretools.Chord):
            pitches = [
                interval.transpose(pitch)
                for pitch in note_or_chord.written_pitches
                ]
github Abjad / abjad / trunk / abjad / tools / scoretools / make_piano_score_from_leaves.py View on Github external
::

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

    When ``lowest_treble_pitch=None`` set to B3.

    Returns score, treble staff, bass staff.
    """
    from abjad.tools import pitchtools
    from abjad.tools import scoretools

    if lowest_treble_pitch is None:
        lowest_treble_pitch = pitchtools.NamedPitch('b')

    score, treble_staff, bass_staff = scoretools.make_empty_piano_score()
    for leaf in leaves:
        treble_chord, bass_chord = leaf._divide(lowest_treble_pitch)
        treble_staff.append(treble_chord)
        bass_staff.append(bass_chord)

    return score, treble_staff, bass_staff
github Abjad / abjad / trunk / abjad / tools / marktools / StaffChangeMark.py View on Github external
def __init__(self, staff=None, target_context=None):
        from abjad.tools import scoretools
        target_context = target_context or scoretools.Staff
        ContextMark.__init__(self, target_context=target_context)
        if not isinstance(staff, (scoretools.Staff, type(None))):
            message = 'staff change mark input value {!r}'
            message += ' must be staff instance.'
            message.format(staff)
            raise TypeError(message)
        self._staff = staff