gracehandlers

digraph InheritanceGraph { graph [bgcolor=transparent, color=lightsteelblue2, fontname=Arial, fontsize=10, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, splines=spline, style="dashed, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=10, height=0, penwidth=2, shape=box, style="filled, rounded", width=0]; edge [color=lightslategrey, penwidth=1]; subgraph cluster_abc { graph [label=abc]; node [color=1]; "abc.ABC" [URL="https://docs.python.org/3.10/library/abc.html#abc.ABC", label=ABC, target=_top]; } subgraph "cluster_abjadext.nauert.gracehandlers" { graph [label="abjadext.nauert.gracehandlers"]; node [color=2]; "abjadext.nauert.gracehandlers.CollapsingGraceHandler" [URL="../api/abjadext/nauert/gracehandlers.html#abjadext.nauert.gracehandlers.CollapsingGraceHandler", color=black, fontcolor=white, label="Collapsing\nGrace\nHandler", target=_top]; "abjadext.nauert.gracehandlers.ConcatenatingGraceHandler" [URL="../api/abjadext/nauert/gracehandlers.html#abjadext.nauert.gracehandlers.ConcatenatingGraceHandler", color=black, fontcolor=white, label="Concatenating\nGrace\nHandler", target=_top]; "abjadext.nauert.gracehandlers.DiscardingGraceHandler" [URL="../api/abjadext/nauert/gracehandlers.html#abjadext.nauert.gracehandlers.DiscardingGraceHandler", color=black, fontcolor=white, label="Discarding\nGrace\nHandler", target=_top]; "abjadext.nauert.gracehandlers.GraceHandler" [URL="../api/abjadext/nauert/gracehandlers.html#abjadext.nauert.gracehandlers.GraceHandler", color=black, fontcolor=white, label="Grace\nHandler", shape=oval, style="bold, filled", target=_top]; "abjadext.nauert.gracehandlers.GraceHandler" -> "abjadext.nauert.gracehandlers.CollapsingGraceHandler"; "abjadext.nauert.gracehandlers.GraceHandler" -> "abjadext.nauert.gracehandlers.ConcatenatingGraceHandler"; "abjadext.nauert.gracehandlers.GraceHandler" -> "abjadext.nauert.gracehandlers.DiscardingGraceHandler"; } subgraph cluster_builtins { graph [label=builtins]; node [color=3]; "builtins.object" [URL="https://docs.python.org/3.10/library/functions.html#object", label=object, target=_top]; } "abc.ABC" -> "abjadext.nauert.gracehandlers.GraceHandler"; "builtins.object" -> "abc.ABC"; }


Abstract Classes

GraceHandler

Abstract grace-handler.

abstract class abjadext.nauert.gracehandlers.GraceHandler[source]

Abstract grace-handler.

Determines what pitch, if any, will be selected from a list of QEvents to be applied to an attack-point generated by a QGrid, and whether there should be a BeforeGraceContainer attached to that attack-point.

When called on a sequence of QEvents, GraceHandler subclasses should return a pair, where the first item of the pair is a sequence of pitch tokens or None, and where the second item of the pair is a BeforeGraceContainer instance or None.


Attributes Summary

__call__

Calls grace handler.


Special methods

overridden abstract __call__(q_events)[source]

Calls grace handler.

Return type:

tuple[tuple[NamedPitch, ...], Optional[tuple], Optional[BeforeGraceContainer]]


Classes

CollapsingGraceHandler

Collapsing grace-handler.

ConcatenatingGraceHandler

Concatenating grace-handler.

DiscardingGraceHandler

Discarding grace-handler.

class abjadext.nauert.gracehandlers.CollapsingGraceHandler[source]

Collapsing grace-handler.

Collapses pitch information into a single chord rather than creating a grace container.

>>> durations = [1000, 1, 1, 997]
>>> pitches = [0, 7, 4, 0]
>>> q_event_sequence = nauert.QEventSequence.from_millisecond_pitch_pairs(
...     tuple(zip(durations, pitches))
... )
>>> grace_handler = nauert.CollapsingGraceHandler()
>>> result = nauert.quantize(q_event_sequence, grace_handler=grace_handler)
>>> abjad.show(result)  

Attributes Summary

__call__

Calls collapsing grace handler.


Special methods

overridden __call__(q_events)[source]

Calls collapsing grace handler.

Return type:

tuple[tuple[NamedPitch, ...], tuple, None]

class abjadext.nauert.gracehandlers.ConcatenatingGraceHandler(discard_grace_rest=True, grace_duration=None, replace_rest_with_final_grace_note=True)[source]

Concatenating grace-handler.

Concatenates all but the final QEvent attached to a QGrid offset into a BeforeGraceContainer, using a fixed leaf duration duration.

When called, it returns pitch information of final QEvent, and the generated BeforeGraceContainer, if any.

>>> durations = [1000, 1, 999]
>>> pitches = [0, 2, 0]
>>> q_event_sequence = nauert.QEventSequence.from_millisecond_pitch_pairs(
...     tuple(zip(durations, pitches))
... )
>>> grace_handler = nauert.ConcatenatingGraceHandler()
>>> result = nauert.quantize(q_event_sequence, grace_handler=grace_handler)
>>> abjad.show(result)  

When discard_grace_rest is set to True (the default), all the grace rests are discarded.

>>> durations = [1000, 1, 999]
>>> pitches = [0, None, 0]
>>> q_event_sequence = nauert.QEventSequence.from_millisecond_pitch_pairs(
...     tuple(zip(durations, pitches))
... )
>>> grace_handler = nauert.ConcatenatingGraceHandler()
>>> result = nauert.quantize(q_event_sequence, grace_handler=grace_handler)
>>> abjad.show(result)  

When discard_grace_rest is set to False, grace rests are not discarded.

>>> grace_handler = nauert.ConcatenatingGraceHandler(discard_grace_rest=False)
>>> result = nauert.quantize(q_event_sequence, grace_handler=grace_handler)
>>> abjad.show(result)  

When replace_rest_with_final_grace_note is set to False, grace notes are allowed to be attached to a rest.

>>> durations = [1000, 1, 999, 1000]
>>> pitches = [0, 0, None, 0]
>>> q_event_sequence = nauert.QEventSequence.from_millisecond_pitch_pairs(
...     tuple(zip(durations, pitches))
... )
>>> grace_handler = nauert.ConcatenatingGraceHandler(
...     replace_rest_with_final_grace_note=False
... )
>>> result = nauert.quantize(q_event_sequence, grace_handler=grace_handler)
>>> abjad.show(result)  

When replace_rest_with_final_grace_note is set to True (the default behavior), any rest with grace notes attached to it is replaced by the last pitched grace note in the grace container.

>>> grace_handler = nauert.ConcatenatingGraceHandler()
>>> result = nauert.quantize(q_event_sequence, grace_handler=grace_handler)
>>> abjad.show(result)  

Attributes Summary

__call__

Calls concatenating grace handler.

discard_grace_rest

Boolean of whether to discard grace rests or not.

grace_duration

Grace duration of concantenating grace handler.

handle_orphaned_q_event_proxies

Embeds orphaned QEvents into an AfterGraceContainer and attaches it to the last leaf.

replace_rest_with_final_grace_note

Boolean of whether to replace the rest with the final (pitched) grace note.


Special methods

overridden __call__(q_events)[source]

Calls concatenating grace handler.

Return type:

tuple[tuple[NamedPitch, ...], Optional[tuple], Optional[BeforeGraceContainer]]


Methods

handle_orphaned_q_event_proxies(last_leaf, q_event_proxies)[source]

Embeds orphaned QEvents into an AfterGraceContainer and attaches it to the last leaf.

>>> durations = [1000, 1000, 1000, 400, 50, 50]
>>> pitches = range(len(durations))
>>> q_event_sequence = nauert.QEventSequence.from_millisecond_pitch_pairs(
...     tuple(zip(durations, pitches))
... )
>>> search_tree = nauert.UnweightedSearchTree()
>>> attack_point_optimizer = nauert.MeasurewiseAttackPointOptimizer()
>>> q_schema = nauert.MeasurewiseQSchema(
...     search_tree=search_tree, time_signature=(7, 8), use_full_measure=True
... )
>>> result = nauert.quantize(
...     q_event_sequence,
...     q_schema=q_schema,
...     attach_tempos=True,
...     attack_point_optimizer=attack_point_optimizer,
... )
>>> staff = abjad.Staff([result])
>>> score = abjad.Score([staff], name="Score")
>>> abjad.show(staff)  

Read-only properties

discard_grace_rest

Boolean of whether to discard grace rests or not.

grace_duration

Grace duration of concantenating grace handler.

replace_rest_with_final_grace_note

Boolean of whether to replace the rest with the final (pitched) grace note.

class abjadext.nauert.gracehandlers.DiscardingGraceHandler[source]

Discarding grace-handler.

Discards all but final q-event attached to an offset.

Does not create grace containers.

>>> durations = [1000, 1, 999]
>>> pitches = [0, 0, 1]
>>> q_event_sequence = nauert.QEventSequence.from_millisecond_pitch_pairs(
...     tuple(zip(durations, pitches))
... )
>>> grace_handler = nauert.DiscardingGraceHandler()
>>> result = nauert.quantize(q_event_sequence, grace_handler=grace_handler)
>>> abjad.show(result)  

Attributes Summary

__call__

Calls discarding grace handler.


Special methods

overridden __call__(q_events)[source]

Calls discarding grace handler.

Return type:

tuple[tuple[NamedPitch, ...], tuple, None]