PitchClassSegment

digraph InheritanceGraph { graph [bgcolor=transparent, color=lightsteelblue2, fontname=Arial, fontsize=10, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, splines=spline, style="dashed, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=10, height=0, penwidth=2, shape=box, style="filled, rounded", width=0]; edge [color=lightslategrey, penwidth=1]; subgraph "cluster_abjad.pitch" { graph [label="abjad.pitch"]; node [color=1]; "abjad.pitch.PitchClassSegment.PitchClassSegment" [URL="../api/abjad/pitch/PitchClassSegment.html#abjad.pitch.PitchClassSegment.PitchClassSegment", color=black, fontcolor=white, label="Pitch\nClass\nSegment", target=_top]; "abjad.pitch.Segment.Segment" [URL="../api/abjad/pitch/Segment.html#abjad.pitch.Segment.Segment", label=Segment, shape=oval, style=bold, target=_top]; "abjad.pitch.TwelveToneRow.TwelveToneRow" [URL="../api/abjad/pitch/TwelveToneRow.html#abjad.pitch.TwelveToneRow.TwelveToneRow", label="Twelve\nTone\nRow", target=_top]; "abjad.pitch.PitchClassSegment.PitchClassSegment" -> "abjad.pitch.TwelveToneRow.TwelveToneRow"; "abjad.pitch.Segment.Segment" -> "abjad.pitch.PitchClassSegment.PitchClassSegment"; } subgraph "cluster_abjad.system" { graph [label="abjad.system"]; node [color=2]; "abjad.system.AbjadObject.AbjadObject" [URL="../api/abjad/pitch/../system/AbjadObject.html#abjad.system.AbjadObject.AbjadObject", label="Abjad\nObject", target=_top]; } subgraph "cluster_abjad.utilities" { graph [label="abjad.utilities"]; node [color=3]; "abjad.utilities.TypedCollection.TypedCollection" [URL="../api/abjad/pitch/../utilities/TypedCollection.html#abjad.utilities.TypedCollection.TypedCollection", label="Typed\nCollection", shape=oval, style=bold, target=_top]; "abjad.utilities.TypedTuple.TypedTuple" [URL="../api/abjad/pitch/../utilities/TypedTuple.html#abjad.utilities.TypedTuple.TypedTuple", label="Typed\nTuple", target=_top]; "abjad.utilities.TypedCollection.TypedCollection" -> "abjad.utilities.TypedTuple.TypedTuple"; } subgraph cluster_builtins { graph [label=builtins]; node [color=4]; "builtins.object" [URL="https://docs.python.org/3.6/library/functions.html#object", label=object, target=_top]; } subgraph "cluster_collections.abc" { graph [label="collections.abc"]; node [color=5]; "collections.abc.Collection" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Collection", label=Collection, shape=oval, style=bold, target=_top]; "collections.abc.Container" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Container", label=Container, shape=oval, style=bold, target=_top]; "collections.abc.Iterable" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Iterable", label=Iterable, shape=oval, style=bold, target=_top]; "collections.abc.Reversible" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Reversible", label=Reversible, shape=oval, style=bold, target=_top]; "collections.abc.Sequence" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Sequence", label=Sequence, shape=oval, style=bold, target=_top]; "collections.abc.Sized" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Sized", label=Sized, shape=oval, style=bold, target=_top]; "collections.abc.Collection" -> "collections.abc.Sequence"; "collections.abc.Container" -> "collections.abc.Collection"; "collections.abc.Iterable" -> "collections.abc.Collection"; "collections.abc.Iterable" -> "collections.abc.Reversible"; "collections.abc.Reversible" -> "collections.abc.Sequence"; "collections.abc.Sized" -> "collections.abc.Collection"; } "abjad.system.AbjadObject.AbjadObject" -> "abjad.utilities.TypedCollection.TypedCollection"; "abjad.utilities.TypedTuple.TypedTuple" -> "abjad.pitch.Segment.Segment"; "builtins.object" -> "abjad.system.AbjadObject.AbjadObject"; "builtins.object" -> "collections.abc.Container"; "builtins.object" -> "collections.abc.Iterable"; "builtins.object" -> "collections.abc.Sized"; "collections.abc.Sequence" -> "abjad.utilities.TypedTuple.TypedTuple"; }

class abjad.pitch.PitchClassSegment.PitchClassSegment(items=None, item_class=None)

Pitch-class segment.

Initializes segment with numbered pitch-classes:

>>> items = [-2, -1.5, 6, 7, -1.5, 7]
>>> segment = abjad.PitchClassSegment(items=items)
>>> abjad.show(segment) 
>>> expression = abjad.Expression()
>>> expression = expression.pitch_class_segment()
>>> segment = expression([-2, -1.5, 6, 7, -1.5, 7])
>>> abjad.show(segment) 

Initializes segment with named pitch-classes:

>>> items = ['c', 'ef', 'bqs,', 'd']
>>> segment = abjad.PitchClassSegment(
...     items=items,
...     item_class=abjad.NamedPitchClass,
...     )
>>> abjad.show(segment) 
>>> expression = abjad.Expression()
>>> expression = expression.pitch_class_segment(
...     item_class=abjad.NamedPitchClass,
...     )
>>> segment = expression(['c', 'ef', 'bqs,', 'd'])
>>> abjad.show(segment) 

Attributes Summary

__add__ Adds argument to segment.
__contains__ Is true when pitch-class segment contains argument.
__format__ Formats segment.
__getitem__ Gets argument from segment.
__illustrate__ Illustrates segment.
__mul__ Multiplies pitch-class segment by n.
__repr__ Gets interpreter representation.
__rmul__ Multiplies n by pitch-class segment.
__str__ Gets string representation of pitch-class segment.
count Counts item in segment.
from_selection Initializes segment from selection.
has_duplicates Is true when segment contains duplicate items.
index Gets index of item in segment.
invert Inverts segment.
item_class Gets item class of segment.
items Gets items in segment.
make_notes Makes first n notes in segment.
multiply Multiplies pitch-classes in segment by n.
permute Permutes segment by twelve-tone row.
retrograde Gets retrograde of segment.
rotate Rotates segment by index n.
to_pitch_classes Changes to pitch-classes.
to_pitches Changes to pitches.
transpose Transposes segment by index n.
voice_horizontally Voices segment with each pitch as close to the previous pitch as possible.
voice_vertically Voices segment with each pitch higher than the previous.

Special methods

__add__(argument)

Adds argument to segment.

Example segments:

>>> pitch_numbers = [-2, -1.5, 6, 7, -1.5, 7]
>>> abjad.PitchClassSegment(items=pitch_numbers)
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7])
>>> J = abjad.PitchClassSegment(items=pitch_numbers)
>>> abjad.show(J) 
>>> pitch_names = ['c', 'ef', 'bqs,', 'd']
>>> abjad.PitchClassSegment(items=pitch_names)
PitchClassSegment("c ef bqs d")
>>> K = abjad.PitchClassSegment(items=pitch_names)
>>> abjad.show(K) 

