def repeat_to_duration(self, duration):
        r'''Repeat payload expression to duration.

        ::

            >>> result = \
            ...     payload_expression.repeat_to_duration(Duration(13, 16))

        ::

            >>> print(format(result))
            musicexpressiontools.IterablePayloadExpression(
                payload=(
                    durationtools.Division(4, 16),
                    durationtools.Division(2, 16),
                    durationtools.Division(4, 16),
                    durationtools.Division(2, 16),
                    durationtools.Division(1, 16),
                    ),
                )

        Returns newly constructed payload expression.
        '''
        if not mathtools.all_are_numbers(self.payload):
            payload = [durationtools.Division(_) for _ in self.payload]
        else:
            payload = self.payload
        payload = sequencetools.repeat_sequence_to_weight(payload, duration)
        payload = [durationtools.Division(_) for _ in payload]
        result = new(self, payload=payload)
        return result
예제 #2
0
    def repeat_to_duration(self, duration):
        r'''Repeat payload expression to duration.

        ::

            >>> result = \
            ...     payload_expression.repeat_to_duration(Duration(13, 16))

        ::

            >>> print(format(result))
            musicexpressiontools.IterablePayloadExpression(
                payload=(
                    durationtools.Division(4, 16),
                    durationtools.Division(2, 16),
                    durationtools.Division(4, 16),
                    durationtools.Division(2, 16),
                    durationtools.Division(1, 16),
                    ),
                )

        Returns newly constructed payload expression.
        '''
        if not mathtools.all_are_numbers(self.payload):
            payload = [durationtools.Division(_) for _ in self.payload]
        else:
            payload = self.payload
        payload = sequencetools.repeat_sequence_to_weight(payload, duration)
        payload = [durationtools.Division(_) for _ in payload]
        result = new(self, payload=payload)
        return result
    def __and__(self, timespan):
        r'''Logical AND of payload expression and `timespan`.

        ::

            >>> timespan = timespantools.Timespan((1, 16), (5, 16))
            >>> result = payload_expression & timespan

        ::

            >>> print format(result)
            timespantools.TimespanInventory(
                [
                    musicexpressiontools.IterablePayloadExpression(
                        payload=(
                            musicexpressiontools.Division(
                                '[3, 16]',
                                start_offset=durationtools.Offset(1, 16),
                                ),
                            musicexpressiontools.Division(
                                '[1, 16]',
                                start_offset=durationtools.Offset(1, 4),
                                ),
                            ),
                        ),
                    ]
                )

        Returns newly constructed payload expression.
        '''
        from experimental.tools import musicexpressiontools
        if not mathtools.all_are_numbers(self.payload):
            payload = [mathtools.NonreducedFraction(x) for x in self.payload]
        else:
            payload = self.payload
        division_payload_expression = \
            musicexpressiontools.StartPositionedDivisionPayloadExpression(
            payload=payload, start_offset=0, voice_name='dummy voice name')
        result = division_payload_expression & timespan
        assert len(result) in (0, 1)
        if result:
            divisions = result[0].payload.divisions
            expression = new(self, payload=divisions)
            result[0] = expression
        return result
예제 #4
0
    def __and__(self, timespan):
        r'''Logical AND of payload expression and `timespan`.

        ::

            >>> timespan = timespantools.Timespan((1, 16), (5, 16))
            >>> result = payload_expression & timespan

        ::

            >>> print(format(result))
            timespantools.TimespanInventory(
                [
                    musicexpressiontools.IterablePayloadExpression(
                        payload=(
                            durationtools.Division(3, 16),
                            durationtools.Division(1, 16),
                            ),
                        ),
                    ]
                )

        Returns newly constructed payload expression.
        '''
        from experimental.tools import musicexpressiontools
        if not mathtools.all_are_numbers(self.payload):
            payload = [durationtools.Division(x) for x in self.payload]
        else:
            payload = self.payload
        division_payload_expression = \
            musicexpressiontools.StartPositionedDivisionPayloadExpression(
            payload=payload, start_offset=0, voice_name='dummy voice name')
        result = division_payload_expression & timespan
        assert len(result) in (0, 1)
        if result:
            divisions = result[0].payload.divisions
            expression = new(self, payload=divisions)
            result[0] = expression
        return result