Previous topic

music21.instrument

Next topic

music21.intervalNetwork

Table Of Contents

Table Of Contents

This Page

music21.interval

This module defines various types of interval objects. Fundamental classes are Interval, GenericInterval, and ChromaticInterval.

Functions

music21.interval.notesToChromatic(n1, n2)

Given two Note objects, returns a ChromaticInterval object.

Works equally well with Pitch objects.

>>> aNote = note.Note('c4')
>>> bNote = note.Note('g#5')
>>> interval.notesToChromatic(aNote, bNote)
<music21.interval.ChromaticInterval 20>
>>> aPitch = pitch.Pitch('c#4')
>>> bPitch = pitch.Pitch('f-5')
>>> bInterval = interval.notesToChromatic(aPitch, bPitch)
>>> bInterval
<music21.interval.ChromaticInterval 15>
music21.interval.intervalsToDiatonic(gInt, cInt)

Given a GenericInterval and a ChromaticInterval object, return a DiatonicInterval.

>>> aInterval = interval.GenericInterval('descending fifth')
>>> bInterval = interval.ChromaticInterval(-7)
>>> cInterval = interval.intervalsToDiatonic(aInterval, bInterval)
>>> cInterval
<music21.interval.DiatonicInterval P5>
music21.interval.intervalFromGenericAndChromatic(gInt, cInt)

Given a GenericInterval and a ChromaticInterval object, return a full Interval.

>>> aInterval = interval.GenericInterval('descending fifth')
>>> bInterval = interval.ChromaticInterval(-8)
>>> cInterval = interval.intervalFromGenericAndChromatic(aInterval, bInterval)
>>> cInterval
<music21.interval.Interval A-5>
>>> cInterval.name
'A5'
>>> cInterval.directedName
'A-5'    
>>> cInterval.directedNiceName
'Descending Augmented Fifth'
>>> interval.intervalFromGenericAndChromatic(3, 4)
<music21.interval.Interval M3>
>>> interval.intervalFromGenericAndChromatic(3, 3)
<music21.interval.Interval m3>
>>> interval.intervalFromGenericAndChromatic(5, 6)
<music21.interval.Interval d5>
>>> interval.intervalFromGenericAndChromatic(5, 5)
<music21.interval.Interval dd5>
>>> interval.intervalFromGenericAndChromatic(-2, -2)
<music21.interval.Interval M-2>
>>> interval.intervalFromGenericAndChromatic(1, 0.5)
<music21.interval.Interval A1 (-50c)>
music21.interval.add(intervalList)

Add a list of intervals and return the composite interval Intervals can be Interval objects or just strings.

(Currently not particularly efficient for large lists...)

>>> A2 = interval.Interval('A2')
>>> P5 = interval.Interval('P5')
>>> interval.add([A2, P5])
<music21.interval.Interval A6>
>>> interval.add([P5, "m2"])
<music21.interval.Interval m6>
>>> interval.add(["W","W","H","W","W","W","H"])
<music21.interval.Interval P8>

Direction does matter:

>>> interval.add([P5, "P-4"])
<music21.interval.Interval M2>
music21.interval.convertDiatonicNumberToStep(dn)

Convert a diatonic number to a step name (without accidental) and a octave integer. The lowest C on a Bosendorfer Imperial Grand is assigned 1 the D above it is 2, E is 3, etc. See pitch.diatonicNoteNum for more details

>>> interval.convertDiatonicNumberToStep(15)
('C', 2)
>>> interval.convertDiatonicNumberToStep(23)
('D', 3)
>>> interval.convertDiatonicNumberToStep(0)
('B', -1)
>>> interval.convertDiatonicNumberToStep(1)
('C', 0)

Extremely high and absurdly low numbers also produce “notes”.

>>> interval.convertDiatonicNumberToStep(2100)
('B', 299)
>>> interval.convertDiatonicNumberToStep(-19)
('D', -3)
music21.interval.convertGeneric(value)

Convert an interval specified in terms of its name (second, third) into an integer. If integers are passed, assume the are correct.

