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
-
(
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.
-
__len__
()¶ Gets number of components in parentage.
Returns nonnegative integer.
-
(
AbjadObject
).__repr__
()¶ Gets interpreter representation of Abjad object.
Returns string.
Methods
-
get_first
(prototype=None)¶ Gets first instance of
prototype
in parentage.Returns component or none.
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.
-