IterationAgent

class agenttools.IterationAgent(client=None)

Iteration agent.

Iterates components:

>>> staff = Staff("c'4 e'4 d'4 f'4")
>>> show(staff) 
>>> for component in iterate(staff).by_class():
...     component
... 
Staff("c'4 e'4 d'4 f'4")
Note("c'4")
Note("e'4")
Note("d'4")
Note("f'4")
>>> expression = iterate()
>>> expression = expression.by_class()
>>> for component in expression(staff):
...     component
... 
Staff("c'4 e'4 d'4 f'4")
Note("c'4")
Note("e'4")
Note("d'4")
Note("f'4")

Iterates leaves:

>>> staff = Staff("c'4 e'4 d'4 f'4")
>>> show(staff) 
>>> for leaf in iterate(staff).by_leaf():
...     leaf
... 
Note("c'4")
Note("e'4")
Note("d'4")
Note("f'4")
>>> expression = iterate()
>>> expression = expression.by_leaf()
>>> for leaf in expression(staff):
...     leaf
... 
Note("c'4")
Note("e'4")
Note("d'4")
Note("f'4")

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_agenttools { graph [label=agenttools]; "abjad.tools.agenttools.IterationAgent.IterationAgent" [color=black, fontcolor=white, group=1, label=<<B>IterationAgent</B>>, shape=box, style="filled, rounded"]; } subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=3, group=2, label=object, shape=box]; } "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.agenttools.IterationAgent.IterationAgent"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Bases

Attribute summary

by_class([prototype, pitched, reverse, ...]) Iterates by class.
by_leaf([prototype, pitched, reverse, ...]) Iterates by leaf.
by_leaf_pair() Iterates by leaf pair.
by_logical_tie([nontrivial, pitched, ...]) Iterates by logical tie.
by_logical_voice(prototype, logical_voice[, ...]) Iterates by logical voice.
by_logical_voice_from_component([prototype, ...]) Iterates by logical voice from client.
by_pitch() Iterates by pitch.
by_pitch_pair() Iterates by pitch pair.
by_run([prototype]) Iterates by run.
by_semantic_voice([reverse, start, stop]) Iterates by semantic voice.
by_spanner([prototype, reverse]) Iterates by spanner.
by_timeline([prototype, reverse]) Iterates by timeline.
by_timeline_and_logical_tie([nontrivial, ...]) Iterates by timeline and logical tie.
by_timeline_from_component([prototype, reverse]) Iterates from client by timeline.
by_topmost_logical_ties_and_components() Iterates by topmost logical ties and components.
by_vertical_moment([reverse]) Iterates by vertical moment.
client Gets client of iteration agent.
depth_first([capped, direction, forbid, unique]) Iterates depth first.
__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.

Read-only properties

IterationAgent.client

Gets client of iteration agent.

Gets component client:

>>> staff = Staff("c'4 d' e' f'")
>>> agent = iterate(staff)
>>> agent.client
Staff("c'4 d'4 e'4 f'4")

Gets selection client:

>>> staff = Staff("c'4 d' e' f'")
>>> agent = iterate(staff[:2])
>>> agent.client
Selection([Note("c'4"), Note("d'4")])

Returns component or selection.

Methods

IterationAgent.by_class(prototype=None, pitched=None, reverse=False, start=0, stop=None, with_grace_notes=False)

Iterates by class.

Iterates notes:

>>> staff = Staff()
>>> staff.append(Measure((2, 8), "c'8 d'8"))
>>> staff.append(Measure((2, 8), "e'8 f'8"))
>>> staff.append(Measure((2, 8), "g'8 a'8"))
>>> show(staff) 
>>> for note in iterate(staff).by_class(prototype=Note):
...     note
...
Note("c'8")
Note("d'8")
Note("e'8")
Note("f'8")
Note("g'8")
Note("a'8")
>>> expression = iterate()
>>> expression = expression.by_class(prototype=Note)
>>> for note in expression(staff):
...     note
...
Note("c'8")
Note("d'8")
Note("e'8")
Note("f'8")
Note("g'8")
Note("a'8")

Iterates notes constrained by index:

>>> staff = Staff()
>>> staff.append(Measure((2, 8), "c'8 d'8"))
>>> staff.append(Measure((2, 8), "e'8 f'8"))
>>> staff.append(Measure((2, 8), "g'8 a'8"))
>>> show(staff) 
>>> for note in iterate(staff).by_class(
...     prototype=Note,
...     start=0,
...     stop=3,
...     ):
...     note
...
Note("c'8")
Note("d'8")
Note("e'8")
>>> for note in iterate(staff).by_class(
...     prototype=Note,
...     start=2,
...     stop=4,
...     ):
...     note
...
Note("e'8")
Note("f'8")
>>> expression = iterate()
>>> expression = expression.by_class(
...     prototype=Note,
...     start=0,
...     stop=3,
...     )
>>> for note in expression(staff):
...     note
...
Note("c'8")
Note("d'8")
Note("e'8")
>>> expression = iterate()
>>> expression = expression.by_class(
...     prototype=Note,
...     start=2,
...     stop=4,
...     )
>>> for note in expression(staff):
...     note
...
Note("e'8")
Note("f'8")

Iterates notes in reverse:

>>> staff = Staff()
>>> staff.append(Measure((2, 8), "c'8 d'8"))
>>> staff.append(Measure((2, 8), "e'8 f'8"))
>>> staff.append(Measure((2, 8), "g'8 a'8"))
>>> show(staff) 
>>> for note in iterate(staff).by_class(
...     prototype=Note,
...     reverse=True,
...     ):
...     note
...
Note("a'8")
Note("g'8")
Note("f'8")
Note("e'8")
Note("d'8")
Note("c'8")
>>> expression = iterate()
>>> expression = expression.by_class(
...     prototype=Note,
...     reverse=True,
...     )
>>> for note in expression(staff):
...     note
...
Note("a'8")
Note("g'8")
Note("f'8")
Note("e'8")
Note("d'8")
Note("c'8")

Iterates notes together with grace notes:

>>> voice = Voice("c'8 [ d'8 e'8 f'8 ]")
>>> grace_notes = [Note("cf''16"), Note("bf'16")]
>>> grace = scoretools.GraceContainer(
...     grace_notes,
...     kind='grace',
...     )
>>> attach(grace, voice[1])
>>> show(voice) 
>>> for component in iterate(voice).by_class(
...     with_grace_notes=True,
...     ):
...     component
...
Voice("c'8 d'8 e'8 f'8")
Note("c'8")
Note("cf''16")
Note("bf'16")
Note("d'8")
Note("e'8")
Note("f'8")
>>> expression = iterate()
>>> expression = expression.by_class(
...     with_grace_notes=True,
...     )
>>> for component in expression(voice):
...     component
...
Voice("c'8 d'8 e'8 f'8")
Note("c'8")
Note("cf''16")
Note("bf'16")
Note("d'8")
Note("e'8")
Note("f'8")

Iterates notes together with both grace notes and after grace notes:

>>> voice = Voice("c'8 [ d'8 e'8 f'8 ]")
>>> grace_notes = [Note("cf''16"), Note("bf'16")]
>>> grace = scoretools.GraceContainer(
...     grace_notes,
...     kind='grace',
...     )
>>> attach(grace, voice[1])
>>> after_grace_notes = [Note("af'16"), Note("gf'16")]
>>> after_grace = scoretools.GraceContainer(
...     after_grace_notes,
...     kind='after')
>>> attach(after_grace, voice[1])
>>> show(voice) 
>>> for leaf in iterate(voice).by_class(
...     with_grace_notes=True,
...     ):
...     leaf
...
Voice("c'8 d'8 e'8 f'8")
Note("c'8")
Note("cf''16")
Note("bf'16")
Note("d'8")
Note("af'16")
Note("gf'16")
Note("e'8")
Note("f'8")
>>> expression = iterate()
>>> expression = expression.by_class(
...     with_grace_notes=True,
...     )
>>> for leaf in expression(voice):
...     leaf
...
Voice("c'8 d'8 e'8 f'8")
Note("c'8")
Note("cf''16")
Note("bf'16")
Note("d'8")
Note("af'16")
Note("gf'16")
Note("e'8")
Note("f'8")

