Beispiel #1
0
 def skip(self, duration):
     r"""
     Handles LilyPond ``\skip`` command.
     """
     leaf = core.Skip(duration.duration)
     if duration.multiplier is not None:
         attach(duration.multiplier, leaf)
     return leaf
Beispiel #2
0
 def p_leaf__leaf_body__post_events(self, p):
     """
     leaf : leaf_body post_events
     """
     p[0] = p[1]
     if p[2]:
         annotation = {'post events': p[2]}
         attach(annotation, p[0])
Beispiel #3
0
 def skip(self, duration):
     r"""
     Handles LilyPond ``\skip`` command.
     """
     leaf = core.Skip(duration.duration)
     if duration.multiplier is not None:
         attach(duration.multiplier, leaf)
     return leaf
Beispiel #4
0
 def p_leaf__leaf_body__post_events(self, p):
     """
     leaf : leaf_body post_events
     """
     p[0] = p[1]
     if p[2]:
         annotation = {"post events": p[2]}
         attach(annotation, p[0])
Beispiel #5
0
 def p_measure__PIPE__FRACTION__component_list__PIPE(self, p):
     """
     measure : PIPE FRACTION component_list PIPE
     """
     measure = core.Container()
     for x in p[3]:
         measure.append(x)
     leaf = inspect(measure).leaf(0)
     time_signature = indicators.TimeSignature(p[2].pair)
     attach(time_signature, leaf)
     p[0] = measure
Beispiel #6
0
 def p_measure__PIPE__FRACTION__component_list__PIPE(self, p):
     """
     measure : PIPE FRACTION component_list PIPE
     """
     measure = core.Container()
     for x in p[3]:
         measure.append(x)
     leaf = inspect(measure).leaf(0)
     time_signature = indicators.TimeSignature(p[2].pair)
     attach(time_signature, leaf)
     p[0] = measure
Beispiel #7
0
 def _attach_indicators(self, leaves):
     for leaf in leaves:
         span_events = self._get_span_events(leaf)
         for current_class, directions in span_events.items():
             if current_class in (indicators.StartSlur,
                                  indicators.StopSlur):
                 indicator = current_class()
                 attach(indicator, leaf)
                 continue
             if current_class in (indicators.StartBeam,
                                  indicators.StopBeam):
                 indicator = current_class()
                 attach(indicator, leaf)
                 continue
             if current_class is indicators.TieIndicator:
                 indicator = current_class()
                 attach(indicator, leaf)
                 continue
Beispiel #8
0
 def _attach_indicators(self, leaves):
     for leaf in leaves:
         span_events = self._get_span_events(leaf)
         for current_class, directions in span_events.items():
             if current_class in (
                 indicators.StartSlur,
                 indicators.StopSlur,
             ):
                 indicator = current_class()
                 attach(indicator, leaf)
                 continue
             if current_class in (
                 indicators.StartBeam,
                 indicators.StopBeam,
             ):
                 indicator = current_class()
                 attach(indicator, leaf)
                 continue
             if current_class is indicators.TieIndicator:
                 indicator = current_class()
                 attach(indicator, leaf)
                 continue
Beispiel #9
0
 def _make_unrelativable(self, music):
     if not self._is_unrelativable(music):
         annotation = {"UnrelativableMusic": True}
         attach(annotation, music)
Beispiel #10
0
    def _apply_spanners(self, leaves):
        import abjad

        spanner_references = {
            abjad.Beam: None,
            abjad.Slur: None,
        }

        first_leaf = leaves[0]
        pairs = abjad.sequence(leaves).nwise(wrapped=True)
        for leaf, next_leaf in pairs:
            span_events = self._get_span_events(leaf)
            for current_class, directions in span_events.items():
                starting, stopping = [], []
                for direction in directions:
                    if direction is Left:
                        starting.append(Left)
                    else:
                        stopping.append(Right)

                # apply undirected events immediately,
                # and do not maintain a reference to them
                if current_class is abjad.Tie:
                    if next_leaf is first_leaf:
                        message = 'unterminated {} at {}.'
                        message = message.format(current_class.__name__, leaf)
                        raise Exception(message)
                    previous_tie = [
                        x for x in leaf._get_spanners()
                        if isinstance(x, abjad.Tie)
                    ]
                    if previous_tie:
                        previous_tie[0]._append(next_leaf)
                    else:
                        tie = abjad.Tie()
                        selection = abjad.select([leaf, next_leaf])
                        attach(tie, selection)

                elif current_class is abjad.Beam:
                    # A beam may begin and end on the same leaf
                    # but only one beam spanner may cover any given leaf,
                    # and starting events are processed before ending ones
                    for _ in starting:
                        if spanner_references[current_class] is not None:
                            message = 'already have beam.'
                            raise Exception(message)
                        else:
                            spanner_references[current_class] = current_class()
                    for _ in stopping:
                        if spanner_references[current_class] is not None:
                            spanner_references[current_class]._append(leaf)
                            spanner_references[current_class] = None

                elif current_class is spanners.Slur:
                    # Slurs process stop events before start events,
                    # they must contain more than one leaf,
                    # but they can stop on a leaf and start on the same leaf.
                    for _ in stopping:
                        if spanner_references[current_class] is not None:
                            spanner_references[current_class]._append(leaf)
                            spanner_references[current_class] = None
                        else:
                            message = 'can not end: {}.'
                            message = message.format(current_class.__name)
                            raise Exception(message)
                    for _ in starting:
                        if spanner_references[current_class] is None:
                            spanner_references[current_class] = current_class()
                        else:
                            message = 'already have: {}.'
                            message = message.format(current_class.__name)
                            raise Exception(message)

            # append leaf to all tracked spanners,
            for current_class, instance in spanner_references.items():
                if instance is not None:
                    instance._append(leaf)

        # check for unterminated spanners
        for current_class, instance in spanner_references.items():
            if instance is not None:
                message = 'unterminated {}.'
                message = message.format(current_class.__name__)
                raise Exception(message)
Beispiel #11
0
 def _make_unrelativable(self, music):
     if not self._is_unrelativable(music):
         annotation = {"UnrelativableMusic": True}
         attach(annotation, music)