You are on page 1of 8

Keyfinding

... Adventure

The Problem

Consider the following melody, a fragment of a simplification of a well known song by a great composer, represented
in Cloy:

C1 / F3 / A1 / C3 \ F1 / Z1 / D1 / F1 \ D1 \ C3 \ A1
/ Z1 \ G1 R1 / Z1 \ A1 \ F1 R1 / A1 \ G1 G1 / B1 B1 / C3

What is the key of this sequence of notes?

The Encoding in C Major

To start the investigation of key via Krumhansl’s algorithm in MxM, we encode the melodic fragment in the key of
C major, since presumably we don’t know its key. Here is the Clay code:

TUNE >> ONE TWO THREE


ONE >> PLAY 3RP X3 PLAY S3 2RP PLAY 2RP X3 PLAY S3 7LP
TWO >> 3RP PLAY 3RP PLAYXLP 2RP PLAY 2RP PLAY 2LP PLAY LP X3 PLAY S3 7LP
THREE >> 5RP PLAY RP PLAYXLP 2LP PLAY REST 2RP PLAYXLP LP PLAY 2LP PLAY REST
2RP PLAY LP PLAY PLAY 2RP PLAY PLAY RP X3 PLAY S3 7LP

Of course, we should verify that our code actually generates the melody. In the following demo you can see that I
changed the Cloy output mode to “text” and then ran the program to generate the melodic fragment:

Meta> -RENDER
TYPE OF NOTE = Text

Clay> TUNE
C1 / F3 / A1 / C3 \ F1 / Z1 / D1 / F1 \ D1 \ C3 \ A1
/ Z1 \ G1 R1 / Z1 \ A1 \ F1 R1 / A1 \ G1 G1 / B1 B1 / C3

Using MxM to run Krumhansel’s Algorithm

We will ask MxM to run Krumhansel’s key finding algorithm. In the demo, I do so twice. Once without the relevant
trace flag set. Once with it set. In each case, I launch the algorithm by means of the “statistics” button.

Meta> -STATS
Performing the Krumhansl Key Finding Algorithm ...
F major

Clay> .TRACE.KKFA.ON
Meta> -STATS
Performing the Krumhansl Key Finding Algorithm ...

pitchclass-duration sequence ...


C1.0 F3.0 A1.0 C3.0 F1.0 Z1.0 D1.0 F1.0 D1.0 C3.0 A1.0
Z1.0 G1.0 Z1.0 A1.0 F1.0 A1.0 G1.0 G1.0 B1.0 B1.0 C3.0

pprofile ...
C10.0 C#0.0 D2.0 Eb0.0 E0.0 F6.0 F#0.0 G3.0 Ab0.0 A4.0 Bb3.0 B2.0

computing a correlation ......


