Ejemplo n.º 1
0
 def __init__(
     self,
     left_rhythm=None,
     right_rhythm=None,
     left_markup=None,
     right_markup=None,
     ):
     from abjad.tools import indicatortools
     from abjad.tools import markuptools
     from abjad.tools import scoretools
     # TODO: make default scope work
     #self._default_scope = scoretools.Score
     self._default_scope = None
     left_rhythm = left_rhythm or scoretools.Note('c4')
     right_rhythm = right_rhythm or scoretools.Note('c4')
     left_rhythm = self._initialize_rhythm(left_rhythm)
     self._left_rhythm = left_rhythm
     right_rhythm = self._initialize_rhythm(right_rhythm)
     self._right_rhythm = right_rhythm
     self._right_rhythm = right_rhythm
     if left_markup is not None:
         assert isinstance(left_markup, markuptools.Markup)
     self._left_markup = left_markup
     if right_markup is not None:
         assert isinstance(right_markup, markuptools.Markup)
     self._right_markup = right_markup
Ejemplo n.º 2
0
def edit_second_violin_voice(score, durated_reservoir):
    r'''Edits second violin voice.
    '''

    voice = score['Second Violin Voice']
    descents = durated_reservoir['Second Violin']

    last_descent = select(descents[-1])
    copied_descent = mutate(last_descent).copy()
    copied_descent = list(copied_descent)
    copied_descent[-1].written_duration = durationtools.Duration(1, 1)
    copied_descent.append(scoretools.Note('a2'))
    for leaf in copied_descent:
        articulation = indicatortools.Articulation('accent')
        attach(articulation, leaf)
        articulation = indicatortools.Articulation('tenuto')
        attach(articulation, leaf)
    voice.extend(copied_descent)

    final_sustain = []
    for _ in range(32):
        final_sustain.append(scoretools.Note('a1.'))
    final_sustain.append(scoretools.Note('a2'))
    articulation = indicatortools.Articulation('accent')
    attach(articulation, final_sustain[0])
    articulation = indicatortools.Articulation('tenuto')
    attach(articulation, final_sustain[0])

    voice.extend(final_sustain)
    tie = spannertools.Tie()
    attach(tie, final_sustain)
    voice.extend('r4 r2.')