>>> interval.convertGeneric(3)
3
>>> interval.convertGeneric('third')
3
>>> interval.convertGeneric('3rd')
3
>>> interval.convertGeneric('octave')
8
>>> interval.convertGeneric('twelfth')
12
>>> interval.convertGeneric('descending twelfth')
-12
>>> interval.convertGeneric(12)
12
>>> interval.convertGeneric(-12)
-12
>>> interval.convertGeneric(1)
1
>>> interval.convertGeneric(None)
Traceback (most recent call last):
IntervalException: Cannot get a direction from None
>>> interval.convertGeneric("1")
Traceback (most recent call last):
IntervalException: Cannot get a direction from 1
music21.interval.convertSemitoneToSpecifierGeneric(count)

Given a number of semitones, return a default diatonic specifier.

>>> interval.convertSemitoneToSpecifierGeneric(0)
('P', 1)
>>> interval.convertSemitoneToSpecifierGeneric(-2)
('M', -2)
>>> interval.convertSemitoneToSpecifierGeneric(1)
('m', 2)
>>> interval.convertSemitoneToSpecifierGeneric(7)
('P', 5)
>>> interval.convertSemitoneToSpecifierGeneric(11)
('M', 7)
>>> interval.convertSemitoneToSpecifierGeneric(12)
('P', 8)
>>> interval.convertSemitoneToSpecifierGeneric(13)
('m', 9)
>>> interval.convertSemitoneToSpecifierGeneric(-15)
('m', -10)
>>> interval.convertSemitoneToSpecifierGeneric(24)
('P', 15)
music21.interval.convertSemitoneToSpecifierGenericMicrotone(count)

Given a number of semitones, return a default diatonic specifier and cent offset.

MSC: 2013 Oct – unused and deprecated; may be moved or removed.

>>> interval.convertSemitoneToSpecifierGenericMicrotone(2.5)
('M', 2, 50.0)
>>> interval.convertSemitoneToSpecifierGenericMicrotone(2.25)
('M', 2, 25.0)
>>> interval.convertSemitoneToSpecifierGenericMicrotone(1.0)
('m', 2, 0.0)
>>> interval.convertSemitoneToSpecifierGenericMicrotone(1.75)
('M', 2, -25.0)
>>> interval.convertSemitoneToSpecifierGenericMicrotone(1.9)
('M', 2, -10.0...)
>>> interval.convertSemitoneToSpecifierGenericMicrotone(0.25)
('P', 1, 25.0)
>>> interval.convertSemitoneToSpecifierGenericMicrotone(12.25)
('P', 8, 25.0)
>>> interval.convertSemitoneToSpecifierGenericMicrotone(24.25)
('P', 15, 25.0)
>>> interval.convertSemitoneToSpecifierGenericMicrotone(23.75)
('P', 15, -25.0)
music21.interval.convertSpecifier(specifier)

Given an integer or a string representing a “specifier” (major, minor, perfect, diminished, etc.), return a tuple of (1) an integer which refers to the appropriate specifier in a list and (2) a standard form for the specifier.

This function permits specifiers to specified in a flexible manner.

>>> interval.convertSpecifier(3)
(3, 'm')
>>> interval.convertSpecifier('p')
(1, 'P')
>>> interval.convertSpecifier('P')
(1, 'P')
>>> interval.convertSpecifier('M')
(2, 'M')
>>> interval.convertSpecifier('major')
(2, 'M')
>>> interval.convertSpecifier('m')
(3, 'm')
>>> interval.convertSpecifier('Augmented')
(4, 'A')
>>> interval.convertSpecifier('a')
(4, 'A')
>>> interval.convertSpecifier(None)
(None, None)
music21.interval.convertStaffDistanceToInterval(staffDist)

Returns an integer of the generic interval number (P5 = 5, M3 = 3, minor 3 = 3 also) etc. from the given staff distance.