pitch profile ...
C10.0 C#0.0 D2.0 Eb0.0 E0.0 F6.0 F#0.0 G3.0 Ab0.0 A4.0 Bb3.0 B2.0
key profile Cmajor ...
(C,6.35)(C#,2.23)(D,3.48)(Eb,2.33)(E,4.38)(F,4.09)(F#,2.52)(G,5.19)(Ab,2.39)(A,3.66)(Bb,2.29)(B,2.88)
xbar = 2.5
ybar = 3.4825000000000004
cor(top) = 33.365
cor(bot(x)) = 103.0
cor(bot(y)) = 19.146225
cor(bot) = 44.40789541286549
cor = 0.7513303589328344

computing a correlation ......


pitch profile ...
C10.0 C#0.0 D2.0 Eb0.0 E0.0 F6.0 F#0.0 G3.0 Ab0.0 A4.0 Bb3.0 B2.0
key profile Cminor ...
(C,6.33)(C#,2.68)(D,3.52)(Eb,5.38)(E,2.6)(F,3.53)(G#,2.54)(G,4.75)(Ab,3.98)(A,2.69)(Bb,3.34)(B,3.17)
xbar = 2.5
ybar = 3.709166666666667
cor(top) = 21.615000000000002
cor(bot(x)) = 103.0
cor(bot(y)) = 16.007091666666668
cor(bot) = 40.60456183320621
cor = 0.5323293498102314

computing a correlation ......


pitch profile ...
C10.0 C#0.0 D2.0 Eb0.0 E0.0 F6.0 F#0.0 G3.0 Ab0.0 A4.0 Bb3.0 B2.0
key profile CSHARPmajor ...
(C,2.88)(C#,6.35)(D,2.23)(Eb,3.48)(E,2.33)(F,4.38)(F#,4.09)(G,2.52)(Ab,5.19)(A,2.39)(Bb,3.66)(B,2.29)
xbar = 2.5
ybar = 3.4825
cor(top) = -12.255
cor(bot(x)) = 103.0
cor(bot(y)) = 19.146224999999998
cor(bot) = 44.40789541286549
cor = -0.2759644402434253

computing a correlation ......


pitch profile ...
C10.0 C#0.0 D2.0 Eb0.0 E0.0 F6.0 F#0.0 G3.0 Ab0.0 A4.0 Bb3.0 B2.0
key profile CSHARPminor ...
(C,3.17)(C#,6.33)(D,2.68)(Eb,3.52)(E,5.38)(F,2.6)(F#,3.53)(G,2.54)(Ab,4.75)(A,3.98)(Bb,2.69)(B,3.34)
xbar = 2.5
ybar = 3.709166666666666
cor(top) = -20.325000000000006
cor(bot(x)) = 103.0
cor(bot(y)) = 16.007091666666668
cor(bot) = 40.60456183320621
cor = -0.5005595204669422

computing a correlation ......


pitch profile ...
C10.0 C#0.0 D2.0 Eb0.0 E0.0 F6.0 F#0.0 G3.0 Ab0.0 A4.0 Bb3.0 B2.0
key profile Dmajor ...
(C,2.29)(C#,2.88)(D,6.35)(Eb,2.23)(E,3.48)(F,2.33)(F#,4.38)(G,4.09)(Ab,2.52)(A,5.19)(Bb,2.39)(B,3.66)
xbar = 2.5
ybar = 3.4825000000000004
cor(top) = -7.374999999999999
cor(bot(x)) = 103.0
cor(bot(y)) = 19.146225
cor(bot) = 44.40789541286549
cor = -0.16607407154592096

computing a correlation ......


pitch profile ...
C10.0 C#0.0 D2.0 Eb0.0 E0.0 F6.0 F#0.0 G3.0 Ab0.0 A4.0 Bb3.0 B2.0
key profile Dminor ...
(C,3.34)(C#,3.17)(D,6.33)(Eb,2.68)(E,3.52)(F,5.38)(F#,2.6)(G,3.53)(Ab,2.54)(A,4.75)(Bb,3.98)(B,2.69)
xbar = 2.5
ybar = 3.7091666666666665
cor(top) = 13.974999999999998
cor(bot(x)) = 103.0
cor(bot(y)) = 16.007091666666668
cor(bot) = 40.60456183320621
cor = 0.3441731512189675

computing a correlation ......


pitch profile ...
C10.0 C#0.0 D2.0 Eb0.0 E0.0 F6.0 F#0.0 G3.0 Ab0.0 A4.0 Bb3.0 B2.0
key profile EFLATmajor ...
(D,3.66)(C#,2.29)(D,2.88)(Eb,6.35)(E,2.23)(F,3.48)(F#,2.33)(G,4.38)(Ab,4.09)(A,2.52)(Bb,5.19)(B,2.39)
xbar = 2.5
ybar = 3.4825
cor(top) = 2.3350000000000017
cor(bot(x)) = 103.0
cor(bot(y)) = 19.146225
cor(bot) = 44.40789541286549
cor = 0.0525807399403018

computing a correlation ......


pitch profile ...
C10.0 C#0.0 D2.0 Eb0.0 E0.0 F6.0 F#0.0 G3.0 Ab0.0 A4.0 Bb3.0 B2.0
key profile EFLATminor ...
(C,2.69)(C#,3.34)(D,3.17)(Eb,6.33)(E,2.68)(F,3.52)(F#,5.38)(FG,2.6)(Ab,3.53)(A,2.54)(Bb,4.75)(B,3.98)
xbar = 2.5
ybar = 3.7091666666666665
cor(top) = -16.745000000000005
cor(bot(x)) = 103.0
cor(bot(y)) = 16.007091666666664
cor(bot) = 40.60456183320621
cor = -0.4123920870956432

computing a correlation ......


pitch profile ...
C10.0 C#0.0 D2.0 Eb0.0 E0.0 F6.0 F#0.0 G3.0 Ab0.0 A4.0 Bb3.0 B2.0
key profile Emajor ...
(C,2.39)(C#,3.66)(D,2.29)(Eb,2.88)(E,6.35)(F,2.23)(F#,3.48)(G,2.33)(Ab,4.38)(A,4.09)(Bb,2.52)(B,5.19)
xbar = 2.5
ybar = 3.4825
cor(top) = -21.325
cor(bot(x)) = 103.0
cor(bot(y)) = 19.146225
cor(bot) = 44.40789541286549
cor = -0.48020740009718843

computing a correlation ......


pitch profile ...
C10.0 C#0.0 D2.0 Eb0.0 E0.0 F6.0 F#0.0 G3.0 Ab0.0 A4.0 Bb3.0 B2.0
key profile Eminor ...
(C,3.98)(C#,2.69)(D,3.34)(Eb,3.17)(E,6.33)(F,2.68)(F#,3.52)(G,5.38)(Ab,2.6)(A,3.53)(Bb,2.54)(B,4.75)
xbar = 2.5
ybar = 3.7091666666666665
cor(top) = -1.3349999999999993
cor(bot(x)) = 103.0
cor(bot(y)) = 16.007091666666668
cor(bot) = 40.60456183320621
cor = -0.03287807920410171

computing a correlation ......


pitch profile ...
C10.0 C#0.0 D2.0 Eb0.0 E0.0 F6.0 F#0.0 G3.0 Ab0.0 A4.0 Bb3.0 B2.0
key profile Fmajor ...
(C,5.19)(C#,2.39)(D,3.66)(Eb,2.29)(E,2.88)(F,6.35)(F#,2.23)(G,3.48)(Ab,2.33)(A,4.38)(Bb,4.09)(B,2.52)
xbar = 2.5
ybar = 3.4825
cor(top) = 38.11500000000001
cor(bot(x)) = 103.0
cor(bot(y)) = 19.146225
cor(bot) = 44.40789541286549
cor = 0.8582933202674956

computing a correlation ......


pitch profile ...
C10.0 C#0.0 D2.0 Eb0.0 E0.0 F6.0 F#0.0 G3.0 Ab0.0 A4.0 Bb3.0 B2.0
key profile Fminor ...
(C,4.75)(C#,3.98)(D,2.69)(Eb,3.34)(E,3.17)(F,6.33)(F#,2.68)(G,3.52)(Ab,5.38)(A,2.6)(Bb,3.53)(B,2.54)
xbar = 2.5
ybar = 3.7091666666666665
cor(top) = 16.215
cor(bot(x)) = 103.0
cor(bot(y)) = 16.007091666666664
cor(bot) = 40.60456183320621
cor = 0.39933936651274127
computing a correlation ......
pitch profile ...
C10.0 C#0.0 D2.0 Eb0.0 E0.0 F6.0 F#0.0 G3.0 Ab0.0 A4.0 Bb3.0 B2.0
key profile FSHARPmajor ...
(C,2.52)(C#,5.19)(D,2.39)(Eb,3.66)(E,2.29)(F,2.88)(F#,6.35)(G,2.23)(Ab,3.48)(A,2.33)(Bb,4.38)(B,4.09)
xbar = 2.5
ybar = 3.4825000000000004
cor(top) = -19.885
cor(bot(x)) = 103.0
cor(bot(y)) = 19.146225
cor(bot) = 44.40789541286549
cor = -0.44778073392415446

computing a correlation ......


pitch profile ...
C10.0 C#0.0 D2.0 Eb0.0 E0.0 F6.0 F#0.0 G3.0 Ab0.0 A4.0 Bb3.0 B2.0
key profile FSHARPminor ...
(C,2.54)(C#,4.75)(D,3.98)(Eb,2.69)(E,3.34)(F,3.17)(F#,6.33)(G,2.68)(Ab,3.52)(A,5.38)(Bb,2.6)(B,3.53)
xbar = 2.5
ybar = 3.709166666666667
cor(top) = -14.475000000000003
cor(bot(x)) = 103.0
cor(bot(y)) = 16.007091666666668
cor(bot) = 40.60456183320621
cor = -0.35648703856132785

computing a correlation ......


pitch profile ...
C10.0 C#0.0 D2.0 Eb0.0 E0.0 F6.0 F#0.0 G3.0 Ab0.0 A4.0 Bb3.0 B2.0
key profile Gmajor ...
(C,4.09)(C#,2.52)(D,5.19)(Eb,2.39)(E,3.66)(F,2.29)(F#,2.88)(G,6.35)(Ab,2.23)(A,3.48)(Bb,2.33)(B,4.38)
xbar = 2.5
ybar = 3.4825
cor(top) = 9.264999999999997
cor(bot(x)) = 103.0
cor(bot(y)) = 19.146224999999998
cor(bot) = 44.40789541286549
cor = 0.20863407089802813

computing a correlation ......


pitch profile ...
C10.0 C#0.0 D2.0 Eb0.0 E0.0 F6.0 F#0.0 G3.0 Ab0.0 A4.0 Bb3.0 B2.0
key profile Gminor ...
(C,3.53)(C#,2.54)(D,4.75)(Eb,3.98)(E,2.69)(F,3.34)(F#,3.17)(G,6.33)(Ab,2.68)(A,3.52)(Bb,5.38)(B,2.6)
xbar = 2.5
ybar = 3.709166666666667
cor(top) = 7.974999999999998
cor(bot(x)) = 103.0
cor(bot(y)) = 16.007091666666668
cor(bot) = 40.60456183320621
cor = 0.19640650311064511

computing a correlation ......


pitch profile ...
C10.0 C#0.0 D2.0 Eb0.0 E0.0 F6.0 F#0.0 G3.0 Ab0.0 A4.0 Bb3.0 B2.0
key profile AFLATmajor ...
(C,4.38)(C#,4.09)(D,2.52)(Eb,5.19)(E,2.39)(F,3.66)(F#,2.29)(G,2.88)(Ab,6.35)(A,2.23)(Bb,3.48)(B,2.33)
xbar = 2.5
ybar = 3.4824999999999995
cor(top) = -1.0150000000000008
cor(bot(x)) = 103.0
cor(bot(y)) = 19.146224999999998
cor(bot) = 44.40789541286549
cor = -0.022856295948353887

computing a correlation ......


pitch profile ...
C10.0 C#0.0 D2.0 Eb0.0 E0.0 F6.0 F#0.0 G3.0 Ab0.0 A4.0 Bb3.0 B2.0
key profile AFLATminor ...
(C,2.6)(C#,3.53)(D,2.54)(Eb,4.75)(E,3.98)(F,2.69)(F#,3.34)(G,3.17)(Ab,6.33)(A,2.68)(Bb,3.52)(B,5.38)
xbar = 2.5
ybar = 3.709166666666667
cor(top) = -22.504999999999995
cor(bot(x)) = 103.0
cor(bot(y)) = 16.007091666666668
cor(bot) = 40.60456183320621
cor = -0.5542480692796324

computing a correlation ......


pitch profile ...
C10.0 C#0.0 D2.0 Eb0.0 E0.0 F6.0 F#0.0 G3.0 Ab0.0 A4.0 Bb3.0 B2.0
key profile Amajor ...
(C,2.33)(C#,4.38)(D,4.09)(Eb,2.52)(E,5.19)(F,2.39)(F#,3.66)(G,2.29)(Ab,2.88)(A,6.35)(Bb,2.23)(B,3.48)
xbar = 2.5
ybar = 3.4824999999999995
cor(top) = -12.735000000000003
cor(bot(x)) = 103.0
cor(bot(y)) = 19.146224999999998
cor(bot) = 44.40789541286549
cor = -0.2867733289677701

computing a correlation ......


pitch profile ...
C10.0 C#0.0 D2.0 Eb0.0 E0.0 F6.0 F#0.0 G3.0 Ab0.0 A4.0 Bb3.0 B2.0
key profile Aminor ...
(C,5.38)(C#,2.6)(D,3.53)(Eb,2.54)(E,4.75)(F,3.98)(F#,2.69)(G,3.34)(Ab,3.17)(A,6.33)(Bb,2.68)(B,3.52)
xbar = 2.5
ybar = 3.709166666666667
cor(top) = 23.88499999999999
cor(bot(x)) = 103.0
cor(bot(y)) = 16.007091666666664
cor(bot) = 40.60456183320621
cor = 0.5882343983445465

computing a correlation ......


pitch profile ...
C10.0 C#0.0 D2.0 Eb0.0 E0.0 F6.0 F#0.0 G3.0 Ab0.0 A4.0 Bb3.0 B2.0
key profile BFLATmajor ...
(C,3.48)(C#,2.33)(D,4.38)(Eb,4.09)(E,2.52)(F,5.19)(F#,2.39)(G,3.66)(Ab,2.29)(A,2.88)(Bb,6.35)(B,2.23)
xbar = 2.5
ybar = 3.4825
cor(top) = 16.235
cor(bot(x)) = 103.0
cor(bot(y)) = 19.146224999999998
cor(bot) = 44.40789541286549
cor = 0.3655881425827833

computing a correlation ......


pitch profile ...
C10.0 C#0.0 D2.0 Eb0.0 E0.0 F6.0 F#0.0 G3.0 Ab0.0 A4.0 Bb3.0 B2.0
key profile BFLATminor ...
(C,3.52)(C#,5.38)(D,2.6)(Eb,3.53)(E,2.54)(F,4.75)(F#,3.98)(G,2.69)(Ab,3.34)(A,3.17)(Bb,6.33)(B,2.68)
xbar = 2.5
ybar = 3.7091666666666665
cor(top) = 2.7250000000000014
cor(bot(x)) = 103.0
cor(bot(y)) = 16.007091666666668
cor(bot) = 40.60456183320621
cor = 0.06711068601586312

computing a correlation ......


pitch profile ...
C10.0 C#0.0 D2.0 Eb0.0 E0.0 F6.0 F#0.0 G3.0 Ab0.0 A4.0 Bb3.0 B2.0
key profile Bmajor ...
(C,2.23)(C#,3.48)(D,2.33)(Eb,4.38)(E,4.09)(F,2.52)(F#,5.19)(G,2.39)(Ab,3.66)(A,2.29)(Bb,2.88)(B,6.35)
xbar = 2.5
ybar = 3.4825000000000004
cor(top) = -24.724999999999998
cor(bot(x)) = 103.0
cor(bot(y)) = 19.146224999999998
cor(bot) = 44.40789541286549
cor = -0.5567703618946299

computing a correlation ......


pitch profile ...
C10.0 C#0.0 D2.0 Eb0.0 E0.0 F6.0 F#0.0 G3.0 Ab0.0 A4.0 Bb3.0 B2.0
key profile Bminor ...
(C,2.68)(C#,3.52)(D,5.38)(Eb,2.6)(E,3.53)(F,2.54)(F#,4.75)(G,3.98)(Ab,2.69)(A,3.34)(Bb,3.17)(B,6.33)
xbar = 2.5
ybar = 3.709166666666667
cor(top) = -11.005
cor(bot(x)) = 103.0
cor(bot(y)) = 16.007091666666668
cor(bot) = 40.60456183320621
cor = -0.271028660405348

Key/Corrolation Table ...


C major 0.75133(2) C minor 0.532329(4)
C# major -0.275964(16) C# minor -0.50056(22)
D major -0.166074(14) D minor 0.344173(7)
Eb major 0.052581(11) Eb minor -0.412392(19)
E major -0.480207(21) E minor -0.032878(13)
F major 0.858293(1)*** F minor 0.399339(5)
F# major -0.447781(20) F# minor -0.356487(18)
G major 0.208634(8) G minor 0.196407(9)
Ab major -0.022856(12) Ab minor -0.554248(23)
A major -0.286773(17) A minor 0.588234(3)
Bb major 0.365588(6) Bb minor 0.067111(10)
B major -0.55677(24) B minor -0.271029(15)

F major

Anaysis

The piece is in the key of F major. The key and the four runners up: F major > C major > A minor > C minor >
F minor.

You might also like