Adds J and K:

>>> J + K
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7, 0, 3, 11.5, 2])
>>> segment = J + K
>>> abjad.show(segment) 
>>> expression_J = abjad.Expression(name='J')
>>> expression_J = expression_J.pitch_class_segment()
>>> expression_K = abjad.Expression(name='K')
>>> expression_K = expression_K.pitch_class_segment()
>>> expression = expression_J + expression_K
>>> expression(pitch_numbers, pitch_names)
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7, 0, 3, 11.5, 2])
>>> expression.get_string()
'J + K'
>>> segment = expression(pitch_numbers, pitch_names)
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 

Adds K and J:

>>> K + J
PitchClassSegment("c ef bqs d bf bqf fs g bqf g")
>>> segment = K + J
>>> abjad.show(segment) 
>>> expression_J = abjad.Expression(name='J')
>>> expression_J = expression_J.pitch_class_segment()
>>> expression_K = abjad.Expression(name='K')
>>> expression_K = expression_K.pitch_class_segment()
>>> expression = expression_K + expression_J
>>> expression(pitch_names, pitch_numbers)
PitchClassSegment("c ef bqs d bf bqf fs g bqf g")
>>> expression.get_string()
'K + J'
>>> segment = expression(pitch_names, pitch_numbers)
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 

Adds J repeatedly:

>>> J + J + J
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7, 10, 10.5, 6, 7, 10.5, 7, 10, 10.5, 6, 7, 10.5, 7])
>>> segment = J + J + J
>>> abjad.show(segment) 
>>> expression_J = abjad.Expression(name='J')
>>> expression_J = expression_J.pitch_class_segment()
>>> expression = expression_J + expression_J + expression_J
>>> expression(pitch_numbers, pitch_numbers, pitch_numbers)
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7, 10, 10.5, 6, 7, 10.5, 7, 10, 10.5, 6, 7, 10.5, 7])
>>> expression.get_string()
'J + J + J'
>>> list_ = [pitch_numbers, pitch_numbers, pitch_numbers]
>>> segment = expression(*list_)
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 

Adds transformed segments:

>>> J.rotate(n=1) + K.rotate(n=2)
PitchClassSegment([7, 10, 10.5, 6, 7, 10.5, 11.5, 2, 0, 3])
>>> segment = J.rotate(n=1) + K.rotate(n=2)
>>> abjad.show(segment) 
>>> expression_J = abjad.Expression(name='J')
>>> expression_J = expression_J.pitch_class_segment()
>>> expression_J = expression_J.rotate(n=1)
>>> expression_K = abjad.Expression(name='K')
>>> expression_K = expression_K.pitch_class_segment()
>>> expression_K = expression_K.rotate(n=2)
>>> expression = expression_J + expression_K
>>> expression(pitch_numbers, pitch_names)
PitchClassSegment([7, 10, 10.5, 6, 7, 10.5, 11.5, 2, 0, 3])
>>> expression.get_string()
'r1(J) + r2(K)'
>>> segment = expression(pitch_numbers, pitch_names)
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 

Reverses result:

>>> segment = J.rotate(n=1) + K.rotate(n=2)
>>> segment.retrograde()
PitchClassSegment([3, 0, 2, 11.5, 10.5, 7, 6, 10.5, 10, 7])
>>> segment = segment.retrograde()
>>> abjad.show(segment) 
>>> expression_J = abjad.Expression(name='J')
>>> expression_J = expression_J.pitch_class_segment()
>>> expression_J = expression_J.rotate(n=1)
>>> expression_K = abjad.Expression(name='K')
>>> expression_K = expression_K.pitch_class_segment()
>>> expression_K = expression_K.rotate(n=2)
>>> expression = expression_J + expression_K
>>> expression = expression.retrograde()
>>> expression(pitch_numbers, pitch_names)
PitchClassSegment([3, 0, 2, 11.5, 10.5, 7, 6, 10.5, 10, 7])
>>> expression.get_string()
'R(r1(J) + r2(K))'
>>> segment = expression(pitch_numbers, pitch_names)
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 

Establishes equivalence:

>>> expression_J = abjad.Expression(name='J')
>>> expression_J = expression_J.pitch_class_segment()
>>> expression_J = expression_J.rotate(n=1)
>>> expression_K = abjad.Expression(name='K')
>>> expression_K = expression_K.pitch_class_segment()
>>> expression_K = expression_K.rotate(n=2)
>>> expression = expression_J + expression_K
>>> expression = expression.establish_equivalence(name='Q')
>>> expression(pitch_numbers, pitch_names)
PitchClassSegment([7, 10, 10.5, 6, 7, 10.5, 11.5, 2, 0, 3])
>>> expression.get_string()
'Q = r1(J) + r2(K)'
>>> segment = expression(pitch_numbers, pitch_names)
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 

Transforms equivalence:

>>> expression = expression.transpose(n=1)
>>> expression(pitch_numbers, pitch_names)
PitchClassSegment([8, 11, 11.5, 7, 8, 11.5, 0.5, 3, 1, 4])
>>> expression.get_string()
'T1(Q)'
>>> segment = expression(pitch_numbers, pitch_names)
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 

Returns new segment.

__contains__(argument)

Is true when pitch-class segment contains argument.

Example segments:

>>> pitch_numbers = [-2, -1.5, 6, 7, -1.5, 7]
>>> segment = abjad.PitchClassSegment(items=pitch_numbers)
>>> segment
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7])
>>> abjad.NamedPitch('bf') in segment
True
>>> abjad.NamedPitch('cs') in segment
False
>>> 'bf' in segment
True
>>> 'cs' in segment
False
>>> 10 in segment
True
>>> 13 in segment
False

Returns true or false.

(TypedCollection).__eq__(argument)

Is true when argument is a typed collection with items that compare equal to those of this typed collection.

Returns true or false.

__format__(format_specification='')

Formats segment.

With numbered pitch-classes:

>>> pitch_numbers = [-2, -1.5, 6, 7, -1.5, 7]
>>> J = abjad.PitchClassSegment(items=pitch_numbers)
>>> abjad.f(J)
abjad.PitchClassSegment(
    (
        abjad.NumberedPitchClass(10),
        abjad.NumberedPitchClass(10.5),
        abjad.NumberedPitchClass(6),
        abjad.NumberedPitchClass(7),
        abjad.NumberedPitchClass(10.5),
        abjad.NumberedPitchClass(7),
        ),
    item_class=abjad.NumberedPitchClass,
    )
>>> abjad.show(J) 

With named pitch-classes:

>>> pitch_names = ['c', 'ef', 'bqs,', 'd']
>>> K = abjad.PitchClassSegment(
...     items=pitch_names,
...     item_class=abjad.NamedPitchClass,
...     )
>>> abjad.f(K)
abjad.PitchClassSegment(
    (
        abjad.NamedPitchClass('c'),
        abjad.NamedPitchClass('ef'),
        abjad.NamedPitchClass('bqs'),
        abjad.NamedPitchClass('d'),
        ),
    item_class=abjad.NamedPitchClass,
    )
>>> abjad.show(K) 

Returns string.

__getitem__(argument)

Gets argument from segment.

Example segment:

>>> pitch_numbers = [-2, -1.5, 6, 7, -1.5, 7]
>>> abjad.PitchClassSegment(items=pitch_numbers)
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7])
>>> J = abjad.PitchClassSegment(items=pitch_numbers)
>>> abjad.show(J) 

Gets item at nonnegative index:

>>> J[0]
NumberedPitchClass(10)
>>> expression = abjad.Expression(name='J')
>>> expression = expression.pitch_class_segment()
>>> expression = expression[0]
>>> expression(items=[-2, -1.5, 6, 7, -1.5, 7])
NumberedPitchClass(10)
>>> expression.get_string()
'J[0]'
>>> markup = expression.get_markup()
>>> abjad.show(markup) 

Gets item at negative index:

>>> J[-1]
NumberedPitchClass(7)
>>> expression = abjad.Expression(name='J')
>>> expression = expression.pitch_class_segment()
>>> expression = expression[-1]
>>> expression(items=[-2, -1.5, 6, 7, -1.5, 7])
NumberedPitchClass(7)
>>> expression.get_string()
'J[-1]'
>>> markup = expression.get_markup()
>>> abjad.show(markup) 