Ejemplo n.º 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
Ejemplo n.º 4
0
    def __illustrate__(self):
        r'''Illustrates tempo 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
        from abjad.tools.topleveltools import new
        staff = scoretools.Staff()
        score = scoretools.Score([staff])
        time_signature = indicatortools.TimeSignature((2, 4))
        attach(time_signature, staff)
        # the zero note avoids a lilypond spacing problem:
        # score-initial tempo indications slip to the left
        zero_note = scoretools.Note("c'2")
        staff.append(zero_note)
        command = indicatortools.LilyPondCommand('break')
        attach(command, zero_note)
        for tempo in self.items:
            note = scoretools.Note("c'2")
            attach(tempo, note)
            staff.append(note)
            command = indicatortools.LilyPondCommand('break')
            attach(command, note)
        override(score).bar_line.transparent = True
        override(score).bar_number.stencil = False
        override(score).clef.stencil = False
        override(score).note_head.no_ledgers = True
        override(score).note_head.transparent = True
        override(score).staff_symbol.transparent = True
        override(score).stem.transparent = True
        override(score).time_signature.stencil = False
        lilypond_file = lilypondfiletools.make_basic_lilypond_file(score)
        lilypond_file.layout_block.indent = 0
        lilypond_file.layout_block.ragged_right = True
        lilypond_file.items.remove(lilypond_file['paper'])
        lilypond_file.header_block.tagline = markuptools.Markup('""')
        return lilypond_file
Ejemplo n.º 5
0
    def __illustrate__(self, **kwargs):
        r'''Illustrates segment.

        Returns LilyPond file.
        '''
        from abjad.tools import durationtools
        from abjad.tools import indicatortools
        from abjad.tools import lilypondfiletools
        from abjad.tools import markuptools
        from abjad.tools import scoretools
        from abjad.tools import schemetools
        from abjad.tools.topleveltools import attach
        from abjad.tools.topleveltools import override
        from abjad.tools.topleveltools import select
        from abjad.tools.topleveltools import set_
        notes = []
        for item in self:
            note = scoretools.Note(item, durationtools.Duration(1, 8))
            notes.append(note)
        voice = scoretools.Voice(notes)
        staff = scoretools.Staff([voice])
        score = scoretools.Score([staff])
        score.add_final_bar_line()
        override(score).bar_line.transparent = True
        override(score).bar_number.stencil = False
        override(score).beam.stencil = False
        override(score).flag.stencil = False
        override(score).stem.stencil = False
        override(score).time_signature.stencil = False
        string = 'override Score.BarLine.transparent = ##f'
        command = indicatortools.LilyPondCommand(string, format_slot='after')
        last_leaf = select().by_leaf()(score)[-1][-1]
        attach(command, last_leaf)
        moment = schemetools.SchemeMoment((1, 12))
        set_(score).proportional_notation_duration = moment
        lilypond_file = lilypondfiletools.make_basic_lilypond_file(
            global_staff_size=12,
            music=score,
        )
        if 'title' in kwargs:
            title = kwargs.get('title')
            if not isinstance(title, markuptools.Markup):
                title = markuptools.Markup(title)
            lilypond_file.header_block.title = title
        if 'subtitle' in kwargs:
            markup = markuptools.Markup(kwargs.get('subtitle'))
            lilypond_file.header_block.subtitle = markup
        command = indicatortools.LilyPondCommand('accidentalStyle forget')
        lilypond_file.layout_block.items.append(command)
        lilypond_file.layout_block.indent = 0
        string = 'markup-system-spacing.padding = 8'
        command = indicatortools.LilyPondCommand(string, prefix='')
        lilypond_file.paper_block.items.append(command)
        string = 'system-system-spacing.padding = 10'
        command = indicatortools.LilyPondCommand(string, prefix='')
        lilypond_file.paper_block.items.append(command)
        string = 'top-markup-spacing.padding = 4'
        command = indicatortools.LilyPondCommand(string, prefix='')
        lilypond_file.paper_block.items.append(command)
        return lilypond_file
Ejemplo n.º 6
0
    def make_hairpin_score_03(self):
        r'''Make 200-note voice with crescendo spanner on every 100 notes.

        ::

            2.12 (r9726) initialization:        249,363 function calls
            2.12 (r9726) initialization:        249,363 function calls

            2.12 (r9726) LilyPond format:       133,898 function calls
            2.12 (r9728) LilyPond format:       128,948 function calls

        '''
        from abjad.tools import scoretools
        from abjad.tools import sequencetools
        from abjad.tools import spannertools
        from abjad.tools import topleveltools
        voice = scoretools.Voice(200 * scoretools.Note("c'16"))
        for part in sequencetools.partition_sequence_by_counts(
                voice[:],
            [100],
                cyclic=True,
        ):
            crescendo = spannertools.Crescendo()
            topleveltools.attach(crescendo, part)
        return voice
Ejemplo n.º 7
0
    def make_spanner_score_03(self):
        r'''Make 200-note voice with durated complex beam spanner
        on every 100 notes.

        ::

            2.12 (r9710) initialization:        251,606 function calls
            2.12 (r9724) initialization:        249,369 function calls

            2.12 (r9703) LilyPond format:       509,752 function calls
            2.12 (r9710) LilyPond format:       510,556 function calls
            2.12 (r9724) LilyPond format:       525,463 function calls

        '''
        from abjad.tools import scoretools
        from abjad.tools import sequencetools
        from abjad.tools import spannertools
        from abjad.tools import topleveltools
        voice = scoretools.Voice(200 * scoretools.Note("c'16"))
        for part in sequencetools.partition_sequence_by_counts(
                voice[:],
            [100],
                cyclic=True,
        ):
            beam = spannertools.DuratedComplexBeam()
            topleveltools.attach(beam, part)
        return voice
Ejemplo n.º 8
0
def make_notes_with_multiplied_durations(
    pitch,
    written_duration,
    multiplied_durations,
):
    '''Make `written_duration` notes with `pitch` and `multiplied_durations`:

    ::

        >>> args = [0, Duration(1, 4), [(1, 2), (1, 3), (1, 4), (1, 5)]]
        >>> scoretools.make_notes_with_multiplied_durations(*args)
        Selection(Note("c'4 * 2"), Note("c'4 * 4/3"), Note("c'4 * 1"), Note("c'4 * 4/5"))

    Useful for making spatially positioned notes.

    Returns list of notes.
    '''
    from abjad.tools import scoretools
    from abjad.tools import selectiontools

    # initialize input
    written_duration = durationtools.Duration(written_duration)

    # make notes
    notes = []
    for multiplied_duration in multiplied_durations:
        multiplied_duration = durationtools.Duration(multiplied_duration)
        note = scoretools.Note(pitch, written_duration)
        multiplier = multiplied_duration / written_duration
        attach(multiplier, note)
        notes.append(note)

    # return notes
    notes = selectiontools.Selection(notes)
    return notes
Ejemplo n.º 9
0
    def make_spanner_score_02(self):
        r'''Make 200-note voice with durated complex beam spanner
        on every 20 notes.

        ::

            2.12 (r9710) initialization:        250,954 function calls
            2.12 (r9724) initialization:        248,717 function calls

            2.12 (r9703) LilyPond format:       495,768 function calls
            2.12 (r9710) LilyPond format:       496,572 function calls
            2.12 (r9724) LilyPond format:       511,471 function calls

        '''
        from abjad.tools import scoretools
        from abjad.tools import sequencetools
        from abjad.tools import spannertools
        from abjad.tools import topleveltools
        voice = scoretools.Voice(200 * scoretools.Note("c'16"))
        for part in sequencetools.partition_sequence_by_counts(
                voice[:],
            [20],
                cyclic=True,
        ):
            beam = spannertools.DuratedComplexBeam()
            topleveltools.attach(beam, part)
        return voice
Ejemplo n.º 10
0
 def _bracket_inner_nodes(self, leaf_list_stack, node, voice):
     from abjad.tools import durationtools
     from abjad.tools import markuptools
     from abjad.tools import scoretools
     from abjad.tools import spannertools
     from abjad.tools.topleveltools import attach
     if len(node):
         if node.level:
             leaf_list_stack.append([])
         for child_node in node:
             self._bracket_inner_nodes(
                 leaf_list_stack,
                 child_node,
                 voice,
                 )
         if node.level:
             bracket = spannertools.HorizontalBracketSpanner()
             attach(bracket, leaf_list_stack[-1])
             if node.level == 1:
                 node_index = node.parent.index(node)
                 level_one_first_leaf = leaf_list_stack[-1][0]
                 string = r'\bold {{ {} }}'.format(node_index)
                 markup = markuptools.Markup(string, Up)
                 attach(markup, level_one_first_leaf)
             leaf_list_stack.pop()
     elif node.payload:
         note = scoretools.Note(
             node.payload,
             durationtools.Duration(1, 8),
             )
         voice.append(note)
         for leaf_list in leaf_list_stack:
             leaf_list.append(note)
Ejemplo n.º 11
0
    def make_score_with_indicators_01(self):
        r'''Make 200-note voice with dynamic on every 20th note:

        ::

            2.12 (r9704) initialization:        630,433 function calls
            2.12 (r9710) initialization:        235,120 function calls
            2.12 r(9726) initialization:        235,126 function calls

            2.12 (r9704) LilyPond format:       136,637 function calls
            2.12 (r9710) LilyPond format:        82,730 function calls
            2.12 (r9726) LilyPond format:        88,382 function calls

        '''
        from abjad.tools import indicatortools
        from abjad.tools import scoretools
        from abjad.tools import sequencetools
        from abjad.tools import topleveltools
        staff = scoretools.Staff(200 * scoretools.Note("c'16"))
        for part in sequencetools.partition_sequence_by_counts(
                staff[:],
            [20],
                cyclic=True,
        ):
            dynamic = indicatortools.Dynamic('f')
            topleveltools.attach(dynamic, part[0])
        return staff
Ejemplo n.º 12
0
    def make_bound_hairpin_score_03(self):
        r'''Make 200-note voice with p-to-f bound crescendo spanner
        on every 100 notes.

        ::

            2.12 (r9726) initialization:        267,417 function calls

            2.12 (r9726) LilyPond format:       116,534 function calls

        '''
        from abjad.tools import indicatortools
        from abjad.tools import scoretools
        from abjad.tools import sequencetools
        from abjad.tools import spannertools
        from abjad.tools import topleveltools
        voice = scoretools.Voice(200 * scoretools.Note("c'16"))
        for part in sequencetools.partition_sequence_by_counts(
                voice[:],
            [100],
                cyclic=True,
        ):
            crescendo = spannertools.Crescendo()
            topleveltools.attach(crescendo, part)
            dynamic = indicatortools.Dynamic('p')
            topleveltools.attach(dynamic, part[0])
            dynamic = indicatortools.Dynamic('r')
            topleveltools.attach(dynamic, part[-1])
        return voice
Ejemplo n.º 13
0
    def __call__(self, q_events):
        r'''Calls concatenating grace handler.
        '''
        from abjad.tools import quantizationtools

        grace_events, final_event = q_events[:-1], q_events[-1]

        if isinstance(final_event, quantizationtools.PitchedQEvent):
            pitches = final_event.pitches
        else:
            pitches = ()

        if grace_events:
            grace_container = scoretools.GraceContainer()
            for q_event in grace_events:
                if isinstance(q_event, quantizationtools.PitchedQEvent):
                    if len(q_event.pitches) == 1:
                        leaf = scoretools.Note(q_event.pitches[0],
                                               self.grace_duration)
                    else:
                        leaf = scoretools.Chord(q_event.pitches,
                                                self.grace_duration)
                else:
                    leaf = scoretools.Rest(self.grace_duration)
                grace_container.append(leaf)
        else:
            grace_container = None

        return pitches, grace_container
Ejemplo n.º 14
0
    def make_spanner_score_01(self):
        r'''Make 200-note voice with durated complex beam spanner
        on every 4 notes.

        ::

            2.12 (r9710) initialization:        248,654 function calls
            2.12 (r9724) initialization:        248,660 function calls

            2.12 (r9703) LilyPond format:       425,848 function calls
            2.12 (r9710) LilyPond format:       426,652 function calls
            2.12 (r9724) LilyPond format:       441,884 function calls

        '''
        from abjad.tools import scoretools
        from abjad.tools import sequencetools
        from abjad.tools import spannertools
        from abjad.tools import topleveltools
        voice = scoretools.Voice(200 * scoretools.Note("c'16"))
        for part in sequencetools.partition_sequence_by_counts(
                voice[:],
            [4],
                cyclic=True,
        ):
            beam = spannertools.DuratedComplexBeam()
            topleveltools.attach(beam, part)
        return voice
Ejemplo n.º 15
0
    def make_score_with_indicators_02(self):
        r'''Make 200-note staff with dynamic on every 4th note.

        ::

            2.12 (r9704) initialization:      4,632,761 function calls
            2.12 (r9710) initialization:        327,280 function calls
            2.12 (r9726) initialization:        325,371 function calls

            2.12 (r9704) LilyPond format:       220,277 function calls
            2.12 (r9710) LilyPond format:        84,530 function calls
            2.12 (r9726) LilyPond format:        90,056 function calls

        '''
        from abjad.tools import indicatortools
        from abjad.tools import scoretools
        from abjad.tools import sequencetools
        from abjad.tools import topleveltools
        staff = scoretools.Staff(200 * scoretools.Note("c'16"))
        for part in sequencetools.partition_sequence_by_counts(
                staff[:],
            [4],
                cyclic=True,
        ):
            dynamic = indicatortools.Dynamic('f')
            topleveltools.attach(dynamic, part[0])
        return staff
Ejemplo n.º 16
0
def edit_cello_voice(score, durated_reservoir):
    r'''Edits cello voice.
    '''

    voice = score['Cello Voice']
    descents = durated_reservoir['Cello']

    logical_tie = inspect_(voice[-1]).get_logical_tie()
    for leaf in logical_tie.leaves:
        parent = leaf._get_parentage().parent
        index = parent.index(leaf)
        parent[index] = scoretools.Chord(['e,', 'a,'], leaf.written_duration)

    selection = voice[-len(descents[-1]):]
    unison_descent = mutate(selection).copy()
    voice.extend(unison_descent)
    for chord in unison_descent:
        index = inspect_(chord).get_parentage().parent.index(chord)
        parent[index] = scoretools.Note(
            chord.written_pitches[1], chord.written_duration)
        articulation = indicatortools.Articulation('accent')
        attach(articulation, parent[index])
        articulation = indicatortools.Articulation('tenuto')
        attach(articulation, parent[index])

    voice.extend('a,1. ~ a,2')
    voice.extend('b,1 ~ b,1. ~ b,1.')
    voice.extend('a,1. ~ a,1. ~ a,1. ~ a,1. ~ a,1. ~ a,2')
    voice.extend('r4 r2.')
Ejemplo n.º 17
0
 def _cast_defective_chord(chord):
     from abjad.tools import scoretools
     if isinstance(chord, Chord):
         note_head_count = len(chord.note_heads)
         if not note_head_count:
             return scoretools.Rest(chord)
         elif note_head_count == 1:
             return scoretools.Note(chord)
     return chord
Ejemplo n.º 18
0
def _make_new_notes(anchor_pitch, anchor_written_duration, subrun_intervals):
    from abjad.tools import pitchtools
    from abjad.tools import scoretools
    new_notes = []
    for subrun_interval in subrun_intervals:
        new_pc = (pitchtools.NumberedPitch(anchor_pitch).pitch_number +
                  subrun_interval) % 12
        new_note = scoretools.Note(new_pc, anchor_written_duration)
        new_notes.append(new_note)
    return new_notes
Ejemplo n.º 19
0
def make_multiplied_quarter_notes(
    pitches,
    multiplied_durations,
):
    r'''Make quarter notes with `pitches` and `multiplied_durations`:

    ::

        >>> args = [[0, 2, 4, 5], [(1, 4), (1, 5), (1, 6), (1, 7)]]
        >>> scoretools.make_multiplied_quarter_notes(*args)
        Selection(Note("c'4 * 1"), Note("d'4 * 4/5"), Note("e'4 * 2/3"), Note("f'4 * 4/7"))

    Read `pitches` cyclically where the length of `pitches` is
    less than the length of `multiplied_durations`:

    ::

        >>> args = [[0], [(1, 4), (1, 5), (1, 6), (1, 7)]]
        >>> scoretools.make_multiplied_quarter_notes(*args)
        Selection(Note("c'4 * 1"), Note("c'4 * 4/5"), Note("c'4 * 2/3"), Note("c'4 * 4/7"))

    Read `multiplied_durations` cyclically where the length of
    `multiplied_durations` is less than the length of `pitches`:

    ::

        >>> args = [[0, 2, 4, 5], [(1, 5)]]
        >>> scoretools.make_multiplied_quarter_notes(*args)
        Selection(Note("c'4 * 4/5"), Note("d'4 * 4/5"), Note("e'4 * 4/5"),
        Note("f'4 * 4/5"))

    Returns list of zero or more newly constructed notes.
    '''
    from abjad.tools import scoretools

    multiplied_durations = [
        durationtools.Duration(x) for x in multiplied_durations
    ]
    quarter_notes = []

    sequences = [pitches, multiplied_durations]
    for pitch, duration in sequencetools.zip_sequences(sequences, cyclic=True):
        quarter_note = scoretools.Note(pitch, durationtools.Duration(1, 4))
        duration = durationtools.Duration(duration)
        multiplier = durationtools.Multiplier(duration /
                                              durationtools.Duration(1, 4))
        attach(multiplier, quarter_note)
        quarter_notes.append(quarter_note)

    quarter_notes = selectiontools.Selection(quarter_notes)
    return quarter_notes
Ejemplo n.º 20
0
    def __illustrate__(self):
        r'''Illustrates articulation.

        Returns LilyPond file.
        '''
        from abjad.tools import lilypondfiletools
        from abjad.tools import scoretools
        from abjad.tools import topleveltools
        note = scoretools.Note("c'4")
        articulation = copy.copy(self)
        topleveltools.attach(articulation, note)
        lilypond_file = lilypondfiletools.make_basic_lilypond_file(note)
        lilypond_file.header_block.tagline = False
        return lilypond_file
Ejemplo n.º 21
0
def fill_measures_in_expr_with_time_signature_denominator_notes(
    expr, iterctrl=None):
    r'''Fill measures in `expr` with time signature denominator notes:

    ::

        >>> staff = Staff([Measure((3, 4), []), Measure((3, 16), []), Measure((3, 8), [])])
        >>> scoretools.fill_measures_in_expr_with_time_signature_denominator_notes(staff)

    ..  doctest::

        >>> print(format(staff))
        \new Staff {
            {
                \time 3/4
                c'4
                c'4
                c'4
            }
            {
                \time 3/16
                c'16
                c'16
                c'16
            }
            {
                \time 3/8
                c'8
                c'8
                c'8
            }
        }

    Delete existing contents of measures in `expr`.

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

    if iterctrl is None:
        iterctrl = lambda measure, i: True
    for i, measure in enumerate(iterate(expr).by_class(scoretools.Measure)):
        if iterctrl(measure, i):
            time_signature = measure.time_signature
            denominator = mathtools.greatest_power_of_two_less_equal(
                time_signature.denominator)
            numerator = time_signature.numerator
            notes = scoretools.Note(0, (1, denominator)) * numerator
            measure[:] = notes
