Given a list of pitchNames, a bassPitch, and a maxPitch, returns a sorted list of pitches between the two limits (inclusive) which correspond to items in pitchNames.
>>> from music21.figuredBass import segment
>>> from music21 import pitch
>>> segment.getPitches()
[C3, E3, G3, C4, E4, G4, C5, E5, G5, C6, E6, G6, C7, E7, G7, C8]
>>> segment.getPitches(['G', 'B', 'D', 'F'], bassPitch = pitch.Pitch('B2'))
[B2, D3, F3, G3, B3, D4, F4, G4, B4, D5, F5, G5, B5, D6, F6, G6, B6, D7, F7, G7, B7]
>>> segment.getPitches(['F##','A#','C#'], bassPitch = pitch.Pitch('A#3'))
[A#3, C#4, F##4, A#4, C#5, F##5, A#5, C#6, F##6, A#6, C#7, F##7, A#7]
Method which can print to the console rules inputted into singlePossibilityRules(), consecutivePossibilityRules(), and specialResolutionRules(). For the first two methods, maxLength is 4. For the third method, maxLength is 3.
Inherits from: Segment
Class to allow Segments to be overlayed with non-chord notes.
A Segment corresponds to a 1:1 realization of a bassNote and notationString of a FiguredBassLine. It is created by passing six arguments: a FiguredBassScale, a bassNote, a notationString, a Rules object, a number of parts and a maximum pitch. Realizations of a Segment are represented as possibility tuples (see possibility for more details).
Methods in Python’s itertools module are used extensively. Methods which generate possibilities or possibility progressions return iterators, which are turned into lists in the examples for display purposes only.
Here, a Segment is created using the default values: a FiguredBassScale in C, a bassNote of C3, an empty notationString, and a default Rules object.
>>> from music21.figuredBass import segment
>>> s1 = segment.Segment()
>>> s1.bassNote
<music21.note.Note C>
>>> s1.numParts
4
>>> s1.pitchNamesInChord
['C', 'E', 'G']
>>> s1.allPitchesAboveBass
[C3, E3, G3, C4, E4, G4, C5, E5, G5]
>>> s1.segmentChord
<music21.chord.Chord C3 E3 G3 C4 E4 G4 C5 E5 G5>
A Segment corresponds to a 1:1 realization of a bassNote and notationString of a FiguredBassLine. It is created by passing six arguments: a FiguredBassScale, a bassNote, a notationString, a Rules object, a number of parts and a maximum pitch. Realizations of a Segment are represented as possibility tuples (see possibility for more details).
Methods in Python’s itertools module are used extensively. Methods which generate possibilities or possibility progressions return iterators, which are turned into lists in the examples for display purposes only.
Here, a Segment is created using the default values: a FiguredBassScale in C, a bassNote of C3, an empty notationString, and a default Rules object.
>>> from music21.figuredBass import segment
>>> s1 = segment.Segment()
>>> s1.bassNote
<music21.note.Note C>
>>> s1.numParts
4
>>> s1.pitchNamesInChord
['C', 'E', 'G']
>>> s1.allPitchesAboveBass
[C3, E3, G3, C4, E4, G4, C5, E5, G5]
>>> s1.segmentChord
<music21.chord.Chord C3 E3 G3 C4 E4 G4 C5 E5 G5>
Segment attributes
- numParts¶
The number of parts (including the bass) that possibilities should contain, which comes directly from numParts in the Rules object.
- segmentChord¶
allPitchesAboveBass represented as a Chord.
- allPitchesAboveBass¶
A list of allowable pitches in the upper parts of a possibility. This is derived using getPitches(), providing bassNote.pitch, maxPitch from the Rules object, and pitchNamesInChord as arguments.
- pitchNamesInChord¶
A list of allowable pitch names. This is derived from bassNote.pitch and notationString using getPitchNames().
Segment methods
- allSinglePossibilities()¶
Returns an iterator through a set of naive possibilities for a Segment, using numParts, the pitch of bassNote, and allPitchesAboveBass.
>>> from music21.figuredBass import segment >>> segmentA = segment.Segment() >>> allPossib = segmentA.allSinglePossibilities() >>> allPossib.__class__ <type 'itertools.product'>The number of naive possibilities is always the length of allPitchesAboveBass raised to the (numParts - 1) power. The power is 1 less than the number of parts because the bass pitch is constant.
>>> allPossibList = list(allPossib) >>> len(segmentA.allPitchesAboveBass) 9 >>> segmentA.numParts 4 >>> len(segmentA.allPitchesAboveBass) ** (segmentA.numParts-1) 729 >>> len(allPossibList) 729 >>> allPossibList[81] (E3, C3, C3, C3) >>> allPossibList[275] (C4, C4, G4, C3) >>> allPossibList[426] (G4, G3, C4, C3)
- singlePossibilityRules(fbRules=<music21.figuredBass.rules Rules>)¶
A framework for storing single possibility rules and methods to be applied in allCorrectSinglePossibilities(). Takes in a Rules object, fbRules.
Items are added within this method in the following form:
(willRunOnlyIfTrue, methodToRun, keepSolnsWhichReturn, optionalArgs)
These items are compiled internally when allCorrectSinglePossibilities() is called on a Segment. Here, the compilation of rules and methods bases on a default fbRules is shown.
>>> from music21.figuredBass import segment >>> segmentA = segment.Segment() >>> allSingleRules = segmentA.singlePossibilityRules() >>> segment.printRules(allSingleRules) Will run: Method: Keep solutions which return: Arguments: True isIncomplete False ['C', 'E', 'G'] True upperPartsWithinLimit True 12 True voiceCrossing False NoneHere, a modified fbRules is provided, which allows for incomplete possibilities.
>>> from music21.figuredBass import rules >>> fbRules = rules.Rules() >>> fbRules.forbidIncompletePossibilities = False >>> allSingleRules = segmentA.singlePossibilityRules(fbRules) >>> segment.printRules(allSingleRules) Will run: Method: Keep solutions which return: Arguments: False isIncomplete False ['C', 'E', 'G'] True upperPartsWithinLimit True 12 True voiceCrossing False None
- allCorrectSinglePossibilities()¶
Uses allSinglePossibilities() and returns an iterator through a set of correct possibilities for a Segment, all possibilities which pass all filters in singlePossibilityRules().
>>> from music21.figuredBass import segment >>> segmentA = segment.Segment() >>> allPossib = segmentA.allSinglePossibilities() >>> allCorrectPossib = segmentA.allCorrectSinglePossibilities()Most of the 729 naive possibilities were filtered out using the default rules set, leaving only 21.
>>> allPossibList = list(allPossib) >>> len(allPossibList) 729 >>> allCorrectPossibList = list(allCorrectPossib) >>> len(allCorrectPossibList) 21 >>> allCorrectPossibList[5] (E4, G3, G3, C3) >>> allCorrectPossibList[12] (C5, G4, E4, C3) >>> allCorrectPossibList[20] (G5, G5, E5, C3)
- consecutivePossibilityRules(fbRules=<music21.figuredBass.rules Rules>)¶
A framework for storing consecutive possibility rules and methods to be applied in allCorrectConsecutivePossibilities(). Takes in a Rules object, fbRules.
Items are added within this method in the following form:
(willRunOnlyIfTrue, methodToRun, keepSolnsWhichReturn, optionalArgs)
These items are compiled internally when allCorrectConsecutivePossibilities() is called on a Segment. Here, the compilation of rules and methods bases on a default fbRules is shown.
>>> from music21.figuredBass import segment >>> segmentA = segment.Segment() >>> allConsecRules = segmentA.consecutivePossibilityRules() >>> segment.printRules(allConsecRules) Will run: Method: Keep solutions which return: Arguments: True partsSame True [] False upperPartsSame True None True voiceOverlap False None True partMovementsWithinLimits True [] True parallelFifths False None True parallelOctaves False None True hiddenFifth False None True hiddenOctave False None False couldBeItalianA6Resolution True [C3, C3, E3, G3], TrueNow, a modified fbRules is provided, allowing hidden octaves and voice overlap, and limiting the soprano line to stepwise motion.
>>> from music21.figuredBass import rules >>> fbRules = rules.Rules() >>> fbRules.forbidVoiceOverlap = False >>> fbRules.forbidHiddenOctaves = False >>> fbRules.partMovementLimits.append((1,2)) >>> allConsecRules = segmentA.consecutivePossibilityRules(fbRules) >>> segment.printRules(allConsecRules) Will run: Method: Keep solutions which return: Arguments: True partsSame True [] False upperPartsSame True None False voiceOverlap False None True partMovementsWithinLimits True [(1, 2)] True parallelFifths False None True parallelOctaves False None True hiddenFifth False None False hiddenOctave False None False couldBeItalianA6Resolution True [C3, C3, E3, G3], True
- specialResolutionRules(fbRules=<music21.figuredBass.rules Rules>)¶
A framework for storing methods which perform special resolutions on Segments. Unlike the methods in singlePossibilityRules() and consecutivePossibilityRules(), these methods deal with the Segment itself, and rely on submethods to resolve the individual possibilities accordingly depending on what the resolution Segment is.
Items are added within this method in the following form:
(willRunOnlyIfTrue, methodToRun, optionalArgs)
These items are compiled internally when allCorrectConsecutivePossibilities() is called on a Segment. Here, the compilation of rules and methods based on a default fbRules is shown.
>>> from music21.figuredBass import segment >>> segmentA = segment.Segment() >>> allSpecialResRules = segmentA.specialResolutionRules() >>> segment.printRules(allSpecialResRules, maxLength = 3) Will run: Method: Arguments: False resolveDominantSeventhSegment None False resolveDiminishedSeventhSegment False False resolveAugmentedSixthSegment NoneDominant Seventh Segment:
>>> from music21 import note >>> segmentA = segment.Segment(bassNote = note.Note('B2'), notationString = "6,5") >>> allSpecialResRules = segmentA.specialResolutionRules() >>> segment.printRules(allSpecialResRules, maxLength = 3) Will run: Method: Arguments: True resolveDominantSeventhSegment None False resolveDiminishedSeventhSegment False False resolveAugmentedSixthSegment NoneFully-Diminished Seventh Segment:
>>> segmentA = segment.Segment(bassNote = note.Note('B2'), notationString = "-7") >>> allSpecialResRules = segmentA.specialResolutionRules() >>> segment.printRules(allSpecialResRules, maxLength = 3) Will run: Method: Arguments: False resolveDominantSeventhSegment None True resolveDiminishedSeventhSegment False False resolveAugmentedSixthSegment NoneAugmented Sixth Segment:
>>> segmentA = segment.Segment(bassNote = note.Note('A-2'), notationString = "#6,b5") >>> allSpecialResRules = segmentA.specialResolutionRules() >>> segment.printRules(allSpecialResRules, maxLength = 3) Will run: Method: Arguments: False resolveDominantSeventhSegment None False resolveDiminishedSeventhSegment False True resolveAugmentedSixthSegment None
- allCorrectConsecutivePossibilities(segmentB)¶
Returns an iterator through correct (possibA, possibB) pairs.
- If segmentA (self) is a special Segment, meaning that one of the Segment resolution methods in specialResolutionRules() needs to be applied, then this method returns every correct possibility of segmentA matched up with exactly one resolution possibility.
- If segmentA is an ordinary, non-special Segment, then this method returns every combination of correct possibilities of segmentA and correct possibilities of segmentB which passes all filters in consecutivePossibilityRules().
Two notes on segmentA being a special Segment:
- By default resolution possibilities are not filtered using singlePossibilityRules() rules of segmentB. Filter by setting applySinglePossibRulesToResolution to True.
- By default, (possibA, possibB) pairs are not filtered using consecutivePossibilityRules() rules of segmentA. Filter by setting applyConsecutivePossibRulesToResolution to True.
>>> from music21.figuredBass import segment >>> from music21 import note >>> segmentA = segment.Segment(bassNote = note.Note('C3'), notationString = "") >>> segmentB = segment.Segment(bassNote = note.Note('D3'), notationString = "4,3")Here, an ordinary resolution is being executed, because segmentA is an ordinary Segment.
>>> consecPairs1 = segmentA.allCorrectConsecutivePossibilities(segmentB) >>> consecPairsList1 = list(consecPairs1) >>> len(consecPairsList1) 31 >>> consecPairsList1[29] ((G5, G5, E5, C3), (G5, F5, B4, D3))Here, a special resolution is being executed, because segmentA below is a special Segment.
>>> segmentA = segment.Segment(bassNote = note.Note('D3'), notationString = "4,3") >>> segmentB = segment.Segment(bassNote = note.Note('C3'), notationString = "") >>> consecPairs2 = segmentA.allCorrectConsecutivePossibilities(segmentB) >>> consecPairsList2 = list(consecPairs2) >>> len(consecPairsList2) 6 >>> consecPairsList2[5] ((G5, F5, B4, D3), (G5, E5, C5, C3))
- resolveDominantSeventhSegment(segmentB)¶
Can resolve a Segment whose segmentChord spells out a dominant seventh chord. If no applicable method in resolution can be used, the Segment is resolved as an ordinary Segment.
>>> from music21.figuredBass import segment >>> from music21 import note >>> segmentA = segment.Segment(bassNote = note.Note('G2'), notationString = "7") >>> allDomPossib = segmentA.allCorrectSinglePossibilities() >>> allDomPossibList = list(allDomPossib) >>> len(allDomPossibList) 8 >>> allDomPossibList[2] (D4, B3, F3, G2) >>> allDomPossibList[5] (D5, B4, F4, G2) >>> allDomPossibList[7] # Soprano pitch of resolution (C6) exceeds default maxPitch of B5, filtered out. (B5, F5, D5, G2)>>> segmentB = segment.Segment(bassNote = note.Note('C3'), notationString = "") >>> domResPairs = segmentA.resolveDominantSeventhSegment(segmentB) >>> domResPairsList = list(domResPairs) >>> len(domResPairsList) 7 >>> domResPairsList[2] ((D4, B3, F3, G2), (C4, C4, E3, C3)) >>> domResPairsList[5] ((D5, B4, F4, G2), (C5, C5, E4, C3))
- resolveDiminishedSeventhSegment(segmentB, doubledRoot=False)¶
Can resolve a Segment whose segmentChord spells out a diminished seventh chord. If no applicable method in resolution can be used, the Segment is resolved as an ordinary Segment.
>>> from music21.figuredBass import segment >>> from music21 import note >>> segmentA = segment.Segment(bassNote = note.Note('B2'), notationString = "b7") >>> allDimPossib = segmentA.allCorrectSinglePossibilities() >>> allDimPossibList = list(allDimPossib) >>> len(allDimPossibList) 7 >>> allDimPossibList[4] (D5, A-4, F4, B2) >>> allDimPossibList[6] (A-5, F5, D5, B2)>>> segmentB = segment.Segment(bassNote = note.Note('C3'), notationString = "") >>> dimResPairs = segmentA.resolveDiminishedSeventhSegment(segmentB) >>> dimResPairsList = list(dimResPairs) >>> len(dimResPairsList) 7 >>> dimResPairsList[4] ((D5, A-4, F4, B2), (E5, G4, E4, C3)) >>> dimResPairsList[6] ((A-5, F5, D5, B2), (G5, E5, E5, C3))
- resolveAugmentedSixthSegment(segmentB)¶
Can resolve a Segment whose segmentChord spells out a French, German, or Swiss augmented sixth chord. Italian augmented sixth Segments are solved as an ordinary Segment using couldBeItalianA6Resolution(). If no applicable method in resolution can be used, the Segment is resolved as an ordinary Segment.
>>> from music21.figuredBass import segment >>> from music21 import note >>> segmentA = segment.Segment(bassNote = note.Note("A-2"), notationString = "#6,b5,3") >>> segmentA.pitchNamesInChord # spell out a Gr+6 chord ['A-', 'C', 'E-', 'F#'] >>> allAugSixthPossib = segmentA.allCorrectSinglePossibilities() >>> allAugSixthPossibList = list(allAugSixthPossib) >>> len(allAugSixthPossibList) 7 >>> allAugSixthPossibList[1] (C4, F#3, E-3, A-2) >>> allAugSixthPossibList[4] (C5, F#4, E-4, A-2)>>> segmentB = segment.Segment(bassNote = note.Note("G2"), notationString = "") >>> allAugResPossibPairs = segmentA.resolveAugmentedSixthSegment(segmentB) >>> allAugResPossibPairsList = list(allAugResPossibPairs) >>> len(allAugResPossibPairsList) 7 >>> allAugResPossibPairsList[1] ((C4, F#3, E-3, A-2), (B3, G3, D3, G2)) >>> allAugResPossibPairsList[4] ((C5, F#4, E-4, A-2), (B4, G4, D4, G2))