Gets slice:

>>> J[:4]
PitchClassSegment([10, 10.5, 6, 7])
>>> segment = J[:4]
>>> abjad.show(segment) 
>>> expression = abjad.Expression(name='J')
>>> expression = expression.pitch_class_segment()
>>> expression = expression[:4]
>>> expression(items=[-2, -1.5, 6, 7, -1.5, 7])
PitchClassSegment([10, 10.5, 6, 7])
>>> expression.get_string()
'J[:4]'
>>> segment = expression(items=[-2, -1.5, 6, 7, -1.5, 7])
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 

Gets retrograde of slice:

>>> J[:4].retrograde()
PitchClassSegment([7, 6, 10.5, 10])
>>> segment = J[:4].retrograde()
>>> abjad.show(segment) 
>>> expression = abjad.Expression(name='J')
>>> expression = expression.pitch_class_segment()
>>> expression = expression[:4]
>>> expression = expression.retrograde()
>>> expression(items=[-2, -1.5, 6, 7, -1.5, 7])
PitchClassSegment([7, 6, 10.5, 10])
>>> expression.get_string()
'R(J[:4])'
>>> segment = expression(items=[-2, -1.5, 6, 7, -1.5, 7])
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 

Gets slice of retrograde:

>>> J.retrograde()[:4]
PitchClassSegment([7, 10.5, 7, 6])
>>> segment = J.retrograde()[:4]
>>> abjad.show(segment) 
>>> expression = abjad.Expression(name='J')
>>> expression = expression.pitch_class_segment()
>>> expression = expression.retrograde()
>>> expression = expression[:4]
>>> expression(items=[-2, -1.5, 6, 7, -1.5, 7])
PitchClassSegment([7, 10.5, 7, 6])
>>> expression.get_string()
'R(J)[:4]'
>>> segment = expression(items=[-2, -1.5, 6, 7, -1.5, 7])
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 

Returns pitch-class or pitch-class segment:

>>> isinstance(segment, abjad.PitchClassSegment)
True
(TypedTuple).__hash__()

Hashes typed tuple.

Returns integer.

__illustrate__(expression_markup_direction=Up, **keywords)

Illustrates segment.

Illustrates numbered segment:

>>> items = [-2, -1.5, 6, 7, -1.5, 7]
>>> segment = abjad.PitchClassSegment(items=items)
>>> abjad.show(segment) 

Illustrates named segment:

>>> items = ['c', 'ef', 'bqs,', 'd']
>>> segment = abjad.PitchClassSegment(
...     items=items,
...     item_class=abjad.NumberedPitchClass,
...     )
>>> abjad.show(segment) 

Returns LilyPond file:

>>> prototype = abjad.LilyPondFile
>>> isinstance(segment.__illustrate__(), prototype)
True
(TypedCollection).__iter__()

Iterates typed collection.

Returns generator.

(TypedCollection).__len__()

Gets length of typed collection.

Returns nonnegative integer.

__mul__(n)

Multiplies pitch-class segment by n.

>>> items = [-2, -1.5, 6, 7, -1.5, 7]
>>> 2 * abjad.PitchClassSegment(items=items)
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7, 10, 10.5, 6, 7, 10.5, 7])

Returns new pitch-class segment.

(TypedTuple).__radd__(argument)

Right-adds argument to typed tuple.

__repr__()

Gets interpreter representation.

Interpreter representation:

>>> items = [-2, -1.5, 6, 7, -1.5, 7]
>>> abjad.PitchClassSegment(items=items)
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7])

Returns string.

(Sequence).__reversed__()
__rmul__(n)

Multiplies n by pitch-class segment.

>>> items = [-2, -1.5, 6, 7, -1.5, 7]
>>> abjad.PitchClassSegment(items=items) * 2
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7, 10, 10.5, 6, 7, 10.5, 7])

Returns new pitch-class segment.

__str__()

Gets string representation of pitch-class segment.

Gets string represenation of numbered pitch class:

>>> segment = abjad.PitchClassSegment([-2, -1.5, 6, 7, -1.5, 7])
>>> str(segment)
'PC<10, 10.5, 6, 7, 10.5, 7>'

Gets string represenation of named pitch class:

>>> segment = abjad.PitchClassSegment(
...     items=[-2, -1.5, 6, 7, -1.5, 7],
...     item_class=abjad.NamedPitchClass,
...     )
>>> str(segment)
'PC<bf bqf fs g bqf g>'

Returns string.


Methods

count(item)

Counts item in segment.

Example segment:

>>> items = [-2, -1.5, 6, 7, -1.5, 7]
>>> segment = abjad.PitchClassSegment(items=items)
>>> abjad.show(segment) 

Counts existing item in segment:

>>> segment.count(-1.5)
2

Counts nonexisting item in segment:

>>> segment.count('text')
0

Returns nonnegative integer:

>>> isinstance(segment.count('text'), int)
True
has_duplicates()

Is true when segment contains duplicate items.

