forked from tonaljs/tonal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
41 lines (38 loc) · 1.23 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { tokenize } from "@tonaljs/chord";
import { distance, interval, NoteLiteral, transpose } from "@tonaljs/core";
import { get as romanNumeral } from "@tonaljs/roman-numeral";
/**
* Given a tonic and a chord list expressed with roman numeral notation
* returns the progression expressed with leadsheet chords symbols notation
* @example
* fromRomanNumerals("C", ["I", "IIm7", "V7"]);
* // => ["C", "Dm7", "G7"]
*/
export function fromRomanNumerals(
tonic: NoteLiteral,
chords: string[],
): string[] {
const romanNumerals = chords.map(romanNumeral);
return romanNumerals.map(
(rn) => transpose(tonic, interval(rn)) + rn.chordType,
);
}
/**
* Given a tonic and a chord list with leadsheet symbols notation,
* return the chord list with roman numeral notation
* @example
* toRomanNumerals("C", ["CMaj7", "Dm7", "G7"]);
* // => ["IMaj7", "IIm7", "V7"]
*/
export function toRomanNumerals(
tonic: NoteLiteral,
chords: string[],
): string[] {
return chords.map((chord) => {
const [note, chordType] = tokenize(chord);
const intervalName = distance(tonic, note);
const roman = romanNumeral(interval(intervalName));
return roman.name + chordType;
});
}
export default { fromRomanNumerals, toRomanNumerals };