>>> interval.convertStaffDistanceToInterval(3)
4
>>> interval.convertStaffDistanceToInterval(7)
8
>>> interval.convertStaffDistanceToInterval(0)
1
>>> interval.convertStaffDistanceToInterval(-1)
-2
music21.interval.getAbsoluteHigherNote(note1, note2)

Given two Note objects, returns the higher note based on actual frequency. If both pitches are the same, returns the first note given.

>>> aNote = note.Note('c#3')
>>> bNote = note.Note('d--3')
>>> interval.getAbsoluteHigherNote(aNote, bNote)
<music21.note.Note C#>
music21.interval.getAbsoluteLowerNote(note1, note2)

Given two Note objects, returns the lower note based on actual pitch. If both pitches are the same, returns the first note given.

>>> aNote = note.Note('c#3')
>>> bNote = note.Note('d--3')
>>> interval.getAbsoluteLowerNote(aNote, bNote)
<music21.note.Note D-->
music21.interval.getWrittenHigherNote(note1, note2)

Given two Note or Pitch objects, this function returns the higher object based on diatonic note numbers. Returns the note higher in pitch if the diatonic number is the same, or the first note if pitch is also the same.

>>> cis = pitch.Pitch("C#")
>>> deses = pitch.Pitch("D--")
>>> higher = interval.getWrittenHigherNote(cis, deses)
>>> higher is deses
True
>>> aNote = note.Note('c#3')
>>> bNote = note.Note('d-3')
>>> interval.getWrittenHigherNote(aNote, bNote)
<music21.note.Note D->
>>> aNote = note.Note('c#3')
>>> bNote = note.Note('d--3')
>>> interval.getWrittenHigherNote(aNote, bNote)
<music21.note.Note D-->
music21.interval.getWrittenLowerNote(note1, note2)

Given two Note objects, returns the lower note based on diatonic note number. Returns the note lower in pitch if the diatonic number is the same, or the first note if pitch is also the same.

>>> aNote = note.Note('c#3')
>>> bNote = note.Note('d--3')
>>> interval.getWrittenLowerNote(aNote, bNote)
<music21.note.Note C#>
>>> aNote = note.Note('c#3')
>>> bNote = note.Note('d-3')
>>> interval.getWrittenLowerNote(aNote, bNote)
<music21.note.Note C#>
music21.interval.notesToGeneric(n1, n2)

Given two Note objects, returns a GenericInterval object.

Works equally well with Pitch objects

>>> aNote = note.Note('c4')
>>> bNote = note.Note('g5')
>>> aInterval = interval.notesToGeneric(aNote, bNote)
>>> aInterval
<music21.interval.GenericInterval 12>
>>> aPitch = pitch.Pitch('c#4')
>>> bPitch = pitch.Pitch('f-5')
>>> bInterval = interval.notesToGeneric(aPitch, bPitch)
>>> bInterval
<music21.interval.GenericInterval 11>
music21.interval.notesToInterval(n1, n2=None)

Given two Note objects, returns an Interval object. The same functionality is available by calling the Interval class with two Notes as arguments.

Works equally well with Pitch objects.

N.B.: MOVE TO PRIVATE USE. Use: inverval.Interval(noteStart=aNote, noteEnd=bNote) instead. Do not remove because used in interval.Interval()!

>>> aNote = note.Note('c4')
>>> bNote = note.Note('g5')
>>> aInterval = interval.notesToInterval(aNote, bNote)
>>> aInterval
<music21.interval.Interval P12>
>>> bInterval = interval.Interval(noteStart=aNote, noteEnd=bNote)
>>> aInterval.niceName == bInterval.niceName
True
>>> aPitch = pitch.Pitch('c#4')
>>> bPitch = pitch.Pitch('f-5')
>>> cInterval = interval.notesToInterval(aPitch, bPitch)
>>> cInterval
<music21.interval.Interval dd11>
>>> cPitch = pitch.Pitch('e#4')
>>> dPitch = pitch.Pitch('f-4')
>>> dInterval = interval.notesToInterval(cPitch, dPitch)
>>> dInterval
<music21.interval.Interval dd2>
>>> ePitch = pitch.Pitch('e##4')
>>> fPitch = pitch.Pitch('f--4')
>>> dInterval = interval.notesToInterval(ePitch, fPitch)
>>> dInterval
<music21.interval.Interval dddd2>
>>> gPitch = pitch.Pitch('c--4')
>>> hPitch = pitch.Pitch('c##4')
>>> iInterval = interval.notesToInterval(gPitch, hPitch)
>>> iInterval
<music21.interval.Interval AAAA1>
>>> interval.notesToInterval(pitch.Pitch('e##4'), pitch.Pitch('f--5'))
<music21.interval.Interval dddd9>
music21.interval.subtract(intervalList)

