Classes for representing and manipulating pitches, pitch-space, and accidentals.

Each Note object has a Pitch object embedded in it. Some of the methods below, such as, Pitch.step, etc. are made available directly in the Note object, so they will seem familiar.


music21.pitch.simplifyMultipleEnharmonics(pitches, criterion=<function _dissonanceScore>, keyContext=None)

Tries to simplify the enharmonic spelling of a list of pitches, pitch- or pitch-class numbers according to a given criterion.

A function can be passed as an argument to criterion, that is tried to be minimized in a greedy left-to-right fashion.

>>> pitch.simplifyMultipleEnharmonics([11, 3, 6])
[<music21.pitch.Pitch B>, <music21.pitch.Pitch D#>, <music21.pitch.Pitch F#>]
>>> pitch.simplifyMultipleEnharmonics([3, 8, 0])
[<music21.pitch.Pitch E->, <music21.pitch.Pitch A->, <music21.pitch.Pitch C>]
>>> pitch.simplifyMultipleEnharmonics([pitch.Pitch('G3'), 
...                                    pitch.Pitch('C-4'), 
...                                    pitch.Pitch('D4')])
[<music21.pitch.Pitch G3>, <music21.pitch.Pitch B3>, <music21.pitch.Pitch D4>]
>>> pitch.simplifyMultipleEnharmonics([pitch.Pitch('A3'), 
...                                    pitch.Pitch('B#3'), 
...                                    pitch.Pitch('E4')])
[<music21.pitch.Pitch A3>, <music21.pitch.Pitch C4>, <music21.pitch.Pitch E4>] 

The attribute keyContext is for supplying a KeySignature or a Key which is used in the simplification:

>>> pitch.simplifyMultipleEnharmonics([6, 10, 1], keyContext=key.Key('B'))
[<music21.pitch.Pitch F#>, <music21.pitch.Pitch A#>, <music21.pitch.Pitch C#>]
>>> pitch.simplifyMultipleEnharmonics([6, 10, 1], keyContext=key.Key('C-'))
[<music21.pitch.Pitch G->, <music21.pitch.Pitch B->, <music21.pitch.Pitch D->]


class music21.pitch.Pitch(name=None, **keywords)

A fundamental object that represents a single pitch.

Pitch objects are most often created by passing in a note name (C, D, E, F, G, A, B), an optional accidental (one or more “#”s or “-“s, where “-” means flat), and an optional octave number:

>>> highEflat = pitch.Pitch('E-6')
>>> highEflat.step
>>> highEflat.accidental
<accidental flat>
>>> highEflat.octave

The .nameWithOctave property gives back what we put in, ‘E-6’:

>>> highEflat.nameWithOctave

Pitch objects represent themselves as the class name followed by the .nameWithOctave:

>>> p1 = pitch.Pitch('a#4')
>>> p1
<music21.pitch.Pitch A#4>

Printing a pitch.Pitch object or converting it to a string gives a more compact form:

>>> print(p1)
>>> str(p1)


A Pitch without an accidental has a .accidental of None, not Natural. This can lead to problems if you assume that every Pitch or Note has a .accidental that you can call .alter or something like that on:

>>> c = pitch.Pitch("C4")
>>> c.accidental is None
>>> alters = []
>>> for pName in ['G#5','B-5','C6']:
...     p = pitch.Pitch(pName)
...     alters.append(p.accidental.alter)
Traceback (most recent call last):
AttributeError: 'NoneType' object has no attribute 'alter'
>>> alters
[1.0, -1.0]

If a Pitch doesn’t have an associated octave, then its .octave value is None. This means that it represents any G#, regardless of octave. Transposing this note up an octave doesn’t change anything.

>>> anyGsharp = pitch.Pitch("G#")
>>> anyGsharp.octave is None
>>> print(anyGsharp.transpose("P8"))

Sometimes we need an octave for a Pitch even if it’s not specified. For instance, we can’t play an octave-less Pitch in MIDI or display it on a staff. So there is an .implicitOctave tag to deal with these situations; by default it’s always 4.

>>> anyGsharp.implicitOctave

If a Pitch has its .octave explicitly set, then .implicitOctave always equals .octave.

>>> highEflat.implicitOctave

A pitch.Pitch object can also be created using only a number from 0-11, that number is taken to be a pitchClass, where 0 = C, 1 = C#/D-, etc.:

>>> p2 = pitch.Pitch(3)
>>> p2
<music21.pitch.Pitch E->

Since pitch.Pitch(3) could be either a D# or an E-flat, this Pitch object has an attribute, .implicitAccidental that is set to True. That means that when it is transposed or displayed, other programs should feel free to substitute an enharmonically equivalent pitch in its place:

>>> p2.implicitAccidental
>>> p1.implicitAccidental

Instead of using a single string or integer for creating the object, a succession of named keywords can be used instead:

>>> p3 = pitch.Pitch(name = 'C', accidental = '#', octave = 7, microtone = -30)
>>> p3.fullName
'C-sharp in octave 7 (-30c)'

The full list of supported key words are: name, accidental (which can be a string or an Accidental object), octave, microtone (which can be a number or a Microtone object), pitchClass (0-11), fundamental (another Pitch object representing the fundamental for this harmonic; harmonic is not yet supported, but should be), and midi or ps (two ways of specifying nearly the same thing, see below).

Using keywords to create Pitch objects is especially important if extreme pitches might be found. For instance, the first Pitch is B-double flat in octave 3, not B-flat in octave -3. The second object creates that low Pitch properly:

>>> p4 = pitch.Pitch("B--3")
>>> p4.accidental
<accidental double-flat>
>>> p4.octave
>>> p5 = pitch.Pitch(step = "B", accidental = "-", octave = -3)
>>> p5.accidental
<accidental flat>
>>> p5.octave

Internally, pitches are represented by their scale step (self.step), their octave, and their accidental. Pitch objects use these three elements to figure out their pitch space representation (; altering any of the first three changes the pitch space (ps) representation. Similarly, altering the .ps representation alters the first three.

>>> aSharp = pitch.Pitch("A#5")
>>> aSharp.octave = 4
>>> = 60.0
>>> aSharp.nameWithOctave

Two Pitches are equal if they represent the same pitch and are spelled the same (enharmonics do not count). A Pitch is greater than another Pitch if its .ps is greater than the other. Thus C##4 > D-4.

>>> pitch.Pitch("C#5") == pitch.Pitch("C#5")
>>> pitch.Pitch("C#5") == pitch.Pitch("D-5")
>>> pitch.Pitch("C##5") > pitch.Pitch("D-5")

A consequence of comparing enharmonics for equality but .ps for comparisons is that a Pitch can be neither less than or greater than another Pitch without being equal:

>>> pitch.Pitch("C#5") == pitch.Pitch("D-5")
>>> pitch.Pitch("C#5") > pitch.Pitch("D-5")
>>> pitch.Pitch("C#5") < pitch.Pitch("D-5")

Pitches used to be Music21Object subclasses, so they retain some of the attributes there such as .classes and .groups, but they don’t have Duration or Sites objects

Pitch read-only properties


Return the pitch alteration as a numeric value, where 1 is the space of one half step and all base pitch values are given by step alone. Thus, the alter value combines the pitch change suggested by the Accidental and the Microtone combined.

>>> p = pitch.Pitch('g#4')
>>> p.alter
>>> p.microtone = -25 # in cents
>>> p.alter

Read-only attribute. Returns the name of a Pitch in the French system (where A = la, B = si, B-flat = si bémol, C-sharp = do dièse, etc.) (Microtones and Quartertones raise an error). Note that do is used instead of the also acceptable ut.

>>> print(pitch.Pitch('B-').french)
si bémol
>>> print(pitch.Pitch('B').french)
>>> print(pitch.Pitch('E-').french)
mi bémol
>>> print(pitch.Pitch('C#').french)
do dièse
>>> print(pitch.Pitch('A--').french)
la double bémol
>>> p1 = pitch.Pitch('C')
>>> p1.accidental = pitch.Accidental('half-sharp')
>>> p1.french
Traceback (most recent call last):
PitchException: On ne peut pas utiliser les microtones avec "french." Quelle Dommage!        

Return the most complete representation of this Pitch, providing name, octave, accidental, and any microtonal adjustments.

>>> p = pitch.Pitch('A-3')
>>> p.microtone = 33.33
>>> p.fullName
'A-flat in octave 3 (+33c)'
>>> p = pitch.Pitch('A`7')
>>> p.fullName
'A-half-flat in octave 7'

Read-only property. Returns the name of a Pitch in the German system (where B-flat = B, B = H, etc.) (Microtones and Quartertones raise an error). Note that Ases is used instead of the also acceptable Asas.

>>> print(pitch.Pitch('B-').german)
>>> print(pitch.Pitch('B').german)
>>> print(pitch.Pitch('E-').german)
>>> print(pitch.Pitch('C#').german)
>>> print(pitch.Pitch('A--').german)
>>> p1 = pitch.Pitch('C')
>>> p1.accidental = pitch.Accidental('half-sharp')
>>> p1.german
Traceback (most recent call last):
PitchException: Es geht nicht "german" zu benutzen mit Microt...nen.  Schade!

Note these rarely used pitches:

>>> print(pitch.Pitch('B--').german)
>>> print(pitch.Pitch('B#').german)

Returns the octave of the Pitch, or defaultOctave if octave was never set. To set an octave, use .octave. Default octave is usually 4.


Read-only attribute. Returns the name of a Pitch in the Italian system (F-sharp is fa diesis, C-flat is do bemolle, etc.) (Microtones and Quartertones raise an error).

>>> print(pitch.Pitch('B-').italian)
si bemolle
>>> print(pitch.Pitch('B').italian)
>>> print(pitch.Pitch('E-9').italian)
mi bemolle
>>> print(pitch.Pitch('C#').italian)
do diesis
>>> print(pitch.Pitch('A--4').italian)
la doppio bemolle
>>> p1 = pitch.Pitch('C')
>>> p1.accidental = pitch.Accidental('half-sharp')
>>> p1.italian
Traceback (most recent call last):
PitchException: Non si puo usare `italian` con microtoni

Note these rarely used pitches:

>>> print(pitch.Pitch('E####').italian)
mi quadruplo diesis
>>> print(pitch.Pitch('D---').italian)
re triplo bemolle        

Read-only attribute. Returns the name of a Pitch in Spanish (Microtones and Quartertones raise an error).

>>> print(pitch.Pitch('B-').spanish)
si bèmol
>>> print(pitch.Pitch('E-').spanish)
mi bèmol
>>> print(pitch.Pitch('C#').spanish)
do sostenido
>>> print(pitch.Pitch('A--').spanish)
la doble bèmol
>>> p1 = pitch.Pitch('C')
>>> p1.accidental = pitch.Accidental('half-sharp')
>>> p1.spanish
Traceback (most recent call last):
PitchException: Unsupported accidental type.

Note these rarely used pitches:

>>> print(pitch.Pitch('B--').spanish)
si doble bèmol
>>> print(pitch.Pitch('B#').spanish)
si sostenido        

Name presently returns pitch name and accidental without octave.

>>> a = pitch.Pitch('G#')

This only displays properly in Py3:

a.unicodeName -> ‘G♯’


Return the pitch name with octave with unicode accidental symbols, if available.

Read-only property.

>>> p = pitch.Pitch("C#4")

This only displays properly in Py3

p.unicodeNameWithOctave -> ‘C♯4’

Pitch read/write properties


Stores an optional accidental object contained within the Pitch object. This might return None, which is different than a natural accidental:

>>> a = pitch.Pitch('E-')
>>> a.accidental.alter
>>> a.accidental.modifier
>>> b = pitch.Pitch('C4')
>>> b.accidental is None
>>> b.accidental = pitch.Accidental('natural')
>>> b.accidental is None
>>> b.accidental
<accidental natural>
>>> b = pitch.Pitch('C4')
>>> b.accidental = 1.5
>>> print(b)
>>> b.accidental = 1.65
>>> print(b)
>>> b.accidental = 1.95
>>> print(b)

Returns (or takes) an integer that uniquely identifies the diatonic version of a note, that is ignoring accidentals. The number returned is the diatonic interval above C0 (the lowest C on a Boesendorfer Imperial Grand), so G0 = 5, C1 = 8, etc. Numbers can be negative for very low notes.

C4 (middleC) = 29, C#4 = 29, C##4 = 29, D-4 = 30, D4 = 30, etc.

>>> c = pitch.Pitch('c4')
>>> c.diatonicNoteNum

Unlike MIDI numbers (or .ps), C and C# has the same diatonicNoteNum:

>>> c = pitch.Pitch('c#4')
>>> c.diatonicNoteNum

But D-double-flat has a different diatonicNoteNum than C.

>>> d = pitch.Pitch('d--4')
>>> d.diatonicNoteNum
>>> lowc = pitch.Pitch('c1')
>>> lowc.diatonicNoteNum
>>> b = pitch.Pitch()
>>> b.step = "B"
>>> b.octave = -1
>>> b.diatonicNoteNum

An implicitOctave of 4 is used if octave is not set:

>>> c = pitch.Pitch("C")
>>> c.diatonicNoteNum

diatonicNoteNum can also be set. Changing it does not change the Accidental associated with the Pitch.

>>> lowDSharp = pitch.Pitch("C#7") # start high !!!
>>> lowDSharp.diatonicNoteNum = 9  # move low
>>> lowDSharp.octave

Negative diatonicNoteNums are possible, in case, like John Luther Adams, you want to notate the sounds of sub-sonic Earth rumblings.

>>> lowlowA = pitch.Pitch("A")
>>> lowlowA.octave = -1
>>> lowlowA.diatonicNoteNum
>>> lowlowlowD = pitch.Pitch("D")
>>> lowlowlowD.octave = -3
>>> lowlowlowD.diatonicNoteNum
Return type:int

Gets the frequency of the note as if it’s in an equal temperment context where A4 = 440hz. The same as .frequency so long as no other temperments are currently being used.

Since we don’t have any other temperament objects as of v1.3, this is the same as .frequency always.


The frequency property gets or sets the frequency of the pitch in hertz.

If the frequency has not been overridden, then it is computed based on A440Hz and equal temperament

>>> a = pitch.Pitch()
>>> a.frequency = 440.0
>>> a.frequency
>>> a.octave

Microtones are captured if the frequency doesn’t correspond to any standard note.

>>> a.frequency = 450.0
>>> a
<music21.pitch.Pitch A~4(-11c)>

Sets the microtone object contained within the Pitch object. Microtones must be supplied in cents.

>>> p = pitch.Pitch('E4-')
>>> p.microtone.cents == 0
>>> p.microtone = 33 # adjustment in cents
>>> str(p)
>>> (, p.nameWithOctave) # these representations are unchanged
('E-', 'E-4')
>>> p.microtone = '(-12c' # adjustment in cents
>>> p
<music21.pitch.Pitch E-4(-12c)>
>>> p.microtone = pitch.Microtone(-30)
>>> p
<music21.pitch.Pitch E-4(-30c)>

Get or set a pitch value in MIDI. MIDI pitch values are like ps values (pitchSpace) rounded to the nearest integer; while the ps attribute will accommodate floats.

>>> c = pitch.Pitch('C4')
>>> c.midi
>>> c.midi =  23.5
>>> c.midi

Note that like ps (pitchSpace), MIDI notes do not distinguish between sharps and flats, etc.

>>> dSharp = pitch.Pitch('D#4')
>>> dSharp.midi
>>> eFlat = pitch.Pitch('E-4')
>>> eFlat.midi

Midi values are constrained to the space 0-127. Higher or lower values will be transposed octaves to fit in this space.

>>> veryHighFHalfFlat = pitch.Pitch("F")
>>> veryHighFHalfFlat.octave = 12
>>> veryHighFHalfFlat.accidental = pitch.Accidental('half-flat')
>>> veryHighFHalfFlat
<music21.pitch.Pitch F`12>
>>> veryHighFHalfFlat.midi
>>> notAsHighNote = pitch.Pitch()
>>> = veryHighFHalfFlat.midi
>>> notAsHighNote
<music21.pitch.Pitch F9>

Note that the conversion of improper midi values to proper midi values is done before assigning .ps:

>>> a = pitch.Pitch()
>>> a.midi = -10
>>> a.midi
>>> a.implicitAccidental

Gets or sets the name (pitch name with accidental but without octave) of the Pitch.

>>> p = pitch.Pitch("D#5")
>>> = 'C#'

Return or set the pitch name with an octave designation. If no octave as been set, no octave value is returned.

>>> gSharp = pitch.Pitch('G#4')
>>> gSharp.nameWithOctave
>>> dFlatFive = pitch.Pitch()
>>> dFlatFive.step = 'D'
>>> dFlatFive.accidental = pitch.Accidental('flat')
>>> dFlatFive.octave = 5
>>> dFlatFive.nameWithOctave
>>> dFlatFive.nameWithOctave = 'C#6'
>>> dFlatFive.octave

N.B. – it’s generally better to set the name and octave separately, especially since you may at some point encounter very low pitches such as “A octave -1”, which will be interpreted as “A-flat, octave 1”. Our crude setting algorithm also does not support octaves above 9.

>>> lowA = pitch.Pitch()
>>> = 'A'
>>> lowA.octave = -1
>>> lowA.nameWithOctave
>>> lowA.nameWithOctave = lowA.nameWithOctave
>>> lowA.octave

Returns or sets the octave of the note. Setting the octave updates the pitchSpace attribute.

>>> a = pitch.Pitch('g')
>>> a.octave is None
>>> a.implicitOctave
>>>  ## will use implicitOctave
>>> a.octave = 14
>>> a.octave
>>> a.implicitOctave

Returns or sets the integer value for the pitch, 0-11, where C=0, C#=1, D=2...B=11. Can be set using integers (0-11) or ‘A’ or ‘B’ for 10 or 11.

>>> a = pitch.Pitch('a3')
>>> a.pitchClass
>>> dis = pitch.Pitch('d3')
>>> dis.pitchClass
>>> dis.accidental = pitch.Accidental("#")
>>> dis.pitchClass

If a string “A” or “B” is given to pitchClass, it is still returned as an int.

>>> dis.pitchClass = "A"
>>> dis.pitchClass

Extreme octaves will not affect pitchClass

>>> dis.octave = -10
>>> dis.pitchClass

In the past, certain microtones and/or octaves were returning pc 12! This is now fixed.

>>> flattedC = pitch.Pitch('C4')
>>> flattedC.microtone = -4
>>> print(flattedC)
>>> flattedC.pitchClass
>>> print(
>>> flattedC.octave = -3
>>> print(
>>> flattedC.pitchClass

Note that the pitchClass of a microtonally altered pitch is the pitch class of the nearest pitch and that differences can occur between Python 2 and Python 3 rounding mechanisms. For instance, C~4 (C half sharp 4) is pitchClass 1 in Python 2, which rounds the ps of 60.5 to 61, while it is pitchClass 0 in Python 3, which uses the “round-to-even” algorithm for rounding. However, C#~ (C one-and-a-half-sharp) will round the same way in each system, to D.

>>> p = pitch.Pitch("C#~4")
>>> p.pitchClass

This means that pitchClass + microtone is NOT a good way to estimate the frequency of a pitch. For instance, if we take a pitch that is 90% of the way between pitchClass 0 (C) and pitchClass 1 (C#/D-flat), this formula gives an inaccurate answer of 1.9, not 0.9:

>>> p = pitch.Pitch("C4")
>>> p.microtone = 90
>>> p
<music21.pitch.Pitch C4(+90c)>
>>> p.pitchClass + p.microtone.cents/100.0

Returns or sets a string representation of the pitch class, where integers greater than 10 are replaced by A and B, respectively. Can be used to set pitch class by a string representation as well (though this is also possible with pitchClass.

>>> a = pitch.Pitch('a#3')
>>> a.pitchClass
>>> a.pitchClassString

We can set the pitchClassString as well:

>>> a.pitchClassString = 'B'
>>> a.pitchClass

The ps property permits getting and setting a pitch space value, a floating point number representing pitch space, where 60.0 is C4, middle C, 61.0 is C#4 or D-4, and floating point values are microtonal tunings (.01 is equal to one cent), so a quarter-tone sharp above C5 is 72.5.

Note that the choice of 60.0 for C4 makes it identical to the integer value of 60 for .midi, but .midi does not allow for microtones and is limited to 0-127 while .ps allows for notes before midi 0 or above midi 127.

>>> a = pitch.Pitch("C4")

Changing the ps value for a will change the step and octave:

>>> = 45
>>> a
<music21.pitch.Pitch A2>

Notice that ps 61 represents both C# and D-flat. Thus “implicitAccidental” will be true after setting our pitch to 61:

>>> = 61
>>> a
<music21.pitch.Pitch C#4>
>>> a.implicitAccidental

Microtonal accidentals and pure Microtones are allowed, as are extreme ranges:

>>> b = pitch.Pitch('B9')
>>> b.accidental = pitch.Accidental('half-flat')
>>> b
<music21.pitch.Pitch B`9>
>>> p = pitch.Pitch('c4')
>>> p.microtone = 20
>>> print('%.1f' % p._getPs())

Octaveless pitches use their .implicitOctave attributes:

>>> d = pitch.Pitch("D#")
>>> d.octave is None
>>> d.implicitOctave
>>> d.defaultOctave = 5

The diatonic name of the note; i.e. does not give the accidental or octave.

>>> a = pitch.Pitch('B-3')
>>> a.step

Upper-case or lower-case names can be given to .step – they will be converted to upper-case

>>> b = pitch.Pitch()
>>> b.step = "c"
>>> b.step

Changing the .step does not change the .accidental or .octave:

>>> a = pitch.Pitch('F#5')
>>> a.step = 'D'
>>> a.nameWithOctave

Giving a value that includes an accidental raises a PitchException. Use .name instead to change that.

>>> b = pitch.Pitch('E4')
>>> b.step = "B-"
Traceback (most recent call last):
PitchException: Cannot make a step out of 'B-'

This is okay though:

>>> = "B-"

Pitch methods


Convert any Microtones available to quarter tones, if possible.

>>> p = pitch.Pitch('g3')
>>> p.microtone = 78
>>> str(p)
>>> p.convertMicrotonesToQuarterTones(inPlace=True)
>>> str(p)
>>> p = pitch.Pitch('d#3')
>>> p.microtone = 46
>>> p
<music21.pitch.Pitch D#3(+46c)>
>>> p.convertMicrotonesToQuarterTones(inPlace=True)
>>> p
<music21.pitch.Pitch D#~3(-4c)>
>>> p = pitch.Pitch('f#2')
>>> p.microtone = -38
>>> p.convertMicrotonesToQuarterTones(inPlace=True)
>>> str(p)

Convert any quarter tone Accidentals to Microtones.

tilde is the symbol for half-sharp, so G#~ is G three-quarters sharp.

>>> p = pitch.Pitch('G#~')
>>> str(p), p.microtone
('G#~', (+0c))
>>> p.convertQuarterTonesToMicrotones(inPlace=True)
>>> str(p), p.microtone
('G#(+50c)', (+50c))
>>> p = pitch.Pitch('A')
>>> p.accidental = pitch.Accidental('half-flat')  # back-tick
>>> str(p), p.microtone
('A`', (+0c))
>>> x = p.convertQuarterTonesToMicrotones(inPlace=False)
>>> str(x), x.microtone
('A(-50c)', (-50c))
>>> str(p), p.microtone
('A`', (+0c))

Return all common unique enharmonics for a pitch, or those that do not involve more than two accidentals.

>>> p = pitch.Pitch('c#3')
>>> p.getAllCommonEnharmonics()
[<music21.pitch.Pitch D-3>, <music21.pitch.Pitch B##2>]

“Higher” enharmonics are listed before “Lower”:

>>> p = pitch.Pitch('G4')
>>> p.getAllCommonEnharmonics()
[<music21.pitch.Pitch A--4>, <music21.pitch.Pitch F##4>]

By setting alterLimit to a higher or lower number we can limit the maximum number of notes to return:

>>> p = pitch.Pitch('G-6')
>>> p.getAllCommonEnharmonics(alterLimit=1)
[<music21.pitch.Pitch F#6>]

If you set alterLimit to 3 or 4, you’re stretching the name of the method; some of these are certainly not common enharmonics:

>>> p = pitch.Pitch('G-6')
>>> enharmonics = p.getAllCommonEnharmonics(alterLimit=3)
>>> [str(enh) for enh in enharmonics]
['A---6', 'F#6', 'E##6']

Music21 does not support accidentals beyond quadruple sharp/flat, so alterLimit = 4 is the most you can use. (Thank goodness!)

Return type:list(Pitch)

Get cent deviation of this pitch from MIDI pitch.

>>> p = pitch.Pitch('c~4')
>>> p.midi # midi values automatically round up
>>> p.getCentShiftFromMidi()
>>> p = pitch.Pitch('c#4')
>>> p.microtone = -25
>>> p.getCentShiftFromMidi()
>>> p = pitch.Pitch('c#~4')
>>> p.getCentShiftFromMidi()
>>> p.microtone = 3
>>> p.getCentShiftFromMidi()
>>> p = pitch.Pitch('c`4') # quarter tone flat
>>> p.getCentShiftFromMidi()
>>> p.microtone = 3
>>> p.getCentShiftFromMidi()

Returns a new Pitch that is the(/an) enharmonic equivalent of this Pitch.

N.B.: == getEnharmonic(getEnharmonic(n1)).name is not necessarily true. For instance:

getEnharmonic(E##) => F# getEnharmonic(F#) => G- getEnharmonic(A–) => G getEnharmonic(G) => F##

However, for all cases not involving double sharps or flats (and even many that do), getEnharmonic(getEnharmonic(n)) = n

For the most ambiguous cases, it’s good to know that these are the enharmonics:

C <-> B#, D <-> C##, E <-> F-; F <-> E#, G <-> F##, A <-> B–, B <-> C-

However, isEnharmonic() for A## and B certainly returns True.

>>> p = pitch.Pitch('d#')
>>> print(p.getEnharmonic())
>>> p = pitch.Pitch('e-8')
>>> print(p.getEnharmonic())

Other tests:

>>> print(pitch.Pitch('c-3').getEnharmonic())
>>> print(pitch.Pitch('e#2').getEnharmonic())
>>> print(pitch.Pitch('f#2').getEnharmonic())
>>> print(pitch.Pitch('c##5').getEnharmonic())
>>> print(pitch.Pitch('g3').getEnharmonic())
>>> print(pitch.Pitch('B7').getEnharmonic())

Octaveless Pitches remain octaveless:

>>> p = pitch.Pitch('a-')
>>> p.getEnharmonic()
<music21.pitch.Pitch G#>
>>> p = pitch.Pitch('B#')
>>> p.getEnharmonic()
<music21.pitch.Pitch C>

Works with half-sharps, etc. but converts them to microtones:

>>> p = pitch.Pitch('D~')
>>> print(p.getEnharmonic())
Return type:music21.pitch.Pitch

Return a Pitch object representing the harmonic found above this Pitch.

>>> p = pitch.Pitch('a4')
>>> print(p.getHarmonic(2))
>>> print(p.getHarmonic(3))
>>> print(p.getHarmonic(4))
>>> print(p.getHarmonic(5))
>>> print(p.getHarmonic(6))
>>> print(p.getHarmonic(7))
>>> print(p.getHarmonic(8))
>>> p2 = p.getHarmonic(2)
>>> p2
<music21.pitch.Pitch A5>
>>> p2.fundamental
<music21.pitch.Pitch A4>
>>> p2.transpose('p5', inPlace=True)
>>> p2
<music21.pitch.Pitch E6>
>>> p2.fundamental
<music21.pitch.Pitch E5>

Or we can iterate over a list of the next 8 odd harmonics:

>>> allHarmonics = ""
>>> for i in [9,11,13,15,17,19,21,23]:
...     allHarmonics += " " + str(p.getHarmonic(i))
>>> print(allHarmonics)
B7(+4c) D~8(+1c) F~8(-9c) G#8(-12c) B-8(+5c) C9(-2c) C#~9(+21c) E`9(-22c)

Microtonally adjusted notes also generate harmonics:

>>> q = pitch.Pitch('C4')
>>> q.microtone = 10
>>> q.getHarmonic(2)
<music21.pitch.Pitch C5(+10c)>
>>> q.getHarmonic(3)
<music21.pitch.Pitch G5(+12c)>

The fundamental is stored with the harmonic.

>>> h7 = pitch.Pitch("A4").getHarmonic(7)
>>> print(h7)
>>> h7.fundamental
<music21.pitch.Pitch A4>
>>> h7.harmonicString()
>>> h7.harmonicString('A3')
>>> h2 = h7.getHarmonic(2)
>>> h2
<music21.pitch.Pitch F#~8(+19c)>
>>> h2.fundamental
<music21.pitch.Pitch F#~7(+19c)>
>>> h2.fundamental.fundamental
<music21.pitch.Pitch A4>
>>> h2.transpose(-24, inPlace=True)
>>> h2
<music21.pitch.Pitch F#~6(+19c)>
>>> h2.fundamental.fundamental
<music21.pitch.Pitch A2>
Return type:music21.pitch.Pitch

Returns an enharmonic Pitch object that is a higher enharmonic. That is, the Pitch a diminished-second above the current Pitch.

>>> p1 = pitch.Pitch('C#3')
>>> p2 = p1.getHigherEnharmonic()
>>> print(p2)

We can also set it in place (in which case it returns None):

>>> p1 = pitch.Pitch('C#3')
>>> p1.getHigherEnharmonic(inPlace=True)
>>> print(p1)

The method even works for certain CRAZY enharmonics

>>> p3 = pitch.Pitch('D--3')
>>> p4 = p3.getHigherEnharmonic()
>>> print(p4)

But not for things that are just utterly insane:

>>> p4.getHigherEnharmonic()
Traceback (most recent call last):
AccidentalException: -5 is not a supported accidental type

Note that half accidentals get converted to microtones:

>>> pHalfSharp = pitch.Pitch('D~4')
>>> p3QtrsFlat = pHalfSharp.getHigherEnharmonic()
>>> print(p3QtrsFlat)

(Same thing if done in place; prior bug)

>>> pHalfSharp = pitch.Pitch('D~4')
>>> pHalfSharp.getHigherEnharmonic(inPlace=True)
>>> print(pHalfSharp)
Return type:music21.pitch.Pitch

returns a Pitch enharmonic that is a diminished second below the current note

If inPlace is set to true, changes the current Pitch and returns None.

>>> p1 = pitch.Pitch('C-3')
>>> p2 = p1.getLowerEnharmonic()
>>> print(p2)
>>> p1 = pitch.Pitch('C#3')
>>> p1.getLowerEnharmonic(inPlace=True)
>>> print(p1)
Return type:music21.pitch.Pitch

If pitch bend will be used to adjust MIDI values, the given pitch values for microtones should go to the nearest non-microtonal pitch value, not rounded up or down. This method is used in MIDI output generation.

>>> p = pitch.Pitch('c~4')
>>> p.getMidiPreCentShift()
>>> p = pitch.Pitch('c#4')
>>> p.getMidiPreCentShift()
>>> p.microtone = 65
>>> p.getMidiPreCentShift()
>>> p.getCentShiftFromMidi()

Given a chord, determines whether the chord constitutes a string harmonic and then returns a new chord with the proper sounding pitch added.

>>> n1 = note.Note('d3')
>>> n2 = note.Note('g3')
>>> n2.notehead = 'diamond'
>>> n2.noteheadFill = False
>>> p1 = pitch.Pitch('d3')
>>> harmChord = chord.Chord([n1, n2])
>>> harmChord.quarterLength = 1
>>> newChord = p1.getStringHarmonic(harmChord)
>>> newChord.quarterLength = 1
>>> pitchList = newChord.pitches
>>> pitchList
(<music21.pitch.Pitch D3>, <music21.pitch.Pitch G3>, <music21.pitch.Pitch D5>)

Given a Pitch that is a plausible target for a fundamental, return the harmonic number and a potentially shifted fundamental that describes this Pitch.

>>> g4 = pitch.Pitch('g4')
>>> g4.harmonicAndFundamentalFromPitch('c3')
(3, <music21.pitch.Pitch C3(-2c)>)

Given a Pitch that is a plausible target for a fundamental, return the harmonic number and a potentially shifted fundamental that describes this Pitch. Return a string representation.

>>> pitch.Pitch('g4').harmonicAndFundamentalStringFromPitch('c3')
>>> pitch.Pitch('c4').harmonicAndFundamentalStringFromPitch('c3')
>>> p = pitch.Pitch('c4')
>>> p.microtone = 20 # raise 20
>>> p.harmonicAndFundamentalStringFromPitch('c3')
>>> p.microtone = -20 # lower 20
>>> p.harmonicAndFundamentalStringFromPitch('c3')
>>> p = pitch.Pitch('c4')
>>> f = pitch.Pitch('c3')
>>> f.microtone = -20
>>> p.harmonicAndFundamentalStringFromPitch(f)
>>> f.microtone = +20
>>> p.harmonicAndFundamentalStringFromPitch(f)
>>> p = pitch.Pitch('A4')
>>> p.microtone = 69
>>> p.harmonicAndFundamentalStringFromPitch('c2')
>>> p = pitch.Pitch('A4')
>>> p.harmonicAndFundamentalStringFromPitch('c2')
Return type:str

Given another Pitch as a fundamental, find the harmonic of that pitch that is equal to this Pitch.

Returns a tuple of harmonic number and the number of cents that the first Pitch object would have to be shifted to be the exact harmonic of this fundamental.

Microtones applied to the fundamental are irrelevant, as the fundamental may be microtonally shifted to find a match to this Pitch.

Example: G4 is the third harmonic of C3, albeit 2 cents flatter than the true 3rd harmonic.

>>> p = pitch.Pitch('g4')
>>> f = pitch.Pitch('c3')
>>> p.harmonicFromFundamental(f)
(3, 2.0)
>>> p.microtone = p.harmonicFromFundamental(f)[1] # adjust microtone
>>> int(f.getHarmonic(3).frequency) == int(p.frequency)

The shift from B-5 to the 7th harmonic of C3 is more substantial and likely to be noticed by the audience. To make p the 7th harmonic it’d have to be lowered by 31 cents. Note that the second argument is a float, but because the default rounding of music21 is to the nearest cent, the .0 is not a significant digit. I.e. it might be more like 31.3 cents.

>>> p = pitch.Pitch('B-5')
>>> f = pitch.Pitch('C3')
>>> p.harmonicFromFundamental(f)
(7, -31.0)

Return a string representation of a harmonic equivalence.

N.B. this has nothing to do with what string a string player would use to play the harmonic on. (Perhaps should be renamed).

>>> pitch.Pitch('g4').harmonicString('c3')
>>> pitch.Pitch('c4').harmonicString('c3')
>>> p = pitch.Pitch('c4')
>>> p.microtone = 20 # raise 20
>>> p.harmonicString('c3')
>>> p.microtone = -20 # lower 20
>>> p.harmonicString('c3')
>>> p = pitch.Pitch('c4')
>>> f = pitch.Pitch('c3')
>>> f.microtone = -20
>>> p.harmonicString(f)
>>> f.microtone = +20
>>> p.harmonicString(f)
>>> p = pitch.Pitch('A4')
>>> p.microtone = 69
>>> p.harmonicString('c2')
>>> p = pitch.Pitch('A4')
>>> p.harmonicString('c2')

Return True if other is an enharmonic equivalent of self.

>>> p1 = pitch.Pitch('C#3')
>>> p2 = pitch.Pitch('D-3')
>>> p3 = pitch.Pitch('D#3')
>>> p1.isEnharmonic(p2)
>>> p2.isEnharmonic(p1)
>>> p3.isEnharmonic(p1)

Quarter tone enharmonics work as well:

>>> pC = pitch.Pitch('C4')
>>> pC.accidental = pitch.Accidental('one-and-a-half-sharp')
>>> pC
<music21.pitch.Pitch C#~4>
>>> pD = pitch.Pitch('D4')
>>> pD.accidental = pitch.Accidental('half-flat')
>>> pD
<music21.pitch.Pitch D`4>
>>> pC.isEnharmonic(pD)

Notes in different ranges are not enharmonics:

>>> pitch.Pitch("C#4").isEnharmonic( pitch.Pitch("D-5") )

However, different octaves can be the same range, because octave number is relative to the step (natural form) of the pitch.

>>> pitch.Pitch("C4").isEnharmonic( pitch.Pitch("B#3") )
>>> pitch.Pitch("C4").isEnharmonic( pitch.Pitch("B#4") )

If either pitch is octaveless, then they a pitch in any octave will match:

>>> pitch.Pitch("C#").isEnharmonic( pitch.Pitch("D-9") )
>>> pitch.Pitch("C#4").isEnharmonic( pitch.Pitch("D-") )

Microtonally altered pitches do not return True unless the microtones are the same:

>>> pSharp = pitch.Pitch("C#4")
>>> pSharp.microtone = 20
>>> pFlat = pitch.Pitch("D-4")
>>> pSharp.isEnharmonic(pFlat)
>>> pFlat.microtone = 20
>>> pSharp.isEnharmonic(pFlat)

Extreme enharmonics seem to work great.

>>> p4 = pitch.Pitch('B##3')
>>> p5 = pitch.Pitch('D-4')
>>> p4.isEnharmonic(p5)
Return type:bool

Return True if this Pitch is one of the twelve tones available on a piano keyboard. Returns False if it instead has a non-zero microtonal adjustment or has a quarter tone accidental.

>>> p = pitch.Pitch('g4')
>>> p.isTwelveTone()
>>> p.microtone = -20
>>> p.isTwelveTone()
>>> p2 = pitch.Pitch('g~4')
>>> p2.isTwelveTone()
Pitch.simplifyEnharmonic(inPlace=False, mostCommon=False)

Returns a new Pitch (or sets the current one if inPlace is True) that is either the same as the current pitch or has fewer sharps or flats if possible. For instance, E# returns F, while A# remains A# (i.e., does not take into account that B- is more common than A#). Useful to call if you ever have an algorithm that might take your piece far into the realm of double or triple flats or sharps.

If mostCommon is set to true, then the most commonly used enharmonic spelling is chosen (that is, the one that appears first in key signatures as you move away from C on the circle of fifths). Thus G-flat becomes F#, A# becomes B-flat, D# becomes E-flat, D-flat becomes C#, G# and A-flat are left alone.

>>> p1 = pitch.Pitch("B#5")
>>> p1.simplifyEnharmonic().nameWithOctave
>>> p2 = pitch.Pitch("A#2")
>>> p2.simplifyEnharmonic(inPlace = True)
>>> p2
<music21.pitch.Pitch A#2>
>>> p3 = pitch.Pitch("E--3")
>>> p4 = p3.transpose(interval.Interval('-A5'))
>>> p4.simplifyEnharmonic()
<music21.pitch.Pitch F#2>

Setting mostCommon = True simplifies enharmonics even further.

>>> pList = [pitch.Pitch("A#4"), pitch.Pitch("B-4"), 
...          pitch.Pitch("G-4"), pitch.Pitch("F#4")]
>>> [str(p.simplifyEnharmonic(mostCommon = True)) for p in pList]
['B-4', 'B-4', 'F#4', 'F#4']

Note that pitches with implicit octaves retain their implicit octaves. This might change the pitch space for B#s and C-s.

>>> pList = [pitch.Pitch("B"), pitch.Pitch("C#"), pitch.Pitch("G"), pitch.Pitch("A--")]
>>> [str(p.simplifyEnharmonic()) for p in pList]
['B', 'C#', 'G', 'G']
>>> pList = [pitch.Pitch("C-"), pitch.Pitch("B#")]
>>> [ for p in pList]
[59.0, 72.0]
>>> [p.simplifyEnharmonic().ps for p in pList]
[71.0, 60.0]
Return type:music21.pitch.Pitch
Pitch.transpose(value, inPlace=False)

Transpose the pitch by the user-provided value. If the value is an integer, the transposition is treated in half steps. If the value is a string, any Interval string specification can be provided. Alternatively, a music21.interval.Interval object can be supplied.

>>> aPitch = pitch.Pitch('g4')
>>> bPitch = aPitch.transpose('m3')
>>> bPitch
<music21.pitch.Pitch B-4>
>>> cPitch = bPitch.transpose(interval.GenericInterval(2))
>>> cPitch
<music21.pitch.Pitch C-5>
>>> aInterval = interval.Interval(-6)
>>> bPitch = aPitch.transpose(aInterval)
>>> bPitch
<music21.pitch.Pitch C#4>
>>> aPitch
<music21.pitch.Pitch G4>
>>> aPitch.transpose(aInterval, inPlace=True)
>>> aPitch
<music21.pitch.Pitch C#4>
Pitch.transposeAboveTarget(target, minimize=False, inPlace=True)

Given a source Pitch, shift it up octaves until it is above the target. Note: this manipulates src inPlace.

If minimize is True, a pitch above the target will move down to the nearest octave.

>>> pitch.Pitch('d2').transposeAboveTarget(pitch.Pitch('e4'))
<music21.pitch.Pitch D5>

If already above the target, make no change:

>>> pitch.Pitch('d7').transposeAboveTarget(pitch.Pitch('e2'))
<music21.pitch.Pitch D7>

Accept the same pitch:

>>> pitch.Pitch('d2').transposeAboveTarget(pitch.Pitch('d8'))
<music21.pitch.Pitch D8>

If minimize is True, we go the closest position:

>>> pitch.Pitch('d#8').transposeAboveTarget(pitch.Pitch('d2'), minimize=True)
<music21.pitch.Pitch D#2>
>>> pitch.Pitch('d7').transposeAboveTarget(pitch.Pitch('e2'), minimize=True)
<music21.pitch.Pitch D3>
>>> pitch.Pitch('d0').transposeAboveTarget(pitch.Pitch('e2'), minimize=True)
<music21.pitch.Pitch D3>
Return type:music21.pitch.Pitch
Pitch.transposeBelowTarget(target, minimize=False, inPlace=True)

Given a source Pitch, shift it down octaves until it is below the target. Note: this manipulates src inPlace.

If minimize is True, a pitch below the target will move up to the nearest octave.

>>> p = pitch.Pitch('g5')
>>> p.transposeBelowTarget(pitch.Pitch('c#4'), inPlace=True)
<music21.pitch.Pitch G3>
>>> p
<music21.pitch.Pitch G3>

Music21 2.0 transition period: inPlace is allowed now. Right now the default is True, but it will become False later.

>>> p = pitch.Pitch('g5')
>>> c = p.transposeBelowTarget(pitch.Pitch('c#4'), inPlace=False)
>>> c
<music21.pitch.Pitch G3>
>>> p
<music21.pitch.Pitch G5>

If already below the target, make no change:

>>> pitch.Pitch('g#3').transposeBelowTarget(pitch.Pitch('c#6'))
<music21.pitch.Pitch G#3>

Accept the same pitch:

>>> pitch.Pitch('g#8').transposeBelowTarget(pitch.Pitch('g#1'))
<music21.pitch.Pitch G#1>

This does nothing because it is already low enough...

>>> pitch.Pitch('g#2').transposeBelowTarget(pitch.Pitch('f#8'))
<music21.pitch.Pitch G#2>

But with minimize=True, it makes a difference...

>>> pitch.Pitch('g#2').transposeBelowTarget(pitch.Pitch('f#8'), minimize=True)
<music21.pitch.Pitch G#7>
>>> pitch.Pitch('f#2').transposeBelowTarget(pitch.Pitch('f#8'), minimize=True)
<music21.pitch.Pitch F#8>
Return type:music21.pitch.Pitch
Pitch.updateAccidentalDisplay(pitchPast=None, pitchPastMeasure=None, alteredPitches=None, cautionaryPitchClass=True, cautionaryAll=False, overrideStatus=False, cautionaryNotImmediateRepeat=True, lastNoteWasTied=False)

Given an ordered list of Pitch objects in pitchPast, determine if this pitch’s Accidental object needs to be created or updated with a natural or other cautionary accidental.

Changes to this Pitch object’s Accidental object are made in-place.

pitchPast is a list of pitches preceeding this pitch. If None, a new list will be made.

pitchPastMeasure is a list of pitches preceeding this pitch but in a previous measure. If None, a new list will be made.

The alteredPitches list supplies pitches from a KeySignature object using the alteredPitches property. If None, a new list will be made.

If cautionaryPitchClass is True, comparisons to past accidentals are made regardless of register. That is, if a past sharp is found two octaves above a present natural, a natural sign is still displayed. Note that this has nothing to do with whether a sharp (not in the key signature) is found in a different octave from the same note in a different octave. The sharp must always be displayed.

If overrideStatus is True, this method will ignore any current displayStatus stetting found on the Accidental. By default this does not happen. If displayStatus is set to None, the Accidental’s displayStatus is set.

If cautionaryNotImmediateRepeat is True, cautionary accidentals will be displayed for an altered pitch even if that pitch had already been displayed as altered (unless it’s an immediate repetition).

If lastNoteWasTied is True then this note will be treated as immediately following a tie.

>>> a = pitch.Pitch('a')
>>> past = [pitch.Pitch('a#'), pitch.Pitch('c#'), pitch.Pitch('c')]
>>> a.updateAccidentalDisplay(past, cautionaryAll=True)
>>> a.accidental, a.accidental.displayStatus
(<accidental natural>, True)
>>> b = pitch.Pitch('a')
>>> past = [pitch.Pitch('a#'), pitch.Pitch('c#'), pitch.Pitch('c')]
>>> b.updateAccidentalDisplay(past) # should add a natural
>>> b.accidental, b.accidental.displayStatus
(<accidental natural>, True)

In this example, the method will not add a natural because the match is pitchSpace and our octave is different.

>>> a4 = pitch.Pitch('a4')
>>> past = [pitch.Pitch('a#3'), pitch.Pitch('c#'), pitch.Pitch('c')]
>>> a4.updateAccidentalDisplay(past, cautionaryPitchClass=False)
>>> a4.accidental is None


class music21.pitch.Accidental(specifier='natural')

Accidental class, representing the symbolic and numerical representation of pitch deviation from a pitch name (e.g., G, B).

Two accidentals are considered equal if their names are equal.

Accidentals have three defining attributes: a name, a modifier, and an alter. For microtonal specifications, the name and modifier are the same except in the case of half-sharp, half-flat, one-and-a-half-flat, and one-and-a-half-sharp.

Accidentals up to quadruple-sharp and quadruple-flat are allowed.

Natural-sharp etc. (for canceling a previous flat) are not yet supported.

>>> a = pitch.Accidental('sharp')
>>>, a.alter, a.modifier
('sharp', 1.0, '#')

Accidental bases

Accidental read-only properties


Return the most complete representation of this Accidental.

>>> a = pitch.Accidental('double-flat')
>>> a.fullName

Note that non-standard microtones are converted to standard ones

>>> a = pitch.Accidental('quarter-flat')
>>> a.fullName

Return a unicode representation of this accidental or the best ascii representation if that is not possible.

Accidental read/write properties


Get or set the alter of the Accidental, or the semitone shift caused by the Accidental.

>>> sharp = pitch.Accidental('sharp')
>>> sharp.alter
>>> sharp.alter = -1

Note that name is still the same after changing alter... should it be?


Given the displayType, should this accidental be displayed?

In general, a display status of None is assumed to mean that no high-level processing of accidentals has happened.

Can be True, False, or None if not defined. For contexts where the next program down the line cannot evaluate displayType. See stream.makeAccidentals() for more information.


Returns or sets the display type of the accidental

“normal” (default) displays it if it is the first in measure, or is needed to contradict a previous accidental, etc.

other valid terms: “always”, “never”, “unless-repeated” (show always unless the immediately preceding note is the same), “even-tied” (stronger than always: shows even if it is tied to the previous note)


Get or set the alter of the modifier, or the string representation.’

Get or set the name of the Accidental, like ‘sharp’ or ‘double-flat’

Accidental methods


Given another Accidental object, inherit all the display properites of that object.

This is needed when transposing Pitches: we need to retain accidental display properties.

>>> a = pitch.Accidental('double-flat')
>>> a.displayType = 'always'
>>> b = pitch.Accidental('sharp')
>>> b.inheritDisplay(a)
>>> b.displayType

Return a boolean if this Accidental describes a twelve-tone pitch.

>>> a = pitch.Accidental('~')
>>> a.isTwelveTone()
>>> a = pitch.Accidental('###')
>>> a.isTwelveTone()
classmethod Accidental.listNames()

Returns a list of accidental names that have any sort of semantic importance in music21.

You may choose a name not from this list (1/7th-sharp) but if it’s not on this list don’t expect it to do anything for you.

This is a class method, so you may call it directly on the class:

Listed in alphabetical order. (TODO: maybe from lowest to highest or something implying importance?)

>>> pitch.Accidental.listNames()
 ['double-flat', 'double-sharp', 'flat', 'half-flat', 
  'half-sharp', 'natural', 'one-and-a-half-flat', 'one-and-a-half-sharp', 
  'quadruple-flat', 'quadruple-sharp', 'sharp', 'triple-flat', 'triple-sharp']

Or call on an instance of an accidental:

>>> f = pitch.Accidental('flat')
>>> f.listNames()
 ['double-flat', 'double-sharp', 'flat', 'half-flat', 'half-sharp', 'natural', 
  'one-and-a-half-flat', 'one-and-a-half-sharp', 'quadruple-flat', 'quadruple-sharp', 
  'sharp', 'triple-flat', 'triple-sharp']              

Change the type of the Accidental. Strings values, numbers, and Lilypond Abbreviations are all accepted. All other values will change after setting.

>>> a = pitch.Accidental()
>>> a.set('sharp')
>>> a.alter
>>> a = pitch.Accidental()
>>> a.set(2)
>>> a.modifier == "##"
>>> a = pitch.Accidental()
>>> a.set(2.0)
>>> a.modifier == "##"
>>> a = pitch.Accidental('--')
>>> a.alter

Accidental instance variables


A signed decimal representing the number of half-steps shifted by this Accidental, such as 1.0 for a sharp and -.5 for a quarter tone flat.


Location of accidental: “normal”, “above”, “below”.


Size in display: “cue”, “large”, or a percentage.


Determines if this Accidental is to be displayed; can be None (for not set), True, or False.


Style of display: “parentheses”, “bracket”, “both”.


A string symbol used to modify the pitch name, such as “#” or “-” for sharp and flat, respectively.

A string name of the Accidental, such as “sharp” or “double-flat”.


class music21.pitch.Microtone(centsOrString=0, harmonicShift=1)

The Microtone object defines a pitch transformation above or below a standard Pitch and its Accidental.

>>> m = pitch.Microtone(20)
>>> m.cents
>>> m.alter
>>> m

Microtones can be shifted according to the harmonic. Here we take the 3rd harmonic of the previous microtone

>>> m.harmonicShift = 3
>>> m
>>> m.cents
>>> m.alter

Microtonal changes can be positive or negative. Both Positive and negative numbers can optionally be placed in parentheses Negative numbers in parentheses still need the minus sign.

>>> m = pitch.Microtone('(-33.333333)')
>>> m
>>> m = pitch.Microtone('33.333333')
>>> m

Note that we round the display of microtones to the nearest cent, but we keep the exact alteration in both .cents and .alter:

>>> m.cents
>>> m.alter

Microtone bases

Microtone read-only properties


Return the microtone value in accidental alter values.


Return the microtone value in cents. This is not a settable property. To set the value in cents, simply use that value as a creation argument.

Microtone read/write properties


Set or get the harmonic shift, altering the microtone