Пример #1
0
 def _tie_consecutive_notes_(self, divisions):
     import abjad
     if not self.tie_consecutive_notes:
         return
     leaves = list(abjad.iterate(divisions).leaves())
     for leaf in leaves:
         abjad.detach(abjad.Tie, leaf)
     pairs = itertools.groupby(leaves, lambda _: _.__class__)
     def _get_pitches(component):
         if isinstance(component, abjad.Note):
             return component.written_pitch
         elif isinstance(component, abjad.Chord):
             return component.written_pitches
         else:
             raise TypeError(component)
     for class_, group in pairs:
         group = list(group)
         if not isinstance(group[0], (abjad.Note, abjad.Chord)):
             continue
         subpairs = itertools.groupby(group, lambda _: _get_pitches(_))
         for pitches, subgroup in subpairs:
             subgroup = list(subgroup)
             if len(subgroup) == 1:
                 continue
             tie = abjad.Tie()
             assert tie._attachment_test_all(subgroup) is True
             abjad.attach(tie, abjad.select(subgroup))
Пример #2
0
 def _strip_ties_(self, divisions):
     import abjad
     if not self.strip_ties:
         return
     for division in divisions:
         for leaf in abjad.iterate(division).leaves():
             abjad.detach(abjad.Tie, leaf)
Пример #3
0
 def _scale(self, multiplier=None):
     import abjad
     if multiplier is None:
         return
     multiplier = abjad.Multiplier(multiplier)
     old_time_signature = self.time_signature
     if (abjad.mathtools.is_nonnegative_integer_power_of_two(multiplier) and
         1 <= multiplier):
         old_numerator = old_time_signature.numerator
         old_denominator = old_time_signature.denominator
         new_denominator = old_denominator // multiplier.numerator
         pair = (old_numerator, new_denominator)
         new_time_signature = abjad.TimeSignature(pair)
     else:
         old_denominator = old_time_signature.denominator
         old_duration = old_time_signature.duration
         new_duration = multiplier * old_duration
         new_time_signature = self._duration_to_time_signature(
             new_duration,
             [old_denominator],
             multiplier.denominator,
             )
     abjad.detach(abjad.TimeSignature, self)
     abjad.attach(new_time_signature, self)
     contents_multiplier_denominator = \
         abjad.mathtools.greatest_power_of_two_less_equal(
             multiplier.denominator)
     pair = (multiplier.numerator, contents_multiplier_denominator)
     contents_multiplier = abjad.Multiplier(*pair)
     self._scale_contents(contents_multiplier)
Пример #4
0
 def _populate_time_signature_context(self):
     time_signature_context = self._score['Time Signature Context']
     music_voice = self._score['Music Voice']
     measure_durations = []
     current_duration = abjad.Duration(0)
     ideal_measure_duration = abjad.Duration(4, 4)
     for component in music_voice:
         component_duration = abjad.inspect_(component).get_duration()
         candidate_duration = current_duration + component_duration
         if ideal_measure_duration < candidate_duration:
             if 0 < current_duration:
                 measure_durations.append(current_duration)
             current_duration = component_duration
         else:
             current_duration = candidate_duration
     measure_durations.append(current_duration)
     measures = abjad.scoretools.make_spacer_skip_measures(
         measure_durations)
     time_signature_context.extend(measures)
     for measure in abjad.iterate(time_signature_context).by_class(abjad.Measure):
         time_signature = abjad.inspect_(measure).get_indicator(abjad.TimeSignature)
         if time_signature.denominator < 4:
             fraction = abjad.mathtools.NonreducedFraction(
                 time_signature.pair)
             fraction = fraction.with_multiple_of_denominator(4)
             abjad.detach(time_signature, measure)
             new_time_signature = abjad.TimeSignature(fraction)
             abjad.attach(new_time_signature, measure)
    def _replace(self, old_leaf, new_leaf):
        after_grace = abjad.inspect(old_leaf).get_after_grace_container()
        if after_grace is not None:
            old_after_grace = after_grace
            grace_notes = list(iterate(old_after_grace).by_leaf())
            detach(scoretools.GraceContainer, old_leaf)

        indicator_expressions = abjad.inspect(old_leaf).get_indicators(unwrap=False)
        #for indicator_expression in indicator_expressions:
        #    detach(indicator, old_leaf)

        timespan = old_leaf._timespan
        start_offset = old_leaf._start_offset
        stop_offset = old_leaf._stop_offset
        logical_measure_number = old_leaf._logical_measure_number
        mutate(old_leaf).replace(new_leaf)
        new_leaf._timespan = timespan
        new_leaf._start_offset = start_offset
        new_leaf._stop_offset = stop_offset
        new_leaf._logical_measure_number = logical_measure_number

        if after_grace is not None:
            new_after_grace = scoretools.AfterGraceContainer(grace_notes)
            attach(new_after_grace, new_leaf)

        for indicator_expression in indicator_expressions:
            attach(indicator_expression, new_leaf)
Пример #6
0
 def detach_grace_containers(containers, indices):
     #for i, leaf in enumerate(abjad.iterate(containers).leaves()):
     leaves = abjad.iterate(containers).leaves(grace_notes=False)
     for i, leaf in enumerate(leaves):
         if i not in indices:
             continue
         abjad.detach(abjad.GraceContainer, leaf)
Пример #7
0
    def _replace(self, old_leaf, new_leaf):
        grace_containers = inspect_(old_leaf).get_grace_containers('after')
        if grace_containers:
            old_grace_container = grace_containers[0]
            grace_notes = list(iterate(old_grace_container).by_leaf())
            detach(scoretools.GraceContainer, old_leaf)

        indicator_expressions = inspect_(old_leaf).get_indicators(unwrap=False)
        #for indicator_expression in indicator_expressions:
        #    detach(indicator, old_leaf)

        timespan = old_leaf._timespan
        start_offset = old_leaf._start_offset
        stop_offset = old_leaf._stop_offset
        logical_measure_number = old_leaf._logical_measure_number
        mutate(old_leaf).replace(new_leaf)
        new_leaf._timespan = timespan
        new_leaf._start_offset = start_offset
        new_leaf._stop_offset = stop_offset
        new_leaf._logical_measure_number = logical_measure_number

        if grace_containers:
            new_grace_container = scoretools.GraceContainer(
                grace_notes,
                kind='after',
                )
            attach(new_grace_container, new_leaf)

        for indicator_expression in indicator_expressions:
            attach(indicator_expression, new_leaf)
def test_scoretools_Mutation_copy_07():

    voice = abjad.Voice("abj: | 2/8 c'8 d'8 || 2/8 e'8 f'8 |"
                        "| 2/8 g'8 a'8 || 2/8 b'8 c''8 |")
    leaves = abjad.select(voice).leaves()
    beam = abjad.Beam()
    abjad.attach(beam, leaves)
    slur = abjad.Slur()
    abjad.attach(slur, leaves)

    assert format(voice) == abjad.String.normalize(r'''
        \new Voice
        {
            {   % measure
                \time 2/8
                c'8
                [
                (
                d'8
            }   % measure
            {   % measure
                e'8
                f'8
            }   % measure
            {   % measure
                g'8
                a'8
            }   % measure
            {   % measure
                b'8
                c''8
                ]
                )
            }   % measure
        }
        ''')

    result = abjad.mutate(voice[-2:]).copy()
    new_voice = abjad.Voice(result)
    for component in abjad.iterate(new_voice).components():
        abjad.detach(abjad.Spanner, component)

    assert format(new_voice) == abjad.String.normalize(r'''
        \new Voice
        {
            {   % measure
                \time 2/8
                g'8
                a'8
            }   % measure
            {   % measure
                b'8
                c''8
            }   % measure
        }
        ''')

    assert abjad.inspect(voice).is_well_formed()
    assert abjad.inspect(new_voice).is_well_formed()
Пример #9
0
    def _remove_gliss_from_hidden_after_grace(tie):
        grace = abjad.inspect(tie[:-1]).grace_container()[0]
        glissando = abjad.indicatortools.LilyPondCommand(
            'glissando',
            format_slot='right'
        )

        abjad.detach(glissando, grace)
Пример #10
0
 def _detach_optional_tone_tweaks(staff: abjad.Staff) -> None:
     for bar in staff:
         for obj in bar:
             abjad.detach(abjad.LilyPondLiteral("\\once \\tiny"), obj)
             if type(obj) == abjad.Chord:
                 for note_head in obj.note_heads:
                     if hasattr(note_head.tweaks, "font_size"):
                         del note_head.tweaks.font_size