Starts with the first interval and subtracts the following intervals from it:

>>> interval.subtract(["P5","M3"])
<music21.interval.Interval m3>
>>> interval.subtract(["P4","d3"])
<music21.interval.Interval A2>
>>> m2Object = interval.Interval("m2")
>>> interval.subtract(["M6","m2",m2Object])
<music21.interval.Interval AA4>
>>> interval.subtract(["P4", "M-2"])
<music21.interval.Interval P5>
>>> interval.subtract(["A2","A2"])
<music21.interval.Interval P1>
>>> interval.subtract(["A1","P1"])
<music21.interval.Interval A1>
>>> interval.subtract(["P8","P1"])
<music21.interval.Interval P8>
>>> interval.subtract(["P8","d2"])
<music21.interval.Interval A7>
>>> interval.subtract(["P8","A1"])
<music21.interval.Interval d8>
>>> a = interval.subtract(["P5","A5"])
>>> a.niceName
'Diminished Unison'
>>> a.directedNiceName
'Descending Diminished Unison'
>>> a.chromatic.semitones
-1    
music21.interval.transposeNote(note1, intervalString)

Given a Note and a interval string (such as ‘P5’) or an Interval object, return a new Note object at the appropriate pitch level.

>>> aNote = note.Note('c4')
>>> bNote = interval.transposeNote(aNote, 'p5')
>>> bNote
<music21.note.Note G>
>>> bNote.pitch
<music21.pitch.Pitch G4>
>>> aNote = note.Note('f#4')
>>> bNote = interval.transposeNote(aNote, 'm2')
>>> bNote
<music21.note.Note G>
music21.interval.transposePitch(pitch1, interval1)

Given a Pitch and a Interval object, return a new Pitch object at the appropriate pitch level.

>>> aPitch = pitch.Pitch('C4')
>>> aInterval = interval.Interval('P5')
>>> bPitch = interval.transposePitch(aPitch, aInterval)
>>> bPitch
<music21.pitch.Pitch G4>
>>> bInterval = interval.Interval('P-5')
>>> cPitch = interval.transposePitch(aPitch, bInterval)
>>> cPitch
<music21.pitch.Pitch F3>

Implicit Intervals should still work:

>>> dPitch = pitch.Pitch('G')
>>> ePitch = interval.transposePitch(dPitch, aInterval)
>>> ePitch
<music21.pitch.Pitch D>

Interval

class music21.interval.Interval(*arguments, **keywords)

An Interval class that encapsulates both ChromaticInterval and DiatonicInterval objects all in one model.

The interval is specified either as named arguments, a DiatonicInterval and a ChromaticInterval, or two Note objects (or Pitch objects), from which both a ChromaticInterval and DiatonicInterval are derived.
>>> n1 = note.Note('c3')
>>> n2 = note.Note('c5')
>>> aInterval = interval.Interval(noteStart=n1, noteEnd=n2)
>>> aInterval
<music21.interval.Interval P15>
>>> aInterval.name
'P15'
>>> aInterval.noteStart is n1
True
>>> aInterval.noteEnd is n2
True

Reduce to less than an octave:

>>> aInterval.simpleName
'P1'

Reduce to no more than an octave:

>>> aInterval.semiSimpleName
'P8'

An interval can also be specified directly

