Example #1
0
    def evaluate(self):
        r'''Evaluate timespan expression.

        Returns none when nonevaluable.

        Returns timespan when evaluable.
        '''
        from experimental.tools import musicexpressiontools
        result = self._evaluate_anchor_timespan()
        if result is None:
            return
        elif isinstance(result, timespantools.Timespan):
            timespan = self._apply_callbacks(result)
            expression = \
                musicexpressiontools.IterablePayloadExpression([timespan])
            return expression
        elif isinstance(result, list):
            timespan_expressions = []
            for timespan in result:
                timespan = self._apply_callbacks(timespan)
                expression = \
                    musicexpressiontools.IterablePayloadExpression([timespan])
                timespan_expressions.append(expression)
            assert len(result) == len(timespan_expressions)
            return timespan_expressions
        else:
            raise TypeError(result)
Example #2
0
    def evaluate(self):
        r'''Evaluate time signature set expression lookup expression.

        Returns payload expression.
        '''
        from experimental.tools import musicexpressiontools
        time_signatures = self.root_specification.time_signatures[:]
        expression = \
            musicexpressiontools.IterablePayloadExpression(time_signatures)
        expression = self._apply_callbacks(expression)
        return expression
Example #3
0
 def make_default_timespan_delimited_single_context_division_set_expression(
         self, target_timespan, voice_name):
     from experimental.tools import musicexpressiontools
     divisions = self.get_time_signature_slice(target_timespan)
     return musicexpressiontools.TimespanScopedSingleContextDivisionSetExpression(
         source_expression=musicexpressiontools.IterablePayloadExpression(
             divisions),
         target_timespan=target_timespan,
         scope_name=voice_name,
         fresh=True,
         truncate=True,
     )
Example #4
0
    def register_material(self, material):
        r'''Register `material`.

        Change tuple or list to payload expression.

        Change parseable string to start-positioned rhythm payload expression.
        '''
        from experimental.tools import musicexpressiontools
        if isinstance(material, (tuple, list)):
            return musicexpressiontools.IterablePayloadExpression(material)
        elif isinstance(material, (str)):
            component = topleveltools.parse(material)
            return musicexpressiontools.StartPositionedRhythmPayloadExpression(
                [component], start_offset=0)
        else:
            raise TypeError(material)
Example #5
0
 def _expr_to_expression(self, expr):
     from abjad.tools import rhythmmakertools
     from experimental.tools import musicexpressiontools
     if isinstance(expr, musicexpressiontools.Expression):
         return expr
     elif self._all_are_expressions(expr):
         return musicexpressiontools.ExpressionInventory(expr)
     elif isinstance(expr, (tuple, list, datastructuretools.TypedList)):
         return musicexpressiontools.IterablePayloadExpression(expr)
     elif isinstance(expr, (str)):
         component = topleveltools.parse(expr)
         return musicexpressiontools.StartPositionedRhythmPayloadExpression(
             [component], start_offset=0)
     elif isinstance(expr, rhythmmakertools.RhythmMaker):
         return musicexpressiontools.RhythmMakerExpression(expr)
     else:
         message = 'do not know how to change {!r} to expression.'
         raise TypeError(message.format(expr))
Example #6
0
    def evaluate_early(self):
        r'''Evaluate measure select expression early.

        Special definition because time signatures can be evaluated
        without knowing the timespan they occupy.

        Returns start-positioned division payload expression.
        '''
        from experimental.tools import musicexpressiontools
        time_signatures = self.root_specification.time_signatures[:]
        time_signatures = [durationtools.Division(x) for x in time_signatures]
        expression = \
            musicexpressiontools.IterablePayloadExpression(time_signatures)
        expression = self._apply_callbacks(expression)
        assert isinstance(
            expression,
            musicexpressiontools.IterablePayloadExpression)
        return expression
Example #7
0
    def evaluate(self):
        r'''Evaluate offset expression.

        Returns none when nonevaluable.

        Returns payload expression when evaluable.
        '''
        from experimental.tools import musicexpressiontools
        edge = self.edge or Left
        anchor_timespan = self._evaluate_anchor_timespan()
        if anchor_timespan is None:
            return
        if edge == Left:
            offset = anchor_timespan.start_offset
        else:
            offset = anchor_timespan.stop_offset
        offset = self._apply_callbacks(offset)
        expression = musicexpressiontools.IterablePayloadExpression([offset])
        return expression
Example #8
0
    def evaluate_against_score(self, score):
        r'''Evaluate counttime component select expression against `score`.

        Returns iterable payload expression.
        '''
        from experimental.tools import musicexpressiontools
        assert isinstance(score, scoretools.Score), repr(score)
        voice = score[self.voice_name]
        anchor_timespan = self._evaluate_anchor_timespan()
        # list signals the result of a call to map_to_each()
        if isinstance(anchor_timespan, list):
            is_map_to_each = True
        else:
            is_map_to_each = False
            anchor_timespan = [anchor_timespan]
        result = []
        anchor_timespans = anchor_timespan
        for anchor_timespan in anchor_timespans:
            time_relation = self._get_time_relation(anchor_timespan)
            voice_proxy = \
                self.score_specification.voice_data_structures_by_voice[
                    self.voice_name]
            start, stop = time_relation.get_offset_indices(
                voice_proxy.leaf_start_offsets, voice_proxy.leaf_stop_offsets)
            components = voice_proxy.leaves[start:stop]
            if not components:
                continue
            expression = \
                musicexpressiontools.IterablePayloadExpression(components)
            expression = self._apply_callbacks(expression)
            result.append(expression)
        if is_map_to_each:
            return result
        else:
            expression = result[0]
            return expression