Ejemplo n.º 22
0
    def make_score_00(self):
        r'''Make 200-note voice (with nothing else).

        ::

            2.12 (r9710) initialization:        156,821 function calls
            2.12 (r9726) initialization:        156,827 function calls

            2.12 (r9703) LilyPond format:        99,127 function calls
            2.12 (r9710) LilyPond format:       100,126 function calls
            2.12 (r9726) LilyPond format:       105,778 function calls

        '''
        from abjad.tools import scoretools
        voice = scoretools.Voice(200 * scoretools.Note("c'16"))
        return voice
Ejemplo n.º 23
0
 def _notate_leaves(
     self,
     grace_handler=None,
     voice=None,
     ):
     for leaf in iterate(voice).by_leaf():
         if leaf._has_indicator(indicatortools.Annotation):
             annotation = leaf._get_indicator(indicatortools.Annotation)
             pitches, grace_container = grace_handler(annotation.value)
             if not pitches:
                 new_leaf = scoretools.Rest(leaf)
             elif 1 < len(pitches):
                 new_leaf = scoretools.Chord(leaf)
                 new_leaf.written_pitches = pitches
             else:
                 new_leaf = scoretools.Note(leaf)
                 new_leaf.written_pitch = pitches[0]
             if grace_container:
                 attach(grace_container, new_leaf)
             tie = spannertools.Tie()
             if tie._attachment_test(new_leaf):
                 attach(tie, new_leaf)
             mutate(leaf).replace(new_leaf)
         else:
             previous_leaf = leaf._get_leaf(-1)
             if isinstance(previous_leaf, scoretools.Rest):
                 new_leaf = type(previous_leaf)(
                     leaf.written_duration,
                     )
             elif isinstance(previous_leaf, scoretools.Note):
                 new_leaf = type(previous_leaf)(
                     previous_leaf.written_pitch,
                     leaf.written_duration,
                     )
             else:
                 new_leaf = type(previous_leaf)(
                     previous_leaf.written_pitch,
                     leaf.written_duration,
                     )
             mutate(leaf).replace(new_leaf)
             tie = inspect_(previous_leaf).get_spanner(spannertools.Tie)
             if tie is not None:
                 tie._append(new_leaf)
         if leaf._has_indicator(indicatortools.Tempo):
             tempo = leaf._get_indicator(indicatortools.Tempo)
             detach(indicatortools.Tempo, leaf)
             attach(tempo, new_leaf)
