Skip to main content

Module enharmonics

Module enharmonics 

Source
Expand description

The best spelling of a run of pitches: music21’s analysis.enharmonics.

Every pitch may be written as itself or as any common enharmonic with at most one sharp or flat. Each combination is scored by three penalties and the lowest score wins, the first of equals in the order the combinations are listed:

  aug/dim     (augmented + diminished steps + 1) * aug_dim penalty
+ alteration  (sharps + flats + 1)               * alteration penalty
+ mixture     min(sharps, flats)                 * mixture penalty

A penalty that is off scores 1 rather than 0, as music21’s does.

Structs§

EnharmonicRules
The three penalties a spelling is scored by: music21’s EnharmonicScoreRules and its subclasses. A penalty of None or nought is off, and scores 1 whatever the spelling.

Functions§

best_choice
Which option of each position scores best under rules, one index per position: the heart of music21’s bestPitches. Combinations are tried in the order itertools.product lists them, and the first strictly lowest wins. A position with no options leaves nothing to choose.
best_spelling
The best spelling of pitches under rules: music21’s EnharmonicSimplifier.bestPitches. Octaves move with a respelling, so B#3 may come back as C4.
spelling_options
Every spelling each pitch may take: itself first, then its common enharmonics with at most one sharp or flat. music21’s EnharmonicSimplifier.getRepresentations.