Has duplicates:

>>> items = [-2, -1.5, 6, 7, -1.5, 7]
>>> segment = abjad.PitchClassSegment(items=items)
>>> abjad.show(segment) 
>>> segment.has_duplicates()
True

Has no duplicates:

>>> items = "c d e f g a b"
>>> segment = abjad.PitchClassSegment(items=items)
>>> abjad.show(segment) 
>>> segment.has_duplicates()
False

Returns true or false.

index(item)

Gets index of item in segment.

Example segment:

>>> items = [-2, -1.5, 6, 7, -1.5, 7]
>>> segment = abjad.PitchClassSegment(items=items)
>>> abjad.show(segment) 

Gets index of first item in segment:

>>> segment.index(-2)
0

Gets index of second item in segment:

>>> segment.index(-1.5)
1

Returns nonnegative integer:

>>> isinstance(segment.index(-1.5), int)
True
invert(axis=None)

Inverts segment.

Example segment:

>>> items = [-2, -1.5, 6, 7, -1.5, 7]
>>> J = abjad.PitchClassSegment(items=items)
>>> J
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7])
>>> abjad.show(J) 

Inverts segment:

>>> J.invert()
PitchClassSegment([2, 1.5, 6, 5, 1.5, 5])
>>> segment = J.invert()
>>> abjad.show(segment) 
>>> expression = abjad.Expression(name='J')
>>> expression = expression.pitch_class_segment()
>>> expression = expression.invert()
>>> expression([-2, -1.5, 6, 7, -1.5, 7])
PitchClassSegment([2, 1.5, 6, 5, 1.5, 5])
>>> expression.get_string()
'I(J)'
>>> segment = expression([-2, -1.5, 6, 7, -1.5, 7])
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 

Inverts inversion of segment:

>>> J.invert().invert()
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7])
>>> segment = J.invert().invert()
>>> abjad.show(segment) 
>>> segment == J
True
>>> expression = abjad.Expression(name='J')
>>> expression = expression.pitch_class_segment()
>>> expression = expression.invert()
>>> expression = expression.invert()
>>> expression([-2, -1.5, 6, 7, -1.5, 7])
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7])
>>> expression.get_string()
'I(I(J))'
>>> segment = expression([-2, -1.5, 6, 7, -1.5, 7])
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 

Returns pitch-class segment:

>>> isinstance(segment, abjad.PitchClassSegment)
True
make_notes(n=None, written_duration=None)

Makes first n notes in segment.

Example segment:

>>> items = [2, 4.5, 6, 11, 4.5, 10]
>>> segment = abjad.PitchClassSegment(items=items)
>>> abjad.show(segment) 

Makes eighth notes:

>>> notes = segment.make_notes()
>>> staff = abjad.Staff(notes)
>>> abjad.show(staff) 

Makes notes with nonassignable durations:

>>> notes = segment.make_notes(4, abjad.Duration(5, 16))
>>> staff = abjad.Staff(notes)
>>> time_signature = abjad.TimeSignature((5, 4))
>>> abjad.attach(time_signature, staff[0])
>>> abjad.show(staff) 

Interprets none-valued n equal to length of segment.

Interprets none-valued written_duration equal to 1/8.

Returns selection:

>>> isinstance(segment.make_notes(), abjad.Selection)
True
multiply(n=1)

Multiplies pitch-classes in segment by n.

Example segment:

>>> items = [-2, -1.5, 6, 7, -1.5, 7]
>>> J = abjad.PitchClassSegment(items=items)
>>> J
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7])
>>> abjad.show(J) 

Multiplies pitch-classes in segment by 1:

>>> J.multiply(n=1)
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7])
>>> segment = J.multiply(n=1)
>>> abjad.show(segment) 
>>> expression = abjad.Expression(name='J')
>>> expression = expression.pitch_class_segment()
>>> expression = expression.multiply(n=1)
>>> expression([-2, -1.5, 6, 7, -1.5, 7])
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7])
>>> expression.get_string()
'M1(J)'
>>> segment = expression([-2, -1.5, 6, 7, -1.5, 7])
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 

Multiplies pitch-classes in segment by 5:

>>> J.multiply(n=5)
PitchClassSegment([2, 4.5, 6, 11, 4.5, 11])
>>> segment = J.multiply(n=5)
>>> abjad.show(segment) 
>>> expression = abjad.Expression(name='J')
>>> expression = expression.pitch_class_segment()
>>> expression = expression.multiply(n=5)
>>> expression([-2, -1.5, 6, 7, -1.5, 7])
PitchClassSegment([2, 4.5, 6, 11, 4.5, 11])
>>> expression.get_string()
'M5(J)'
>>> segment = expression([-2, -1.5, 6, 7, -1.5, 7])
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 

Multiplies pitch-classes in segment by 7:

>>> J.multiply(n=7)
PitchClassSegment([10, 1.5, 6, 1, 1.5, 1])
>>> segment = J.multiply(n=7)
>>> abjad.show(segment) 
>>> expression = abjad.Expression(name='J')
>>> expression = expression.pitch_class_segment()
>>> expression = expression.multiply(n=7)
>>> expression([-2, -1.5, 6, 7, -1.5, 7])
PitchClassSegment([10, 1.5, 6, 1, 1.5, 1])
>>> expression.get_string()
'M7(J)'
>>> segment = expression([-2, -1.5, 6, 7, -1.5, 7])
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 

Multiplies pitch-classes in segment by 11:

>>> segment = J.multiply(n=11)
>>> segment
PitchClassSegment([2, 7.5, 6, 5, 7.5, 5])
>>> abjad.show(segment) 
>>> expression = abjad.Expression(name='J')
>>> expression = expression.pitch_class_segment()
>>> expression = expression.multiply(n=11)
>>> expression([-2, -1.5, 6, 7, -1.5, 7])
PitchClassSegment([2, 7.5, 6, 5, 7.5, 5])
>>> expression.get_string()
'M11(J)'
>>> segment = expression([-2, -1.5, 6, 7, -1.5, 7])
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 

Returns pitch-class segment:

>>> isinstance(segment, abjad.PitchClassSegment)
True
permute(row=None)

Permutes segment by twelve-tone row.

>>> abjad.PitchClassSegment([-2, -1, 6, 7, -1, 7])
PitchClassSegment([10, 11, 6, 7, 11, 7])
>>> segment = abjad.PitchClassSegment([-2, -1, 6, 7, -1, 7])
>>> abjad.show(segment) 
>>> segment.permute([10, 0, 2, 6, 8, 7, 5, 3, 1, 9, 4, 11])
PitchClassSegment([4, 11, 5, 3, 11, 3])
>>> segment = segment.permute([10, 0, 2, 6, 8, 7, 5, 3, 1, 9, 4, 11])
>>> abjad.show(segment) 
>>> expression = abjad.Expression(name='J')
>>> expression = expression.pitch_class_segment()
>>> row = [10, 0, 2, 6, 8, 7, 5, 3, 1, 9, 4, 11]
>>> expression = expression.permute(row)
>>> expression([-2, -1, 6, 7, -1, 7])
PitchClassSegment([4, 11, 5, 3, 11, 3])
>>> expression.get_string()
'permute(J, row=[10, 0, 2, 6, 8, 7, 5, 3, 1, 9, 4, 11])'
>>> segment = expression([-2, -1, 6, 7, -1, 7])
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 

Returns new segment.

retrograde()

Gets retrograde of segment.

Example segment:

>>> items = [-2, -1.5, 6, 7, -1.5, 7]
>>> J = abjad.PitchClassSegment(items=items)
>>> J
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7])
>>> abjad.show(J) 

Gets retrograde of segment:

>>> segment = J.retrograde()
>>> segment
PitchClassSegment([7, 10.5, 7, 6, 10.5, 10])
>>> abjad.show(segment) 
>>> expression = abjad.Expression(name='J')
>>> expression = expression.pitch_class_segment()
>>> expression = expression.retrograde()
>>> expression([-2, -1.5, 6, 7, -1.5, 7])
PitchClassSegment([7, 10.5, 7, 6, 10.5, 10])
>>> expression.get_string()
'R(J)'
>>> segment = expression([-2, -1.5, 6, 7, -1.5, 7])
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 

Gets retrograde of retrograde of segment:

>>> segment = J.retrograde().retrograde()
>>> segment
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7])
>>> abjad.show(segment) 
>>> segment == J
True
>>> expression = abjad.Expression(name='J')
>>> expression = expression.pitch_class_segment()
>>> expression = expression.retrograde()
>>> expression = expression.retrograde()
>>> expression([-2, -1.5, 6, 7, -1.5, 7])
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7])
>>> expression.get_string()
'R(R(J))'
>>> segment = expression([-2, -1.5, 6, 7, -1.5, 7])
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 
>>> segment == J
True

Returns pitch-class segment:

>>> isinstance(segment, abjad.PitchClassSegment)
True
rotate(n=0, stravinsky=False)

Rotates segment by index n.

Example segment:

>>> items = [-2, -1.5, 6, 7, -1.5, 7]
>>> J = abjad.PitchClassSegment(items=items)
>>> J
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7])
>>> abjad.show(J) 

Rotates segment to the right:

>>> J.rotate(n=1)
PitchClassSegment([7, 10, 10.5, 6, 7, 10.5])
>>> segment = J.rotate(n=1)
>>> abjad.show(segment) 
>>> expression = abjad.Expression(name='J')
>>> expression = expression.pitch_class_segment()
>>> expression = expression.rotate(n=1)
>>> expression([-2, -1.5, 6, 7, -1.5, 7])
PitchClassSegment([7, 10, 10.5, 6, 7, 10.5])
>>> expression.get_string()
'r1(J)'
>>> segment = expression([-2, -1.5, 6, 7, -1.5, 7])
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 

Rotates segment to the left:

>>> J.rotate(n=-1)
PitchClassSegment([10.5, 6, 7, 10.5, 7, 10])
>>> segment = J.rotate(n=-1)
>>> abjad.show(segment) 
>>> expression = abjad.Expression(name='J')
>>> expression = expression.pitch_class_segment()
>>> expression = expression.rotate(n=-1)
>>> expression([-2, -1.5, 6, 7, -1.5, 7])
PitchClassSegment([10.5, 6, 7, 10.5, 7, 10])
>>> expression.get_string()
'r-1(J)'
>>> segment = expression([-2, -1.5, 6, 7, -1.5, 7])
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 

Rotates segment by zero:

>>> J.rotate(n=0)
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7])
>>> segment = J.rotate(n=0)
>>> abjad.show(segment) 
>>> segment == J
True
>>> expression = abjad.Expression(name='J')
>>> expression = expression.pitch_class_segment()
>>> expression = expression.rotate(n=0)
>>> expression([-2, -1.5, 6, 7, -1.5, 7])
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7])
>>> expression.get_string()
'r0(J)'
>>> segment = expression([-2, -1.5, 6, 7, -1.5, 7])
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 
>>> segment == J
True

Stravinsky-style rotation back-transposes segment to begin at zero:

>>> J.rotate(n=1, stravinsky=True)
PitchClassSegment([0, 3, 3.5, 11, 0, 3.5])
>>> segment = J.rotate(n=1, stravinsky=True)
>>> abjad.show(segment) 
>>> expression = abjad.Expression(name='J')
>>> expression = expression.pitch_class_segment()
>>> expression = expression.rotate(n=1, stravinsky=True)
>>> expression([-2, -1.5, 6, 7, -1.5, 7])
PitchClassSegment([0, 3, 3.5, 11, 0, 3.5])
>>> expression.get_string()
'rs1(J)'
>>> segment = expression([-2, -1.5, 6, 7, -1.5, 7])
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 

Returns pitch-class segment:

>>> isinstance(segment, abjad.PitchClassSegment)
True
to_pitch_classes()

Changes to pitch-classes.

To numbered pitch-class segment:

>>> items = [-2, -1.5, 6, 7, -1.5, 7]
>>> segment = abjad.PitchClassSegment(items=items)
>>> segment
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7])
>>> abjad.show(segment) 
>>> segment = segment.to_pitch_classes()
>>> segment
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7])
>>> abjad.show(segment) 

To named pitch-class segment:

>>> items = [-2, -1.5, 6, 7, -1.5, 7]
>>> segment = abjad.PitchClassSegment(
...     items=items,
...     item_class=abjad.NamedPitchClass,
...     )
>>> segment
PitchClassSegment("bf bqf fs g bqf g")
>>> abjad.show(segment) 
>>> segment = segment.to_pitch_classes()
>>> segment
PitchClassSegment("bf bqf fs g bqf g")
>>> abjad.show(segment) 

Returns new segment.

to_pitches()

Changes to pitches.

To numbered pitch segment:

>>> items = [-2, -1.5, 6, 7, -1.5, 7]
>>> segment = abjad.PitchClassSegment(items=items)
>>> segment
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7])
>>> abjad.show(segment) 
>>> segment = segment.to_pitches()
>>> segment
PitchSegment([10, 10.5, 6, 7, 10.5, 7])
>>> abjad.show(segment) 

To named pitch segment:

>>> items = [-2, -1.5, 6, 7, -1.5, 7]
>>> segment = abjad.PitchClassSegment(
...     items=items,
...     item_class=abjad.NamedPitchClass,
...     )
>>> segment
PitchClassSegment("bf bqf fs g bqf g")
>>> abjad.show(segment) 
>>> segment = segment.to_pitches()
>>> segment
PitchSegment("bf' bqf' fs' g' bqf' g'")
>>> abjad.show(segment) 

Returns new segment.

transpose(n=0)

Transposes segment by index n.

Example segment:

>>> items = [-2, -1.5, 6, 7, -1.5, 7]
>>> J = abjad.PitchClassSegment(items=items)
>>> J
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7])
>>> abjad.show(J) 

Transposes segment by positive index:

>>> J.transpose(n=13)
PitchClassSegment([11, 11.5, 7, 8, 11.5, 8])
>>> segment = J.transpose(n=13)
>>> abjad.show(segment) 
>>> expression = abjad.Expression(name='J')
>>> expression = expression.pitch_class_segment()
>>> expression = expression.transpose(n=13)
>>> expression([-2, -1.5, 6, 7, -1.5, 7])
PitchClassSegment([11, 11.5, 7, 8, 11.5, 8])
>>> expression.get_string()
'T13(J)'
>>> segment = expression([-2, -1.5, 6, 7, -1.5, 7])
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 

Transposes segment by negative index:

>>> J.transpose(n=-13)
PitchClassSegment([9, 9.5, 5, 6, 9.5, 6])
>>> segment = J.transpose(n=-13)
>>> abjad.show(segment) 
>>> expression = abjad.Expression(name='J')
>>> expression = expression.pitch_class_segment()
>>> expression = expression.transpose(n=-13)
>>> expression([-2, -1.5, 6, 7, -1.5, 7])
PitchClassSegment([9, 9.5, 5, 6, 9.5, 6])
>>> expression.get_string()
'T-13(J)'
>>> segment = expression([-2, -1.5, 6, 7, -1.5, 7])
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 

