PitchSegment

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

Pitch segment.

Numbered pitch segment:

>>> segment = PitchSegment([-2, -1.5, 6, 7, -1.5, 7])
>>> str(segment)
'<-2, -1.5, 6, 7, -1.5, 7>'
>>> show(segment) 

Named pitch segment:

>>> segment = PitchSegment("bf, aqs fs' g' bqf g'")
>>> str(segment)
"<bf, aqs fs' g' bqf g'>"
>>> 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.PitchSegment.PitchSegment" [color=black, fontcolor=white, group=3, label=<<B>PitchSegment</B>>, shape=box, style="filled, rounded"]; "abjad.tools.pitchtools.Segment.Segment" [color=4, group=3, label=Segment, shape=oval, style=bold]; "abjad.tools.pitchtools.Segment.Segment" -> "abjad.tools.pitchtools.PitchSegment.PitchSegment"; } 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"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Attribute summary

count(item) Counts item in collection.
from_selection(class_, selection[, item_class]) Makes pitch segment from selection.
has_duplicates() Is true when segment has duplicates.
hertz Gets Hertz of pitches in segment.
index(item) Gets index of item in collection.
inflection_point_count Gets segment inflection point count.
invert([axis]) Inverts pitch segment about axis.
item_class Gets item class of collection.
items Gets items in collection.
local_maxima Gets segment local maxima.
local_minima Gets segment local minima.
make_notes([n, written_duration]) Makes first n notes in pitch segment.
multiply([n]) Multiplies pitch segment by index n.
retrograde() Retrograde of pitch segment.
rotate([n, stravinsky]) Rotates pitch segment by index n.
to_pitch_classes() Changes to pitch-classes.
to_pitches() Changes to pitches.
transpose([n]) Transposes pitch segment by index n.
__add__(argument) Adds typed tuple to argument.
__contains__(item) Is true if typed tuple contains item.
__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 Abjad object.
__getitem__(argument) Gets item or slice identified by argument.
__hash__() Hashes typed tuple.
__illustrate__() Illustrates pitch segment.
__iter__() Iterates typed collection.
__len__() Gets length of typed collection.
__mul__(argument) Multiplies typed tuple by argument.
__ne__(argument) Is true when argument is not a typed collection with items equal to this typed collection.
__radd__(argument) Right-adds argument to typed tuple.
__repr__() Gets interpreter representation of segment.
__rmul__(argument) Multiplies argument by typed tuple.
__str__() Gets pitch segment string.

Read-only properties

PitchSegment.hertz

Gets Hertz of pitches in segment.

>>> segment = PitchSegment('c e g b')
>>> segment.hertz
[130.8127826502993, 164.81377845643496, 195.99771799087463, 246.94165062806206]

Returns list.

PitchSegment.inflection_point_count

Gets segment inflection point count.

>>> segment = PitchSegment([-2, -1.5, 6, 7, -1.5, 7])
>>> show(segment) 
>>> segment.inflection_point_count
2

Returns nonnegative integer.

(TypedCollection).item_class

Gets item class of collection.

Collection coerces items according to item_class.

Returns class.

(TypedCollection).items

Gets items in collection.

Returns list.

PitchSegment.local_maxima

Gets segment local maxima.

>>> segment = PitchSegment([-2, -1.5, 6, 7, -1.5, 7])
>>> show(segment) 
>>> segment.local_maxima
[NumberedPitch(7)]

Returns list.

PitchSegment.local_minima

Gets segment local minima.

>>> segment = PitchSegment([-2, -1.5, 6, 7, -1.5, 7])
>>> show(segment) 
>>> segment.local_minima
[NumberedPitch(-1.5)]

Returns list.

Methods

(TypedTuple).count(item)

Counts item in collection.

Coerces item.

Returns nonnegative integer.

PitchSegment.has_duplicates()

Is true when segment has duplicates. Otherwise false.

>>> segment = PitchSegment([-2, -1.5, 6, 7, -1.5, 7])
>>> segment.has_duplicates()
True
>>> segment = PitchSegment("c d e f g a b")
>>> segment.has_duplicates()
False

Returns true or false.

(TypedTuple).index(item)

Gets index of item in collection.

Coerces item.

Returns nonnegative integer.

PitchSegment.invert(axis=None)

Inverts pitch segment about axis.

>>> segment = PitchSegment([-2, -1.5, 6, 7, -1.5, 7])
>>> show(segment) 
>>> segment = segment.invert(axis=0)
>>> str(segment)
'<2, 1.5, -6, -7, 1.5, -7>'
>>> show(segment) 

Returns new pitch segment.

PitchSegment.make_notes(n=None, written_duration=None)

Makes first n notes in pitch segment.

Todo

Move somewhere else.

Sets n equal to n or length of segment.

Sets written_duration equal to written_duration or 1/8:

>>> segment = PitchSegment([-2, -1.5, 6, 7, -1.5, 7])
>>> notes = segment.make_notes()
>>> staff = Staff(notes)
>>> show(staff) 

