Previous topic

music21.scala.base

Next topic

music21.search

Table Of Contents

Table Of Contents

music21.scale

The various Scale objects provide a bi-directional object representation of octave repeating and non-octave repeating scales built by network of Interval objects as modeled in BoundIntervalNetwork.

The main public interface to these resources are subclasses of ConcreteScale, such as MajorScale, MinorScale, and MelodicMinorScale.

More unusual scales are also available, such as OctatonicScale, SieveScale, and RagMarwa.

All ConcreteScale subclasses provide the ability to get a pitches across any range, get a pitch for scale step, get a scale step for pitch, and, for any given pitch ascend or descend to the next pitch. In all cases Pitch objects are returned.

>>> from music21 import *
>>> sc1 = scale.MajorScale('a')
>>> [str(p) for p in sc1.getPitches('g2', 'g4')]
['G#2', 'A2', 'B2', 'C#3', 'D3', 'E3', 'F#3', 'G#3', 'A3', 'B3', 'C#4', 'D4', 'E4', 'F#4']
>>> sc2 = scale.MelodicMinorScale('a')
>>> [str(p) for p in sc2.getPitches('g2', 'g4', direction='descending')]
['G4', 'F4', 'E4', 'D4', 'C4', 'B3', 'A3', 'G3', 'F3', 'E3', 'D3', 'C3', 'B2', 'A2', 'G2']

>>> [str(p) for p in sc2.getPitches('g2', 'g4', direction='ascending')]
['G#2', 'A2', 'B2', 'C3', 'D3', 'E3', 'F#3', 'G#3', 'A3', 'B3', 'C4', 'D4', 'E4', 'F#4']

ConcreteScale

Inherits from: Scale, Music21Object

class music21.scale.ConcreteScale(tonic=None, pitches=None)

A concrete scale is specific scale formation with a defined pitch collection (a tonic Pitch) that may or may not be bound by specific range. For example, a specific Major Scale, such as G Major, from G2 to G4.

This class is can either be used directly or more commonly as a base class for all concrete scales.

Here we treat a diminished triad as a scale:

>>> from music21 import *
>>> myscale = scale.ConcreteScale(pitches = ["C4", "E-4", "G-4", "A4"])
>>> myscale.getTonic()
<music21.pitch.Pitch C4>
>>> myscale.next("G-2")
<music21.pitch.Pitch A2>
>>> [str(p) for p in myscale.getPitches("E-5","G-7")]
['E-5', 'G-5', 'A5', 'C6', 'E-6', 'G-6', 'A6', 'C7', 'E-7', 'G-7']

A scale that lasts two octaves and uses quarter tones (D~)

>>> from music21 import *
>>> complexscale = scale.ConcreteScale(pitches = ["C#3", "E-3", "F3", "G3", "B3", "D~4", "F#4", "A4", "C#5"])
>>> complexscale.getTonic()
<music21.pitch.Pitch C#3>
>>> complexscale.next("G3", direction=scale.DIRECTION_DESCENDING)
<music21.pitch.Pitch F3>

>>> [str(p) for p in complexscale.getPitches("C3","C7")]
['C#3', 'E-3', 'F3', 'G3', 'B3', 'D~4', 'F#4',
 'A4', 'C#5', 'E-5', 'F5', 'G5', 'B5', 'D~6', 'F#6', 'A6']

Descending form:

>>> [str(p) for p in complexscale.getPitches("C7","C5")]
['A6', 'F#6', 'D~6', 'B5', 'G5', 'F5', 'E-5', 'C#5']

ConcreteScale attributes

Attributes without Documentation: tonic, boundRange

Attributes inherited from Scale: type

Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, hideObjectOnPrint, xPosition, sites, groups, id

ConcreteScale properties

abstract

Return the AbstractScale instance governing this ConcreteScale.

>>> from music21 import *
>>> sc1 = scale.MajorScale('d')
>>> sc2 = scale.MajorScale('b-')
>>> sc1 == sc2
False
>>> sc1.abstract == sc2.abstract
True
chord

Return a Chord object from this harmony over a default range. Use the getChord() method if you need greater control over the parameters of the chord.

isConcrete

Return True if the scale is Concrete, that is, it has a defined Tonic.

>>> from music21 import *
>>> sc1 = scale.MajorScale('c')
>>> sc1.isConcrete
True
>>> sc2 = scale.MajorScale()
>>> sc2.isConcrete
False
name

Return or construct the name of this scale.

>>> from music21 import *
>>> sc = scale.DiatonicScale() # abstract, as no defined tonic
>>> sc.name
'Abstract diatonic'
pitches

Get a default pitch list from this scale.

Properties inherited from Music21Object: classes, fullyQualifiedClasses, activeSite, beat, beatDuration, beatStr, beatStrength, derivationHierarchy, duration, isGrace, measureNumber, offset, priority, seconds

ConcreteScale methods

derive(other, comparisonAttribute='pitchClass')

Return the closest-matching ConcreteScale based on the pitch collection provided as a Stream, a ConcreteScale, or a list of Pitch objects.

How the “closest-matching” scale is defined still needs to be refined and will probably change in the future.

>>> from music21 import *
>>> sc1 = scale.MajorScale()
>>> sc1.derive(['c#', 'e', 'g#'])
<music21.scale.MajorScale B major>

>>> sc1.derive(['e-', 'b-', 'd'], comparisonAttribute='name')
<music21.scale.MajorScale B- major>
deriveAll(other, comparisonAttribute='pitchClass')

Return a list of all Scales of the same class as self where all the pitches in other are contained.

Similar to “deriveRanked” but only returns those scales no matter how many which contain all the pitches.

Just returns a list in order.

If you are working with Diatonic Scales, you will probably want to change the comparisonAttribute to name.

>>> from music21 import *
>>> sc1 = scale.MajorScale()
>>> sc1.deriveAll(['c', 'e', 'b'])
[<music21.scale.MajorScale G major>, <music21.scale.MajorScale C major>]

>>> [sc.name for sc in sc1.deriveAll(['d-', 'e', 'b'])]
['B major', 'A major', 'E major', 'D major', 'C- major']
>>> sc1.deriveAll(['d-', 'e', 'b'], comparisonAttribute='name')
[]

Find all instances of this pentatonic scale in major scales:

>>> scList = sc1.deriveAll(['c#', 'd#', 'f#', 'g#', 'a#'], comparisonAttribute = 'name')
>>> [sc.name for sc in scList]
['B major', 'F# major', 'C# major']
deriveByDegree(degree, pitch)

Given a scale degree and a pitch, return a new ConcreteScale that satisfies that condition.

Find a major scale with C as the 7th degree:

>>> from music21 import *
>>> sc1 = scale.MajorScale()
>>> sc1.deriveByDegree(7, 'c')
<music21.scale.MajorScale D- major>

TODO: Does not yet work for directional scales

deriveRanked(other, resultsReturned=4, comparisonAttribute='pitchClass', removeDuplicates=False)

Return a list of closest-matching ConcreteScale objects based on this AbstractScale, provided as a Stream, a ConcreteScale, or a list of Pitch objects. Returned integer values represent the number of mathces.

If you are working with Diatonic Scales, you will probably want to change the comparisonAttribute to name.

