NamedPitch

class pitchtools.NamedPitch(name="c'", arrow=None)

Named pitch.

>>> import abjad
>>> import pytest

Initializes from pitch name:

>>> pitch = abjad.NamedPitch("cs''")
>>> show(pitch) 

Initializes quartertone from pitch name:

>>> pitch = abjad.NamedPitch("aqs")
>>> show(pitch) 

Initializes from pitch-class / octave string:

>>> pitch = abjad.NamedPitch('C#5')
>>> show(pitch) 

Initializes quartertone from pitch-class / octave string:

>>> pitch = abjad.NamedPitch('A+3')
>>> show(pitch) 

Initializes arrowed pitch:

>>> pitch = abjad.NamedPitch('C#5', arrow=Up)
>>> show(pitch) 

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

Bases

Attribute summary

accidental Gets accidental of named pitch.
arrow Gets arrow of named pitch.
from_hertz(hertz) Makes named pitch from hertz.
from_pitch_carrier(pitch_carrier) Makes named pitch from pitch_carrier.
from_pitch_number(pitch_number, …) Makes named pitch from pitch_number.
get_name([locale]) Gets name of named pitch according to locale.
hertz Gets frequency of named pitch in Hertz.
invert([axis]) Inverts named pitch around axis.
multiply([n]) Multiplies named pitch.
name Gets name of named pitch.
number Gets number of named pitch.
octave Gets octave of named pitch.
pitch_class Gets pitch-class of named pitch.
to_staff_position([clef]) Changes named pitch to staff position.
transpose([n]) Transposes named pitch by index n.
transpose_staff_position(staff_positions, …) Transposes named pitch by staff_positions and interval.
__add__(interval) Adds named pitch to interval.
__copy__(*arguments) Copies named pitch.
__eq__(argument) Is true when argument is a named pitch equal to this named pitch.
__float__() Coerce to float.
__format__([format_specification]) Formats pitch.
__ge__(other[, NotImplemented]) Return a >= b.
__gt__(other[, NotImplemented]) Return a > b.
__hash__() Hashes named pitch.
__illustrate__() Illustrates pitch.
__le__(other[, NotImplemented]) Return a <= b.
__lt__(argument) Is true when named pitch is less than argument.
__ne__(argument) Is true when Abjad object does not equal argument.
__radd__(interval) Right-addition not defined on named pitches.
__repr__() Gets interpreter representation of Abjad object.
__str__() Gets string representation of named pitch.
__sub__(argument) Subtracts argument from named pitch.

Read-only properties

NamedPitch.accidental

Gets accidental of named pitch.

>>> abjad.NamedPitch("c''").accidental
Accidental('natural')
>>> abjad.NamedPitch("cs''").accidental
Accidental('sharp')
>>> abjad.NamedPitch("df''").accidental
Accidental('flat')

Returns accidental.

NamedPitch.arrow

Gets arrow of named pitch.

>>> abjad.NamedPitch("cs''").arrow is None
True
>>> abjad.NamedPitch("cs''", arrow=Up).arrow
Up
>>> abjad.NamedPitch("cs''", arrow=Down).arrow
Down

Displays arrow in interpreter representation:

>>> abjad.NamedPitch("cs''", arrow=Down)
NamedPitch("cs''", arrow=Down)

Returns up, down or none.

NamedPitch.hertz

Gets frequency of named pitch in Hertz.

>>> abjad.NamedPitch("c''").hertz
523.2511306011972
>>> abjad.NamedPitch("cs''").hertz
554.3652619537442
>>> abjad.NamedPitch("df''").hertz
554.3652619537442

Returns float.

NamedPitch.name

Gets name of named pitch.

>>> abjad.NamedPitch("c''").name
"c''"
>>> abjad.NamedPitch("cs''").name
"cs''"
>>> abjad.NamedPitch("df''").name
"df''"

Returns string.

NamedPitch.number

Gets number of named pitch.

>>> abjad.NamedPitch("c''").number
12
>>> abjad.NamedPitch("cs''").number
13
>>> abjad.NamedPitch("df''").number
13

Returns number.

NamedPitch.octave

Gets octave of named pitch.

>>> abjad.NamedPitch("c''").octave
Octave(5)
>>> abjad.NamedPitch("cs''").octave
Octave(5)
>>> abjad.NamedPitch("df''").octave
Octave(5)