Iterates pitched components:

>>> staff = Staff()
>>> staff.append(Measure((2, 8), "<c' bf'>8 <g' a'>8"))
>>> staff.append(Measure((2, 8), "af'8 r8"))
>>> staff.append(Measure((2, 8), "r8 gf'8"))
>>> show(staff) 
>>> for leaf in iterate(staff).by_class(pitched=True):
...     leaf
...
Chord("<c' bf'>8")
Chord("<g' a'>8")
Note("af'8")
Note("gf'8")
>>> expression = iterate()
>>> expression = expression.by_class(pitched=True)
>>> for leaf in expression(staff):
...     leaf
...
Chord("<c' bf'>8")
Chord("<g' a'>8")
Note("af'8")
Note("gf'8")

Iterates nonpitched components:

>>> staff = Staff()
>>> staff.append(Measure((2, 8), "<c' bf'>8 <g' a'>8"))
>>> staff.append(Measure((2, 8), "af'8 r8"))
>>> staff.append(Measure((2, 8), "r8 gf'8"))
>>> show(staff) 
>>> for leaf in iterate(staff).by_class(pitched=False):
...     leaf
...
<Staff{3}>
Measure((2, 8), "<c' bf'>8 <g' a'>8")
Measure((2, 8), "af'8 r8")
Rest('r8')
Measure((2, 8), "r8 gf'8")
Rest('r8')
>>> expression = iterate()
>>> expression = expression.by_class(pitched=False)
>>> for leaf in expression(staff):
...     leaf
...
<Staff{3}>
Measure((2, 8), "<c' bf'>8 <g' a'>8")
Measure((2, 8), "af'8 r8")
Rest('r8')
Measure((2, 8), "r8 gf'8")
Rest('r8')

Returns generator.

IterationAgent.by_leaf(prototype=None, pitched=None, reverse=False, start=0, stop=None, with_grace_notes=False)

Iterates by leaf.

Iterates leaves:

>>> staff = Staff()
>>> staff.append(Measure((2, 8), "<c' bf'>8 <g' a'>8"))
>>> staff.append(Measure((2, 8), "af'8 r8"))
>>> staff.append(Measure((2, 8), "r8 gf'8"))
>>> show(staff) 
>>> for leaf in iterate(staff).by_leaf():
...     leaf
...
Chord("<c' bf'>8")
Chord("<g' a'>8")
Note("af'8")
Rest('r8')
Rest('r8')
Note("gf'8")
>>> expression = iterate()
>>> expression = expression.by_leaf()
>>> for leaf in expression(staff):
...     leaf
...
Chord("<c' bf'>8")
Chord("<g' a'>8")
Note("af'8")
Rest('r8')
Rest('r8')
Note("gf'8")

Iterates leaves constrained by index:

>>> staff = Staff()
>>> staff.append(Measure((2, 8), "<c' bf'>8 <g' a'>8"))
>>> staff.append(Measure((2, 8), "af'8 r8"))
>>> staff.append(Measure((2, 8), "r8 gf'8"))
>>> show(staff) 
>>> for leaf in iterate(staff).by_leaf(start=0, stop=3):
...     leaf
...
Chord("<c' bf'>8")
Chord("<g' a'>8")
Note("af'8")
>>> for leaf in iterate(staff).by_leaf(start=2, stop=4):
...     leaf
...
Note("af'8")
Rest('r8')
>>> expression = iterate()
>>> expression = expression.by_leaf(start=0, stop=3)
>>> for leaf in expression(staff):
...     leaf
...
Chord("<c' bf'>8")
Chord("<g' a'>8")
Note("af'8")
>>> expression = iterate()
>>> expression = expression.by_leaf(start=2, stop=4)
>>> for leaf in expression(staff):
...     leaf
...
Note("af'8")
Rest('r8')

Iterates leaves in reverse:

>>> staff = Staff()
>>> staff.append(Measure((2, 8), "<c' bf'>8 <g' a'>8"))
>>> staff.append(Measure((2, 8), "af'8 r8"))
>>> staff.append(Measure((2, 8), "r8 gf'8"))
>>> show(staff) 
>>> for leaf in iterate(staff).by_leaf(reverse=True):
...     leaf
...
Note("gf'8")
Rest('r8')
Rest('r8')
Note("af'8")
Chord("<g' a'>8")
Chord("<c' bf'>8")
>>> expression = iterate()
>>> expression = expression.by_leaf(reverse=True)
>>> for leaf in expression(staff):
...     leaf
...
Note("gf'8")
Rest('r8')
Rest('r8')
Note("af'8")
Chord("<g' a'>8")
Chord("<c' bf'>8")

Iterates leaves together with grace notes:

>>> voice = Voice("c'8 [ d'8 e'8 f'8 ]")
>>> grace_notes = [Note("cf''16"), Note("bf'16")]
>>> grace = scoretools.GraceContainer(
...     grace_notes,
...     kind='grace',
...     )
>>> attach(grace, voice[1])
>>> after_grace_notes = [Note("af'16"), Note("gf'16")]
>>> after_grace = scoretools.GraceContainer(
...     after_grace_notes,
...     kind='after')
>>> attach(after_grace, voice[1])
>>> show(voice) 
>>> for leaf in iterate(voice).by_leaf(
...     with_grace_notes=True,
...     ):
...     leaf
...
Note("c'8")
Note("cf''16")
Note("bf'16")
Note("d'8")
Note("af'16")
Note("gf'16")
Note("e'8")
Note("f'8")
>>> expression = iterate()
>>> expression = expression.by_leaf(
...     with_grace_notes=True,
...     )
>>> for leaf in expression(voice):
...     leaf
...
Note("c'8")
Note("cf''16")
Note("bf'16")
Note("d'8")
Note("af'16")
Note("gf'16")
Note("e'8")
Note("f'8")

Iterates pitched leaves:

>>> staff = Staff()
>>> staff.append(Measure((2, 8), "<c' bf'>8 <g' a'>8"))
>>> staff.append(Measure((2, 8), "af'8 r8"))
>>> staff.append(Measure((2, 8), "r8 gf'8"))
>>> show(staff) 
>>> for leaf in iterate(staff).by_leaf(pitched=True):
...     leaf
...
Chord("<c' bf'>8")
Chord("<g' a'>8")
Note("af'8")
Note("gf'8")
>>> expression = iterate()
>>> expression = expression.by_leaf(pitched=True)
>>> for leaf in expression(staff):
...     leaf
...
Chord("<c' bf'>8")
Chord("<g' a'>8")
Note("af'8")
Note("gf'8")

Iterates nonpitched leaves:

>>> staff = Staff()
>>> staff.append(Measure((2, 8), "<c' bf'>8 <g' a'>8"))
>>> staff.append(Measure((2, 8), "af'8 r8"))
>>> staff.append(Measure((2, 8), "r8 gf'8"))
>>> show(staff) 
>>> for leaf in iterate(staff).by_leaf(pitched=False):
...     leaf
...
Rest('r8')
Rest('r8')
>>> expression = iterate()
>>> expression = expression.by_leaf(pitched=False)
>>> for leaf in expression(staff):
...     leaf
...
Rest('r8')
Rest('r8')

Returns generator.

IterationAgent.by_leaf_pair()

Iterates by leaf pair.

Iterates leaf pairs:

>>> score = Score([])
>>> score.append(Staff("c'8 d'8 e'8 f'8 g'4"))
>>> score.append(Staff("c4 a,4 g,4"))
>>> attach(Clef('bass'), score[1])
>>> show(score) 
>>> for leaf_pair in iterate(score).by_leaf_pair():
...     leaf_pair
...
Selection([Note("c'8"), Note('c4')])
Selection([Note("c'8"), Note("d'8")])
Selection([Note('c4'), Note("d'8")])
Selection([Note("d'8"), Note("e'8")])
Selection([Note("d'8"), Note('a,4')])
Selection([Note('c4'), Note("e'8")])
Selection([Note('c4'), Note('a,4')])
Selection([Note("e'8"), Note('a,4')])
Selection([Note("e'8"), Note("f'8")])
Selection([Note('a,4'), Note("f'8")])
Selection([Note("f'8"), Note("g'4")])
Selection([Note("f'8"), Note('g,4')])
Selection([Note('a,4'), Note("g'4")])
Selection([Note('a,4'), Note('g,4')])
Selection([Note("g'4"), Note('g,4')])
>>> expression = iterate()
>>> expression = expression.by_leaf_pair()
>>> for leaf_pair in expression(score):
...     leaf_pair
...
Selection([Note("c'8"), Note('c4')])
Selection([Note("c'8"), Note("d'8")])
Selection([Note('c4'), Note("d'8")])
Selection([Note("d'8"), Note("e'8")])
Selection([Note("d'8"), Note('a,4')])
Selection([Note('c4'), Note("e'8")])
Selection([Note('c4'), Note('a,4')])
Selection([Note("e'8"), Note('a,4')])
Selection([Note("e'8"), Note("f'8")])
Selection([Note('a,4'), Note("f'8")])
Selection([Note("f'8"), Note("g'4")])
Selection([Note("f'8"), Note('g,4')])
Selection([Note('a,4'), Note("g'4")])
Selection([Note('a,4'), Note('g,4')])
Selection([Note("g'4"), Note('g,4')])

Iterates leaf pairs left-to-right and top-to-bottom.

Returns generator.

IterationAgent.by_logical_tie(nontrivial=False, pitched=False, reverse=False, parentage_mask=None, with_grace_notes=False)

Iterates by logical tie.

Iterates logical ties:

>>> string = r"c'4 ~ \times 2/3 { c'16 d'8 } e'8 f'4 ~ f'16"
>>> staff = Staff(string)
>>> show(staff) 
>>> for logical_tie in iterate(staff).by_logical_tie():
...     logical_tie
...
LogicalTie([Note("c'4"), Note("c'16")])
LogicalTie([Note("d'8")])
LogicalTie([Note("e'8")])
LogicalTie([Note("f'4"), Note("f'16")])
>>> expression = iterate()
>>> expression = expression.by_logical_tie()
>>> for logical_tie in expression(staff):
...     logical_tie
...
LogicalTie([Note("c'4"), Note("c'16")])
LogicalTie([Note("d'8")])
LogicalTie([Note("e'8")])
LogicalTie([Note("f'4"), Note("f'16")])

Iterates logical ties in reverse:

>>> string = r"c'4 ~ \times 2/3 { c'16 d'8 } e'8 f'4 ~ f'16"
>>> staff = Staff(string)
>>> show(staff) 
>>> for logical_tie in iterate(staff).by_logical_tie(
...     reverse=True,
...     ):
...     logical_tie
...
LogicalTie([Note("f'4"), Note("f'16")])
LogicalTie([Note("e'8")])
LogicalTie([Note("d'8")])
LogicalTie([Note("c'4"), Note("c'16")])
>>> expression = iterate()
>>> expression = expression.by_logical_tie(reverse=True)
>>> for logical_tie in expression(staff):
...     logical_tie
...
LogicalTie([Note("f'4"), Note("f'16")])
LogicalTie([Note("e'8")])
LogicalTie([Note("d'8")])
LogicalTie([Note("c'4"), Note("c'16")])

Iterates pitched logical ties:

>>> string = r"c'4 ~ \times 2/3 { c'16 d'8 } e'8 f'4 ~ f'16"
>>> staff = Staff(string)
>>> show(staff) 
>>> for logical_tie in iterate(staff).by_logical_tie(
...     pitched=True,
...     ):
...     logical_tie
...
LogicalTie([Note("c'4"), Note("c'16")])
LogicalTie([Note("d'8")])
LogicalTie([Note("e'8")])
LogicalTie([Note("f'4"), Note("f'16")])
>>> expression = iterate()
>>> expression = expression.by_logical_tie(pitched=True)
>>> for logical_tie in expression(staff):
...     logical_tie
...
LogicalTie([Note("c'4"), Note("c'16")])
LogicalTie([Note("d'8")])
LogicalTie([Note("e'8")])
LogicalTie([Note("f'4"), Note("f'16")])

Iterates nontrivial logical ties:

>>> string = r"c'4 ~ \times 2/3 { c'16 d'8 } e'8 f'4 ~ f'16"
>>> staff = Staff(string)
>>> show(staff) 
>>> for logical_tie in iterate(staff).by_logical_tie(
...     nontrivial=True,
...     ):
...     logical_tie
...
LogicalTie([Note("c'4"), Note("c'16")])
LogicalTie([Note("f'4"), Note("f'16")])
>>> expression = iterate()
>>> expression = expression.by_logical_tie(nontrivial=True)
>>> for logical_tie in expression(staff):
...     logical_tie
...
LogicalTie([Note("c'4"), Note("c'16")])
LogicalTie([Note("f'4"), Note("f'16")])

Iterates logical ties masked by parentage:

Note

When iterating logical ties in a container, the yielded logical ties may contain leaves outside that container’s parentage. By specifying a parentage mask, composers can constrain the contents of the yielded logical ties to only those leaves actually within the parentage of the container under iteration.

>>> staff = Staff("{ c'1 ~ } { c'2 d'2 ~ } { d'1 }")
>>> show(staff) 
>>> for logical_tie in iterate(staff[1]).by_logical_tie():
...     logical_tie
...
LogicalTie([Note("c'1"), Note("c'2")])
LogicalTie([Note("d'2"), Note("d'1")])
>>> for logical_tie in iterate(staff[1]).by_logical_tie(
...     parentage_mask=staff[1]):
...     logical_tie
...
LogicalTie([Note("c'2")])
LogicalTie([Note("d'2")])
>>> expression = iterate()
>>> expression = expression.by_logical_tie()
>>> for logical_tie in expression(staff[1]):
...     logical_tie
...
LogicalTie([Note("c'1"), Note("c'2")])
LogicalTie([Note("d'2"), Note("d'1")])
>>> expression = iterate()
>>> expression = expression.by_logical_tie(
...     parentage_mask=staff[1],
...     )

Todo

Reimplement parentage_mask to work with persistable values (like component name or score position). Method will then work with expression protocol.

Iterates logical ties together with grace notes:

>>> voice = Voice("c'8 [ d'8 e'8 f'8 ]")
>>> grace_notes = [Note("cf''16"), Note("bf'16")]
>>> grace = scoretools.GraceContainer(
...     grace_notes,
...     kind='grace',
...     )
>>> attach(grace, voice[1])
>>> show(voice) 
>>> for logical_tie in iterate(voice).by_logical_tie(
...     with_grace_notes=True,
...     ):
...     logical_tie
... 
LogicalTie([Note("c'8")])
LogicalTie([Note("cf''16")])
LogicalTie([Note("bf'16")])
LogicalTie([Note("d'8")])
LogicalTie([Note("e'8")])
LogicalTie([Note("f'8")])
>>> expression = iterate()
>>> expression = expression.by_logical_tie(
...     with_grace_notes=True,
...     )
>>> for logical_tie in expression(voice):
...     logical_tie
...
LogicalTie([Note("c'8")])
LogicalTie([Note("cf''16")])
LogicalTie([Note("bf'16")])
LogicalTie([Note("d'8")])
LogicalTie([Note("e'8")])
LogicalTie([Note("f'8")])

Iterates logical ties together with after grace notes:

>>> voice = Voice("c'8 [ d'8 e'8 f'8 ]")
>>> after_grace_notes = [Note("af'16"), Note("gf'16")]
>>> after_grace = scoretools.GraceContainer(
...     after_grace_notes,
...     kind='after')
>>> attach(after_grace, voice[1])
>>> show(voice) 
>>> for logical_tie in iterate(voice).by_logical_tie(
...     with_grace_notes=True,
...     ):
...     logical_tie
... 
LogicalTie([Note("c'8")])
LogicalTie([Note("d'8")])
LogicalTie([Note("af'16")])
LogicalTie([Note("gf'16")])
LogicalTie([Note("e'8")])
LogicalTie([Note("f'8")])
>>> expression = iterate()
>>> expression = expression.by_logical_tie(
...     with_grace_notes=True,
...     )
>>> for logical_tie in expression(voice):
...     logical_tie
...
LogicalTie([Note("c'8")])
LogicalTie([Note("d'8")])
LogicalTie([Note("af'16")])
LogicalTie([Note("gf'16")])
LogicalTie([Note("e'8")])
LogicalTie([Note("f'8")])

Iterates logical ties together with both grace notes and after grace notes:

>>> voice = Voice("c'8 [ d'8 e'8 f'8 ]")
>>> grace_notes = [Note("cf''16"), Note("bf'16")]
>>> grace = scoretools.GraceContainer(
...     grace_notes,
...     kind='grace',
...     )
>>> attach(grace, voice[1])
>>> after_grace_notes = [Note("af'16"), Note("gf'16")]
>>> after_grace = scoretools.GraceContainer(
...     after_grace_notes,
...     kind='after')
>>> attach(after_grace, voice[1])
>>> show(voice) 
>>> for logical_tie in iterate(voice).by_logical_tie(
...     with_grace_notes=True,
...     ):
...     logical_tie
...
LogicalTie([Note("c'8")])
LogicalTie([Note("cf''16")])
LogicalTie([Note("bf'16")])
LogicalTie([Note("d'8")])
LogicalTie([Note("af'16")])
LogicalTie([Note("gf'16")])
LogicalTie([Note("e'8")])
LogicalTie([Note("f'8")])
>>> expression = iterate()
>>> expression = expression.by_logical_tie(
...     with_grace_notes=True,
...     )
>>> for logical_tie in expression(voice):
...     logical_tie
...
LogicalTie([Note("c'8")])
LogicalTie([Note("cf''16")])
LogicalTie([Note("bf'16")])
LogicalTie([Note("d'8")])
LogicalTie([Note("af'16")])
LogicalTie([Note("gf'16")])
LogicalTie([Note("e'8")])
LogicalTie([Note("f'8")])

Returns generator.

IterationAgent.by_logical_voice(prototype, logical_voice, reverse=False)

Iterates by logical voice.

Iterates notes in logical voice 1:

>>> container_1 = Container([Voice("c'8 d'8"), Voice("e'8 f'8")])
>>> container_1.is_simultaneous = True
>>> container_1[0].name = 'voice 1'
>>> override(container_1[0]).stem.direction = Down
>>> container_1[1].name = 'voice 2'
>>> container_2 = Container([Voice("g'8 a'8"), Voice("b'8 c''8")])
>>> container_2.is_simultaneous = True
>>> container_2[0].name = 'voice 1'
>>> override(container_2[0]).stem.direction = Down
>>> container_2[1].name = 'voice 2'
>>> staff = Staff([container_1, container_2])
>>> show(staff) 
>>> selector = select().by_leaf(flatten=True)
>>> leaves = selector(staff)
>>> leaf = leaves[0]
>>> signature = inspect_(leaf).get_parentage().logical_voice
>>> for note in iterate(staff).by_logical_voice(
...     prototype=Note,
...     logical_voice=signature,
...     ):
...     note
...
Note("c'8")
Note("d'8")
Note("g'8")
Note("a'8")
>>> selector = select().by_leaf(flatten=True)
>>> leaves = selector(staff)
>>> leaf = leaves[0]
>>> signature = inspect_(leaf).get_parentage().logical_voice
>>> expression = iterate()

Todo

Implement a persistable signature (in terms of container names or score position). Method will then work with expression protocol.

Returns generator.

IterationAgent.by_logical_voice_from_component(prototype=None, reverse=False)

Iterates by logical voice from client.

Iterates from first leaf in score:

>>> container_1 = Container([Voice("c'8 d'8"), Voice("e'8 f'8")])
>>> container_1.is_simultaneous = True
>>> container_1[0].name = 'voice 1'
>>> override(container_1[0]).stem.direction = Down
>>> container_1[1].name = 'voice 2'
>>> container_2 = Container([Voice("g'8 a'8"), Voice("b'8 c''8")])
>>> container_2.is_simultaneous = True
>>> container_2[0].name = 'voice 1'
>>> override(container_2[0]).stem.direction = Down
>>> container_2[1].name = 'voice 2'
>>> staff = Staff([container_1, container_2])
>>> show(staff) 
>>> selector = select().by_leaf(flatten=True)
>>> leaves = selector(staff)
>>> leaf = leaves[0]
>>> for note in iterate(leaf).by_logical_voice_from_component(
...     prototype=Note,
...     ):
...     note
...
Note("c'8")
Note("d'8")
Note("g'8")
Note("a'8")
>>> selector = select().by_leaf(flatten=True)
>>> leaves = selector(staff)
>>> leaf = leaves[0]
>>> expression = iterate()
>>> expression = expression.by_logical_voice_from_component(
...     prototype=Note,
...     )
>>> for note in expression(leaf):
...     note
...
Note("c'8")
Note("d'8")
Note("g'8")
Note("a'8")

Iterates from second leaf in score:

>>> container_1 = Container([Voice("c'8 d'8"), Voice("e'8 f'8")])
>>> container_1.is_simultaneous = True
>>> container_1[0].name = 'voice 1'
>>> override(container_1[0]).stem.direction = Down
>>> container_1[1].name = 'voice 2'
>>> container_2 = Container([Voice("g'8 a'8"), Voice("b'8 c''8")])
>>> container_2.is_simultaneous = True
>>> container_2[0].name = 'voice 1'
>>> override(container_2[0]).stem.direction = Down
>>> container_2[1].name = 'voice 2'
>>> staff = Staff([container_1, container_2])
>>> show(staff) 
>>> leaf = leaves[1]
>>> agent = iterate(leaf)
>>> for note in agent.by_logical_voice_from_component(
...     prototype=Note,
...     ):
...     note
...
Note("d'8")
Note("g'8")
Note("a'8")
>>> leaf = leaves[1]
>>> expression = iterate()
>>> expression = expression.by_logical_voice_from_component(
...     prototype=Note,
...     )
>>> for note in expression(leaf):
...     note
...
Note("d'8")
Note("g'8")
Note("a'8")

Iterates all components in logical voice:

>>> container_1 = Container([Voice("c'8 d'8"), Voice("e'8 f'8")])
>>> container_1.is_simultaneous = True
>>> container_1[0].name = 'voice 1'
>>> override(container_1[0]).stem.direction = Down
>>> container_1[1].name = 'voice 2'
>>> container_2 = Container([Voice("g'8 a'8"), Voice("b'8 c''8")])
>>> container_2.is_simultaneous = True
>>> container_2[0].name = 'voice 1'
>>> override(container_2[0]).stem.direction = Down
>>> container_2[1].name = 'voice 2'
>>> staff = Staff([container_1, container_2])
>>> show(staff) 
>>> leaf = leaves[0]
>>> for component in iterate(leaf).by_logical_voice_from_component():
...     component
...
Note("c'8")
Voice("c'8 d'8")
Note("d'8")
Voice("g'8 a'8")
Note("g'8")
Note("a'8")
>>> leaf = leaves[0]
>>> expression = iterate()
>>> expression = expression.by_logical_voice_from_component()
>>> for component in expression(leaf):
...     component
...
Note("c'8")
Voice("c'8 d'8")
Note("d'8")
Voice("g'8 a'8")
Note("g'8")
Note("a'8")

