PitchSegment

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

Pitch segment.

Example 1. Numbered pitch segment:

>>> numbered_pitch_segment = pitchtools.PitchSegment(
...     items=[-2, -1.5, 6, 7, -1.5, 7],
...     item_class=pitchtools.NumberedPitch,
...     )
>>> numbered_pitch_segment
PitchSegment([-2, -1.5, 6, 7, -1.5, 7])
>>> show(numbered_pitch_segment) 

Example 2. Named pitch segment:

>>> named_pitch_segment = pitchtools.PitchSegment(
...     ['bf,', 'aqs', "fs'", "g'", 'bqf', "g'"],
...     item_class=NamedPitch,
...     )
>>> named_pitch_segment
PitchSegment(['bf,', 'aqs', "fs'", "g'", 'bqf', "g'"])
>>> show(named_pitch_segment) 

Pitch segments are immutable.

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) Changes item to item.
from_selection(class_, selection[, item_class]) Makes pitch segment from selection.
has_duplicates True if pitch segment has duplicate items.
hertz Gets hertz of pitches in pitch segment.
index(item) Changes item to item.
inflection_point_count Inflection point count of pitch segment.
invert([axis]) Inverts pitch segment about axis.
is_equivalent_under_transposition(expr) True if pitch segment is equivalent to expr under transposition.
item_class Item class to coerce items into.
items Gets collection items.
local_maxima Local maxima of pitch segment.
local_minima Local minima of pitch segment.
make_notes([n, written_duration]) Makes first n notes in pitch segment.
multiply(index) Multiplies pitch segment.
retrograde() Retrograde of pitch segment.
rotate(n[, transpose]) Rotates pitch segment.
transpose(expr) Transposes pitch segment by expr.
__add__(expr) Adds typed tuple to expr.
__contains__(item) Change item to item and return true if item exists in collection.
__eq__(expr) Is true when expr is a typed collection with items that compare equal to those of this typed collection.
__format__([format_specification]) Formats Abjad object.
__getitem__(i) Gets i from type tuple.
__getslice__(start, stop) Gets slice from start to stop in typed tuple.
__hash__() Hashes typed tuple.
__illustrate__() Illustrates pitch segment.
__iter__() Iterates typed collection.
__len__() Length of typed collection.
__mul__(expr) Multiplies typed tuple by expr.
__ne__(expr) Is true when expr is not a typed collection with items equal to this typed collection.
__radd__(expr) Right-adds expr to typed tuple.
__repr__() Gets interpreter representation of Abjad object.
__rmul__(expr) Multiplies expr by typed tuple.
__str__() Gets string representation of segment.

Read-only properties

PitchSegment.has_duplicates

True if pitch segment has duplicate items. Otherwise false.

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

Returns true or false.

PitchSegment.hertz

Gets hertz of pitches in pitch segment.

>>> pitch_segment = pitchtools.PitchSegment('c e g b')
>>> pitch_segment.hertz
(130.8127826502993, 164.81377845643496, 195.99771799087463, 246.94165062806206)

Returns tuple.

PitchSegment.inflection_point_count

Inflection point count of pitch segment.

Returns nonnegative integer.

(TypedCollection).item_class

Item class to coerce items into.

(TypedCollection).items

Gets collection items.

PitchSegment.local_maxima

Local maxima of pitch segment.

Returns tuple.

PitchSegment.local_minima

Local minima of pitch segment.

Returns tuple.

Methods

(TypedTuple).count(item)

Changes item to item.

Returns count in collection.

(TypedTuple).index(item)

Changes item to item.

Returns index in collection.

PitchSegment.invert(axis=None)

Inverts pitch segment about axis.

Returns new pitch segment.

PitchSegment.is_equivalent_under_transposition(expr)

True if pitch segment is equivalent to expr under transposition. Otherwise false.

Returns true or false.

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

Makes first n notes in pitch segment.

Set n equal to n or length of segment.

Set written_duration equal to written_duration or 1/8:

>>> notes = named_pitch_segment.make_notes()
>>> staff = Staff(notes)
>>> show(staff) 

Allows nonassignable written_duration:

>>> notes = named_pitch_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(index)

Multiplies pitch segment.

>>> result = named_pitch_segment.multiply(3)
>>> result
PitchSegment(['fs,', 'eqs', "fs'", "a'", 'gqs', "a'"])
>>> show(result) 

Returns new pitch segment.

PitchSegment.retrograde()

Retrograde of pitch segment.

>>> result = named_pitch_segment.retrograde()
>>> result
PitchSegment(["g'", 'bqf', "g'", "fs'", 'aqs', 'bf,'])
>>> show(result) 

Returns new pitch segment.

PitchSegment.rotate(n, transpose=False)

Rotates pitch segment.

>>> result = numbered_pitch_segment.rotate(1)
>>> result
PitchSegment([7, -2, -1.5, 6, 7, -1.5])
>>> show(result) 
>>> result = named_pitch_segment.rotate(-2)
>>> result
PitchSegment(["fs'", "g'", 'bqf', "g'", 'bf,', 'aqs'])
>>> show(result) 
>>> pitch_segment = pitchtools.PitchSegment("c' d' e' f'")
>>> result = pitch_segment.rotate(-1, transpose=True)
>>> result
PitchSegment(["c'", "d'", "ef'", 'bf'])
>>> show(result) 

Returns new pitch segment.

PitchSegment.transpose(expr)

Transposes pitch segment by expr.

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))
>>> pitch_segment = pitchtools.PitchSegment.from_selection(
...     selection)
>>> pitch_segment
PitchSegment(["c'", "d'", "fs'", "a'", 'b', 'c', 'g'])
>>> show(pitch_segment) 

Returns pitch segment.

Special methods

(TypedTuple).__add__(expr)

Adds typed tuple to expr.

Returns new typed tuple.

(TypedTuple).__contains__(item)

Change item to item and return true if item exists in collection.

Returns none.

(TypedCollection).__eq__(expr)

Is true when expr 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__(i)

Gets i from type tuple.

Returns item.

(TypedTuple).__getslice__(start, stop)

Gets slice from start to stop in typed tuple.

Returns new typed tuple.

(TypedTuple).__hash__()

Hashes typed tuple.

Returns integer.

PitchSegment.__illustrate__()

Illustrates pitch segment.

>>> named_pitch_segment = pitchtools.PitchSegment(
...     ['bf,', 'aqs', "fs'", "g'", 'bqf', "g'"],
...     item_class=NamedPitch,
...     )
>>> show(named_pitch_segment) 

Returns LilyPond file.

(TypedCollection).__iter__()

Iterates typed collection.

Returns generator.

(TypedCollection).__len__()

Length of typed collection.

Returns nonnegative integer.

(TypedTuple).__mul__(expr)

Multiplies typed tuple by expr.

Returns new typed tuple.

(TypedCollection).__ne__(expr)

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

Returns true or false.

(TypedTuple).__radd__(expr)

Right-adds expr to typed tuple.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.

(TypedTuple).__rmul__(expr)

Multiplies expr by typed tuple.

Returns new typed tuple.

(Segment).__str__()

Gets string representation of segment.

Returns string.