>>> aInterval = interval.Interval('m3')
>>> aInterval
<music21.interval.Interval m3>
>>> aInterval = interval.Interval('M3')
>>> aInterval
<music21.interval.Interval M3>    
>>> aInterval = interval.Interval('p5')
>>> aInterval
<music21.interval.Interval P5>
>>> aInterval.isChromaticStep
False
>>> aInterval.isDiatonicStep
False
>>> aInterval.isStep
False
>>> aInterval = interval.Interval('half')
>>> aInterval
<music21.interval.Interval m2>
>>> aInterval.isChromaticStep
True
>>> aInterval.isDiatonicStep
True
>>> aInterval.isStep
True
>>> aInterval = interval.Interval('-h')
>>> aInterval
<music21.interval.Interval m-2>
>>> aInterval.directedName
'm-2'
>>> aInterval.name
'm2'

A single int is treated as a number of half-steps:

>>> aInterval = interval.Interval(4)
>>> aInterval
<music21.interval.Interval M3>
>>> aInterval = interval.Interval(7)
>>> aInterval
<music21.interval.Interval P5>

If giving a starting note, an ending note has to be specified.

>>> aInterval = interval.Interval(noteStart=n1, noteEnd=None)
Traceback (most recent call last):
IntervalException: either both the starting and the ending note.Note must be given or neither can be given.  You cannot have one without the other.

An Interval can be constructed from a Diatonic and Chromatic Interval object

>>> aInterval = interval.DiatonicInterval('major', 'third')
>>> bInterval = interval.ChromaticInterval(4)
>>> cInterval = interval.Interval(diatonic=aInterval, chromatic=bInterval)
>>> cInterval
<music21.interval.Interval M3>
>>> cInterval = interval.Interval(diatonic=aInterval, chromatic=None)
Traceback (most recent call last):
IntervalException: either both a DiatonicInterval and a ChromaticInterval object have to be given or neither can be given.  You cannot have one without the other.

Two Intervals are the same if their Chromatic and Diatonic intervals are the same. N.B. that interval.Interval(‘a4’) != ‘a4’ – maybe it should...

Interval bases

Interval read-only properties

Interval.cents

Return the cents from the chromatic interval, where 100 cents = a half-step

>>> aInterval = interval.Interval('M3')
>>> aInterval.cents
400.0
>>> n1 = note.Note("C4")
>>> n2 = note.Note("D4")
>>> n2.pitch.microtone = 30
>>> microtoneInterval = interval.Interval(noteStart = n1, noteEnd = n2)
>>> microtoneInterval.cents
230.0
Interval.complement

Return a new Interval object that is the complement of this Interval.

>>> aInterval = interval.Interval('M3')
>>> bInterval = aInterval.complement
>>> bInterval
<music21.interval.Interval m6>
>>> cInterval = interval.Interval('A2')
>>> dInterval = cInterval.complement
>>> dInterval
<music21.interval.Interval d7>
Interval.intervalClass

Return the interval class from the chromatic interval, that is, the lesser of the number of half-steps in the simpleInterval or its complement.

>>> aInterval = interval.Interval('M3')
>>> aInterval.intervalClass
4
>>> bInterval = interval.Interval('m6')
>>> bInterval.intervalClass
4

Read-only properties inherited from Music21Object:

Interval read/write properties

Interval.noteEnd

Assuming this Interval has been defined, set the end note to a new value; this will adjust the value of the start note (noteStart).

>>> aInterval = interval.Interval('M3')
>>> aInterval.noteEnd = note.Note('e4')
>>> aInterval.noteStart.nameWithOctave
'C4'
>>> aInterval = interval.Interval('m2')
>>> aInterval.noteEnd = note.Note('A#3')
>>> aInterval.noteStart.nameWithOctave
'G##3'
>>> n1 = note.Note('g#3')
>>> n2 = note.Note('c3')
>>> aInterval = interval.Interval(n1, n2)
>>> aInterval.directedName # downward augmented fifth
'A-5'
>>> aInterval.noteEnd = note.Note('c4')
>>> aInterval.noteStart.nameWithOctave
'G#4'
>>> aInterval = interval.Interval('M3')
>>> aInterval.noteEnd = note.Note('A-3')
>>> aInterval.noteStart.nameWithOctave
'F-3'
Interval.noteStart

