Key‐finding - mtpearce/idyom GitHub Wiki
This app implements the Krumhansl-Schmuckler key-finding algorithm. It estimates the key of a composition by computing a duration-weighted pitch-class distribution and comparing that distribution with stored major and minor key profiles.
This can be useful for corpora imported into the database without key information (e.g., from MIDI files). The key can be estimated and recorded in the database before running IDyOM to allow tonal viewpoints to be used.
For an extension of IDyOM to estimate key via Bayesian inference see Jackdaw.
Two top-level functions are provided:
-
key-finding:find-key: estimate the key of a single composition -
key-finding:find-keys: estimate the keys of all compositions in a dataset and compare the estimates with the keys stored in the database
The function key-finding:find-key takes a dataset-id and a composition-id. These are positional arguments and should be supplied in that order. It returns a list of four values:
-
keysig: the estimated key signature -
mode:0for major or9for minor -
tonic: the estimated tonic as a pitch class -
coefficient: the correlation coefficient for the best-fitting key profile
The optional :method parameter determines which set of key profiles is used. The default is :temperley. If a value other than :temperley is supplied, the Krumhansl-Kessler profiles are used.
The following is an example:
This estimates the key of composition 0 in dataset 0 and returns the estimated key signature, mode, tonic and correlation coefficient.
CL-USER> (key-finding:find-key 0 0)
The function key-finding:find-keys applies the same procedure to every composition in a dataset. It prints any compositions whose estimated key does not match the key stored in the database, and then prints an overall score.
Useful optional parameters are:
-
method: the key profile set to use (default:temperley) -
update-db?: ift, update the key signature and mode stored in the database; ifnil(the default), only report the estimates
For example:
This processes every composition in dataset 0 using the Temperley profiles, prints any disagreements with the stored keys, and then prints an overall score.
CL-USER> (key-finding:find-keys 0 :method :temperley)