This module defines various types of interval objects. Fundamental classes are Interval, GenericInterval, and ChromaticInterval.
Numerous utility functions are provided for processing and generating intervals.
module authors: Michael Scott Cuthbert, Jackie Rogoff, Amy Hailes, and Christopher Ariza
Given two Note objects, returns a ChromaticInterval object. Works equally well with Pitch objects.
>>> from music21 import *
>>> aNote = note.Note('c4')
>>> bNote = note.Note('g#5')
>>> notesToChromatic(aNote, bNote)
<music21.interval.ChromaticInterval 20>
>>> aPitch = pitch.Pitch('c#4')
>>> bPitch = pitch.Pitch('f-5')
>>> bInterval = notesToChromatic(aPitch, bPitch)
>>> bInterval
<music21.interval.ChromaticInterval 15>
Given a GenericInterval and a ChromaticInterval object, return a DiatonicInterval.
>>> from music21 import *
>>> aInterval = interval.GenericInterval('descending fifth')
>>> bInterval = interval.ChromaticInterval(-7)
>>> cInterval = interval.intervalsToDiatonic(aInterval, bInterval)
>>> cInterval
<music21.interval.DiatonicInterval P5>
Given a GenericInterval and a ChromaticInterval object, return a full Interval.
>>> from music21 import *
>>> 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>
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...)
>>> from music21 import *
>>> 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>
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
>>> from music21 import *
>>> 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)
Convert an interval specified in terms of its name (second, third) into an integer. If integers are passed, assume the are correct.
>>> from music21 import *
>>> 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
Convert a generic specification into an interval count. This uses a default mapping.
Given a number of semitones, return a default diatonic specifier.
>>> from music21 import *
>>> 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)
Given a number of semitones, return a default diatonic specifier and cent offset.
>>> from music21 import *
>>> 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)
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.
>>> from music21 import *
>>> 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)
Returns an integer of the generic interval number (P5 = 5, M3 = 3, minor 3 = 3 also) etc. from the given staff distance.
>>> from music21 import *
>>> interval.convertStaffDistanceToInterval(3)
4
>>> interval.convertStaffDistanceToInterval(7)
8
>>> interval.convertStaffDistanceToInterval(0)
1
>>> interval.convertStaffDistanceToInterval(-1)
-2
Given two Note objects, returns the higher note based on actual pitch. If both pitches are the same, returns the first note given.
>>> from music21 import *
>>> aNote = note.Note('c#3')
>>> bNote = note.Note('d--3')
>>> interval.getAbsoluteHigherNote(aNote, bNote)
<music21.note.Note C#>
Given two Note objects, returns the lower note based on actual pitch. If both pitches are the same, returns the first note given.
>>> from music21 import *
>>> aNote = note.Note('c#3')
>>> bNote = note.Note('d--3')
>>> interval.getAbsoluteLowerNote(aNote, bNote)
<music21.note.Note D-->
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.
>>> from music21 import *
>>> 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-->
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.
>>> from music21 import *
>>> 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#>
Given two Note objects, returns a GenericInterval object. works equally well with Pitch objects
>>> from music21 import *
>>> aNote = note.Note('c4')
>>> bNote = note.Note('g5')
>>> aInterval = notesToGeneric(aNote, bNote)
>>> aInterval
<music21.interval.GenericInterval 12>
>>> aPitch = pitch.Pitch('c#4')
>>> bPitch = pitch.Pitch('f-5')
>>> bInterval = notesToGeneric(aPitch, bPitch)
>>> bInterval
<music21.interval.GenericInterval 11>
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.
>>> from music21 import *
>>> 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>
starts with the first interval and subtracts the following intervals from it:
>>> from music21 import *
>>> 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>
>>> a = interval.subtract(["P5","A5"])
>>> a.niceName
'Augmented Unison'
>>> a.chromatic.semitones
-1
BUG: should be Descending Augmented Unison, currently giving Oblique Augmented Unison ! AARGH
Given a Note and a interval string (such as ‘P5’) or an Interval object, return a new Note object at the appropriate pitch level.
>>> from music21 import *
>>> aNote = note.Note('c4')
>>> bNote = interval.transposeNote(aNote, 'p5')
>>> bNote
<music21.note.Note G>
>>> bNote.pitch
G4
>>> aNote = note.Note('f#4')
>>> bNote = interval.transposeNote(aNote, 'm2')
>>> bNote
<music21.note.Note G>
Given a Pitch and a Interval object, return a new Pitch object at the appropriate pitch level.
>>> from music21 import *
>>> aPitch = pitch.Pitch('C4')
>>> aInterval = interval.Interval('P5')
>>> bPitch = interval.transposePitch(aPitch, aInterval)
>>> bPitch
G4
>>> bInterval = interval.Interval('P-5')
>>> cPitch = interval.transposePitch(aPitch, bInterval)
>>> cPitch
F3
Inherits from: Music21Object, JSONSerializer
An Interval class that encapsulates both Chromatic and Diatonic intervals all in one model.
The interval is specified either as named arguments, a DiatonicInterval and a ChromaticInterval, or two Note objects, from which both a ChromaticInterval and DiatonicInterval are derived.
>>> from music21 import * >>> n1 = note.Note('c3') >>> n2 = note.Note('c5') >>> aInterval = interval.Interval(noteStart=n1, noteEnd=n2) >>> aInterval <music21.interval.Interval P15> >>> aInterval.name 'P15'Reduce to a single 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'>>> aInterval = interval.Interval(3) >>> aInterval <music21.interval.Interval m3>>>> aInterval = interval.Interval(7) >>> aInterval <music21.interval.Interval P5>>>> n1 = note.Note('c3') >>> n2 = note.Note('g3') >>> aInterval = interval.Interval(noteStart=n1, noteEnd=n2) >>> aInterval <music21.interval.Interval P5>>>> 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.>>> 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 attributes
Attributes without Documentation: chromatic, diatonic, diatonicType, direction, generic, niceName, type
Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, hideObjectOnPrint, groups, id
Interval properties
- cents¶
Return the cents from the chromatic interval, where 100 cents = a half-step
>>> from music21 import * >>> 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
- complement¶
Return a new Interval object that is the complement of this Interval.
>>> from music21 import * >>> aInterval = interval.Interval('M3') >>> bInterval = aInterval.complement >>> bInterval <music21.interval.Interval m6> >>> cInterval = interval.Interval('A2') >>> dInterval = cInterval.complement >>> dInterval <music21.interval.Interval d7>
- 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.
>>> from music21 import * >>> aInterval = interval.Interval('M3') >>> aInterval.intervalClass 4 >>> bInterval = interval.Interval('m6') >>> bInterval.intervalClass 4
- noteEnd¶
Assuming this Interval has been defined, set the end note (_noteEnd) to a new value; this will adjust the value of the start note (_noteStart).
>>> from music21 import * >>> 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'
- noteStart¶
Assuming this Interval has been defined, set the start note (_noteStart) to a new value; this will adjust the value of the end note (_noteEnd).
>>> from music21 import * >>> 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'Properties inherited from Music21Object: activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, duration, isGrace, measureNumber, offset, priority, seconds
Properties inherited from JSONSerializer: json
Interval methods
- 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)
>>> from music21 import * >>> i1 = notesToInterval(note.Note('C'), note.Note('E')) >>> i1.isConsonant() True >>> i1 = notesToInterval(note.Note('B-'), note.Note('C')) >>> i1.isConsonant() False
- reinit()¶
Reinitialize the internal interval objects in case something has changed. Called during __init__ to assign attributes.
- reverse()¶
Return an reversed version of this interval. If given Notes, these notes are reversed.
>>> from music21 import * >>> 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 == aInterval.noteEnd True >>> aInterval = interval.Interval('m3') >>> aInterval.reverse() <music21.interval.Interval m-3>
- 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. For example, a value of 2 will permit double sharps but not triple sharps.
>>> from music21 import * >>> p1 = pitch.Pitch('a#') >>> i = interval.Interval('m3') >>> p2 = i.transposePitch(p1) >>> p2 C#5 >>> p2 = i.transposePitch(p1, reverse=True) >>> p2 F##4 >>> i.transposePitch(p1, reverse=True, maxAccidental=1) G4Methods inherited from Music21Object: searchActiveSiteByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndActiveSite(), freezeIds(), getAllContextsByClass(), getCommonSiteIds(), getCommonSites(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeLocations(), purgeOrphans(), purgeUndeclaredIds(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()
Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()
Inherits from: Music21Object, JSONSerializer
Chromatic interval class. Unlike a Diatonic interval, 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.
>>> from music21 import *
>>> aInterval = interval.ChromaticInterval(-14)
>>> aInterval.semitones
-14
>>> aInterval.undirected
14
>>> aInterval.mod12
10
>>> aInterval.intervalClass
2
>>> aInterval.isChromaticStep
False
>>> aInterval.isStep
False
>>> aInterval = interval.ChromaticInterval(1)
>>> aInterval.isChromaticStep
True
>>> aInterval.isStep
True
ChromaticInterval attributes
Attributes without Documentation: simpleUndirected, cents, simpleDirected, mod12, isChromaticStep, undirected, direction, intervalClass, directed, semitones, isStep
Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, id, groups, hideObjectOnPrint
ChromaticInterval properties
Properties inherited from Music21Object: activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, duration, isGrace, measureNumber, offset, priority, seconds
Properties inherited from JSONSerializer: json
ChromaticInterval methods
- getDiatonic()¶
Given a Chromatic interval, return a Diatonic interval 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.
>>> from music21 import * >>> 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>
- reverse()¶
Return an inverted interval, that is, reversing the direction.
>>> from music21 import * >>> aInterval = interval.ChromaticInterval(-14) >>> aInterval.reverse() <music21.interval.ChromaticInterval 14> >>> aInterval = interval.ChromaticInterval(3) >>> aInterval.reverse() <music21.interval.ChromaticInterval -3>
- transposePitch(p, reverse=False, clearAccidentalDisplay=True)¶
Given a Pitch object, return a new, transposed Pitch, that is transformed according to this ChromaticInterval.
Because ChromaticIntervals 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.
>>> from music21 import * >>> ci = interval.ChromaticInterval(6) >>> p = pitch.Pitch("E#4") >>> p2 = ci.transposePitch(p) >>> p2 B4 >>> p3 = ci.transposePitch(p2) >>> p3 F5Methods inherited from Music21Object: searchActiveSiteByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndActiveSite(), freezeIds(), getAllContextsByClass(), getCommonSiteIds(), getCommonSites(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeLocations(), purgeOrphans(), purgeUndeclaredIds(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()
Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()
Inherits from: Music21Object, JSONSerializer
A class representing a diatonic interval. Two required arguments are a specifier (such as perfect, major, or minor) and a generic, an interval size (such as 2, 2nd, or second).
A DiatonicInterval contains and encapsulates a GenericInterval
Two DiatonicIntervals are the same if their GenericIntervals are the same and their specifiers are the same.
The specifier is an integer or string specifying a value in the prefixSpecs and niceSpecNames lists.
The generic is an integer or GenericInterval instance.
>>> from music21 import *
>>> aInterval = interval.DiatonicInterval(1, 1)
>>> aInterval.simpleName
'P1'
>>> aInterval = interval.DiatonicInterval('p', 1)
>>> aInterval.simpleName
'P1'
>>> aInterval = interval.DiatonicInterval('major', 3)
>>> aInterval.simpleName
'M3'
>>> aInterval.niceName
'Major Third'
>>> aInterval.semiSimpleName
'M3'
>>> aInterval.directedSimpleName
'M3'
>>> aInterval.invertedOrderedSpecifier
'm'
>>> aInterval.mod7
'M3'
>>> aInterval = interval.DiatonicInterval('major', 'third')
>>> aInterval.niceName
'Major Third'
>>> aInterval = interval.DiatonicInterval('perfect', 'octave')
>>> aInterval.niceName
'Perfect Octave'
>>> aInterval = interval.DiatonicInterval('minor', 10)
>>> aInterval.mod7
'm3'
>>> aInterval.isDiatonicStep
False
>>> aInterval.isStep
False
>>> aInterval = interval.DiatonicInterval('major', 2)
>>> aInterval.isDiatonicStep
True
>>> aInterval.isStep
True
DiatonicInterval attributes
- directedName¶
The name of the interval in abbreviated form with direction.
- directedNiceName¶
The name of the interval in full form with direction.
- niceName¶
The name of the interval in full form.
- generic¶
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 accepted.
staffDistance: the number of lines or spaces apart, eg:
E.g. C4 to C4 = 0; C4 to D4 = 1; C4 to B3 = -1Two generic intervals are the equal if their size and direction are the same.
- name¶
The name of the interval in abbreviated form without direction.
Attributes without Documentation: specifier, isDiatonicStep, directedSimpleNiceName, mod7, mod7inversion, simpleName, semiSimpleName, simpleNiceName, semiSimpleNiceName, directedSimpleName, specificName, invertedOrderedSpecifier, prefectable, isStep, orderedSpecifierIndex, invertedOrderedSpecIndex
Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, id, groups, hideObjectOnPrint
DiatonicInterval properties
- cents¶
Return a cents representation of this interval, always assuming equal an equal tempered presentation.
>>> from music21 import * >>> i = interval.DiatonicInterval('minor', 'second') >>> i.niceName 'Minor Second' >>> i.cents 100.0Properties inherited from Music21Object: activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, duration, isGrace, measureNumber, offset, priority, seconds
Properties inherited from JSONSerializer: json
DiatonicInterval methods
- getChromatic()¶
Return a music21.interval.ChromaticInterval based on the size of this Interval.
>>> from music21 import * >>> 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>
- reverse()¶
Return a DiatonicInterval that is an inversion of this Interval.
>>> from music21 import * >>> aInterval = interval.DiatonicInterval('major', 3) >>> aInterval.reverse().directedName 'M-3' >>> aInterval = interval.DiatonicInterval('augmented', 5) >>> aInterval.reverse().directedName 'A-5'Methods inherited from Music21Object: searchActiveSiteByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndActiveSite(), freezeIds(), getAllContextsByClass(), getCommonSiteIds(), getCommonSites(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeLocations(), purgeOrphans(), purgeUndeclaredIds(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()
Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()
Inherits from: Music21Object, JSONSerializer
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 accepted.
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.
>>> from music21 import *
>>> gi = interval.GenericInterval(8)
>>> gi
<music21.interval.GenericInterval 8>
>>> aInterval = interval.GenericInterval(3)
>>> aInterval.direction
1
>>> aInterval.perfectable
False
>>> aInterval.staffDistance
2
>>> aInterval = interval.GenericInterval('Third')
>>> aInterval.directed
3
>>> aInterval.staffDistance
2
>>> aInterval = interval.GenericInterval(-12)
>>> aInterval.niceName
'Twelfth'
>>> aInterval.perfectable
True
>>> aInterval.staffDistance
-11
>>> aInterval.mod7
4
>>> bInterval = aInterval.complement()
>>> bInterval.staffDistance
3
>>> aInterval = interval.GenericInterval('descending twelfth')
>>> aInterval.perfectable
True
>>> aInterval.staffDistance
-11
>>> aInterval = interval.GenericInterval(0)
Traceback (most recent call last):
IntervalException: The Zeroth is not an interval
>>> aInterval = interval.GenericInterval(24)
>>> aInterval.niceName
'24'
>>> aInterval.isDiatonicStep
False
>>> aInterval.isStep
False
>>> aInterval = interval.GenericInterval(2)
>>> aInterval.isDiatonicStep
True
>>> aInterval.isStep
True
GenericInterval attributes
Attributes without Documentation: simpleUndirected, octaves, niceName, semiSimpleUndirected, simpleDirected, isSkip, mod7, mod7inversion, simpleNiceName, semiSimpleNiceName, undirected, isDiatonicStep, direction, perfectable, undirectedOctaves, directed, isUnison, staffDistance, value, semiSimpleDirected, isStep
Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, id, groups, hideObjectOnPrint
GenericInterval properties
Properties inherited from Music21Object: activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, duration, isGrace, measureNumber, offset, priority, seconds
Properties inherited from JSONSerializer: json
GenericInterval methods
- complement()¶
Returns a new GenericInterval object where descending 3rds are 6ths, etc.
>>> from music21 import * >>> aInterval = interval.GenericInterval('Third') >>> aInterval.complement() <music21.interval.GenericInterval 6>
- getDiatonic(specifier)¶
Given a specifier, return a DiatonicInterval object.
Specifier should be provided as a string name, such as ‘dd’, ‘M’, or ‘perfect’.
>>> from music21 import * >>> 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>
- reverse()¶
Returns a new GenericInterval object that is inverted.
>>> from music21 import * >>> 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: searchActiveSiteByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndActiveSite(), freezeIds(), getAllContextsByClass(), getCommonSiteIds(), getCommonSites(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeLocations(), purgeOrphans(), purgeUndeclaredIds(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()
Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()