Transposes segment by zero index:

>>> J.transpose(n=0)
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7])
>>> segment = J.transpose(n=0)
>>> abjad.show(segment) 
>>> segment == J
True
>>> expression = abjad.Expression(name='J')
>>> expression = expression.pitch_class_segment()
>>> expression = expression.transpose(n=0)
>>> expression([-2, -1.5, 6, 7, -1.5, 7])
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7])
>>> expression.get_string()
'T0(J)'
>>> segment = expression([-2, -1.5, 6, 7, -1.5, 7])
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 
>>> segment == J
True

Returns pitch-class segment:

>>> isinstance(segment, abjad.PitchClassSegment)
True
voice_horizontally(initial_octave=4)

Voices segment with each pitch as close to the previous pitch as possible.

Todo

Should be implemented somewhere else.

Voices horizontally:

>>> items = "c b d e f g e b a c"
>>> segment = abjad.PitchClassSegment(items=items)
>>> abjad.show(segment) 
>>> voiced_segment = segment.voice_horizontally()
>>> abjad.show(voiced_segment) 

Returns pitch segment:

>>> voiced_segment
PitchSegment("c' b d' e' f' g' e' b a c'")
voice_vertically(initial_octave=4)

Voices segment with each pitch higher than the previous.

Todo

Should be implemented somewhere else.

Voices vertically:

>>> string = "c' ef' g' bf' d'' f'' af''"
>>> segment = abjad.PitchClassSegment(string)
>>> abjad.show(segment) 
>>> voiced_segment = segment.voice_vertically()
>>> abjad.show(voiced_segment) 

Returns pitch segment:

>>> voiced_segment
PitchSegment("c' ef' g' bf' d'' f'' af''")

Class & static methods

classmethod from_selection(selection, item_class=None)

Initializes segment from selection.

Initializes from selection:

>>> staff_1 = abjad.Staff("c'4 <d' fs' a'>4 b2")
>>> staff_2 = abjad.Staff("c4. r8 g2")
>>> staff_group = abjad.StaffGroup([staff_1, staff_2])
>>> abjad.show(staff_group) 
>>> selection = abjad.select((staff_1, staff_2))
>>> segment = abjad.PitchClassSegment.from_selection(selection)
>>> abjad.show(segment) 

Returns pitch-class segment:

>>> segment
PitchClassSegment("c d fs a b c g")

Read-only properties

item_class

Gets item class of segment.

Gets item class of numbered segment:

>>> items = [-2, -1.5, 6, 7, -1.5, 7]
>>> segment = abjad.PitchClassSegment(items=items)
>>> abjad.show(segment) 
>>> segment.item_class
<class 'abjad.pitch.NumberedPitchClass.NumberedPitchClass'>

Gets item class of named segment:

>>> items = ['c', 'ef', 'bqs,', 'd']
>>> segment = abjad.PitchClassSegment(
...     items=items,
...     item_class=abjad.NamedPitchClass,
...     )
>>> abjad.show(segment) 
>>> segment.item_class
<class 'abjad.pitch.NamedPitchClass.NamedPitchClass'>

Returns class:

>>> type(segment.item_class)
<class 'abc.ABCMeta'>
items

Gets items in segment.

Initializes items positionally:

>>> items = [-2, -1.5, 6, 7, -1.5, 7]
>>> segment = abjad.PitchClassSegment(items)
>>> for item in segment.items:
...     item
... 
NumberedPitchClass(10)
NumberedPitchClass(10.5)
NumberedPitchClass(6)
NumberedPitchClass(7)
NumberedPitchClass(10.5)
NumberedPitchClass(7)

Initializes items from keyword:

>>> items = [-2, -1.5, 6, 7, -1.5, 7]
>>> segment = abjad.PitchClassSegment(items=items)
>>> for item in segment.items:
...     item
... 
NumberedPitchClass(10)
NumberedPitchClass(10.5)
NumberedPitchClass(6)
NumberedPitchClass(7)
NumberedPitchClass(10.5)
NumberedPitchClass(7)

Initializes items positionally:

>>> expression = abjad.Expression()
>>> expression = expression.pitch_class_segment()
>>> items = [-2, -1.5, 6, 7, -1.5, 7]
>>> segment = expression(items)
>>> for item in segment.items:
...     item
... 
NumberedPitchClass(10)
NumberedPitchClass(10.5)
NumberedPitchClass(6)
NumberedPitchClass(7)
NumberedPitchClass(10.5)
NumberedPitchClass(7)

Initializes items from keyword:

>>> expression = abjad.Expression()
>>> expression = expression.pitch_class_segment()
>>> items = [-2, -1.5, 6, 7, -1.5, 7]
>>> segment = expression(items=items)
>>> for item in segment.items:
...     item
... 
NumberedPitchClass(10)
NumberedPitchClass(10.5)
NumberedPitchClass(6)
NumberedPitchClass(7)
NumberedPitchClass(10.5)
NumberedPitchClass(7)

Returns list:

>>> isinstance(segment.items, list)
True