コード例 #1
0
    def from_tempo_scaled_durations(cls, durations, tempo=None):
        r'''Convert ``durations``, scaled by ``tempo``
        into a ``QEventSequence``:

        ::

            >>> tempo = Tempo((1, 4), 174)
            >>> durations = [(1, 4), (-3, 16), (1, 16), (-1, 2)]

        ::

            >>> sequence = \
            ...     quantizationtools.QEventSequence.from_tempo_scaled_durations(
            ...     durations, tempo=tempo)

        ::

            >>> for q_event in sequence:
            ...     print(format(q_event, 'storage'))
            ...
            quantizationtools.PitchedQEvent(
                offset=durationtools.Offset(0, 1),
                pitches=(
                    pitchtools.NamedPitch("c'"),
                    ),
                )
            quantizationtools.SilentQEvent(
                offset=durationtools.Offset(10000, 29),
                )
            quantizationtools.PitchedQEvent(
                offset=durationtools.Offset(17500, 29),
                pitches=(
                    pitchtools.NamedPitch("c'"),
                    ),
                )
            quantizationtools.SilentQEvent(
                offset=durationtools.Offset(20000, 29),
                )
            quantizationtools.TerminalQEvent(
                offset=durationtools.Offset(40000, 29),
                )

        Returns ``QEventSequence`` instance.
        '''
        from abjad.tools import quantizationtools
        durations = [durationtools.Duration(x) for x in durations]
        assert isinstance(tempo, indicatortools.Tempo)
        durations = [
            x for x in sequencetools.sum_consecutive_elements_by_sign(
                durations,
                sign=[-1],
            ) if x
        ]
        durations = [tempo.duration_to_milliseconds(x) for x in durations]
        offsets = mathtools.cumulative_sums(abs(x) for x in durations)
        q_events = []
        for pair in zip(offsets, durations):
            offset = durationtools.Offset(pair[0])
            duration = pair[1]
            if duration < 0:  # negative duration indicates silence
                q_event = quantizationtools.SilentQEvent(offset)
            else:  # otherwise, use middle-C
                q_event = quantizationtools.PitchedQEvent(offset, [0])
            q_events.append(q_event)
        # insert terminating silence QEvent
        q_events.append(quantizationtools.TerminalQEvent(offsets[-1]))
        return cls(q_events)
コード例 #2
0
ファイル: QEventSequence.py プロジェクト: DnMllr/abjad
    def from_tempo_scaled_durations(cls, durations, tempo=None):
        r'''Convert ``durations``, scaled by ``tempo``
        into a ``QEventSequence``:

        ::

            >>> tempo = Tempo((1, 4), 174)
            >>> durations = [(1, 4), (-3, 16), (1, 16), (-1, 2)]

        ::

            >>> sequence = \
            ...     quantizationtools.QEventSequence.from_tempo_scaled_durations(
            ...     durations, tempo=tempo)

        ::

            >>> for q_event in sequence:
            ...     print(format(q_event, 'storage'))
            ... 
            quantizationtools.PitchedQEvent(
                offset=durationtools.Offset(0, 1),
                pitches=(
                    pitchtools.NamedPitch("c'"),
                    ),
                )
            quantizationtools.SilentQEvent(
                offset=durationtools.Offset(10000, 29),
                )
            quantizationtools.PitchedQEvent(
                offset=durationtools.Offset(17500, 29),
                pitches=(
                    pitchtools.NamedPitch("c'"),
                    ),
                )
            quantizationtools.SilentQEvent(
                offset=durationtools.Offset(20000, 29),
                )
            quantizationtools.TerminalQEvent(
                offset=durationtools.Offset(40000, 29),
                )

        Returns ``QEventSequence`` instance.
        '''
        from abjad.tools import quantizationtools
        durations = [durationtools.Duration(x) for x in durations]
        assert isinstance(tempo, indicatortools.Tempo)
        durations = [x for x in
            sequencetools.sum_consecutive_elements_by_sign(
                durations,
                sign=[-1],
                ) if x]
        durations = [tempo.duration_to_milliseconds(x) for x in durations]
        offsets = mathtools.cumulative_sums(abs(x) for x in durations)
        q_events = []
        for pair in zip(offsets, durations):
            offset = durationtools.Offset(pair[0])
            duration = pair[1]
            if duration < 0: # negative duration indicates silence
                q_event = quantizationtools.SilentQEvent(offset)
            else: # otherwise, use middle-C
                q_event = quantizationtools.PitchedQEvent(offset, [0])
            q_events.append(q_event)
        # insert terminating silence QEvent
        q_events.append(quantizationtools.TerminalQEvent(offsets[-1]))
        return cls(q_events)
