Quantizer

class quantizationtools.Quantizer

Quantizer.

>>> import abjad
>>> from abjad.tools import quantizationtools

Quantizes sequences of attack-points, encapsulated by QEventSequences, into score trees.

>>> quantizer = quantizationtools.Quantizer()
>>> durations = [1000] * 8
>>> pitches = range(8)
>>> q_event_sequence = \
...     quantizationtools.QEventSequence.from_millisecond_pitch_pairs(
...     tuple(zip(durations, pitches)))

Quantization defaults to outputting into a 4/4, quarter=60 musical structure:

>>> result = quantizer(q_event_sequence)
>>> staff = abjad.Staff([result])
>>> score = abjad.Score([staff])
>>> show(score) 

However, the behavior of the Quantizer can be modified at call-time. Passing a QSchema instance will alter the macro-structure of the output.

Here, we quantize using settings specified by a MeasurewiseQSchema, which will cause the Quantizer to group the output into measures with different tempi and time signatures:

>>> measurewise_q_schema = quantizationtools.MeasurewiseQSchema(
...     {'tempo': ((1, 4), 78), 'time_signature': (2, 4)},
...     {'tempo': ((1, 8), 57), 'time_signature': (5, 4)},
...     )
>>> result = quantizer(
...     q_event_sequence,
...     q_schema=measurewise_q_schema,
...     )
>>> staff = abjad.Staff([result])
>>> score = abjad.Score([staff])
>>> show(score) 

Here we quantize using settings specified by a BeatwiseQSchema, which keeps the output of the quantizer “flattened”, without measures or explicit time signatures. The default beat-wise settings of quarter=60 persists until the third “beatspan”:

>>> beatwise_q_schema = quantizationtools.BeatwiseQSchema(
... {
...     2: {'tempo': ((1, 4), 120)},
...     5: {'tempo': ((1, 4), 90)},
...     7: {'tempo': ((1, 4), 30)},
... })
>>> result = quantizer(
...     q_event_sequence,
...     q_schema=beatwise_q_schema,
...     )
>>> staff = abjad.Staff([result])
>>> score = abjad.Score([staff])
>>> show(score) 

Note that TieChains are generally fused together in the above example, but break at tempo changes.

Other keyword arguments are:

  • grace_handler: a GraceHandler instance controls whether and how grace notes are used in the output. Options currently include CollapsingGraceHandler, ConcatenatingGraceHandler and DiscardingGraceHandler.
  • heuristic: a Heuristic instance controls how output rhythms are selected from a pool of candidates. Options currently include the DistanceHeuristic class.
  • job_handler: a JobHandler instance controls whether or not parallel processing is used during the quantization process. Options include the SerialJobHandler and ParallelJobHandler classes.
  • attack_point_optimizer: an AttackPointOptimizer instance controls whether and how logical ties are re-notated. Options currently include MeasurewiseAttackPointOptimizer, NaiveAttackPointOptimizer and NullAttackPointOptimizer.

Refer to the reference pages for BeatwiseQSchema and MeasurewiseQSchema for more information on controlling the Quantizer’s output, and to the reference on SearchTree for information on controlling the rhythmic complexity of that same output.

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.Quantizer.Quantizer" [color=black, fontcolor=white, group=2, label=<<B>Quantizer</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.Quantizer.Quantizer"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Bases

Attribute summary

__call__(q_event_sequence[, q_schema, …]) Calls quantizer.
__eq__(argument) Is true when ID of argument equals ID of Abjad object.
__format__([format_specification]) Formats Abjad object.
__hash__() Hashes Abjad object.
__ne__(argument) Is true when Abjad object does not equal argument.
__repr__() Gets interpreter representation of Abjad object.

Special methods

Quantizer.__call__(q_event_sequence, q_schema=None, grace_handler=None, heuristic=None, job_handler=None, attack_point_optimizer=None, attach_tempos=True)

Calls quantizer.

Returns Abjad components.

(AbjadObject).__eq__(argument)

Is true when ID of argument equals ID of Abjad object. Otherwise false.

Returns true or false.

(AbjadObject).__format__(format_specification='')

Formats Abjad object.

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

Returns string.

(AbjadObject).__hash__()

Hashes Abjad object.

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

Returns 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.