PitchVector

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

Pitch vector.

>>> vector = pitchtools.PitchVector(
...     items=[7, 6, -2, -3, -3, 0, 1, 14, 15, 16, 16],
...     item_class=pitchtools.NumberedPitch,
...     )
>>> items = list(vector.items())
>>> items.sort(key=lambda x: x[0].pitch_number)
>>> for pitch_class, count in items:
...     print(pitch_class, count)
-3 2
-2 1
0 1
1 1
6 1
7 1
14 1
15 1
16 2

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.TypedCounter.TypedCounter" [color=3, group=2, label=TypedCounter, shape=box]; "abjad.tools.datastructuretools.TypedCollection.TypedCollection" -> "abjad.tools.datastructuretools.TypedCounter.TypedCounter"; } subgraph cluster_pitchtools { graph [label=pitchtools]; "abjad.tools.pitchtools.PitchVector.PitchVector" [color=black, fontcolor=white, group=3, label=<<B>PitchVector</B>>, shape=box, style="filled, rounded"]; "abjad.tools.pitchtools.Vector.Vector" [color=4, group=3, label=Vector, shape=oval, style=bold]; "abjad.tools.pitchtools.Vector.Vector" -> "abjad.tools.pitchtools.PitchVector.PitchVector"; } 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.TypedCounter.TypedCounter" -> "abjad.tools.pitchtools.Vector.Vector"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Attribute summary

clear() Clears typed counter.
copy() Copies typed counter.
elements() Elements in typed counter.
from_selection(class_, selection[, item_class]) Makes pitch vector from selection.
item_class Gets item class of collection.
items() Items in typed counter.
keys() Iterates keys in typed counter.
most_common([n]) Please document.
subtract([iterable]) Stracts iterable from typed counter.
update([iterable]) Updates typed counter with iterable.
values() Iterates values in typed counter.
viewitems() Please document.
viewkeys() Please document.
viewvalues() Please document.
__add__(argument) Adds typed counter to argument.
__and__(argument) Logical AND of typed counter and argument.
__contains__(item) Is true when typed collection contains item.
__delitem__(item) Deletes item from typed counter.
__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 collection.
__iter__() Iterates typed collection.
__len__() Gets length of typed collection.
__missing__(item) Returns zero.
__ne__(argument) Is true when argument is not a typed collection with items equal to this typed collection.
__or__(argument) Logical OR of typed counter and argument.
__repr__() Gets interpreter representation of pitch vector.
__setitem__(item, value) Sets typed counter item to value.
__str__() String representation of vector.
__sub__(argument) Subtracts argument from typed counter.

Read-only properties

(TypedCollection).item_class

Gets item class of collection.

Collection coerces items according to item_class.

Returns class.

Methods

(TypedCounter).clear()

Clears typed counter.

Returns none.

(TypedCounter).copy()

Copies typed counter.

Returns new typed counter.

(TypedCounter).elements()

Elements in typed counter.

(TypedCounter).items()

Items in typed counter.

Returns tuple.

(TypedCounter).keys()

Iterates keys in typed counter.

(TypedCounter).most_common(n=None)

Please document.

(TypedCounter).subtract(iterable=None, **keywords)

Stracts iterable from typed counter.

(TypedCounter).update(iterable=None, **keywords)

Updates typed counter with iterable.

(TypedCounter).values()

Iterates values in typed counter.

(TypedCounter).viewitems()

Please document.

(TypedCounter).viewkeys()

Please document.

(TypedCounter).viewvalues()

Please document.

Class & static methods

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

Makes pitch vector from selection.

Returns pitch vector.

Special methods

(TypedCounter).__add__(argument)

Adds typed counter to argument.

Returns new typed counter.

(TypedCounter).__and__(argument)

Logical AND of typed counter and argument.

Returns new typed counter.

(TypedCollection).__contains__(item)

Is true when typed collection contains item. Otherwise false.

Returns true or false.

(TypedCounter).__delitem__(item)

Deletes item from typed counter.

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.

(TypedCounter).__getitem__(argument)

Gets item or slice identified by argument.

Returns item or slice.

(TypedCollection).__hash__()

Hashes typed collection.

Required to be explicitly redefined on Python 3 if __eq__ changes.

Returns integer.

(TypedCollection).__iter__()

Iterates typed collection.

Returns generator.

(TypedCollection).__len__()

Gets length of typed collection.

Returns nonnegative integer.

(TypedCounter).__missing__(item)

Returns zero.

Returns zero.

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

(TypedCounter).__or__(argument)

Logical OR of typed counter and argument.

Returns new typed counter.

PitchVector.__repr__()

Gets interpreter representation of pitch vector.

Gets interpreter representation of pitch vector:

>>> vector = pitchtools.PitchVector(
...     items=[7, 6, -2, -3, -3, 0, 1, 14, 15, 16, 16],
...     item_class=pitchtools.NumberedPitch,
...     )
>>> vector
PitchVector({-3: 2, -2: 1, 0: 1, 1: 1, 6: 1, 7: 1, 14: 1, 15: 1, 16: 2}, item_class=NumberedPitch)

Initializes from interpreter representation of pitch vector:

>>> pitchtools.PitchVector(vector)
PitchVector({-3: 2, -2: 1, 0: 1, 1: 1, 6: 1, 7: 1, 14: 1, 15: 1, 16: 2}, item_class=NumberedPitch)

Returns string.

(TypedCounter).__setitem__(item, value)

Sets typed counter item to value.

Returns none.

(Vector).__str__()

String representation of vector.

Returns string.

(TypedCounter).__sub__(argument)

Subtracts argument from typed counter.

Returns new typed counter.