Automatically reduce a MeasureStack to a single chord or group of chords.
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>
ChordReducer methods
>>> 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
Return a multipart reduction of a stream.
Everything from before plus consonance
>>> 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.notes[0].quarterLength
4.0