Пример #11
0
def make_mozart_score():
    """
    Makes Mozart score.
    """
    score_template = abjad.TwoStaffPianoScoreTemplate()
    score = score_template()
    # select the measures to use
    choices = abjad.demos.mozart.choose_mozart_measures()
    # create and populate the volta containers
    treble_volta = abjad.Container()
    bass_volta = abjad.Container()
    for choice in choices[:7]:
        treble, bass = abjad.demos.mozart.make_mozart_measure(choice)
        treble_volta.append(treble)
        bass_volta.append(bass)
    # abjad.attach indicators to the volta containers
    command = abjad.LilyPondLiteral(r"\repeat volta 2", "before")
    abjad.attach(command, treble_volta)
    command = abjad.LilyPondLiteral(r"\repeat volta 2", "before")
    abjad.attach(command, bass_volta)
    # append the volta containers to our staves
    score["RH_Voice"].append(treble_volta)
    score["LH_Voice"].append(bass_volta)
    # create and populate the alternative ending containers
    treble_alternative = abjad.Container()
    bass_alternative = abjad.Container()
    for choice in choices[7:9]:
        treble, bass = abjad.demos.mozart.make_mozart_measure(choice)
        treble_alternative.append(treble)
        bass_alternative.append(bass)
    # abjad.attach indicators to the alternative containers
    command = abjad.LilyPondLiteral(r"\alternative", "before")
    abjad.attach(command, treble_alternative)
    command = abjad.LilyPondLiteral(r"\alternative", "before")
    abjad.attach(command, bass_alternative)
    # append the alternative containers to our staves
    score["RH_Voice"].append(treble_alternative)
    score["LH_Voice"].append(bass_alternative)
    # create the remaining measures
    for choice in choices[9:]:
        treble, bass = abjad.demos.mozart.make_mozart_measure(choice)
        score["RH_Voice"].append(treble)
        score["LH_Voice"].append(bass)
    # abjad.attach indicators
    time_signature = abjad.TimeSignature((3, 8))
    leaf = abjad.inspect(score["RH_Staff"]).leaf(0)
    abjad.attach(time_signature, leaf)
    bar_line = abjad.BarLine("|.")
    leaf = abjad.inspect(score["RH_Staff"]).leaf(-1)
    abjad.attach(bar_line, leaf)
    # remove the default piano instrument and add a custom one:
    abjad.detach(abjad.Instrument, score["Piano_Staff"])
    klavier = abjad.Piano(name="Katzenklavier", short_name="kk.")
    leaf = abjad.inspect(score["Piano_Staff"]).leaf(0)
    abjad.attach(klavier, leaf)
    return score
Пример #12
0
def make_mozart_score():
    """
    Makes Mozart score.
    """
    score_template = abjad.TwoStaffPianoScoreTemplate()
    score = score_template()
    # select the measures to use
    choices = abjad.demos.mozart.choose_mozart_measures()
    # create and populate the volta containers
    treble_volta = abjad.Container()
    bass_volta = abjad.Container()
    for choice in choices[:7]:
        treble, bass = abjad.demos.mozart.make_mozart_measure(choice)
        treble_volta.append(treble)
        bass_volta.append(bass)
    # abjad.attach indicators to the volta containers
    command = abjad.LilyPondLiteral(r"\repeat volta 2", "before")
    abjad.attach(command, treble_volta)
    command = abjad.LilyPondLiteral(r"\repeat volta 2", "before")
    abjad.attach(command, bass_volta)
    # append the volta containers to our staves
    score["RH_Voice"].append(treble_volta)
    score["LH_Voice"].append(bass_volta)
    # create and populate the alternative ending containers
    treble_alternative = abjad.Container()
    bass_alternative = abjad.Container()
    for choice in choices[7:9]:
        treble, bass = abjad.demos.mozart.make_mozart_measure(choice)
        treble_alternative.append(treble)
        bass_alternative.append(bass)
    # abjad.attach indicators to the alternative containers
    command = abjad.LilyPondLiteral(r"\alternative", "before")
    abjad.attach(command, treble_alternative)
    command = abjad.LilyPondLiteral(r"\alternative", "before")
    abjad.attach(command, bass_alternative)
    # append the alternative containers to our staves
    score["RH_Voice"].append(treble_alternative)
    score["LH_Voice"].append(bass_alternative)
    # create the remaining measures
    for choice in choices[9:]:
        treble, bass = abjad.demos.mozart.make_mozart_measure(choice)
        score["RH_Voice"].append(treble)
        score["LH_Voice"].append(bass)
    # abjad.attach indicators
    time_signature = abjad.TimeSignature((3, 8))
    leaf = abjad.inspect(score["RH_Staff"]).leaf(0)
    abjad.attach(time_signature, leaf)
    bar_line = abjad.BarLine("|.")
    leaf = abjad.inspect(score["RH_Staff"]).leaf(-1)
    abjad.attach(bar_line, leaf)
    # remove the default piano instrument and add a custom one:
    abjad.detach(abjad.Instrument, score["Piano_Staff"])
    klavier = abjad.Piano(name="Katzenklavier", short_name="kk.")
    leaf = abjad.inspect(score["Piano_Staff"]).leaf(0)
    abjad.attach(klavier, leaf)
    return score
Пример #13
0
 def _detach_centre_markup(self) -> None:
     r'Detaches the centre markup tweaks.'
     literal1 = abjad.LilyPondLiteral(
         r'\once \override TextScript.parent-alignment-X = 0')
     literal2 = abjad.LilyPondLiteral(
         r'\once \override TextScript.self-alignment-X = 0')
     if abjad.get.indicator(self, literal1):
         abjad.detach(literal1, self)
     if abjad.get.indicator(self, literal2):
         abjad.detach(literal2, self)
Пример #14
0
 def _set_pitch(self, leaf, pitch):
     string = 'not yet pitched'
     if abjad.inspect_(leaf).has_indicator(string):
         abjad.detach(string, leaf)
     if isinstance(leaf, abjad.Note):
         leaf.written_pitch = pitch
     elif isinstance(leaf, abjad.Chord):
         raise NotImplementedError
     if self.allow_repeated_pitches:
         abjad.attach('repeated pitch allowed', leaf)
Пример #15
0
 def _conditionally_adjust_time_signature(self, old_denominator):
     import abjad
     if self.automatically_adjust_time_signature:
         naive_time_signature = self._get_preprolated_duration()
         better_time_signature = \
             abjad.NonreducedFraction(naive_time_signature)
         better_time_signature = \
             better_time_signature.with_denominator(old_denominator)
         better_time_signature = abjad.TimeSignature(better_time_signature)
         abjad.detach(abjad.TimeSignature, self)
         abjad.attach(better_time_signature, self)
Пример #16
0
 def _process_previous_metadata(self, previous_metadata):
     if previous_metadata is None:
         return
     first_tempo = self._get_first_tempo()
     first_time_signature = self._get_first_time_signature()
     voice = self._score[0][0]
     first_leaf = abjad.get.leaf(voice, 0)
     if first_tempo == previous_metadata["last_tempo"]:
         abjad.detach(abjad.MetronomeMark, first_leaf)
     if first_time_signature == previous_metadata["last_time_signature"]:
         abjad.detach(abjad.TimeSignature, first_leaf)
Пример #17
0
def test_Staff_time_signature_03():
    """
    Staff time signature set and then clear.
    """

    staff = abjad.Staff(abjad.Note("c'4") * 8)
    time_signature = abjad.TimeSignature((2, 4))
    abjad.attach(time_signature, staff[0])
    abjad.detach(time_signature, staff[0])
    for leaf in staff:
        assert abjad.inspect(leaf).effective(abjad.TimeSignature) is None
Пример #18
0
def test_Staff_time_signature_03():
    """
    Staff time signature set and then clear.
    """

    staff = abjad.Staff("c'4 c'4 c'4 c'4 c'4 c'4 c'4 c'4")
    time_signature = abjad.TimeSignature((2, 4))
    abjad.attach(time_signature, staff[0])
    abjad.detach(time_signature, staff[0])
    for leaf in staff:
        assert abjad.get.effective(leaf, abjad.TimeSignature) is None
Пример #19
0
 def _notate_leaves(self,
                    grace_handler: GraceHandler,
                    voice: abjad.Voice | None = None) -> list[tuple | None]:
     all_q_event_attachments: list[tuple | None] = []
     for leaf in abjad.iterate.leaves(voice):
         if leaf._has_indicator(dict):
             annotation = leaf._get_indicator(dict)
             q_events = annotation["q_events"]
             pitches, attachments, grace_container = grace_handler(q_events)
             new_leaf: abjad.Leaf
             if not pitches:
                 new_leaf = abjad.Rest(leaf)
             elif 1 < len(pitches):
                 new_leaf = abjad.Chord(leaf)
                 new_leaf.written_pitches = pitches
             else:
                 new_leaf = abjad.Note(leaf)
                 new_leaf.written_pitch = pitches[0]
             if attachments is not None:
                 all_q_event_attachments.append(attachments)
             if grace_container:
                 abjad.attach(grace_container, new_leaf)
             abjad.mutate.replace(leaf, new_leaf)
             if not isinstance(new_leaf, abjad.Rest):
                 abjad.annotate(new_leaf, "tie_to_next", True)
             elif abjad.get.indicator(new_leaf, abjad.Tie):
                 abjad.detach(abjad.Tie, new_leaf)
         else:
             previous_leaf = abjad._iterlib._get_leaf(leaf, -1)
             if isinstance(previous_leaf, abjad.Rest):
                 new_leaf = type(previous_leaf)(leaf.written_duration)
             elif isinstance(previous_leaf, abjad.Note):
                 new_leaf = type(previous_leaf)(previous_leaf.written_pitch,
                                                leaf.written_duration)
             else:
                 new_leaf = type(previous_leaf)(
                     previous_leaf.written_pitches, leaf.written_duration)
             abjad.mutate.replace(leaf, new_leaf)
             if abjad.get.annotation(previous_leaf, "tie_to_next") is True:
                 leaves = [previous_leaf, new_leaf]
                 abjad.tie(leaves)
                 abjad.annotate(new_leaf, "tie_to_next", True)
         if leaf._has_indicator(abjad.MetronomeMark):
             tempo = leaf._get_indicator(abjad.MetronomeMark)
             abjad.detach(abjad.MetronomeMark, leaf)
             abjad.detach(abjad.MetronomeMark, new_leaf)
             abjad.attach(tempo, new_leaf)
         if leaf._has_indicator(abjad.TimeSignature):
             time_signature = leaf._get_indicator(abjad.TimeSignature)
             abjad.detach(abjad.TimeSignature, leaf)
             abjad.detach(abjad.TimeSignature, new_leaf)
             abjad.attach(time_signature, new_leaf)
     return all_q_event_attachments
