Parentage

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_abjad.core" { graph [label="abjad.core"]; node [color=1]; "abjad.core.Parentage.Parentage" [URL="../api/abjad/core/Parentage.html#abjad.core.Parentage.Parentage", color=black, fontcolor=white, label=Parentage, target=_top]; } subgraph "cluster_abjad.system" { graph [label="abjad.system"]; node [color=2]; "abjad.system.AbjadObject.AbjadObject" [URL="../api/abjad/core/../system/AbjadObject.html#abjad.system.AbjadObject.AbjadObject", label="Abjad\nObject", target=_top]; } subgraph cluster_builtins { graph [label=builtins]; node [color=3]; "builtins.object" [URL="https://docs.python.org/3.6/library/functions.html#object", label=object, target=_top]; } subgraph "cluster_collections.abc" { graph [label="collections.abc"]; node [color=4]; "collections.abc.Collection" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Collection", label=Collection, shape=oval, style=bold, target=_top]; "collections.abc.Container" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Container", label=Container, shape=oval, style=bold, target=_top]; "collections.abc.Iterable" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Iterable", label=Iterable, shape=oval, style=bold, target=_top]; "collections.abc.Reversible" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Reversible", label=Reversible, shape=oval, style=bold, target=_top]; "collections.abc.Sequence" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Sequence", label=Sequence, shape=oval, style=bold, target=_top]; "collections.abc.Sized" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Sized", label=Sized, shape=oval, style=bold, target=_top]; "collections.abc.Collection" -> "collections.abc.Sequence"; "collections.abc.Container" -> "collections.abc.Collection"; "collections.abc.Iterable" -> "collections.abc.Collection"; "collections.abc.Iterable" -> "collections.abc.Reversible"; "collections.abc.Reversible" -> "collections.abc.Sequence"; "collections.abc.Sized" -> "collections.abc.Collection"; } "abjad.system.AbjadObject.AbjadObject" -> "abjad.core.Parentage.Parentage"; "builtins.object" -> "abjad.system.AbjadObject.AbjadObject"; "builtins.object" -> "collections.abc.Container"; "builtins.object" -> "collections.abc.Iterable"; "builtins.object" -> "collections.abc.Sized"; "collections.abc.Sequence" -> "abjad.core.Parentage.Parentage"; }

class abjad.core.Parentage.Parentage(component=None, include_self=True, grace_notes=False)

Parentage of a component.

>>> score = abjad.Score()
>>> string = r"""\new Voice = "Treble Voice" { e'4 }"""
>>> treble_staff = abjad.Staff(string, name='Treble Staff')
>>> score.append(treble_staff)
>>> string = r"""\new Voice = "Bass Voice" { c4 }"""
>>> bass_staff = abjad.Staff(string, name='Bass Staff')
>>> clef = abjad.Clef('bass')
>>> abjad.attach(clef, bass_staff[0][0])
>>> score.append(bass_staff)
>>> abjad.show(score) 
>>> bass_voice = score['Bass Voice']
>>> note = bass_voice[0]
>>> for component in abjad.inspect(note).parentage():
...     component
... 
Note('c4')
Voice('c4', name='Bass Voice')
<Staff-"Bass Staff"{1}>
<Score<<2>>>

Attributes Summary

__getitem__ Gets argument.
__len__ Gets number of components in parentage.
component The component from which the selection was derived.
components Gets components.
depth Length of proper parentage of component.
get_first Gets first instance of prototype in parentage.
is_grace_note Is true when parentage contains a grace container.
is_orphan Is true when component has no parent.
logical_voice Gets logical voice.
parent Gets parent.
prolation Gets prolation.
root Gets root.
score_index Gets score index.
tuplet_depth Gets tuplet depth.

Special methods

(Sequence).__contains__(value)
(AbjadObject).__format__(format_specification='')

Formats Abjad object.

Set format_specification to '' or 'storage'. Interprets '' equal to 'storage'.

Returns string.

__getitem__(argument)

Gets argument.

Returns component or tuple of components.

(Sequence).__iter__()
__len__()

Gets number of components in parentage.

Returns nonnegative integer.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.

(Sequence).__reversed__()