Returns octave.

NamedPitch.pitch_class

Gets pitch-class of named pitch.

>>> abjad.NamedPitch("c''").pitch_class
NamedPitchClass('c')
>>> abjad.NamedPitch("cs''").pitch_class
NamedPitchClass('cs')
>>> abjad.NamedPitch("df''").pitch_class
NamedPitchClass('df')

Returns named pitch-class.

Methods

NamedPitch.get_name(locale=None)

Gets name of named pitch according to locale.

>>> abjad.NamedPitch("cs''").get_name()
"cs''"
>>> abjad.NamedPitch("cs''").get_name(locale='us')
'C#5'

Set locale to ‘us’ or none.

Returns string.

NamedPitch.invert(axis=None)

Inverts named pitch around axis.

Inverts pitch around middle C explicitly:

>>> abjad.NamedPitch("d'").invert("c'")
NamedPitch('bf')
>>> abjad.NamedPitch('bf').invert("c'")
NamedPitch("d'")

Inverts pitch around middle C implicitly:

>>> abjad.NamedPitch("d'").invert()
NamedPitch('bf')
>>> abjad.NamedPitch('bf').invert()
NamedPitch("d'")

Inverts pitch around A3:

>>> abjad.NamedPitch("d'").invert('a')
NamedPitch('e')

Interprets none-valued axis equal to middle C.

Returns new named pitch.

NamedPitch.multiply(n=1)

Multiplies named pitch.

>>> abjad.NamedPitch("d'").multiply(1)
NamedPitch("d'")
>>> abjad.NamedPitch("d'").multiply(3)
NamedPitch("fs'")
>>> abjad.NamedPitch("d'").multiply(6)
NamedPitch("c''")
>>> abjad.NamedPitch("d'").multiply(6.5)
NamedPitch("cs''")

Returns new named pitch.

NamedPitch.to_staff_position(clef=None)

Changes named pitch to staff position.

Changes C#5 to absolute staff position:

>>> abjad.NamedPitch('C#5').to_staff_position()
StaffPosition(7)

Changes C#5 to treble staff position:

>>> abjad.NamedPitch('C#5').to_staff_position(clef=abjad.Clef('treble'))
StaffPosition(1)

Changes C#5 to bass staff position:

>>> abjad.NamedPitch('C#5').to_staff_position(clef=abjad.Clef('bass'))
StaffPosition(13)

Marks up absolute staff position of many pitches:

>>> staff = abjad.Staff("g16 a b c' d' e' f' g' a' b' c'' d'' e'' f'' g'' a''")
>>> for note in staff:
...     staff_position = note.written_pitch.to_staff_position()
...     markup = abjad.Markup(staff_position.number)
...     abjad.attach(markup, note)
... 
>>> abjad.override(staff).text_script.staff_padding = 5
>>> show(staff) 

Marks up treble staff position of many pitches:

>>> staff = abjad.Staff("g16 a b c' d' e' f' g' a' b' c'' d'' e'' f'' g'' a''")
>>> clef = abjad.Clef('treble')
>>> for note in staff:
...     staff_position = note.written_pitch.to_staff_position(
...         clef=clef
...         )
...     markup = abjad.Markup(staff_position.number)
...     abjad.attach(markup, note)
... 
>>> abjad.override(staff).text_script.staff_padding = 5
>>> show(staff) 

Marks up bass staff position of many pitches:

>>> staff = abjad.Staff("g,16 a, b, c d e f g a b c' d' e' f' g' a'")
>>> clef = abjad.Clef('bass')
>>> abjad.attach(clef, staff[0])
>>> for note in staff:
...     staff_position = note.written_pitch.to_staff_position(
...         clef=clef
...         )
...     markup = abjad.Markup(staff_position.number)
...     abjad.attach(markup, note)
... 
>>> abjad.override(staff).text_script.staff_padding = 5
>>> show(staff) 

Returns staff position.

NamedPitch.transpose(n=0)

Transposes named pitch by index n.

Transposes C4 up a minor second:

>>> abjad.NamedPitch("c'").transpose(n='m2')
NamedPitch("df'")

Transposes C4 down a major second:

>>> abjad.NamedPitch("c'").transpose(n='-M2')
NamedPitch('bf')

Returns new named pitch.

NamedPitch.transpose_staff_position(staff_positions, interval)