Пример #20
0
 def _apply_division_masks(self, selections):
     import abjad
     from abjad.tools import rhythmmakertools
     if not self.division_masks:
         return selections
     new_selections = []
     duration_specifier = self._get_duration_specifier()
     decrease_monotonic = duration_specifier.decrease_monotonic
     forbidden_duration = duration_specifier.forbidden_duration
     tie_specifier = self._get_tie_specifier()
     total_divisions = len(selections)
     division_masks = self.division_masks
     leaf_maker = abjad.LeafMaker(
         decrease_monotonic=decrease_monotonic,
         forbidden_duration=forbidden_duration,
         repeat_ties=tie_specifier.repeat_ties,
     )
     previous_divisions_consumed = self._previous_divisions_consumed()
     for i, selection in enumerate(selections):
         matching_division_mask = division_masks.get_matching_pattern(
             i + previous_divisions_consumed,
             total_divisions + previous_divisions_consumed,
             rotation=self.previous_state.get('rotation'),
         )
         if not matching_division_mask:
             new_selections.append(selection)
             continue
         duration = abjad.inspect(selection).get_duration()
         if isinstance(
                 matching_division_mask,
                 rhythmmakertools.SustainMask,
         ):
             leaf_maker = abjad.new(
                 leaf_maker,
                 use_multimeasure_rests=False,
             )
             new_selection = leaf_maker([0], [duration])
         else:
             use_multimeasure_rests = getattr(
                 matching_division_mask,
                 'use_multimeasure_rests',
                 False,
             )
             leaf_maker = abjad.new(
                 leaf_maker,
                 use_multimeasure_rests=use_multimeasure_rests,
             )
             new_selection = leaf_maker([None], [duration])
         for component in abjad.iterate(selection).components():
             abjad.detach(abjad.Tie, component)
         new_selections.append(new_selection)
     return new_selections
def test_scoretools_Inspection_get_effective_08():
    r'''Attaching and then abjad.detaching works as expected.
    '''

    staff = abjad.Staff("c'8 d'8 e'8 f'8")
    clef = abjad.Clef('alto')
    abjad.attach(clef, staff[0])
    clef = abjad.inspect(staff[0]).get_effective(abjad.Clef)
    abjad.detach(clef, staff[0])

    for leaf in staff:
        clef = abjad.inspect(leaf).get_effective(abjad.Clef)
        assert clef is None
Пример #22
0
 def _attach_voice_numbers(self, note_lists):
     for component in self.voice_map:
         assert len(component) == 2
         voice_number = component[0]
         indices = component[1]
         notes = baca.sequence(note_lists).flatten()
         for i, note in enumerate(notes):
             if i in indices:
                 abjad.detach(int, note)
                 abjad.attach(voice_number, note)
     notes = baca.sequence(note_lists).flatten()
     for note in notes:
         assert abjad.inspect(note).has_indicator(int), repr(note)
Пример #23
0
 def _set_duration(self, new_duration, repeat_ties=False):
     import abjad
     new_duration = abjad.Duration(new_duration)
     # change LilyPond multiplier if leaf already has LilyPond multiplier
     if self._get_indicators(abjad.Multiplier):
         abjad.detach(abjad.Multiplier, self)
         multiplier = new_duration.__div__(self.written_duration)
         abjad.attach(multiplier, self)
         return abjad.select(self)
     # change written duration if new duration is assignable
     try:
         self.written_duration = new_duration
         return abjad.select(self)
     except AssignabilityError:
         pass
     # make new notes or tuplets if new duration is nonassignable
     maker = abjad.NoteMaker(repeat_ties=repeat_ties, )
     components = maker(0, new_duration)
     if isinstance(components[0], abjad.Leaf):
         tied_leaf_count = len(components) - 1
         tied_leaves = tied_leaf_count * self
         all_leaves = [self] + tied_leaves
         for leaf, component in zip(all_leaves, components):
             leaf.written_duration = component.written_duration
         self._splice(tied_leaves, grow_spanners=True)
         parentage = abjad.inspect(self).get_parentage()
         if not abjad.inspect(parentage).get_spanners(abjad.Tie):
             tie = abjad.Tie()
             if tie._attachment_test(self):
                 tie = abjad.Tie(repeat_ties=repeat_ties, )
                 abjad.attach(tie, all_leaves)
         return abjad.select(all_leaves)
     else:
         assert isinstance(components[0], abjad.Tuplet)
         tuplet = components[0]
         components = tuplet[:]
         tied_leaf_count = len(components) - 1
         tied_leaves = tied_leaf_count * self
         all_leaves = [self] + tied_leaves
         for leaf, component in zip(all_leaves, components):
             leaf.written_duration = component.written_duration
         self._splice(tied_leaves, grow_spanners=True)
         if not self._get_spanners(abjad.Tie):
             tie = abjad.Tie()
             if tie._attachment_test(self):
                 tie = abjad.Tie(repeat_ties=repeat_ties, )
                 abjad.attach(tie, all_leaves)
         multiplier = tuplet.multiplier
         tuplet = abjad.Tuplet(multiplier, [])
         abjad.mutate(all_leaves).wrap(tuplet)
         return abjad.select(tuplet)
Пример #24
0
def isAttack(note: abj.Note) -> bool:
    """
    an attack is the first of a group of tied notes. The group
    can be of length 1 for a single note.
    """
    insp = abj.inspect(note)
    logical_tie = insp.logical_tie()
    tiehead = logical_tie[0] is note
    if insp.grace() and len(logical_tie) > 1 and tiehead:
        print("grace note with tie?")
        for t in logical_tie[1:]:
            abj.detach(t, note, by_id=True)
    print(note, tiehead)
    return tiehead
def test_scoretools_Inspection_get_effective_16():
    r'''Detaches metronome mark.
    '''

    staff = abjad.Staff([abjad.Note("c'4")])
    mark = abjad.MetronomeMark(abjad.Duration(1, 8), 38)
    abjad.attach(mark, staff[0], context='Staff')
    abjad.detach(mark, staff[0])

    assert format(staff) == abjad.String.normalize(r'''
        \new Staff {
            c'4
        }
        ''')
Пример #26
0
    def __mul__(self, n):
        r'''Copies component `n` times and detaches spanners.

        Returns list of new components.
        '''
        import abjad
        components = []
        for i in range(n):
            component = abjad.mutate(self).copy()
            components.append(component)
        for component in abjad.iterate(components).components():
            abjad.detach(abjad.Spanner, component)
        result = abjad.select(components)
        return result
def test_scoretools_Measure_duration_is_underfull_01():

    measure = abjad.Measure((3, 8), "c'8 c'8 c'8")
    assert not measure.is_underfull

    abjad.detach(abjad.TimeSignature, measure)
    time_signature = abjad.TimeSignature((4, 8))
    abjad.attach(time_signature, measure)
    assert measure.is_underfull

    abjad.detach(abjad.TimeSignature, measure)
    time_signature = abjad.TimeSignature((3, 8))
    abjad.attach(time_signature, measure)
    assert not measure.is_underfull
Пример #28
0
 def markup(self,
            markup: str,
            ) -> None:
     if markup is not None:
         if not isinstance(markup, str):
             raise TypeError("'markup' must be 'str'")
         self._markup = markup
         markup = abjad.Markup(self._markup,
                               direction=self._direction,
                               )
         abjad.attach(markup, self)
     else:
         self._markup = markup
         if abjad.get.indicator(self, abjad.Markup):
             abjad.detach(abjad.Markup, self)
Пример #29
0
 def _copy_with_indicators_but_without_children_or_spanners(self):
     import abjad
     new = type(self)(*self.__getnewargs__())
     # only the following line differs from Container
     abjad.detach(abjad.TimeSignature, new)
     if getattr(self, '_lilypond_grob_name_manager', None) is not None:
         new._lilypond_grob_name_manager = copy.copy(abjad.override(self))
     if getattr(self, '_lilypond_setting_name_manager', None) is not None:
         new._lilypond_setting_name_manager = copy.copy(abjad.setting(self))
     for indicator in self._get_indicators():
         new_indicator = copy.copy(indicator)
         abjad.attach(new_indicator, new)
     new.is_simultaneous = self.is_simultaneous
     new.implicit_scaling = self.implicit_scaling
     return new
def test_scoretools_Inspection_get_effective_05():
    r'''None cancels an explicit clef.
    '''

    staff = abjad.Staff("c'8 d'8 e'8 f'8 g'8 a'8 b'8 c''8")
    clef = abjad.Clef('treble')
    abjad.attach(clef, staff[0])
    clef = abjad.Clef('bass')
    abjad.attach(clef, staff[4])
    clef = abjad.inspect(staff[4]).get_effective(abjad.Clef)
    abjad.detach(clef, staff[4])

    for note in staff:
        clef = abjad.inspect(note).get_effective(abjad.Clef)
        assert clef == abjad.Clef('treble')
Пример #31
0
    def __mul__(self, n):
        r'''Copies component `n` times and detaches spanners.

        Returns list of new components.
        '''
        import abjad
        result = abjad.mutate(self).copy(n=n)
        for component in abjad.iterate(result).components():
            abjad.detach(abjad.Spanner, component)
        if isinstance(result, type(self)):
            result = [result]
        else:
            result = list(result)
        result = abjad.select(result)
        return result