Ejemplo n.º 24
0
def make_desordre_cell(pitches):
    '''The function constructs and returns a *Désordre cell*.
    `pitches` is a list of numbers or, more generally, pitch tokens.
    '''

    notes = [scoretools.Note(pitch, (1, 8)) for pitch in pitches]
    beam = spannertools.Beam()
    attach(beam, notes)
    slur = spannertools.Slur()
    attach(slur, notes)
    clef = indicatortools.Dynamic('f')
    attach(clef, notes[0])
    dynamic = indicatortools.Dynamic('p')
    attach(dynamic, notes[1])

    # make the lower voice
    lower_voice = scoretools.Voice(notes)
    lower_voice.name = 'RH Lower Voice'
    command = indicatortools.LilyPondCommand('voiceTwo')
    attach(command, lower_voice)
    n = int(math.ceil(len(pitches) / 2.))
    chord = scoretools.Chord([pitches[0], pitches[0] + 12], (n, 8))
    articulation = indicatortools.Articulation('>')
    attach(articulation, chord)

    # make the upper voice
    upper_voice = scoretools.Voice([chord])
    upper_voice.name = 'RH Upper Voice'
    command = indicatortools.LilyPondCommand('voiceOne')
    attach(command, upper_voice)

    # combine them together
    container = scoretools.Container([lower_voice, upper_voice])
    container.is_simultaneous = True

    # make all 1/8 beats breakable
    leaves = select(lower_voice).by_leaf()
    for leaf in leaves[:-1]:
        bar_line = indicatortools.BarLine('')
        attach(bar_line, leaf)

    return container
