PitchArray

class pitchtools.PitchArray(rows=None)

Pitch array.

Example 1. A two-by-three pitch array:

>>> pitch_array = pitchtools.PitchArray([[1, 2, 1], [2, 1, 1]])
>>> print(pitch_array)
[ ] [     ] [ ]
[     ] [ ] [ ]
>>> print(format(pitch_array))
pitchtools.PitchArray(
    rows=(
        pitchtools.PitchArrayRow(
            cells=(
                pitchtools.PitchArrayCell(
                    width=1,
                    ),
                pitchtools.PitchArrayCell(
                    width=2,
                    ),
                pitchtools.PitchArrayCell(
                    width=1,
                    ),
                ),
            ),
        pitchtools.PitchArrayRow(
            cells=(
                pitchtools.PitchArrayCell(
                    width=2,
                    ),
                pitchtools.PitchArrayCell(
                    width=1,
                    ),
                pitchtools.PitchArrayCell(
                    width=1,
                    ),
                ),
            ),
        ),
    )

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_pitchtools { graph [label=pitchtools]; "abjad.tools.pitchtools.PitchArray.PitchArray" [color=black, fontcolor=white, group=2, label=<<B>PitchArray</B>>, shape=box, style="filled, rounded"]; } subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=2, group=1, label=object, shape=box]; } "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.pitchtools.PitchArray.PitchArray"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Bases

Attribute summary

append_column(column) Appends column to pitch array.
append_row(row) Appends row to pitch array.
apply_pitches_by_row(pitch_lists) Applies pitch_lists to pitch array by row.
cell_tokens_by_row Gets cells tokens of pitch array by row.
cell_widths_by_row Gets cell widths of pitch array by row.
cells Gets cells of pitch array.
columns Gets columns of pitch array.
copy_subarray(upper_left_pair, lower_right_pair) Copies subarray of pitch array.
depth Gets depth of pitch array.
dimensions Gets dimensions of pitch array.
from_counts(class_, row_count, column_count) Makes pitch array from row and column counts.
from_score(class_, score[, populate]) Makes pitch array from score.
has_spanning_cell_over_index(index) Is true when pitch array has one or more spanning cells over index.
has_voice_crossing Is true when pitch array has voice crossing.
is_rectangular Is true when no rows in pitch array are defective.
list_nonspanning_subarrays() Lists nonspanning subarrays of pitch array.
pad_to_depth(depth) Pads pitch array to depth.
pad_to_width(width) Pads pitch array to width.
pitches Gets pitches in pitch array.
pitches_by_row Gets pitches in pitch array by row.
pop_column(column_index) Pops column column_index from pitch array.
pop_row([row_index]) Pops row row_index from pitch array.
remove_row(row) Removes row from pitch array.
rows Gets rows in pitch array.
size Gets size of pitch array.
to_measures([cell_duration_denominator]) Changes pitch array to measures.
voice_crossing_count Gets voice crossing count of pitch array.
weight Gets weight of pitch array.
width Gets width of pitch array.
__add__(arg) Concatenates arg to pitch array.
__contains__(arg) Is true when pitch array contains arg.
__copy__() Copies pitch array.
__eq__(arg) Is true when arg is a pitch aarray with contents equal to that of this pitch array.
__format__([format_specification]) Formats Abjad object.
__getitem__(arg) Gets row arg from pitch array.
__hash__() Hashes pitch array.
__iadd__(arg) Adds arg to pitch array in place.
__ne__(arg) Is true when pitch array does not equal arg.
__repr__() Gets interpreter representation of Abjad object.
__setitem__(i, arg) Sets pitch array row i to arg.
__str__() String representation of pitch array.

Read-only properties

PitchArray.cell_tokens_by_row

Gets cells tokens of pitch array by row.

Returns tuple.

PitchArray.cell_widths_by_row

Gets cell widths of pitch array by row.

Returns tuple.

PitchArray.cells

Gets cells of pitch array.

Returns set.

PitchArray.columns

Gets columns of pitch array.

Returns tuple.

PitchArray.depth

Gets depth of pitch array.

Defined equal to number of pitch array rows in pitch array.

Returns nonnegative integer.

PitchArray.dimensions

Gets dimensions of pitch array.

Returns pair.

PitchArray.has_voice_crossing

Is true when pitch array has voice crossing. Otherwise false.

Returns true or false.

PitchArray.is_rectangular

Is true when no rows in pitch array are defective. Otherwise false.

Returns true or false.

PitchArray.pitches

Gets pitches in pitch array.

Returns tuple.

PitchArray.pitches_by_row

Gets pitches in pitch array by row.

Returns tuple.

PitchArray.rows

Gets rows in pitch array.

Returns tuple.

PitchArray.size

Gets size of pitch array.

Defined equal to the product of depth and width.

Returns nonnegative integer.

PitchArray.voice_crossing_count

Gets voice crossing count of pitch array.

Returns nonnegative integer.

PitchArray.weight

Gets weight of pitch array.

Defined equal to the sum of the weight of the rows in pitch array.

Returns nonnegative integer.

PitchArray.width

Gets width of pitch array.

Defined equal to the width of the widest row in pitch array.

Returns nonnegative integer.

Methods

PitchArray.append_column(column)

Appends column to pitch array.

Returns none.

PitchArray.append_row(row)

Appends row to pitch array.

Returns none.

PitchArray.apply_pitches_by_row(pitch_lists)

Applies pitch_lists to pitch array by row.

Returns none.

PitchArray.copy_subarray(upper_left_pair, lower_right_pair)