Пример #32
0
 def _double_bar_line_adder(container: abjad.Container) -> None:
     r"""Goes through a container and adds double bar lines before each and
     every time signature change."""
     leaves = abjad.select(container).leaves()
     for i, leaf in enumerate(leaves[1:], 1):
         time_signature = abjad.get.indicator(leaf, abjad.TimeSignature)
         if time_signature is not None:
             bar_line = abjad.get.indicator(leaves[i - 1], abjad.BarLine)
             if bar_line is not None and bar_line.abbreviation in ('|', ''):
                 abjad.detach(abjad.BarLine, leaves[i - 1])
                 bar_line = None
             if bar_line is None:
                 abjad.attach(abjad.BarLine("||"),
                              leaves[i - 1],
                              context='Voice',
                              )
Пример #33
0
 def _make_build_file(self, previous_metadata=None):
     includes = self._get_lilypond_includes()
     build_file_score = copy.deepcopy(self._score)
     if previous_metadata is not None:
         first_tempo = self._get_first_tempo()
         first_time_signature = self._get_first_time_signature()
         first_leaf = abjad.get.leaf(build_file_score, 0)
         if first_tempo == previous_metadata["last_tempo"]:
             abjad.detach(abjad.MetronomeMark, first_leaf)
         if first_time_signature == previous_metadata[
                 "last_time_signature"]:
             abjad.detach(abjad.TimeSignature, first_leaf)
     build_file = abjad.LilyPondFile(items=[build_file_score],
                                     includes=includes,
                                     use_relative_includes=True)
     self._build_file = build_file
Пример #34
0
 def _notate_leaves(
     self,
     grace_handler=None,
     voice=None,
 ):
     import abjad
     for leaf in abjad.iterate(voice).leaves():
         if leaf._has_indicator(dict):
             annotation = leaf._get_indicator(dict)
             q_events = annotation['q_events']
             pitches, grace_container = grace_handler(q_events)
             if not pitches:
                 new_leaf = abjad.Rest(leaf)
             elif 1 < len(pitches):
                 new_leaf = abjad.Chord(leaf)
                 new_leaf.written_pitches = pitches
             else:
                 new_leaf = abjad.Note(leaf)
                 new_leaf.written_pitch = pitches[0]
             if grace_container:
                 abjad.attach(grace_container, new_leaf)
             tie = abjad.Tie()
             if tie._attachment_test(new_leaf):
                 abjad.attach(tie, abjad.select(new_leaf))
             abjad.mutate(leaf).replace(new_leaf)
         else:
             previous_leaf = leaf._get_leaf(-1)
             if isinstance(previous_leaf, abjad.Rest):
                 new_leaf = type(previous_leaf)(leaf.written_duration, )
             elif isinstance(previous_leaf, abjad.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,
                 )
             abjad.mutate(leaf).replace(new_leaf)
             tie = abjad.inspect(previous_leaf).get_spanner(abjad.Tie)
             if tie is not None:
                 tie._append(new_leaf)
         if leaf._has_indicator(abjad.MetronomeMark):
             tempo = leaf._get_indicator(abjad.MetronomeMark)
             abjad.detach(indicatortools.MetronomeMark, leaf)
             abjad.attach(tempo, new_leaf)
Пример #35
0
 def _remove_and_shrink_durated_parent_containers(self):
     import abjad
     prolated_leaf_duration = self._get_duration()
     parentage = abjad.inspect(self).get_parentage(include_self=False)
     prolations = parentage._prolations
     current_prolation, i = abjad.Duration(1), 0
     parent = self._parent
     while parent is not None and not parent.is_simultaneous:
         current_prolation *= prolations[i]
         if isinstance(parent, abjad.Measure):
             indicator = parent._get_indicator(abjad.TimeSignature)
             parent_time_signature = indicator
             old_prolation = parent_time_signature.implied_prolation
             naive_time_signature = (parent_time_signature.duration -
                                     prolated_leaf_duration)
             better_time_signature = abjad.NonreducedFraction(
                 naive_time_signature)
             better_time_signature = better_time_signature.with_denominator(
                 parent_time_signature.denominator)
             better_time_signature = abjad.TimeSignature(
                 better_time_signature)
             abjad.detach(abjad.TimeSignature, parent)
             abjad.attach(better_time_signature, parent)
             indicator = parent._get_indicator(abjad.TimeSignature)
             parent_time_signature = indicator
             new_prolation = parent_time_signature.implied_prolation
             adjusted_prolation = old_prolation / new_prolation
             for x in parent:
                 if adjusted_prolation != 1:
                     new_target = x._get_preprolated_duration()
                     new_target *= adjusted_prolation
                     contents_duration = abjad.inspect(x)
                     multiplier = new_target / contents_duration
                     tuplet = abjad.Tuplet(multiplier, [])
                     abjad.mutate(x).wrap(tuplet)
         parent = parent._parent
         i += 1
     parentage = abjad.inspect(self).get_parentage(include_self=False)
     parent = self._parent
     if parent:
         index = parent.index(self)
         del (parent[index])
     for x in parentage:
         if not len(x):
             x._extract()
         else:
             break
Пример #36
0
 def _tie_across_divisions_(self, divisions):
     import abjad
     if not self.tie_across_divisions:
         return
     if self.strip_ties:
         return
     if self.tie_consecutive_notes:
         return
     length = len(divisions)
     tie_across_divisions = self.tie_across_divisions
     if isinstance(tie_across_divisions, bool):
         tie_across_divisions = [tie_across_divisions]
     if not isinstance(tie_across_divisions, abjad.Pattern):
         tie_across_divisions = abjad.Pattern.from_vector(
             tie_across_divisions)
     pairs = abjad.sequence(divisions).nwise()
     rest_prototype = (abjad.Rest, abjad.MultimeasureRest)
     for i, pair in enumerate(pairs):
         if not tie_across_divisions.matches_index(i, length):
             continue
         division_one, division_two = pair
         leaf_one = next(abjad.iterate(division_one).leaves(reverse=True))
         leaf_two = next(abjad.iterate(division_two).leaves())
         leaves = [leaf_one, leaf_two]
         if isinstance(leaf_one, rest_prototype):
             continue
         if isinstance(leaf_two, rest_prototype):
             continue
         pitched_prototype = (abjad.Note, abjad.Chord)
         if not all(isinstance(_, pitched_prototype) for _ in leaves):
             continue
         logical_tie_one = abjad.inspect(leaf_one).get_logical_tie()
         logical_tie_two = abjad.inspect(leaf_two).get_logical_tie()
         if logical_tie_one == logical_tie_two:
             continue
         combined_logical_tie = logical_tie_one + logical_tie_two
         for leaf in combined_logical_tie:
             abjad.detach(abjad.Tie, leaf)
         tie = abjad.Tie(repeat=self.repeat_ties)
         tie._unconstrain_contiguity()
         if tie._attachment_test_all(combined_logical_tie) is True:
             try:
                 abjad.attach(tie, combined_logical_tie)
             except:
                 raise Exception(tie, combined_logical_tie)
         tie._constrain_contiguity()
Пример #37
0
 def _scale_denominator(self, factor):
     import abjad
     # save old time signature duration
     old_time_signature_duration = self.time_signature.duration
     # find new time signature
     new_time_signature = self._duration_to_time_signature(
         old_time_signature_duration,
         factor=factor,
         )
     # scale contents of measures in argument
     multiplier = new_time_signature.implied_prolation.reciprocal
     self._scale(multiplier)
     # assign new time signature
     abjad.detach(abjad.TimeSignature, self)
     abjad.attach(new_time_signature, self)
     if new_time_signature.has_non_power_of_two_denominator:
         self.implicit_scaling = True
def test_spannertools_Beam_detach_02():
    r'''Detach length-four spanner.
    '''

    staff = abjad.Staff("c'8 cs'8 d'8 ef'8 e'8 f'8 fs'8 g'8")
    beam = abjad.Beam()
    abjad.attach(beam, staff[:4])

    assert format(staff) == abjad.String.normalize(
        r'''
        \new Staff
        {
            c'8
            [
            cs'8
            d'8
            ef'8
            ]
            e'8
            f'8
            fs'8
            g'8
        }
        '''
        )

    abjad.detach(beam, staff[0])

    assert format(staff) == abjad.String.normalize(
        r'''
        \new Staff
        {
            c'8
            cs'8
            d'8
            ef'8
            e'8
            f'8
            fs'8
            g'8
        }
        '''
        )

    assert abjad.inspect(staff).is_well_formed()
    def _handle_lifeline_voice(self, voice, current_stage):
        if self._fret_combinations is None:
            return

        # reset the fret combination pattern cycle
        pattern = self._fret_combination_patterns[current_stage]
        pattern.reset()

        for logical_tie in abjad.iterate(voice).by_logical_tie(pitched=True):
            # hide all note_heads
            for chord in logical_tie:
                self._hide_note_head(chord)

            # make a glissando map
            fret_combination = self._fret_combinations[pattern.next()]
            glissando_map = self._make_glissando_map(
                fret_combination,
                voice.context_name
            )

            # attach glissando map and glissando command
            if glissando_map is not None:
                abjad.attach(glissando_map, logical_tie.head)
                self._attach_glissando(logical_tie.head, thickness=2)

                if not logical_tie.is_trivial:
                    for leaf in logical_tie[1:]:
                        self._add_gliss_skip(leaf)

            # make glissando anchor into chord
            try:
                anchor = \
                    abjad.inspect(logical_tie[-1]).get_after_grace_container()
                anchor[0] = abjad.Chord(logical_tie[0])
            except Exception:
                pass

        # strip other markups
        abjad.detach(abjad.Markup, voice)

        # get groups of non-rest leaves, attach gliss anchor to last
        for note_group in self._get_consecutive_note_groups(voice):
            last = note_group[-1]
            self._hidden_grace_after(last, grace_note=abjad.Chord(last))