>>> from music21 import *
>>> sc1 = scale.MajorScale()
>>> sc1.deriveRanked(['c', 'e', 'b'])
[(3, <music21.scale.MajorScale G major>), (3, <music21.scale.MajorScale C major>), (2, <music21.scale.MajorScale B major>), (2, <music21.scale.MajorScale A major>)]
>>> sc1.deriveRanked(['d-', 'e', 'b'])
[(3, <music21.scale.MajorScale B major>), (3, <music21.scale.MajorScale A major>), (3, <music21.scale.MajorScale E major>), (3, <music21.scale.MajorScale D major>)]
>>> sc1.deriveRanked(['d-', 'e', 'b'], comparisonAttribute='name')
[(2, <music21.scale.MajorScale B major>), (2, <music21.scale.MajorScale A major>), (2, <music21.scale.MajorScale G major>), (2, <music21.scale.MajorScale E major>)]

>>> sc1.deriveRanked(['c', 'e', 'e', 'e', 'b'])
[(5, <music21.scale.MajorScale G major>), (5, <music21.scale.MajorScale C major>), (4, <music21.scale.MajorScale B major>), (4, <music21.scale.MajorScale A major>)]
>>> sc1.deriveRanked(['c#', 'e', 'g#'])
[(3, <music21.scale.MajorScale B major>), (3, <music21.scale.MajorScale A major>), (3, <music21.scale.MajorScale E major>), (3, <music21.scale.MajorScale C- major>)]

Test that a Concrete Scale (that is, with no _abstract defined) still has similar characteristics to the original.

Create a scale like a Harmonic minor but with flat 2 and sharp 4