Iterates all components in logical voice in reverse:

>>> container_1 = Container([Voice("c'8 d'8"), Voice("e'8 f'8")])
>>> container_1.is_simultaneous = True
>>> container_1[0].name = 'voice 1'
>>> override(container_1[0]).stem.direction = Down
>>> container_1[1].name = 'voice 2'
>>> container_2 = Container([Voice("g'8 a'8"), Voice("b'8 c''8")])
>>> container_2.is_simultaneous = True
>>> container_2[0].name = 'voice 1'
>>> override(container_2[0]).stem.direction = Down
>>> container_2[1].name = 'voice 2'
>>> staff = Staff([container_1, container_2])
>>> show(staff) 
>>> leaf = leaves[-1]
>>> for note in iterate(leaf).by_logical_voice_from_component(
...     prototype=Note,
...     reverse=True,
...     ):
...     note
...
Note("c''8")
Note("b'8")
Note("f'8")
Note("e'8")
>>> leaf = leaves[-1]
>>> for component in iterate(leaf).by_logical_voice_from_component(
...     reverse=True,
...     ):
...     component
...
Note("c''8")
Voice("b'8 c''8")
Note("b'8")
Voice("e'8 f'8")
Note("f'8")
Note("e'8")
>>> leaf = leaves[-1]
>>> expression = iterate()
>>> expression = expression.by_logical_voice_from_component(
...     prototype=Note,
...     reverse=True,
...     )
>>> for note in expression(leaf):
...     note
...
Note("c''8")
Note("b'8")
Note("f'8")
Note("e'8")
>>> leaf = leaves[-1]
>>> expression = iterate()
>>> expression = expression.by_logical_voice_from_component(
...     reverse=True,
...     )
>>> for component in expression(leaf):
...     component
...
Note("c''8")
Voice("b'8 c''8")
Note("b'8")
Voice("e'8 f'8")
Note("f'8")
Note("e'8")

Returns generator.

IterationAgent.by_pitch()

Iterates by pitch.

Iterates pitches in container:

>>> staff = Staff("c'8 d'8 e'8 f'8")
>>> beam = spannertools.Beam()
>>> attach(beam, staff[:])
>>> show(staff) 
>>> for pitch in iterate(staff).by_pitch():
...     pitch
...
NamedPitch("c'")
NamedPitch("d'")
NamedPitch("e'")
NamedPitch("f'")
>>> expression = iterate()
>>> expression = expression.by_pitch()
>>> for pitch in expression(staff):
...     pitch
...
NamedPitch("c'")
NamedPitch("d'")
NamedPitch("e'")
NamedPitch("f'")

Iterates pitches in spanner:

>>> staff = Staff("c'8 d'8 e'8 f'8")
>>> beam = spannertools.Beam()
>>> attach(beam, staff[:])
>>> show(staff) 
>>> for pitch in iterate(beam).by_pitch():
...     pitch
...
NamedPitch("c'")
NamedPitch("d'")
NamedPitch("e'")
NamedPitch("f'")
>>> expression = iterate()
>>> expression = expression.by_pitch()
>>> for pitch in expression(beam):
...     pitch
...
NamedPitch("c'")
NamedPitch("d'")
NamedPitch("e'")
NamedPitch("f'")

Iterates pitches in pitch set:

>>> pitch_set = pitchtools.PitchSet([0, 2, 4, 5])
>>> for pitch in iterate(pitch_set).by_pitch():
...     pitch
...
NumberedPitch(0)
NumberedPitch(2)
NumberedPitch(4)
NumberedPitch(5)
>>> expression = iterate()
>>> expression = expression.by_pitch()
>>> for pitch in expression(pitch_set):
...     pitch
...
NumberedPitch(0)
NumberedPitch(2)
NumberedPitch(4)
NumberedPitch(5)

Iterates different types of object in tuple:

>>> pitches = (
...     NamedPitch("c'"),
...     Note("d'4"),
...     Chord("<e' fs' g>4"),
...     )
>>> for pitch in iterate(pitches).by_pitch():
...     pitch
...
NamedPitch("c'")
NamedPitch("d'")
NamedPitch('g')
NamedPitch("e'")
NamedPitch("fs'")
>>> expression = iterate()
>>> expression = expression.by_pitch()
>>> for pitch in expression(pitches):
...     pitch
...
NamedPitch("c'")
NamedPitch("d'")
NamedPitch('g')
NamedPitch("e'")
NamedPitch("fs'")

Returns generator.

IterationAgent.by_pitch_pair()

Iterates by pitch pair.

Iterates notes by pitch pair:

>>> score = Score([])
>>> notes = [Note("c'8"), Note("d'8"), Note("e'8"), Note("f'8"), Note("g'4")]
>>> score.append(Staff(notes))
>>> notes = [Note(x, (1, 4)) for x in [-12, -15, -17]]
>>> score.append(Staff(notes))
>>> clef = Clef('bass')
>>> attach(clef, score[1])
>>> show(score) 
>>> for pair in iterate(score).by_pitch_pair():
...     pair
...
PitchSegment("c' c")
PitchSegment("c' d'")
PitchSegment("c d'")
PitchSegment("d' e'")
PitchSegment("d' a,")
PitchSegment("c e'")
PitchSegment("c a,")
PitchSegment("e' a,")
PitchSegment("e' f'")
PitchSegment("a, f'")
PitchSegment("f' g'")
PitchSegment("f' g,")
PitchSegment("a, g'")
PitchSegment("a, g,")
PitchSegment("g' g,")
>>> expression = iterate()
>>> expression = expression.by_pitch_pair()
>>> for pair in expression(score):
...     pair
...
PitchSegment("c' c")
PitchSegment("c' d'")
PitchSegment("c d'")
PitchSegment("d' e'")
PitchSegment("d' a,")
PitchSegment("c e'")
PitchSegment("c a,")
PitchSegment("e' a,")
PitchSegment("e' f'")
PitchSegment("a, f'")
PitchSegment("f' g'")
PitchSegment("f' g,")
PitchSegment("a, g'")
PitchSegment("a, g,")
PitchSegment("g' g,")

Iterates chords by pitch pair:

>>> chord_1 = Chord([0, 2, 4], (1, 4))
>>> chord_2 = Chord([17, 19], (1, 4))
>>> staff = Staff([chord_1, chord_2])
>>> for pair in iterate(staff).by_pitch_pair():
...     pair
...
PitchSegment("c' d'")
PitchSegment("c' e'")
PitchSegment("d' e'")
PitchSegment("c' f''")
PitchSegment("c' g''")
PitchSegment("d' f''")
PitchSegment("d' g''")
PitchSegment("e' f''")
PitchSegment("e' g''")
PitchSegment("f'' g''")
>>> expression = iterate()
>>> expression = expression.by_pitch_pair()
>>> for pair in expression(staff):
...     pair
...
PitchSegment("c' d'")
PitchSegment("c' e'")
PitchSegment("d' e'")
PitchSegment("c' f''")
PitchSegment("c' g''")
PitchSegment("d' f''")
PitchSegment("d' g''")
PitchSegment("e' f''")
PitchSegment("e' g''")
PitchSegment("f'' g''")

Returns generator.

IterationAgent.by_run(prototype=None)

Iterates by run.

Iterates runs of notes and chords at only the top level of score:

>>> staff = Staff(r"\times 2/3 { c'8 d'8 r8 }")
>>> staff.append(r"\times 2/3 { r8 <e' g'>8 <f' a'>8 }")
>>> staff.extend("g'8 a'8 r8 r8 <b' d''>8 <c'' e''>8")
>>> show(staff) 
>>> prototype = (Note, Chord)
>>> for run in iterate(staff[:]).by_run(
...     prototype=prototype,
...     ):
...     run
...
(Note("g'8"), Note("a'8"))
(Chord("<b' d''>8"), Chord("<c'' e''>8"))
>>> prototype = (Note, Chord)
>>> expression = iterate()
>>> expression = expression.by_run(prototype=prototype)
>>> for run in expression(staff[:]):
...     run
...
(Note("g'8"), Note("a'8"))
(Chord("<b' d''>8"), Chord("<c'' e''>8"))