Пример #40
0
 def reconfigure_double_grace_containers(containers, indices):
     #for i, leaf in enumerate(abjad.iterate(containers).leaves()):
     leaves = abjad.iterate(containers).leaves(grace_notes=False)
     for i, leaf in enumerate(leaves):
         if i not in indices:
             continue
         grace_container = abjad.inspect(leaf).grace_container()
         if not grace_container:
             continue
         grace_containers = [grace_container]
         if len(grace_containers) == 1:
             grace_container = grace_containers[0]
             assert isinstance(grace_container, abjad.GraceContainer)
             abjad.detach(abjad.GraceContainer, leaf)
         elif len(grace_containers) == 2:
             assert isinstance(grace_containers[0], abjad.GraceContainer)
             grace_container = grace_containers[0]
             assert isinstance(
                 grace_containers[1],
                 abjad.AfterGraceContainer,
                 )
             after_grace_container = grace_containers[1]
             if len(grace_container) == 1:
                 abjad.detach(grace_container, leaf)
             elif 1 < len(grace_container):
                 new_grace_container = abjad.AfterGraceContainer(
                     grace_container[:],
                     )
                 abjad.detach(grace_container, leaf)
                 abjad.detach(after_grace_container, leaf)
                 new_grace_container[2:] = []
                 del(new_grace_container[0])
                 abjad.attach(new_grace_container, leaf)
             else:
                 raise Exception(grace_container)
         else:
             raise Exception(grace_containers)
    def __call__(self):
        import consort

        manager = consort.ScoreTemplateManager

        time_signature_context = manager.make_time_signature_context()

        violin_one = manager.make_single_string_performer(
            clef=indicatortools.Clef('treble'),
            instrument=instrumenttools.Violin(
                instrument_name='violin 1',
                instrument_name_markup=markuptools.Markup(
                    'Violin 1').hcenter_in(10),
                short_instrument_name='vln. 1',
                short_instrument_name_markup=markuptools.Markup(
                    'Vln. 1').hcenter_in(10)
                ),
            split=self.split,
            score_template=self,
            )

        violin_two = manager.make_single_string_performer(
            clef=indicatortools.Clef('treble'),
            instrument=instrumenttools.Violin(
                instrument_name='violin 2',
                instrument_name_markup=markuptools.Markup(
                    'Violin 2').hcenter_in(10),
                short_instrument_name='vln. 2',
                short_instrument_name_markup=markuptools.Markup(
                    'Vln. 2').hcenter_in(10)
                ),
            split=self.split,
            score_template=self,
            )

        viola = manager.make_single_string_performer(
            clef=indicatortools.Clef('alto'),
            instrument=instrumenttools.Viola(
                instrument_name='viola',
                instrument_name_markup=markuptools.Markup(
                    'Viola').hcenter_in(10),
                short_instrument_name='va.',
                short_instrument_name_markup=markuptools.Markup(
                    'Va.').hcenter_in(10)
                ),
            split=self.split,
            score_template=self,
            )

        cello = manager.make_single_string_performer(
            clef=indicatortools.Clef('bass'),
            instrument=instrumenttools.Cello(
                instrument_name='cello',
                instrument_name_markup=markuptools.Markup(
                    'Cello').hcenter_in(10),
                short_instrument_name='vc.',
                short_instrument_name_markup=markuptools.Markup(
                    'Vc.').hcenter_in(10)
                ),
            split=self.split,
            score_template=self,
            )

        score = abjad.Score(
            [
                time_signature_context,
                violin_one,
                violin_two,
                viola,
                cello,
                ],
            name='String Quartet Score',
            )

        if self.without_instruments:
            for staff in iterate(score).by_class(abjad.Context):
                detach(instrumenttools.Instrument, staff)

        return score