コード例 #3
0
    def from_millisecond_durations(cls, milliseconds, fuse_silences=False):
        r'''Convert a sequence of millisecond durations ``durations`` into
        a ``QEventSequence``:

        ::

            >>> durations = [-250, 500, -1000, 1250, -1000]

        ::

            >>> sequence = \
            ...     quantizationtools.QEventSequence.from_millisecond_durations(
            ...     durations)

        ::

            >>> for q_event in sequence:
            ...     print(format(q_event, 'storage'))
            ...
            quantizationtools.SilentQEvent(
                offset=durationtools.Offset(0, 1),
                )
            quantizationtools.PitchedQEvent(
                offset=durationtools.Offset(250, 1),
                pitches=(
                    pitchtools.NamedPitch("c'"),
                    ),
                )
            quantizationtools.SilentQEvent(
                offset=durationtools.Offset(750, 1),
                )
            quantizationtools.PitchedQEvent(
                offset=durationtools.Offset(1750, 1),
                pitches=(
                    pitchtools.NamedPitch("c'"),
                    ),
                )
            quantizationtools.SilentQEvent(
                offset=durationtools.Offset(3000, 1),
                )
            quantizationtools.TerminalQEvent(
                offset=durationtools.Offset(4000, 1),
                )

        Returns ``QEventSequence`` instance.
        '''
        from abjad.tools import quantizationtools
        if fuse_silences:
            durations = [x for x in \
                sequencetools.sum_consecutive_elements_by_sign(
                    milliseconds, sign=[-1]) if x]
        else:
            durations = milliseconds
        offsets = mathtools.cumulative_sums([abs(x) for x in durations])
        q_events = []
        for pair in zip(offsets, durations):
            offset = durationtools.Offset(pair[0])
            duration = pair[1]
            if duration < 0:  # negative duration indicates silence
                q_event = quantizationtools.SilentQEvent(offset)
            else:
                q_event = quantizationtools.PitchedQEvent(offset, [0])
            q_events.append(q_event)
        q_events.append(
            quantizationtools.TerminalQEvent(durationtools.Offset(
                offsets[-1])))
        return cls(q_events)
コード例 #4
0
ファイル: QEventSequence.py プロジェクト: DnMllr/abjad
    def from_millisecond_durations(cls, milliseconds, fuse_silences=False):
        r'''Convert a sequence of millisecond durations ``durations`` into
        a ``QEventSequence``:

        ::

            >>> durations = [-250, 500, -1000, 1250, -1000]

        ::

            >>> sequence = \
            ...     quantizationtools.QEventSequence.from_millisecond_durations(
            ...     durations)

        ::

            >>> for q_event in sequence:
            ...     print(format(q_event, 'storage'))
            ... 
            quantizationtools.SilentQEvent(
                offset=durationtools.Offset(0, 1),
                )
            quantizationtools.PitchedQEvent(
                offset=durationtools.Offset(250, 1),
                pitches=(
                    pitchtools.NamedPitch("c'"),
                    ),
                )
            quantizationtools.SilentQEvent(
                offset=durationtools.Offset(750, 1),
                )
            quantizationtools.PitchedQEvent(
                offset=durationtools.Offset(1750, 1),
                pitches=(
                    pitchtools.NamedPitch("c'"),
                    ),
                )
            quantizationtools.SilentQEvent(
                offset=durationtools.Offset(3000, 1),
                )
            quantizationtools.TerminalQEvent(
                offset=durationtools.Offset(4000, 1),
                )

        Returns ``QEventSequence`` instance.
        '''
        from abjad.tools import quantizationtools
        if fuse_silences:
            durations = [x for x in \
                sequencetools.sum_consecutive_elements_by_sign(
                    milliseconds, sign=[-1]) if x]
        else:
            durations = milliseconds
        offsets = mathtools.cumulative_sums([abs(x) for x in durations])
        q_events = []
        for pair in zip(offsets, durations):
            offset = durationtools.Offset(pair[0])
            duration = pair[1]
            if duration < 0: # negative duration indicates silence
                q_event = quantizationtools.SilentQEvent(offset)
            else:
                q_event = quantizationtools.PitchedQEvent(offset, [0])
            q_events.append(q_event)
        q_events.append(quantizationtools.TerminalQEvent(
            durationtools.Offset(offsets[-1])))
        return cls(q_events)