예제 #1
0
 def skip(self, duration):
     r'''Handles LilyPond ``\skip`` command.
     '''
     leaf = scoretools.Skip(duration.duration)
     if duration.multiplier is not None:
         attach(duration.multiplier, leaf)
     return leaf
예제 #2
0
def make_skips(
    written_duration,
    multiplied_durations,
    ):
    '''Make `written_duration` skips with `multiplied_durations`:

    ::

        >>> scoretools.make_skips(
        ...     Duration(1, 4), [(1, 2), (1, 3), (1, 4), (1, 5)])
        Selection(Skip('s4 * 2'), Skip('s4 * 4/3'), Skip('s4 * 1'), Skip('s4 * 4/5'))

    Useful for making invisible layout voices.

    Returns selection.
    '''
    from abjad.tools import scoretools

    # initialize skips and written duration
    skips = []
    written_duration = durationtools.Duration(written_duration)

    # make skips
    for multiplied_duration in multiplied_durations:
        multiplied_duration = durationtools.Duration(multiplied_duration)
        skip = scoretools.Skip(written_duration)
        multiplier = multiplied_duration / written_duration
        attach(multiplier, skip)
        skips.append(skip)

    # return skips
    skips = selectiontools.Selection(skips)
    return skips
예제 #3
0
    def __illustrate__(self):
        r'''Illustrates pitch range.

        ::

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

        Returns LilyPond file.
        '''
        from abjad.tools import durationtools
        from abjad.tools import lilypondfiletools
        from abjad.tools import indicatortools
        from abjad.tools import markuptools
        from abjad.tools import pitchtools
        from abjad.tools import scoretools
        from abjad.tools import spannertools
        from abjad.tools.topleveltools import attach
        from abjad.tools.topleveltools import iterate
        from abjad.tools.topleveltools import override
        start_pitch_clef = pitchtools.suggest_clef_for_named_pitches(
            self.start_pitch)
        stop_pitch_clef = pitchtools.suggest_clef_for_named_pitches(
            self.stop_pitch)
        start_note = scoretools.Note(self.start_pitch, 1)
        stop_note = scoretools.Note(self.stop_pitch, 1)
        glissando = spannertools.Glissando()
        if start_pitch_clef == stop_pitch_clef:
            if start_pitch_clef == indicatortools.Clef('bass'):
                bass_staff = scoretools.Staff()
                attach(indicatortools.Clef('bass'), bass_staff)
                bass_staff.extend([start_note, stop_note])
                attach(glissando, bass_staff.select_leaves())
                score = scoretools.Score([bass_staff])
            else:
                treble_staff = scoretools.Staff()
                attach(indicatortools.Clef('treble'), treble_staff)
                treble_staff.extend([start_note, stop_note])
                attach(glissando, treble_staff.select_leaves())
                score = scoretools.Score([treble_staff])
        else:
            result = scoretools.make_empty_piano_score()
            score, treble_staff, bass_staff = result
            bass_staff.extend([start_note, stop_note])
            treble_staff.extend(scoretools.Skip(1) * 2)
            attach(glissando, bass_staff.select_leaves())
            attach(indicatortools.StaffChange(treble_staff), bass_staff[1])
        for leaf in iterate(score).by_class(scoretools.Leaf):
            attach(durationtools.Multiplier(1, 4), leaf)
        override(score).bar_line.stencil = False
        override(score).span_bar.stencil = False
        override(score).glissando.thickness = 2
        override(score).time_signature.stencil = False
        lilypond_file = lilypondfiletools.make_basic_lilypond_file(score)
        lilypond_file.header_block.tagline = markuptools.Markup('""')
        return lilypond_file
예제 #4
0
def append_spacer_skip_to_underfull_measure(measure):
    r'''Append spacer skip to underfull `measure`:

    ::

        >>> measure = Measure((4, 12), "c'8 d'8 e'8 f'8")
        >>> measure.implicit_scaling = True
        >>> detach(TimeSignature, measure)
        (TimeSignature((4, 12)),)
        >>> new_time_signature = TimeSignature((5, 12))
        >>> attach(new_time_signature, measure)
        >>> measure.is_underfull
        True

    ::

        >>> scoretools.append_spacer_skip_to_underfull_measure(measure)
        Measure((5, 12), "c'8 d'8 e'8 f'8 s1 * 1/8", implicit_scaling=True)

    ..  doctest::

        >>> print(format(measure))
        {
            \time 5/12
            \scaleDurations #'(2 . 3) {
                c'8
                d'8
                e'8
                f'8
                s1 * 1/8
            }
        }

    Append nothing to nonunderfull `measure`.

    Return `measure`.
    '''
    from abjad.tools import scoretools

    assert isinstance(measure, scoretools.Measure)

    if measure.is_underfull:
        target_duration = measure.time_signature.duration
        duration = measure._get_duration()
        skip = scoretools.Skip((1, 1))
        time_signature_multiplier = \
            measure.time_signature.implied_prolation
        new_duration = target_duration - duration
        new_multiplier = new_duration.__div__(time_signature_multiplier)
        attach(new_multiplier, skip)
        measure.append(skip)

    return measure