Assuming this Interval has been defined, set the start note to a new value; this will adjust the value of the end note (noteEnd).

>>> aInterval = interval.Interval('M3')
>>> aInterval.noteStart = note.Note('c4')
>>> aInterval.noteEnd.nameWithOctave
'E4'
>>> n1 = note.Note('c3')
>>> n2 = note.Note('g#3')
>>> aInterval = interval.Interval(n1, n2)
>>> aInterval.name
'A5'
>>> aInterval.noteStart = note.Note('g4')
>>> aInterval.noteEnd.nameWithOctave
'D#5'
>>> aInterval = interval.Interval('-M3')
>>> aInterval.noteStart = note.Note('c4')
>>> aInterval.noteEnd.nameWithOctave
'A-3'
>>> aInterval = interval.Interval('M-2')
>>> aInterval.noteStart = note.Note('A#3')
>>> aInterval.noteEnd.nameWithOctave
'G#3'
>>> aInterval = interval.Interval('h')
>>> aInterval.directedName
'm2'
>>> aInterval.noteStart = note.Note('F#3')
>>> aInterval.noteEnd.nameWithOctave
'G3'

Read/write properties inherited from Music21Object:

Interval methods

Interval.isConsonant()

returns True if the pitches are a major or minor third or sixth or perfect fifth or unison.

These rules define all common-practice consonances (and earlier back to about 1300 all imperfect consonances)

>>> i1 = interval.notesToInterval(note.Note('C'), note.Note('E'))
>>> i1.isConsonant()
True
>>> i1 = interval.notesToInterval(note.Note('B-'), note.Note('C'))
>>> i1.isConsonant()
False
Interval.reinit()

Reinitialize the internal interval objects in case something has changed. Called during __init__ to assign attributes.

Interval.reverse()

Return an reversed version of this interval. If Note objects are stored as noteStart and noteEnd, these notes are reversed.

>>> n1 = note.Note('c3')
>>> n2 = note.Note('g3')
>>> aInterval = interval.Interval(noteStart=n1, noteEnd=n2)
>>> aInterval
<music21.interval.Interval P5>
>>> bInterval = aInterval.reverse()
>>> bInterval
<music21.interval.Interval P-5>
>>> bInterval.noteStart is aInterval.noteEnd
True
>>> aInterval = interval.Interval('m3')
>>> aInterval.reverse()
<music21.interval.Interval m-3>
Interval.transposePitch(p, reverse=False, clearAccidentalDisplay=True, maxAccidental=4)

Given a Pitch object, return a new, transposed Pitch, that is transformed according to this Interval. This is the main public interface to all transposition routines found on higher-level objects.

The maxAccidental parameter sets an integer number of half step alterations that will be accepted in the transposed pitch before it is simplified. For example, a value of 2 will permit double sharps but not triple sharps. The maxAccidental default is 4, because music21 does not support quintuple sharps/flats. Set to None to try anyhow.

>>> p1 = pitch.Pitch('A#4')
>>> i = interval.Interval('m3')
>>> p2 = i.transposePitch(p1)
>>> p2
<music21.pitch.Pitch C#5>
>>> p2 = i.transposePitch(p1, reverse=True)
>>> p2
<music21.pitch.Pitch F##4>
>>> i.transposePitch(p1, reverse=True, maxAccidental=1)
<music21.pitch.Pitch G4>

Pitch objects without octaves are transposed also into objects without octaves. This might make them appear to be lower than the original even if transposed up:

>>> anyA = pitch.Pitch('A')
>>> anyC = i.transposePitch(anyA)
>>> anyC
<music21.pitch.Pitch C>
>>> anyC.ps < anyA.ps  # !!
True

Methods inherited from Music21Object:

Interval instance variables

Instance variables inherited from Music21Object:

ChromaticInterval

class music21.interval.ChromaticInterval(value=0)