Transposes named pitch by staff_positions and interval.

Transposes middle C but leaves at same staff position:

>>> pitch = abjad.NamedPitch(0)
>>> pitch.transpose_staff_position(0, -2)
NamedPitch("cff'")
>>> pitch.transpose_staff_position(0, -1.5)
NamedPitch("ctqf'")
>>> pitch.transpose_staff_position(0, -1)
NamedPitch("cf'")
>>> pitch.transpose_staff_position(0, -0.5)
NamedPitch("cqf'")
>>> pitch.transpose_staff_position(0, 0)
NamedPitch("c'")
>>> pitch.transpose_staff_position(0, 0.5)
NamedPitch("cqs'")
>>> pitch.transpose_staff_position(0, 1)
NamedPitch("cs'")
>>> pitch.transpose_staff_position(0, 1.5)
NamedPitch("ctqs'")

Transposes middle C and then respells up 1 staff position:

>>> pitch.transpose_staff_position(1, 0)
NamedPitch("dff'")
>>> pitch.transpose_staff_position(1, 0.5)
NamedPitch("dtqf'")
>>> pitch.transpose_staff_position(1, 1)
NamedPitch("df'")
>>> pitch.transpose_staff_position(1, 1.5)
NamedPitch("dqf'")
>>> pitch.transpose_staff_position(1, 2)
NamedPitch("d'")
>>> pitch.transpose_staff_position(1, 2.5)
NamedPitch("dqs'")
>>> pitch.transpose_staff_position(1, 3)
NamedPitch("ds'")
>>> pitch.transpose_staff_position(1, 3.5)
NamedPitch("dtqs'")
>>> pitch.transpose_staff_position(1, 4)
NamedPitch("dss'")

Returns new named pitch.

Class & static methods

classmethod NamedPitch.from_hertz(hertz)

Makes named pitch from hertz.

>>> abjad.NamedPitch.from_hertz(440)
NamedPitch("a'")
>>> abjad.NamedPitch.from_hertz(519)
NamedPitch("c'")

Returns newly constructed named pitch.

classmethod NamedPitch.from_pitch_carrier(pitch_carrier)

Makes named pitch from pitch_carrier.

Makes named pitch from named pitch:

>>> pitch = abjad.NamedPitch(('df', 5))
>>> abjad.NamedPitch.from_pitch_carrier(pitch)
NamedPitch("df''")

Makes named pitch from note:

>>> note = abjad.Note("df''4")
>>> abjad.NamedPitch.from_pitch_carrier(note)
NamedPitch("df''")

Makes named pitch from note-head:

>>> note = abjad.Note("df''4")
>>> abjad.NamedPitch.from_pitch_carrier(note.note_head)
NamedPitch("df''")

Makes named pitch from chord:

>>> chord = abjad.Chord("<df''>4")
>>> abjad.NamedPitch.from_pitch_carrier(chord)
NamedPitch("df''")

Makes named pitch from integer:

>>> abjad.NamedPitch.from_pitch_carrier(13)
NamedPitch("cs''")

Makes named pitch from numbered pitch-class:

>>> pitch_class = abjad.NumberedPitchClass(7)
>>> abjad.NamedPitch.from_pitch_carrier(pitch_class)
NamedPitch("g'")

Raises value error when pitch_carrier carries no pitch.

Raises value error when pitch_carrier carries more than one pitch.

Returns new named pitch.

classmethod NamedPitch.from_pitch_number(pitch_number, diatonic_pitch_class_name)

Makes named pitch from pitch_number.

>>> abjad.NamedPitch.from_pitch_number(12, 'b')
NamedPitch("bs'")
>>> abjad.NamedPitch.from_pitch_number(12, 'c')
NamedPitch("c''")
>>> abjad.NamedPitch.from_pitch_number(12, 'd')
NamedPitch("dff''")
>>> abjad.NamedPitch.from_pitch_number(13, 'b')
NamedPitch("bss'")
>>> abjad.NamedPitch.from_pitch_number(13, 'c')
NamedPitch("cs''")
>>> abjad.NamedPitch.from_pitch_number(13, 'd')
NamedPitch("df''")
>>> abjad.NamedPitch.from_pitch_number(14, 'c')
NamedPitch("css''")
>>> abjad.NamedPitch.from_pitch_number(14, 'd')
NamedPitch("d''")
>>> abjad.NamedPitch.from_pitch_number(14, 'e')
NamedPitch("eff''")

