music21.analysis.reduceChords

Automatically reduce a MeasureStack to a single chord or group of chords.

ChordReducer

class music21.analysis.reduceChords.ChordReducer

A chord reducer.

ChordReducer methods

ChordReducer.alignHockets(scoreTree)

Aligns hockets between parts in tree.

ChordReducer.collapseArpeggios(scoreTree)

Collapses arpeggios in tree.

>>> m = stream.Measure([chord.Chord('C4 E4'), chord.Chord('C4 G4')])
>>> cr = analysis.reduceChords.ChordReducer()
>>> spans = m.asTimespans(classList=(note.NotRest,))
>>> len(spans)
2
>>> cr.collapseArpeggios(spans)
>>> len(spans)
1
ChordReducer.computeMeasureChordWeights(measureObject, weightAlgorithm=None)

Compute measure chord weights:

>>> s = analysis.reduceChords.testMeasureStream1().notes
>>> cr = analysis.reduceChords.ChordReducer()
>>> cws = cr.computeMeasureChordWeights(s)
>>> for pcs in sorted(cws):
...     print("%18r  %2.1f" % (pcs, cws[pcs]))
    (0, 4, 7)  3.0
(0, 11, 4, 5)  1.0

Add beatStrength:

>>> cws = cr.computeMeasureChordWeights(s,
...     weightAlgorithm=cr.quarterLengthBeatStrength)
>>> for pcs in sorted(cws):
...     print("%18r  %2.1f" % (pcs, cws[pcs]))
    (0, 4, 7)  2.2
(0, 11, 4, 5)  0.5

Give extra weight to the last element in a measure:

>>> cws = cr.computeMeasureChordWeights(s,
...     weightAlgorithm=cr.quarterLengthBeatStrengthMeasurePosition)
>>> for pcs in sorted(cws):
...     print("%18r  %2.1f" % (pcs, cws[pcs]))
    (0, 4, 7)  3.0
(0, 11, 4, 5)  0.5

Make consonance count a lot:

>>> cws = cr.computeMeasureChordWeights(s,
...     weightAlgorithm=cr.qlbsmpConsonance)
>>> for pcs in sorted(cws):
...     print("%18r  %2.1f" % (pcs, cws[pcs]))
     (0, 4, 7)  3.0
 (0, 11, 4, 5)  0.1
ChordReducer.fillBassGaps(scoreTree, partwiseTrees)
ChordReducer.fillMeasureGaps(scoreTree, partwiseTrees)

Fills measure gaps in tree.

ChordReducer.fuseTimespansByPart(scoreTree, part)
ChordReducer.qlbsmpConsonance(chordObject)

Everything from before plus consonance

ChordReducer.quarterLengthBeatStrength(chordObject)
ChordReducer.quarterLengthBeatStrengthMeasurePosition(chordObject)
ChordReducer.quarterLengthOnly(chordObject)
ChordReducer.reduceMeasureToNChords(measureObject, maximumNumberOfChords=1, weightAlgorithm=None, trimBelow=0.25)

Reduces measure to n chords:

>>> s = analysis.reduceChords.testMeasureStream1()
>>> cr = analysis.reduceChords.ChordReducer()

Reduce to a maximum of 3 chords; though here we will only get one because the other chord is below the trimBelow threshold.

>>> newS = cr.reduceMeasureToNChords(s, 3,
...     weightAlgorithm=cr.qlbsmpConsonance,
...     trimBelow=0.3)
>>> newS.show('text')
{0.0} <music21.meter.TimeSignature 4/4>
{0.0} <music21.chord.Chord C4 E4 G4 C5>
>>> newS[-1].quarterLength
4.0
ChordReducer.removeNonChordTones(scoreTree)

Removes timespans containing passing and neighbor tones from tree.

ChordReducer.removeShortTimespans(scoreTree, partwiseTrees, duration=0.5)

Removes timespans in tree shorter than duration.

Special treatment is given to groups of short timespans if they take up an entire measure. In that case, the timespans with the most common sets of pitches are kept.

ChordReducer.removeVerticalDissonances(scoreTree=None, allowableChords=None, forbiddenChords=None)

Removes timespans in each dissonant verticality of tree whose pitches are above the lowest pitch in that verticality.

ChordReducer.removeZeroDurationTimespans(scoreTree)
ChordReducer.run(inputScore, allowableChords=None, closedPosition=False, forbiddenChords=None, maximumNumberOfChords=3)
ChordReducer.splitByBass(scoreTree)

Functions

music21.analysis.reduceChords.testMeasureStream1()

returns a simple measure stream for testing:

>>> s = analysis.reduceChords.testMeasureStream1()
>>> s.show('text')
{0.0} <music21.meter.TimeSignature 4/4>
{0.0} <music21.chord.Chord C4 E4 G4 C5>
{2.0} <music21.chord.Chord C4 E4 F4 B4>
{3.0} <music21.chord.Chord C4 E4 G4 C5>