Пример #42
0
def make_key_staff():
    """
    Makes key staff.

    Returns staff.
    """

    outer = baca.sequence([[1, 1, 2], [2, 3], [1, 1, 2, 3]])
    outer = outer.helianthate(1, 1)
    outer = outer.flatten()
    outer = outer.repeat(n=3).flatten()

    assert len(outer) == 324

    slice_indicators = [(0, 8), (32, 8), (64, 8), (160, 8), (192, 8), (224, 8)]
    outer = cary.overwrite_elements(outer, slice_indicators)
    outer = baca.sequence(outer).rotate(n=-20)

    assert len(outer) == 324

    modifications = cary.make_key_modifications()
    outer = cary.negate_elements(outer, indices=modifications['outer'])

    assert len(outer) == 324

    time_signatures = cary.make_time_signatures()
    numerators = time_signatures['numerators']
    assert len(numerators) == 138

    adjusted_measure_number = 101
    numerators = list(numerators)
    numerators[adjusted_measure_number-1] += 3

    flattened_outer = baca.sequence(outer).flatten()
    outer_weight = abjad.mathtools.weight(flattened_outer)
    numerator_weight = abjad.mathtools.weight(numerators)
    assert numerator_weight <= outer_weight

    outer = baca.sequence(outer).partition_by_weights(
        numerators,
        cyclic=False,
        overhang=False,
        allow_part_weights=abjad.More,
        )

    assert len(outer) == 138

    numerators[adjusted_measure_number-1] -= 3

    assert [list(_) for _ in outer] == [
        [-2, 3], [1, 1, 1, -2], [1, 1, 1, 2], [3, 2], [-1, -1, 1], [1, 1, 1],
        [-1, 1, 2], [1, 1, 2], [3, 3], [2], [3], [1], [1, 2], [1, 2], [1], [-1,
        -1, 2], [2, 3], [2, 3], [1, 1, -1], [2], [2, -2], [2, -2], [2, 2], [2,
        2], [3, 1], [1, 2, 3], [1, -2], [1, 1], [1, 2], [3, 2], [3, 1], [1],
        [2], [2, 3], [1, 1, 2], [1, 1, 2], [3, -3], [2, 1], [2, 3], [1, 1, 2],
        [1, 1], [1, 2], [2, 3], [-1, 1], [2], [3], [3], [1, 1, 2], [2, -1], [1,
        3], [2, 2, -3], [2, -3], [1, 1], [1, 2], [1, 1, 1], [2, 3], [2, 1, -2],
        [-3], [1, 1], [1], [2, 3], [2, 1, 1], [2, 3], [3, -2], [3, 1], [1, 2,
        1], [-2], [2, 2], [2, 2], [2, 2], [2], [3], [1, 1, 1], [-2, 3], [1, 2,
        1], [1], [3], [2], [2], [-3, -1], [1, -2], [3], [1, 2, 1, 1], [1, 2],
        [3], [3, -3], [3, 3], [3, 3], [3], [1, 1, 2], [-1, -1, 2], [3, 3], [-2,
        1, 2], [3], [1, 1, 2], [1], [1, 1], [-2, 2], [3, 1, 1], [2, 3], [3, 3],
        [-3], [3, 3], [3], [3, 3], [2, 2], [3], [2, 3], [-1, -1, -1], [2, 1,
        1], [1, 2, 3], [2], [1, 2], [3], [1], [1, 1], [-2, 3], [2, 1, 1], [-2,
        3], [3], [2, 3], [-1, -1, 2], [1, 2, 1], [1, 1, 2], [2], [3], [-2, 3],
        [1, 1, 1, 2], [3, 1], [-2], [1, 1, 3], [2, 2], [3], [1], [1, 2], [3, 1,
        -2], [1, 1, 1, 2], [3],
        ], repr(outer)

    inner = [2, 5, 3]
    length = len(baca.sequence(outer).flatten())
    inner = baca.sequence(inner).repeat_to_length(length)

    assert len(inner) == 281, len(inner)

    counts = [len(_) for _ in outer]
    inner = baca.sequence(inner).partition_by_counts(counts)

    assert len(inner) == 138

    assert [list(_) for _ in inner[:5]] == [
        [2, 5], [3, 2, 5, 3], [2, 5, 3, 2], [5, 3], [2, 5, 3],
        ]

    chopped_numerators = [int(_) for _ in numerators]
    inner = cary.increase_sublist_end_elements(inner, chopped_numerators)

    assert len(inner) == 138

    assert inner == [
        [5, 9], [5, 2, 5, 7], [6, 5, 3, 5], [9, 6], [5, 5, 5], [5, 5, 7], [4,
        5, 7], [6, 5, 6], [6, 6], [3], [2], [5], [4, 4], [7, 4], [2], [6, 3,
        5], [9, 6], [5, 8], [6, 2, 6], [3], [3, 8], [7, 5], [8, 6], [5, 8], [6,
        6], [8, 3, 4], [9, 4], [4, 7], [4, 5], [7, 7], [5, 6], [3], [2], [7,
        7], [5, 5, 6], [6, 5, 6], [5, 8], [6, 5], [8, 7], [5, 5, 5], [6, 7],
        [5, 5], [7, 4], [5, 6], [3], [2], [5], [5, 2, 8], [7, 5], [8, 7], [5,
        5, 7], [6, 6], [7, 5], [6, 6], [5, 5, 6], [5, 8], [6, 2, 6], [3], [3,
        6], [3], [3, 9], [6, 2, 8], [7, 5], [8, 6], [5, 9], [6, 2, 6], [3], [3,
        9], [6, 5], [9, 3], [2], [5], [4, 2, 9], [6, 5], [9, 3, 2], [5], [3],
        [2], [5], [4, 5], [9, 6], [2], [8, 3, 2, 7], [7, 5], [5], [6, 6], [8,
        7], [6, 7], [3], [4, 5, 6], [5, 5, 7], [5, 9], [7, 2, 7], [3], [4, 5,
        4], [2], [6, 6], [4, 9], [6, 2, 8], [7, 4], [8, 6], [2], [8, 5], [2],
        [7, 5], [5, 8], [3], [5, 7], [7, 2, 8], [5, 2, 8], [6, 2, 7], [3], [4,
        6], [3], [2], [6, 7], [4, 8], [7, 2, 8], [6, 3], [5], [4, 6], [8, 3,
        5], [9, 3, 5], [8, 3, 3], [5], [3], [5, 8], [7, 2, 5, 6], [5, 6], [3],
        [3, 5, 7], [5, 7], [3], [2], [6, 7], [5, 5, 6], [6, 5, 3, 5], [5],
        ]

    inner = baca.sequence(inner).flatten()

    assert len(inner) == 281

    inner = [[1] * _ for _ in inner]

    assert inner[:3] == [
        [1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1]
        ]

    indices = (modifications['inner'], None)
    material = ([[1]], 1)
    inner = baca.sequence(inner).replace_at(indices, material)

    assert [list(_) for _ in inner[:3]] == [[1], [1], [1]]

    containers = cary.nest_tuplets(
        time_signatures['pairs'],
        outer,
        inner,
        )
    assert isinstance(containers, list), repr(containers)

    for measure_index, container in enumerate(containers):
        assert isinstance(container, abjad.Container), repr(container)
        measure_number = measure_index + 1
        if measure_number in cary.silent_measure_numbers:
            duration = abjad.inspect(container).duration()
            maker = abjad.LeafMaker()
            rests = maker([None], [duration])
            inner_tuplet = abjad.Tuplet((1, 1), rests)
            outer_tuplet = abjad.Tuplet((1, 1), [inner_tuplet])
            container[:] = [outer_tuplet]

    def apply_pitches(containers, pitched_notes):
        pitch_index = 0
        #leaves = abjad.iterate(containers).leaves()
        leaves = abjad.iterate(containers).leaves(grace_notes=False)
        for leaf_index, leaf in enumerate(leaves):
            if not isinstance(leaf, abjad.Note):
                continue
            if leaf_index == 603:
                pitch_index += 1
            pitched_note = pitched_notes[pitch_index]
            written_pitch = pitched_note.written_pitch
            leaf.written_pitch = written_pitch
            if written_pitch == -1:
                abjad.label(leaf).color_leaves('green')
            pitch_index += 1
            inspection = abjad.inspect(leaf)
            grace_container = inspection.grace_container()
            if not grace_container:
                continue
            for grace_container in [grace_container]:
                agent = abjad.iterate(grace_container)
                for note in agent.leaves(pitched=True):
                    pitched_note = pitched_notes[pitch_index]
                    written_pitch = pitched_note.written_pitch
                    note.written_pitch = written_pitch
                    pitch_index += 1

    def detach_grace_containers(containers, indices):
        #for i, leaf in enumerate(abjad.iterate(containers).leaves()):
        leaves = abjad.iterate(containers).leaves(grace_notes=False)
        for i, leaf in enumerate(leaves):
            if i not in indices:
                continue
            abjad.detach(abjad.GraceContainer, leaf)

    def reconfigure_double_grace_containers(containers, indices):
        #for i, leaf in enumerate(abjad.iterate(containers).leaves()):
        leaves = abjad.iterate(containers).leaves(grace_notes=False)
        for i, leaf in enumerate(leaves):
            if i not in indices:
                continue
            grace_container = abjad.inspect(leaf).grace_container()
            if not grace_container:
                continue
            grace_containers = [grace_container]
            if len(grace_containers) == 1:
                grace_container = grace_containers[0]
                assert isinstance(grace_container, abjad.GraceContainer)
                abjad.detach(abjad.GraceContainer, leaf)
            elif len(grace_containers) == 2:
                assert isinstance(grace_containers[0], abjad.GraceContainer)
                grace_container = grace_containers[0]
                assert isinstance(
                    grace_containers[1],
                    abjad.AfterGraceContainer,
                    )
                after_grace_container = grace_containers[1]
                if len(grace_container) == 1:
                    abjad.detach(grace_container, leaf)
                elif 1 < len(grace_container):
                    new_grace_container = abjad.AfterGraceContainer(
                        grace_container[:],
                        )
                    abjad.detach(grace_container, leaf)
                    abjad.detach(after_grace_container, leaf)
                    new_grace_container[2:] = []
                    del(new_grace_container[0])
                    abjad.attach(new_grace_container, leaf)
                else:
                    raise Exception(grace_container)
            else:
                raise Exception(grace_containers)

    def truncate_grace_containers(containers, indices):
        #leaves = abjad.iterate(containers).leaves()
        leaves = abjad.iterate(containers).leaves(grace_notes=False)
        for i, leaf in enumerate(leaves):
            if i not in indices:
                continue
            grace_container = abjad.inspect(leaf).after_grace_container()
            if grace_container is None:
                continue
            assert isinstance(grace_container, abjad.AfterGraceContainer)
            grace_container[1:] = []
            abjad.label(grace_container).color_leaves('blue')

    grace_indices = cary.make_grace_indices()

    cary.attach_grace_containers(
        cyclic=True,
        indices=cary.make_key_region_indices()[0],
        material=True,
        minimum_duration=abjad.Duration(1, 12),
        components=containers,
        )

    cary.attach_grace_containers(
        cyclic=True,
        indices=cary.make_key_region_indices()[2],
        material=True,
        minimum_duration=abjad.Duration(1, 12),
        components=containers,
        )

    cary.attach_grace_containers(
        cyclic=True,
        indices=cary.make_key_region_indices()[3],
        material=True,
        minimum_duration=abjad.Duration(1, 12),
        components=containers,
        )

    cary.attach_grace_containers(
        cyclic=True,
        indices=grace_indices['first']['indices'],
        material=grace_indices['first']['material'],
        minimum_duration=abjad.Duration(1, 12),
        components=containers,
        )

    cary.attach_grace_containers(
        cyclic=False,
        indices=grace_indices['second']['indices'],
        material=grace_indices['second']['material'],
        minimum_duration=abjad.Duration(1, 24),
        components=containers,
        )

    notes = cary.make_notes()
    apply_pitches(containers, notes)

    detach_grace_containers(
        containers,
        cary.make_key_region_indices()[0],
        )

    truncate_grace_containers(
        containers,
        cary.make_key_region_indices()[1],
        )

    reconfigure_double_grace_containers(
        containers,
        cary.make_key_region_indices()[2],
        )

    truncate_grace_containers(
        containers,
        cary.make_key_region_indices()[-1],
        )

    #notes = abjad.select(containers).leaves(pitched=True)
    notes = abjad.select(containers).leaves(
        pitched=True,
        grace_notes=False,
        )
    last_note = notes[-1]
    abjad.detach(abjad.GraceContainer, last_note)

    tuplets = abjad.iterate(containers).components(abjad.Tuplet)
    for tuplet in tuplets:
        if not any(isinstance(_, abjad.Tuplet) for _ in tuplet):
            #leaves = abjad.select(tuplet).leaves()
            leaves = abjad.select(tuplet).leaves(grace_notes=False)
            abjad.beam(leaves)

    key_voice = abjad.Voice(
        components=containers,
        lilypond_type='KeyVoice',
        name='Key_Voice',
        )

    notes = 15 * abjad.Note("aqs'4")
    inner_tuplet = abjad.Tuplet((14, 15), notes)
    outer_tuplet = abjad.Tuplet((1, 1), [inner_tuplet])
    container = abjad.Container([outer_tuplet])
    overwrite_measure_numbers = cary.overwrite_measure_numbers
    start_measure_number, stop_measure_number = overwrite_measure_numbers
    start_measure_index = start_measure_number - 1
    stop_measure_index = stop_measure_number - 1
    # TODO: uncomment after rebuild
    key_voice[start_measure_index:stop_measure_index] = [container]

    key_staff = abjad.Staff(
        components=[
            key_voice,
            ],
        lilypond_type='KeyStaff',
        name='KeyStaff'
        )

    return key_staff