Copies subarray of pitch array.

Returns new pitch array.

PitchArray.has_spanning_cell_over_index(index)

Is true when pitch array has one or more spanning cells over index. Otherwise false.

Returns true or false.

PitchArray.list_nonspanning_subarrays()

Lists nonspanning subarrays of pitch array.

Example 1. Lists three nonspanning subarrays:

>>> array = pitchtools.PitchArray([
...     [2, 2, 3, 1],
...     [1, 2, 1, 1, 2, 1],
...     [1, 1, 1, 1, 1, 1, 1, 1]])
>>> print(array)
[     ] [     ] [     ] [ ]
[ ] [     ] [ ] [ ] [     ] [ ]
[ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ]
>>> subarrays = array.list_nonspanning_subarrays()
>>> len(subarrays)
3
>>> print(subarrays[0])
[     ] [     ]
[ ] [     ] [ ]
[ ] [ ] [ ] [ ]
>>> print(subarrays[1])
[     ]
[ ] [     ]
[ ] [ ] [ ]
>>> print(subarrays[2])
[ ]
[ ]
[ ]

Returns list.

PitchArray.pad_to_depth(depth)

Pads pitch array to depth.

Returns none.

PitchArray.pad_to_width(width)

Pads pitch array to width.

Returns none.

PitchArray.pop_column(column_index)

Pops column column_index from pitch array.

Returns pitch array column.

PitchArray.pop_row(row_index=-1)

Pops row row_index from pitch array.

Returns pitch array row.

PitchArray.remove_row(row)

Removes row from pitch array.

Returns none.

PitchArray.to_measures(cell_duration_denominator=8)

Changes pitch array to measures.

Makes time signatures with numerators equal to row width and denominators equal to cell_duration_denominator for each row in pitch array.

Example 1. Changes two-by-three pitch array to measures:

>>> array = pitchtools.PitchArray([
...     [1, (2, 1), ([-2, -1.5], 2)],
...     [(7, 2), (6, 1), 1],
...     ])
>>> print(array)
[  ] [d'] [bf bqf    ]
[g'     ] [fs'   ] [ ]
>>> measures = array.to_measures()
>>> staff = Staff(measures)
>>> show(staff) 

Returns list of measures.

Class & static methods

classmethod PitchArray.from_counts(class_, row_count, column_count)

Makes pitch array from row and column counts.

Returns pitch array.

classmethod PitchArray.from_score(class_, score, populate=True)

Makes pitch array from score.

Example 1. Makes empty pitch array from score:

>>> score = Score([])
>>> score.append(Staff("c'8 d'8 e'8 f'8"))
>>> score.append(Staff("c'4 d'4"))
>>> score.append(
...     Staff(
...     scoretools.FixedDurationTuplet(
...     Duration(2, 8), "c'8 d'8 e'8") * 2))
>>> show(score) 
>>> array = pitchtools.PitchArray.from_score(
...     score, populate=False)
>>> print(array)
[     ] [     ] [     ] [     ]
[     ] [     ]
[ ] [     ] [ ] [ ] [     ] [ ]

Example 2. Makes populated pitch array from score:

>>> score = Score([])
>>> score.append(Staff("c'8 d'8 e'8 f'8"))
>>> score.append(Staff("c'4 d'4"))
>>> score.append(
...     Staff(
...     scoretools.FixedDurationTuplet(
...     Duration(2, 8), "c'8 d'8 e'8") * 2))
>>> show(score) 
>>> array = pitchtools.PitchArray.from_score(
...     score, populate=True)
>>> print(array)
[c'     ] [d'     ] [e'     ] [f'     ]
[c'     ] [d'     ]
[c'] [d'     ] [e'] [c'] [d'     ] [e']

Returns pitch array.

Special methods

PitchArray.__add__(arg)

Concatenates arg to pitch array.

Returns new pitch array.

PitchArray.__contains__(arg)

Is true when pitch array contains arg. Otherwise false.

Returns true or false.

PitchArray.__copy__()

Copies pitch array.

Returns new pitch array.

PitchArray.__eq__(arg)

Is true when arg is a pitch aarray with contents equal to that of this pitch array. 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.

PitchArray.__getitem__(arg)

Gets row arg from pitch array.

Returns pitch array row.

PitchArray.__hash__()

Hashes pitch array.

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

Returns integer.

PitchArray.__iadd__(arg)

Adds arg to pitch array in place.

>>> array_1 = pitchtools.PitchArray([[1, 2, 1], [2, 1, 1]])
>>> print(array_1)
[ ] [     ] [ ]
[     ] [ ] [ ]
>>> array_2 = pitchtools.PitchArray([[3, 4], [4, 3]])
>>> print(array_2)
[   ] [   ]
[     ] [   ]
>>> array_3 = pitchtools.PitchArray([[1, 1], [1, 1]])
>>> print(array_3)
[ ] [ ]
[ ] [ ]
>>> array_1 += array_2
>>> print(array_1)
[ ] [     ] [ ] [   ] [   ]
[     ] [ ] [ ] [     ] [   ]
>>> array_1 += array_3
>>> print(array_1)
[ ] [     ] [ ] [   ] [   ] [ ] [ ]
[     ] [ ] [ ] [     ] [   ] [ ] [ ]

Returns pitch array.

PitchArray.__ne__(arg)

Is true when pitch array does not equal arg. Otherwise false.

Returns true or false.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.

PitchArray.__setitem__(i, arg)

Sets pitch array row i to arg.

Retunrs none.

PitchArray.__str__()

String representation of pitch array.

Returns string.