def __call__(self, argument):
        r'''Calls naive attack-point optimizer.

        Returns none.
        '''
        import abjad
        for logical_tie in abjad.iterate(argument).logical_ties(
                grace_notes=False,
                reverse=True,
        ):
            sub_logical_ties = []
            current_sub_logical_tie = []
            for leaf in logical_tie:
                tempos = leaf._get_indicators(abjad.MetronomeMark)
                if tempos:
                    if current_sub_logical_tie:
                        current_sub_logical_tie = abjad.LogicalTie(
                            current_sub_logical_tie)
                        sub_logical_ties.append(current_sub_logical_tie)
                    current_sub_logical_tie = []
                current_sub_logical_tie.append(leaf)
            if current_sub_logical_tie:
                current_sub_logical_tie = abjad.LogicalTie(
                    current_sub_logical_tie)
                sub_logical_ties.append(current_sub_logical_tie)
            for sub_logical_tie in sub_logical_ties:
                sub_logical_tie._fuse_leaves_by_immediate_parent()
Пример #2
0
 def _get_logical_tie(self):
     import abjad
     for component in [self]:
         ties = inspect(component).spanners(abjad.Tie)
         if len(ties) == 1:
             tie = ties.pop()
             return abjad.LogicalTie(items=tie.leaves)
         elif 1 < len(ties):
             message = f'parentage of {self!r} contains {len(ties)} ties.'
             raise Exception(ties)
     else:
         return abjad.LogicalTie(items=self)
Пример #3
0
 def _get_logical_tie(self):
     import abjad
     for component in abjad.inspect(self).get_parentage():
         tie_spanners = abjad.inspect(component).get_spanners(abjad.Tie)
         if len(tie_spanners) == 1:
             tie_spanner = tie_spanners.pop()
             return abjad.LogicalTie(items=tie_spanner.leaves)
         elif 1 < len(tie_spanners):
             message = 'parentage of {!r} contains {} tie spanners.'
             message = message.format(self, len(tie_spanners))
             raise Exception(message)
     else:
         return abjad.LogicalTie(items=self)
Пример #4
0
 def __call__(self, argument):
     """
     Calls naive attack-point optimizer.
     """
     for logical_tie in abjad.iterate.logical_ties(
         argument, grace=False, reverse=True
     ):
         sub_logical_ties = []
         current_sub_logical_tie = []
         for leaf in logical_tie:
             tempos = leaf._get_indicators(abjad.MetronomeMark)
             if tempos:
                 if current_sub_logical_tie:
                     current_sub_logical_tie = abjad.LogicalTie(
                         current_sub_logical_tie
                     )
                     sub_logical_ties.append(current_sub_logical_tie)
                 current_sub_logical_tie = []
             current_sub_logical_tie.append(leaf)
         if current_sub_logical_tie:
             current_sub_logical_tie = abjad.LogicalTie(current_sub_logical_tie)
             sub_logical_ties.append(current_sub_logical_tie)
         for sub_logical_tie in sub_logical_ties:
             abjad.mutate._fuse_leaves_by_immediate_parent(sub_logical_tie)
Пример #5
0
#
# DEMO 3#
staff = abjad.Staff("c'4 c'4 c'4 r4 c'4 c'4 r8 c'8 c'4 r1")
selections = abjad.Selection(staff[:])
handler = DynamicHandler(
    dynamic_list=["f", "mp", "p", "mf", "ff"],
    flare_boolean_vector=[1, 0, 0, 1],
    flare_forget=False,
    forget=False,
    name="dynamic_handler_one",
)
for run in abjad.Selection(selections).runs():
    ties = abjad.Selection(run).logical_ties()
    maker = AddSpannerAnchor(leaf=ties[-1][-1],
                             anchor_dur=abjad.Duration(1, 16))
    maker.add_spanner_anchor()
    new_ties = ties + abjad.Selection(
        [abjad.LogicalTie(items=maker.calc_anchor()[-1])])
    print("NEW TIES")
    print(new_ties)
    print("TIE 0")
    print(new_ties[0])
    print("TIE -1")
    print(new_ties[-1])
    handler(new_ties)
print(abjad.lilypond(staff))