Пример #43
0
    def __call__(
        self,
        segment_metadata=None,
        previous_segment_metadata=None,
        ):
        r'''Calls segment-maker.

        Returns LilyPond file and segment metadata.
        '''
        self._segment_metadata = segment_metadata or \
            abjad.datastructuretools.TypedOrderedDict()
        self._previous_segment_metadata = previous_segment_metadata or \
            abjad.datastructuretools.TypedOrderedDict()

        score_template = hijinks.tools.ScoreTemplate()
        score = score_template()
        violin_music_staff = score['Violin Music Staff']
        piano_staff_group = score['Piano Staff Group']
        instruments = hijinks.materials.instruments
        abjad.detach(abjad.instrumenttools.Instrument, violin_music_staff)
        abjad.attach(instruments['violin'], violin_music_staff)
        abjad.detach(abjad.instrumenttools.Instrument, piano_staff_group)
        abjad.attach(instruments['piano'], piano_staff_group)

        #aggregate = pitch.CC[0][175 - 1]
        aggregate = [10, 19, 20, 23, 24, 26, 27, 29, 30, 33, 37, 40]
        assert aggregate == [10, 19, 20, 23, 24, 26, 27, 29, 30, 33, 37, 40]

        cary = [[-2, -12, -10], [18, 8, 7, 17], [15, 25, 21, 4, 11]]

        order_1 = abjad.sequencetools.flatten_sequence(cary)
        order_1 = [_ % 12 for _ in order_1]
        assert order_1 == [10, 0, 2, 6, 8, 7, 5, 3, 1, 9, 4, 11]

        order_2 = [abjad.sequencetools.rotate_sequence(_, 1) for _ in cary]
        order_2 = abjad.sequencetools.rotate_sequence(order_2, -1)
        order_2 = abjad.sequencetools.flatten_sequence(order_2)
        order_2 = [_ % 12 for _ in order_2]
        assert order_2 == [5, 6, 8, 7, 11, 3, 1, 9, 4, 2, 10, 0]

        order_3 = [abjad.sequencetools.rotate_sequence(_, 2) for _ in cary]
        order_3 = abjad.sequencetools.rotate_sequence(order_3, -2)
        order_3 = abjad.sequencetools.flatten_sequence(order_3)
        order_3 = [_ % 12 for _ in order_3]
        assert order_3 == [4, 11, 3, 1, 9, 0, 2, 10, 7, 5, 6, 8]

        aggregate = abjad.pitchtools.PitchSet(
            items=aggregate,
            item_class=abjad.pitchtools.NumberedPitch,
            )

        violin_pitches = []
        orders = (order_1, order_2, order_3)
        for order in orders:
            pitches_ = aggregate.register(order)
            violin_pitches.extend(pitches_)

        #circuit = 8 * [0]
        #circuit[1-1] = CC[5][111 - 1]
        #circuit[2-1] = CC[6][68 - 1]
        #circuit[3-1] = CC[7][31 - 1]
        #circuit[4-1] = CC[0][175 - 1]
        #circuit[5-1] = CC[1][93 - 1]
        #circuit[6-1] = CC[2][31 - 1]
        #circuit[7-1] = CC[3][2 - 1]
        #circuit[8-1] = CC[4][85 - 1]

        circuit = 8 * [0]
        circuit[1-1] = [-37, -18, -16, -5, -3, 3, 13, 14, 16, 22, 24, 29]
        circuit[2-1] = [-25, -17, -12, -10, -6, -4, -2, 5, 15, 16, 21, 25]
        circuit[3-1] = [-36, -34, -26, -20, -16, -7, 3, 13, 23, 31, 42, 45]
        circuit[4-1] = [10, 19, 20, 23, 24, 26, 27, 29, 30, 33, 37, 40]
        circuit[5-1] = [-8, -4, -1, 5, 7, 12, 14, 15, 18, 21, 22, 25]
        circuit[6-1] = [-20, -13, -12, -10, -2, 3, 8, 9, 13, 17, 19, 30]
        circuit[7-1] = [-36, -32, -25, -22, -21, -14, -11, -4, -3, 5, 6, 7]
        circuit[8-1] = [-34, -29, -26, -19, -12, -9, 1, 4, 11, 30, 32, 45]

        violin_tuplet_definitions = [
            ([4, 2, 2, 2], (8, 16)),
            ([2, 2, 4, 1, 1], (8, 16)),
            ([4, 2, 2, 2], (8, 16)),
            ([3, 2], (4, 16)),
            ]

        tuplet_maker = \
            abjad.Tuplet.from_nonreduced_ratio_and_nonreduced_fraction

        violin_tuplets = []
        for definition in violin_tuplet_definitions:
            violin_tuplet = tuplet_maker(*definition)
            leaves = list(abjad.iterate(violin_tuplet).by_leaf())
            abjad.attach(abjad.spannertools.MultipartBeam(), leaves)
            violin_tuplets.append(violin_tuplet)

        violin_music_staff = score['Violin Music Staff']
        violin_music_staff.extend(violin_tuplets)

        notes = abjad.iterate(violin_music_staff).by_leaf(pitched=True)
        for i, note in enumerate(notes):
            note.written_pitch = violin_pitches[i]

        violin_music_staff[-1:-1] = [abjad.Rest((1, 8))]

        rh_pairs = [(n, 16) for n in (4, 3, 3, 4, 3, 3, 4, 4)]
        lh_pairs = [(n, 16) for n in (3, 4, 3, 2, 4, 4, 4, 4)]

        rh_proportions = [
            [2, 2, 2, 1, 1, 1, 1],
            [1, 1, 4, 4, 4],
            [4, 4, 2, 2, 1, 1],
            [4, 1, 1, 1, 1, 4, 4, 2, 1, 1, 1, 1],
            [4, 2, 2, 2, 2, 1, 1, 1, 1],
            [4, 4, 1, 1, 4, 1, 1],
            [4, 12, 12],
            [1, 1, 2, 2, 4, 4],
            ]

        lh_proportions = [
            [4, 3, 3, 3, 1],
            [4, 4, 3, 3, 2, 2, 2],
            [2, 2, 2, 4, 4, 4],
            [-8],
            [6, 6, 8],
            [2, 2, 3, 3, 4],
            [2, 2, 1, 1, 1, 1, 4, 4, 4],
            [6, 6, 2, 2, 1, 1],
            ]

        piano_rh_music_staff = score['Piano RH Music Staff']
        rh_tuplets = []
        for rh_proportion, rh_pair, aggregate in zip(
            rh_proportions, rh_pairs, circuit):
            rh_tuplet = tuplet_maker(rh_proportion, rh_pair)
            if isinstance(rh_tuplet, abjad.Tuplet):
                duration = abjad.inspect_(rh_tuplet).get_duration()
                duration = duration.with_denominator(32)
                rh_tuplet.preferred_denominator = duration.numerator
            leaves = list(abjad.iterate(rh_tuplet).by_leaf())
            abjad.attach(abjad.spannertools.MultipartBeam(), leaves)
            notes = list(abjad.iterate(rh_tuplet).by_leaf(pitched=True))
            for note, pitch_number in zip(notes, reversed(aggregate)):
                note.written_pitch = pitch_number
            rh_tuplets.append(rh_tuplet)
        piano_rh_music_staff.extend(rh_tuplets)
        piano_rh_music_staff[-1:-1] = [abjad.Rest((1, 8))]

        piano_lh_music_staff = score['Piano LH Music Staff']
        lh_tuplets = []
        for lh_proportion, lh_pair, aggregate in zip(
            lh_proportions, lh_pairs, circuit):
            lh_tuplet = tuplet_maker(lh_proportion, lh_pair)
            if isinstance(lh_tuplet, abjad.Tuplet):
                duration = abjad.inspect_(lh_tuplet).get_duration()
                duration = duration.with_denominator(32)
                lh_tuplet.preferred_denominator = duration.numerator
            leaves = list(abjad.iterate(lh_tuplet).by_leaf())
            abjad.attach(abjad.spannertools.MultipartBeam(), leaves)
            notes = abjad.iterate(lh_tuplet).by_leaf(pitched=True)
            for note, pitch_number in zip(notes, aggregate):
                note.written_pitch = pitch_number
            lh_tuplets.append(lh_tuplet)
        piano_lh_music_staff.extend(lh_tuplets)
        piano_lh_music_staff[-1:-1] = [abjad.Rest((1, 8))]

        leaves = list(abjad.iterate(piano_lh_music_staff).by_leaf())
        second_lh_note = leaves[1]
        markup = abjad.Markup('ped. ad libitum').italic()
        abjad.attach(markup, second_lh_note)
        abjad.override(second_lh_note).text_script.padding = 2

        for note in abjad.iterate(piano_staff_group).by_leaf(pitched=True):
            if note.written_duration <= abjad.Duration(1, 64):
                abjad.attach(abjad.Articulation('staccato'), note)
            else:
                abjad.attach(abjad.Articulation('tenuto'), note)

        for note in abjad.iterate(violin_music_staff).by_leaf(pitched=True):
            if note.written_duration <= abjad.Duration(1, 16):
                abjad.attach(abjad.Articulation('staccato'), note)
            abjad.attach(abjad.Articulation('tenuto'), note)

        tempo = abjad.Tempo((1, 8), 32)
        abjad.attach(tempo, violin_music_staff)

        time_signature = abjad.TimeSignature((1, 8))
        abjad.attach(time_signature, violin_music_staff)

        leaves = list(abjad.iterate(violin_music_staff).by_leaf())
        first_violin_leaf = leaves[0]

        markup = abjad.Markup('pp').dynamic()
        markup = markup.line(abjad.Markup('sempre al fino').italic())

        abjad.attach(markup, first_violin_leaf)
        abjad.override(first_violin_leaf).text_script.staff_padding = 5

        tuplets = list(abjad.iterate(violin_music_staff).by_class(
            prototype=abjad.Tuplet))
        abjad.override(tuplets[-1]).tuplet_bracket.shorten_pair = (0, 0.6)

        leaves = list(abjad.iterate(piano_rh_music_staff).by_leaf())
        first_rh_leaf = leaves[0]

        markup = abjad.Markup('pp').dynamic()
        markup = markup.line(abjad.Markup('sempre al fino').italic())

        abjad.attach(markup, first_rh_leaf)
        abjad.override(first_rh_leaf).text_script.staff_padding = 7

        tuplets = list(abjad.iterate(piano_rh_music_staff).by_class(
            prototype=abjad.Tuplet))
        abjad.override(tuplets[-1]).tuplet_bracket.shorten_pair = (0, 0.6)

        tuplets = list(abjad.iterate(piano_lh_music_staff).by_class(
            prototype=abjad.Tuplet))
        abjad.override(tuplets[-1]).tuplet_bracket.shorten_pair = (0, 0.6)

        leaves = list(abjad.iterate(score).by_leaf())
        last_leaf = leaves[-1]
        command = abjad.indicatortools.LilyPondCommand('bar "|."', 'after')
        abjad.attach(command, last_leaf)

        string = "override Score.BarLine #'transparent = ##f"
        command = abjad.indicatortools.LilyPondCommand(string, 'after')
        abjad.attach(command, last_leaf)

        string = "override Score.SpanBar #'transparent = ##f"
        command = abjad.indicatortools.LilyPondCommand(string, 'after')
        abjad.attach(command, last_leaf)

        final_markup = hijinks.tools.make_final_markup()
        abjad.attach(final_markup, last_leaf)
        abjad.override(last_leaf).text_script.extra_offset = (-7.5, -4)

        stylesheet_path = os.path.join(
            '..',
            '..',
            'stylesheets',
            'stylesheet.ily',
            )

        lilypond_file = abjad.lilypondfiletools.make_basic_lilypond_file(
            score,
            default_paper_size=('letter', 'portrait'),
            global_staff_size=14,
            includes=(stylesheet_path,),
            use_relative_includes=True,
            )

        return lilypond_file, self._segment_metadata
