@libraz/libcantus - v1.1.0
    Preparing search index...

    Function enharmonicKeyOf

    • The same sounding key written the other way round the circle of fifths, or null when it has no second spelling.

      Twelve fifths is one enharmonic turn of the circle, so a tonic's alternative spelling sits at its own position ±12: Db (-5) is also C# (+7). It is offered only when the key is actually written there, by the same test spelledKeyOf spells with. That is why C major is alone while Db major and F# major each answer with their twin: Eb major's twin would be D# major and its nine sharps, and pitch class 3 altered is written D# but never Eb, which would need two double flats to say the same thing.

      The answer is therefore always a spelling the key is written on, which makes the relation its own inverse for such a key. A key spelled some other way — a tonic a transposition drove out to Ebb, say — still names its written twin, so this is also the way back from a spelling no one writes.

      The relation respells rather than moves, so the mask is kept: the other spelling of C# lydian is Db lydian, and its root pitch class is the one it was handed.

      Parameters

      • tonic: NoteLike

        The spelled tonic of the key, as a note name, note data, or a Note.

      • key: KeyLike

        The key/scale, as a key name, a key/scale, or a Key; its mask decides the mode the tonic is read in, and is carried into the result.

      Returns ResolvedKey | null

      The other spelling of the key, or null when it is not written.

      If the tonic or the mask is malformed.

      import { enharmonicKeyOf, formatNote, majorKey, parseNote } from '@libraz/libcantus';
      const other = enharmonicKeyOf(parseNote('Db'), majorKey(1));
      other === null ? 'none' : formatNote(other.tonic); // 'C#'
      enharmonicKeyOf('C', majorKey(0)); // null