Selection¶
-
class
abjad.core.Selection.
Selection
(items=None)¶ Selection of items (components / or other selections).
Selects runs:
>>> string = r"c'4 \times 2/3 { d'8 r8 e'8 } r16 f'16 g'8 a'4" >>> staff = abjad.Staff(string) >>> abjad.setting(staff).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).runs()
>>> for item in result: ... item ... Selection([Note("c'4"), Note("d'8")]) Selection([Note("e'8")]) Selection([Note("f'16"), Note("g'8"), Note("a'4")])
Attributes Summary
__add__
Cocatenates argument
to selection.__contains__
Is true when argument
is in selection.__eq__
Is true when selection and argument
are of the same type and when items in selection equal item inargument
.__format__
Formats duration. __getitem__
Gets item, slice or pattern argument
in selection.__hash__
Hashes selection. __illustrate__
Attempts to illustrate selection. __len__
Gets number of items in selection. __radd__
Concatenates selection to argument
.__repr__
Gets interpreter representation of selection. are_contiguous_logical_voice
Is true when items in selection are contiguous components in the same logical voice. are_contiguous_same_parent
Is true when items in selection are all contiguous components in the same parent. are_leaves
Is true when items in selection are all leaves. are_logical_voice
Is true when items in selection are all components in the same logical voice. chord
Selects chord n
.chords
Selects chords. components
Selects components. filter
Filters selection by predicate
.filter_duration
Filters selection by operator
andduration
.filter_length
Filters selection by operator
andlength
.filter_pitches
Filters selection by operator
andpitches
.filter_preprolated
Filters selection by operator
and preprolatedduration
.flatten
Flattens selection to depth
.group
Groups selection. group_by
Groups items in selection by predicate
.group_by_contiguity
Groups items in selection by contiguity. group_by_duration
Groups items in selection by duration. group_by_length
Groups items in selection by length. group_by_measure
Groups items in selection by measure. group_by_pitch
Groups items in selection by pitches. items
Gets items. leaf
Selects leaf n
.leaves
Selects leaves (without grace notes). logical_ties
Selects logical ties (without grace notes). map
Maps expression
to items in selection.nontrivial
Filters selection by length greater than 1. note
Selects note n
.notes
Selects notes. partition_by_counts
Partitions selection by counts
.partition_by_durations
Partitions selection by durations
.partition_by_ratio
Partitions selection by ratio
.rest
Selects rest n
.rests
Selects rests. run
Selects run n
.runs
Selects runs. top
Selects top components. tuplet
Selects tuplet n
.tuplets
Selects tuplets. with_next_leaf
Extends selection with next leaf. with_previous_leaf
Extends selection with previous leaf. Special methods
-
__add__
(argument)¶ Cocatenates
argument
to selection.Returns new selection.
-
__contains__
(argument)¶ Is true when
argument
is in selection.Returns true or false.
-
(
AbjadValueObject
).__copy__
(*arguments)¶ Copies Abjad value object.
Returns new Abjad value object.
-
__eq__
(argument)¶ Is true when selection and
argument
are of the same type and when items in selection equal item inargument
.Returns true or false.
-
__format__
(format_specification='')¶ Formats duration.
Returns string.
-
__getitem__
(argument)¶ Gets item, slice or pattern
argument
in selection.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).auto_beaming = False >>> abjad.show(staff)
>>> pattern = abjad.index([0], 2) >>> for leaf in abjad.select(staff).leaves()[pattern]: ... leaf ... Note("c'8") Note("d'8") Note("e'8") Rest('r8')
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).auto_beaming = False >>> abjad.show(staff)
>>> pattern = abjad.index([0], 2) >>> selection = abjad.select(staff).logical_ties(pitched=True) >>> for logical_tie in selection[pattern]: ... logical_tie ... LogicalTie([Note("c'8")]) LogicalTie([Note("e'8"), Note("e'8"), Note("e'8")])
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).auto_beaming = False >>> abjad.show(staff)
>>> getter = abjad.select().leaves()[abjad.index([1])] >>> for selection in abjad.select(staff).logical_ties( ... pitched=True, ... ).map(getter): ... selection ... Selection(items=()) Selection([Note("d'8")]) Selection([Note("e'8")]) Selection(items=())
>>> getter = abjad.select().leaves()[abjad.index([1])] >>> selector = abjad.select().logical_ties(pitched=True) >>> selector = selector.map(getter) >>> result = selector(staff)
>>> selector.print(result) Selection(items=()) Selection([Note("d'8")]) Selection([Note("e'8")]) Selection(items=())
>>> selector.color(result) >>> abjad.show(staff)
>>> abjad.select().leaves()[:2] abjad.select().leaves()[:2]
Returns a single item (or expression) when
argument
is an integer.Returns new selection (or expression) when
argument
is a slice.Returns new selection (or expression) when
argument
is a pattern.
-
__hash__
()¶ Hashes selection.
Redefined in tandem with __eq__.
-
__illustrate__
()¶ Attempts to illustrate selection.
Evaluates the storage format of the selection (to sever any references to the source score from which the selection was taken). Then tries to wrap the result in a staff; in the case that notes of only C4 are found then sets the staff context name to
'RhythmicStaff'
. If this works then the staff is wrapped in a LilyPond file and the file is returned. If this doesn’t work then the method raises an exception.The idea is that the illustration should work for simple selections of that represent an essentially contiguous snippet of a single voice of music.
Returns LilyPond file.
-
__len__
()¶ Gets number of items in selection.
Returns nonnegative integer.
-
__radd__
(argument)¶ Concatenates selection to
argument
.Returns newly created selection.
-
__repr__
()¶ Gets interpreter representation of selection.
Returns string.
Methods
-
are_contiguous_logical_voice
(prototype=None, allow_orphans=True)¶ Is true when items in selection are contiguous components in the same logical voice.
>>> staff = abjad.Staff("c'4 d'4 e'4 f'4") >>> staff[:].are_contiguous_logical_voice() True
>>> selection = staff[:1] + staff[-1:] >>> selection.are_contiguous_logical_voice() False
Returns true or false.
-
are_contiguous_same_parent
(prototype=None, allow_orphans=True)¶ Is true when items in selection are all contiguous components in the same parent.
>>> staff = abjad.Staff("c'4 d'4 e'4 f'4") >>> staff[:].are_contiguous_same_parent() True
>>> selection = staff[:1] + staff[-1:] >>> selection.are_contiguous_same_parent() False
Returns true or false.
-
are_leaves
()¶ Is true when items in selection are all leaves.
>>> abjad.Staff("c'4 d'4 e'4 f'4")[:].are_leaves() True
Returns true or false.
-
are_logical_voice
(prototype=None, allow_orphans=True)¶ Is true when items in selection are all components in the same logical voice.
>>> staff = abjad.Staff("c'4 d'4 e'4 f'4") >>> staff[:].are_logical_voice() True
>>> selection = staff[:1] + staff[-1:] >>> selection.are_logical_voice() True
Returns true or false.
-
chord
(n)¶ Selects chord
n
.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([(10, 9), (8, 9), (10, 9)], tuplets) >>> tuplets = [abjad.Tuplet(*_) for _ in tuplets] >>> tuplets = [abjad.select(tuplets)] >>> lilypond_file = abjad.LilyPondFile.rhythm(tuplets) >>> staff = lilypond_file[abjad.Staff] >>> abjad.setting(staff).auto_beaming = False >>> abjad.override(staff).tuplet_bracket.direction = abjad.Up >>> abjad.override(staff).tuplet_bracket.staff_padding = 3 >>> abjad.show(lilypond_file)
>>> result = abjad.select(staff).chord(-1)
>>> result Chord("<fs' gs'>16")
-
chords
()¶ Selects chords.
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([(10, 9), (8, 9), (10, 9)], tuplets) >>> tuplets = [abjad.Tuplet(*_) for _ in tuplets] >>> tuplets = [abjad.select(tuplets)] >>> lilypond_file = abjad.LilyPondFile.rhythm(tuplets) >>> staff = lilypond_file[abjad.Staff] >>> abjad.setting(staff).auto_beaming = False >>> abjad.override(staff).tuplet_bracket.direction = abjad.Up >>> abjad.override(staff).tuplet_bracket.staff_padding = 3 >>> abjad.show(lilypond_file)
>>> result = abjad.select(staff).chords()
>>> 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")
>>> selector = abjad.select().chords() >>> result = selector(staff)
>>> selector.print(result) 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")
>>> selector.color(result) >>> abjad.show(lilypond_file)
-
components
(prototype=None, grace_notes=None, reverse=False)¶ Selects components.
Selects notes:
Returns new selection (or expression).
-
filter
(predicate=None)¶ Filters selection 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).auto_beaming = False >>> abjad.show(staff)
>>> inequality = abjad.DurationInequality('==', (2, 8)) >>> result = abjad.select(staff).runs().filter(inequality)
>>> for item in result: ... item ... Selection([Note("d'8"), Note("e'8")])
Returns new selection (or expression).
-
filter_duration
(operator, duration)¶ Filters selection by
operator
andduration
.Selects runs with duration equal to 2/8:
Selects runs with duration less than 3/8:
>>> staff = abjad.Staff("c'8 r8 d'8 e'8 r8 f'8 g'8 a'8") >>> abjad.setting(staff).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).runs() >>> result = result.filter_duration('<', (3, 8))
>>> for item in result: ... item ... Selection([Note("c'8")]) Selection([Note("d'8"), Note("e'8")])
Returns new selection (or expression).
-
filter_length
(operator, length)¶ Filters selection by
operator
andlength
.Selects notes runs with length greater than 1:
>>> staff = abjad.Staff("c'8 r8 d'8 e'8 r8 f'8 g'8 a'8") >>> abjad.setting(staff).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).runs().filter_length('>', 1)
>>> for item in result: ... item ... Selection([Note("d'8"), Note("e'8")]) Selection([Note("f'8"), Note("g'8"), Note("a'8")])
Selects runs with length less than 3:
-
filter_pitches
(operator, pitches)¶ Filters selection by
operator
andpitches
.Selects leaves with pitches intersecting C4:
>>> staff = abjad.Staff("c'8 d'8 ~ d'8 e'8") >>> abjad.setting(staff).auto_beaming = False >>> staff.extend("r8 <c' e' g'>8 ~ <c' e' g'>4") >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves() >>> result = result.filter_pitches('&', 'C4')
>>> for item in result: ... item ... Note("c'8") Chord("<c' e' g'>8") Chord("<c' e' g'>4")
Selects leaves with pitches intersecting C4 or E4:
>>> staff = abjad.Staff("c'8 d'8 ~ d'8 e'8") >>> abjad.setting(staff).auto_beaming = False >>> staff.extend("r8 <c' e' g'>8 ~ <c' e' g'>4") >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves() >>> result = result.filter_pitches('&', 'C4 E4')
>>> for item in result: ... item ... Note("c'8") Note("e'8") Chord("<c' e' g'>8") Chord("<c' e' g'>4")
Selects logical ties with pitches intersecting C4:
>>> staff = abjad.Staff("c'8 d'8 ~ d'8 e'8") >>> abjad.setting(staff).auto_beaming = False >>> staff.extend("r8 <c' e' g'>8 ~ <c' e' g'>4") >>> abjad.show(staff)
>>> result = abjad.select(staff).logical_ties() >>> result = result.filter_pitches('&', 'C4')
>>> for item in result: ... item ... LogicalTie([Note("c'8")]) LogicalTie([Chord("<c' e' g'>8"), Chord("<c' e' g'>4")])
Returns new selection (or expression).
-
filter_preprolated
(operator, duration)¶ Filters selection by
operator
and preprolatedduration
.Selects runs with duration equal to 2/8:
Selects runs with duration less than 3/8:
>>> staff = abjad.Staff("c'8 r8 d'8 e'8 r8 f'8 g'8 a'8") >>> abjad.setting(staff).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).runs() >>> result = result.filter_preprolated('<', (3, 8))
>>> for item in result: ... item ... Selection([Note("c'8")]) Selection([Note("d'8"), Note("e'8")])
Returns new selection (or expression).
-
flatten
(depth=1)¶ Flattens selection to
depth
.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([(10, 9), (8, 9), (10, 9)], tuplets) >>> tuplets = [abjad.Tuplet(*_) for _ in tuplets] >>> tuplets = [abjad.select(tuplets)] >>> lilypond_file = abjad.LilyPondFile.rhythm(tuplets) >>> staff = lilypond_file[abjad.Staff] >>> abjad.setting(staff).auto_beaming = False >>> abjad.override(staff).tuplet_bracket.direction = abjad.Up >>> abjad.override(staff).tuplet_bracket.staff_padding = 3 >>> abjad.show(lilypond_file)
>>> getter = abjad.select().leaves()[:2] >>> result = abjad.select(staff).tuplets().map(getter)
>>> for item in result: ... item ... Selection([Rest('r16'), Note("bf'16")]) Selection([Rest('r16'), Note("bf'16")]) Selection([Rest('r16'), Note("bf'16")])
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([(10, 9), (8, 9), (10, 9)], tuplets) >>> tuplets = [abjad.Tuplet(*_) for _ in tuplets] >>> tuplets = [abjad.select(tuplets)] >>> lilypond_file = abjad.LilyPondFile.rhythm(tuplets) >>> staff = lilypond_file[abjad.Staff] >>> abjad.setting(staff).auto_beaming = False >>> abjad.override(staff).tuplet_bracket.direction = abjad.Up >>> abjad.override(staff).tuplet_bracket.staff_padding = 3 >>> abjad.show(lilypond_file)
>>> getter = abjad.select().leaves()[:2] >>> result = abjad.select(staff).tuplets().map(getter) >>> result = result.flatten()
>>> for item in result: ... item ... Rest('r16') Note("bf'16") Rest('r16') Note("bf'16") Rest('r16') Note("bf'16")
Returns new selection (or expression).
-
group
()¶ Groups 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).auto_beaming = False >>> abjad.show(staff, strict=89)
>>> result = abjad.select(staff).leaves(pitched=True).group()
>>> for item in result: ... item ... Selection([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")])
>>> selector = abjad.select().leaves(pitched=True).group() >>> result = selector(staff)
>>> selector.print(result) Selection([Selection([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")])])
>>> selector.color(result) >>> abjad.show(staff, strict=89)
Returns nested selection (or expression).
-
group_by
(predicate=None)¶ Groups items in selection 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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves(pitched=True) >>> result = result.group_by()
>>> for item in result: ... item ... Selection([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")])
>>> selector = abjad.select().leaves(pitched=True).group_by() >>> result = selector(staff)
>>> selector.print(result) Selection([Selection([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")])])
>>> selector.color(result) >>> abjad.show(staff)
Returns nested selection (or expression).
-
group_by_contiguity
()¶ Groups items in selection 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).auto_beaming = False >>> staff.extend("r8 <c' e' g'>8 ~ <c' e' g'>4") >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves(pitched=True) >>> result = result.group_by_contiguity()
>>> for item in result: ... item ... Selection([Note("c'8"), Note("d'8")]) Selection([Note("e'8")]) Selection([Note("f'8"), Note("g'8"), Note("a'8")]) Selection([Chord("<c' e' g'>8"), Chord("<c' e' g'>4")])
>>> selector = abjad.select().leaves(pitched=True) >>> selector = selector.group_by_contiguity() >>> result = selector(staff)
>>> selector.print(result) Selection([Note("c'8"), Note("d'8")]) Selection([Note("e'8")]) Selection([Note("f'8"), Note("g'8"), Note("a'8")]) Selection([Chord("<c' e' g'>8"), Chord("<c' e' g'>4")])
>>> selector.color(result) >>> abjad.show(staff)
Groups sixteenths by contiguity:
>>> staff = abjad.Staff("c'4 d'16 d' d' d' e'4 f'16 f' f' f'") >>> abjad.setting(staff).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves() >>> result = result.filter_duration('==', (1, 16)) >>> result = result.group_by_contiguity()
>>> for item in result: ... item ... Selection([Note("d'16"), Note("d'16"), Note("d'16"), Note("d'16")]) Selection([Note("f'16"), Note("f'16"), Note("f'16"), Note("f'16")])
>>> selector = abjad.select().leaves() >>> selector = selector.filter_duration('==', (1, 16)) >>> selector = selector.group_by_contiguity() >>> result = selector(staff)
>>> selector.print(result) Selection([Note("d'16"), Note("d'16"), Note("d'16"), Note("d'16")]) Selection([Note("f'16"), Note("f'16"), Note("f'16"), Note("f'16")])
>>> selector.color(result) >>> abjad.show(staff)
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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).logical_ties() >>> result = result.filter_duration('<', (1, 4)) >>> result = result.group_by_contiguity() >>> result = result.map(abjad.select().leaves()[0])
>>> for item in result: ... item ... Note("d'8") Note("g'8")
>>> selector = abjad.select().logical_ties() >>> selector = selector.filter_duration('<', (1, 4)) >>> selector = selector.group_by_contiguity() >>> selector = selector.map(abjad.select().leaves()[0]) >>> result = selector(staff)
>>> selector.print(result) Note("d'8") Note("g'8")
>>> selector.color(result) >>> abjad.show(staff)
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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves(pitched=True) >>> result = result.group_by_pitch() >>> result = result.map(abjad.select().group_by_contiguity()) >>> result = result.flatten()
>>> for item in result: ... item ... Selection([Note("c'8"), Note("c'16"), Note("c'16")]) Selection([Note("c'16"), Note("c'16")]) Selection([Note("d'8"), Note("d'16"), Note("d'16")]) Selection([Note("d'16"), Note("d'16")])
>>> selector = abjad.select().leaves(pitched=True) >>> selector = selector.group_by_pitch() >>> selector = selector.map( ... abjad.select().group_by_contiguity() ... ) >>> selector = selector.flatten() >>> result = selector(staff)
>>> selector.print(result) Selection([Note("c'8"), Note("c'16"), Note("c'16")]) Selection([Note("c'16"), Note("c'16")]) Selection([Note("d'8"), Note("d'16"), Note("d'16")]) Selection([Note("d'16"), Note("d'16")])
>>> selector.color(result) >>> abjad.show(staff)
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).auto_beaming = False >>> abjad.show(staff)
>>> getter = abjad.select().group_by_pitch()
>>> result = abjad.select(staff).logical_ties(pitched=True) >>> result = result.group_by_contiguity() >>> result = result.map(getter).flatten()
>>> for item in result: ... item ... Selection([LogicalTie([Note("c'8"), Note("c'16")]), LogicalTie([Note("c'16")])]) Selection([LogicalTie([Note("c'16")]), LogicalTie([Note("c'16")])]) Selection([LogicalTie([Note("d'8"), Note("d'16")]), LogicalTie([Note("d'16")])]) Selection([LogicalTie([Note("d'16")]), LogicalTie([Note("d'16")])])
>>> selector = abjad.select().logical_ties(pitched=True) >>> selector = selector.group_by_contiguity() >>> selector = selector.map(getter).flatten() >>> result = selector(staff)
>>> selector.print(result) Selection([LogicalTie([Note("c'8"), Note("c'16")]), LogicalTie([Note("c'16")])]) Selection([LogicalTie([Note("c'16")]), LogicalTie([Note("c'16")])]) Selection([LogicalTie([Note("d'8"), Note("d'16")]), LogicalTie([Note("d'16")])]) Selection([LogicalTie([Note("d'16")]), LogicalTie([Note("d'16")])])
>>> selector.color(result) >>> abjad.show(staff)
Returns new selection (or expression).
-
group_by_duration
()¶ Groups items in selection 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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).logical_ties() >>> result = result.group_by_duration()
>>> for item in result: ... item ... Selection([LogicalTie([Note("c'4"), Note("c'16")])]) Selection([LogicalTie([Note("d'16"), Note("d'16")])]) Selection([LogicalTie([Note("d'16")])]) Selection([LogicalTie([Note("e'4"), Note("e'16")])]) Selection([LogicalTie([Note("f'16"), Note("f'16")])]) Selection([LogicalTie([Note("f'16")])])
>>> selector = abjad.select().logical_ties().group_by_duration() >>> result = selector(staff)
>>> selector.print(result) Selection([LogicalTie([Note("c'4"), Note("c'16")])]) Selection([LogicalTie([Note("d'16"), Note("d'16")])]) Selection([LogicalTie([Note("d'16")])]) Selection([LogicalTie([Note("e'4"), Note("e'16")])]) Selection([LogicalTie([Note("f'16"), Note("f'16")])]) Selection([LogicalTie([Note("f'16")])])
>>> selector.color(result) >>> abjad.show(staff)
Returns nested selection (or expression).
-
group_by_length
()¶ Groups items in selection 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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).logical_ties().group_by_length()
>>> for item in result: ... item ... Selection([LogicalTie([Note("c'4"), Note("c'16")]), LogicalTie([Note("d'16"), Note("d'16")])]) Selection([LogicalTie([Note("d'16")])]) Selection([LogicalTie([Note("e'4"), Note("e'16")]), LogicalTie([Note("f'16"), Note("f'16")])]) Selection([LogicalTie([Note("f'16")])])
>>> selector = abjad.select().logical_ties().group_by_length() >>> result = selector(staff)
>>> selector.print(result) Selection([LogicalTie([Note("c'4"), Note("c'16")]), LogicalTie([Note("d'16"), Note("d'16")])]) Selection([LogicalTie([Note("d'16")])]) Selection([LogicalTie([Note("e'4"), Note("e'16")]), LogicalTie([Note("f'16"), Note("f'16")])]) Selection([LogicalTie([Note("f'16")])])
>>> selector.color(result) >>> abjad.show(staff)
Returns nested selection (or expression).
-
group_by_measure
()¶ Groups items in selection by measure.
Groups leaves by logical measure:
>>> staff = abjad.Staff("c'8 d' e' f' g' a' b' c''") >>> abjad.setting(staff).auto_beaming = 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]) >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves() >>> result = result.group_by_measure()
>>> for item in result: ... item ... Selection([Note("c'8"), Note("d'8")]) Selection([Note("e'8"), Note("f'8")]) Selection([Note("g'8"), Note("a'8"), Note("b'8")]) Selection([Note("c''8")])
>>> selector = abjad.select().leaves() >>> selector = selector.group_by_measure() >>> result = selector(staff)
>>> selector.print(result) Selection([Note("c'8"), Note("d'8")]) Selection([Note("e'8"), Note("f'8")]) Selection([Note("g'8"), Note("a'8"), Note("b'8")]) Selection([Note("c''8")])
>>> selector.color(result) >>> abjad.show(staff)
Groups leaves by logical measure and joins pairs of consecutive groups:
>>> staff = abjad.Staff("c'8 d' e' f' g' a' b' c''") >>> abjad.setting(staff).auto_beaming = 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]) >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves() >>> result = result.group_by_measure() >>> result = result.partition_by_counts([2], cyclic=True) >>> result = result.map(abjad.select().flatten())
>>> for item in result: ... item ... Selection([Note("c'8"), Note("d'8"), Note("e'8"), Note("f'8")]) Selection([Note("g'8"), Note("a'8"), Note("b'8"), Note("c''8")])
>>> selector = abjad.select().leaves() >>> selector = selector.group_by_measure() >>> selector = selector.partition_by_counts([2], cyclic=True) >>> selector = selector.map(abjad.select().flatten()) >>> result = selector(staff)
>>> selector.print(result) Selection([Note("c'8"), Note("d'8"), Note("e'8"), Note("f'8")]) Selection([Note("g'8"), Note("a'8"), Note("b'8"), Note("c''8")])
>>> selector.color(result) >>> abjad.show(staff)
Groups leaves by logical measure; then gets item 0 in each group:
>>> staff = abjad.Staff("c'8 d' e' f' g' a' b' c''") >>> abjad.setting(staff).auto_beaming = 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]) >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves() >>> result = result.group_by_measure() >>> result = result.map(abjad.select()[0])
>>> for item in result: ... item ... Note("c'8") Note("e'8") Note("g'8") Note("c''8")
Groups leaves by logical measure; then gets item -1 in each group:
>>> staff = abjad.Staff("c'8 d' e' f' g' a' b' c''") >>> abjad.setting(staff).auto_beaming = 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]) >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves() >>> result = result.group_by_measure() >>> result = result.map(abjad.select()[-1])
>>> for item in result: ... item ... Note("d'8") Note("f'8") Note("b'8") Note("c''8")
Works with implicit time signatures:
>>> staff = abjad.Staff("c'4 d' e' f' g' a' b' c''") >>> abjad.setting(staff).auto_beaming = False >>> score = abjad.Score([staff]) >>> scheme = abjad.SchemeMoment((1, 16)) >>> abjad.setting(score).proportional_notation_duration = scheme >>> abjad.show(score)
>>> result = abjad.select(score).leaves() >>> result = result.group_by_measure()
>>> for item in result: ... item ... Selection([Note("c'4"), Note("d'4"), Note("e'4"), Note("f'4")]) Selection([Note("g'4"), Note("a'4"), Note("b'4"), Note("c''4")])
>>> selector = abjad.select().leaves() >>> selector = selector.group_by_measure() >>> result = selector(score)
>>> selector.print(result) Selection([Note("c'4"), Note("d'4"), Note("e'4"), Note("f'4")]) Selection([Note("g'4"), Note("a'4"), Note("b'4"), Note("c''4")])
>>> selector.color(result) >>> abjad.show(staff)
Returns new selection (or expression).
-
group_by_pitch
()¶ Groups items in selection by pitches.
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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).logical_ties().group_by_pitch()
>>> for item in result: ... item ... Selection([LogicalTie([Note("c'4"), Note("c'16")])]) Selection([LogicalTie([Note("d'16"), Note("d'16")]), LogicalTie([Note("d'16")])]) Selection([LogicalTie([Note("e'4"), Note("e'16")])]) Selection([LogicalTie([Note("f'16"), Note("f'16")]), LogicalTie([Note("f'16")])])
>>> selector = abjad.select().logical_ties().group_by_pitch() >>> result = selector(staff)
>>> selector.print(result) Selection([LogicalTie([Note("c'4"), Note("c'16")])]) Selection([LogicalTie([Note("d'16"), Note("d'16")]), LogicalTie([Note("d'16")])]) Selection([LogicalTie([Note("e'4"), Note("e'16")])]) Selection([LogicalTie([Note("f'16"), Note("f'16")]), LogicalTie([Note("f'16")])])
>>> selector.color(result) >>> abjad.show(staff)
Returns nested selection (or expression).
-
leaf
(n)¶ Selects leaf
n
.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([(10, 9), (8, 9), (10, 9)], tuplets) >>> tuplets = [abjad.Tuplet(*_) for _ in tuplets] >>> tuplets = [abjad.select(tuplets)] >>> lilypond_file = abjad.LilyPondFile.rhythm(tuplets) >>> staff = lilypond_file[abjad.Staff] >>> abjad.setting(staff).auto_beaming = False >>> abjad.override(staff).tuplet_bracket.direction = abjad.Up >>> abjad.override(staff).tuplet_bracket.staff_padding = 3 >>> abjad.show(lilypond_file)
>>> result = abjad.select(staff).leaf(-1)
>>> result Chord("<fs' gs'>16")
-
leaves
(prototype=None, grace_notes=False, head=None, pitched=None, reverse=False, tail=None, trim=None)¶ Selects leaves (without grace notes).
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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves()
>>> 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')
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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves(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")
Trimmed leaves are the correct selection for ottava spanners.
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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves(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")
Set
trim
toabjad.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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves(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')
>>> selector = abjad.select().leaves(trim=abjad.Left) >>> result = selector(staff)
>>> selector.print(result) 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.attach(abjad.OctavationSpanner(), result)
>>> selector.color(result) >>> abjad.show(staff)
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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves(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")
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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).components(abjad.Tuplet) >>> result = result.leaves()
>>> for item in result: ... item ... Rest('r8') Note("d'8") Note("e'8") Note("e'8") Note("d'8") Rest('r8')
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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).components(abjad.Tuplet) >>> result = result.leaves(trim=True)
>>> for item in result: ... item ... Note("d'8") Note("e'8") Note("e'8") Note("d'8")
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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).components(abjad.Tuplet) >>> result = result.leaves(head=True, pitched=True)
>>> for item in result: ... item ... Note("c'8") Note("d'8") Note("d'8") Note("c'8")
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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).components(abjad.Tuplet) >>> result = result.leaves(tail=True, pitched=True)
>>> for item in result: ... item ... Note("c'8") Note("d'8") Note("d'8") Note("c'8")
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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).components(abjad.Tuplet) >>> result = result.leaves(abjad.Chord, head=True)
>>> for item in result: ... item ... Chord("<c' e' g'>8") Chord("<c' d'>8")
Returns new selection (or expression).
-
logical_ties
(grace_notes=False, nontrivial=None, pitched=None, reverse=False)¶ Selects logical ties (without grace notes).
Selects logical ties:
>>> staff = abjad.Staff("c'8 d' ~ { d' e' r f'~ } f' r") >>> abjad.setting(staff).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).logical_ties()
>>> for item in result: ... item ... LogicalTie([Note("c'8")]) LogicalTie([Note("d'8"), Note("d'8")]) LogicalTie([Note("e'8")]) LogicalTie([Rest('r8')]) LogicalTie([Note("f'8"), Note("f'8")]) LogicalTie([Rest('r8')])
>>> selector = abjad.select().logical_ties() >>> result = selector(staff)
>>> selector.print(result) LogicalTie([Note("c'8")]) LogicalTie([Note("d'8"), Note("d'8")]) LogicalTie([Note("e'8")]) LogicalTie([Rest('r8')]) LogicalTie([Note("f'8"), Note("f'8")]) LogicalTie([Rest('r8')])
>>> selector.color(result) >>> abjad.show(staff)
Selects pitched logical ties:
>>> staff = abjad.Staff("c'8 d' ~ { d' e' r f'~ } f' r") >>> abjad.setting(staff).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).logical_ties(pitched=True)
>>> for item in result: ... item ... LogicalTie([Note("c'8")]) LogicalTie([Note("d'8"), Note("d'8")]) LogicalTie([Note("e'8")]) LogicalTie([Note("f'8"), Note("f'8")])
Selects pitched nontrivial logical ties:
>>> staff = abjad.Staff("c'8 d' ~ { d' e' r f'~ } f' r") >>> abjad.setting(staff).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).logical_ties( ... pitched=True, ... nontrivial=True, ... )
>>> for item in result: ... item ... LogicalTie([Note("d'8"), Note("d'8")]) LogicalTie([Note("f'8"), Note("f'8")])
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).auto_beaming = False >>> abjad.show(staff)
>>> getter = abjad.select().logical_ties(pitched=True) >>> result = abjad.select(staff).components(abjad.Tuplet) >>> result = result.map(getter)
>>> for item in result: ... item ... Selection([LogicalTie([Note("c'8")]), LogicalTie([Note("d'8")]), LogicalTie([Note("e'8"), Note("e'8")])]) Selection([LogicalTie([Note("g'8")]), LogicalTie([Note("a'8"), Note("a'8")])]) Selection([LogicalTie([Note("c''8")]), LogicalTie([Note("d''8")])])
>>> selector = abjad.select().components(abjad.Tuplet) >>> selector = selector.map(getter) >>> result = selector(staff)
>>> selector.print(result) Selection([LogicalTie([Note("c'8")]), LogicalTie([Note("d'8")]), LogicalTie([Note("e'8"), Note("e'8")])]) Selection([LogicalTie([Note("g'8")]), LogicalTie([Note("a'8"), Note("a'8")])]) Selection([LogicalTie([Note("c''8")]), LogicalTie([Note("d''8")])])
>>> selector.color(result) >>> abjad.show(staff)
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).auto_beaming = False >>> abjad.show(staff)
>>> getter = abjad.select().logical_ties(pitched=True) >>> result = abjad.select(staff).components(abjad.Tuplet)[-2:] >>> result = result.map(getter)
>>> for item in result: ... item ... Selection([LogicalTie([Note("g'8")]), LogicalTie([Note("a'8"), Note("a'8")])]) Selection([LogicalTie([Note("c''8")]), LogicalTie([Note("d''8")])])
>>> selector = abjad.select().components(abjad.Tuplet)[-2:] >>> selector = selector.map(getter) >>> result = selector(staff)
>>> selector.print(result) Selection([LogicalTie([Note("g'8")]), LogicalTie([Note("a'8"), Note("a'8")])]) Selection([LogicalTie([Note("c''8")]), LogicalTie([Note("d''8")])])
>>> selector.color(result) >>> abjad.show(staff)
Returns new selection (or expression).
-
map
(expression=None)¶ Maps
expression
to items in selection.Selects each tuplet as a separate selection:
>>> staff = abjad.Staff(r""" ... \times 2/3 { r8 d' e' } f' r ... r f' \times 2/3 { e' d' r8 } ... """) >>> abjad.setting(staff).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).components(abjad.Tuplet) >>> result = result.map(abjad.select())
>>> for item in result: ... item ... Selection([Tuplet(Multiplier(2, 3), "r8 d'8 e'8")]) Selection([Tuplet(Multiplier(2, 3), "e'8 d'8 r8")])
>>> selector = abjad.select().components(abjad.Tuplet) >>> selector = selector.map(abjad.select()) >>> result = selector(staff)
>>> selector.print(result) Selection([Tuplet(Multiplier(2, 3), "r8 d'8 e'8")]) Selection([Tuplet(Multiplier(2, 3), "e'8 d'8 r8")])
>>> selector.color(result) >>> abjad.show(staff)
Selects leaves in each component:
>>> staff = abjad.Staff(r""" ... \times 2/3 { r8 d' e' } f' r ... r f' \times 2/3 { e' d' r8 } ... """) >>> abjad.setting(staff).auto_beaming = False >>> abjad.show(staff)
>>> result = staff[:].map(abjad.select().leaves())
>>> for item in result: ... item ... Selection([Rest('r8'), Note("d'8"), Note("e'8")]) Selection([Note("f'8")]) Selection([Rest('r8')]) Selection([Rest('r8')]) Selection([Note("f'8")]) Selection([Note("e'8"), Note("d'8"), Rest('r8')])
>>> selector = abjad.select().map(abjad.select().leaves()) >>> result = selector(staff[:])
>>> selector.print(result) Selection([Rest('r8'), Note("d'8"), Note("e'8")]) Selection([Note("f'8")]) Selection([Rest('r8')]) Selection([Rest('r8')]) Selection([Note("f'8")]) Selection([Note("e'8"), Note("d'8"), Rest('r8')])
>>> selector.color(result) >>> abjad.show(staff)
Gets item 0 in each note run:
>>> string = r"c'4 \times 2/3 { d'8 r8 e'8 } r16 f'16 g'8 a'4" >>> staff = abjad.Staff(string) >>> abjad.setting(staff).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).runs() >>> result = result.map(abjad.select()[0])
>>> for item in result: ... item ... Note("c'4") Note("e'8") Note("f'16")
Returns new selection (or expression).
-
nontrivial
()¶ Filters selection by length greater than 1.
Selects nontrivial runs:
>>> staff = abjad.Staff("c'8 r8 d'8 e'8 r8 f'8 g'8 a'8") >>> abjad.setting(staff).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).runs().nontrivial()
>>> for item in result: ... item ... Selection([Note("d'8"), Note("e'8")]) Selection([Note("f'8"), Note("g'8"), Note("a'8")])
-
note
(n)¶ Selects note
n
.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([(10, 9), (8, 9), (10, 9)], tuplets) >>> tuplets = [abjad.Tuplet(*_) for _ in tuplets] >>> tuplets = [abjad.select(tuplets)] >>> lilypond_file = abjad.LilyPondFile.rhythm(tuplets) >>> staff = lilypond_file[abjad.Staff] >>> abjad.setting(staff).auto_beaming = False >>> abjad.override(staff).tuplet_bracket.direction = abjad.Up >>> abjad.override(staff).tuplet_bracket.staff_padding = 3 >>> abjad.show(lilypond_file)
>>> result = abjad.select(staff).note(-1)
>>> result Note("e'16")
-
notes
()¶ Selects notes.
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([(10, 9), (8, 9), (10, 9)], tuplets) >>> tuplets = [abjad.Tuplet(*_) for _ in tuplets] >>> tuplets = [abjad.select(tuplets)] >>> lilypond_file = abjad.LilyPondFile.rhythm(tuplets) >>> staff = lilypond_file[abjad.Staff] >>> abjad.setting(staff).auto_beaming = False >>> abjad.override(staff).tuplet_bracket.direction = abjad.Up >>> abjad.override(staff).tuplet_bracket.staff_padding = 3 >>> abjad.show(lilypond_file)
>>> result = abjad.select(staff).notes()
>>> for item in result: ... item ... Note("bf'16") Note("c'16") Note("bf'16") Note("d'16") Note("bf'16") Note("e'16")
-
partition_by_counts
(counts, cyclic=False, enchain=False, fuse_overhang=False, nonempty=False, overhang=False)¶ Partitions selection 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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves() >>> result = result.partition_by_counts( ... [3], ... cyclic=False, ... overhang=False, ... )
>>> for item in result: ... item ... Selection([Note("c'8"), Rest('r8'), Note("d'8")])
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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves().partition_by_counts( ... [3], ... cyclic=True, ... overhang=False, ... )
>>> for item in result: ... item ... Selection([Note("c'8"), Rest('r8'), Note("d'8")]) Selection([Note("e'8"), Rest('r8'), Note("f'8")])
>>> selector = abjad.select().leaves().partition_by_counts( ... [3], ... cyclic=True, ... overhang=False, ... ) >>> result = selector(staff)
>>> selector.print(result) Selection([Note("c'8"), Rest('r8'), Note("d'8")]) Selection([Note("e'8"), Rest('r8'), Note("f'8")])
>>> selector.color(result) >>> abjad.show(staff)
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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves().partition_by_counts( ... [3], ... cyclic=True, ... overhang=True, ... )
>>> for item in result: ... item ... Selection([Note("c'8"), Rest('r8'), Note("d'8")]) Selection([Note("e'8"), Rest('r8'), Note("f'8")]) Selection([Note("g'8"), Note("a'8")])
>>> selector = abjad.select().leaves().partition_by_counts( ... [3], ... cyclic=True, ... overhang=True, ... ) >>> result = selector(staff)
>>> selector.print(result) Selection([Note("c'8"), Rest('r8'), Note("d'8")]) Selection([Note("e'8"), Rest('r8'), Note("f'8")]) Selection([Note("g'8"), Note("a'8")])
>>> selector.color(result) >>> abjad.show(staff)
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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves().partition_by_counts( ... [3], ... cyclic=True, ... fuse_overhang=True, ... overhang=True, ... )
>>> for item in result: ... item ... Selection([Note("c'8"), Rest('r8'), Note("d'8")]) Selection([Note("e'8"), Rest('r8'), Note("f'8"), Note("g'8"), Note("a'8")])
>>> selector = abjad.select().leaves().partition_by_counts( ... [3], ... cyclic=True, ... fuse_overhang=True, ... overhang=True, ... ) >>> result = selector(staff)
>>> selector.print(result) Selection([Note("c'8"), Rest('r8'), Note("d'8")]) Selection([Note("e'8"), Rest('r8'), Note("f'8"), Note("g'8"), Note("a'8")])
>>> selector.color(result) >>> abjad.show(staff)
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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves().partition_by_counts( ... [1, 2, 3], ... cyclic=True, ... overhang=True, ... )
>>> for item in result: ... item ... Selection([Note("c'8")]) Selection([Rest('r8'), Note("d'8")]) Selection([Note("e'8"), Rest('r8'), Note("f'8")]) Selection([Note("g'8")]) Selection([Note("a'8"), Note("b'8")]) Selection([Rest('r8'), Note("c''8")])
>>> selector = abjad.select().leaves().partition_by_counts( ... [1, 2, 3], ... cyclic=True, ... overhang=True, ... ) >>> result = selector(staff)
>>> selector.print(result) Selection([Note("c'8")]) Selection([Rest('r8'), Note("d'8")]) Selection([Note("e'8"), Rest('r8'), Note("f'8")]) Selection([Note("g'8")]) Selection([Note("a'8"), Note("b'8")]) Selection([Rest('r8'), Note("c''8")])
>>> selector.color(result, ['red', 'blue', 'cyan']) >>> abjad.show(staff)
Returns nested selection (or expression):
>>> type(result).__name__ 'Selection'
-
partition_by_durations
(durations, cyclic=False, fill=None, in_seconds=False, overhang=False)¶ Partitions selection by
durations
.Cyclically partitions leaves into parts equal to exactly 3/8; returns overhang at end:
>>> staff = abjad.Staff( ... "abj: | 2/8 c'8 d'8 || 2/8 e'8 f'8 |" ... "| 2/8 g'8 a'8 || 2/8 b'8 c''8 |" ... ) >>> abjad.setting(staff).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves().partition_by_durations( ... [abjad.Duration(3, 8)], ... cyclic=True, ... fill=abjad.Exact, ... in_seconds=False, ... overhang=True, ... )
>>> for item in result: ... item ... Selection([Note("c'8"), Note("d'8"), Note("e'8")]) Selection([Note("f'8"), Note("g'8"), Note("a'8")]) Selection([Note("b'8"), Note("c''8")])
>>> selector = abjad.select().leaves().partition_by_durations( ... [abjad.Duration(3, 8)], ... cyclic=True, ... fill=abjad.Exact, ... in_seconds=False, ... overhang=True, ... ) >>> result = selector(staff)
>>> selector.print(result) Selection([Note("c'8"), Note("d'8"), Note("e'8")]) Selection([Note("f'8"), Note("g'8"), Note("a'8")]) Selection([Note("b'8"), Note("c''8")])
>>> selector.color(result) >>> abjad.show(staff)
Partitions leaves into one part equal to exactly 3/8; truncates overhang:
>>> staff = abjad.Staff( ... "abj: | 2/8 c'8 d'8 || 2/8 e'8 f'8 |" ... "| 2/8 g'8 a'8 || 2/8 b'8 c''8 |" ... ) >>> abjad.setting(staff).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves() >>> result = result.partition_by_durations( ... [abjad.Duration(3, 8)], ... cyclic=False, ... fill=abjad.Exact, ... in_seconds=False, ... overhang=False, ... )
>>> for item in result: ... item ... Selection([Note("c'8"), Note("d'8"), Note("e'8")])
>>> selector = abjad.select().leaves() >>> selector = selector.partition_by_durations( ... [abjad.Duration(3, 8)], ... cyclic=False, ... fill=abjad.Exact, ... in_seconds=False, ... overhang=False, ... ) >>> result = selector(staff)
>>> selector.print(result) Selection([Note("c'8"), Note("d'8"), Note("e'8")])
>>> selector.color(result) >>> abjad.show(staff)
Cyclically partitions leaves into parts equal to (or just less than) 3/16 and 1/16; returns overhang at end:
>>> staff = abjad.Staff( ... "abj: | 2/8 c'8 d'8 || 2/8 e'8 f'8 |" ... "| 2/8 g'8 a'8 || 2/8 b'8 c''8 |" ... ) >>> abjad.setting(staff).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves() >>> result = result.partition_by_durations( ... [abjad.Duration(3, 16), abjad.Duration(1, 16)], ... cyclic=True, ... fill=abjad.More, ... in_seconds=False, ... overhang=True, ... )
>>> for item in result: ... item ... Selection([Note("c'8"), Note("d'8")]) Selection([Note("e'8")]) Selection([Note("f'8"), Note("g'8")]) Selection([Note("a'8")]) Selection([Note("b'8"), Note("c''8")])
>>> selector = abjad.select().leaves() >>> selector = selector.partition_by_durations( ... [abjad.Duration(3, 16), abjad.Duration(1, 16)], ... cyclic=True, ... fill=abjad.More, ... in_seconds=False, ... overhang=True, ... ) >>> result = selector(staff)
>>> selector.print(result) Selection([Note("c'8"), Note("d'8")]) Selection([Note("e'8")]) Selection([Note("f'8"), Note("g'8")]) Selection([Note("a'8")]) Selection([Note("b'8"), Note("c''8")])
>>> selector.color(result) >>> abjad.show(staff)
Cyclically partitions leaves into parts equal to (or just less than) 3/16; truncates overhang:
>>> staff = abjad.Staff( ... "abj: | 2/8 c'8 d'8 || 2/8 e'8 f'8 |" ... "| 2/8 g'8 a'8 || 2/8 b'8 c''8 |" ... ) >>> abjad.setting(staff).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves() >>> result = result.partition_by_durations( ... [abjad.Duration(3, 16)], ... cyclic=True, ... fill=abjad.Less, ... in_seconds=False, ... overhang=False, ... )
>>> for item in result: ... item ... Selection([Note("c'8")]) Selection([Note("d'8")]) Selection([Note("e'8")]) Selection([Note("f'8")]) Selection([Note("g'8")]) Selection([Note("a'8")]) Selection([Note("b'8")])
>>> selector = abjad.select().leaves() >>> selector = selector.partition_by_durations( ... [abjad.Duration(3, 16)], ... cyclic=True, ... fill=abjad.Less, ... in_seconds=False, ... overhang=False, ... ) >>> result = selector(staff)
>>> selector.print(result) Selection([Note("c'8")]) Selection([Note("d'8")]) Selection([Note("e'8")]) Selection([Note("f'8")]) Selection([Note("g'8")]) Selection([Note("a'8")]) Selection([Note("b'8")])
>>> selector.color(result) >>> abjad.show(staff)
Partitions leaves into a single part equal to (or just less than) 3/16; truncates overhang:
>>> staff = abjad.Staff( ... "abj: | 2/8 c'8 d'8 || 2/8 e'8 f'8 |" ... "| 2/8 g'8 a'8 || 2/8 b'8 c''8 |" ... ) >>> abjad.setting(staff).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves() >>> result = result.partition_by_durations( ... [abjad.Duration(3, 16)], ... cyclic=False, ... fill=abjad.Less, ... in_seconds=False, ... overhang=False, ... )
>>> for item in result: ... item ... Selection([Note("c'8")])
>>> selector = abjad.select().leaves() >>> selector = selector.partition_by_durations( ... [abjad.Duration(3, 16)], ... cyclic=False, ... fill=abjad.Less, ... in_seconds=False, ... overhang=False, ... ) >>> result = selector(staff)
>>> selector.print(result) Selection([Note("c'8")])
>>> selector.color(result) >>> abjad.show(staff)
Cyclically partitions leaves into parts equal to exactly 1.5 seconds; truncates overhang:
>>> staff = abjad.Staff( ... "abj: | 2/8 c'8 d'8 || 2/8 e'8 f'8 |" ... "| 2/8 g'8 a'8 || 2/8 b'8 c''8 |" ... ) >>> abjad.setting(staff).auto_beaming = False >>> mark = abjad.MetronomeMark((1, 4), 60) >>> leaf = abjad.inspect(staff).leaf(0) >>> abjad.attach(mark, leaf, context='Staff') >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves() >>> result = result.partition_by_durations( ... [1.5], ... cyclic=True, ... fill=abjad.Exact, ... in_seconds=True, ... overhang=False, ... )
>>> for item in result: ... item ... Selection([Note("c'8"), Note("d'8"), Note("e'8")]) Selection([Note("f'8"), Note("g'8"), Note("a'8")])
>>> selector = abjad.select().leaves() >>> selector = selector.partition_by_durations( ... [1.5], ... cyclic=True, ... fill=abjad.Exact, ... in_seconds=True, ... overhang=False, ... ) >>> result = selector(staff)
>>> selector.print(result) Selection([Note("c'8"), Note("d'8"), Note("e'8")]) Selection([Note("f'8"), Note("g'8"), Note("a'8")])
>>> selector.color(result) >>> abjad.show(staff)
Cyclically partitions leaves into parts equal to exactly 1.5 seconds; returns overhang at end:
>>> staff = abjad.Staff( ... "abj: | 2/8 c'8 d'8 || 2/8 e'8 f'8 |" ... "| 2/8 g'8 a'8 || 2/8 b'8 c''8 |" ... ) >>> abjad.setting(staff).auto_beaming = False >>> mark = abjad.MetronomeMark((1, 4), 60) >>> leaf = abjad.inspect(staff).leaf(0) >>> abjad.attach(mark, leaf, context='Staff') >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves() >>> result = result.partition_by_durations( ... [1.5], ... cyclic=True, ... fill=abjad.Exact, ... in_seconds=True, ... overhang=True, ... )
>>> for item in result: ... item ... Selection([Note("c'8"), Note("d'8"), Note("e'8")]) Selection([Note("f'8"), Note("g'8"), Note("a'8")]) Selection([Note("b'8"), Note("c''8")])
>>> selector = abjad.select().leaves() >>> selector = selector.partition_by_durations( ... [1.5], ... cyclic=True, ... fill=abjad.Exact, ... in_seconds=True, ... overhang=True, ... )
>>> selector.print(result) Selection([Note("c'8"), Note("d'8"), Note("e'8")]) Selection([Note("f'8"), Note("g'8"), Note("a'8")]) Selection([Note("b'8"), Note("c''8")])
>>> selector.color(result) >>> abjad.show(staff)
Partitions leaves into a single part equal to exactly 1.5 seconds; truncates overhang:
>>> staff = abjad.Staff( ... "abj: | 2/8 c'8 d'8 || 2/8 e'8 f'8 |" ... "| 2/8 g'8 a'8 || 2/8 b'8 c''8 |" ... ) >>> abjad.setting(staff).auto_beaming = False >>> mark = abjad.MetronomeMark((1, 4), 60) >>> leaf = abjad.inspect(staff).leaf(0) >>> abjad.attach(mark, leaf, context='Staff') >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves() >>> result = result.partition_by_durations( ... [1.5], ... cyclic=False, ... fill=abjad.Exact, ... in_seconds=True, ... overhang=False, ... )
>>> for item in result: ... item ... Selection([Note("c'8"), Note("d'8"), Note("e'8")])
>>> selector = abjad.select().leaves() >>> selector = selector.partition_by_durations( ... [1.5], ... cyclic=False, ... fill=abjad.Exact, ... in_seconds=True, ... overhang=False, ... ) >>> result = selector(staff)
>>> selector.print(result) Selection([Note("c'8"), Note("d'8"), Note("e'8")])
>>> selector.color(result) >>> abjad.show(staff)
Cyclically partitions leaves into parts equal to (or just less than) 0.75 seconds; truncates overhang:
>>> staff = abjad.Staff( ... "abj: | 2/8 c'8 d'8 || 2/8 e'8 f'8 |" ... "| 2/8 g'8 a'8 || 2/8 b'8 c''8 |" ... ) >>> abjad.setting(staff).auto_beaming = False >>> mark = abjad.MetronomeMark((1, 4), 60) >>> leaf = abjad.inspect(staff).leaf(0) >>> abjad.attach(mark, leaf, context='Staff') >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves() >>> result = result.partition_by_durations( ... [0.75], ... cyclic=True, ... fill=abjad.Less, ... in_seconds=True, ... overhang=False, ... )
>>> for item in result: ... item ... Selection([Note("c'8")]) Selection([Note("d'8")]) Selection([Note("e'8")]) Selection([Note("f'8")]) Selection([Note("g'8")]) Selection([Note("a'8")]) Selection([Note("b'8")])
>>> selector = abjad.select().leaves() >>> selector = selector.partition_by_durations( ... [0.75], ... cyclic=True, ... fill=abjad.Less, ... in_seconds=True, ... overhang=False, ... ) >>> result = selector(staff)
>>> selector.print(result) Selection([Note("c'8")]) Selection([Note("d'8")]) Selection([Note("e'8")]) Selection([Note("f'8")]) Selection([Note("g'8")]) Selection([Note("a'8")]) Selection([Note("b'8")])
>>> selector.color(result) >>> abjad.show(staff)
Partitions leaves into one part equal to (or just less than) 0.75 seconds; truncates overhang:
>>> staff = abjad.Staff( ... "abj: | 2/8 c'8 d'8 || 2/8 e'8 f'8 |" ... "| 2/8 g'8 a'8 || 2/8 b'8 c''8 |" ... ) >>> abjad.setting(staff).auto_beaming = False >>> mark = abjad.MetronomeMark((1, 4), 60) >>> leaf = abjad.inspect(staff).leaf(0) >>> abjad.attach(mark, leaf, context='Staff') >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves() >>> result = result.partition_by_durations( ... [0.75], ... cyclic=False, ... fill=abjad.Less, ... in_seconds=True, ... overhang=False, ... )
>>> for item in result: ... item ... Selection([Note("c'8")])
>>> selector = abjad.select().leaves() >>> selector = selector.partition_by_durations( ... [0.75], ... cyclic=False, ... fill=abjad.Less, ... in_seconds=True, ... overhang=False, ... ) >>> result = selector(staff)
>>> selector.print(result) Selection([Note("c'8")])
>>> selector.color(result) >>> abjad.show(staff)
Interprets
fill
asExact
whenfill
is none.Parts must equal
durations
exactly whenfill
isExact
.Parts must be less than or equal to
durations
whenfill
isLess
.Parts must be greater or equal to
durations
whenfill
isMore
.Reads
durations
cyclically whencyclic
is true.Reads component durations in seconds when
in_seconds
is true.Returns remaining components at end in final part when
overhang
is true.Returns nested selection (or expression):
>>> type(result).__name__ 'Selection'
-
partition_by_ratio
(ratio)¶ Partitions selection 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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves() >>> result = result.partition_by_ratio((1, 1))
>>> for item in result: ... item ... Selection([Note("c'8"), Note("d'8"), Rest('r8'), Note("e'8"), Rest('r8')]) Selection([Note("f'8"), Note("g'8"), Note("a'8"), Rest('r8')])
>>> selector = abjad.select().leaves() >>> selector = selector.partition_by_ratio((1, 1)) >>> result = selector(staff)
>>> selector.print(result) Selection([Note("c'8"), Note("d'8"), Rest('r8'), Note("e'8"), Rest('r8')]) Selection([Note("f'8"), Note("g'8"), Note("a'8"), Rest('r8')])
>>> selector.color(result) >>> abjad.show(staff)
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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves() >>> result = result.partition_by_ratio((1, 1, 1))
>>> for item in result: ... item ... Selection([Note("c'8"), Note("d'8"), Rest('r8')]) Selection([Note("e'8"), Rest('r8'), Note("f'8")]) Selection([Note("g'8"), Note("a'8"), Rest('r8')])
>>> selector = abjad.select().leaves() >>> selector = selector.partition_by_ratio((1, 1, 1)) >>> result = selector(staff)
>>> selector.print(result) Selection([Note("c'8"), Note("d'8"), Rest('r8')]) Selection([Note("e'8"), Rest('r8'), Note("f'8")]) Selection([Note("g'8"), Note("a'8"), Rest('r8')])
>>> selector.color(result, ['red', 'blue', 'cyan']) >>> abjad.show(staff)
Returns nested selection (or expression):
>>> type(result).__name__ 'Selection'
-
rest
(n)¶ Selects rest
n
.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([(10, 9), (8, 9), (10, 9)], tuplets) >>> tuplets = [abjad.Tuplet(*_) for _ in tuplets] >>> tuplets = [abjad.select(tuplets)] >>> lilypond_file = abjad.LilyPondFile.rhythm(tuplets) >>> staff = lilypond_file[abjad.Staff] >>> abjad.setting(staff).auto_beaming = False >>> abjad.override(staff).tuplet_bracket.direction = abjad.Up >>> abjad.override(staff).tuplet_bracket.staff_padding = 3 >>> abjad.show(lilypond_file)
>>> result = abjad.select(staff).rest(-1)
>>> result Rest('r16')
-
rests
()¶ Selects rests.
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([(10, 9), (8, 9), (10, 9)], tuplets) >>> tuplets = [abjad.Tuplet(*_) for _ in tuplets] >>> tuplets = [abjad.select(tuplets)] >>> lilypond_file = abjad.LilyPondFile.rhythm(tuplets) >>> staff = lilypond_file[abjad.Staff] >>> abjad.setting(staff).auto_beaming = False >>> abjad.override(staff).tuplet_bracket.direction = abjad.Up >>> abjad.override(staff).tuplet_bracket.staff_padding = 3 >>> abjad.show(lilypond_file)
>>> result = abjad.select(staff).rests()
>>> for item in result: ... item ... Rest('r16') Rest('r16') Rest('r16')
-
run
(n)¶ Selects run
n
.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([(10, 9), (8, 9), (10, 9)], tuplets) >>> tuplets = [abjad.Tuplet(*_) for _ in tuplets] >>> tuplets = [abjad.select(tuplets)] >>> lilypond_file = abjad.LilyPondFile.rhythm(tuplets) >>> staff = lilypond_file[abjad.Staff] >>> abjad.setting(staff).auto_beaming = False >>> abjad.override(staff).tuplet_bracket.direction = abjad.Up >>> abjad.override(staff).tuplet_bracket.staff_padding = 3 >>> abjad.show(lilypond_file)
>>> result = abjad.select(staff).run(-1)
>>> result Selection([Note("e'16"), Note("e'16"), Note("e'16"), Chord("<fs' gs'>4"), Chord("<fs' gs'>16")])
-
runs
()¶ Selects runs.
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([(10, 9), (8, 9), (10, 9)], tuplets) >>> tuplets = [abjad.Tuplet(*_) for _ in tuplets] >>> tuplets = [abjad.select(tuplets)] >>> lilypond_file = abjad.LilyPondFile.rhythm(tuplets) >>> staff = lilypond_file[abjad.Staff] >>> abjad.setting(staff).auto_beaming = False >>> abjad.override(staff).tuplet_bracket.direction = abjad.Up >>> abjad.override(staff).tuplet_bracket.staff_padding = 3 >>> abjad.show(lilypond_file)
>>> result = abjad.select(staff).runs()
>>> for item in result: ... item ... Selection([Note("c'16"), Note("c'16"), Note("c'16"), Chord("<d' e'>4"), Chord("<d' e'>16")]) Selection([Note("d'16"), Note("d'16"), Note("d'16"), Chord("<e' fs'>4"), Chord("<e' fs'>16")]) Selection([Note("e'16"), Note("e'16"), Note("e'16"), Chord("<fs' gs'>4"), Chord("<fs' gs'>16")])
>>> selector = abjad.select().runs() >>> result = selector(staff)
>>> selector.print(result) Selection([Note("c'16"), Note("c'16"), Note("c'16"), Chord("<d' e'>4"), Chord("<d' e'>16")]) Selection([Note("d'16"), Note("d'16"), Note("d'16"), Chord("<e' fs'>4"), Chord("<e' fs'>16")]) Selection([Note("e'16"), Note("e'16"), Note("e'16"), Chord("<fs' gs'>4"), Chord("<fs' gs'>16")])
>>> selector.color(result) >>> abjad.show(lilypond_file)
-
top
()¶ Selects top components.
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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).leaves().top()
>>> for item in result: ... item ... Note("c'8") Note("d'8") Rest('r8') Tuplet(Multiplier(2, 3), "e'8 r8 f'8") Note("g'8") Note("a'8") Rest('r8')
-
tuplet
(n)¶ Selects tuplet
n
.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([(10, 9), (8, 9), (10, 9)], tuplets) >>> tuplets = [abjad.Tuplet(*_) for _ in tuplets] >>> tuplets = [abjad.select(tuplets)] >>> lilypond_file = abjad.LilyPondFile.rhythm(tuplets) >>> staff = lilypond_file[abjad.Staff] >>> abjad.setting(staff).auto_beaming = False >>> abjad.override(staff).tuplet_bracket.direction = abjad.Up >>> abjad.override(staff).tuplet_bracket.staff_padding = 3 >>> abjad.show(lilypond_file)
>>> result = abjad.select(staff).tuplet(-1)
>>> result Tuplet(Multiplier(10, 9), "r16 bf'16 <a'' b''>16 e'16 <fs' gs'>4 ~ <fs' gs'>16")
-
tuplets
()¶ Selects tuplets.
Selects 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([(10, 9), (8, 9), (10, 9)], tuplets) >>> tuplets = [abjad.Tuplet(*_) for _ in tuplets] >>> tuplets = [abjad.select(tuplets)] >>> lilypond_file = abjad.LilyPondFile.rhythm(tuplets) >>> staff = lilypond_file[abjad.Staff] >>> abjad.setting(staff).auto_beaming = False >>> abjad.override(staff).tuplet_bracket.direction = abjad.Up >>> abjad.override(staff).tuplet_bracket.staff_padding = 3 >>> abjad.show(lilypond_file)
>>> result = abjad.select(staff).tuplets()
>>> for item in result: ... item ... Tuplet(Multiplier(10, 9), "r16 bf'16 <a'' b''>16 c'16 <d' e'>4 ~ <d' e'>16") Tuplet(Multiplier(8, 9), "r16 bf'16 <a'' b''>16 d'16 <e' fs'>4 ~ <e' fs'>16") Tuplet(Multiplier(10, 9), "r16 bf'16 <a'' b''>16 e'16 <fs' gs'>4 ~ <fs' gs'>16")
>>> selector = abjad.select().tuplets() >>> result = selector(staff)
>>> selector.print(result) Tuplet(Multiplier(10, 9), "r16 bf'16 <a'' b''>16 c'16 <d' e'>4 ~ <d' e'>16") Tuplet(Multiplier(8, 9), "r16 bf'16 <a'' b''>16 d'16 <e' fs'>4 ~ <e' fs'>16") Tuplet(Multiplier(10, 9), "r16 bf'16 <a'' b''>16 e'16 <fs' gs'>4 ~ <fs' gs'>16")
>>> selector.color(result) >>> abjad.show(lilypond_file)
-
with_next_leaf
()¶ Extends selection 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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).runs() >>> result = result.map(abjad.select().with_next_leaf())
>>> for item in result: ... item ... Selection([Note("c'8"), Rest('r8')]) Selection([Note("d'8"), Note("e'8"), Rest('r8')]) Selection([Note("f'8"), Note("g'8"), Note("a'8")])
>>> selector = abjad.select().runs() >>> selector = selector.map(abjad.select().with_next_leaf()) >>> result = selector(staff)
>>> selector.print(result) Selection([Note("c'8"), Rest('r8')]) Selection([Note("d'8"), Note("e'8"), Rest('r8')]) Selection([Note("f'8"), Note("g'8"), Note("a'8")])
>>> selector.color(result) >>> abjad.show(staff)
Selects pitched tails (each with next leaf):
>>> staff = abjad.Staff(r"c'8 r d' ~ d' e' ~ e' r8 f'8") >>> abjad.setting(staff).auto_beaming = False >>> abjad.show(staff)
>>> getter = abjad.select()[-1].select().with_next_leaf() >>> result = abjad.select(staff).logical_ties(pitched=True) >>> result = result.map(getter)
>>> for item in result: ... item ... Selection([Note("c'8"), Rest('r8')]) Selection([Note("d'8"), Note("e'8")]) Selection([Note("e'8"), Rest('r8')]) Selection([Note("f'8")])
>>> selector = abjad.select().logical_ties(pitched=True) >>> selector = selector.map(getter) >>> result = selector(staff)
>>> selector.print(result) Selection([Note("c'8"), Rest('r8')]) Selection([Note("d'8"), Note("e'8")]) Selection([Note("e'8"), Rest('r8')]) Selection([Note("f'8")])
>>> selector.color(result) >>> abjad.show(staff)
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).auto_beaming = False >>> abjad.show(staff)
>>> result = abjad.select(staff).logical_ties(pitched=True) >>> result = result.map(abjad.select().with_next_leaf())
>>> for item in result: ... item ... Selection([Note("c'8"), Rest('r8')]) Selection([Note("d'8"), Note("d'8"), Note("e'8")]) Selection([Note("e'8"), Note("e'8"), Rest('r8')]) Selection([Note("f'8")])
>>> selector = abjad.select().logical_ties(pitched=True) >>> selector = selector.map(abjad.select().with_next_leaf()) >>> result = selector(staff)
>>> selector.print(result) Selection([Note("c'8"), Rest('r8')]) Selection([Note("d'8"), Note("d'8"), Note("e'8")]) Selection([Note("e'8"), Note("e'8"), Rest('r8')]) Selection([Note("f'8")])
>>> for item in result: ... abjad.attach(abjad.PianoPedalSpanner(), item) ...
>>> selector.color(result) >>> manager = abjad.override(staff).sustain_pedal_line_spanner >>> manager.staff_padding = 6 >>> abjad.show(staff)
Returns new selection (or expression).
-
with_previous_leaf
()¶ Extends selection 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).auto_beaming = False >>> abjad.show(staff)
>>> getter = abjad.select().with_previous_leaf() >>> result = abjad.select(staff).runs().map(getter)
>>> for item in result: ... item ... Selection([Note("c'8")]) Selection([Rest('r8'), Note("d'8"), Note("e'8")]) Selection([Rest('r8'), Note("f'8"), Note("g'8"), Note("a'8")])
Selects pitched heads (each with previous leaf):
>>> staff = abjad.Staff(r"c'8 r d' ~ d' e' ~ e' r8 f'8") >>> abjad.setting(staff).auto_beaming = False >>> abjad.show(staff)
>>> getter = abjad.select()[0].select().with_previous_leaf() >>> result = abjad.select(staff).logical_ties(pitched=True) >>> result = result.map(getter)
>>> for item in result: ... item ... Selection([Note("c'8")]) Selection([Rest('r8'), Note("d'8")]) Selection([Note("d'8"), Note("e'8")]) Selection([Rest('r8'), Note("f'8")])
>>> selector = abjad.select().logical_ties(pitched=True) >>> selector = selector.map(getter) >>> result = selector(staff)
>>> selector.print(result) Selection([Note("c'8")]) Selection([Rest('r8'), Note("d'8")]) Selection([Note("d'8"), Note("e'8")]) Selection([Rest('r8'), Note("f'8")])
>>> selector.color(result) >>> abjad.show(staff)
Returns new selection (or expression).
Read-only properties
-
items
¶ Gets items.
>>> abjad.Staff("c'4 d'4 e'4 f'4")[:].items (Note("c'4"), Note("d'4"), Note("e'4"), Note("f'4"))
Returns tuple.
-