Methods

(Sequence).count(value) → integer -- return number of occurrences of value
get_first(prototype=None)

Gets first instance of prototype in parentage.

Returns component or none.

(Sequence).index(value[, start[, stop]]) → integer -- return first index of value.

Raises ValueError if the value is not present.

Supporting start and stop arguments is optional, but recommended.


Read-only properties

component

The component from which the selection was derived.

Returns component.

components

Gets components.

Returns tuple.

depth

Length of proper parentage of component.

Returns nonnegative integer.

is_grace_note

Is true when parentage contains a grace container.

Grace notes:

>>> voice = abjad.Voice("c'4 d'4 e'4 f'4")
>>> container = abjad.GraceContainer("c'16 d'16")
>>> abjad.attach(container, voice[1])
>>> abjad.show(voice) 
>>> for leaf in abjad.iterate(voice).leaves():
...     parentage = abjad.inspect(leaf).parentage()
...     print(leaf, parentage.is_grace_note)
... 
c'4 False
c'16 True
d'16 True
d'4 False
e'4 False
f'4 False

Returns true or false.

is_orphan

Is true when component has no parent.

Returns true or false.

logical_voice

Gets logical voice.

Gets logical voice of note:

>>> voice = abjad.Voice("c'4 d'4 e'4 f'4", name='CustomVoice')
>>> staff = abjad.Staff([voice], name='CustomStaff')
>>> score = abjad.Score([staff], name='CustomScore')
>>> abjad.show(score) 
>>> note = voice[0]
>>> parentage = abjad.inspect(note).parentage()
>>> logical_voice = parentage.logical_voice
>>> for key, value in logical_voice.items():
...     print('%12s: %s' % (key, value))
... 
       score: Score-'CustomScore'
 staff group: 
       staff: Staff-'CustomStaff'
       voice: Voice-'CustomVoice'

Returns ordered dictionary.

parent

Gets parent.

Returns none when component has no parent.

Returns component or none.

prolation

Gets prolation.

Returns multiplier.

root

Gets root.

Root defined equal to last component in parentage.

Returns component.

score_index

Gets score index.

Todo

Define score index for grace notes.

Gets note score indices:

>>> staff_1 = abjad.Staff(r"\times 2/3 { c''2 b'2 a'2 }")
>>> staff_2 = abjad.Staff("c'2 d'2")
>>> score = abjad.Score([staff_1, staff_2])
>>> abjad.show(score) 
>>> for leaf in abjad.select(score).leaves():
...     parentage = abjad.inspect(leaf).parentage()
...     leaf, parentage.score_index
... 
(Note("c''2"), (0, 0, 0))
(Note("b'2"), (0, 0, 1))
(Note("a'2"), (0, 0, 2))
(Note("c'2"), (1, 0))
(Note("d'2"), (1, 1))

With grace notes:

>>> voice = abjad.Voice("c'8 [ d'8 e'8 f'8 ]")
>>> container = abjad.GraceContainer("cf''16 bf'16")
>>> abjad.attach(container, voice[1])
>>> abjad.show(voice) 
>>> leaves = abjad.iterate(voice).components()
>>> for leaf in leaves:
...     parentage = abjad.inspect(leaf).parentage()
...     leaf, parentage.score_index
... 
(Voice("c'8 d'8 e'8 f'8"), ())
(Note("c'8"), (0,))
(Note("cf''16"), (0,))
(Note("bf'16"), (1,))
(Note("d'8"), (1,))
(Note("e'8"), (2,))
(Note("f'8"), (3,))

Todo

Incorrect values returned for grace notes.

Returns tuple of zero or more nonnegative integers.

tuplet_depth

Gets tuplet depth.

Gets tuplet depth:

>>> tuplet = abjad.Tuplet((2, 3), "c'2 d'2 e'2")
>>> staff = abjad.Staff([tuplet])
>>> note = tuplet[0]
>>> abjad.show(staff) 
>>> abjad.inspect(note).parentage().tuplet_depth
1
>>> abjad.inspect(tuplet).parentage().tuplet_depth
0
>>> abjad.inspect(staff).parentage().tuplet_depth
0

Returns nonnegative integer.