>>> e = scale.ConcreteScale(pitches=['A4', 'B-4', 'C5', 'D#5', 'E5', 'F5', 'G#5', 'A5'])
>>> f = e.deriveRanked(['C','E','G'])
>>> f
[(3, <music21.scale.ConcreteScale E Concrete>), (3, <music21.scale.ConcreteScale D- Concrete>), (3, <music21.scale.ConcreteScale C# Concrete>), (2, <music21.scale.ConcreteScale B Concrete>)]
>>> ' '.join([str(p) for p in f[0][1].pitches])
'E4 F4 G4 A#4 B4 C5 D#5 E5'
findMissing(other, comparisonAttribute='pitchClass', minPitch=None, maxPitch=None, direction='ascending', alteredDegrees={})

Given another object of the forms that extractPitches takes (e.g., a Stream, a ConcreteScale, a list of Pitch objects), return a list of pitches that are found in this Scale but are not found in the provided object.

>>> from music21 import *
>>> sc1 = scale.MajorScale('g4')
>>> [str(p) for p in sc1.findMissing(['d'])]
['G4', 'A4', 'B4', 'C5', 'E5', 'F#5', 'G5']
getChord(minPitch=None, maxPitch=None, direction='ascending', **keywords)

Return a realized chord containing all the pitches in this scale within a particular inclusive range defined by two pitches.

All keyword arguments are passed on to the Chord, permitting specification of quarterLength and similar parameters.

getDegreeMaxUnique()

Convenience routine to get this from the AbstractScale.

getPitches(minPitch=None, maxPitch=None, direction=None)

Return a list of Pitch objects, using a deepcopy of a cached version if available.

getScalaStorage()

Return a configured ScalaStorage Object for this scale. It can be used to find interval distances in cents between degrees.

getScaleDegreeAndAccidentalFromPitch(pitchTarget, direction='ascending', comparisonAttribute='name')

Given a scale (or Key object) and a pitch, return a two-element tuple of the degree of the scale and an accidental (or None) needed to get this pitch.

>>> from music21 import *
>>> cmaj = key.Key('C')
>>> cmaj.getScaleDegreeAndAccidentalFromPitch(pitch.Pitch('E'))
(3, None)
>>> cmaj.getScaleDegreeAndAccidentalFromPitch(pitch.Pitch('E-'))
(3, <accidental flat>)

The Direction of a melodic minor scale is significant

>>> amin = scale.MelodicMinorScale('a')
>>> amin.getScaleDegreeAndAccidentalFromPitch(pitch.Pitch('G'), direction=scale.DIRECTION_DESCENDING)
(7, None)
>>> amin.getScaleDegreeAndAccidentalFromPitch(pitch.Pitch('G'), direction=scale.DIRECTION_ASCENDING)
(7, <accidental flat>)
>>> amin.getScaleDegreeAndAccidentalFromPitch(pitch.Pitch('G-'), direction=scale.DIRECTION_ASCENDING)
(7, <accidental double-flat>)

Returns (None, None) if for some reason this scale does not have this step (a whole-tone scale, for instance)

getScaleDegreeFromPitch(pitchTarget, direction='ascending', comparisonAttribute='name')

For a given pitch, return the appropriate scale degree. If no scale degree is available, None is returned.

Note – by default it will find based on note name not on PitchClass because this is used so commonly by tonal functions. So if it’s important that D# and E- are the same, set the comparisonAttribute to pitchClass

>>> from music21 import *
>>> sc = scale.MajorScale('e-')
>>> sc.getScaleDegreeFromPitch('e-2')
1
>>> sc.getScaleDegreeFromPitch('d')
7
>>> sc.getScaleDegreeFromPitch('d#', comparisonAttribute='name') is None
True
>>> sc.getScaleDegreeFromPitch('d#', comparisonAttribute='pitchClass')
1
>>> sc.getScaleDegreeFromPitch('e') == None
True
>>> sc.getScaleDegreeFromPitch('e', comparisonAttribute='step')
1
>>> sc = scale.HarmonicMinorScale('a')
>>> sc.getScaleDegreeFromPitch('c')
3
>>> sc.getScaleDegreeFromPitch('g#')
7
>>> sc.getScaleDegreeFromPitch('g') is None
True
>>> cmaj = key.Key('C')
>>> cmaj.getScaleDegreeFromPitch(pitch.Pitch('E-'), direction=scale.DIRECTION_ASCENDING, comparisonAttribute = 'step')
3
getTonic()

Return the tonic.

>>> from music21 import *
>>> sc = scale.ConcreteScale(tonic = 'e-4')
>>> sc.getTonic()
<music21.pitch.Pitch E-4>
intervalBetweenDegrees(degreeStart, degreeEnd, direction='ascending', equateTermini=True)

Given two degrees, provide the interval as an interval.Interval object.

>>> from music21 import *
>>> sc = scale.MajorScale('e-')
>>> sc.intervalBetweenDegrees(3, 7)
<music21.interval.Interval P5>
isNext(other, pitchOrigin, direction='ascending', stepSize=1, getNeighbor=True, comparisonAttribute='name')

Given another pitch, as well as an origin and a direction, determine if this other pitch is in the next in the scale.

>>> from music21 import *
>>> sc1 = scale.MajorScale('g')
>>> sc1.isNext('d4', 'c4', 'ascending')
True
match(other, comparisonAttribute='name')

Given another object of the forms that extractPitchList can take, (e.g., a Stream, a ConcreteScale, a list of Pitch objects), return a named dictionary of pitch lists with keys ‘matched’ and ‘notMatched’.

>>> from music21 import *
>>> sc1 = scale.MajorScale('g')
>>> sc2 = scale.MajorScale('d')
>>> sc3 = scale.MajorScale('a')
>>> sc4 = scale.MajorScale('e')
>>> sc1.match(sc2)
{'notMatched': [<music21.pitch.Pitch C#5>],
 'matched': [<music21.pitch.Pitch D4>, <music21.pitch.Pitch E4>,
             <music21.pitch.Pitch F#4>, <music21.pitch.Pitch G4>,
             <music21.pitch.Pitch A4>, <music21.pitch.Pitch B4>]}

>>> sc2.match(sc3)
{'notMatched': [<music21.pitch.Pitch G#5>],
 'matched': [<music21.pitch.Pitch A4>, <music21.pitch.Pitch B4>,
             <music21.pitch.Pitch C#5>, <music21.pitch.Pitch D5>,
             <music21.pitch.Pitch E5>, <music21.pitch.Pitch F#5>]}
>>> sc1.match(sc4)
{'notMatched': [<music21.pitch.Pitch G#4>,
                <music21.pitch.Pitch C#5>,
                <music21.pitch.Pitch D#5>],
 'matched': [<music21.pitch.Pitch E4>, <music21.pitch.Pitch F#4>,
             <music21.pitch.Pitch A4>, <music21.pitch.Pitch B4>]}
next(pitchOrigin=None, direction='ascending', stepSize=1, getNeighbor=True)

Get the next pitch above (or if direction is ‘descending’, below) a pitchOrigin or None. If the pitchOrigin is None, the tonic pitch is returned. This is useful when starting a chain of iterative calls.

The direction attribute may be either ascending or descending. Default is ascending. Optionally, positive or negative integers may be provided as directional stepSize scalars.

An optional stepSize argument can be used to set the number of scale steps that are stepped through. Thus, .next(stepSize=2) will give not the next pitch in the scale, but the next after this one.

The getNeighbor will return a pitch from the scale if pitchOrigin is not in the scale. This value can be True, ‘ascending’, or ‘descending’.

>>> from music21 import *
>>> sc = scale.MajorScale('e-')
>>> print(sc.next('e-5'))
F5
>>> print(sc.next('e-5', stepSize=2))
G5
>>> print(sc.next('e-6', stepSize=3))
A-6

This uses the getNeighbor attribute to find the next note above f#5 in the E-flat major scale:

>>> sc.next('f#5')
<music21.pitch.Pitch G5>
>>> from music21 import *
>>> sc = scale.HarmonicMinorScale('g')
>>> sc.next('g4', 'descending')
<music21.pitch.Pitch F#4>
>>> sc.next('F#4', 'descending')
<music21.pitch.Pitch E-4>
>>> sc.next('E-4', 'descending')
<music21.pitch.Pitch D4>
>>> sc.next('E-4', 'ascending', 1)
<music21.pitch.Pitch F#4>
>>> sc.next('E-4', 'ascending', 2)
<music21.pitch.Pitch G4>
pitchFromDegree(degree, minPitch=None, maxPitch=None, direction='ascending', equateTermini=True)

Given a scale degree, return a deepcopy of the appropriate pitch.

>>> from music21 import *
>>> sc = scale.MajorScale('e-')
>>> sc.pitchFromDegree(2)
<music21.pitch.Pitch F4>
>>> sc.pitchFromDegree(7)
<music21.pitch.Pitch D5>
pitchesFromScaleDegrees(degreeTargets, minPitch=None, maxPitch=None, direction='ascending')

Given one or more scale degrees, return a list of all matches over the entire range.

>>> from music21 import *
>>> sc = scale.MajorScale('e-')
>>> sc.pitchesFromScaleDegrees([3,7])
[<music21.pitch.Pitch G4>, <music21.pitch.Pitch D5>]
>>> [str(p) for p in sc.pitchesFromScaleDegrees([3,7], 'c2', 'c6')]
['D2', 'G2', 'D3', 'G3', 'D4', 'G4', 'D5', 'G5']

>>> sc = scale.HarmonicMinorScale('a')
>>> [str(p) for p in sc.pitchesFromScaleDegrees([3,7], 'c2', 'c6')]
['C2', 'G#2', 'C3', 'G#3', 'C4', 'G#4', 'C5', 'G#5', 'C6']
romanNumeral(degree)

Return a RomanNumeral object built on the specified scale degree.

>>> from music21 import *
>>> sc1 = scale.MajorScale('a-4')
>>> h1 = sc1.romanNumeral(1)
>>> h1.root()
<music21.pitch.Pitch A-4>

>>> h5 = sc1.romanNumeral(5)
>>> h5.root()
<music21.pitch.Pitch E-5>
>>> h5
<music21.roman.RomanNumeral V in A- major>
show(fmt=None, app=None, direction='ascending')

Show the scale in a format. Here, prepare scala format if requested.

solfeg(pitchTarget=None, direction='ascending', variant='music21', chromatic=True)

Returns the chromatic solfege (or diatonic if chromatic is False) for a given pitch in a given scale.

The variant method lets one specify either the default music21 or humdrum solfeg representation for altered notes.

>>> from music21 import *
>>> eflatMaj = key.Key('E-')
>>> eflatMaj.solfeg(pitch.Pitch('G'))
'mi'
>>> eflatMaj.solfeg(pitch.Pitch('A'))
'fi'
>>> eflatMaj.solfeg(pitch.Pitch('A'), chromatic=False)
'fa'
>>> eflatMaj.solfeg(pitch.Pitch('G#'), variant='music21') #default
'mis'
>>> eflatMaj.solfeg(pitch.Pitch('G#'), variant='humdrum')
'my'
transpose(value, inPlace=False)

Transpose this Scale by the given interval

note: it does not makes sense to transpose an abstract scale; thus, only concrete scales can be transposed.

>>> from music21 import *
>>> sc1 = scale.MajorScale('C')
>>> sc2 = sc1.transpose('p5')
>>> sc2
<music21.scale.MajorScale G major>
>>> sc3 = sc2.transpose('p5')
>>> sc3
<music21.scale.MajorScale D major>
tune(streamObj, minPitch=None, maxPitch=None, direction=None)

Given a Stream object containing Pitches, match all pitch names and or pitch space values and replace the target pitch with copies of pitches stored in this scale.

This is always applied recursively to all sub-Streams.

write(fmt=None, fp=None, direction='ascending')

Write the scale in a format. Here, prepare scala format if requested.

Methods inherited from Scale: extractPitchList()

Methods inherited from Music21Object: findAttributeInHierarchy(), getContextAttr(), setContextAttr(), addContext(), addLocation(), getAllContextsByClass(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), previous(), purgeLocations(), purgeOrphans(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unwrapWeakref(), wrapWeakref()

AbstractScale

Inherits from: Scale, Music21Object

class music21.scale.AbstractScale

An abstract scale is specific scale formation, but does not have a defined pitch collection or pitch reference. For example, all Major scales can be represented by an AbstractScale; a ConcreteScale, however, is a specific Major Scale, such as G Major.

These classes provide an interface to, and create and manipulate, the stored BoundIntervalNetwork object. Thus, they are rarely created or manipulated directly by most users.

The AbstractScale additionally stores an _alteredDegrees dictionary. Subclasses can define altered nodes in AbstractScale that are passed to the BoundIntervalNetwork.

AbstractScale attributes

Attributes without Documentation: octaveDuplicating, deterministic, tonicDegree

Attributes inherited from Scale: type

Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, hideObjectOnPrint, xPosition, sites, groups, id

AbstractScale properties

networkxGraph

Return a networks Graph object representing a realized version of this BoundIntervalNetwork.

Properties inherited from Scale: isConcrete, name

Properties inherited from Music21Object: classes, fullyQualifiedClasses, activeSite, beat, beatDuration, beatStr, beatStrength, derivationHierarchy, duration, isGrace, measureNumber, offset, priority, seconds

AbstractScale methods

buildNetworkFromPitches(pitchList)

Builds the network (list of motions) for an abstract scale from a list of pitch.Pitch objects. If the concluding note (usually the “octave”) is not given, then it’ll be created automatically.

Here we treat the augmented triad as a scale:

>>> from music21 import *
>>> p1 = pitch.Pitch("C4")
>>> p2 = pitch.Pitch("E4")
>>> p3 = pitch.Pitch("G#4")
>>> absc = scale.AbstractScale()
>>> absc.buildNetworkFromPitches([p1, p2, p3])
>>> absc.octaveDuplicating
True
>>> absc._net
<music21.intervalNetwork.BoundIntervalNetwork object at 0x...>

Now see it return a new “scale” of the augmentedTriad on D5

>>> absc._net.realizePitch('D5')
[<music21.pitch.Pitch D5>, <music21.pitch.Pitch F#5>,
 <music21.pitch.Pitch A#5>, <music21.pitch.Pitch D6>]
fixDefaultOctaveForPitchList(pitchList)

Suppose you have a set of octaveless Pitches that you use to make a scale.

Something like:

>>> from music21 import *
>>> pitchListStrs = "a b c d e f g a".split()
>>> pitchList = [pitch.Pitch(p) for p in pitchListStrs]

Here’s the problem, between pitchList[1] and pitchList[2] the .implicitOctave stays the same, so the .ps drops:

>>> (pitchList[1].implicitOctave, pitchList[2].implicitOctave)
(4, 4)
>>> (pitchList[1].ps, pitchList[2].ps)
(71.0, 60.0)

Hence this helper method that makes it so that for octaveless pitches ONLY, each one has a .ps above the previous:

>>> sc = scale.AbstractScale()
>>> pitchList2 = sc.fixDefaultOctaveForPitchList(pitchList)
>>> (pitchList2[1].implicitOctave, pitchList2[2].implicitOctave, pitchList2[3].implicitOctave)
(4, 5, 5)
>>> (pitchList2[1].ps, pitchList2[2].ps)
(71.0, 72.0)

Note that the list is modified inPlace:

>>> pitchList is pitchList2
True
>>> pitchList[2] is pitchList2[2]
True
getDegreeMaxUnique()

Return the maximum number of scale steps, or the number to use as a modulus.

getIntervals(stepOfPitch=None, minPitch=None, maxPitch=None, direction='ascending', reverse=False)

Realize the abstract scale as a list of pitch objects, given a pitch object, the step of that pitch object, and a min and max pitch.

getNewTonicPitch(pitchReference, nodeName, direction='ascending', minPitch=None, maxPitch=None)

Define a pitch target and a node.

getPitchFromNodeDegree(pitchReference, nodeName, nodeDegreeTarget, direction='ascending', minPitch=None, maxPitch=None, equateTermini=True)

Get a pitch for desired scale degree.

getRealization(pitchObj, stepOfPitch, minPitch=None, maxPitch=None, direction='ascending', reverse=False)

Realize the abstract scale as a list of pitch objects, given a pitch object, the step of that pitch object, and a min and max pitch.

getRelativeNodeDegree(pitchReference, nodeName, pitchTarget, comparisonAttribute='pitchClass', direction='ascending')

Expose functionality from BoundIntervalNetwork, passing on the stored alteredDegrees dictionary.

getScalaStorage(direction='ascending')

Get the interval sequence as a :class:~music21.scala.ScalaStorage object for a particular scale:

nextPitch(pitchReference, nodeName, pitchOrigin, direction='ascending', stepSize=1, getNeighbor=True)

Expose functionality from BoundIntervalNetwork, passing on the stored alteredDegrees dictionary.

plot(*args, **keywords)

Create and display a plot.

realizePitchByDegree(pitchReference, nodeId, nodeDegreeTargets, direction='ascending', minPitch=None, maxPitch=None)

Given one or more scale degrees, return a list of all matches over the entire range. See realizePitchByDegree(). in intervalNetwork.BoundIntervalNetwork.

Create an abstract pentatonic scale:

>>> from music21 import *
>>> pitchList = ["C#4","D#4","F#4","G#4","A#4"]
>>> absc = scale.AbstractScale()
>>> absc.buildNetworkFromPitches([pitch.Pitch(p) for p in pitchList])
show(fmt=None, app=None, direction='ascending')

Show the scale in a format. Here, prepare scala format if requested.

write(fmt=None, fp=None, direction='ascending')

Write the scale in a format. Here, prepare scala format if requested.

Methods inherited from Scale: extractPitchList()

Methods inherited from Music21Object: findAttributeInHierarchy(), getContextAttr(), setContextAttr(), addContext(), addLocation(), getAllContextsByClass(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeLocations(), purgeOrphans(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unwrapWeakref(), wrapWeakref()

AbstractCyclicalScale

Inherits from: AbstractScale, Scale, Music21Object

class music21.scale.AbstractCyclicalScale(mode=None)

A scale of any size built with an interval list of any form. The resulting scale may be non octave repeating.

AbstractDiatonicScale

Inherits from: AbstractScale, Scale, Music21Object

class music21.scale.AbstractDiatonicScale(mode=None)

AbstractDiatonicScale attributes

Attributes without Documentation: relativeMinorDegree, relativeMajorDegree, dominantDegree

Attributes inherited from AbstractScale: octaveDuplicating, deterministic, tonicDegree

Attributes inherited from Scale: type

Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, xPosition, id, sites, groups, hideObjectOnPrint

AbstractDiatonicScale properties

AbstractDiatonicScale methods

Methods inherited from AbstractScale: buildNetworkFromPitches(), fixDefaultOctaveForPitchList(), getDegreeMaxUnique(), getIntervals(), getNewTonicPitch(), getPitchFromNodeDegree(), getRealization(), getRelativeNodeDegree(), getScalaStorage(), nextPitch(), plot(), realizePitchByDegree(), show(), write()

Methods inherited from Scale: extractPitchList()

Methods inherited from Music21Object: findAttributeInHierarchy(), getContextAttr(), setContextAttr(), addContext(), addLocation(), getAllContextsByClass(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeLocations(), purgeOrphans(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unwrapWeakref(), wrapWeakref()

AbstractHarmonicMinorScale

Inherits from: AbstractScale, Scale, Music21Object

class music21.scale.AbstractHarmonicMinorScale(mode=None)

A true bi-directional scale that with the augmented second to a leading tone.

This is the only scale to use the “_alteredDegrees” property.

AbstractHarmonicMinorScale attributes

Attributes without Documentation: dominantDegree

Attributes inherited from AbstractScale: octaveDuplicating, deterministic, tonicDegree

Attributes inherited from Scale: type

Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, hideObjectOnPrint, xPosition, sites, groups, id

AbstractHarmonicMinorScale properties

AbstractHarmonicMinorScale methods

Methods inherited from AbstractScale: buildNetworkFromPitches(), fixDefaultOctaveForPitchList(), getDegreeMaxUnique(), getIntervals(), getNewTonicPitch(), getPitchFromNodeDegree(), getRealization(), getRelativeNodeDegree(), getScalaStorage(), nextPitch(), plot(), realizePitchByDegree(), show(), write()

Methods inherited from Scale: extractPitchList()

Methods inherited from Music21Object: findAttributeInHierarchy(), getContextAttr(), setContextAttr(), addContext(), addLocation(), getAllContextsByClass(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeLocations(), purgeOrphans(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unwrapWeakref(), wrapWeakref()

AbstractMelodicMinorScale

Inherits from: AbstractScale, Scale, Music21Object

class music21.scale.AbstractMelodicMinorScale(mode=None)

A directional scale.

AbstractMelodicMinorScale attributes

Attributes without Documentation: dominantDegree

Attributes inherited from AbstractScale: octaveDuplicating, deterministic, tonicDegree

Attributes inherited from Scale: type

Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, hideObjectOnPrint, xPosition, sites, groups, id

AbstractMelodicMinorScale properties

AbstractMelodicMinorScale methods

Methods inherited from AbstractScale: buildNetworkFromPitches(), fixDefaultOctaveForPitchList(), getDegreeMaxUnique(), getIntervals(), getNewTonicPitch(), getPitchFromNodeDegree(), getRealization(), getRelativeNodeDegree(), getScalaStorage(), nextPitch(), plot(), realizePitchByDegree(), show(), write()

Methods inherited from Scale: extractPitchList()

Methods inherited from Music21Object: findAttributeInHierarchy(), getContextAttr(), setContextAttr(), addContext(), addLocation(), getAllContextsByClass(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeLocations(), purgeOrphans(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unwrapWeakref(), wrapWeakref()

AbstractOctatonicScale

Inherits from: AbstractScale, Scale, Music21Object

class music21.scale.AbstractOctatonicScale(mode=None)

Abstract scale representing the two octatonic scales.

AbstractOctaveRepeatingScale

Inherits from: AbstractScale, Scale, Music21Object

class music21.scale.AbstractOctaveRepeatingScale(mode=None)

A scale of any size built with an interval list that assumes octave completion. An additional interval to complete the octave will be added to the provided intervals. This does not guarantee that the octave will be repeated in one octave, only the next octave above the last interval will be provided.

AbstractRagAsawari

Inherits from: AbstractScale, Scale, Music21Object

class music21.scale.AbstractRagAsawari

A pseudo raga-scale.

AbstractRagAsawari attributes

Attributes without Documentation: dominantDegree

Attributes inherited from AbstractScale: octaveDuplicating, deterministic, tonicDegree

Attributes inherited from Scale: type

Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, hideObjectOnPrint, xPosition, sites, groups, id

AbstractRagAsawari properties

AbstractRagAsawari methods

Methods inherited from AbstractScale: buildNetworkFromPitches(), fixDefaultOctaveForPitchList(), getDegreeMaxUnique(), getIntervals(), getNewTonicPitch(), getPitchFromNodeDegree(), getRealization(), getRelativeNodeDegree(), getScalaStorage(), nextPitch(), plot(), realizePitchByDegree(), show(), write()

Methods inherited from Scale: extractPitchList()

Methods inherited from Music21Object: findAttributeInHierarchy(), getContextAttr(), setContextAttr(), addContext(), addLocation(), getAllContextsByClass(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeLocations(), purgeOrphans(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unwrapWeakref(), wrapWeakref()

AbstractRagMarwa

Inherits from: AbstractScale, Scale, Music21Object

class music21.scale.AbstractRagMarwa

A pseudo raga-scale.

AbstractRagMarwa attributes

Attributes without Documentation: dominantDegree

Attributes inherited from AbstractScale: octaveDuplicating, deterministic, tonicDegree

Attributes inherited from Scale: type

Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, hideObjectOnPrint, xPosition, sites, groups, id

AbstractRagMarwa properties

AbstractRagMarwa methods

Methods inherited from AbstractScale: buildNetworkFromPitches(), fixDefaultOctaveForPitchList(), getDegreeMaxUnique(), getIntervals(), getNewTonicPitch(), getPitchFromNodeDegree(), getRealization(), getRelativeNodeDegree(), getScalaStorage(), nextPitch(), plot(), realizePitchByDegree(), show(), write()

Methods inherited from Scale: extractPitchList()

Methods inherited from Music21Object: findAttributeInHierarchy(), getContextAttr(), setContextAttr(), addContext(), addLocation(), getAllContextsByClass(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeLocations(), purgeOrphans(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unwrapWeakref(), wrapWeakref()

AbstractWeightedHexatonicBlues

Inherits from: AbstractScale, Scale, Music21Object

class music21.scale.AbstractWeightedHexatonicBlues

A dynamic, probabilistic mixture of minor pentatonic and a hexatonic blues scale

AbstractWeightedHexatonicBlues attributes

Attributes without Documentation: dominantDegree

Attributes inherited from AbstractScale: octaveDuplicating, deterministic, tonicDegree

Attributes inherited from Scale: type

Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, hideObjectOnPrint, xPosition, sites, groups, id

AbstractWeightedHexatonicBlues properties

AbstractWeightedHexatonicBlues methods

Methods inherited from AbstractScale: buildNetworkFromPitches(), fixDefaultOctaveForPitchList(), getDegreeMaxUnique(), getIntervals(), getNewTonicPitch(), getPitchFromNodeDegree(), getRealization(), getRelativeNodeDegree(), getScalaStorage(), nextPitch(), plot(), realizePitchByDegree(), show(), write()

Methods inherited from Scale: extractPitchList()

Methods inherited from Music21Object: findAttributeInHierarchy(), getContextAttr(), setContextAttr(), addContext(), addLocation(), getAllContextsByClass(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeLocations(), purgeOrphans(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unwrapWeakref(), wrapWeakref()

ChromaticScale

Inherits from: ConcreteScale, Scale, Music21Object

class music21.scale.ChromaticScale(tonic=None)

A concrete cyclical scale, based on a cycle of half steps. These intervals do not have to be octave completing, and thus may produce scales that do no

>>> from music21 import *
>>> sc = scale.ChromaticScale('g2')
>>> [str(p) for p in sc.pitches]
['G2', 'A-2', 'A2', 'B-2', 'B2', 'C3', 'C#3', 'D3', 'E-3', 'E3', 'F3', 'F#3', 'G3']
>>> [str(p) for p in sc.getPitches('g2', 'g6')]
['G2', 'A-2', ..., 'F#3', 'G3', 'A-3', ..., 'F#4', 'G4', 'A-4', ..., 'G5', ..., 'F#6', 'G6']
>>> sc.abstract.getDegreeMaxUnique()
12
>>> sc.pitchFromDegree(1)
<music21.pitch.Pitch G2>
>>> sc.pitchFromDegree(2)
<music21.pitch.Pitch A-2>
>>> sc.pitchFromDegree(3)
<music21.pitch.Pitch A2>
>>> sc.pitchFromDegree(8)
<music21.pitch.Pitch D3>
>>> sc.pitchFromDegree(12)
<music21.pitch.Pitch F#3>
>>> sc.getScaleDegreeFromPitch('g2', comparisonAttribute='pitchClass')
1
>>> sc.getScaleDegreeFromPitch('F#6', comparisonAttribute='pitchClass')
12

CyclicalScale

Inherits from: ConcreteScale, Scale, Music21Object

class music21.scale.CyclicalScale(tonic=None, intervalList=['m2'])

A concrete cyclical scale, based on a cycle of intervals. These intervals do not have to be octave completing, and thus may produce scales that do no

>>> from music21 import *
>>> sc = scale.CyclicalScale('c4', 'p5') # can give one list
>>> sc.pitches
[<music21.pitch.Pitch C4>, <music21.pitch.Pitch G4>]
>>> [str(p) for p in sc.getPitches('g2', 'g6')]
['B-2', 'F3', 'C4', 'G4', 'D5', 'A5', 'E6']
>>> sc.getScaleDegreeFromPitch('g4') # as single interval cycle, all are 1
1
>>> sc.getScaleDegreeFromPitch('b-2', direction='bi')
1

DiatonicScale

Inherits from: ConcreteScale, Scale, Music21Object

class music21.scale.DiatonicScale(tonic=None)

A concrete diatonic scale. Each DiatonicScale has one instance of a AbstractDiatonicScale.

DiatonicScale attributes

Attributes inherited from ConcreteScale: tonic, boundRange

Attributes inherited from Scale: type

Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, hideObjectOnPrint, xPosition, sites, groups, id

DiatonicScale properties

DiatonicScale methods

getDominant()

Return the dominant.

>>> from music21 import *
>>> sc = scale.MajorScale('e-')
>>> sc.getDominant()
<music21.pitch.Pitch B-4>
>>> sc = scale.MajorScale('F#')
>>> sc.getDominant()
<music21.pitch.Pitch C#5>
getLeadingTone()

Return the leading tone.

>>> from music21 import *
>>> sc = scale.MinorScale('c')
>>> sc.getLeadingTone()
<music21.pitch.Pitch B4>

Note that the leading tone isn’t necessarily the same as the 7th scale degree in minor:

>>> sc.pitchFromDegree(7)
<music21.pitch.Pitch B-4>
getParallelMajor()

Return a concrete relative major scale

>>> from music21 import *
>>> sc1 = scale.MinorScale(pitch.Pitch('g'))
>>> [str(p) for p in sc1.pitches]
['G4', 'A4', 'B-4', 'C5', 'D5', 'E-5', 'F5', 'G5']

>>> sc2 = sc1.getParallelMajor()
>>> [str(p) for p in sc2.pitches]
['G4', 'A4', 'B4', 'C5', 'D5', 'E5', 'F#5', 'G5']
getParallelMinor()

Return a parallel minor scale based on this concrete scale.

>>> from music21 import *
>>> sc1 = scale.MajorScale(pitch.Pitch('a'))
>>> [str(p) for p in sc1.pitches]
['A4', 'B4', 'C#5', 'D5', 'E5', 'F#5', 'G#5', 'A5']
>>> sc2 = sc1.getParallelMinor()
>>> [str(p) for p in sc2.pitches]
['A4', 'B4', 'C5', 'D5', 'E5', 'F5', 'G5', 'A5']

Running getParallelMinor() again doesn’t change anything

>>> sc3 = sc2.getParallelMinor()
>>> [str(p) for p in sc3.pitches]
['A4', 'B4', 'C5', 'D5', 'E5', 'F5', 'G5', 'A5']
getRelativeMajor()

Return a concrete relative major scale

>>> from music21 import *

>>> sc1 = scale.MinorScale(pitch.Pitch('g'))
>>> [str(p) for p in sc1.pitches]
['G4', 'A4', 'B-4', 'C5', 'D5', 'E-5', 'F5', 'G5']
>>> sc2 = sc1.getRelativeMajor()
>>> [str(p) for p in sc2.pitches]
['B-4', 'C5', 'D5', 'E-5', 'F5', 'G5', 'A5', 'B-5']

Though it’s unlikely you would want to do it, getRelativeMajor works on other diatonic scales than just Major and Minor.

>>> sc2 = scale.DorianScale('d')
>>> [str(p) for p in sc2.pitches]
['D4', 'E4', 'F4', 'G4', 'A4', 'B4', 'C5', 'D5']

>>> [str(p) for p in sc2.getRelativeMajor().pitches]
['C5', 'D5', 'E5', 'F5', 'G5', 'A5', 'B5', 'C6']
getRelativeMinor()

Return a relative minor scale based on this concrete scale.

>>> from music21 import *
>>> sc1 = scale.MajorScale(pitch.Pitch('a'))
>>> [str(p) for p in sc1.pitches]
['A4', 'B4', 'C#5', 'D5', 'E5', 'F#5', 'G#5', 'A5']
>>> sc2 = sc1.getRelativeMinor()
>>> [str(p) for p in sc2.pitches]
['F#5', 'G#5', 'A5', 'B5', 'C#6', 'D6', 'E6', 'F#6']
getTonic()

Return the tonic of the diatonic scale.

>>> from music21 import *
>>> sc = scale.MajorScale('e-')
>>> sc.getTonic()
<music21.pitch.Pitch E-4>
>>> sc = scale.MajorScale('F#')
>>> sc.getTonic()
<music21.pitch.Pitch F#4>

If no tonic has been defined, it will return an Exception. (same is true for getDominant, getLeadingTone, etc.)

>>> sc = scale.DiatonicScale()
>>> sc.getTonic()
Traceback (most recent call last):
IntervalNetworkException: pitchReference cannot be None

Methods inherited from ConcreteScale: derive(), deriveAll(), deriveByDegree(), deriveRanked(), findMissing(), getChord(), getDegreeMaxUnique(), getPitches(), getScalaStorage(), getScaleDegreeAndAccidentalFromPitch(), getScaleDegreeFromPitch(), intervalBetweenDegrees(), isNext(), match(), next(), pitchFromDegree(), pitchesFromScaleDegrees(), romanNumeral(), show(), solfeg(), transpose(), tune(), write()

Methods inherited from Scale: extractPitchList()

Methods inherited from Music21Object: findAttributeInHierarchy(), getContextAttr(), setContextAttr(), addContext(), addLocation(), getAllContextsByClass(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), previous(), purgeLocations(), purgeOrphans(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unwrapWeakref(), wrapWeakref()

DorianScale

Inherits from: DiatonicScale, ConcreteScale, Scale, Music21Object

class music21.scale.DorianScale(tonic=None)

A natural minor scale, or the Aeolian mode.

>>> sc = DorianScale(pitch.Pitch('d'))
>>> [str(p) for p in sc.pitches]
['D4', 'E4', 'F4', 'G4', 'A4', 'B4', 'C5', 'D5']

HarmonicMinorScale

Inherits from: DiatonicScale, ConcreteScale, Scale, Music21Object

class music21.scale.HarmonicMinorScale(tonic=None)

A harmonic minor scale

>>> sc = HarmonicMinorScale('e4')
>>> [str(p) for p in sc.pitches]
['E4', 'F#4', 'G4', 'A4', 'B4', 'C5', 'D#5', 'E5']
>>> sc.getTonic()
<music21.pitch.Pitch E4>
>>> sc.getDominant()
<music21.pitch.Pitch B4>
>>> sc.pitchFromDegree(1) # scale degree 1 is treated as lowest
<music21.pitch.Pitch E4>

>>> sc = HarmonicMinorScale()
>>> sc.deriveRanked(['C', 'E', 'G'], comparisonAttribute='name')
[(3, <music21.scale.HarmonicMinorScale F harmonic minor>), (3, <music21.scale.HarmonicMinorScale E harmonic minor>), (2, <music21.scale.HarmonicMinorScale B harmonic minor>), (2, <music21.scale.HarmonicMinorScale A harmonic minor>)]

HypoaeolianScale

Inherits from: DiatonicScale, ConcreteScale, Scale, Music21Object

class music21.scale.HypoaeolianScale(tonic=None)

A hypoaeolian scale

>>> sc = HypoaeolianScale(pitch.Pitch('a'))
>>> [str(p) for p in sc.pitches]
['E4', 'F4', 'G4', 'A4', 'B4', 'C5', 'D5', 'E5']

>>> sc = HypoaeolianScale(pitch.Pitch('c'))
>>> [str(p) for p in sc.pitches]
['G3', 'A-3', 'B-3', 'C4', 'D4', 'E-4', 'F4', 'G4']

HypodorianScale

Inherits from: DiatonicScale, ConcreteScale, Scale, Music21Object

class music21.scale.HypodorianScale(tonic=None)

A hypodorian scale

>>> sc = HypodorianScale(pitch.Pitch('d'))
>>> [str(p) for p in sc.pitches]
['A3', 'B3', 'C4', 'D4', 'E4', 'F4', 'G4', 'A4']
>>> sc = HypodorianScale(pitch.Pitch('c'))
>>> [str(p) for p in sc.pitches]
['G3', 'A3', 'B-3', 'C4', 'D4', 'E-4', 'F4', 'G4']

HypolocrianScale

Inherits from: DiatonicScale, ConcreteScale, Scale, Music21Object

class music21.scale.HypolocrianScale(tonic=None)

A hypolocrian scale

>>> sc = HypolocrianScale(pitch.Pitch('b'))
>>> [str(p) for p in sc.pitches]
['F4', 'G4', 'A4', 'B4', 'C5', 'D5', 'E5', 'F5']

>>> sc = HypolocrianScale(pitch.Pitch('c'))
>>> [str(p) for p in sc.pitches]
['G-3', 'A-3', 'B-3', 'C4', 'D-4', 'E-4', 'F4', 'G-4']

HypolydianScale

Inherits from: DiatonicScale, ConcreteScale, Scale, Music21Object

class music21.scale.HypolydianScale(tonic=None)

A hypolydian scale

>>> sc = HypolydianScale(pitch.Pitch('f'))
>>> [str(p) for p in sc.pitches]
['C4', 'D4', 'E4', 'F4', 'G4', 'A4', 'B4', 'C5']
>>> sc = HypolydianScale(pitch.Pitch('c'))
>>> [str(p) for p in sc.pitches]
['G3', 'A3', 'B3', 'C4', 'D4', 'E4', 'F#4', 'G4']

HypomixolydianScale

Inherits from: DiatonicScale, ConcreteScale, Scale, Music21Object

class music21.scale.HypomixolydianScale(tonic=None)

A hypolydian scale

>>> sc = HypomixolydianScale(pitch.Pitch('g'))
>>> [str(p) for p in sc.pitches]
['D4', 'E4', 'F4', 'G4', 'A4', 'B4', 'C5', 'D5']
>>> sc = HypomixolydianScale(pitch.Pitch('c'))
>>> [str(p) for p in sc.pitches]
['G3', 'A3', 'B-3', 'C4', 'D4', 'E4', 'F4', 'G4']

HypophrygianScale

Inherits from: DiatonicScale, ConcreteScale, Scale, Music21Object

class music21.scale.HypophrygianScale(tonic=None)

A hypophrygian scale

>>> sc = HypophrygianScale(pitch.Pitch('e'))
>>> sc.abstract.octaveDuplicating
True
>>> [str(p) for p in sc.pitches]
['B3', 'C4', 'D4', 'E4', 'F4', 'G4', 'A4', 'B4']
>>> sc.getTonic()
<music21.pitch.Pitch E4>
>>> sc.getDominant()
<music21.pitch.Pitch A4>
>>> sc.pitchFromDegree(1) # scale degree 1 is treated as lowest
<music21.pitch.Pitch B3>

LocrianScale

Inherits from: DiatonicScale, ConcreteScale, Scale, Music21Object

class music21.scale.LocrianScale(tonic=None)

A locrian scale

>>> sc = LocrianScale(pitch.Pitch('b'))
>>> [str(p) for p in sc.pitches]
['B4', 'C5', 'D5', 'E5', 'F5', 'G5', 'A5', 'B5']

>>> sc = LocrianScale(pitch.Pitch('c'))
>>> [str(p) for p in sc.pitches]
['C4', 'D-4', 'E-4', 'F4', 'G-4', 'A-4', 'B-4', 'C5']

LydianScale

Inherits from: DiatonicScale, ConcreteScale, Scale, Music21Object

class music21.scale.LydianScale(tonic=None)

A lydian scale

>>> sc = LydianScale(pitch.Pitch('f'))
>>> [str(p) for p in sc.pitches]
['F4', 'G4', 'A4', 'B4', 'C5', 'D5', 'E5', 'F5']

>>> sc = LydianScale(pitch.Pitch('c'))
>>> [str(p) for p in sc.pitches]
['C4', 'D4', 'E4', 'F#4', 'G4', 'A4', 'B4', 'C5']

MajorScale

Inherits from: DiatonicScale, ConcreteScale, Scale, Music21Object

class music21.scale.MajorScale(tonic=None)

A Major Scale

>>> sc = MajorScale(pitch.Pitch('d'))
>>> sc.pitchFromDegree(7).name
'C#'

MelodicMinorScale

Inherits from: DiatonicScale, ConcreteScale, Scale, Music21Object

class music21.scale.MelodicMinorScale(tonic=None)

A melodic minor scale

>>> sc = MelodicMinorScale('e4')

MinorScale

Inherits from: DiatonicScale, ConcreteScale, Scale, Music21Object

class music21.scale.MinorScale(tonic=None)

A natural minor scale, or the Aeolian mode.

>>> sc = MinorScale(pitch.Pitch('g'))
>>> [str(p) for p in sc.pitches]
['G4', 'A4', 'B-4', 'C5', 'D5', 'E-5', 'F5', 'G5']

MixolydianScale

Inherits from: DiatonicScale, ConcreteScale, Scale, Music21Object

class music21.scale.MixolydianScale(tonic=None)

A mixolydian scale

>>> sc = MixolydianScale(pitch.Pitch('g'))
>>> [str(p) for p in sc.pitches]
['G4', 'A4', 'B4', 'C5', 'D5', 'E5', 'F5', 'G5']

>>> sc = MixolydianScale(pitch.Pitch('c'))
>>> [str(p) for p in sc.pitches]
['C4', 'D4', 'E4', 'F4', 'G4', 'A4', 'B-4', 'C5']

OctatonicScale

Inherits from: ConcreteScale, Scale, Music21Object

class music21.scale.OctatonicScale(tonic=None, mode=None)

A concrete Octatonic scale. Two modes

OctaveRepeatingScale

Inherits from: ConcreteScale, Scale, Music21Object

class music21.scale.OctaveRepeatingScale(tonic=None, intervalList=['m2', <music21.interval.Interval M7>, <music21.interval.Interval P1>])

A concrete cyclical scale, based on a cycle of intervals. These intervals do not have to be octave completing, and thus may produce scales that do no

>>> from music21 import *
>>> sc = scale.OctaveRepeatingScale('c4', ['m3', 'M3']) #
>>> sc.pitches
[<music21.pitch.Pitch C4>, <music21.pitch.Pitch E-4>,
 <music21.pitch.Pitch G4>, <music21.pitch.Pitch C5>]
>>> [str(p) for p in sc.getPitches('g2', 'g6')]
['G2', 'C3', 'E-3', 'G3', 'C4', 'E-4', 'G4', 'C5', 'E-5', 'G5', 'C6', 'E-6', 'G6']
>>> sc.getScaleDegreeFromPitch('c4')
1
>>> sc.getScaleDegreeFromPitch('e-')
2

PhrygianScale

Inherits from: DiatonicScale, ConcreteScale, Scale, Music21Object

class music21.scale.PhrygianScale(tonic=None)

A phrygian scale

>>> sc = PhrygianScale(pitch.Pitch('e'))
>>> [str(p) for p in sc.pitches]
['E4', 'F4', 'G4', 'A4', 'B4', 'C5', 'D5', 'E5']

RagAsawari

Inherits from: ConcreteScale, Scale, Music21Object

class music21.scale.RagAsawari(tonic=None)

A concrete pseudo-raga scale.

>>> from music21 import *
>>> sc = scale.RagAsawari('c2')
>>> [str(p) for p in sc.pitches]
['C2', 'D2', 'F2', 'G2', 'A-2', 'C3']
>>> [str(p) for p in sc.getPitches(direction='descending')]
['C3', 'B-2', 'A-2', 'G2', 'F2', 'E-2', 'D2', 'C2']

RagMarwa

Inherits from: ConcreteScale, Scale, Music21Object

class music21.scale.RagMarwa(tonic=None)

A concrete pseudo-raga scale.

>>> from music21 import *
>>> sc = scale.RagMarwa('c2')

this gets a pitch beyond the terminus b/c of descending form max

>>> [str(p) for p in sc.pitches]
['C2', 'D-2', 'E2', 'F#2', 'A2', 'B2', 'A2', 'C3', 'D-3']

ScalaScale

Inherits from: ConcreteScale, Scale, Music21Object

class music21.scale.ScalaScale(tonic=None, scalaString=None)

A scale created from a Scala scale .scl file. Any file in the Scala archive can be given by name. Additionally, a file path to a Scala .scl file, or a raw string representation, can be used.

>>> sc = ScalaScale('g4', 'mbira banda')
>>> [str(p) for p in sc.pitches]
['G4', 'A4(-15c)', 'B4(-11c)', 'C#5(-7c)', 'D~5(+6c)', 'E5(+14c)', 'F~5(+1c)', 'A-5(+2c)']

if only a single string is given and it’s too long to be a tonic or it ends in .scl, assume it’s the name of a scala scale and set the tonic to C4

>>> sc = ScalaScale('pelog_9')
>>> [str(p) for p in sc.pitches]
['C4', 'D`4(-17c)', 'D~4(+17c)', 'F~4(-17c)', 'G`4(+17c)', 'A-4', 'A~4(-17c)', 'C5']

If no scale with that name can be found then it raises an exception:

>>> sc = ScalaScale('badFileName.scl')
Traceback (most recent call last):
ScaleException: Could not find a file named badFileName.scl in the scala database

ScalaScale attributes

Attributes without Documentation: description

Attributes inherited from ConcreteScale: tonic, boundRange

Attributes inherited from Scale: type

Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, hideObjectOnPrint, xPosition, sites, groups, id

ScalaScale properties

ScalaScale methods

Methods inherited from ConcreteScale: derive(), deriveAll(), deriveByDegree(), deriveRanked(), findMissing(), getChord(), getDegreeMaxUnique(), getPitches(), getScalaStorage(), getScaleDegreeAndAccidentalFromPitch(), getScaleDegreeFromPitch(), getTonic(), intervalBetweenDegrees(), isNext(), match(), next(), pitchFromDegree(), pitchesFromScaleDegrees(), romanNumeral(), show(), solfeg(), transpose(), tune(), write()

Methods inherited from Scale: extractPitchList()

Methods inherited from Music21Object: findAttributeInHierarchy(), getContextAttr(), setContextAttr(), addContext(), addLocation(), getAllContextsByClass(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), previous(), purgeLocations(), purgeOrphans(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unwrapWeakref(), wrapWeakref()

Scale

Inherits from: Music21Object

class music21.scale.Scale

Generic base class for all scales, both abstract and concrete.

Scale attributes

Attributes without Documentation: type

Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, hideObjectOnPrint, xPosition, sites, groups, id

Scale properties

isConcrete

To be concrete, a Scale must have a defined tonic. An abstract Scale is not Concrete, nor is a Concrete scale without a defined tonic.

name

Return or construct the name of this scale.

Properties inherited from Music21Object: classes, fullyQualifiedClasses, activeSite, beat, beatDuration, beatStr, beatStrength, derivationHierarchy, duration, isGrace, measureNumber, offset, priority, seconds

Scale methods

extractPitchList(other, comparisonAttribute='nameWithOctave', removeDuplicates=True)

Utility function:

Given a data format as “other” (a ConcreteScale, Chord, Stream, List of Pitches, or single Pitch), extract all unique Pitches using comparisonAttribute to test for them.

>>> from music21 import *
>>> pStrList = ['A4','D4','E4','F-4','D4','D5', 'A', 'D#4']
>>> pList = [pitch.Pitch(p) for p in pStrList]
>>> nList = [note.Note(p) for p in pStrList]
>>> s = stream.Stream()
>>> for n in nList:
...     s.append(n)
>>> sc = scale.Scale()

Here we only remove the second ‘D4’ because the default comparison is nameWithOctave

>>> [str(p) for p in sc.extractPitchList(pList)]
['A4', 'D4', 'E4', 'F-4', 'D5', 'A', 'D#4']

Now we remove the F-4, D5, and A also because we are working with comparisonAttribute=pitchClass. Note that we’re using a Stream as other now...

>>> [str(p) for p in sc.extractPitchList(s, comparisonAttribute='pitchClass')]
['A4', 'D4', 'E4', 'D#4']

Now let’s get rid of all but one diatonic D by using step() as our comparisonAttribute. Note that we can just give a list of strings as well, and they become Pitch objects:

>>> [str(p) for p in sc.extractPitchList(pStrList, comparisonAttribute='step')]
['A4', 'D4', 'E4', 'F-4']

Methods inherited from Music21Object: findAttributeInHierarchy(), getContextAttr(), setContextAttr(), addContext(), addLocation(), getAllContextsByClass(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeLocations(), purgeOrphans(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unwrapWeakref(), wrapWeakref(), write()

SieveScale

Inherits from: ConcreteScale, Scale, Music21Object

class music21.scale.SieveScale(tonic=None, sieveString='2@0', eld=1)

A scale created from a Xenakis sieve logical string, based on the Sieve object definition. The complete period of the sieve is realized as intervals and used to create a scale.

>>> from music21 import *
>>> sc = scale.SieveScale('c4', '3@0')
>>> sc.pitches
[<music21.pitch.Pitch C4>, <music21.pitch.Pitch E-4>]
>>> sc = scale.SieveScale('d4', '3@0')
>>> sc.pitches
[<music21.pitch.Pitch D4>, <music21.pitch.Pitch F4>]
>>> sc = scale.SieveScale('c2', '(-3@2 & 4) | (-3@1 & 4@1) | (3@2 & 4@2) | (-3 & 4@3)')
>>> [str(p) for p in sc.pitches]
['C2', 'D2', 'E2', 'F2', 'G2', 'A2', 'B2', 'C3']

WeightedHexatonicBlues

Inherits from: ConcreteScale, Scale, Music21Object

class music21.scale.WeightedHexatonicBlues(tonic=None)

A concrete scale based on a dynamic mixture of a minor pentatonic and the hexatonic blues scale.

>>> from music21 import *

WholeToneScale

Inherits from: ConcreteScale, Scale, Music21Object

class music21.scale.WholeToneScale(tonic=None)

A concrete whole-tone scale.

>>> from music21 import *
>>> sc = scale.WholeToneScale('g2')
>>> [str(p) for p in sc.pitches]
['G2', 'A2', 'B2', 'C#3', 'D#3', 'E#3', 'G3']
>>> [str(p) for p in sc.getPitches('g2', 'g5')]
['G2', 'A2', 'B2', 'C#3', 'D#3', 'E#3', 'G3', 'A3', 'B3', 'C#4', 'D#4', 'E#4', 'G4', 'A4', 'B4', 'C#5', 'D#5', 'E#5', 'G5']
>>> sc.abstract.getDegreeMaxUnique()
6
>>> sc.pitchFromDegree(1)
<music21.pitch.Pitch G2>
>>> sc.pitchFromDegree(2)
<music21.pitch.Pitch A2>
>>> sc.pitchFromDegree(6)
<music21.pitch.Pitch E#3>
>>> sc.getScaleDegreeFromPitch('g2', comparisonAttribute='pitchClass')
1
>>> sc.getScaleDegreeFromPitch('F6', comparisonAttribute='pitchClass')
6