Conversion between key numbers and note names
tonal-key is a collection of functions to query about tonal keys.
This is part of tonal music theory library.
Example
``js`
// es6
import * as Key from "tonal-key"
// es5
const Key = require("tonal-key")`
Example js`
Key.scale("E mixolydian") // => [ "E", "F#", "G#", "A", "B", "C#", "D" ]
Key.relative("minor", "C major") // => "A minor"
* Key
* .degrees ⇒ Array
* .modeNames(alias) ⇒ Array
* .fromAlter(alt) ⇒ Key
* .props(name) ⇒ Object
* .scale(key) ⇒ Array
* .alteredNotes(key) ⇒ Array
* [.leadsheetSymbols(symbols, keyName, [degrees])](#module_Key.leadsheetSymbols) ⇒ .chords(name, [degrees])function
* [](#module_Key.chords) ⇒ .triads(name, [degrees])Array.<string>
* [](#module_Key.triads) ⇒ .secDomChords(name)Array.<string>
* ⇒ .relative(mode, key)Array
* .tokenize(name)
* ⇒ Array
⇒ ArrayKind: static constant of Key
| Param | Type |
| --- | --- |
| keyName | string |
Example
`js`
Key.degrees("C major") => ["I", "ii", "iii", "IV", "V", "vi", "vii"]
⇒ ArrayKind: static method of Key
Returns: Array - an array of strings
| Param | Type | Description |
| --- | --- | --- |
| alias | Boolean | true to get aliases names |
Example
`js`
Key.modes() // => [ "ionian", "dorian", "phrygian", "lydian",
// "mixolydian", "aeolian", "locrian" ]
Key.modes(true) // => [ "ionian", "dorian", "phrygian", "lydian",
// "mixolydian", "aeolian", "locrian", "major", "minor" ]
⇒ KeyKind: static method of Key
Returns: Key - the key object
| Param | Type | Description |
| --- | --- | --- |
| alt | Integer | the alteration number (positive sharps, negative flats) |
Example
`js`
Key.fromAlter(2) // => "D major"
⇒ Object- name {string}: name
- tonic {string}: key tonic
- mode {string}: key mode
- modenum {Number}: mode number (0 major, 1 dorian, ...)
- intervals {Array}: the scale intervals
- scale {Array}: the scale notes
- acc {string}: accidentals of the key signature
- alt {Number}: alteration number (a numeric representation of accidentals)
Kind: static method of Key
Returns: Object - the key properties object or null if not a valid key
| Param | Type | Description |
| --- | --- | --- |
| name | string | the key name |
Example
`js`
Key.props("C3 dorian") // => { tonic: "C", mode: "dorian", ... }
⇒ ArrayKind: static method of Key
Returns: Array - the key scale
| Param | Type |
| --- | --- |
| key | string \| Object |
Example
`js`
Key.scale("A major") // => [ "A", "B", "C#", "D", "E", "F#", "G#" ]
Key.scale("Bb minor") // => [ "Bb", "C", "Db", "Eb", "F", "Gb", "Ab" ]
Key.scale("C dorian") // => [ "C", "D", "Eb", "F", "G", "A", "Bb" ]
Key.scale("E mixolydian") // => [ "E", "F#", "G#", "A", "B", "C#", "D" ]
⇒ ArrayKind: static method of Key
| Param | Type | Description |
| --- | --- | --- |
| key | string | the key name |
Example
`js`
Key.alteredNotes("Eb major") // => [ "Bb", "Eb", "Ab" ]
⇒ functionThis function is currified (so can be partially applied)
From http://openmusictheory.com/triads.html
A lead-sheet symbol begins with a capital letter (and, if necessary,
an accidental) denoting the root of the chord.
That letter is followed by information about a chord’s quality:
- major triad: no quality symbol is added
- minor triad: lower-case “m”
- diminished triad: lower-case “dim” or a degree sign “°”
- augmented triad: lower-case “aug” or a plus sign “+”
Kind: static method of Key
See
- Key.chords
- Key.triads
| Param | Type | Description |
| --- | --- | --- |
| symbols | Array.<string> | an array of symbols in major scale order |
| keyName | string | the name of the key you want the symbols for |
| [degrees] | Array.<string> | the list of degrees. By default from 1 to 7 in ascending order |
Example
`js`
const chords = Key.leadsheetSymbols(["M", "m", "m", "M", "7", "m", "dim"])
chords("D dorian") //=> ["Dm", "Em", "FM", "G7", "Am", "Bdim", "CM"]
chords("D dorian", ['ii', 'V']) //=> [Em", "G7"]
⇒ Array.<string>Kind: static method of Key
Returns: Array.<string> - seventh chord names
| Param | Type | Description |
| --- | --- | --- |
| name | string | the key name |
| [degrees] | Array.<(number\|string)> | can be numbers or roman numerals |
Example
`js`
Key.chords("A major") // => ["AMaj7", "Bm7", "C#m7", "DMaj7", ..,]
Key.chords("A major", ['I', 'IV', 'V']) // => ["AMaj7", "DMaj7", "E7"]
Key.chords("A major", [5, 4, 1]) // => ["E7", "DMaj7", AMaj7"]
⇒ Array.<string>Kind: static method of Key
Returns: Array.<string> - triad names
| Param | Type | Description |
| --- | --- | --- |
| name | string | the key name |
| [degrees] | Array.<(string\|number)> | |
Example
`js`
Key.triads("A major") // => ["AM", "Bm", "C#m", "DM", "E7", "F#m", "G#mb5"]
Key.triads("A major", ['I', 'IV', 'V']) // => ["AMaj7", "DMaj7", "E7"]
Key.triads("A major", [1, 4, 5]) // => ["AMaj7", "DMaj7", "E7"]
⇒ ArrayKind: static method of Key
| Param | Type | Description |
| --- | --- | --- |
| name | string | the key name |
Example
`js`
Key.secDomChords("A major") // => ["E7", "F#7", ...]
It can be partially applied.
Kind: static method of Key
| Param | Type | Description |
| --- | --- | --- |
| mode | string | the relative destination |
| key | string | the key source |
Example
`js`
Key.relative("dorian", "B major") // => "C# dorian"
// partial application
var minor = Key.relative("minor")
minor("C major") // => "A minor"
minor("E major") // => "C# minor"
⇒ ArrayKind: static method of Key
Returns: Array - an array in the form [tonic, key]
| Param | Type |
| --- | --- |
| name | string |
Example
`js``
Key.tokenize("C major") // => ["C", "major"]