Returns new named pitch.

Special methods

NamedPitch.__add__(interval)

Adds named pitch to interval.

>>> abjad.NamedPitch("cs''") + abjad.NamedInterval('-M2')
NamedPitch("b'")
>>> abjad.NamedPitch("cs''") + abjad.NamedInterval('P1')
NamedPitch("cs''")
>>> abjad.NamedPitch("cs''") + abjad.NamedInterval('+M2')
NamedPitch("ds''")

Returns new named pitch.

NamedPitch.__copy__(*arguments)

Copies named pitch.

>>> import copy
>>> copy.copy(abjad.NamedPitch("c''"))
NamedPitch("c''")
>>> copy.copy(abjad.NamedPitch("cs''"))
NamedPitch("cs''")
>>> copy.copy(abjad.NamedPitch("df''"))
NamedPitch("df''")

Copies arrowed pitch:

>>> pitch = abjad.NamedPitch("cs''", arrow=Up)
>>> copy.copy(pitch)
NamedPitch("cs''", arrow=Up)

Returns new named pitch.

NamedPitch.__eq__(argument)

Is true when argument is a named pitch equal to this named pitch. Otherwise false.

>>> pitch_1 = abjad.NamedPitch('fs')
>>> pitch_2 = abjad.NamedPitch('fs')
>>> pitch_3 = abjad.NamedPitch('gf')
>>> pitch_1 == pitch_1
True
>>> pitch_1 == pitch_2
True
>>> pitch_1 == pitch_3
False
>>> pitch_2 == pitch_1
True
>>> pitch_2 == pitch_2
True
>>> pitch_2 == pitch_3
False
>>> pitch_3 == pitch_1
False
>>> pitch_3 == pitch_2
False
>>> pitch_3 == pitch_3
True

Returns true or false.

(Pitch).__float__()

Coerce to float.

Returns float.

(Pitch).__format__(format_specification='')

Formats pitch.

Set format_specification to ‘’, ‘lilypond’ or ‘storage’.

Returns string.

(Pitch).__ge__(other, NotImplemented=NotImplemented)

Return a >= b. Computed by @total_ordering from (not a < b).

(Pitch).__gt__(other, NotImplemented=NotImplemented)

Return a > b. Computed by @total_ordering from (not a < b) and (a != b).

NamedPitch.__hash__()

Hashes named pitch.

Returns integer.

(Pitch).__illustrate__()

Illustrates pitch.

Returns LilyPond file.

(Pitch).__le__(other, NotImplemented=NotImplemented)

Return a <= b. Computed by @total_ordering from (a < b) or (a == b).

NamedPitch.__lt__(argument)

Is true when named pitch is less than argument. Otherwise false.

>>> pitch_1 = abjad.NamedPitch('fs')
>>> pitch_2 = abjad.NamedPitch('fs')
>>> pitch_3 = abjad.NamedPitch('gf')
>>> pitch_1 < pitch_1
False
>>> pitch_1 < pitch_2
False
>>> pitch_1 < pitch_3
True
>>> pitch_2 < pitch_1
False
>>> pitch_2 < pitch_2
False
>>> pitch_2 < pitch_3
True
>>> pitch_3 < pitch_1
False
>>> pitch_3 < pitch_2
False
>>> pitch_3 < pitch_3
False

Returns true or false.

(AbjadObject).__ne__(argument)

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

Returns true or false.

NamedPitch.__radd__(interval)

Right-addition not defined on named pitches.

>>> statement = 'abjad.NamedPitch("cs\'").__radd__(1)'
>>> pytest.raises(NotImplementedError, statement)
<ExceptionInfo NotImplementedError tblen=3>
(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.

NamedPitch.__str__()

Gets string representation of named pitch.

>>> str(abjad.NamedPitch("c''"))
"c''"
>>> str(abjad.NamedPitch("cs''"))
"cs''"
>>> str(abjad.NamedPitch("df''"))
"df''"

Returns string.

NamedPitch.__sub__(argument)

Subtracts argument from named pitch.

>>> abjad.NamedPitch("cs''") - abjad.NamedPitch("b'")
NamedInterval('-M2')
>>> abjad.NamedPitch("cs''") - abjad.NamedPitch("fs''")
NamedInterval('+P4')

Returns named interval.