Ejemplo n.º 25
0
    def make_score_with_indicators_03(self):
        r'''Make 200-note staff with dynamic on every note.

        ::

            2.12 (r9704) initialization:     53,450,195 function calls (!!)
            2.12 (r9710) initialization:      2,124,500 function calls
            2.12 (r9724) initialization:      2,122,591 function calls

            2.12 (r9704) LilyPond format:       533,927 function calls
            2.12 (r9710) LilyPond format:        91,280 function calls
            2.12 (r9724) LilyPond format:        96,806 function calls

        '''
        from abjad.tools import indicatortools
        from abjad.tools import scoretools
        from abjad.tools import topleveltools
        staff = scoretools.Staff(200 * scoretools.Note("c'16"))
        for note in staff.select_leaves():
            dynamic = indicatortools.Dynamic('f')
            topleveltools.attach(dynamic, note)
        return staff
Ejemplo n.º 26
0
 def _to_tuplet_with_ratio(self, proportions, is_diminution=True):
     from abjad.tools import scoretools
     # check input
     proportions = mathtools.Ratio(proportions)
     # find target duration of fixed-duration tuplet
     target_duration = self.written_duration
     # find basic duration of note in tuplet
     basic_prolated_duration = target_duration / sum(proportions.numbers)
     # find basic written duration of note in tuplet
     basic_written_duration = \
         basic_prolated_duration.equal_or_greater_assignable
     # find written duration of each note in tuplet
     written_durations = [
         _ * basic_written_duration for _ in proportions.numbers
     ]
     # make tuplet notes
     try:
         notes = [scoretools.Note(0, x) for x in written_durations]
     except AssignabilityError:
         denominator = target_duration._denominator
         note_durations = [
             durationtools.Duration(_, denominator)
             for _ in proportions.numbers
         ]
         notes = scoretools.make_notes(0, note_durations)
     # make tuplet
     tuplet = scoretools.FixedDurationTuplet(target_duration, notes)
     # fix tuplet contents if necessary
     tuplet._fix()
     # change prolation if necessary
     if not tuplet.multiplier == 1:
         if is_diminution:
             if not tuplet.is_diminution:
                 tuplet.toggle_prolation()
         else:
             if tuplet.is_diminution:
                 tuplet.toggle_prolation()
     # return tuplet
     return tuplet
