This module, the heart of fbRealizer, is all about realizing a bass line of (bassNote, notationString) pairs. All it takes to create well-formed realizations of a bass line is a few lines of music21 code, from start to finish. See FiguredBassLine for more details.
>>> from music21.figuredBass import realizer
>>> from music21 import note
>>> fbLine = realizer.FiguredBassLine()
>>> fbLine.addElement(note.Note('C3'))
>>> fbLine.addElement(note.Note('D3'), '4,3')
>>> fbLine.addElement(note.Note('C3', quarterLength = 2.0))
>>> allSols = fbLine.realize()
>>> allSols.getNumSolutions()
30
>>> allSols.generateRandomRealizations(14).show()
The same can be accomplished by taking the notes and notations from a Stream. See figuredBassFromStream() for more details.
>>> from music21 import tinyNotation
>>> s = tinyNotation.TinyNotationStream("C4 D4_4,3 C2")
>>> fbLine = realizer.figuredBassFromStream(s)
>>> allSols2 = fbLine.realize()
>>> allSols2.getNumSolutions()
30
Takes a Part (or another Stream subclass) and returns a FiguredBassLine object whose bass notes have notations taken from the lyrics in the source stream. This method along with the realize() method provide the easiest way of converting from a notated version of a figured bass (such as in a MusicXML file) to a realized version of the same line.
>>> s = tinyNotation.TinyNotationStream('4/4 C4 D8_6 E8_6 F4 G4_7 c1')
>>> fb = figuredBass.realizer.figuredBassFromStream(s)
>>> fb
<music21.figuredBass.realizer.FiguredBassLine object at 0x...>
>>> fbRules = figuredBass.rules.Rules()
>>> fbRules.partMovementLimits = [(1,2),(2,12),(3,12)]
>>> fbRealization = fb.realize(fbRules)
>>> fbRealization.getNumSolutions()
13
>>> fbRealization.generateRandomRealizations(8).show()
Deprecated. Use figuredBassFromStream() instead.
(Keep because it appears in the Cabel-Ugaz thesis)
Takes in a bassNote and a corresponding notationString as arguments. Adds the parsed notationString as lyrics to the bassNote, which is useful when displaying the figured bass in external software.
>>> from music21.figuredBass import realizer
>>> from music21 import note
>>> n1 = note.Note('G3')
>>> realizer.addLyricsToBassNote(n1, "6,4")
>>> n1.lyrics[0].text
'6'
>>> n1.lyrics[1].text
'4'
>>> n1.show()
A FiguredBassLine is an interface for realization of a line of (bassNote, notationString) pairs. Currently, only 1:1 realization is supported, meaning that every bassNote is realized and the quarterLength or duration of a realization above a bassNote is identical to that of the bassNote.
inKey defaults to C major.
inTime defaults to 4/4.
>>> from music21.figuredBass import realizer
>>> from music21 import key
>>> from music21 import meter
>>> fbLine = realizer.FiguredBassLine(key.Key('B'), meter.TimeSignature('3/4'))
>>> fbLine.inKey
<music21.key.Key of B major>
>>> fbLine.inTime
<music21.meter.TimeSignature 3/4>
FiguredBassLine methods
Use this method to add (bassNote, notationString) pairs to the bass line. Elements are realized in the order they are added.
>>> from music21.figuredBass import realizer
>>> from music21 import key
>>> from music21 import meter
>>> from music21 import note
>>> fbLine = realizer.FiguredBassLine(key.Key('B'), meter.TimeSignature('3/4'))
>>> fbLine.addElement(note.Note('B2'))
>>> fbLine.addElement(note.Note('C#3'), "6")
>>> fbLine.addElement(note.Note('D#3'), "6")
>>> fbLine.generateBassLine().show()
Generates the bass line as a Score.
>>> from music21.figuredBass import realizer
>>> from music21 import key
>>> from music21 import meter
>>> from music21 import note
>>> fbLine = realizer.FiguredBassLine(key.Key('B'), meter.TimeSignature('3/4'))
>>> fbLine.addElement(note.Note('B2'))
>>> fbLine.addElement(note.Note('C#3'), "6")
>>> fbLine.addElement(note.Note('D#3'), "6")
>>> fbLine.generateBassLine().show()
>>> from music21 import corpus
>>> sBach = corpus.parse('bach/bwv307')
>>> sBach['bass'].measure(0).show("text")
{0.0} <music21.clef.BassClef>
{0.0} <music21.key.KeySignature of 2 flats, mode major>
{0.0} <music21.meter.TimeSignature 4/4>
{0.0} <music21.note.Note B->
{0.5} <music21.note.Note C>
>>> fbLine = realizer.figuredBassFromStream(sBach['bass'])
>>> fbLine.generateBassLine().measure(1).show("text")
{0.0} <music21.clef.BassClef>
{0.0} <music21.key.KeySignature of 2 flats>
{0.0} <music21.meter.TimeSignature 4/4>
{3.0} <music21.note.Note B->
{3.5} <music21.note.Note C>
Generates a random realization of a figured bass as a Score, with the default rules set and a soprano line limited to stepwise motion.
Note
Deprecated. Use realize() which returns a Realization. Then, call generateRandomRealization().
Creates a Segment for each (bassNote, notationString) pair added using addElement(). Each Segment is associated with the Rules object provided, meaning that rules are universally applied across all Segments. The number of parts in a realization (including the bass) can be controlled through numParts, and the maximum pitch can likewise be controlled through maxPitch. Returns a Realization.
If this methods is called without having provided any (bassNote, notationString) pairs, a FiguredBassLineException is raised. If only one pair is provided, the Realization will contain allCorrectConsecutivePossibilities() for the one note.
if fbRules is None, creates a new rules.Rules() object
if maxPitch is None, uses pitch.Pitch(‘B5’)
>>> from music21.figuredBass import realizer
>>> from music21.figuredBass import rules
>>> from music21 import key
>>> from music21 import meter
>>> from music21 import note
>>> fbLine = realizer.FiguredBassLine(key.Key('B'), meter.TimeSignature('3/4'))
>>> fbLine.addElement(note.Note('B2'))
>>> fbLine.addElement(note.Note('C#3'), "6")
>>> fbLine.addElement(note.Note('D#3'), "6")
>>> fbRules = rules.Rules()
>>> r1 = fbLine.realize(fbRules)
>>> r1.getNumSolutions()
208
>>> fbRules.forbidVoiceOverlap = False
>>> r2 = fbLine.realize(fbRules)
>>> r2.getNumSolutions()
7908
generates the segmentList from an fbList, including any overlayed Segments
if fbRules is None, creates a new rules.Rules() object
if maxPitch is None, uses pitch.Pitch(‘B5’)
Displays all realizations of a figured bass as a musicxml in external software, with the default rules set and a soprano line limited to stepwise motion.
Note
Deprecated. Use realize() which returns a Realization. Then, call generateAllRealizations() followed by a call to show().
Warning
This method is unoptimized, and may take a prohibitive amount of time for a Realization which has more than tens of unique realizations.
Displays a random realization of a figured bass as a musicxml in external software, with the default rules set and a soprano line limited to stepwise motion.
Note
Deprecated. Use realize() which returns a Realization. Then, call generateRandomRealization() followed by a call to show().
FiguredBassLine instance variables
A Key which implies a scale value, scale mode, and key signature for a FiguredBassScale.
A TimeSignature which specifies the time signature of realizations outputted to a Score.
Returned by FiguredBassLine after calling realize(). Allows for the generation of realizations as a Score.
Realization methods
Generates all unique realizations as a Score.
Warning
This method is unoptimized, and may take a prohibitive amount of time for a Realization which has more than 100 solutions.
Generates amountToGenerate unique realizations as a Score.
Warning
This method is unoptimized, and may take a prohibitive amount of time if amountToGenerate is more than 100.
Generates a realization as a Score given a possibility progression.
Compiles each unique possibility progression, adding it to a master list. Returns the master list.
Warning
This method is unoptimized, and may take a prohibitive amount of time for a Realization which has more than 200,000 solutions.
Returns the number of solutions (unique realizations) to a Realization by calculating the total number of paths through a string of Segment movements. This is faster and more efficient than compiling each unique realization into a list, adding it to a master list, and then taking the length of the master list.
>>> from music21.figuredBass import examples
>>> fbLine = examples.exampleB()
>>> fbRealization = fbLine.realize()
>>> fbRealization.getNumSolutions()
422
>>> fbLine2 = examples.exampleC()
>>> fbRealization2 = fbLine2.realize()
>>> fbRealization2.getNumSolutions()
833
Returns a random unique possibility progression.
Realization instance variables
True by default. If True, generated realizations are represented in keyboard style, with two staves. If False, realizations are represented in chorale style with n staves, where n is the number of parts. SATB if n = 4.