Skip to main content

estimate_key_from_distribution

Function estimate_key_from_distribution 

Source
pub fn estimate_key_from_distribution(
    profile: KeyProfile,
    distribution: &[FloatType; 12],
) -> Vec<KeyEstimate>
Expand description

Every key ranked by how well profile fits distribution, best first: music21’s key-weight analysis.

Each of the 24 keys is scored by the correlation between the distribution and the profile turned to that tonic, summed in music21’s order and averaged as Python sums, so a score is music21’s to within the last digit – music21 squares through the platform’s pow, which is not always exact, where this multiplies. Ties are broken as music21 breaks them, by the higher tonic and then minor before major, and each tonic is spelled as music21 spells it: the pitch class’s usual name, respelled where that is no key in the mode, so a major key on the eighth class is A- and a minor one G#.