Chromatic interval class. Unlike a DiatonicInterval, this Interval class treats interval spaces in half-steps. So Major 3rd and Diminished 4th are the same.

Two ChromaticIntervals are equal if their size and direction are equal.

ChromaticInterval bases

ChromaticInterval read-only properties

Read-only properties inherited from Music21Object:

ChromaticInterval read/write properties

Read/write properties inherited from Music21Object:

ChromaticInterval methods

ChromaticInterval.getDiatonic()

Given a ChromaticInterval, return a DiatonicInterval object of the same size.

While there is more than one Generic Interval for any given chromatic interval, this is needed to to permit easy chromatic specification of Interval objects. No augmented or diminished intervals are returned except for for interval of 6 which returns a diminished fifth, not augmented fourth.

>>> aInterval = interval.ChromaticInterval(5)
>>> aInterval.getDiatonic()
<music21.interval.DiatonicInterval P4>
>>> aInterval = interval.ChromaticInterval(6)
>>> aInterval.getDiatonic()
<music21.interval.DiatonicInterval d5>
>>> aInterval = interval.ChromaticInterval(7)
>>> aInterval.getDiatonic()
<music21.interval.DiatonicInterval P5>
>>> aInterval = interval.ChromaticInterval(11)
>>> aInterval.getDiatonic()
<music21.interval.DiatonicInterval M7>
ChromaticInterval.reverse()

Return an inverted ChromaticInterval, that is, reversing the direction.

>>> aInterval = interval.ChromaticInterval(-14)
>>> aInterval.reverse()
<music21.interval.ChromaticInterval 14>
>>> aInterval = interval.ChromaticInterval(3)
>>> aInterval.reverse()
<music21.interval.ChromaticInterval -3>
ChromaticInterval.transposePitch(p)

Given a Pitch object, return a new, transposed Pitch, that is transformed according to this ChromaticInterval.

Because ChromaticInterval object do not take into account diatonic spelling, the new Pitch is simplified to the most common intervals. See simplifyEnharmonic() with mostCommon = True to see the results.

>>> ci = interval.ChromaticInterval(6)
>>> p = pitch.Pitch("E#4")
>>> p2 = ci.transposePitch(p)
>>> p2
<music21.pitch.Pitch B4>
>>> p3 = ci.transposePitch(p2)
>>> p3
<music21.pitch.Pitch F5>

If no octave number is given then octaves “wrap around” and thus even after transposing upward, you could end up with a pitch that is displayed as lower than the original:

>>> p4 = pitch.Pitch("B")
>>> p4.ps
71.0
>>> p5 = ci.transposePitch(p4)
>>> p5.ps
65.0

Methods inherited from Music21Object:

ChromaticInterval instance variables

Instance variables inherited from Music21Object:

DiatonicInterval

class music21.interval.DiatonicInterval(specifier='P', generic=1)

A class representing a diatonic interval. Two required arguments are a string specifier (such as perfect, major, or minor) and generic, either an int of an interval size (such as 2, 2nd, or second) or a GenericInterval object.

Two DiatonicIntervals are the same if their GenericIntervals are the same and their specifiers are the same and they should be if their directions are the same, but this is not checked yet.

DiatonicInterval bases

DiatonicInterval read-only properties

DiatonicInterval.cents

Return a cents representation of this interval as a float, always assuming an equal-tempered presentation.

>>> i = interval.DiatonicInterval('minor', 'second')
>>> i.niceName
'Minor Second'
>>> i.cents
100.0

Read-only properties inherited from Music21Object:

DiatonicInterval read/write properties

Read/write properties inherited from Music21Object:

DiatonicInterval methods

DiatonicInterval.getChromatic()

Return a music21.interval.ChromaticInterval based on the size of this Interval.

