QEventSequence

class quantizationtools.QEventSequence(sequence=None)

A well-formed sequence of q-events.

Contains only pitched q-events and silent q-events, and terminates with a single terminal q-event.

A q-event sequence is the primary input to the quantizer.

A q-event sequence provides a number of convenience functions to assist with instantiating new sequences:

>>> durations = (1000, -500, 1250, -500, 750)
>>> sequence = \
...     quantizationtools.QEventSequence.from_millisecond_durations(
...     durations)
>>> 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(1000, 1),
    )
quantizationtools.PitchedQEvent(
    offset=durationtools.Offset(1500, 1),
    pitches=(
        pitchtools.NamedPitch("c'"),
        ),
    )
quantizationtools.SilentQEvent(
    offset=durationtools.Offset(2750, 1),
    )
quantizationtools.PitchedQEvent(
    offset=durationtools.Offset(3250, 1),
    pitches=(
        pitchtools.NamedPitch("c'"),
        ),
    )
quantizationtools.TerminalQEvent(
    offset=durationtools.Offset(4000, 1),
    )

Lineage

digraph InheritanceGraph { graph [background=transparent, bgcolor=transparent, color=lightslategrey, fontname=Arial, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, root="__builtin__.object", splines=spline, style="dotted, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=12, penwidth=2, style="filled, rounded"]; edge [color=lightsteelblue2, penwidth=2]; subgraph cluster_abctools { graph [label=abctools]; "abjad.tools.abctools.AbjadObject.AbjadObject" [color=1, group=0, label=AbjadObject, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" [color=1, group=0, label=AbstractBase, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" -> "abjad.tools.abctools.AbjadObject.AbjadObject"; } subgraph cluster_quantizationtools { graph [label=quantizationtools]; "abjad.tools.quantizationtools.QEventSequence.QEventSequence" [color=black, fontcolor=white, group=2, label=<<B>QEventSequence</B>>, shape=box, style="filled, rounded"]; } subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=2, group=1, label=object, shape=box]; } "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.quantizationtools.QEventSequence.QEventSequence"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Bases

Attribute summary

duration_in_ms Duration in milliseconds of the QEventSequence:
from_millisecond_durations(milliseconds[, ...]) Convert a sequence of millisecond durations durations into
from_millisecond_offsets(offsets) Convert millisecond offsets offsets into a QEventSequence:
from_millisecond_pitch_pairs(pairs) Convert millisecond-duration:pitch pairs pairs into a
from_tempo_scaled_durations(durations[, tempo]) Convert durations, scaled by tempo
from_tempo_scaled_leaves(leaves[, tempo]) Convert leaves, optionally with tempo into a
sequence Sequence of q-events.
__contains__(argument) Is true when q-event sequence contains argument.
__eq__(argument) Is true when q-event sequence equals argument.
__format__([format_specification]) Formats q-event sequence.
__getitem__(argument) Gets item or slice identified by argument.
__hash__() Hashes q-event sequence.
__iter__() Iterates q-event sequence.
__len__() Length of q-event sequence.
__ne__(argument) Is true when Abjad object does not equal argument.
__repr__() Gets interpreter representation of Abjad object.

Read-only properties

QEventSequence.duration_in_ms

Duration in milliseconds of the QEventSequence:

>>> durations = (1000, -500, 1250, -500, 750)
>>> sequence = \
...     quantizationtools.QEventSequence.from_millisecond_durations(
...     durations)
>>> sequence.duration_in_ms
Duration(4000, 1)

Return Duration instance.

QEventSequence.sequence

Sequence of q-events.

>>> for q_event in sequence.sequence:
...     print(format(q_event, 'storage'))
...
quantizationtools.PitchedQEvent(
    offset=durationtools.Offset(0, 1),
    pitches=(
        pitchtools.NamedPitch("c'"),
        ),
    )
quantizationtools.SilentQEvent(
    offset=durationtools.Offset(1000, 1),
    )
quantizationtools.PitchedQEvent(
    offset=durationtools.Offset(1500, 1),
    pitches=(
        pitchtools.NamedPitch("c'"),
        ),
    )
quantizationtools.SilentQEvent(
    offset=durationtools.Offset(2750, 1),
    )
quantizationtools.PitchedQEvent(
    offset=durationtools.Offset(3250, 1),
    pitches=(
        pitchtools.NamedPitch("c'"),
        ),
    )
quantizationtools.TerminalQEvent(
    offset=durationtools.Offset(4000, 1),
    )

Returns tuple.

Class & static methods

classmethod QEventSequence.from_millisecond_durations(milliseconds, fuse_silences=False)

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.

classmethod QEventSequence.from_millisecond_offsets(offsets)

Convert millisecond offsets offsets into a QEventSequence:

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

Returns QEventSequence instance.

classmethod QEventSequence.from_millisecond_pitch_pairs(pairs)

Convert millisecond-duration:pitch pairs pairs into a QEventSequence:

>>> durations = [250, 500, 1000, 1250, 1000]
>>> pitches = [(0,), None, (2, 3), None, (1,)]
>>> pairs = tuple(zip(durations, pitches))
>>> sequence = \
...     quantizationtools.QEventSequence.from_millisecond_pitch_pairs(
...     pairs)
>>> 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(250, 1),
    )
quantizationtools.PitchedQEvent(
    offset=durationtools.Offset(750, 1),
    pitches=(
        pitchtools.NamedPitch("d'"),
        pitchtools.NamedPitch("ef'"),
        ),
    )
quantizationtools.SilentQEvent(
    offset=durationtools.Offset(1750, 1),
    )
quantizationtools.PitchedQEvent(
    offset=durationtools.Offset(3000, 1),
    pitches=(
        pitchtools.NamedPitch("cs'"),
        ),
    )
quantizationtools.TerminalQEvent(
    offset=durationtools.Offset(4000, 1),
    )

Returns QEventSequence instance.

classmethod QEventSequence.from_tempo_scaled_durations(durations, tempo=None)

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.

classmethod QEventSequence.from_tempo_scaled_leaves(leaves, tempo=None)

Convert leaves, optionally with tempo into a QEventSequence:

>>> staff = Staff("c'4 <d' fs'>8. r16 gqs'2")
>>> tempo = Tempo((1, 4), 72)
>>> sequence = \
...     quantizationtools.QEventSequence.from_tempo_scaled_leaves(
...     staff[:], tempo=tempo)
>>> for q_event in sequence:
...     print(format(q_event, 'storage'))
...
quantizationtools.PitchedQEvent(
    offset=durationtools.Offset(0, 1),
    pitches=(
        pitchtools.NamedPitch("c'"),
        ),
    )
quantizationtools.PitchedQEvent(
    offset=durationtools.Offset(2500, 3),
    pitches=(
        pitchtools.NamedPitch("d'"),
        pitchtools.NamedPitch("fs'"),
        ),
    )
quantizationtools.SilentQEvent(
    offset=durationtools.Offset(4375, 3),
    )
quantizationtools.PitchedQEvent(
    offset=durationtools.Offset(5000, 3),
    pitches=(
        pitchtools.NamedPitch("gqs'"),
        ),
    )
quantizationtools.TerminalQEvent(
    offset=durationtools.Offset(10000, 3),
    )

If tempo is None, all leaves in leaves must have an effective, non-imprecise tempo. The millisecond-duration of each leaf will be determined by its effective tempo.

Return QEventSequence instance.

Special methods

QEventSequence.__contains__(argument)

Is true when q-event sequence contains argument. Otherwise false.

Returns true or false.

QEventSequence.__eq__(argument)

Is true when q-event sequence equals argument. Otherwise false.

Returns true or false.

QEventSequence.__format__(format_specification='')

Formats q-event sequence.

Set format_specification to ‘’ or ‘storage’. Interprets ‘’ equal to ‘storage’.

>>> print(format(sequence))
quantizationtools.QEventSequence(
    (
        quantizationtools.PitchedQEvent(
            offset=durationtools.Offset(0, 1),
            pitches=(
                pitchtools.NamedPitch("c'"),
                ),
            ),
        quantizationtools.SilentQEvent(
            offset=durationtools.Offset(1000, 1),
            ),
        quantizationtools.PitchedQEvent(
            offset=durationtools.Offset(1500, 1),
            pitches=(
                pitchtools.NamedPitch("c'"),
                ),
            ),
        quantizationtools.SilentQEvent(
            offset=durationtools.Offset(2750, 1),
            ),
        quantizationtools.PitchedQEvent(
            offset=durationtools.Offset(3250, 1),
            pitches=(
                pitchtools.NamedPitch("c'"),
                ),
            ),
        quantizationtools.TerminalQEvent(
            offset=durationtools.Offset(4000, 1),
            ),
        )
    )

Returns string.

QEventSequence.__getitem__(argument)

Gets item or slice identified by argument.

Returns item or slice.

QEventSequence.__hash__()

Hashes q-event sequence.

Required to be explicitly redefined on Python 3 if __eq__ changes.

Returns integer.

QEventSequence.__iter__()

Iterates q-event sequence.

Yields items.

QEventSequence.__len__()

Length of q-event sequence.

Returns nonnegative integer.

(AbjadObject).__ne__(argument)

Is true when Abjad object does not equal argument. Otherwise false.

Returns true or false.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.