Ejemplo n.º 27
0
def edit_viola_voice(score, durated_reservoir):
    r'''Edits viola voice.
    '''

    voice = score['Viola Voice']
    descents = durated_reservoir['Viola']

    for leaf in descents[-1]:
        articulation = indicatortools.Articulation('accent')
        attach(articulation, leaf)
        articulation = indicatortools.Articulation('tenuto')
        attach(articulation, leaf)
    last_descent = select(descents[-1])
    copied_descent = mutate(last_descent).copy()
    for leaf in copied_descent:
        if leaf.written_duration == durationtools.Duration(4, 4):
            leaf.written_duration = durationtools.Duration(8, 4)
        else:
            leaf.written_duration = durationtools.Duration(4, 4)
    voice.extend(copied_descent)

    bridge = scoretools.Note('e1')
    articulation = indicatortools.Articulation('tenuto')
    attach(articulation, bridge)
    articulation = indicatortools.Articulation('accent')
    attach(articulation, bridge)
    voice.append(bridge)

    final_sustain_rhythm = [(6, 4)] * 21 + [(1, 2)]
    final_sustain_notes = scoretools.make_notes(['e'], final_sustain_rhythm)
    articulation = indicatortools.Articulation('accent')
    attach(articulation, final_sustain_notes[0])
    articulation = indicatortools.Articulation('tenuto')
    attach(articulation, final_sustain_notes[0])
    voice.extend(final_sustain_notes)
    tie = spannertools.Tie()
    attach(tie, final_sustain_notes)
    voice.extend('r4 r2.')