>>> aInterval = interval.DiatonicInterval('major', 'third')
>>> aInterval.niceName
'Major Third'
>>> aInterval.getChromatic()
<music21.interval.ChromaticInterval 4>
>>> aInterval = interval.DiatonicInterval('augmented', -5)
>>> aInterval.niceName
'Augmented Fifth'
>>> aInterval.getChromatic()
<music21.interval.ChromaticInterval -8>
>>> aInterval = interval.DiatonicInterval('minor', 'second')
>>> aInterval.niceName
'Minor Second'
>>> aInterval.getChromatic()
<music21.interval.ChromaticInterval 1>
DiatonicInterval.reverse()

Return a DiatonicInterval that is an inversion of this Interval.

>>> aInterval = interval.DiatonicInterval('major', 3)
>>> aInterval.reverse().directedName
'M-3'
>>> aInterval = interval.DiatonicInterval('augmented', 5)
>>> aInterval.reverse().directedName
'A-5'

(Ascending) Augmented Unisons reverse to (Descending) Diminished Unisons and vice-versa

>>> aInterval = interval.DiatonicInterval('augmented', 1)
>>> aInterval.direction
1
>>> aInterval.directedName
'A1'
>>> dimUnison = aInterval.reverse()
>>> dimUnison.directedName
'd1'
>>> dimUnison.directedNiceName
'Descending Diminished Unison'

Methods inherited from Music21Object:

DiatonicInterval instance variables

DiatonicInterval.directedName

The name of the interval in abbreviated form with direction.

DiatonicInterval.directedNiceName

The name of the interval in full form with direction.

DiatonicInterval.name

The name of the interval in abbreviated form without direction.

DiatonicInterval.niceName

The name of the interval in full form.

Instance variables inherited from Music21Object:

GenericInterval

class music21.interval.GenericInterval(value='unison')

A GenericInterval is an interval such as Third, Seventh, Octave, or Tenth. Constructor takes an integer or string specifying the interval and direction.

The interval is not specified in half-steps, but in numeric values derived from interval names: a Third is 3; a Seventh is 7, etc. String values for interval names (‘3rd’ or ‘third’) are generally accepted, but discouraged since not every one will work.

staffDistance: the number of lines or spaces apart, eg:

E.g. C4 to C4 = 0; C4 to D4 = 1; C4 to B3 = -1

Two generic intervals are the equal if their size and direction are the same.

GenericInterval bases

GenericInterval read-only properties

Read-only properties inherited from Music21Object:

GenericInterval read/write properties

Read/write properties inherited from Music21Object:

GenericInterval methods

GenericInterval.complement()

Returns a new GenericInterval object where descending 3rds are 6ths, etc.

>>> aInterval = interval.GenericInterval('Third')
>>> aInterval.complement()
<music21.interval.GenericInterval 6>
GenericInterval.getDiatonic(specifier)

Given a specifier, return a DiatonicInterval object.

Specifier should be provided as a string name, such as ‘dd’, ‘M’, or ‘perfect’.

>>> aInterval = interval.GenericInterval('Third')
>>> aInterval.getDiatonic('major')
<music21.interval.DiatonicInterval M3>
>>> aInterval.getDiatonic('minor')
<music21.interval.DiatonicInterval m3>
>>> aInterval.getDiatonic('d')
<music21.interval.DiatonicInterval d3>
>>> aInterval.getDiatonic('a')
<music21.interval.DiatonicInterval A3>
>>> aInterval.getDiatonic(2)
<music21.interval.DiatonicInterval M3>
>>> bInterval = interval.GenericInterval('fifth')
>>> bInterval.getDiatonic('perfect')
<music21.interval.DiatonicInterval P5>
GenericInterval.reverse()

Returns a new GenericInterval object that is inverted.

>>> aInterval = interval.GenericInterval('Third')
>>> aInterval.reverse()
<music21.interval.GenericInterval -3>
>>> aInterval = interval.GenericInterval(-13)
>>> aInterval.direction
-1
>>> aInterval.reverse()
<music21.interval.GenericInterval 13>

Unisons invert to unisons

>>> aInterval = interval.GenericInterval(1)
>>> aInterval.reverse()
<music21.interval.GenericInterval 1>

Methods inherited from Music21Object:

GenericInterval instance variables

Instance variables inherited from Music21Object: