music21.analysis.reduceChords¶
Automatically reduce a MeasureStack to a single chord or group of chords.
ChordReducer¶
ChordReducer methods
- ChordReducer.collapseArpeggios(scoreTree)[source]¶
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)[source]¶
Compute measure chord weights:
>>> s = analysis.reduceChords.testMeasureStream1().notes >>> cr = analysis.reduceChords.ChordReducer() >>> cws = cr.computeMeasureChordWeights(s) >>> for pcs in sorted(cws): ... print(f'{pcs!r:18} {cws[pcs]:2.1f}') (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(f'{pcs!r:18} {cws[pcs]:2.1f}') (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(f'{pcs!r:18} {cws[pcs]:2.1f}') (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(f'{pcs!r:18} {cws[pcs]:2.1f}') (0, 4, 7) 3.0 (0, 11, 4, 5) 0.1
- ChordReducer.reduceMeasureToNChords(measureObject, maximumNumberOfChords=1, weightAlgorithm=None, trimBelow=0.25)[source]¶
Reduces measure to
nchords:>>> 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)[source]¶
Removes timespans containing passing and neighbor tones from
tree.
- ChordReducer.removeShortTimespans(scoreTree, partwiseTrees, duration=0.5)[source]¶
Removes timespans in
treeshorter thanduration.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)[source]¶
Removes timespans in each dissonant verticality of
treewhose pitches are above the lowest pitch in that verticality.
Functions¶
- music21.analysis.reduceChords.testMeasureStream1()[source]¶
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>