Iterates runs of notes and chords at all levels of score:

>>> staff = Staff(r"\times 2/3 { c'8 d'8 r8 }")
>>> staff.append(r"\times 2/3 { r8 <e' g'>8 <f' a'>8 }")
>>> staff.extend("g'8 a'8 r8 r8 <b' d''>8 <c'' e''>8")
>>> show(staff) 
>>> leaves = iterate(staff).by_leaf()
>>> prototype = (Note, Chord)
>>> for run in iterate(leaves).by_run(
...     prototype=prototype,
...     ):
...     run
...
(Note("c'8"), Note("d'8"))
(Chord("<e' g'>8"), Chord("<f' a'>8"), Note("g'8"), Note("a'8"))
(Chord("<b' d''>8"), Chord("<c'' e''>8"))
>>> leaves = iterate(staff).by_leaf()
>>> prototype = (Note, Chord)
>>> expression = iterate()
>>> expression = expression.by_run(prototype=prototype)
>>> for run in expression(leaves):
...     run
...
(Note("c'8"), Note("d'8"))
(Chord("<e' g'>8"), Chord("<f' a'>8"), Note("g'8"), Note("a'8"))
(Chord("<b' d''>8"), Chord("<c'' e''>8"))

Interprets none prototype equal to leaves:

>>> components = [
...     Note("c'4"),
...     Note("d'4"),
...     Staff(),
...     Note("e'4"),
...     Note("f'4"),
...     Staff(),
...     Rest('r4'),
...     ]
>>> for run in iterate(components).by_run():
...     run
...
(Note("c'4"), Note("d'4"))
(Note("e'4"), Note("f'4"))
(Rest('r4'),)

Returns generator.

IterationAgent.by_semantic_voice(reverse=False, start=0, stop=None)

Iterates by semantic voice.

Todo

Deprecated. Use IterationAgent.by_class(Voice) instead.

Iterates semantic voices:

>>> pairs = [(3, 8), (5, 16), (5, 16)]
>>> measures = scoretools.make_spacer_skip_measures(pairs)
>>> time_signature_voice = Voice(measures)
>>> time_signature_voice.name = 'TimeSignatureVoice'
>>> time_signature_voice.is_nonsemantic = True
>>> music_voice = Voice("c'4. d'4 e'16 f'4 g'16")
>>> music_voice.name = 'MusicVoice'
>>> staff = Staff([time_signature_voice, music_voice])
>>> staff.is_simultaneous = True
>>> show(staff) 

Iterates semantic voices in reverse:

>>> pairs = [(3, 8), (5, 16), (5, 16)]
>>> measures = scoretools.make_spacer_skip_measures(pairs)
>>> time_signature_voice = Voice(measures)
>>> time_signature_voice.name = 'TimeSignatureVoice'
>>> time_signature_voice.is_nonsemantic = True
>>> music_voice = Voice("c'4. d'4 e'16 f'4 g'16")
>>> music_voice.name = 'MusicVoice'
>>> staff = Staff([time_signature_voice, music_voice])
>>> staff.is_simultaneous = True
>>> show(staff) 
>>> for voice in iterate(staff).by_semantic_voice(reverse=True):
...   voice
...
Voice("c'4. d'4 e'16 f'4 g'16")

Note: returns list.

IterationAgent.by_spanner(prototype=None, reverse=False)

Iterates by spanner.

Iterates spanners:

>>> staff = Staff("c'8 d'8 e'8 f'8 g'8 a'8 f'8 b'8 c''8")
>>> attach(Slur(), staff[:4])
>>> attach(Slur(), staff[4:])
>>> attach(Beam(), staff[:])
>>> show(staff) 
>>> for spanner in iterate(staff).by_spanner():
...     spanner
...
Beam("c'8, d'8, ... [5] ..., b'8, c''8")
Slur("c'8, d'8, e'8, f'8")
Slur("g'8, a'8, f'8, b'8, c''8")
>>> expression = iterate()
>>> expression = expression.by_spanner()
>>> for spanner in expression(staff):
...     spanner
...
Beam("c'8, d'8, ... [5] ..., b'8, c''8")
Slur("c'8, d'8, e'8, f'8")
Slur("g'8, a'8, f'8, b'8, c''8")

Iterates spanners in reverse:

>>> staff = Staff("c'8 d'8 e'8 f'8 g'8 a'8 f'8 b'8 c''8")
>>> attach(Slur(), staff[:4])
>>> attach(Slur(), staff[4:])
>>> attach(Beam(), staff[:])
>>> show(staff) 
>>> for spanner in iterate(staff).by_spanner(reverse=True):
...     spanner
...
Beam("c'8, d'8, ... [5] ..., b'8, c''8")
Slur("g'8, a'8, f'8, b'8, c''8")
Slur("c'8, d'8, e'8, f'8")
>>> expression = iterate()
>>> expression = expression.by_spanner(reverse=True)
>>> for spanner in expression(staff):
...     spanner
...
Beam("c'8, d'8, ... [5] ..., b'8, c''8")
Slur("g'8, a'8, f'8, b'8, c''8")
Slur("c'8, d'8, e'8, f'8")

Returns generator.

IterationAgent.by_timeline(prototype=None, reverse=False)

Iterates by timeline.

Timeline-iterates leaves:

>>> score = Score([])
>>> score.append(Staff("c'4 d'4 e'4 f'4"))
>>> score.append(Staff("g'8 a'8 b'8 c''8"))
>>> show(score) 
>>> for leaf in iterate(score).by_timeline():
...     leaf
...
Note("c'4")
Note("g'8")
Note("a'8")
Note("d'4")
Note("b'8")
Note("c''8")
Note("e'4")
Note("f'4")
>>> expression = iterate()
>>> expression = expression.by_timeline()
>>> for leaf in expression(score):
...     leaf
...
Note("c'4")
Note("g'8")
Note("a'8")
Note("d'4")
Note("b'8")
Note("c''8")
Note("e'4")
Note("f'4")

Timeline-iterates leaves in reverse:

>>> score = Score([])
>>> score.append(Staff("c'4 d'4 e'4 f'4"))
>>> score.append(Staff("g'8 a'8 b'8 c''8"))
>>> show(score) 
>>> for leaf in iterate(score).by_timeline(reverse=True):
...     leaf
...
Note("f'4")
Note("e'4")
Note("d'4")
Note("c''8")
Note("b'8")
Note("c'4")
Note("a'8")
Note("g'8")
>>> expression = iterate()
>>> expression = expression.by_timeline(reverse=True)
>>> for leaf in expression(score):
...     leaf
...
Note("f'4")
Note("e'4")
Note("d'4")
Note("c''8")
Note("b'8")
Note("c'4")
Note("a'8")
Note("g'8")

Timeline-iterates leaves together grace notes:

>>> voice = Voice("c'8 [ d'8 e'8 f'8 ]")
>>> grace_notes = [Note("cf''16"), Note("bf'16")]
>>> grace = scoretools.GraceContainer(
...     grace_notes,
...     kind='grace',
...     )
>>> attach(grace, voice[1])
>>> show(voice) 
>>> for component in iterate(voice).by_timeline():
...     component
...
Note("c'8")
Note("d'8")
Note("e'8")
Note("f'8")

Todo

Incorrect because grace notes are not included.

>>> expression = iterate()
>>> expression = expression.by_timeline()
>>> for component in expression(voice):
...     component
...
Note("c'8")
Note("d'8")
Note("e'8")
Note("f'8")

Todo

Incorrect because grace notes are not included.

Iterates leaves when prototype is none.

IterationAgent.by_timeline_and_logical_tie(nontrivial=False, pitched=False, reverse=False)

Iterates by timeline and logical tie.