# WHY DOES THE SPANNER ANCHOR ONLY EXIST AS A NOTE WITH NO LOGICAL TIE?
# WHY DOES ABJAD NOT RECOGNIZE THAT THE ANCHOR IS IN THE SELECTION?
# MULTIPLIERS DISAPPEAR AFTER abjad.show()
Пример #6
0
    def iterate_rewrite_inputs(argument):
        r'''Iterates topmost masked logical ties, rest groups and containers
        in `argument`, masked by `argument`.

        >>> string = "abj: ! 2/4 c'4 d'4 ~ !"
        >>> string += "! 4/4 d'8. r16 r8. e'16 ~ "
        >>> string += "2/3 { e'8 ~ e'8 f'8 ~ } f'4 ~ !"
        >>> string += "! 4/4 f'8 g'8 ~ g'4 a'4 ~ a'8 b'8 ~ !"
        >>> string += "! 2/4 b'4 c''4 !"
        >>> string = string.replace('!', '|')
        >>> staff = abjad.Staff(string)

        ..  docs::

            >>> abjad.f(staff)
            \new Staff
            {
                {   % measure
                    \time 2/4
                    c'4
                    d'4
                    ~
                }   % measure
                {   % measure
                    \time 4/4
                    d'8.
                    r16
                    r8.
                    e'16
                    ~
                    \times 2/3 {
                        e'8
                        ~
                        e'8
                        f'8
                        ~
                    }
                    f'4
                    ~
                }   % measure
                {   % measure
                    f'8
                    g'8
                    ~
                    g'4
                    a'4
                    ~
                    a'8
                    b'8
                    ~
                }   % measure
                {   % measure
                    \time 2/4
                    b'4
                    c''4
                }   % measure
            }

        >>> for x in abjad.MeterManager.iterate_rewrite_inputs(
        ...     staff[0]): x
        ...
        LogicalTie([Note("c'4")])
        LogicalTie([Note("d'4")])

        >>> for x in abjad.MeterManager.iterate_rewrite_inputs(
        ...     staff[1]): x
        ...
        LogicalTie([Note("d'8.")])
        LogicalTie([Rest('r16'), Rest('r8.')])
        LogicalTie([Note("e'16")])
        Tuplet(Multiplier(2, 3), "e'8 ~ e'8 f'8 ~")
        LogicalTie([Note("f'4")])

        >>> for x in abjad.MeterManager.iterate_rewrite_inputs(
        ...     staff[2]): x
        ...
        LogicalTie([Note("f'8")])
        LogicalTie([Note("g'8"), Note("g'4")])
        LogicalTie([Note("a'4"), Note("a'8")])
        LogicalTie([Note("b'8")])

        >>> for x in abjad.MeterManager.iterate_rewrite_inputs(
        ...     staff[3]): x
        ...
        LogicalTie([Note("b'4")])
        LogicalTie([Note("c''4")])

        Returns generator.
        '''
        import abjad
        last_tie_spanner = None
        current_leaf_group = None
        current_leaf_group_is_silent = False
        for x in argument:
            if isinstance(x, (abjad.Note, abjad.Chord)):
                this_tie_spanner = x._get_spanners(abjad.Tie) or None
                if current_leaf_group is None:
                    current_leaf_group = []
                elif (current_leaf_group_is_silent or this_tie_spanner is None
                      or last_tie_spanner != this_tie_spanner):
                    yield abjad.LogicalTie(current_leaf_group)
                    current_leaf_group = []
                current_leaf_group_is_silent = False
                current_leaf_group.append(x)
                last_tie_spanner = this_tie_spanner
            elif isinstance(x, (abjad.Rest, abjad.Skip)):
                if current_leaf_group is None:
                    current_leaf_group = []
                elif not current_leaf_group_is_silent:
                    yield abjad.LogicalTie(current_leaf_group)
                    current_leaf_group = []
                current_leaf_group_is_silent = True
                current_leaf_group.append(x)
                last_tie_spanner = None
            elif isinstance(x, abjad.Container):
                if current_leaf_group is not None:
                    yield abjad.LogicalTie(current_leaf_group)
                    current_leaf_group = None
                    last_tie_spanner = None
                yield x

            else:
                message = 'unhandled component: {!r}.'
                message = message.format(x)
                raise Exception(message)
        if current_leaf_group is not None:
            yield abjad.LogicalTie(current_leaf_group)