@tonaljs/key
Version:
Functions to work with musical keys
79 lines (77 loc) • 2.67 kB
TypeScript
interface Key {
readonly type: "major" | "minor";
readonly tonic: string;
readonly alteration: number;
readonly keySignature: string;
}
interface KeyScale {
readonly tonic: string;
readonly grades: readonly string[];
readonly intervals: readonly string[];
readonly scale: readonly string[];
readonly triads: readonly string[];
readonly chords: readonly string[];
readonly chordsHarmonicFunction: readonly string[];
readonly chordScales: readonly string[];
readonly secondaryDominants: readonly string[];
readonly secondaryDominantSupertonics: readonly string[];
readonly substituteDominants: readonly string[];
readonly substituteDominantSupertonics: readonly string[];
readonly secondaryDominantsMinorRelative: readonly string[];
readonly substituteDominantsMinorRelative: readonly string[];
}
interface MajorKey extends Key, KeyScale {
readonly type: "major";
readonly minorRelative: string;
readonly scale: readonly string[];
readonly substituteDominants: readonly string[];
readonly secondaryDominantSupertonics: readonly string[];
readonly substituteDominantsMinorRelative: readonly string[];
}
interface MinorKey extends Key {
readonly type: "minor";
readonly relativeMajor: string;
readonly natural: KeyScale;
readonly harmonic: KeyScale;
readonly melodic: KeyScale;
}
type KeyChord = {
name: string;
roles: string[];
};
/**
* Get a major key properties in a given tonic
* @param tonic
*/
declare function majorKey(tonic: string): MajorKey;
/**
* Get a list of available chords for a given major key
* @param tonic
* @returns array of { name: string, roles: string[] }
*/
declare function majorKeyChords(tonic: string): KeyChord[];
/**
* Get a list of available chords for a given major key
* @param tonic
* @returns array of { name: string, roles: string[] }
*/
declare function minorKeyChords(tonic: string): KeyChord[];
/**
* Get minor key properties in a given tonic
* @param tonic
*/
declare function minorKey(tnc: string): MinorKey;
/**
* Given a key signature, returns the tonic of the major key
* @param signature
* @example
* majorTonicFromKeySignature('###') // => 'A'
*/
declare function majorTonicFromKeySignature(sig: string | number): string | null;
/** @deprecated */
declare const _default: {
majorKey: typeof majorKey;
majorTonicFromKeySignature: typeof majorTonicFromKeySignature;
minorKey: typeof minorKey;
};
export { type Key, type KeyChord, type KeyScale, type MajorKey, type MinorKey, _default as default, majorKey, majorKeyChords, majorTonicFromKeySignature, minorKey, minorKeyChords };