abjad.select

abjad.select.chord(argument, n, *[, ...])

Selects chord n in argument.

abjad.select.chords(argument, *[, exclude, ...])

Selects chords in argument.

abjad.select.components(argument[, ...])

Selects components.

abjad.select.exclude(argument, indices[, period])

Excludes items at indices by period.

abjad.select.filter(argument[, predicate])

Filters argument by predicate.

abjad.select.flatten(argument[, depth])

Flattens argument.

abjad.select.get(argument, indices[, ...])

Gets items in argument at indices according to period.

abjad.select.group(argument)

Groups argument in selection.

abjad.select.group_by(argument[, predicate])

Groups items in argument by predicate.

abjad.select.group_by_contiguity(argument)

Groups items in argument by contiguity.

abjad.select.group_by_duration(argument)

Groups items in argument by duration.

abjad.select.group_by_length(argument)

Groups items in argument by length.

abjad.select.group_by_measure(argument)

Groups items in argument by measure.

abjad.select.group_by_pitch(argument)

Groups items in argument by pitch.

abjad.select.leaf(argument, n, *[, exclude, ...])

Selects leaf n in argument.

abjad.select.leaves()

Selects leaves in argument.

abjad.select.logical_tie(argument[, n, ...])

Selects logical tie n in argument.

abjad.select.logical_ties(argument, *[, ...])

Selects logical ties in argument.

abjad.select.nontrivial(argument)

Selects nontrivial items in argument.

abjad.select.note(argument, n, *[, exclude, ...])

Selects note n in argument.

abjad.select.notes(argument, *[, exclude, grace])

Selects notes in argument.

abjad.select.partition_by_counts(argument, ...)

Partitions items in argument by counts.

abjad.select.partition_by_durations(...[, ...])

Partitions items in argument by durations.

abjad.select.partition_by_ratio(argument, ratio)

Partitions items in argument by ratio.

abjad.select.rest(argument, n, *[, exclude, ...])

Selects rest n in argument.

abjad.select.rests(argument, *[, exclude, grace])

Selects rests in argument.

abjad.select.run(argument, n, *[, exclude])

Selects run n in argument.

abjad.select.runs(argument, *[, exclude, grace])

Selects runs in argument.

abjad.select.top(argument, *[, exclude])

Selects top components in argument.

abjad.select.tuplet(argument, n, *[, ...])

Selects tuplet n in argument.

abjad.select.tuplets(argument, *[, exclude, ...])

Selects tuplets in argument.

abjad.select.with_next_leaf(argument, *[, grace])

Extends argument with next leaf.

abjad.select.with_previous_leaf(argument)

Extends argument with previous leaf.

abjad.select.LogicalTie([items])

Logical tie of a component.

abjad.select.chord(argument, n: int, *, exclude: str | Enum | Sequence[str | Enum] | None = None, grace: bool | None = None) Chord[source]

Selects chord n in argument.

Selects chord -1:

>>> tuplets = [
...     "r16 bf'16 <a'' b''>16 c'16 <d' e'>4 ~ <d' e'>16",
...     "r16 bf'16 <a'' b''>16 d'16 <e' fs'>4 ~ <e' fs'>16",
...     "r16 bf'16 <a'' b''>16 e'16 <fs' gs'>4 ~ <fs' gs'>16",
... ]
>>> tuplets = zip(["9:8", "9:8", "9:8"], tuplets)
>>> tuplets = [abjad.Tuplet(*_) for _ in tuplets]
>>> lilypond_file = abjad.illustrators.components(tuplets)
>>> staff = lilypond_file["Staff"]
>>> abjad.setting(staff).autoBeaming = False
>>> abjad.override(staff).TupletBracket.direction = abjad.UP
>>> abjad.override(staff).TupletBracket.staff_padding = 3
>>> abjad.show(lilypond_file)  
>>> result = abjad.select.chord(staff, -1)
>>> result
Chord("<fs' gs'>16")
>>> abjad.label.color_leaves(result, "#green")
>>> abjad.show(lilypond_file)  
abjad.select.chords(argument, *, exclude: str | Enum | Sequence[str | Enum] | None = None, grace: bool | None = None) list[Chord][source]

Selects chords in argument.

Selects chords:

>>> tuplets = [
...     "r16 bf'16 <a'' b''>16 c'16 <d' e'>4 ~ <d' e'>16",
...     "r16 bf'16 <a'' b''>16 d'16 <e' fs'>4 ~ <e' fs'>16",
...     "r16 bf'16 <a'' b''>16 e'16 <fs' gs'>4 ~ <fs' gs'>16",
... ]
>>> tuplets = zip(["9:8", "9:8", "9:8"], tuplets)
>>> tuplets = [abjad.Tuplet(*_) for _ in tuplets]
>>> lilypond_file = abjad.illustrators.components(tuplets)
>>> staff = lilypond_file["Staff"]
>>> abjad.setting(staff).autoBeaming = False
>>> abjad.override(staff).TupletBracket.direction = abjad.UP
>>> abjad.override(staff).TupletBracket.staff_padding = 3
>>> abjad.show(lilypond_file)  
>>> result = abjad.select.chords(staff)
>>> for item in result:
...     item
... 
Chord("<a'' b''>16")
Chord("<d' e'>4")
Chord("<d' e'>16")
Chord("<a'' b''>16")
Chord("<e' fs'>4")
Chord("<e' fs'>16")
Chord("<a'' b''>16")
Chord("<fs' gs'>4")
Chord("<fs' gs'>16")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> abjad.show(lilypond_file)  
abjad.select.components(argument, prototype=None, *, exclude: str | Enum | Sequence[str | Enum] | None = None, grace: bool | None = None, reverse: bool | None = None) list[Component][source]

Selects components.

Selects notes:

>>> staff = abjad.Staff("c'4 d'8 ~ d'16 e'16 ~ e'8 r4 g'8")
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.components(staff, abjad.Note)
>>> for item in result:
...     item
... 
Note("c'4")
Note("d'8")
Note("d'16")
Note("e'16")
Note("e'8")
Note("g'8")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Selects both main notes and graces when grace=None:

>>> staff = abjad.Staff("c'8 d'8 e'8 f'8")
>>> container = abjad.BeforeGraceContainer("cf''16 bf'16")
>>> abjad.attach(container, staff[1])
>>> container = abjad.AfterGraceContainer("af'16 gf'16")
>>> abjad.attach(container, staff[1])
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.components(staff, abjad.Leaf, grace=None)
>>> for item in result:
...     item
... 
Note("c'8")
Note("cf''16")
Note("bf'16")
Note("d'8")
Note("af'16")
Note("gf'16")
Note("e'8")
Note("f'8")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Works with independent after-grace containers:

>>> music_voice = abjad.Voice("c'4 d' e' f'", name="MusicVoice")
>>> container = abjad.IndependentAfterGraceContainer("gf'16")
>>> music_voice.insert(3, container)
>>> staff = abjad.Staff([music_voice])
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.components(staff, abjad.Leaf, grace=None)
>>> for item in result:
...     item
... 
Note("c'4")
Note("d'4")
Note("e'4")
Note("gf'16")
Note("f'4")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Excludes grace notes when grace=False:

>>> staff = abjad.Staff("c'8 d'8 e'8 f'8")
>>> container = abjad.BeforeGraceContainer("cf''16 bf'16")
>>> abjad.attach(container, staff[1])
>>> container = abjad.AfterGraceContainer("af'16 gf'16")
>>> abjad.attach(container, staff[1])
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.components(staff, abjad.Leaf, grace=False)
>>> for item in result:
...     item
... 
Note("c'8")
Note("d'8")
Note("e'8")
Note("f'8")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Works with independent after-grace containers:

>>> music_voice = abjad.Voice("c'4 d' e' f'", name="MusicVoice")
>>> container = abjad.IndependentAfterGraceContainer("gf'16")
>>> music_voice.insert(3, container)
>>> staff = abjad.Staff([music_voice])
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.components(staff, abjad.Leaf, grace=False)
>>> for item in result:
...     item
... 
Note("c'4")
Note("d'4")
Note("e'4")
Note("f'4")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Selects only grace notes when grace=True:

>>> staff = abjad.Staff("c'8 d'8 e'8 f'8")
>>> container = abjad.BeforeGraceContainer("cf''16 bf'16")
>>> abjad.attach(container, staff[1])
>>> container = abjad.AfterGraceContainer("af'16 gf'16")
>>> abjad.attach(container, staff[1])
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.components(staff, abjad.Leaf, grace=True)
>>> for item in result:
...     item
... 
Note("cf''16")
Note("bf'16")
Note("af'16")
Note("gf'16")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Works with independent after-grace containers:

>>> music_voice = abjad.Voice("c'4 d' e' f'", name="MusicVoice")
>>> container = abjad.IndependentAfterGraceContainer("gf'16")
>>> music_voice.insert(3, container)
>>> staff = abjad.Staff([music_voice])
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.components(staff, abjad.Leaf, grace=True)
>>> for item in result:
...     item
... 
Note("gf'16")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  
abjad.select.exclude(argument, indices: Sequence[int], period: int | None = None) list[source]

Excludes items at indices by period.

Excludes every other leaf:

>>> string = r"c'8 d'8 ~ d'8 e'8 ~ e'8 ~ e'8 r8 f'8"
>>> staff = abjad.Staff(string)
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff)
>>> result = abjad.select.exclude(result, [0], 2)
>>> for item in result:
...     item
... 
Note("d'8")
Note("e'8")
Note("e'8")
Note("f'8")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Excludes every other logical tie:

>>> string = r"c'8 d'8 ~ d'8 e'8 ~ e'8 ~ e'8 r8 f'8"
>>> staff = abjad.Staff(string)
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.logical_ties(staff, pitched=True)
>>> result = abjad.select.exclude(result, [0], 2)
>>> for item in result:
...     item
... 
LogicalTie(items=[Note("d'8"), Note("d'8")])
LogicalTie(items=[Note("f'8")])
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Excludes note 1 (or nothing) in each pitched logical tie:

>>> staff = abjad.Staff(r"c'8 d'8 ~ d'8 e'8 ~ e'8 ~ e'8 r8 f'8")
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.logical_ties(staff, pitched=True)
>>> result = [abjad.select.leaves(_) for _ in result]
>>> result = [abjad.select.exclude(_, [1]) for _ in result]
>>> for item in result:
...     item
... 
[Note("c'8")]
[Note("d'8")]
[Note("e'8"), Note("e'8")]
[Note("f'8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  
abjad.select.filter(argument, predicate=None) list[source]

Filters argument by predicate.

Selects runs with duration equal to 2/8:

>>> staff = abjad.Staff("c'8 r8 d'8 e'8 r8 f'8 g'8 a'8")
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.runs(staff)
>>> result = abjad.select.filter(
...     result, lambda _: abjad.get.duration(_) == abjad.Duration((2, 8))
... )
>>> for item in result:
...     item
... 
[Note("d'8"), Note("e'8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  
abjad.select.flatten(argument, depth: int = 1) list[source]

Flattens argument.

Selects first two leaves of each tuplet:

>>> tuplets = [
...     "r16 bf'16 <a'' b''>16 c'16 <d' e'>4 ~ <d' e'>16",
...     "r16 bf'16 <a'' b''>16 d'16 <e' fs'>4 ~ <e' fs'>16",
...     "r16 bf'16 <a'' b''>16 e'16 <fs' gs'>4 ~ <fs' gs'>16",
... ]
>>> tuplets = zip(["9:8", "9:8", "9:8"], tuplets)
>>> tuplets = [abjad.Tuplet(*_) for _ in tuplets]
>>> lilypond_file = abjad.illustrators.components(tuplets)
>>> staff = lilypond_file["Staff"]
>>> abjad.setting(staff).autoBeaming = False
>>> abjad.override(staff).TupletBracket.direction = abjad.UP
>>> abjad.override(staff).TupletBracket.staff_padding = 3
>>> abjad.show(lilypond_file)  
>>> result = abjad.select.tuplets(staff)
>>> result = [abjad.select.leaves(_)[:2] for _ in result]
>>> for item in result:
...     item
... 
[Rest('r16'), Note("bf'16")]
[Rest('r16'), Note("bf'16")]
[Rest('r16'), Note("bf'16")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> abjad.show(lilypond_file)  

Selects first two leaves of all tuplets:

>>> tuplets = [
...     "r16 bf'16 <a'' b''>16 c'16 <d' e'>4 ~ <d' e'>16",
...     "r16 bf'16 <a'' b''>16 d'16 <e' fs'>4 ~ <e' fs'>16",
...     "r16 bf'16 <a'' b''>16 e'16 <fs' gs'>4 ~ <fs' gs'>16",
... ]
>>> tuplets = zip(["9:8", "9:8", "9:8"], tuplets)
>>> tuplets = [abjad.Tuplet(*_) for _ in tuplets]
>>> lilypond_file = abjad.illustrators.components(tuplets)
>>> staff = lilypond_file["Staff"]
>>> abjad.setting(staff).autoBeaming = False
>>> abjad.override(staff).TupletBracket.direction = abjad.UP
>>> abjad.override(staff).TupletBracket.staff_padding = 3
>>> abjad.show(lilypond_file)  
>>> result = abjad.select.tuplets(staff)
>>> result = [abjad.select.leaves(_)[:2] for _ in result]
>>> result = abjad.select.flatten(result)
>>> for item in result:
...     item
... 
Rest('r16')
Note("bf'16")
Rest('r16')
Note("bf'16")
Rest('r16')
Note("bf'16")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> abjad.show(lilypond_file)  
abjad.select.get(argument, indices: Sequence[int] | tuple[list[int], int] | Pattern, period: int | None = None, *, invert: bool = False) list[source]

Gets items in argument at indices according to period.

Gets every other leaf:

>>> string = r"c'8 d'8 ~ d'8 e'8 ~ e'8 ~ e'8 r8 f'8"
>>> staff = abjad.Staff(string)
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff)
>>> result = abjad.select.get(result, [0], 2)
>>> for item in result:
...     item
... 
Note("c'8")
Note("d'8")
Note("e'8")
Rest('r8')
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Gets every other logical tie:

>>> string = r"c'8 d'8 ~ d'8 e'8 ~ e'8 ~ e'8 r8 f'8"
>>> staff = abjad.Staff(string)
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.logical_ties(staff, pitched=True)
>>> result = abjad.select.get(result, [0], 2)
>>> for item in result:
...     item
... 
LogicalTie(items=[Note("c'8")])
LogicalTie(items=[Note("e'8"), Note("e'8"), Note("e'8")])
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Gets note 1 (or nothing) in each pitched logical tie:

>>> staff = abjad.Staff(r"c'8 d'8 ~ d'8 e'8 ~ e'8 ~ e'8 r8 f'8")
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.logical_ties(staff, pitched=True)
>>> result = [abjad.select.leaves(_) for _ in result]
>>> result = [abjad.select.get(_, [1]) for _ in result]
>>> for item in result:
...     item
... 
[]
[Note("d'8")]
[Note("e'8")]
[]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  
abjad.select.group(argument) list[list][source]

Groups argument in selection.

>>> staff = abjad.Staff(
...     r"""
...     c'8 ~ c'16 c'16 r8 c'16 c'16
...     d'8 ~ d'16 d'16 r8 d'16 d'16
...     """
... )
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff, pitched=True)
>>> result = abjad.select.group(result)
>>> for item in result:
...     item
... 
[Note("c'8"), Note("c'16"), Note("c'16"), Note("c'16"), Note("c'16"), Note("d'8"), Note("d'16"), Note("d'16"), Note("d'16"), Note("d'16")]
>>> abjad.label.color_leaves(result, "#green")
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  
abjad.select.group_by(argument, predicate=None) list[list][source]

Groups items in argument by predicate.

Wraps selection in selection when predicate is none:

>>> staff = abjad.Staff(
...     r"""
...     c'8 ~ c'16 c'16 r8 c'16 c'16
...     d'8 ~ d'16 d'16 r8 d'16 d'16
...     """
... )
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff, pitched=True)
>>> result = abjad.select.group_by(result)
>>> for item in result:
...     item
... 
[Note("c'8"), Note("c'16"), Note("c'16"), Note("c'16"), Note("c'16"), Note("d'8"), Note("d'16"), Note("d'16"), Note("d'16"), Note("d'16")]
>>> abjad.label.color_leaves(result, "#green")
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  
abjad.select.group_by_contiguity(argument) list[list][source]

Groups items in argument by contiguity.

Groups pitched leaves by contiguity:

>>> string = r"c'8 d' r \times 2/3 { e' r f' } g' a' r"
>>> staff = abjad.Staff(string)
>>> abjad.setting(staff).autoBeaming = False
>>> staff.extend("r8 <c' e' g'>8 ~ <c' e' g'>4")
>>> result = abjad.select.leaves(staff, pitched=True)
>>> result = abjad.select.group_by_contiguity(result)
>>> for item in result:
...     item
... 
[Note("c'8"), Note("d'8")]
[Note("e'8")]
[Note("f'8"), Note("g'8"), Note("a'8")]
[Chord("<c' e' g'>8"), Chord("<c' e' g'>4")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Groups sixteenths by contiguity:

>>> staff = abjad.Staff("c'4 d'16 d' d' d' e'4 f'16 f' f' f'")
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff)
>>> result = abjad.select.filter(
...     result, lambda _: abjad.get.duration(_) == abjad.Duration(1, 16)
... )
>>> result = abjad.select.group_by_contiguity(result)
>>> for item in result:
...     item
... 
[Note("d'16"), Note("d'16"), Note("d'16"), Note("d'16")]
[Note("f'16"), Note("f'16"), Note("f'16"), Note("f'16")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Groups short-duration logical ties by contiguity; then gets leaf 0 in each group:

>>> staff = abjad.Staff("c'4 d'8 ~ d'16 e'16 ~ e'8 f'4 g'8")
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.logical_ties(staff)
>>> result = abjad.select.filter(
...     result, lambda _: abjad.get.duration(_) < abjad.Duration(1, 4)
... )
>>> result = abjad.select.group_by_contiguity(result)
>>> result = [abjad.select.leaf(_, 0) for _ in result]
>>> for item in result:
...     item
... 
Note("d'8")
Note("g'8")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Groups pitched leaves pitch; then regroups each group by contiguity:

>>> staff = abjad.Staff(
...     r"""
...     c'8 ~ c'16 c'16 r8 c'16 c'16
...     d'8 ~ d'16 d'16 r8 d'16 d'16
...     """
... )
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff, pitched=True)
>>> result = abjad.select.group_by_pitch(result)
>>> result = [abjad.select.group_by_contiguity(_) for _ in result]
>>> result = abjad.select.flatten(result)
>>> for item in result:
...     item
... 
[Note("c'8"), Note("c'16"), Note("c'16")]
[Note("c'16"), Note("c'16")]
[Note("d'8"), Note("d'16"), Note("d'16")]
[Note("d'16"), Note("d'16")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Groups pitched logical ties by contiguity; then regroups each group by pitch:

>>> staff = abjad.Staff(
...     r"""
...     c'8 ~ c'16 c'16 r8 c'16 c'16
...     d'8 ~ d'16 d'16 r8 d'16 d'16
...     """
... )
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.logical_ties(staff, pitched=True)
>>> result = abjad.select.group_by_contiguity(result)
>>> result = [abjad.select.group_by_pitch(_) for _ in result]
>>> result = abjad.select.flatten(result)
>>> for item in result:
...     item
... 
[LogicalTie(items=[Note("c'8"), Note("c'16")]), LogicalTie(items=[Note("c'16")])]
[LogicalTie(items=[Note("c'16")]), LogicalTie(items=[Note("c'16")])]
[LogicalTie(items=[Note("d'8"), Note("d'16")]), LogicalTie(items=[Note("d'16")])]
[LogicalTie(items=[Note("d'16")]), LogicalTie(items=[Note("d'16")])]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  
abjad.select.group_by_duration(argument) list[list][source]

Groups items in argument by duration.

Groups logical ties by duration:

>>> string = "c'4 ~ c'16 d' ~ d' d' e'4 ~ e'16 f' ~ f' f'"
>>> staff = abjad.Staff(string)
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.logical_ties(staff)
>>> result = abjad.select.group_by_duration(result)
>>> for item in result:
...     item
... 
[LogicalTie(items=[Note("c'4"), Note("c'16")])]
[LogicalTie(items=[Note("d'16"), Note("d'16")])]
[LogicalTie(items=[Note("d'16")])]
[LogicalTie(items=[Note("e'4"), Note("e'16")])]
[LogicalTie(items=[Note("f'16"), Note("f'16")])]
[LogicalTie(items=[Note("f'16")])]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  
abjad.select.group_by_length(argument) list[list][source]

Groups items in argument by length.

Groups logical ties by length:

>>> string = "c'4 ~ c'16 d' ~ d' d' e'4 ~ e'16 f' ~ f' f'"
>>> staff = abjad.Staff(string)
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.logical_ties(staff)
>>> result = abjad.select.group_by_length(result)
>>> for item in result:
...     item
... 
[LogicalTie(items=[Note("c'4"), Note("c'16")]), LogicalTie(items=[Note("d'16"), Note("d'16")])]
[LogicalTie(items=[Note("d'16")])]
[LogicalTie(items=[Note("e'4"), Note("e'16")]), LogicalTie(items=[Note("f'16"), Note("f'16")])]
[LogicalTie(items=[Note("f'16")])]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  
abjad.select.group_by_measure(argument) list[list][source]

Groups items in argument by measure.

Groups leaves by measure:

>>> staff = abjad.Staff("c'8 d' e' f' g' a' b' c''")
>>> score = abjad.Score([staff], name="Score")
>>> abjad.setting(staff).autoBeaming = False
>>> abjad.attach(abjad.TimeSignature((2, 8)), staff[0])
>>> abjad.attach(abjad.TimeSignature((3, 8)), staff[4])
>>> abjad.attach(abjad.TimeSignature((1, 8)), staff[7])
>>> result = abjad.select.leaves(staff)
>>> result = abjad.select.group_by_measure(result)
>>> for item in result:
...     item
... 
[Note("c'8"), Note("d'8")]
[Note("e'8"), Note("f'8")]
[Note("g'8"), Note("a'8"), Note("b'8")]
[Note("c''8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Groups leaves by measure and joins pairs of consecutive groups:

>>> staff = abjad.Staff("c'8 d' e' f' g' a' b' c''")
>>> score = abjad.Score([staff], name="Score")
>>> abjad.setting(staff).autoBeaming = False
>>> abjad.attach(abjad.TimeSignature((2, 8)), staff[0])
>>> abjad.attach(abjad.TimeSignature((3, 8)), staff[4])
>>> abjad.attach(abjad.TimeSignature((1, 8)), staff[7])
>>> result = abjad.select.leaves(staff)
>>> result = abjad.select.group_by_measure(result)
>>> result = abjad.select.partition_by_counts(result, [2], cyclic=True)
>>> result = [abjad.select.flatten(_) for _ in result]
>>> for item in result:
...     item
... 
[Note("c'8"), Note("d'8"), Note("e'8"), Note("f'8")]
[Note("g'8"), Note("a'8"), Note("b'8"), Note("c''8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Groups leaves by measure; then gets item 0 in each group:

>>> staff = abjad.Staff("c'8 d' e' f' g' a' b' c''")
>>> score = abjad.Score([staff], name="Score")
>>> abjad.setting(staff).autoBeaming = False
>>> abjad.attach(abjad.TimeSignature((2, 8)), staff[0])
>>> abjad.attach(abjad.TimeSignature((3, 8)), staff[4])
>>> abjad.attach(abjad.TimeSignature((1, 8)), staff[7])
>>> result = abjad.select.leaves(staff)
>>> result = abjad.select.group_by_measure(result)
>>> result = [_[0] for _ in result]
>>> for item in result:
...     item
... 
Note("c'8")
Note("e'8")
Note("g'8")
Note("c''8")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Groups leaves by measure; then gets item -1 in each group:

>>> staff = abjad.Staff("c'8 d' e' f' g' a' b' c''")
>>> score = abjad.Score([staff], name="Score")
>>> abjad.setting(staff).autoBeaming = False
>>> abjad.attach(abjad.TimeSignature((2, 8)), staff[0])
>>> abjad.attach(abjad.TimeSignature((3, 8)), staff[4])
>>> abjad.attach(abjad.TimeSignature((1, 8)), staff[7])
>>> result = abjad.select.leaves(staff)
>>> result = abjad.select.group_by_measure(result)
>>> result = [_[-1] for _ in result]
>>> for item in result:
...     item
... 
Note("d'8")
Note("f'8")
Note("b'8")
Note("c''8")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Works with implicit time signatures:

>>> staff = abjad.Staff("c'4 d' e' f' g' a' b' c''")
>>> abjad.setting(staff).autoBeaming = False
>>> score = abjad.Score([staff])
>>> string = r"\musicLength 16"
>>> abjad.setting(score).proportionalNotationDuration = string
>>> result = abjad.select.leaves(score)
>>> result = abjad.select.group_by_measure(result)
>>> for item in result:
...     item
... 
[Note("c'4"), Note("d'4"), Note("e'4"), Note("f'4")]
[Note("g'4"), Note("a'4"), Note("b'4"), Note("c''4")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Groups logical ties by measure:

>>> staff = abjad.Staff("c'8 d' ~ d' e' ~ e' f' g' ~ g'")
>>> score = abjad.Score([staff], name="Score")
>>> abjad.setting(staff).autoBeaming = False
>>> abjad.attach(abjad.TimeSignature((2, 8)), staff[0])
>>> abjad.attach(abjad.TimeSignature((3, 8)), staff[4])
>>> abjad.attach(abjad.TimeSignature((1, 8)), staff[7])
>>> result = abjad.select.logical_ties(staff)
>>> result = abjad.select.group_by_measure(result)
>>> for item in result:
...     item
... 
[LogicalTie(items=[Note("c'8")]), LogicalTie(items=[Note("d'8"), Note("d'8")])]
[LogicalTie(items=[Note("e'8"), Note("e'8")])]
[LogicalTie(items=[Note("f'8")]), LogicalTie(items=[Note("g'8"), Note("g'8")])]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

REGRESSION: works for pickup measure:

>>> staff = abjad.Staff(r"c'4 | d'4 e'4 f'4 | g'4 a'4 b'4")
>>> score = abjad.Score([staff], name="Score")
>>> time_signature = abjad.TimeSignature((3, 4), partial=abjad.Duration(1, 4))
>>> abjad.attach(time_signature, staff[0])
>>> leaves = abjad.select.leaves(staff)
>>> for measure in abjad.select.group_by_measure(leaves):
...     print(measure)
... 
[Note("c'4")]
[Note("d'4"), Note("e'4"), Note("f'4")]
[Note("g'4"), Note("a'4"), Note("b'4")]
abjad.select.group_by_pitch(argument) list[list][source]

Groups items in argument by pitch.

Groups logical ties by pitches:

>>> string = "c'4 ~ c'16 d' ~ d' d' e'4 ~ e'16 f' ~ f' f'"
>>> staff = abjad.Staff(string)
>>> abjad.setting(staff).autoBeaming = False
>>> lts = abjad.select.logical_ties(staff)
>>> result = abjad.select.group_by_pitch(lts)
>>> for item in result:
...     item
... 
[LogicalTie(items=[Note("c'4"), Note("c'16")])]
[LogicalTie(items=[Note("d'16"), Note("d'16")]), LogicalTie(items=[Note("d'16")])]
[LogicalTie(items=[Note("e'4"), Note("e'16")])]
[LogicalTie(items=[Note("f'16"), Note("f'16")]), LogicalTie(items=[Note("f'16")])]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  
abjad.select.leaf(argument, n: int, *, exclude: str | Enum | Sequence[str | Enum] | None = None, grace: bool | None = None, head: bool | None = None, pitched: bool | None = None, prototype=None, reverse: bool | None = None, tail: bool | None = None, trim: bool | Horizontal | None = None) Leaf[source]

Selects leaf n in argument.

Selects leaf -1:

>>> tuplets = [
...     "r16 bf'16 <a'' b''>16 c'16 <d' e'>4 ~ <d' e'>16",
...     "r16 bf'16 <a'' b''>16 d'16 <e' fs'>4 ~ <e' fs'>16",
...     "r16 bf'16 <a'' b''>16 e'16 <fs' gs'>4 ~ <fs' gs'>16",
... ]
>>> tuplets = zip(["9:8", "9:8", "9:8"], tuplets)
>>> tuplets = [abjad.Tuplet(*_) for _ in tuplets]
>>> lilypond_file = abjad.illustrators.components(tuplets)
>>> staff = lilypond_file["Staff"]
>>> abjad.setting(staff).autoBeaming = False
>>> abjad.override(staff).TupletBracket.direction = abjad.UP
>>> abjad.override(staff).TupletBracket.staff_padding = 3
>>> abjad.show(lilypond_file)  
>>> result = abjad.select.leaf(staff, -1)
>>> result
Chord("<fs' gs'>16")
>>> abjad.label.color_leaves(result, "#green")
>>> abjad.show(lilypond_file)  
abjad.select.leaves(argument, *, exclude: str | Enum | Sequence[str | Enum] | None = None, grace: bool | None = None, head: bool | None = None, pitched: bool | None = None, reverse: bool | None = None, tail: bool | None = None, trim: bool | Horizontal | None = None) list[Leaf][source]
abjad.select.leaves(argument, prototype: Type[Chord], *, exclude: str | Enum | Sequence[str | Enum] | None = None, grace: bool | None = None, head: bool | None = None, pitched: bool | None = None, reverse: bool | None = None, tail: bool | None = None, trim: bool | Horizontal | None = None) list[Chord]
abjad.select.leaves(argument, prototype: Type[MultimeasureRest], *, exclude: str | Enum | Sequence[str | Enum] | None = None, grace: bool | None = None, head: bool | None = None, pitched: bool | None = None, reverse: bool | None = None, tail: bool | None = None, trim: bool | Horizontal | None = None) list[MultimeasureRest]
abjad.select.leaves(argument, prototype: Type[Note], *, exclude: str | Enum | Sequence[str | Enum] | None = None, grace: bool | None = None, head: bool | None = None, pitched: bool | None = None, reverse: bool | None = None, tail: bool | None = None, trim: bool | Horizontal | None = None) list[Note]

Selects leaves in argument.

Selects leaves:

>>> staff = abjad.Staff(
...     r"""
...     \times 2/3 { r8 d' e' } f' r
...     r f' \times 2/3 { e' d' r8 }
...     """
... )
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff)
>>> for item in result:
...     item
... 
Rest('r8')
Note("d'8")
Note("e'8")
Note("f'8")
Rest('r8')
Rest('r8')
Note("f'8")
Note("e'8")
Note("d'8")
Rest('r8')
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Selects pitched leaves:

>>> staff = abjad.Staff(
...     r"""
...     \times 2/3 { r8 d' e' } f' r
...     r f' \times 2/3 { e' d' r8 }
...     """
... )
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff, pitched=True)
>>> for item in result:
...     item
... 
Note("d'8")
Note("e'8")
Note("f'8")
Note("f'8")
Note("e'8")
Note("d'8")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Trimmed leaves are the correct selection for ottava brackets.

Selects trimmed leaves:

>>> staff = abjad.Staff(
...     r"""
...     \times 2/3 { r8 d' e' } f' r
...     r f' \times 2/3 { e' d' r8 }
...     """
... )
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff, trim=True)
>>> for item in result:
...     item
... 
Note("d'8")
Note("e'8")
Note("f'8")
Rest('r8')
Rest('r8')
Note("f'8")
Note("e'8")
Note("d'8")
>>> abjad.ottava(result)
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Set trim to abjad.LEFT to trim rests at left (and preserve rests at right):

>>> staff = abjad.Staff(
...     r"""
...     \times 2/3 { r8 d' e' } f' r
...     r f' \times 2/3 { e' d' r8 }
...     """
... )
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff, trim=abjad.LEFT)
>>> for item in result:
...     item
... 
Note("d'8")
Note("e'8")
Note("f'8")
Rest('r8')
Rest('r8')
Note("f'8")
Note("e'8")
Note("d'8")
Rest('r8')
>>> abjad.ottava(result)
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

REGRESSION: selects trimmed leaves (even when there are no rests to trim):

>>> staff = abjad.Staff(
...     r"""
...     \times 2/3 { c'8 d' e' } f' r
...     r f' \times 2/3 { e' d' c' }
...     """
... )
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff, trim=True)
>>> for item in result:
...     item
... 
Note("c'8")
Note("d'8")
Note("e'8")
Note("f'8")
Rest('r8')
Rest('r8')
Note("f'8")
Note("e'8")
Note("d'8")
Note("c'8")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Selects leaves in tuplets:

>>> staff = abjad.Staff(
...     r"""
...     \times 2/3 { r8 d' e' } f' r
...     r f' \times 2/3 { e' d' r8 }
...     """
... )
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.components(staff, abjad.Tuplet)
>>> result = abjad.select.leaves(result)
>>> for item in result:
...     item
... 
Rest('r8')
Note("d'8")
Note("e'8")
Note("e'8")
Note("d'8")
Rest('r8')
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Selects trimmed leaves in tuplets:

>>> staff = abjad.Staff(
...     r"""
...     \times 2/3 { r8 d' e' } f' r
...     r f' \times 2/3 { e' d' r8 }
...     """
... )
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.components(staff, abjad.Tuplet)
>>> result = abjad.select.leaves(result, trim=True)
>>> for item in result:
...     item
... 
Note("d'8")
Note("e'8")
Note("e'8")
Note("d'8")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Pitched heads is the correct selection for most articulations.

Selects pitched heads in tuplets:

>>> staff = abjad.Staff(
...     r"""
...     \times 2/3 { c'8 d' ~ d' } e' r
...     r e' \times 2/3 { d' ~ d' c' }
...     """
... )
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.components(staff, abjad.Tuplet)
>>> result = abjad.select.leaves(result, head=True, pitched=True)
>>> for item in result:
...     item
... 
Note("c'8")
Note("d'8")
Note("d'8")
Note("c'8")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Pitched tails in the correct selection for laissez vibrer.

Selects pitched tails in tuplets:

>>> staff = abjad.Staff(
...     r"""
...     \times 2/3 { c'8 d' ~ d' } e' r
...     r e' \times 2/3 { d' ~ d' c' }
...     """
... )
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.components(staff, abjad.Tuplet)
>>> result = abjad.select.leaves(result, tail=True, pitched=True)
>>> for item in result:
...     item
... 
Note("c'8")
Note("d'8")
Note("d'8")
Note("c'8")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Chord heads are the correct selection for arpeggios.

Selects chord heads in tuplets:

>>> staff = abjad.Staff(
...     r"""
...     \times 2/3 { <c' e' g'>8 ~ <c' e' g'> d' } e' r
...     r <g d' fs'> \times 2/3 { e' <c' d'> ~ <c' d'> }
...     """
... )
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.components(staff, abjad.Tuplet)
>>> result = abjad.select.leaves(result, abjad.Chord, head=True)
>>> for item in result:
...     item
... 
Chord("<c' e' g'>8")
Chord("<c' d'>8")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Excludes leaves with "HIDDEN" indicator:

>>> staff = abjad.Staff(
...     r"""
...     \times 2/3 { r8 d' e' } f' r
...     r f' \times 2/3 { e' d' r8 }
...     """
... )
>>> abjad.attach("HIDDEN", staff[-1][-2])
>>> abjad.attach("HIDDEN", staff[-1][-1])
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff, exclude="HIDDEN")
>>> for item in result:
...     item
... 
Rest('r8')
Note("d'8")
Note("e'8")
Note("f'8")
Rest('r8')
Rest('r8')
Note("f'8")
Note("e'8")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Selects both main notes and graces when grace=None:

>>> staff = abjad.Staff("c'8 d'8 e'8 f'8")
>>> container = abjad.BeforeGraceContainer("cf''16 bf'16")
>>> abjad.attach(container, staff[1])
>>> container = abjad.AfterGraceContainer("af'16 gf'16")
>>> abjad.attach(container, staff[1])
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff, grace=None)
>>> for item in result:
...     item
... 
Note("c'8")
Note("cf''16")
Note("bf'16")
Note("d'8")
Note("af'16")
Note("gf'16")
Note("e'8")
Note("f'8")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Works with independent after-grace containers:

>>> music_voice = abjad.Voice("c'4 d' e' f'", name="MusicVoice")
>>> container = abjad.IndependentAfterGraceContainer("gf'16")
>>> music_voice.insert(3, container)
>>> staff = abjad.Staff([music_voice])
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff, grace=None)
>>> for item in result:
...     item
... 
Note("c'4")
Note("d'4")
Note("e'4")
Note("gf'16")
Note("f'4")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Excludes grace notes when grace=False:

>>> staff = abjad.Staff("c'8 d'8 e'8 f'8")
>>> container = abjad.BeforeGraceContainer("cf''16 bf'16")
>>> abjad.attach(container, staff[1])
>>> container = abjad.AfterGraceContainer("af'16 gf'16")
>>> abjad.attach(container, staff[1])
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff, grace=False)
>>> for item in result:
...     item
... 
Note("c'8")
Note("d'8")
Note("e'8")
Note("f'8")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Works with independent after-grace containers:

>>> music_voice = abjad.Voice("c'4 d' e' f'", name="MusicVoice")
>>> container = abjad.IndependentAfterGraceContainer("gf'16")
>>> music_voice.insert(3, container)
>>> staff = abjad.Staff([music_voice])
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff, grace=False)
>>> for item in result:
...     item
... 
Note("c'4")
Note("d'4")
Note("e'4")
Note("f'4")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Selects only grace notes when grace=True:

>>> staff = abjad.Staff("c'8 d'8 e'8 f'8")
>>> container = abjad.BeforeGraceContainer("cf''16 bf'16")
>>> abjad.attach(container, staff[1])
>>> container = abjad.AfterGraceContainer("af'16 gf'16")
>>> abjad.attach(container, staff[1])
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff, grace=True)
>>> for item in result:
...     item
... 
Note("cf''16")
Note("bf'16")
Note("af'16")
Note("gf'16")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Works with independent after-grace containers:

>>> music_voice = abjad.Voice("c'4 d' e' f'", name="MusicVoice")
>>> container = abjad.IndependentAfterGraceContainer("gf'16")
>>> music_voice.insert(3, container)
>>> staff = abjad.Staff([music_voice])
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff, grace=True)
>>> for item in result:
...     item
... 
Note("gf'16")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  
abjad.select.logical_tie(argument, n: int = 0, *, exclude: str | Enum | Sequence[str | Enum] | None = None, grace: bool | None = None, nontrivial: bool | None = None, pitched: bool | None = None, reverse: bool | None = None) LogicalTie[source]

Selects logical tie n in argument.

Todo

Make work on nonhead leaves.

Todo

Write examples.

Todo

Remove abjad.get.logical_tie().

abjad.select.logical_ties(argument, *, exclude: str | Enum | Sequence[str | Enum] | None = None, grace: bool | None = None, nontrivial: bool | None = None, pitched: bool | None = None, reverse: bool | None = None) list[LogicalTie][source]

Selects logical ties in argument.

Selects logical ties:

>>> staff = abjad.Staff("c'8 d' ~ { d' e' r f'~ } f' r")
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.logical_ties(staff)
>>> for item in result:
...     item
... 
LogicalTie(items=[Note("c'8")])
LogicalTie(items=[Note("d'8"), Note("d'8")])
LogicalTie(items=[Note("e'8")])
LogicalTie(items=[Rest('r8')])
LogicalTie(items=[Note("f'8"), Note("f'8")])
LogicalTie(items=[Rest('r8')])
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Selects pitched logical ties:

>>> staff = abjad.Staff("c'8 d' ~ { d' e' r f'~ } f' r")
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.logical_ties(staff, pitched=True)
>>> for item in result:
...     item
... 
LogicalTie(items=[Note("c'8")])
LogicalTie(items=[Note("d'8"), Note("d'8")])
LogicalTie(items=[Note("e'8")])
LogicalTie(items=[Note("f'8"), Note("f'8")])
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Selects pitched nontrivial logical ties:

>>> staff = abjad.Staff("c'8 d' ~ { d' e' r f'~ } f' r")
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.logical_ties(
...     staff,
...     pitched=True,
...     nontrivial=True,
... )
>>> for item in result:
...     item
... 
LogicalTie(items=[Note("d'8"), Note("d'8")])
LogicalTie(items=[Note("f'8"), Note("f'8")])
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Selects pitched logical ties (starting) in each tuplet:

>>> staff = abjad.Staff(
...     r"""
...     \times 2/3 { c'8 d' e'  ~ } e' f' ~
...     \times 2/3 { f' g' a' ~ } a' b' ~
...     \times 2/3 { b' c'' d'' }
...     """
... )
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.components(staff, abjad.Tuplet)
>>> result = [abjad.select.logical_ties(_, pitched=True) for _ in result]
>>> for item in result:
...     item
... 
[LogicalTie(items=[Note("c'8")]), LogicalTie(items=[Note("d'8")]), LogicalTie(items=[Note("e'8"), Note("e'8")])]
[LogicalTie(items=[Note("g'8")]), LogicalTie(items=[Note("a'8"), Note("a'8")])]
[LogicalTie(items=[Note("c''8")]), LogicalTie(items=[Note("d''8")])]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Selects pitched logical ties (starting) in each of the last two tuplets:

>>> staff = abjad.Staff(
...     r"""
...     \times 2/3 { c'8 d' e'  ~ } e' f' ~
...     \times 2/3 { f' g' a' ~ } a' b' ~
...     \times 2/3 { b' c'' d'' }
...     """
... )
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.components(staff, abjad.Tuplet)[-2:]
>>> result = [abjad.select.logical_ties(_, pitched=True) for _ in result]
>>> for item in result:
...     item
... 
[LogicalTie(items=[Note("g'8")]), LogicalTie(items=[Note("a'8"), Note("a'8")])]
[LogicalTie(items=[Note("c''8")]), LogicalTie(items=[Note("d''8")])]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Selects both main notes and graces when grace=None:

>>> staff = abjad.Staff("c'8 d'8 e'8 f'8")
>>> container = abjad.BeforeGraceContainer("cf''16 bf'16")
>>> abjad.attach(container, staff[1])
>>> container = abjad.AfterGraceContainer("af'16 gf'16")
>>> abjad.attach(container, staff[1])
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.logical_ties(staff, grace=None)
>>> for item in result:
...     item
... 
LogicalTie(items=[Note("c'8")])
LogicalTie(items=[Note("cf''16")])
LogicalTie(items=[Note("bf'16")])
LogicalTie(items=[Note("d'8")])
LogicalTie(items=[Note("af'16")])
LogicalTie(items=[Note("gf'16")])
LogicalTie(items=[Note("e'8")])
LogicalTie(items=[Note("f'8")])
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Works with independent after-grace containers:

>>> music_voice = abjad.Voice("c'4 d' e' f'", name="MusicVoice")
>>> container = abjad.IndependentAfterGraceContainer("gf'16")
>>> music_voice.insert(3, container)
>>> staff = abjad.Staff([music_voice])
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.logical_ties(staff, grace=None)
>>> for item in result:
...     item
... 
LogicalTie(items=[Note("c'4")])
LogicalTie(items=[Note("d'4")])
LogicalTie(items=[Note("e'4")])
LogicalTie(items=[Note("gf'16")])
LogicalTie(items=[Note("f'4")])
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Excludes grace notes when grace=False:

>>> staff = abjad.Staff("c'8 d'8 e'8 f'8")
>>> container = abjad.BeforeGraceContainer("cf''16 bf'16")
>>> abjad.attach(container, staff[1])
>>> container = abjad.AfterGraceContainer("af'16 gf'16")
>>> abjad.attach(container, staff[1])
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.logical_ties(staff, grace=False)
>>> for item in result:
...     item
... 
LogicalTie(items=[Note("c'8")])
LogicalTie(items=[Note("d'8")])
LogicalTie(items=[Note("e'8")])
LogicalTie(items=[Note("f'8")])
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Works with independent after-grace containers:

>>> music_voice = abjad.Voice("c'4 d' e' f'", name="MusicVoice")
>>> container = abjad.IndependentAfterGraceContainer("gf'16")
>>> music_voice.insert(3, container)
>>> staff = abjad.Staff([music_voice])
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.logical_ties(staff, grace=False)
>>> for item in result:
...     item
... 
LogicalTie(items=[Note("c'4")])
LogicalTie(items=[Note("d'4")])
LogicalTie(items=[Note("e'4")])
LogicalTie(items=[Note("f'4")])
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Selects only grace notes when grace=True:

>>> staff = abjad.Staff("c'8 d'8 e'8 f'8")
>>> container = abjad.BeforeGraceContainer("cf''16 bf'16")
>>> abjad.attach(container, staff[1])
>>> container = abjad.AfterGraceContainer("af'16 gf'16")
>>> abjad.attach(container, staff[1])
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.logical_ties(staff, grace=True)
>>> for item in result:
...     item
... 
LogicalTie(items=[Note("cf''16")])
LogicalTie(items=[Note("bf'16")])
LogicalTie(items=[Note("af'16")])
LogicalTie(items=[Note("gf'16")])
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Works with independent after-grace containers:

>>> music_voice = abjad.Voice("c'4 d' e' f'", name="MusicVoice")
>>> container = abjad.IndependentAfterGraceContainer("gf'16")
>>> music_voice.insert(3, container)
>>> staff = abjad.Staff([music_voice])
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.logical_ties(staff, grace=True)
>>> for item in result:
...     item
... 
LogicalTie(items=[Note("gf'16")])
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  
abjad.select.nontrivial(argument) list[source]

Selects nontrivial items in argument.

Selects nontrivial runs:

>>> staff = abjad.Staff("c'8 r8 d'8 e'8 r8 f'8 g'8 a'8")
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.runs(staff)
>>> result = abjad.select.nontrivial(result)
>>> for item in result:
...     item
... 
[Note("d'8"), Note("e'8")]
[Note("f'8"), Note("g'8"), Note("a'8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  
abjad.select.note(argument, n: int, *, exclude: str | Enum | Sequence[str | Enum] | None = None, grace: bool | None = None) Note[source]

Selects note n in argument.

Selects note -1:

>>> tuplets = [
...     "r16 bf'16 <a'' b''>16 c'16 <d' e'>4 ~ <d' e'>16",
...     "r16 bf'16 <a'' b''>16 d'16 <e' fs'>4 ~ <e' fs'>16",
...     "r16 bf'16 <a'' b''>16 e'16 <fs' gs'>4 ~ <fs' gs'>16",
... ]
>>> tuplets = zip(["9:8", "9:8", "9:8"], tuplets)
>>> tuplets = [abjad.Tuplet(*_) for _ in tuplets]
>>> lilypond_file = abjad.illustrators.components(tuplets)
>>> staff = lilypond_file["Staff"]
>>> abjad.setting(staff).autoBeaming = False
>>> abjad.override(staff).TupletBracket.direction = abjad.UP
>>> abjad.override(staff).TupletBracket.staff_padding = 3
>>> abjad.show(lilypond_file)  
>>> result = abjad.select.note(staff, -1)
>>> result
Note("e'16")
>>> abjad.label.color_leaves(result, "#green")
>>> abjad.show(lilypond_file)  
abjad.select.notes(argument, *, exclude: str | Enum | Sequence[str | Enum] | None = None, grace: bool | None = None) list[Note][source]

Selects notes in argument.

Selects notes:

>>> tuplets = [
...     "r16 bf'16 <a'' b''>16 c'16 <d' e'>4 ~ <d' e'>16",
...     "r16 bf'16 <a'' b''>16 d'16 <e' fs'>4 ~ <e' fs'>16",
...     "r16 bf'16 <a'' b''>16 e'16 <fs' gs'>4 ~ <fs' gs'>16",
... ]
>>> tuplets = zip(["9:8", "9:8", "9:8"], tuplets)
>>> tuplets = [abjad.Tuplet(*_) for _ in tuplets]
>>> lilypond_file = abjad.illustrators.components(tuplets)
>>> staff = lilypond_file["Staff"]
>>> abjad.setting(staff).autoBeaming = False
>>> abjad.override(staff).TupletBracket.direction = abjad.UP
>>> abjad.override(staff).TupletBracket.staff_padding = 3
>>> abjad.show(lilypond_file)  
>>> result = abjad.select.notes(staff)
>>> for item in result:
...     item
... 
Note("bf'16")
Note("c'16")
Note("bf'16")
Note("d'16")
Note("bf'16")
Note("e'16")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> abjad.show(lilypond_file)  
abjad.select.partition_by_counts(argument, counts, *, cyclic: bool = False, enchain: bool = False, fuse_overhang: bool = False, nonempty: bool = False, overhang: bool | Comparison = False) list[list][source]

Partitions items in argument by counts.

Partitions leaves into a single part of length 3; truncates overhang:

>>> staff = abjad.Staff("c'8 r8 d'8 e'8 r8 f'8 g'8 a'8")
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff)
>>> result = abjad.select.partition_by_counts(
...     result,
...     [3],
...     cyclic=False,
...     overhang=False,
... )
>>> for item in result:
...     item
... 
[Note("c'8"), Rest('r8'), Note("d'8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Cyclically partitions leaves into parts of length 3; truncates overhang:

>>> staff = abjad.Staff("c'8 r8 d'8 e'8 r8 f'8 g'8 a'8")
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff)
>>> result = abjad.select.partition_by_counts(
...     result,
...     [3],
...     cyclic=True,
...     overhang=False,
... )
>>> for item in result:
...     item
... 
[Note("c'8"), Rest('r8'), Note("d'8")]
[Note("e'8"), Rest('r8'), Note("f'8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Cyclically partitions leaves into parts of length 3; returns overhang at end:

>>> staff = abjad.Staff("c'8 r8 d'8 e'8 r8 f'8 g'8 a'8")
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff)
>>> result = abjad.select.partition_by_counts(
...     result,
...     [3],
...     cyclic=True,
...     overhang=True,
... )
>>> for item in result:
...     item
... 
[Note("c'8"), Rest('r8'), Note("d'8")]
[Note("e'8"), Rest('r8'), Note("f'8")]
[Note("g'8"), Note("a'8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Cyclically partitions leaves into parts of length 3; fuses overhang to last part:

>>> staff = abjad.Staff("c'8 r8 d'8 e'8 r8 f'8 g'8 a'8")
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff)
>>> result = abjad.select.partition_by_counts(
...     result,
...     [3],
...     cyclic=True,
...     fuse_overhang=True,
...     overhang=True,
... )
>>> for item in result:
...     item
... 
[Note("c'8"), Rest('r8'), Note("d'8")]
[Note("e'8"), Rest('r8'), Note("f'8"), Note("g'8"), Note("a'8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Cyclically partitions leaves into parts of length 3; returns overhang at end:

>>> string = "c'8 r8 d'8 e'8 r8 f'8 g'8 a'8 b'8 r8 c''8"
>>> staff = abjad.Staff(string)
>>> abjad.setting(staff).autoBeaming = False
>>> leaves = abjad.select.leaves(staff)
>>> result = abjad.select.partition_by_counts(
...     leaves,
...     [1, 2, 3],
...     cyclic=True,
...     overhang=True,
... )
>>> for item in result:
...     item
... 
[Note("c'8")]
[Rest('r8'), Note("d'8")]
[Note("e'8"), Rest('r8'), Note("f'8")]
[Note("g'8")]
[Note("a'8"), Note("b'8")]
[Rest('r8'), Note("c''8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue", "#cyan"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

With negative counts.

Partitions leaves alternately into parts 2 and -3 (without overhang):

>>> string = "c'8 r8 d'8 e'8 r8 f'8 g'8 a'8 b'8 r8 c''8"
>>> staff = abjad.Staff(string)
>>> abjad.setting(staff).autoBeaming = False
>>> leaves = abjad.select.leaves(staff)
>>> result = abjad.select.partition_by_counts(
...     leaves,
...     [2, -3],
...     cyclic=True,
... )
>>> for item in result:
...     item
... 
[Note("c'8"), Rest('r8')]
[Note("f'8"), Note("g'8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

With negative counts.

Partitions leaves alternately into parts 2 and -3 (with overhang):

>>> string = "c'8 r8 d'8 e'8 r8 f'8 g'8 a'8 b'8 r8 c''8"
>>> staff = abjad.Staff(string)
>>> abjad.setting(staff).autoBeaming = False
>>> leaves = abjad.select.leaves(staff)
>>> result = abjad.select.partition_by_counts(
...     leaves,
...     [2, -3],
...     cyclic=True,
...     overhang=True,
... )
>>> for item in result:
...     item
... 
[Note("c'8"), Rest('r8')]
[Note("f'8"), Note("g'8")]
[Note("c''8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

REGRESSION. Noncyclic counts work when overhang is true:

>>> string = "c'8 r8 d'8 e'8 r8 f'8 g'8 a'8 b'8 r8 c''8"
>>> staff = abjad.Staff(string)
>>> abjad.setting(staff).autoBeaming = False
>>> leaves = abjad.select.leaves(staff)
>>> result = abjad.select.partition_by_counts(
...     leaves,
...     [3],
...     overhang=True,
... )
>>> for item in result:
...     item
... 
[Note("c'8"), Rest('r8'), Note("d'8")]
[Note("e'8"), Rest('r8'), Note("f'8"), Note("g'8"), Note("a'8"), Note("b'8"), Rest('r8'), Note("c''8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  
abjad.select.partition_by_durations(argument, durations, *, cyclic: bool = False, fill: Comparison | None = None, in_seconds: bool = False, overhang: bool | Comparison = False) list[list][source]

Partitions items in argument by durations.

Interprets fill as Exact when fill is none.

Parts must equal durations exactly when fill is Exact.

Parts must be less than or equal to durations when fill is Less.

Parts must be greater or equal to durations when fill is More.

Reads durations cyclically when cyclic is true.

Reads component durations in seconds when in_seconds is true.

Returns remaining components at end in final part when overhang is true.

Cyclically partitions leaves into parts equal to exactly 3/8; returns overhang at end:

>>> staff = abjad.Staff(
...     [
...         abjad.Container("c'8 d'"),
...         abjad.Container("e'8 f'"),
...         abjad.Container("g'8 a'"),
...         abjad.Container("b'8 c''"),
...     ]
... )
>>> score = abjad.Score([staff], name="Score")
>>> for container in staff:
...     time_signature = abjad.TimeSignature((2, 8))
...     abjad.attach(time_signature, container[0])
... 
>>> abjad.setting(staff).autoBeaming = False
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  
>>> leaves = abjad.select.leaves(staff)
>>> result = abjad.select.partition_by_durations(
...     leaves,
...     [abjad.Duration(3, 8)],
...     cyclic=True,
...     fill=abjad.EXACT,
...     in_seconds=False,
...     overhang=True,
... )
>>> for item in result:
...     item
... 
[Note("c'8"), Note("d'8"), Note("e'8")]
[Note("f'8"), Note("g'8"), Note("a'8")]
[Note("b'8"), Note("c''8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Partitions leaves into one part equal to exactly 3/8; truncates overhang:

>>> staff = abjad.Staff(
...     [
...         abjad.Container("c'8 d'"),
...         abjad.Container("e'8 f'"),
...         abjad.Container("g'8 a'"),
...         abjad.Container("b'8 c''"),
...     ]
... )
>>> score = abjad.Score([staff], name="Score")
>>> for container in staff:
...     time_signature = abjad.TimeSignature((2, 8))
...     abjad.attach(time_signature, container[0])
... 
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff)
>>> result = abjad.select.partition_by_durations(
...     result,
...     [abjad.Duration(3, 8)],
...     cyclic=False,
...     fill=abjad.EXACT,
...     in_seconds=False,
...     overhang=False,
... )
>>> for item in result:
...     item
... 
[Note("c'8"), Note("d'8"), Note("e'8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Cyclically partitions leaves into parts equal to (or just less than) 3/16 and 1/16; returns overhang at end:

>>> staff = abjad.Staff(
...     [
...         abjad.Container("c'8 d'"),
...         abjad.Container("e'8 f'"),
...         abjad.Container("g'8 a'"),
...         abjad.Container("b'8 c''"),
...     ]
... )
>>> score = abjad.Score([staff], name="Score")
>>> for container in staff:
...     time_signature = abjad.TimeSignature((2, 8))
...     abjad.attach(time_signature, container[0])
... 
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff)
>>> result = abjad.select.partition_by_durations(
...     result,
...     [abjad.Duration(3, 16), abjad.Duration(1, 16)],
...     cyclic=True,
...     fill=abjad.MORE,
...     in_seconds=False,
...     overhang=True,
... )
>>> for item in result:
...     item
... 
[Note("c'8"), Note("d'8")]
[Note("e'8")]
[Note("f'8"), Note("g'8")]
[Note("a'8")]
[Note("b'8"), Note("c''8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Cyclically partitions leaves into parts equal to (or just less than) 3/16; truncates overhang:

>>> staff = abjad.Staff(
...     [
...         abjad.Container("c'8 d'"),
...         abjad.Container("e'8 f'"),
...         abjad.Container("g'8 a'"),
...         abjad.Container("b'8 c''"),
...     ]
... )
>>> score = abjad.Score([staff], name="Score")
>>> for container in staff:
...     time_signature = abjad.TimeSignature((2, 8))
...     abjad.attach(time_signature, container[0])
... 
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff)
>>> result = abjad.select.partition_by_durations(
...     result,
...     [abjad.Duration(3, 16)],
...     cyclic=True,
...     fill=abjad.LESS,
...     in_seconds=False,
...     overhang=False,
... )
>>> for item in result:
...     item
... 
[Note("c'8")]
[Note("d'8")]
[Note("e'8")]
[Note("f'8")]
[Note("g'8")]
[Note("a'8")]
[Note("b'8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Partitions leaves into a single part equal to (or just less than) 3/16; truncates overhang:

>>> staff = abjad.Staff(
...     [
...         abjad.Container("c'8 d'"),
...         abjad.Container("e'8 f'"),
...         abjad.Container("g'8 a'"),
...         abjad.Container("b'8 c''"),
...     ]
... )
>>> score = abjad.Score([staff], name="Score")
>>> for container in staff:
...     time_signature = abjad.TimeSignature((2, 8))
...     abjad.attach(time_signature, container[0])
... 
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff)
>>> result = abjad.select.partition_by_durations(
...     result,
...     [abjad.Duration(3, 16)],
...     cyclic=False,
...     fill=abjad.LESS,
...     in_seconds=False,
...     overhang=False,
... )
>>> for item in result:
...     item
... 
[Note("c'8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Cyclically partitions leaves into parts equal to exactly 1.5 seconds; truncates overhang:

>>> staff = abjad.Staff(
...     [
...         abjad.Container("c'8 d'"),
...         abjad.Container("e'8 f'"),
...         abjad.Container("g'8 a'"),
...         abjad.Container("b'8 c''"),
...     ]
... )
>>> score = abjad.Score([staff], name="Score")
>>> for container in staff:
...     time_signature = abjad.TimeSignature((2, 8))
...     abjad.attach(time_signature, container[0])
... 
>>> abjad.setting(staff).autoBeaming = False
>>> mark = abjad.MetronomeMark(abjad.Duration(1, 4), 60)
>>> leaf = abjad.get.leaf(staff, 0)
>>> abjad.attach(mark, leaf, context="Staff")
>>> result = abjad.select.leaves(staff)
>>> result = abjad.select.partition_by_durations(
...     result,
...     [1.5],
...     cyclic=True,
...     fill=abjad.EXACT,
...     in_seconds=True,
...     overhang=False,
... )
>>> for item in result:
...     item
... 
[Note("c'8"), Note("d'8"), Note("e'8")]
[Note("f'8"), Note("g'8"), Note("a'8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Cyclically partitions leaves into parts equal to exactly 1.5 seconds; returns overhang at end:

>>> staff = abjad.Staff(
...     [
...         abjad.Container("c'8 d'"),
...         abjad.Container("e'8 f'"),
...         abjad.Container("g'8 a'"),
...         abjad.Container("b'8 c''"),
...     ]
... )
>>> score = abjad.Score([staff], name="Score")
>>> for container in staff:
...     time_signature = abjad.TimeSignature((2, 8))
...     abjad.attach(time_signature, container[0])
... 
>>> abjad.setting(staff).autoBeaming = False
>>> mark = abjad.MetronomeMark(abjad.Duration(1, 4), 60)
>>> leaf = abjad.get.leaf(staff, 0)
>>> abjad.attach(mark, leaf, context="Staff")
>>> result = abjad.select.leaves(staff)
>>> result = abjad.select.partition_by_durations(
...     result,
...     [1.5],
...     cyclic=True,
...     fill=abjad.EXACT,
...     in_seconds=True,
...     overhang=True,
... )
>>> for item in result:
...     item
... 
[Note("c'8"), Note("d'8"), Note("e'8")]
[Note("f'8"), Note("g'8"), Note("a'8")]
[Note("b'8"), Note("c''8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Partitions leaves into a single part equal to exactly 1.5 seconds; truncates overhang:

>>> staff = abjad.Staff(
...     [
...         abjad.Container("c'8 d'"),
...         abjad.Container("e'8 f'"),
...         abjad.Container("g'8 a'"),
...         abjad.Container("b'8 c''"),
...     ]
... )
>>> score = abjad.Score([staff], name="Score")
>>> for container in staff:
...     time_signature = abjad.TimeSignature((2, 8))
...     abjad.attach(time_signature, container[0])
... 
>>> abjad.setting(staff).autoBeaming = False
>>> mark = abjad.MetronomeMark(abjad.Duration(1, 4), 60)
>>> leaf = abjad.get.leaf(staff, 0)
>>> abjad.attach(mark, leaf, context="Staff")
>>> result = abjad.select.leaves(staff)
>>> result = abjad.select.partition_by_durations(
...     result,
...     [1.5],
...     cyclic=False,
...     fill=abjad.EXACT,
...     in_seconds=True,
...     overhang=False,
... )
>>> for item in result:
...     item
... 
[Note("c'8"), Note("d'8"), Note("e'8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Cyclically partitions leaves into parts equal to (or just less than) 0.75 seconds; truncates overhang:

>>> staff = abjad.Staff(
...     [
...         abjad.Container("c'8 d'"),
...         abjad.Container("e'8 f'"),
...         abjad.Container("g'8 a'"),
...         abjad.Container("b'8 c''"),
...     ]
... )
>>> score = abjad.Score([staff], name="Score")
>>> for container in staff:
...     time_signature = abjad.TimeSignature((2, 8))
...     abjad.attach(time_signature, container[0])
... 
>>> abjad.setting(staff).autoBeaming = False
>>> mark = abjad.MetronomeMark(abjad.Duration(1, 4), 60)
>>> leaf = abjad.get.leaf(staff, 0)
>>> abjad.attach(mark, leaf, context="Staff")
>>> result = abjad.select.leaves(staff)
>>> result = abjad.select.partition_by_durations(
...     result,
...     [0.75],
...     cyclic=True,
...     fill=abjad.LESS,
...     in_seconds=True,
...     overhang=False,
... )
>>> for item in result:
...     item
... 
[Note("c'8")]
[Note("d'8")]
[Note("e'8")]
[Note("f'8")]
[Note("g'8")]
[Note("a'8")]
[Note("b'8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Partitions leaves into one part equal to (or just less than) 0.75 seconds; truncates overhang:

>>> staff = abjad.Staff(
...     [
...         abjad.Container("c'8 d'"),
...         abjad.Container("e'8 f'"),
...         abjad.Container("g'8 a'"),
...         abjad.Container("b'8 c''"),
...     ]
... )
>>> score = abjad.Score([staff], name="Score")
>>> for container in staff:
...     time_signature = abjad.TimeSignature((2, 8))
...     abjad.attach(time_signature, container[0])
... 
>>> abjad.setting(staff).autoBeaming = False
>>> mark = abjad.MetronomeMark(abjad.Duration(1, 4), 60)
>>> leaf = abjad.get.leaf(staff, 0)
>>> abjad.attach(mark, leaf, context="Staff")
>>> result = abjad.select.leaves(staff)
>>> result = abjad.select.partition_by_durations(
...     result,
...     [0.75],
...     cyclic=False,
...     fill=abjad.LESS,
...     in_seconds=True,
...     overhang=False,
... )
>>> for item in result:
...     item
... 
[Note("c'8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  
abjad.select.partition_by_ratio(argument, ratio: tuple[int, ...]) list[list][source]

Partitions items in argument by ratio.

Partitions leaves by a ratio of 1:1:

>>> string = r"c'8 d' r \times 2/3 { e' r f' } g' a' r"
>>> staff = abjad.Staff(string)
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff)
>>> result = abjad.select.partition_by_ratio(result, (1, 1))
>>> for item in result:
...     item
... 
[Note("c'8"), Note("d'8"), Rest('r8'), Note("e'8"), Rest('r8')]
[Note("f'8"), Note("g'8"), Note("a'8"), Rest('r8')]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Partitions leaves by a ratio of 1:1:1:

>>> string = r"c'8 d' r \times 2/3 { e' r f' } g' a' r"
>>> staff = abjad.Staff(string)
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff)
>>> result = abjad.select.partition_by_ratio(result, (1, 1, 1))
>>> for item in result:
...     item
... 
[Note("c'8"), Note("d'8"), Rest('r8')]
[Note("e'8"), Rest('r8'), Note("f'8")]
[Note("g'8"), Note("a'8"), Rest('r8')]
>>> abjad.label.color_leaves(result, ["#red", "#blue", "#cyan"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  
abjad.select.rest(argument, n: int, *, exclude: str | Enum | Sequence[str | Enum] | None = None, grace: bool | None = None) Rest | MultimeasureRest[source]

Selects rest n in argument.

Selects rest -1:

>>> tuplets = [
...     "r16 bf'16 <a'' b''>16 c'16 <d' e'>4 ~ <d' e'>16",
...     "r16 bf'16 <a'' b''>16 d'16 <e' fs'>4 ~ <e' fs'>16",
...     "r16 bf'16 <a'' b''>16 e'16 <fs' gs'>4 ~ <fs' gs'>16",
... ]
>>> tuplets = zip(["9:8", "9:8", "9:8"], tuplets)
>>> tuplets = [abjad.Tuplet(*_) for _ in tuplets]
>>> lilypond_file = abjad.illustrators.components(tuplets)
>>> staff = lilypond_file["Staff"]
>>> abjad.setting(staff).autoBeaming = False
>>> abjad.override(staff).TupletBracket.direction = abjad.UP
>>> abjad.override(staff).TupletBracket.staff_padding = 3
>>> abjad.show(lilypond_file)  
>>> result = abjad.select.rest(staff, -1)
>>> result
Rest('r16')
>>> abjad.label.color_leaves(result, "#green")
>>> abjad.show(lilypond_file)  
abjad.select.rests(argument, *, exclude: str | Enum | Sequence[str | Enum] | None = None, grace: bool | None = None) list[Rest | MultimeasureRest][source]

Selects rests in argument.

Selects rests:

>>> tuplets = [
...     "r16 bf'16 <a'' b''>16 c'16 <d' e'>4 ~ <d' e'>16",
...     "r16 bf'16 <a'' b''>16 d'16 <e' fs'>4 ~ <e' fs'>16",
...     "r16 bf'16 <a'' b''>16 e'16 <fs' gs'>4 ~ <fs' gs'>16",
... ]
>>> tuplets = zip(["9:8", "9:8", "9:8"], tuplets)
>>> tuplets = [abjad.Tuplet(*_) for _ in tuplets]
>>> lilypond_file = abjad.illustrators.components(tuplets)
>>> staff = lilypond_file["Staff"]
>>> abjad.setting(staff).autoBeaming = False
>>> abjad.override(staff).TupletBracket.direction = abjad.UP
>>> abjad.override(staff).TupletBracket.staff_padding = 3
>>> abjad.show(lilypond_file)  
>>> result = abjad.select.rests(staff)
>>> for item in result:
...     item
... 
Rest('r16')
Rest('r16')
Rest('r16')
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> abjad.show(lilypond_file)  
abjad.select.run(argument, n: int, *, exclude: str | Enum | Sequence[str | Enum] | None = None) list[Leaf][source]

Selects run n in argument.

Selects run -1:

>>> tuplets = [
...     "r16 c'16 c'16 c'16 <d' e'>4 ~ <d' e'>16",
...     "r16 d'16 d'16 d'16 <e' fs'>4 ~ <e' fs'>16",
...     "r16 e'16 e'16 e'16 <fs' gs'>4 ~ <fs' gs'>16",
... ]
>>> tuplets = zip(["9:8", "9:8", "9:8"], tuplets)
>>> tuplets = [abjad.Tuplet(*_) for _ in tuplets]
>>> lilypond_file = abjad.illustrators.components(tuplets)
>>> staff = lilypond_file["Staff"]
>>> abjad.setting(staff).autoBeaming = False
>>> abjad.override(staff).TupletBracket.direction = abjad.UP
>>> abjad.override(staff).TupletBracket.staff_padding = 3
>>> abjad.show(lilypond_file)  
>>> result = abjad.select.run(staff, -1)
>>> result
[Note("e'16"), Note("e'16"), Note("e'16"), Chord("<fs' gs'>4"), Chord("<fs' gs'>16")]
>>> abjad.label.color_leaves(result, "#green")
>>> abjad.show(lilypond_file)  
abjad.select.runs(argument, *, exclude: str | Enum | Sequence[str | Enum] | None = None, grace: bool | None = None) list[list][source]

Selects runs in argument.

Selects runs:

>>> tuplets = [
...     "r16 c'16 c'16 c'16 <d' e'>4 ~ <d' e'>16",
...     "r16 d'16 d'16 d'16 <e' fs'>4 ~ <e' fs'>16",
...     "r16 e'16 e'16 e'16 <fs' gs'>4 ~ <fs' gs'>16",
... ]
>>> tuplets = zip(["9:8", "9:8", "9:8"], tuplets)
>>> tuplets = [abjad.Tuplet(*_) for _ in tuplets]
>>> lilypond_file = abjad.illustrators.components(tuplets)
>>> staff = lilypond_file["Staff"]
>>> abjad.setting(staff).autoBeaming = False
>>> abjad.override(staff).TupletBracket.direction = abjad.UP
>>> abjad.override(staff).TupletBracket.staff_padding = 3
>>> abjad.show(lilypond_file)  
>>> result = abjad.select.runs(staff)
>>> for item in result:
...     item
... 
[Note("c'16"), Note("c'16"), Note("c'16"), Chord("<d' e'>4"), Chord("<d' e'>16")]
[Note("d'16"), Note("d'16"), Note("d'16"), Chord("<e' fs'>4"), Chord("<e' fs'>16")]
[Note("e'16"), Note("e'16"), Note("e'16"), Chord("<fs' gs'>4"), Chord("<fs' gs'>16")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> abjad.show(lilypond_file)  

REGRESSION. Works with grace note (and containers):

>>> music_voice = abjad.Voice("c'16 d' e' r d'4 e' r8 f'", name="MusicVoice")
>>> container = abjad.BeforeGraceContainer("cs'16")
>>> abjad.attach(container, music_voice[4])
>>> obgc = abjad.on_beat_grace_container("g'16 gs' a' as'", music_voice[5:7])
>>> abjad.attach(abjad.Articulation(">"), obgc[0])
>>> container = abjad.AfterGraceContainer("fs'16")
>>> abjad.attach(container, music_voice[-1])
>>> staff = abjad.Staff([music_voice])
>>> result = abjad.select.runs(staff)
>>> for item in result:
...     item
... 
[Note("c'16"), Note("d'16"), Note("e'16")]
[Note("cs'16"), Note("d'4"), Chord("<e' g'>16"), Note("gs'16"), Note("a'16"), Note("as'16"), Note("e'4")]
[Note("f'8"), Note("fs'16")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  
abjad.select.top(argument, *, exclude: str | Enum | Sequence[str | Enum] | None = None) list[Component][source]

Selects top components in argument.

Selects top components (up from leaves):

>>> string = r"c'8 d' r \times 2/3 { e' r f' } g' a' r"
>>> staff = abjad.Staff(string)
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.leaves(staff)
>>> result = abjad.select.top(result)
>>> for item in result:
...     item
... 
Note("c'8")
Note("d'8")
Rest('r8')
Tuplet('3:2', "e'8 r8 f'8")
Note("g'8")
Note("a'8")
Rest('r8')
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  
abjad.select.tuplet(argument, n: int, *, exclude: str | Enum | Sequence[str | Enum] | None = None, level: int | None = None) Tuplet[source]

Selects tuplet n in argument.

Selects tuplet -1:

>>> tuplets = [
...     "r16 bf'16 <a'' b''>16 c'16 <d' e'>4 ~ <d' e'>16",
...     "r16 bf'16 <a'' b''>16 d'16 <e' fs'>4 ~ <e' fs'>16",
...     "r16 bf'16 <a'' b''>16 e'16 <fs' gs'>4 ~ <fs' gs'>16",
... ]
>>> tuplets = zip(["9:8", "9:8", "9:8"], tuplets)
>>> tuplets = [abjad.Tuplet(*_) for _ in tuplets]
>>> lilypond_file = abjad.illustrators.components(tuplets)
>>> staff = lilypond_file["Staff"]
>>> abjad.setting(staff).autoBeaming = False
>>> abjad.override(staff).TupletBracket.direction = abjad.UP
>>> abjad.override(staff).TupletBracket.staff_padding = 3
>>> abjad.show(lilypond_file)  
>>> result = abjad.select.tuplet(staff, -1)
>>> result
Tuplet('9:8', "r16 bf'16 <a'' b''>16 e'16 <fs' gs'>4 <fs' gs'>16")
>>> abjad.label.color_leaves(result, "#green")
>>> abjad.show(lilypond_file)  
abjad.select.tuplets(argument, *, exclude: str | Enum | Sequence[str | Enum] | None = None, level: int | None = None) list[Tuplet][source]

Selects tuplets in argument.

Selects tuplets at every level:

>>> staff = abjad.Staff(
...     r"\times 2/3 { c'2 \times 2/3 { d'8 e' f' } } \times 2/3 { c'4 d' e' }"
... )
>>> result = abjad.select.tuplets(staff)
>>> for item in result:
...     item
... 
Tuplet('3:2', "c'2 { 3:2 d'8 e'8 f'8 }")
Tuplet('3:2', "d'8 e'8 f'8")
Tuplet('3:2', "c'4 d'4 e'4")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Selects tuplets at level -1; tuplets at level -1 are bottom-level tuplet: tuplets at level -1 contain only one tuplet (themselves) and do not contain any other tuplets:

>>> staff = abjad.Staff(
...     r"\times 2/3 { c'2 \times 2/3 { d'8 e' f' } } \times 2/3 { c'4 d' e' }"
... )
>>> result = abjad.select.tuplets(staff, level=-1)
>>> for item in result:
...     item
... 
Tuplet('3:2', "d'8 e'8 f'8")
Tuplet('3:2', "c'4 d'4 e'4")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Selects tuplets at level 1; tuplets at level 1 are top-level tuplets: level-1 tuplets contain only 1 tuplet (themselves) and are not contained by any other tuplets:

>>> staff = abjad.Staff(
...     r"\times 2/3 { c'2 \times 2/3 { d'8 e' f' } } \times 2/3 { c'4 d' e' }"
... )
>>> result = abjad.select.tuplets(staff, level=1)
>>> for item in result:
...     item
... 
Tuplet('3:2', "c'2 { 3:2 d'8 e'8 f'8 }")
Tuplet('3:2', "c'4 d'4 e'4")
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  
abjad.select.with_next_leaf(argument, *, grace: bool | None = None) list[Leaf][source]

Extends argument with next leaf.

Selects runs (each with next leaf):

>>> staff = abjad.Staff("c'8 r8 d'8 e'8 r8 f'8 g'8 a'8")
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.runs(staff)
>>> result = [abjad.select.with_next_leaf(_) for _ in result]
>>> for item in result:
...     item
... 
[Note("c'8"), Rest('r8')]
[Note("d'8"), Note("e'8"), Rest('r8')]
[Note("f'8"), Note("g'8"), Note("a'8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Selects pitched tails (each with next leaf):

>>> staff = abjad.Staff(r"c'8 r d' ~ d' e' ~ e' r8 f'8")
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.logical_ties(staff, pitched=True)
>>> result = [abjad.select.with_next_leaf(_[-1:]) for _ in result]
>>> for item in result:
...     item
... 
[Note("c'8"), Rest('r8')]
[Note("d'8"), Note("e'8")]
[Note("e'8"), Rest('r8')]
[Note("f'8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Pitched logical ties (each with next leaf) is the correct selection for single-pitch sustain pedal applications.

Selects pitched logical ties (each with next leaf):

>>> staff = abjad.Staff(r"c'8 r d' ~ d' e' ~ e' r8 f'8")
>>> abjad.setting(staff).autoBeaming = False
>>> abjad.setting(staff).pedalSustainStyle = "#'mixed"
>>> result = abjad.select.logical_ties(staff, pitched=True)
>>> result = [abjad.select.with_next_leaf(_) for _ in result]
>>> for item in result:
...     item
... 
[Note("c'8"), Rest('r8')]
[Note("d'8"), Note("d'8"), Note("e'8")]
[Note("e'8"), Note("e'8"), Rest('r8')]
[Note("f'8")]
>>> for item in result:
...     abjad.piano_pedal(item, context="Staff")
... 
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> abjad.override(staff).SustainPedalLineSpanner.staff_padding = 6
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

REGRESSION. Works with grace note (and containers):

>>> music_voice = abjad.Voice("c'4 d' e' f'", name="MusicVoice")
>>> container = abjad.BeforeGraceContainer("cs'16")
>>> abjad.attach(container, music_voice[1])
>>> obgc = abjad.on_beat_grace_container("g'16 gs' a' as'", music_voice[2:3])
>>> abjad.attach(abjad.Articulation(">"), obgc[0])
>>> container = abjad.AfterGraceContainer("fs'16")
>>> abjad.attach(container, music_voice[3])
>>> staff = abjad.Staff([music_voice])
>>> prototype = (
...     abjad.BeforeGraceContainer,
...     abjad.OnBeatGraceContainer,
...     abjad.AfterGraceContainer,
... )
>>> result = abjad.select.components(staff, prototype)
>>> result = [abjad.select.leaves(_) for _ in result]
>>> result = [abjad.select.with_next_leaf(_) for _ in result]
>>> for item in result:
...     item
... 
[Note("cs'16"), Note("d'4")]
[Chord("<e' g'>16"), Note("gs'16"), Note("a'16"), Note("as'16"), Note("e'4")]
[Note("fs'16")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Works with independent after-grace containers (grace-to-main):

>>> music_voice = abjad.Voice("c'4 d' e' f'", name="MusicVoice")
>>> container = abjad.IndependentAfterGraceContainer("gf'16")
>>> music_voice.insert(3, container)
>>> staff = abjad.Staff([music_voice])
>>> abjad.setting(staff).autoBeaming = False
>>> leaves = abjad.select.leaves(staff)
>>> result = [abjad.select.with_next_leaf(_) for _ in [leaves[2:3]]]
>>> for item in result:
...     item
... 
[Note("e'4"), Note("gf'16")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Works with independent after-grace containers (grace-to-main):

>>> music_voice = abjad.Voice("c'4 d' e' f'", name="MusicVoice")
>>> container = abjad.IndependentAfterGraceContainer("gf'16")
>>> music_voice.insert(3, container)
>>> staff = abjad.Staff([music_voice])
>>> abjad.setting(staff).autoBeaming = False
>>> leaves = abjad.select.leaves(staff)
>>> result = [abjad.select.with_next_leaf(_) for _ in [leaves[3:4]]]
>>> for item in result:
...     item
... 
[Note("gf'16"), Note("f'4")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  
abjad.select.with_previous_leaf(argument) list[Leaf][source]

Extends argument with previous leaf.

Selects runs (each with previous leaf):

>>> staff = abjad.Staff("c'8 r8 d'8 e'8 r8 f'8 g'8 a'8")
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.runs(staff)
>>> result = [abjad.select.with_previous_leaf(_) for _ in result]
>>> for item in result:
...     item
... 
[Note("c'8")]
[Rest('r8'), Note("d'8"), Note("e'8")]
[Rest('r8'), Note("f'8"), Note("g'8"), Note("a'8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Selects pitched heads (each with previous leaf):

>>> staff = abjad.Staff(r"c'8 r d' ~ d' e' ~ e' r8 f'8")
>>> abjad.setting(staff).autoBeaming = False
>>> result = abjad.select.logical_ties(staff, pitched=True)
>>> result = [abjad.select.with_previous_leaf(_[:1]) for _ in result]
>>> for item in result:
...     item
... 
[Note("c'8")]
[Rest('r8'), Note("d'8")]
[Note("d'8"), Note("e'8")]
[Rest('r8'), Note("f'8")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

REGRESSION. Works with grace note (and containers):

>>> music_voice = abjad.Voice("c'4 d' e' f'", name="MusicVoice")
>>> container = abjad.BeforeGraceContainer("cs'16")
>>> abjad.attach(container, music_voice[1])
>>> obgc = abjad.on_beat_grace_container("g'16 gs' a' as'", music_voice[2:3])
>>> abjad.attach(abjad.Articulation(">"), obgc[0])
>>> container = abjad.AfterGraceContainer("fs'16")
>>> abjad.attach(container, music_voice[3])
>>> staff = abjad.Staff([music_voice])
>>> prototype = (
...     abjad.BeforeGraceContainer,
...     abjad.OnBeatGraceContainer,
...     abjad.AfterGraceContainer,
... )
>>> result = abjad.select.components(staff, prototype)
>>> result = [abjad.select.leaves(_) for _ in result]
>>> result = [abjad.select.with_previous_leaf(_) for _ in result]
>>> for item in result:
...     item
... 
[Note("c'4"), Note("cs'16")]
[Note("d'4"), Chord("<e' g'>16"), Note("gs'16"), Note("a'16"), Note("as'16")]
[Note("f'4"), Note("fs'16")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Works with independent after-grace containers (grace-to-main):

>>> music_voice = abjad.Voice("c'4 d' e' f'", name="MusicVoice")
>>> container = abjad.IndependentAfterGraceContainer("gf'16")
>>> music_voice.insert(3, container)
>>> staff = abjad.Staff([music_voice])
>>> abjad.setting(staff).autoBeaming = False
>>> leaves = abjad.select.leaves(staff)
>>> result = [abjad.select.with_previous_leaf(_) for _ in [leaves[3:4]]]
>>> for item in result:
...     item
... 
[Note("e'4"), Note("gf'16")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

Works with independent after-grace containers (main-to-grace):

>>> music_voice = abjad.Voice("c'4 d' e' f'", name="MusicVoice")
>>> container = abjad.IndependentAfterGraceContainer("gf'16")
>>> music_voice.insert(3, container)
>>> staff = abjad.Staff([music_voice])
>>> abjad.setting(staff).autoBeaming = False
>>> leaves = abjad.select.leaves(staff)
>>> result = [abjad.select.with_previous_leaf(_) for _ in [leaves[-1:]]]
>>> for item in result:
...     item
... 
[Note("gf'16"), Note("f'4")]
>>> abjad.label.color_leaves(result, ["#red", "#blue"])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  
class abjad.select.LogicalTie(items=None)[source]

Logical tie of a component.

>>> staff = abjad.Staff("c' d' e' ~ e'")
>>> abjad.show(staff)  
>>> abjad.select.logical_tie(staff[2])
LogicalTie(items=[Note("e'4"), Note("e'4")])

head

Reference to element 0 in logical tie.

is_pitched

Is true when logical tie head is a note or chord.

is_trivial

Is true when length of logical tie is less than or equal to 1.

items

Gets items in selection.

tail

Gets last leaf in logical tie.

written_duration

Sum of written duration of all components in logical tie.

head

Reference to element 0 in logical tie.

is_pitched

Is true when logical tie head is a note or chord.

is_trivial

Is true when length of logical tie is less than or equal to 1.

items

Gets items in selection.

tail

Gets last leaf in logical tie.

written_duration

Sum of written duration of all components in logical tie.