Allows nonassignable written_duration:

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

Returns list of notes.

PitchSegment.multiply(n=1)

Multiplies pitch segment by index n.

>>> segment = PitchSegment([-2, -1.5, 6, 7, -1.5, 7])
>>> show(segment) 
>>> segment = segment.multiply(n=3)
>>> str(segment)
'<-6, -4.5, 18, 21, -4.5, 21>'
>>> show(segment) 

Returns new pitch segment.

PitchSegment.retrograde()

Retrograde of pitch segment.

>>> segment = PitchSegment([-2, -1.5, 6, 7, -1.5, 7])
>>> show(segment) 
>>> segment = segment.retrograde()
>>> str(segment)
'<7, -1.5, 7, 6, -1.5, -2>'
>>> show(segment) 

Returns new pitch segment.

PitchSegment.rotate(n=0, stravinsky=False)

Rotates pitch segment by index n.

>>> segment = PitchSegment([-2, -1.5, 6, 7, -1.5, 7])
>>> show(segment) 
>>> segment = segment.rotate(n=1)
>>> str(segment)
'<7, -2, -1.5, 6, 7, -1.5>'
>>> show(segment) 

Returns new pitch segment.

PitchSegment.to_pitch_classes()

Changes to pitch-classes.

To numbered pitch-class segment:

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

To named pitch-class segment:

>>> segment = PitchSegment("bf, aqs fs' g' bqf g'")
>>> show(segment) 
>>> segment = segment.to_pitch_classes()
>>> str(segment)
'PC<bf aqs fs g bqf g>'
>>> show(segment) 

Returns new segment.

PitchSegment.to_pitches()

Changes to pitches.

To numbered pitch segment:

>>> segment = PitchSegment([-2, -1.5, 6, 7, -1.5, 7])
>>> show(segment) 
>>> segment = segment.to_pitches()
>>> str(segment)
'<-2, -1.5, 6, 7, -1.5, 7>'
>>> show(segment) 

To named pitch segment:

>>> segment = PitchSegment("bf, aqs fs' g' bqf g'")
>>> show(segment) 
>>> segment = segment.to_pitches()
>>> str(segment)
"<bf, aqs fs' g' bqf g'>"
>>> show(segment) 

Returns new segment.

PitchSegment.transpose(n=0)

Transposes pitch segment by index n.

>>> segment = PitchSegment([-2, -1.5, 6, 7, -1.5, 7])
>>> show(segment) 
>>> segment = segment.transpose(n=11)
>>> str(segment)
'<9, 9.5, 17, 18, 9.5, 18>'
>>> show(segment) 

Returns new pitch segment.

Class & static methods

classmethod PitchSegment.from_selection(class_, selection, item_class=None)

Makes pitch segment from selection.

>>> staff_1 = Staff("c'4 <d' fs' a'>4 b2")
>>> staff_2 = Staff("c4. r8 g2")
>>> selection = select((staff_1, staff_2))
>>> segment = PitchSegment.from_selection(selection)
>>> str(segment)
"<c' d' fs' a' b c g>"
>>> show(segment) 

Returns pitch segment.

Special methods

(TypedTuple).__add__(argument)

Adds typed tuple to argument.

Returns new typed tuple.

(TypedTuple).__contains__(item)

Is true if typed tuple contains item.

Coerces item.

Returns none.

(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.

(AbjadObject).__format__(format_specification='')

Formats Abjad object.

Set format_specification to ‘’ or ‘storage’. Interprets ‘’ equal to ‘storage’.

Returns string.

(TypedTuple).__getitem__(argument)

Gets item or slice identified by argument.

Returns item or new typed tuple.

(TypedTuple).__hash__()

Hashes typed tuple.

Returns integer.

PitchSegment.__illustrate__()

Illustrates pitch segment.

>>> segment = PitchSegment("bf, aqs fs' g' bqf g'")
>>> show(segment) 

Returns LilyPond file.

(TypedCollection).__iter__()

Iterates typed collection.

Returns generator.

(TypedCollection).__len__()

Gets length of typed collection.

Returns nonnegative integer.

(TypedTuple).__mul__(argument)

Multiplies typed tuple by argument.

Returns new typed tuple.

(TypedCollection).__ne__(argument)

Is true when argument is not a typed collection with items equal to this typed collection. Otherwise false.

Returns true or false.

(TypedTuple).__radd__(argument)

Right-adds argument to typed tuple.

PitchSegment.__repr__()

Gets interpreter representation of segment.

Returns string.

(TypedTuple).__rmul__(argument)

Multiplies argument by typed tuple.

Returns new typed tuple.

PitchSegment.__str__()

Gets pitch segment string.

>>> segment = PitchSegment([-2, -1.5, 6, 7, -1.5, 7])
>>> str(segment)
'<-2, -1.5, 6, 7, -1.5, 7>'
>>> segment = PitchSegment("bf, aqs fs' g' bqf g'")
>>> str(segment)
"<bf, aqs fs' g' bqf g'>"

Returns string.