def _make_repeated_skips_from_time_signature(time_signature):
    from abjad.tools import scoretools

    # afford basic input polymorphism
    time_signature = indicatortools.TimeSignature(time_signature)

    # check input
    if time_signature.has_non_power_of_two_denominator:
        message = 'TODO: extend this function for time signatures'
        message += ' with non-power-of-two denominators.'
        raise NotImplementedError(message)

    # make and return repeated skips
    skip = scoretools.Skip((1, time_signature.denominator))
    skips = time_signature.numerator * skip
    result = selectiontools.Selection(skips)
def fill_measures_in_expr_with_full_measure_spacer_skips(expr, iterctrl=None):
    r'''Fill measures in `expr` with full-measure spacer skips.
    '''
    from abjad.tools import scoretools

    if iterctrl is None:
        iterctrl = lambda measure, i: True

    measures = iterate(expr).by_class(scoretools.Measure)
    for i, measure in enumerate(measures):
        if iterctrl(measure, i):
            skip = scoretools.Skip(1)
            # allow zero-update iteration
            time_signature = measure.time_signature
            duration = time_signature.duration
            if measure.implicit_scaling:
                implied_prolation = time_signature.implied_prolation
                multiplier = duration.__div__(implied_prolation)
            else:
                multiplier = durationtools.Multiplier(duration)
            attach(multiplier, skip)
            measure[:] = [skip]
            for spanner in measure._get_spanners():
                spanner._remove(measure)
예제 #7
0
    def __illustrate__(self):
        r'''Illustrates pitch range inventory.

        ::

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

        Returns LilyPond file.
        '''
        from abjad.tools import durationtools
        from abjad.tools import lilypondfiletools
        from abjad.tools import indicatortools
        from abjad.tools import markuptools
        from abjad.tools import pitchtools
        from abjad.tools import scoretools
        from abjad.tools import spannertools
        from abjad.tools.topleveltools import attach
        from abjad.tools.topleveltools import iterate
        from abjad.tools.topleveltools import override
        start_note_clefs = []
        stop_note_clefs = []
        for pitch_range in self.items:
            start_note_clef = indicatortools.Clef.from_selection(
                pitch_range.start_pitch)
            start_note_clefs.append(start_note_clef)
            stop_note_clef = indicatortools.Clef.from_selection(
                pitch_range.stop_pitch)
            stop_note_clefs.append(stop_note_clef)
        if start_note_clefs == stop_note_clefs:
            clef = start_note_clefs[0]
            staff = scoretools.Staff()
            attach(clef, staff)
            score = scoretools.Score([staff])
            for pitch_range in self.items:
                start_note = scoretools.Note(pitch_range.start_pitch, 1)
                stop_note = scoretools.Note(pitch_range.stop_pitch, 1)
                notes = [start_note, stop_note]
                glissando = spannertools.Glissando()
                staff.extend(notes)
                attach(glissando, notes)
        else:
            result = scoretools.make_empty_piano_score()
            score, treble_staff, bass_staff = result
            for pitch_range in self.items:
                start_note = scoretools.Note(pitch_range.start_pitch, 1)
                start_note_clef = indicatortools.Clef.from_selection(
                    pitch_range.start_pitch)
                stop_note = scoretools.Note(pitch_range.stop_pitch, 1)
                stop_note_clef = indicatortools.Clef.from_selection(
                    pitch_range.stop_pitch)
                notes = [start_note, stop_note]
                glissando = spannertools.Glissando()
                skips = 2 * scoretools.Skip(1)
                treble_clef = indicatortools.Clef('treble')
                bass_clef = indicatortools.Clef('bass')
                if start_note_clef == stop_note_clef == treble_clef:
                    treble_staff.extend(notes)
                    bass_staff.extend(skips)
                elif start_note_clef == stop_note_clef == bass_clef:
                    bass_staff.extend(notes)
                    treble_staff.extend(skips)
                else:
                    assert start_note_clef == bass_clef
                    assert stop_note_clef == treble_clef
                    bass_staff.extend(notes)
                    treble_staff.extend(skips)
                    staff_change = indicatortools.StaffChange(treble_staff)
                    attach(staff_change, stop_note)
                attach(glissando, notes)
        for leaf in iterate(score).by_class(scoretools.Leaf):
            multiplier = durationtools.Multiplier(1, 4)
            attach(multiplier, leaf)
        override(score).bar_line.stencil = False
        override(score).span_bar.stencil = False
        override(score).glissando.thickness = 2
        override(score).time_signature.stencil = False
        lilypond_file = lilypondfiletools.make_basic_lilypond_file(score)
        lilypond_file.items.remove(lilypond_file['layout'])
        lilypond_file.items.remove(lilypond_file['paper'])
        lilypond_file.header_block.tagline = markuptools.Markup('""')
        return lilypond_file