Table of Contents

Class KeyTrajectory

Namespace
Celeritas.Core.Analysis
Assembly
Celeritas.dll

Key changes over time in a piece: the per-window key readings of AnalyzeModulations(NoteBuffer, Rational, Rational), and the modulations judged from the music behind them.

public sealed class KeyTrajectory
Inheritance
KeyTrajectory
Inherited Members

Properties

Points

The per-window detection results: the start position of each analysis window together with the key detected in it, in chronological order.

public IReadOnlyList<(Rational Position, KeyDetectionResult Result)> Points { get; }

Property Value

IReadOnlyList<(Rational Position, KeyDetectionResult Result)>

Methods

DetectModulations()

Detect modulation points: where the music settles in a new key. Each is reported at the start of the whole note in which the new key begins — the first note the old key does not own, moved back to the bar line across notes both keys own — with the key left and the key arrived at.

public IEnumerable<(Rational Position, KeySignature FromKey, KeySignature ToKey)> DetectModulations()

Returns

IEnumerable<(Rational Position, KeySignature FromKey, KeySignature ToKey)>

Remarks

A change is a modulation when a phrase — four bars of the music, read from the music's own pace, or the analysis window when that is longer — read from where the new key begins is decidable, names the new key clearly, fits it better than the key the music was in, sounds a note the new key owns and the old does not, and is owned by the new key — the notes it lacks amounting to less than a quarter of a bar in any bar, its own chromatic chords counted as the key's (an applied chord, a major triad or a dominant seventh resolving down a fifth into a chord of the key; a borrowed chord, a major key's minor subdominant, flat sixth or flat seventh resolving into a chord of the key, both inside a phrase the key's tonic frames; a minor key's Picardy third closing the piece) and its passing tones, neighbour tones and appoggiaturas weighing nothing; when the new key still reads from there through the phrase, or to the end of the piece closing on its tonic from a key the music was still in; and when the new key's own notes return in a second bar before the old key's are heard again, or the phrase is framed by the new tonic chord — in a melody, by a note of the tonic triad at its start and the tonic at its close. A key change that does not hold that long is a tonicization — an applied dominant, a borrowed chord — and is not reported here; ModulationDetector reports those, as Tonicization. The new key begins after the last note it does not own, on a chord of its own — not on one of its applied or borrowed chords: at its pivot chord when the bar before is its, or at the start of the phrase — phrases counted from the first note — in which its own note first sounds, when it owns every bar from there. The opening key is the key of the chord the piece opens on when that key owns the opening phrase as well as any key does, else the key the opening phrase sounds like, extended a phrase at a time while it cannot decide, or the whole piece as a last resort; a change placed at the first note is that key heard better, not a modulation, and so is a change from an opening key read off the profile alone that never sounded a note of its own.

This used to report a modulation at every confident, decidable window whose key differed from the previous such window's — a decision made on one window at a time. At the two-bar window a block-chord passage is read at, a window holds two chords, and two chords read as the key of the pitch class they share: C–F read C, F–G7 read F, G–C read G, D7–G read D. Four bars of I IV V I in C followed by four in D flat came back as four modulations (C to G, G to F minor, F minor to D flat, D flat to A flat); a twelve-bar blues, a minor phrase with its raised leading tone and I V7/V V I came back with three or four each, none of them a modulation; and a bare melody restated a semitone higher came back with none. Judged on forty passages a musician wrote — nursery tunes and textbook modulations in block chords, arpeggios, melody alone and melody over chords — it was wrong on thirty-four; judged by phrase it agrees with the musician on all forty, in every key.

Judged by phrase alone, on sixty-four further passages a reviewer wrote — a pop verse of applied dominants, keys visited for two bars each, a chromatic scale, alternating four-bar areas, real tunes with their chords — it was wrong on eight: a key that left less of a phrase foreign than the key the music was in was taken for the phrase's key, so C Am D7 G | C A7 Dm G7 opened in G and came home at its Dm, a passage visiting D and E for two bars each read as E then F sharp, a chromatic scale in eighths turned to C minor, and C F G C | G C D7 G | C F G C, measured from the D7, held G for two bars and was no modulation at all. A key must own the phrase it is named for, be entered by its own notes returning or by a phrase framed by its tonic, and begin with the phrase in which it is heard; both roads agree with the musician on all sixty-four. Two hundred random diatonic melodies in C, which the profile opens in A minor, E minor or G as readily as in C, reported thirty-six modulations to C; they report none, and two hundred more from another seed, which reported forty-five, report two (melodies whose second half never sounds F, so that G major owns it outright).

With only dominant sevenths counted as a key's applied chords and every note weighed alike, on thirty-eight passages a second reviewer wrote it was wrong on seven, four of them melodies: two chromatic passing eighths in each bar of a G-major melody weighed a quarter of the bar, so a melody alone or over chords with that in every bar named no key; a chromatic quarter-note neighbour under a D7 put G at bar 8 where a musician hears 4, the detector — which never saw the melody's eighths — at 4; a passing F natural in E F F sharp G placed G three eighths into its bar; C F G C | G E Am D7 | G C D7 G and C F G C | G Cm D7 G | G C D7 G reached G two bars late; and Cm Fm G7 Cm | E♭ A♭ B♭ E♭ | Cm A♭ G7 C, closing on a Picardy third, never came home to C minor. A passing tone is not a foreign note, a key's chromatic chords are its own, the Picardy third is the minor key's cadence, and the detector now hears the line its chords carry; both roads agree with the musician on all thirty-eight, and with each other on every passage of the three tables.

On thirty-one passages a third reviewer wrote it was wrong on twelve: a chromatic appoggiatura struck with the chord on every downbeat of the new key, a passing tone inside an arch (G A A♭ G) and a half-note passing tone each named no key; the German sixth in the return's second bar put C minor two bars late; a bar of B flat quoted inside a G phrase put G two bars late; the V/V of a new key that the old key owns (the G of F B♭ G C7, the C of B♭ E♭ C F) and a tonic seventh closing a phrase (B♭ E♭ F B♭7) put the new key a phrase late or named E flat; a 4-3 suspension or a chord tone struck over G's V/ii made it no plain triad; and the V/ii and the borrowed iv arpeggiated in eighths were three foreign eighths a bar. An appoggiatura is defined by its resolution, whether the chord was struck before it or with it; a note where the line turns is structural; a note that leans on a sounding harmony may be long; the augmented sixth and the tonic seventh are a key's chromatic chords; a chord the key in force owns is that key's only while the key stands and the chord's resolution is its own; a key is heard from where its own chords began, a bar of a foreign key inside it a parenthesis; a line note that is a tone of the chord under it is that chord's, and a chord struck as several notes weighs as one; and an arpeggiated chord is that chord. Both roads agree with the musician on all thirty-one, and with each other on every passage of the four tables.

On twenty-three passages a fourth reviewer wrote it was wrong on one: a chorale's two-bar return home, Dm G7 C, sounded no C before its last chord, and a stretch at the end shorter than a phrase had to — so the homecoming was heard as nothing. A return to a key the music has been in is a homecoming, and needs no such confirmation. And on this road a melody over staccato chords — each chord a quarter, then silence — lost its appoggiaturas, the harmony they leaned on having stopped sounding before they resolved, so G began four bars late or not at all where the detector, whose chords then sounded until the next chord, placed it at the bar: a chord's harmony holds until the next chord, a whole note past its notes at most, and a note of the line leans on that. Both roads agree with the musician on all twenty-three, and with each other on every passage of the five tables.

On thirty-three passages a sixth reviewer wrote — accompaniment textures, and the pop loop told either of its keys — it was wrong on five: a bar of silence inside the new key's first phrase put G at bar 9, where a musician hears it from bar 5; the Picardy close with the melody arpeggiating up through the final chord was a modulation to A major; and Am F C G four times was a modulation to C at bar 2 told A minor, and told C too on this road, which opens on the A minor chord where the detector was told C and heard none — the relative major named by the profile with no cadence and no frame. A key is heard from where its phrases began and a silent bar is neither key's, a melody moving through the tones of the closing chord is that chord, and the relative major is confirmed by its cadence or its frame. Both roads agree with the musician on all thirty-three, and with each other on every passage of the seven tables.

On thirty-five passages a seventh reviewer wrote — the pop loops a musician plays every day, told either of their keys; the same loop a tone up; a loop turning into a real move to the relative key; silence around the new key's first phrase; the melody over the Picardy chord — the frame reaching back had swallowed a phrase of V I V I closing on the old tonic (G at bar 5 for bar 9), the cadence that confirms the relative major had been found at the seam of two phrases (C at bar 5 for bar 9), and a scale run or a turn over the closing chord had kept it from ending the piece (a modulation to A major again). A reached-back phrase is framed by the new tonic, opening and closing on it; a confirming cadence closes a phrase of the piece's count; notes on their way by step between the closing chord's tones are that chord's. Both roads agree with the musician on the twenty-four that join the fixture as an eighth table, and with each other on every passage of the eight tables.

Of the seventh reviewer's six passages the library still read otherwise, four are heard now: a minor twelve-bar blues in sevenths opened here in C major — its Am7 read as C6 — and modulated to A minor at its own E7 (a seventh chord opens the key of its root); two bars of silence before the new key were counted as bars of a phrase, and G was a two-bar tonicization (a musician counts the new phrase from the re-entry); a pair of phrases C Dm G Am between A minor's cadences went to C and came home (a loop that comes to rest on the old tonic is the old key's); and the Picardy chord in tremolo eighths was dyads, no Picardy third, and the close was a modulation to A major (a tremolo is the chord it spells whatever its speed). The loop Bm G D A after Am F C G twice, told C, is D major on the detector road (a sequence keeps the reading of its model); this road is told nothing, opens on the A minor chord, and hears B minor, the told-A-minor answer. The relative major from its IV, F G C Am | F G C C after A minor's cadence, is left with its debate: the reviewer plans C from bar 5, the judge hears it from the cadencing phrase at bar 9 with the Am of bar 8 its pivot. Both roads agree with the musician on the twenty-eight of the eighth table, and with each other on every passage of the eight tables.

On forty-seven passages an eighth reviewer wrote — pieces opening on a seventh chord, on ii or IV, told a key they never sound; the same loop moved a fourth, a minor third, a tone and two tones, told either key; a real sequence through three keys; a circle of fifths; three silent bars, a re-entry in the old key; tremolo eighths for a whole passage, on a major close, on the dominant sevenths; a trill on the Picardy third; the relative major's cadence inside a phrase and at its end — the sequence rule had fired on the copy alone and not on its verbatim repeat, so `Am Dm G C` twice then `Bm Em A D` twice, told A minor, was B minor at the copy and D major at the repeat, whose closing A D read from its second chord was the cadence that closes the piece; and `Am Dm G C` four times changed to C at its fourth statement the same way. A phrase repeated is its model at the unison and keeps its key, judged from the phrase a candidate falls in. Both roads agree with the musician on the thirty-five that join the fixture as a ninth table, and with each other on every passage of the nine tables; the four transposed loops told C are the major with vi first on the detector road and the minor on this one, which opens on the A minor chord, as the fact in TheTwoRoadsHearEveryTextureAlikeTests pins road by road.

Of the eighth reviewer's eight passages the library still read otherwise, six are heard now, and the lens's residual besides. The minor blues in sevenths told C was C going to A minor at its E7 on the detector road, where this road heard A minor from bar 1: the given C was taken for opened on, its tonic with a note above it being what Am7 read as — a seventh chord is the tonic of its root's key alone, and a given major key whose tonic chord never sounds in the opening phrase was the caller's guess; C Dm G Am7 twice between A minor's cadences, whose G → Am7 read as C's V–I6, is one key as the loop with a plain A minor triad is. Two silent bars after a fifth bar of tonic — a pause off the phrase grid — and a two-bar fermata after a silent bar each left G a tonicization: a pause between phrases is heard wherever it falls once a phrase has sounded, both counts of the phrases are kept, a fermata closes its phrase, and a held chord's second bar is its own. The Picardy chord as an Alberti bass, restruck in quarters under a melody ending on its second, and in tremolo eighths under a passing tone each closed the piece as a modulation to A major: the closing harmony is what the accompaniment spells, and the tune over it is the line. And the piece opening on IV with its second bar silent, the lens's residual: a phrase that comes to rest on a chord opens in that chord's key, so this road opens F – C C in C as the detector, told C, does. The silent 3/4 bar is heard now: the judge reads the bar from the music's own pace and counts its phrases in 3/4 bars. The two loops Am F G C under a tune whose B rises to C at each close stay one key with A minor's cadences around them, as the same chords do without the tune: the G chord already carries the B, and a phrase opening on the minor's tonic is the minor's; the reviewer plans the major, and the lead decides. Both roads agree with the musician on the forty-one of the ninth table, and with each other on every passage of the nine tables in every texture but the Dorian tune with its second bar silent.

On thirty-four passages a ninth reviewer wrote — a piece told its relative major or minor, its dominant, its subdominant, a tritone away, or the key of its own ii7, vi7 or IVmaj7; a tonic voiced as a sixth chord and followed by plain triads; a half-bar rest, a fermata then silence, a general pause in the new key, silence before the return home; closes decorated with quarters under the seventh and the ninth, tremolo under a passing tone, an appoggiatura; 2/4 half notes; the loops under tunes carrying a leading tone or a raised sixth — a piece whose tonic is voiced as a sixth chord had opened in the relative minor and heard its plain triads as a modulation, the four notes of A C E G being A minor's i7 and C major's tonic with a sixth on it alike. An opening named by a seventh chord is a reading of a voicing, which the music may refute as it refutes a guess. Both roads agree with the musician on twenty-eight of them, and on two of the library's own beside; the thirty join the fixture as a tenth table, and the roads agree with each other on every passage of the ten tables in every texture but the Dorian tune with its second bar silent.

Three more of the reviewer's are heard now. A piece told C that opens on A minor's i7 and moves to C — Am7 Dm7 E7 Am7 | C F G C | C F G7 C — was C throughout on the detector road and A minor going to C at bar 4 on the trajectory: a given key is refuted where the piece opens, the tonic chord that confirms it is looked for in the opening phrase alone, and the margin a change must clear does not guard a caller's guess — a relative pair separate by 0.020, a fifth of it. C F G C | R | G C D7 G over a held dominant pedal had no bar of silence, so the pause between its phrases was never heard and the roads read a two-bar tonicization of G and no change at all: a bar in which nothing is STRUCK is a bar of silence for the phrase count, whatever is still sounding from before, and a fermata — a chord held with nothing struck under it — closes its own phrase as it always did. And a trill in sixteenths over the Picardy chord restruck in quarters closed the piece as a modulation to A major on both roads: a restrike carries the chord's harmony on, and the line over it is looked through against the harmony last struck.

The window no longer limits what is heard: a one-bar window over arpeggiated triads has undecidable points, and the modulation is still found, because the phrase is read from the notes. The points remain the per-window readings they always were.

On thirty-four passages a tenth reviewer wrote — one modulating passage in four metres and a piece that changes metre at its modulation; a pedal that changes with the key, one inner voice held across a silent bar, a chord tied across the pivot, a fermata in the upper voices while the bass rests; a piece told a key whose tonic chord arrives only at the end, told the key of its second chord, told the relative minor of a piece opening on I6, a piece opening on a lone bass note or a bare fifth; the closing chord as a two-hand arpeggio over three octaves, the melody arpeggiating it alone in sixteenths; the loop in 3/4 and over its own pedal; a sequence through three keys in 6/8 — thirty are heard as a musician hears them and join the fixture as an eleventh table. The judge reads the bar from the music's own pace, so the same passage is heard at its own fifth bar in 4/4, 3/4, 6/8, 5/4 and 12/8 alike, and in 2/4 while it stays where it goes (a 2/4 piece of four-bar sections that comes home is among the limitations below), and a slow piece of two-whole-note chords is heard at all; a pedal is one note under the harmony and no longer outweighs what is played over it; the closing figure may lie above the tune as well as below it; and the bar a phrase closes on in the key it leaves is that key's cadence and no pivot, which moved every Picardy close and every homecoming of the fixture to the bar its own phrase begins in. Two are not heard: a 3/4 piece whose phrases are three bars where the judge's are four, and the Picardy close with the tune crossing below the figure, both in eighths.

On thirty-eight passages an eleventh reviewer wrote — the same modulating passage in 9/8, 5/8, 7/8, 2/2 and 6/8, a rubato, a pickup, a waltz, an oom-pah and an Alberti bass; four pedals held and one struck again at every bar line; the closing chord rolled upwards, downwards and over two bars, and figures sharing the tune's register; pieces told C that open on vi, iii and ii — thirty-three are heard as a musician hears them and join the fixture as a twelfth table. This road is told nothing and guesses its opening key, so the openings were its own to answer: vi, iii and ii are chords of a key and not keys, and Am Dm G7 C | C F G C | C F G7 C, which opened here on the A minor chord and reported C at bar 3, is C throughout as it is to the detector told C.

On thirty more a twelfth reviewer wrote — ordinary music only: pieces told a key they open away from, closes as they are actually written, pedals as they are actually played, and the everyday shapes of hymn, waltz, blues, pop loop, march and folk tune — all thirty are heard as a musician hears them and join the fixture as a thirteenth table. This road is told nothing and guesses its opening key, so the openings were again its own to answer: the chord a piece opens on is a chord of its key before it is a key, whichever its mode, and III and VI of a minor key are its chords as vi and iii are the major's — C G Am E7 | Am Dm E7 Am | Am Dm E7 Am, which opened here in C major and reported A minor at bar 3, is A minor throughout with a III first; a loop is a chord coming back at the music's own phrase length and not a chord that sounds once more somewhere later, so the pop loop Am F C G7 three times over closing on C F G7 C, which opened here in A minor and reported C at bar 12, is C with a vi first; and a pedal is one note under the harmony however often it is struck, so a tonic strummed on every beat or repeated in eighths is heard as one is that is struck once a bar. Six shapes are known and unheard, and are written up in the judge's own remarks (Celeritas.Core.Analysis.KeyAreaJudge): the bar of chords of irregular length in no pattern, and of a melody alone — where this road, which guesses its key from a profile the clock's bars cut wrong, hears no change at all and the detector told the key hears the musician's answer; the close under a tune as quick as the figure — a two-hand arpeggio in sixteenths under a trill, and a tune in eighths above the held chord outlining its upper thirds; a pedal struck an eighth before the first chord, which sounds alone at its onset and is therefore a note of the line; and the piece whose opening phrase is the relative major's and whose rest is the minor's, told the major — C G Am E7 | Am Dm E7 Am | Am Dm E7 Am told C, where this road, told nothing, hears one key in A minor as a musician told nothing does, and the detector, told C, hears A minor at bar 3 as a musician told C does; the piece in 2/4 that leaves and comes home, whose four-bar sections are two whole notes and shorter than the evidence a key is asked for — a march or a polka in block chords or oom-pah alike; and the bass note struck once a bar under a broken-chord accompaniment, which makes a chord of its own with the notes above it where the same note held, or taken away, is heard rightly. There is no further iteration of this work: those six are the library's documented limits.