PitchClassSegment

class pitchtools.PitchClassSegment(items=None, item_class=None)

Pitch-class segment.

>>> import abjad

Initializes segment with numbered pitch-classes:

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

Initializes segment with named pitch-classes:

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

Lineage

digraph InheritanceGraph { graph [background=transparent, bgcolor=transparent, color=lightslategrey, fontname=Arial, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, root="__builtin__.object", splines=spline, style="dotted, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=12, penwidth=2, style="filled, rounded"]; edge [color=lightsteelblue2, penwidth=2]; subgraph cluster_abctools { graph [label=abctools]; "abjad.tools.abctools.AbjadObject.AbjadObject" [color=1, group=0, label=AbjadObject, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" [color=1, group=0, label=AbstractBase, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" -> "abjad.tools.abctools.AbjadObject.AbjadObject"; } subgraph cluster_datastructuretools { graph [label=datastructuretools]; "abjad.tools.datastructuretools.TypedCollection.TypedCollection" [color=3, group=2, label=TypedCollection, shape=oval, style=bold]; "abjad.tools.datastructuretools.TypedTuple.TypedTuple" [color=3, group=2, label=TypedTuple, shape=box]; "abjad.tools.datastructuretools.TypedCollection.TypedCollection" -> "abjad.tools.datastructuretools.TypedTuple.TypedTuple"; } subgraph cluster_pitchtools { graph [label=pitchtools]; "abjad.tools.pitchtools.PitchClassSegment.PitchClassSegment" [color=black, fontcolor=white, group=3, label=<<B>PitchClassSegment</B>>, shape=box, style="filled, rounded"]; "abjad.tools.pitchtools.Segment.Segment" [color=4, group=3, label=Segment, shape=oval, style=bold]; "abjad.tools.pitchtools.TwelveToneRow.TwelveToneRow" [color=4, group=3, label=TwelveToneRow, shape=box]; "abjad.tools.pitchtools.PitchClassSegment.PitchClassSegment" -> "abjad.tools.pitchtools.TwelveToneRow.TwelveToneRow"; "abjad.tools.pitchtools.Segment.Segment" -> "abjad.tools.pitchtools.PitchClassSegment.PitchClassSegment"; } subgraph cluster_tonalanalysistools { graph [label=tonalanalysistools]; "abjad.tools.tonalanalysistools.Scale.Scale" [color=5, group=4, label=Scale, shape=box]; } subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=2, group=1, label=object, shape=box]; } "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.datastructuretools.TypedCollection.TypedCollection"; "abjad.tools.datastructuretools.TypedTuple.TypedTuple" -> "abjad.tools.pitchtools.Segment.Segment"; "abjad.tools.pitchtools.PitchClassSegment.PitchClassSegment" -> "abjad.tools.tonalanalysistools.Scale.Scale"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Attribute summary

count(item) Counts item in segment.
from_selection(selection[, item_class]) Initializes segment from selection.
has_duplicates() Is true when segment contains duplicate items.
index(item) Gets index of item in segment.
invert([axis]) Inverts segment.
item_class Gets item class of segment.
items Gets items in segment.
make_notes([n, written_duration]) Makes first n notes in segment.
multiply([n]) Multiplies pitch-classes in segment by n.
permute([row]) Permutes segment by twelve-tone row.
retrograde() Gets retrograde of segment.
rotate([n, stravinsky]) Rotates segment by index n.
to_pitch_classes() Changes to pitch-classes.
to_pitches() Changes to pitches.
transpose([n]) Transposes segment by index n.
voice_horizontally([initial_octave]) Voices segment with each pitch as close to the previous pitch as possible.
voice_vertically([initial_octave]) Voices segment with each pitch higher than the previous.
__add__(argument) Adds argument to segment.
__contains__(argument) Is true when pitch-class segment contains argument.
__eq__(argument) Is true when argument is a typed collection with items that compare equal to those of this typed collection.
__format__([format_specification]) Formats segment.
__getitem__(argument) Gets argument from segment.
__hash__() Hashes typed tuple.
__illustrate__([expression_markup_direction]) Illustrates segment.
__iter__() Iterates typed collection.
__len__() Gets length of typed collection.
__mul__(n) Multiplies pitch-class segment by n.
__ne__(argument) Is true when Abjad object does not equal argument.
__radd__(argument) Right-adds argument to typed tuple.
__repr__() Gets interpreter representation.
__rmul__(n) Multiplies n by pitch-class segment.
__str__() Gets string representation of pitch-class segment.

Read-only properties

PitchClassSegment.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)
>>> show(segment) 
>>> segment.item_class
<class 'abjad.tools.pitchtools.NumberedPitchClass.NumberedPitchClass'>

Gets item class of named segment:

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

Returns class:

>>> type(segment.item_class)
<class 'abc.ABCMeta'>
PitchClassSegment.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

Methods

PitchClassSegment.count(item)

Counts item in segment.

Example segment:

>>> items = [-2, -1.5, 6, 7, -1.5, 7]
>>> segment = abjad.PitchClassSegment(items=items)
>>> 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
PitchClassSegment.has_duplicates()

Is true when segment contains duplicate items. Otherwise false.

Has duplicates:

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

Has no duplicates:

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

Returns true or false.

PitchClassSegment.index(item)

Gets index of item in segment.

Example segment:

>>> items = [-2, -1.5, 6, 7, -1.5, 7]
>>> segment = abjad.PitchClassSegment(items=items)
>>> 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
PitchClassSegment.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])
>>> show(J) 

Inverts segment:

>>> J.invert()
PitchClassSegment([2, 1.5, 6, 5, 1.5, 5])
>>> segment = J.invert()
>>> 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()
>>> 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()
>>> 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()
>>> show(segment, figure_name=markup) 