Timeline-iterates logical ties:

>>> score = Score([])
>>> score.append(Staff("c''4 ~ c''8 d''8 r4 ef''4"))
>>> score.append(Staff("r8 g'4. ~ g'8 r16 f'8. ~ f'8"))
>>> show(score) 
>>> agent = iterate(score)
>>> for logical_tie in agent.by_timeline_and_logical_tie():
...     logical_tie
...
LogicalTie([Note("c''4"), Note("c''8")])
LogicalTie([Rest('r8')])
LogicalTie([Note("g'4."), Note("g'8")])
LogicalTie([Note("d''8")])
LogicalTie([Rest('r4')])
LogicalTie([Rest('r16')])
LogicalTie([Note("f'8."), Note("f'8")])
LogicalTie([Note("ef''4")])
>>> expression = iterate()
>>> expression = expression.by_timeline_and_logical_tie()
>>> for logical_tie in expression(score):
...     logical_tie
...
LogicalTie([Note("c''4"), Note("c''8")])
LogicalTie([Rest('r8')])
LogicalTie([Note("g'4."), Note("g'8")])
LogicalTie([Note("d''8")])
LogicalTie([Rest('r4')])
LogicalTie([Rest('r16')])
LogicalTie([Note("f'8."), Note("f'8")])
LogicalTie([Note("ef''4")])

Timeline-iterates logical ties in reverse:

>>> score = Score([])
>>> score.append(Staff("c''4 ~ c''8 d''8 r4 ef''4"))
>>> score.append(Staff("r8 g'4. ~ g'8 r16 f'8. ~ f'8"))
>>> show(score) 
>>> agent = iterate(score)
>>> for logical_tie in agent.by_timeline_and_logical_tie(
...     reverse=True,
...     ):
...     logical_tie
...
LogicalTie([Note("ef''4")])
LogicalTie([Note("f'8."), Note("f'8")])
LogicalTie([Rest('r4')])
LogicalTie([Rest('r16')])
LogicalTie([Note("g'4."), Note("g'8")])
LogicalTie([Note("d''8")])
LogicalTie([Note("c''4"), Note("c''8")])
LogicalTie([Rest('r8')])
>>> expression = iterate()
>>> expression = expression.by_timeline_and_logical_tie(
...     reverse=True,
...     )
>>> for logical_tie in expression(score):
...     logical_tie
...
LogicalTie([Note("ef''4")])
LogicalTie([Note("f'8."), Note("f'8")])
LogicalTie([Rest('r4')])
LogicalTie([Rest('r16')])
LogicalTie([Note("g'4."), Note("g'8")])
LogicalTie([Note("d''8")])
LogicalTie([Note("c''4"), Note("c''8")])
LogicalTie([Rest('r8')])

Timeline-iterates pitched logical ties:

>>> agent = iterate(score)
>>> for logical_tie in agent.by_timeline_and_logical_tie(
...     pitched=True,
...     ):
...     logical_tie
...
LogicalTie([Note("c''4"), Note("c''8")])
LogicalTie([Note("g'4."), Note("g'8")])
LogicalTie([Note("d''8")])
LogicalTie([Note("f'8."), Note("f'8")])
LogicalTie([Note("ef''4")])
>>> expression = iterate()
>>> expression = expression.by_timeline_and_logical_tie(
...     pitched=True,
...     )
>>> for logical_tie in expression(score):
...     logical_tie
...
LogicalTie([Note("c''4"), Note("c''8")])
LogicalTie([Note("g'4."), Note("g'8")])
LogicalTie([Note("d''8")])
LogicalTie([Note("f'8."), Note("f'8")])
LogicalTie([Note("ef''4")])

Timeline-iterates nontrivial logical ties:

>>> agent = iterate(score)
>>> for logical_tie in agent.by_timeline_and_logical_tie(
...     nontrivial=True,
...     ):
...     logical_tie
...
LogicalTie([Note("c''4"), Note("c''8")])
LogicalTie([Note("g'4."), Note("g'8")])
LogicalTie([Note("f'8."), Note("f'8")])
>>> expression = iterate()
>>> expression = expression.by_timeline_and_logical_tie(
...     nontrivial=True,
...     )
>>> for logical_tie in expression(score):
...     logical_tie
...
LogicalTie([Note("c''4"), Note("c''8")])
LogicalTie([Note("g'4."), Note("g'8")])
LogicalTie([Note("f'8."), Note("f'8")])
IterationAgent.by_timeline_from_component(prototype=None, reverse=False)

Iterates from client by timeline.

Timeline-iterates from note:

>>> score = Score([])
>>> score.append(Staff("c'4 d'4 e'4 f'4"))
>>> score.append(Staff("g'8 a'8 b'8 c''8"))
>>> show(score) 
>>> agent = iterate(score[1][2])
>>> for leaf in agent.by_timeline_from_component():
...     leaf
...
Note("b'8")
Note("c''8")
Note("e'4")
Note("f'4")
>>> expression = iterate()
>>> expression = expression.by_timeline_from_component()
>>> for leaf in expression(score[1][2]):
...     leaf
...
Note("b'8")
Note("c''8")
Note("e'4")
Note("f'4")

Timeline-iterates from note in reverse:

>>> score = Score([])
>>> score.append(Staff("c'4 d'4 e'4 f'4"))
>>> score.append(Staff("g'8 a'8 b'8 c''8"))
>>> show(score) 
>>> agent = iterate(score[1][2])
>>> for leaf in agent.by_timeline_from_component(
...     reverse=True,
...     ):
...     leaf
...
Note("b'8")
Note("c'4")
Note("a'8")
Note("g'8")
>>> expression = iterate()
>>> expression = expression.by_timeline_from_component(
...     reverse=True,
...     )
>>> for leaf in expression(score[1][2]):
...     leaf
...
Note("b'8")
Note("c'4")
Note("a'8")
Note("g'8")

Returns generator.

IterationAgent.by_topmost_logical_ties_and_components()

Iterates by topmost logical ties and components.

Iterates topmost logical ties and components:

>>> string = r"c'8 ~ c'32 d'8 ~ d'32 \times 2/3 { e'8 f'8 g'8 } "
>>> string += "a'8 ~ a'32 b'8 ~ b'32"
>>> staff = Staff(string)
>>> show(staff) 
>>> agent = iterate(staff)
>>> for item in agent.by_topmost_logical_ties_and_components():
...     item
...
LogicalTie([Note("c'8"), Note("c'32")])
LogicalTie([Note("d'8"), Note("d'32")])
Tuplet(Multiplier(2, 3), "e'8 f'8 g'8")
LogicalTie([Note("a'8"), Note("a'32")])
LogicalTie([Note("b'8"), Note("b'32")])
>>> expression = iterate()
>>> expression = expression.by_topmost_logical_ties_and_components()
>>> for item in expression(staff):
...     item
...
LogicalTie([Note("c'8"), Note("c'32")])
LogicalTie([Note("d'8"), Note("d'32")])
Tuplet(Multiplier(2, 3), "e'8 f'8 g'8")
LogicalTie([Note("a'8"), Note("a'32")])
LogicalTie([Note("b'8"), Note("b'32")])

Returns generator.

IterationAgent.by_vertical_moment(reverse=False)

Iterates by vertical moment.

Iterates vertical moments:

>>> score = Score([])
>>> staff = Staff(r"\times 4/3 { d''8 c''8 b'8 }")
>>> score.append(staff)
>>> staff_group = StaffGroup([])
>>> staff_group.context_name = 'PianoStaff'
>>> staff_group.append(Staff("a'4 g'4"))
>>> staff_group.append(Staff(r"""\clef "bass" f'8 e'8 d'8 c'8"""))
>>> score.append(staff_group)
>>> show(score) 
>>> for vertical_moment in iterate(score).by_vertical_moment():
...     vertical_moment.leaves
...
(Note("d''8"), Note("a'4"), Note("f'8"))
(Note("d''8"), Note("a'4"), Note("e'8"))
(Note("c''8"), Note("a'4"), Note("e'8"))
(Note("c''8"), Note("g'4"), Note("d'8"))
(Note("b'8"), Note("g'4"), Note("d'8"))
(Note("b'8"), Note("g'4"), Note("c'8"))
>>> for vertical_moment in iterate(staff_group).by_vertical_moment():
...     vertical_moment.leaves
...
(Note("a'4"), Note("f'8"))
(Note("a'4"), Note("e'8"))
(Note("g'4"), Note("d'8"))
(Note("g'4"), Note("c'8"))
>>> expression = iterate()
>>> expression = expression.by_vertical_moment()
>>> for vertical_moment in expression(score):
...     vertical_moment.leaves
...
(Note("d''8"), Note("a'4"), Note("f'8"))
(Note("d''8"), Note("a'4"), Note("e'8"))
(Note("c''8"), Note("a'4"), Note("e'8"))
(Note("c''8"), Note("g'4"), Note("d'8"))
(Note("b'8"), Note("g'4"), Note("d'8"))
(Note("b'8"), Note("g'4"), Note("c'8"))
>>> expression = iterate()
>>> expression = expression.by_vertical_moment()
>>> for vertical_moment in expression(staff_group):
...     vertical_moment.leaves
...
(Note("a'4"), Note("f'8"))
(Note("a'4"), Note("e'8"))
(Note("g'4"), Note("d'8"))
(Note("g'4"), Note("c'8"))

Iterates vertical moments in reverse:

>>> score = Score([])
>>> staff = Staff(r"\times 4/3 { d''8 c''8 b'8 }")
>>> score.append(staff)
>>> staff_group = StaffGroup([])
>>> staff_group.context_name = 'PianoStaff'
>>> staff_group.append(Staff("a'4 g'4"))
>>> staff_group.append(Staff(r"""\clef "bass" f'8 e'8 d'8 c'8"""))
>>> score.append(staff_group)
>>> show(score) 
>>> agent = iterate(score)
>>> for vertical_moment in agent.by_vertical_moment(
...     reverse=True,
...     ):
...     vertical_moment.leaves
...
(Note("b'8"), Note("g'4"), Note("c'8"))
(Note("b'8"), Note("g'4"), Note("d'8"))
(Note("c''8"), Note("g'4"), Note("d'8"))
(Note("c''8"), Note("a'4"), Note("e'8"))
(Note("d''8"), Note("a'4"), Note("e'8"))
(Note("d''8"), Note("a'4"), Note("f'8"))
>>> agent = iterate(staff_group)
>>> for vertical_moment in agent.by_vertical_moment(
...     reverse=True,
...     ):
...     vertical_moment.leaves
...
(Note("g'4"), Note("c'8"))
(Note("g'4"), Note("d'8"))
(Note("a'4"), Note("e'8"))
(Note("a'4"), Note("f'8"))
>>> expression = iterate()
>>> expression = expression.by_vertical_moment(reverse=True)
>>> for vertical_moment in expression(score):
...     vertical_moment.leaves
...
(Note("b'8"), Note("g'4"), Note("c'8"))
(Note("b'8"), Note("g'4"), Note("d'8"))
(Note("c''8"), Note("g'4"), Note("d'8"))
(Note("c''8"), Note("a'4"), Note("e'8"))
(Note("d''8"), Note("a'4"), Note("e'8"))
(Note("d''8"), Note("a'4"), Note("f'8"))
>>> expression = iterate()
>>> expression = expression.by_vertical_moment(reverse=True)
>>> for vertical_moment in expression(staff_group):
...     vertical_moment.leaves
...
(Note("g'4"), Note("c'8"))
(Note("g'4"), Note("d'8"))
(Note("a'4"), Note("e'8"))
(Note("a'4"), Note("f'8"))

Returns generator.

IterationAgent.depth_first(capped=True, direction=Left, forbid=None, unique=True)

Iterates depth first.

Iterates depth first:

>>> score = Score([])
>>> score.append(Staff("c''4 ~ c''8 d''8 r4 ef''4"))
>>> score.append(Staff("r8 g'4. ~ g'8 r16 f'8. ~ f'8"))
>>> show(score) 
>>> for component in iterate(score).depth_first():
...     component
...
<Score<<2>>>
Staff("c''4 ~ c''8 d''8 r4 ef''4")
Note("c''4")
Note("c''8")
Note("d''8")
Rest('r4')
Note("ef''4")
Staff("r8 g'4. ~ g'8 r16 f'8. ~ f'8")
Rest('r8')
Note("g'4.")
Note("g'8")
Rest('r16')
Note("f'8.")
Note("f'8")
>>> expression = iterate()
>>> expression = expression.depth_first()
>>> for component in expression(score):
...     component
...
<Score<<2>>>
Staff("c''4 ~ c''8 d''8 r4 ef''4")
Note("c''4")
Note("c''8")
Note("d''8")
Rest('r4')
Note("ef''4")
Staff("r8 g'4. ~ g'8 r16 f'8. ~ f'8")
Rest('r8')
Note("g'4.")
Note("g'8")
Rest('r16')
Note("f'8.")
Note("f'8")

Iterates depth first in reverse:

>>> score = Score([])
>>> score.append(Staff("c''4 ~ c''8 d''8 r4 ef''4"))
>>> score.append(Staff("r8 g'4. ~ g'8 r16 f'8. ~ f'8"))
>>> show(score) 
>>> agent = iterate(score)
>>> for component in agent.depth_first(direction=Right):
...     component
...
<Score<<2>>>
Staff("r8 g'4. ~ g'8 r16 f'8. ~ f'8")
Note("f'8")
Note("f'8.")
Rest('r16')
Note("g'8")
Note("g'4.")
Rest('r8')
Staff("c''4 ~ c''8 d''8 r4 ef''4")
Note("ef''4")
Rest('r4')
Note("d''8")
Note("c''8")
Note("c''4")
>>> expression = iterate()
>>> expression = expression.depth_first(direction=Right)
>>> for component in expression(score):
...     component
...
<Score<<2>>>
Staff("r8 g'4. ~ g'8 r16 f'8. ~ f'8")
Note("f'8")
Note("f'8.")
Rest('r16')
Note("g'8")
Note("g'4.")
Rest('r8')
Staff("c''4 ~ c''8 d''8 r4 ef''4")
Note("ef''4")
Rest('r4')
Note("d''8")
Note("c''8")
Note("c''4")

Iterates depth first with grace notes:

>>> voice = Voice("c'8 [ d'8 e'8 f'8 ]")
>>> grace_notes = [Note("cf''16"), Note("bf'16")]
>>> grace = scoretools.GraceContainer(
...     grace_notes,
...     kind='grace',
...     )
>>> attach(grace, voice[1])
>>> after_grace_notes = [Note("af'16"), Note("gf'16")]
>>> after_grace = scoretools.GraceContainer(
...     after_grace_notes,
...     kind='after')
>>> attach(after_grace, voice[1])
>>> show(voice) 
>>> for component in iterate(voice).depth_first():
...     component
...
Voice("c'8 d'8 e'8 f'8")
Note("c'8")
Note("d'8")
GraceContainer("cf''16 bf'16")
Note("cf''16")
Note("bf'16")
GraceContainer("af'16 gf'16")
Note("af'16")
Note("gf'16")
Note("e'8")
Note("f'8")
>>> expression = iterate()
>>> expression = expression.depth_first()
>>> for component in expression(voice):
...     component
...
Voice("c'8 d'8 e'8 f'8")
Note("c'8")
Note("d'8")
GraceContainer("cf''16 bf'16")
Note("cf''16")
Note("bf'16")
GraceContainer("af'16 gf'16")
Note("af'16")
Note("gf'16")
Note("e'8")
Note("f'8")

Note

Reverse-iteration does not yet support grace notes. (Relatively straightforward to implement when the need arises.)

Returns generator.

Special methods

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