Пример #44
0
    def _interpret_music_handlers(self):
        r""" Fills the empty score with music based on each instrument's music
        handler and maker. Removes instrument indicators from staff contexts.
        """
        # For each stage,
        for stage in range(self.number_of_stages):
            # Log the stage
            stage_string = '\tStage {} of {}'
            stage_string = stage_string.format(
                stage + 1,
                self.number_of_stages
            )
            print(stage_string)

            # For each music handler,
            for music_handler in self._music_handlers:
                # Format handler name for logging
                handler_instrument = music_handler.instrument.instrument_name
                handler_instrument = handler_instrument.title()
                if handler_instrument[-1] == 'i':
                    handler_instrument = handler_instrument[0:-1] + 'I'
                handler_name = music_handler.name.title()
                handler_string = '\t\tMusic handler: {} {}'
                handler_string = handler_string.format(
                    handler_instrument, handler_name)
                print(handler_string)
                print('\t\t\tMaking music...')

                # Call the music handler
                voices = music_handler(stage)
                print('\t\t\tMatching voices to staves...')

                # For each voice generated by handler,
                for voice in voices:
                    # Get the instrument attached to the voice
                    voice_instrument = abjad.inspect(voice).get_indicator(
                        abjad.Instrument
                    )
                    assert(isinstance(voice_instrument, abjad.Instrument))
                    voice_instrument = voice_instrument.instrument_name
                    voice_instrument = voice_instrument.title()

                    # Capitalize roman numerals
                    if voice_instrument[-1] == 'i':
                        voice_instrument = voice_instrument[0:-1] + 'I'

                    # For each staff in the score:
                    for staff in abjad.iterate(self._score).by_class(
                            abjad.Staff):
                        # Skip separator staves.
                        if staff.name is 'Separator':
                            continue

                        # Get instrument attached to staff.
                        staff_instrument = abjad.inspect(staff).get_annotation(
                            'instrument'
                        )

                        # If instruments match, ...
                        if voice.name in staff_map[staff.name] and \
                                voice_instrument == staff_instrument:
                            # ... remove the instrument indicator from voice,
                            abjad.detach(
                                abjad.instrumenttools.Instrument,
                                voice
                            )

                            # ...and either add voice to staff, ...
                            if len(staff) == 0:
                                staff.append(voice)

                            # ... or extend existing voice.
                            else:
                                voice_in_staff = False
                                for existing_voice in staff:
                                    if voice.name == existing_voice.name:
                                        existing_voice.extend(voice)
                                        voice_in_staff = True
                                if not voice_in_staff:
                                    staff.append(voice)
Пример #45
0
        maker = baca.SegmentMaker(
            breaks=breaks,
            do_not_check_persistence=True,
            do_not_include_layout_ly=True,
            final_bar_line=False,
            first_measure_number=first_measure_number,
            score_template=baca.SingleStaffScoreTemplate(),
            spacing=spacing,
            time_signatures=time_signatures,
            )
        lilypond_file = maker.run(remove=abjad.tags.layout_removal_tags())
        context = lilypond_file['GlobalSkips']
        measure_count = len(context)
        skips = baca.select(context).skips()
        for skip in skips:
            abjad.detach(abjad.TimeSignature, skip)
        score = lilypond_file['Score']
        del(score['MusicContext'])
    except:
        traceback.print_exc()
        sys.exit(1)

    try:
        score = lilypond_file['Score']
        text = format(score, 'lilypond')
        text = text.replace('GlobalSkips', 'PageLayout')
        text = abjad.LilyPondFormatManager.left_shift_tags(text, realign=89)
        time_signatures = [str(_) for _ in time_signatures]
        line_1 = f'% time_signatures = {{time_signatures}}\n'
        measure_count = len(time_signatures)
        line_2 = f'% measure_count = {{measure_count}}\n'
    def _handle_lifeline_voice(self, voice, current_stage):
        # hide note heads if no fingerings
        if self._fingerings is None:
            for note in abjad.iterate(voice).by_leaf():
                self._hide_note_head(note)
            return

        WoodwindFingeringHandler._reset_cycle(
            self._fingering_patterns[current_stage]
        )

        # loop through logical ties
        i = 0
        for logical_tie in abjad.iterate(voice).by_logical_tie(pitched=True):
            # hide all note heads
            for chord in logical_tie:
                assert(isinstance(chord, abjad.Chord))
                for note_head in chord.note_heads:
                    note_head.tweak.stencil = \
                        abjad.schemetools.Scheme('point-stencil')

            # create glissando map (note index -> note index)
            fingering_index = self._cycle_next(
                self._fingering_patterns,
                current_stage
            )

            fingering = self._fingerings[current_stage][fingering_index]

            glissando_map = WoodwindFingeringHandler._make_glissando_map(
                fingering,
                voice.context_name
            )

            # attach glissando map and glissando command

            if glissando_map is not None:
                abjad.attach(glissando_map, logical_tie.head)

                # determine line style
                trill = self._cycle_next(self._trill_patterns, current_stage)
                if trill:
                    style = 'dashed-line'
                else:
                    style = None

                # attach lifelines
                self._attach_glissando(
                    logical_tie.head,
                    thickness=2,
                    style=style
                )

                # add gliss skip to non-first leaves
                if not logical_tie.is_trivial:
                    for leaf in logical_tie[1:]:
                        self._add_gliss_skip(leaf)
            i += 1

        # remove markups
        abjad.detach(abjad.Markup, voice)

        # get groups of non-rest leaves, attach final gliss anchor to last
        for note_group in self._get_consecutive_note_groups(voice):
            last = note_group[-1]
            self._hidden_grace_after(
                last,
                grace_note=abjad.Chord(last.note_heads, (1, 16))
            )
Пример #47
0
def nest_tuplets(
    time_signature_pairs,
    outer_tuplet_proportions,
    inner_tuplet_proportions,
    ):
    """
    Nests tuplets.

    Returns list of containers.

    Each container contains a single nested tuplet.
    """
    measure_count = len(time_signature_pairs)
    assert len(outer_tuplet_proportions) == measure_count
    assert not len(inner_tuplet_proportions) == measure_count

#    pairs = zip(time_signature_pairs, outer_tuplet_proportions)
#    for i, pair in enumerate(pairs):
#        tsp, otp = pair
#        print(i+1, tsp, otp)

    inner_tuplets_per_measure = [len(_) for _ in outer_tuplet_proportions]
    inner_tuplet_proportions_by_measure = baca.sequence(
        inner_tuplet_proportions).partition_by_counts(
        inner_tuplets_per_measure,
        )
    tuplet_maker = abjad.Tuplet.from_ratio_and_pair
    containers = []
    for measure_index in range(measure_count):
        time_signature_pair = time_signature_pairs[measure_index]
        outer_tuplet_proportion = outer_tuplet_proportions[measure_index]
        inner_tuplet_proportions = inner_tuplet_proportions_by_measure[
            measure_index]
        dummy_outer_tuplet = tuplet_maker(
            outer_tuplet_proportion,
            time_signature_pair,
            )
        inner_tuplet_durations = []
        for logical_tie in abjad.iterate(dummy_outer_tuplet).logical_ties():
            inner_tuplet_duration = logical_tie.written_duration
            inner_tuplet_durations.append(inner_tuplet_duration)
        pairs = enumerate(inner_tuplet_durations)
        inner_tuplets = []
        for inner_tuplet_index, inner_tuplet_duration in pairs:
            is_rest_filled = outer_tuplet_proportion[inner_tuplet_index] < 0
            if is_rest_filled:
                rest = abjad.Rest(inner_tuplet_duration)
                inner_tuplet = abjad.Tuplet((1, 1), [rest])
            else:
                inner_tuplet = tuplet_maker(
                    inner_tuplet_proportions[inner_tuplet_index],
                    inner_tuplet_duration.pair,
                    )
            assert isinstance(inner_tuplet, abjad.Tuplet), repr(inner_tuplet)
            inner_tuplets.append(inner_tuplet)
        duration = abjad.Duration(time_signature_pair)
        outer_tuplet = abjad.Tuplet.from_duration(duration, inner_tuplets)
        container = abjad.Container([outer_tuplet])
        containers.append(container)
    for leaf in abjad.iterate(containers).leaves():
        abjad.detach(abjad.TieIndicator, leaf)
        abjad.detach(abjad.RepeatTie, leaf)
    return containers
 def _set_pitch(pleaf, pitch):
     pleaf.written_pitch = pitch
     abjad.detach("not yet registered", pleaf)
Пример #49
0
 def _set_pitch(note, written_pitch):
     note.written_pitch = written_pitch
     abjad.detach('not yet registered', note)