Returns pitch-class segment:

>>> isinstance(segment, abjad.PitchClassSegment)
True
PitchClassSegment.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)
>>> show(segment) 

Makes eighth notes:

>>> notes = segment.make_notes()
>>> staff = abjad.Staff(notes)
>>> 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])
>>> 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
PitchClassSegment.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])
>>> 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)
>>> 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()
>>> 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)
>>> 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()
>>> 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)
>>> 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()
>>> 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])
>>> 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()
>>> show(segment, figure_name=markup) 

Returns pitch-class segment:

>>> isinstance(segment, abjad.PitchClassSegment)
True
PitchClassSegment.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])
>>> 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])
>>> 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()
>>> show(segment, figure_name=markup) 

Returns new segment.

PitchClassSegment.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])
>>> show(J) 

Gets retrograde of segment:

>>> segment = J.retrograde()
>>> segment
PitchClassSegment([7, 10.5, 7, 6, 10.5, 10])
>>> 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()
>>> 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])
>>> 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()
>>> show(segment, figure_name=markup) 
>>> segment == J
True

Returns pitch-class segment:

>>> isinstance(segment, abjad.PitchClassSegment)
True
PitchClassSegment.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])
>>> 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)
>>> 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()
>>> 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)
>>> 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()
>>> 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)
>>> 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()
>>> 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)
>>> 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()
>>> show(segment, figure_name=markup) 

Returns pitch-class segment:

>>> isinstance(segment, abjad.PitchClassSegment)
True
PitchClassSegment.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])
>>> show(segment) 
>>> segment = segment.to_pitch_classes()
>>> segment
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7])
>>> 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")
>>> show(segment) 
>>> segment = segment.to_pitch_classes()
>>> segment
PitchClassSegment("bf bqf fs g bqf g")
>>> show(segment) 

Returns new segment.

PitchClassSegment.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])
>>> show(segment) 
>>> segment = segment.to_pitches()
>>> segment
PitchSegment([10, 10.5, 6, 7, 10.5, 7])
>>> 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")
>>> show(segment) 
>>> segment = segment.to_pitches()
>>> segment
PitchSegment("bf' bqf' fs' g' bqf' g'")
>>> show(segment) 

Returns new segment.

PitchClassSegment.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])
>>> 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)
>>> 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()
>>> 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)
>>> 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()
>>> 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)
>>> 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()
>>> show(segment, figure_name=markup) 
>>> segment == J
True

Returns pitch-class segment:

>>> isinstance(segment, abjad.PitchClassSegment)
True
PitchClassSegment.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)
>>> show(segment) 
>>> voiced_segment = segment.voice_horizontally()
>>> show(voiced_segment) 

Returns pitch segment:

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

Voices segment with each pitch higher than the previous.

Todo

Should be implemented somewhere else.

Voices vertically:

>>> scale_degree_numbers = [1, 3, 5, 7, 9, 11, 13]
>>> scale = abjad.tonalanalysistools.Scale(('c', 'minor'))
>>> segment = abjad.PitchClassSegment((
...     scale.scale_degree_to_named_pitch_class(x)
...     for x in scale_degree_numbers))
>>> show(segment) 
>>> voiced_segment = segment.voice_vertically()
>>> show(voiced_segment) 

Returns pitch segment:

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

Class & static methods

classmethod PitchClassSegment.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])
>>> show(staff_group) 
>>> selection = abjad.select((staff_1, staff_2))
>>> segment = abjad.PitchClassSegment.from_selection(selection)
>>> show(segment) 

Returns pitch-class segment:

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

Special methods

PitchClassSegment.__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)
>>> show(J) 
>>> pitch_names = ['c', 'ef', 'bqs,', 'd']
>>> abjad.PitchClassSegment(items=pitch_names)
PitchClassSegment("c ef bqs d")
>>> K = abjad.PitchClassSegment(items=pitch_names)
>>> 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
>>> 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()
>>> 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
>>> 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()
>>> 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
>>> 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()
>>> 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)
>>> 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()
>>> 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()
>>> 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()
>>> 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()
>>> 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()
>>> show(segment, figure_name=markup) 

Returns new segment.

PitchClassSegment.__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. Otherwise false.

Returns true or false.

PitchClassSegment.__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)
>>> 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,
    )
>>> show(J) 

With named pitch-classes:

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

Returns string.

PitchClassSegment.__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)
>>> 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()
>>> 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()
>>> show(markup) 

Gets slice:

>>> J[:4]
PitchClassSegment([10, 10.5, 6, 7])
>>> segment = J[:4]
>>> 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()
>>> show(segment, figure_name=markup) 

Gets retrograde of slice:

>>> J[:4].retrograde()
PitchClassSegment([7, 6, 10.5, 10])
>>> segment = J[:4].retrograde()
>>> 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()
>>> show(segment, figure_name=markup) 

Gets slice of retrograde:

>>> J.retrograde()[:4]
PitchClassSegment([7, 10.5, 7, 6])
>>> segment = J.retrograde()[:4]
>>> 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()
>>> show(segment, figure_name=markup) 

Returns pitch-class or pitch-class segment:

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

Hashes typed tuple.

Returns integer.

PitchClassSegment.__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)
>>> show(segment) 

Illustrates named segment:

>>> items = ['c', 'ef', 'bqs,', 'd']
>>> segment = abjad.PitchClassSegment(
...     items=items,
...     item_class=abjad.NumberedPitchClass,
...     )
>>> 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.

PitchClassSegment.__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.

(AbjadObject).__ne__(argument)

Is true when Abjad object does not equal argument. Otherwise false.

Returns true or false.

(TypedTuple).__radd__(argument)

Right-adds argument to typed tuple.

PitchClassSegment.__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.

PitchClassSegment.__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.

PitchClassSegment.__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.