Ejemplo n.º 28
0
    def __illustrate__(self):
        r'''Illustrates pitch.

        Returns LilyPond file.
        '''
        from abjad.tools import durationtools
        from abjad.tools import lilypondfiletools
        from abjad.tools import markuptools
        from abjad.tools import pitchtools
        from abjad.tools import scoretools
        from abjad.tools.topleveltools import attach
        from abjad.tools.topleveltools import override
        pitch = pitchtools.NamedPitch(self)
        note = scoretools.Note(pitch, 1)
        attach(durationtools.Multiplier(1, 4), note)
        clef = pitchtools.suggest_clef_for_named_pitches([pitch])
        staff = scoretools.Staff()
        attach(clef, staff)
        staff.append(note)
        override(staff).time_signature.stencil = False
        lilypond_file = lilypondfiletools.make_basic_lilypond_file(staff)
        lilypond_file.header_block.tagline = markuptools.Markup('""')
        return lilypond_file
def make_repeated_notes_from_time_signature(time_signature, pitch="c'"):
    '''Make repeated notes from `time_signature`:

    ::

        >>> scoretools.make_repeated_notes_from_time_signature((5, 32))
        Selection([Note("c'32"), Note("c'32"), Note("c'32"), Note("c'32"), Note("c'32")])

    Make repeated notes with `pitch` from `time_signature`:

    ::

        >>> scoretools.make_repeated_notes_from_time_signature((5, 32), pitch="d''")
        Selection([Note("d''32"), Note("d''32"), Note("d''32"), Note("d''32"), Note("d''32")])

    Returns list of notes.
    '''
    from abjad.tools import indicatortools
    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:
        raise NotImplementedError(
            'TODO: extend this function for time signatures with a non-power-of-two denominators.'
        )

    # make and return repeated notes
    duration = (1, time_signature.denominator)
    result = time_signature.numerator * scoretools.Note(pitch, duration)

    # return result
    result = selectiontools.Selection(result)
    return result
Ejemplo n.º 30
0
    def make_spanner_score_09(self):
        r'''Make 200-note voice with (vanilla) beam spanner on every 100 notes.

        ::

            2.12 (r9724) initialization:        249,339 function calls

            2.12 (r9703) LilyPond format:       121,497 function calls
            2.12 (r9724) LilyPond format:       128,494 function calls

        '''
        from abjad.tools import scoretools
        from abjad.tools import sequencetools
        from abjad.tools import spannertools
        from abjad.tools import topleveltools
        voice = scoretools.Voice(200 * scoretools.Note("c'16"))
        for part in sequencetools.partition_sequence_by_counts(
                voice[:],
            [100],
                cyclic=True,
        ):
            beam = spannertools.Beam()
            topleveltools.attach(beam, part)
        return voice