@libraz/libcantus 0.9.2 → 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -5
- package/dist/analyze/index.cjs +41 -1676
- package/dist/analyze/index.cjs.map +1 -1
- package/dist/analyze/index.d.cts +194 -122
- package/dist/analyze/index.d.ts +194 -122
- package/dist/analyze/index.js +19 -8
- package/dist/chunk-36N73KZ3.cjs +246 -0
- package/dist/chunk-36N73KZ3.cjs.map +1 -0
- package/dist/chunk-4HLLZPXT.cjs +3077 -0
- package/dist/chunk-4HLLZPXT.cjs.map +1 -0
- package/dist/chunk-7MGZ7D62.cjs +498 -0
- package/dist/chunk-7MGZ7D62.cjs.map +1 -0
- package/dist/{chunk-R3S2LUBH.js → chunk-7NKDPF74.js} +660 -305
- package/dist/chunk-7NKDPF74.js.map +1 -0
- package/dist/chunk-CAN76NCU.cjs +679 -0
- package/dist/chunk-CAN76NCU.cjs.map +1 -0
- package/dist/{chunk-7Y7WF64D.js → chunk-D2FAJBYL.js} +104 -35
- package/dist/chunk-D2FAJBYL.js.map +1 -0
- package/dist/{chunk-COKTX2G5.js → chunk-EHVEBWM5.js} +1052 -510
- package/dist/chunk-EHVEBWM5.js.map +1 -0
- package/dist/chunk-FCANXBAT.cjs +30 -0
- package/dist/chunk-FCANXBAT.cjs.map +1 -0
- package/dist/chunk-FNDWXRRI.cjs +479 -0
- package/dist/chunk-FNDWXRRI.cjs.map +1 -0
- package/dist/{chunk-GQKN5KDT.js → chunk-GQSGS2N4.js} +43 -29
- package/dist/chunk-GQSGS2N4.js.map +1 -0
- package/dist/chunk-HKGYCQ34.js +53 -0
- package/dist/chunk-HKGYCQ34.js.map +1 -0
- package/dist/chunk-I24MV65U.js +106 -0
- package/dist/chunk-I24MV65U.js.map +1 -0
- package/dist/{chunk-LN7ZZMD2.js → chunk-KMHOICIY.js} +322 -173
- package/dist/chunk-KMHOICIY.js.map +1 -0
- package/dist/chunk-LW53AHQU.cjs +1117 -0
- package/dist/chunk-LW53AHQU.cjs.map +1 -0
- package/dist/chunk-N6IHQUOX.js +1 -0
- package/dist/chunk-N6IHQUOX.js.map +1 -0
- package/dist/chunk-NKIBQ6PT.js +30 -0
- package/dist/chunk-NKIBQ6PT.js.map +1 -0
- package/dist/chunk-NP4NA2FB.cjs +106 -0
- package/dist/chunk-NP4NA2FB.cjs.map +1 -0
- package/dist/chunk-NVE34YGZ.cjs +1449 -0
- package/dist/chunk-NVE34YGZ.cjs.map +1 -0
- package/dist/{chunk-A4532ZFR.js → chunk-NYYWMV2C.js} +115 -47
- package/dist/chunk-NYYWMV2C.js.map +1 -0
- package/dist/{chunk-5HTNMQW4.js → chunk-Q2XUP227.js} +310 -118
- package/dist/chunk-Q2XUP227.js.map +1 -0
- package/dist/chunk-Q6OP4U43.cjs +327 -0
- package/dist/chunk-Q6OP4U43.cjs.map +1 -0
- package/dist/chunk-RC6GBMCD.cjs +845 -0
- package/dist/chunk-RC6GBMCD.cjs.map +1 -0
- package/dist/{chunk-XTC3X6MS.js → chunk-RK35RIN7.js} +453 -152
- package/dist/chunk-RK35RIN7.js.map +1 -0
- package/dist/chunk-RUMU3UA6.cjs +53 -0
- package/dist/chunk-RUMU3UA6.cjs.map +1 -0
- package/dist/chunk-T64C7ZD7.cjs +1 -0
- package/dist/chunk-T64C7ZD7.cjs.map +1 -0
- package/dist/chunk-XEBG3G53.js +498 -0
- package/dist/chunk-XEBG3G53.js.map +1 -0
- package/dist/chunk-YLEMGEFH.js +246 -0
- package/dist/chunk-YLEMGEFH.js.map +1 -0
- package/dist/chunk-ZEJR4TKL.cjs +173 -0
- package/dist/chunk-ZEJR4TKL.cjs.map +1 -0
- package/dist/core/index.cjs +130 -431
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +331 -17
- package/dist/core/index.d.ts +331 -17
- package/dist/core/index.js +71 -13
- package/dist/{function-2bJW1Zp_.d.ts → function-BtiZb9i9.d.ts} +28 -7
- package/dist/{function-r2sh-jOO.d.cts → function-DNugAOrt.d.cts} +28 -7
- package/dist/generate/index.cjs +30 -3751
- package/dist/generate/index.cjs.map +1 -1
- package/dist/generate/index.d.cts +373 -59
- package/dist/generate/index.d.ts +373 -59
- package/dist/generate/index.js +23 -9
- package/dist/{index-DZ1M21do.d.cts → index-6VR8-kit.d.ts} +20 -4
- package/dist/index-70p168VM.d.ts +192 -0
- package/dist/{index-D_ZTUNKp.d.cts → index-Be74mcon.d.cts} +18 -17
- package/dist/index-BtXT6UQ0.d.cts +192 -0
- package/dist/{index-BMPxwjwV.d.ts → index-C5UBbQ4G.d.ts} +18 -17
- package/dist/{index-BOBXBNwP.d.cts → index-C83mZI1P.d.ts} +93 -8
- package/dist/{index-BdeQ1r_p.d.cts → index-D6b6na69.d.cts} +14 -11
- package/dist/{index-Cl7mhOFM.d.cts → index-DXd9JikN.d.cts} +92 -10
- package/dist/{index-Cl7mhOFM.d.ts → index-DXd9JikN.d.ts} +92 -10
- package/dist/index-OG65ocOr.d.cts +272 -0
- package/dist/index-OG65ocOr.d.ts +272 -0
- package/dist/{index-BreoJRw0.d.ts → index-tJhkmQgE.d.cts} +20 -4
- package/dist/{index-CP3wAfEH.d.ts → index-tSQh-xwY.d.ts} +14 -11
- package/dist/{index-CM5W4rcm.d.ts → index-y_ak9_Hi.d.cts} +93 -8
- package/dist/index.cjs +419 -6848
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -13
- package/dist/index.d.ts +14 -13
- package/dist/index.js +132 -27
- package/dist/model/index.cjs +8 -2423
- package/dist/model/index.cjs.map +1 -1
- package/dist/model/index.d.cts +433 -74
- package/dist/model/index.d.ts +433 -74
- package/dist/model/index.js +6 -7
- package/dist/styled-DIRkk9Uz.d.ts +506 -0
- package/dist/styled-DJbkJQfj.d.cts +506 -0
- package/dist/theory/index.cjs +172 -1676
- package/dist/theory/index.cjs.map +1 -1
- package/dist/theory/index.d.cts +151 -233
- package/dist/theory/index.d.ts +151 -233
- package/dist/theory/index.js +31 -7
- package/dist/{types-MGP29r3t.d.cts → types-BN6_Q9Kl.d.cts} +11 -2
- package/dist/{types-MGP29r3t.d.ts → types-BN6_Q9Kl.d.ts} +11 -2
- package/package.json +73 -24
- package/dist/chunk-5HTNMQW4.js.map +0 -1
- package/dist/chunk-7Y7WF64D.js.map +0 -1
- package/dist/chunk-A4532ZFR.js.map +0 -1
- package/dist/chunk-BHUT2S5G.js +0 -22
- package/dist/chunk-BHUT2S5G.js.map +0 -1
- package/dist/chunk-CCBLVAPK.js +0 -42
- package/dist/chunk-CCBLVAPK.js.map +0 -1
- package/dist/chunk-COKTX2G5.js.map +0 -1
- package/dist/chunk-DYWFNC4A.js +0 -152
- package/dist/chunk-DYWFNC4A.js.map +0 -1
- package/dist/chunk-GQKN5KDT.js.map +0 -1
- package/dist/chunk-LN7ZZMD2.js.map +0 -1
- package/dist/chunk-MSWFZF7J.js +0 -118
- package/dist/chunk-MSWFZF7J.js.map +0 -1
- package/dist/chunk-R3S2LUBH.js.map +0 -1
- package/dist/chunk-SDM3VJJ5.js +0 -41
- package/dist/chunk-SDM3VJJ5.js.map +0 -1
- package/dist/chunk-XTC3X6MS.js.map +0 -1
- package/dist/chunk-ZXW5YIWK.js +0 -55
- package/dist/chunk-ZXW5YIWK.js.map +0 -1
- package/dist/index-CGMZNCx6.d.cts +0 -140
- package/dist/index-CGMZNCx6.d.ts +0 -140
- package/dist/styled-BjXtOFNk.d.cts +0 -282
- package/dist/styled-D7BAx3S3.d.ts +0 -282
- package/src/analyze/arrange/index.ts +0 -21
- package/src/analyze/arrange/internal.ts +0 -125
- package/src/analyze/arrange/tension.ts +0 -187
- package/src/analyze/arrange/tracks.ts +0 -279
- package/src/analyze/detect/index.ts +0 -235
- package/src/analyze/functional/borrowed.ts +0 -84
- package/src/analyze/functional/cadence.ts +0 -66
- package/src/analyze/functional/function.ts +0 -184
- package/src/analyze/functional/index.ts +0 -23
- package/src/analyze/functional/internal.ts +0 -29
- package/src/analyze/functional/roman.ts +0 -393
- package/src/analyze/index.ts +0 -49
- package/src/analyze/timeline/index.ts +0 -415
- package/src/analyze/voice/index.ts +0 -330
- package/src/core/index.ts +0 -47
- package/src/core/interval/index.ts +0 -81
- package/src/core/meter/index.ts +0 -282
- package/src/core/pitch/index.ts +0 -311
- package/src/core/random/index.ts +0 -53
- package/src/core/tuning/index.ts +0 -156
- package/src/core/types.ts +0 -29
- package/src/generate/bass/index.ts +0 -350
- package/src/generate/countermelody/index.ts +0 -379
- package/src/generate/drums/beat.ts +0 -266
- package/src/generate/drums/euclid.ts +0 -58
- package/src/generate/drums/fills.ts +0 -356
- package/src/generate/drums/ghost.ts +0 -119
- package/src/generate/drums/hihat.ts +0 -285
- package/src/generate/drums/hit.ts +0 -31
- package/src/generate/drums/index.ts +0 -329
- package/src/generate/drums/internal.ts +0 -257
- package/src/generate/drums/kick.ts +0 -160
- package/src/generate/drums/percussion.ts +0 -121
- package/src/generate/drums/rng.ts +0 -7
- package/src/generate/drums/swing.ts +0 -71
- package/src/generate/groove/index.ts +0 -326
- package/src/generate/harmonize/index.ts +0 -440
- package/src/generate/index.ts +0 -59
- package/src/generate/motif/index.ts +0 -398
- package/src/generate/progression/index.ts +0 -370
- package/src/generate/reharmony/index.ts +0 -330
- package/src/generate/rhythm/index.ts +0 -165
- package/src/index.ts +0 -247
- package/src/model/chord.ts +0 -423
- package/src/model/index.ts +0 -15
- package/src/model/interval.ts +0 -82
- package/src/model/key.ts +0 -266
- package/src/model/note.ts +0 -176
- package/src/model/progression.ts +0 -161
- package/src/model/shared.ts +0 -12
- package/src/theory/chord/index.ts +0 -373
- package/src/theory/chordscale/index.ts +0 -374
- package/src/theory/counterpoint/index.ts +0 -230
- package/src/theory/harmony/index.ts +0 -92
- package/src/theory/index.ts +0 -107
- package/src/theory/safety/index.ts +0 -419
- package/src/theory/scale/degrees.ts +0 -123
- package/src/theory/scale/index.ts +0 -28
- package/src/theory/scale/key.ts +0 -56
- package/src/theory/scale/masks.ts +0 -153
- package/src/theory/spelling/index.ts +0 -182
- package/src/theory/symbol/index.ts +0 -268
- package/src/theory/voicing/index.ts +0 -5
- package/src/theory/voicing/internal.ts +0 -168
- package/src/theory/voicing/leading.ts +0 -112
- package/src/theory/voicing/satb.ts +0 -195
- package/src/theory/voicing/styled.ts +0 -176
- package/tsconfig.json +0 -23
|
@@ -1,393 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Roman-numeral parsing and formatting.
|
|
3
|
-
*
|
|
4
|
-
* The {@link ROMAN_STYLE} table is the single source of truth for both
|
|
5
|
-
* directions, so {@link chordToRoman} and {@link romanToChord} stay mutual
|
|
6
|
-
* inverses by construction.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { KeyScale } from '../../core/types.js';
|
|
10
|
-
import type { Chord, ChordQuality } from '../../theory/chord/index.js';
|
|
11
|
-
import { makeChord } from '../../theory/chord/index.js';
|
|
12
|
-
import { majorKey, scaleTonesInDegreeOrder } from '../../theory/scale/index.js';
|
|
13
|
-
import { degreeRootPc, mod12 } from './internal.js';
|
|
14
|
-
|
|
15
|
-
/** Roman numeral glyphs indexed by degree number - 1. */
|
|
16
|
-
const ROMAN = ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII'] as const;
|
|
17
|
-
|
|
18
|
-
/** Roman glyph -> degree number (1..7). */
|
|
19
|
-
const ROMAN_TO_DEGREE: Record<string, number> = {
|
|
20
|
-
I: 1,
|
|
21
|
-
II: 2,
|
|
22
|
-
III: 3,
|
|
23
|
-
IV: 4,
|
|
24
|
-
V: 5,
|
|
25
|
-
VI: 6,
|
|
26
|
-
VII: 7,
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/** Major-key Roman spelling for each semitone offset above the tonic. */
|
|
30
|
-
const OFFSET_SPELLING: readonly [number, string][] = [
|
|
31
|
-
[1, ''],
|
|
32
|
-
[2, 'b'],
|
|
33
|
-
[2, ''],
|
|
34
|
-
[3, 'b'],
|
|
35
|
-
[3, ''],
|
|
36
|
-
[4, ''],
|
|
37
|
-
[4, '#'],
|
|
38
|
-
[5, ''],
|
|
39
|
-
[6, 'b'],
|
|
40
|
-
[6, ''],
|
|
41
|
-
[7, 'b'],
|
|
42
|
-
[7, ''],
|
|
43
|
-
];
|
|
44
|
-
|
|
45
|
-
/** Choose a seventh-chord quality from a triad label and the numeral case. */
|
|
46
|
-
function seventhQuality(base: 'maj' | 'min' | 'dim' | 'aug', halfDim: boolean): ChordQuality {
|
|
47
|
-
if (halfDim) {
|
|
48
|
-
return 'm7b5';
|
|
49
|
-
}
|
|
50
|
-
if (base === 'dim') {
|
|
51
|
-
return 'dim7';
|
|
52
|
-
}
|
|
53
|
-
if (base === 'aug') {
|
|
54
|
-
return 'aug7';
|
|
55
|
-
}
|
|
56
|
-
return base === 'maj' ? 'dom7' : 'min7';
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** Figure strings that denote a recognized figured-bass inversion. */
|
|
60
|
-
const INVERSION_FIGURES = new Set(['6', '64', '65', '43', '42', '2', '7']);
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Canonical Roman-numeral rendering (numeral case and quality suffix) for every
|
|
64
|
-
* supported chord quality. The table is the single source of truth for both
|
|
65
|
-
* directions: {@link chordToRoman} renders from it and {@link romanToChord}
|
|
66
|
-
* recognizes its exact case-sensitive suffixes, so the two stay mutual
|
|
67
|
-
* inverses by construction. Suffixes are chosen to never collide with
|
|
68
|
-
* figured-bass inversion digits (`6`, `64`, `65`, `43`, `42`, `2`) — the added
|
|
69
|
-
* sixth is `add6`, the six-nine chord is `69` — and each (case, suffix) pair is
|
|
70
|
-
* unique.
|
|
71
|
-
*/
|
|
72
|
-
const ROMAN_STYLE: Record<ChordQuality, { lower: boolean; suffix: string }> = {
|
|
73
|
-
maj: { lower: false, suffix: '' },
|
|
74
|
-
min: { lower: true, suffix: '' },
|
|
75
|
-
dim: { lower: true, suffix: 'o' },
|
|
76
|
-
aug: { lower: false, suffix: '+' },
|
|
77
|
-
maj7: { lower: false, suffix: 'maj7' },
|
|
78
|
-
min7: { lower: true, suffix: '7' },
|
|
79
|
-
dom7: { lower: false, suffix: '7' },
|
|
80
|
-
dim7: { lower: true, suffix: 'o7' },
|
|
81
|
-
m7b5: { lower: true, suffix: 'ø7' },
|
|
82
|
-
minMaj7: { lower: true, suffix: 'maj7' },
|
|
83
|
-
aug7: { lower: false, suffix: '+7' },
|
|
84
|
-
augMaj7: { lower: false, suffix: '+maj7' },
|
|
85
|
-
majb5: { lower: false, suffix: 'b5' },
|
|
86
|
-
'6': { lower: false, suffix: 'add6' },
|
|
87
|
-
min6: { lower: true, suffix: 'add6' },
|
|
88
|
-
'6/9': { lower: false, suffix: '69' },
|
|
89
|
-
sus2: { lower: false, suffix: 'sus2' },
|
|
90
|
-
sus4: { lower: false, suffix: 'sus4' },
|
|
91
|
-
add9: { lower: false, suffix: 'add9' },
|
|
92
|
-
add11: { lower: false, suffix: 'add11' },
|
|
93
|
-
maj9: { lower: false, suffix: 'maj9' },
|
|
94
|
-
min9: { lower: true, suffix: '9' },
|
|
95
|
-
dom9: { lower: false, suffix: '9' },
|
|
96
|
-
'7b9': { lower: false, suffix: '7b9' },
|
|
97
|
-
'7#9': { lower: false, suffix: '7#9' },
|
|
98
|
-
'7#11': { lower: false, suffix: '7#11' },
|
|
99
|
-
'7b13': { lower: false, suffix: '7b13' },
|
|
100
|
-
'11': { lower: false, suffix: '11' },
|
|
101
|
-
'13': { lower: false, suffix: '13' },
|
|
102
|
-
'5': { lower: false, suffix: '5' },
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
/** Reverse lookup of {@link ROMAN_STYLE}: `(case, exact suffix) -> quality`. */
|
|
106
|
-
const SUFFIX_QUALITY: ReadonlyMap<string, ChordQuality> = new Map(
|
|
107
|
-
(Object.entries(ROMAN_STYLE) as [ChordQuality, { lower: boolean; suffix: string }][]).map(
|
|
108
|
-
([quality, style]) => [`${style.lower ? 'l' : 'u'}:${style.suffix}`, quality],
|
|
109
|
-
),
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
/** Read figured-bass digits into a chord inversion and whether a seventh is implied. */
|
|
113
|
-
function parseInversion(figures: string): { inversion: number; seventh: boolean } {
|
|
114
|
-
if (figures === '65') {
|
|
115
|
-
return { inversion: 1, seventh: true };
|
|
116
|
-
}
|
|
117
|
-
if (figures === '43') {
|
|
118
|
-
return { inversion: 2, seventh: true };
|
|
119
|
-
}
|
|
120
|
-
if (figures === '42' || figures === '2') {
|
|
121
|
-
return { inversion: 3, seventh: true };
|
|
122
|
-
}
|
|
123
|
-
if (figures === '7') {
|
|
124
|
-
return { inversion: 0, seventh: true };
|
|
125
|
-
}
|
|
126
|
-
if (figures === '64') {
|
|
127
|
-
return { inversion: 2, seventh: false };
|
|
128
|
-
}
|
|
129
|
-
if (figures === '6') {
|
|
130
|
-
return { inversion: 1, seventh: false };
|
|
131
|
-
}
|
|
132
|
-
return { inversion: 0, seventh: false };
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/** Parse a Roman numeral (no secondary '/') into a root, quality, and inversion. */
|
|
136
|
-
function parseSimpleRoman(
|
|
137
|
-
text: string,
|
|
138
|
-
key: KeyScale,
|
|
139
|
-
): { rootPc: number; quality: ChordQuality; inversion: number } {
|
|
140
|
-
const match = /^([b#]?)([iIvV]+)(.*)$/.exec(text.trim());
|
|
141
|
-
if (!match) {
|
|
142
|
-
throw new Error(`Invalid Roman numeral: ${text}`);
|
|
143
|
-
}
|
|
144
|
-
const accidental = match[1] === 'b' ? -1 : match[1] === '#' ? 1 : 0;
|
|
145
|
-
const glyph = (match[2] ?? '').toUpperCase();
|
|
146
|
-
const degreeNumber = ROMAN_TO_DEGREE[glyph];
|
|
147
|
-
if (degreeNumber === undefined) {
|
|
148
|
-
throw new Error(`Invalid Roman numeral: ${text}`);
|
|
149
|
-
}
|
|
150
|
-
const isUpper = (match[2] ?? '')[0] === (match[2] ?? '')[0]?.toUpperCase();
|
|
151
|
-
const suffix = match[3] ?? '';
|
|
152
|
-
const rootPc = mod12(degreeRootPc(degreeNumber, key) + accidental);
|
|
153
|
-
|
|
154
|
-
// Canonical quality suffixes (exact match, case-sensitive on the numeral)
|
|
155
|
-
// come first so every chordToRoman rendering re-parses to the same quality:
|
|
156
|
-
// `V9` -> dom9 but `ii9` -> min9 and `Imaj9` -> maj9, and added-tone suffixes
|
|
157
|
-
// whose digits would otherwise be misread as figured bass (`Iadd6`, `I69`,
|
|
158
|
-
// `Isus2`, `Iadd11`) resolve to their qualities in root position.
|
|
159
|
-
const canonical = SUFFIX_QUALITY.get(`${isUpper ? 'u' : 'l'}:${suffix}`);
|
|
160
|
-
if (canonical !== undefined) {
|
|
161
|
-
return { rootPc, quality: canonical, inversion: 0 };
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const isDim = /o|°|dim/.test(suffix);
|
|
165
|
-
const isAug = /\+|aug/.test(suffix);
|
|
166
|
-
const isHalfDim = /ø/.test(suffix);
|
|
167
|
-
const explicitMaj7 = /maj7|M7/.test(suffix);
|
|
168
|
-
const figures = suffix.replace(/maj7|M7/g, '').replace(/[^0-9]/g, '');
|
|
169
|
-
|
|
170
|
-
// Reject figure strings that are neither a known figured-bass inversion nor a
|
|
171
|
-
// canonical quality suffix rather than silently degrading to a root triad.
|
|
172
|
-
if (figures !== '' && !INVERSION_FIGURES.has(figures)) {
|
|
173
|
-
throw new Error(`Unsupported figured-bass or extension "${figures}" in Roman numeral: ${text}`);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const { inversion, seventh } = parseInversion(figures);
|
|
177
|
-
// The ø glyph is the half-diminished seventh by definition (there is no
|
|
178
|
-
// half-diminished triad), so it always implies a seventh.
|
|
179
|
-
const hasSeventh = explicitMaj7 || seventh || isHalfDim;
|
|
180
|
-
|
|
181
|
-
let base: 'maj' | 'min' | 'dim' | 'aug';
|
|
182
|
-
if (isDim || isHalfDim) {
|
|
183
|
-
base = 'dim';
|
|
184
|
-
} else if (isAug) {
|
|
185
|
-
base = 'aug';
|
|
186
|
-
} else {
|
|
187
|
-
base = isUpper ? 'maj' : 'min';
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
let quality: ChordQuality;
|
|
191
|
-
if (explicitMaj7) {
|
|
192
|
-
quality = base === 'min' ? 'minMaj7' : base === 'aug' ? 'augMaj7' : 'maj7';
|
|
193
|
-
} else if (hasSeventh) {
|
|
194
|
-
quality = seventhQuality(base, isHalfDim);
|
|
195
|
-
} else if (base === 'dim') {
|
|
196
|
-
quality = 'dim';
|
|
197
|
-
} else if (base === 'aug') {
|
|
198
|
-
quality = 'aug';
|
|
199
|
-
} else {
|
|
200
|
-
quality = base;
|
|
201
|
-
}
|
|
202
|
-
return { rootPc, quality, inversion };
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/** Build a chord from a parsed Roman numeral, attaching a bass for inversions. */
|
|
206
|
-
function chordFromParsed(parsed: {
|
|
207
|
-
rootPc: number;
|
|
208
|
-
quality: ChordQuality;
|
|
209
|
-
inversion: number;
|
|
210
|
-
}): Chord {
|
|
211
|
-
const chord = makeChord(parsed.rootPc, parsed.quality);
|
|
212
|
-
if (parsed.inversion > 0 && parsed.inversion < chord.intervals.length) {
|
|
213
|
-
chord.bassPc = mod12(parsed.rootPc + (chord.intervals[parsed.inversion] ?? 0));
|
|
214
|
-
}
|
|
215
|
-
return chord;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Build the chord denoted by a Roman numeral in a key.
|
|
220
|
-
*
|
|
221
|
-
* Supports accidentals (`bVII`, `#iv`), case-based triad quality, the `o`/`ø`/`+`
|
|
222
|
-
* suffixes, sevenths (`V7`, `viio7`, `Imaj7`), figured-bass inversions
|
|
223
|
-
* (`V6`, `V64`, `V65`, `V43`, `V42`), and applied/secondary chords via a slash
|
|
224
|
-
* (`V7/V`, `viio/ii`). The target after the slash is read as a scale degree
|
|
225
|
-
* whose root becomes a local major tonic for the applied chord. Inverted chords
|
|
226
|
-
* carry a `bassPc`.
|
|
227
|
-
*
|
|
228
|
-
* The `ø` glyph always denotes the half-diminished seventh (`iiø` == `iiø7` ==
|
|
229
|
-
* `m7b5`), since no half-diminished triad exists. Extension and added-tone
|
|
230
|
-
* suffixes are the canonical case-sensitive forms emitted by
|
|
231
|
-
* {@link chordToRoman} and honor the numeral case: `V9` -> `dom9`, `ii9` ->
|
|
232
|
-
* `min9`, `Imaj9` -> `maj9`, `V11` -> `11`, `V13` -> `13`, `Iadd6`/`iadd6` ->
|
|
233
|
-
* `6`/`min6`, `I69` -> `6/9`, `Isus2`/`Isus4`, `Iadd9`/`Iadd11`, `Ib5` ->
|
|
234
|
-
* `majb5`, `I5` -> `5`, and the altered dominants `V7b9`/`V7#9`/`V7#11`/`V7b13`.
|
|
235
|
-
* A figure string that is neither a recognized inversion nor a supported
|
|
236
|
-
* quality suffix throws rather than silently degrading to a triad.
|
|
237
|
-
*
|
|
238
|
-
* @param text The Roman numeral.
|
|
239
|
-
* @param key The prevailing key.
|
|
240
|
-
* @returns The chord.
|
|
241
|
-
* @example
|
|
242
|
-
* ```ts
|
|
243
|
-
* import { romanToChord, majorKey } from '@libraz/libcantus';
|
|
244
|
-
* romanToChord('V7', majorKey(0)); // G7 in C major: { rootPc: 7, quality: 'dom7', ... }
|
|
245
|
-
* ```
|
|
246
|
-
* @category Functional Harmony
|
|
247
|
-
*/
|
|
248
|
-
export function romanToChord(text: string, key: KeyScale): Chord {
|
|
249
|
-
const trimmed = text.trim();
|
|
250
|
-
const slash = trimmed.indexOf('/');
|
|
251
|
-
if (slash >= 0) {
|
|
252
|
-
const applied = trimmed.slice(0, slash);
|
|
253
|
-
const target = trimmed.slice(slash + 1);
|
|
254
|
-
const targetRoot = parseSimpleRoman(target, key).rootPc;
|
|
255
|
-
const localKey = majorKey(targetRoot);
|
|
256
|
-
return chordFromParsed(parseSimpleRoman(applied, localKey));
|
|
257
|
-
}
|
|
258
|
-
return chordFromParsed(parseSimpleRoman(trimmed, key));
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/** Case and suffix for rendering a chord quality as a Roman numeral. */
|
|
262
|
-
function romanStyle(quality: ChordQuality): { lower: boolean; suffix: string } {
|
|
263
|
-
return ROMAN_STYLE[quality];
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/** Choose the degree number and accidental to spell a root as a Roman numeral. */
|
|
267
|
-
function romanSpelling(
|
|
268
|
-
rootPc: number,
|
|
269
|
-
key: KeyScale,
|
|
270
|
-
): { degreeNumber: number; accidental: string } {
|
|
271
|
-
const tones = scaleTonesInDegreeOrder(key);
|
|
272
|
-
const diatonic = tones.indexOf(mod12(rootPc));
|
|
273
|
-
if (diatonic >= 0) {
|
|
274
|
-
return { degreeNumber: diatonic + 1, accidental: '' };
|
|
275
|
-
}
|
|
276
|
-
// Chromatic root: prefer a flat of the diatonic degree a semitone above it,
|
|
277
|
-
// then a sharp of the degree a semitone below. Degree 1 (the tonic) and
|
|
278
|
-
// degree 5 (the dominant) are skipped in the flat pass, so a raised leading
|
|
279
|
-
// tone spells as `#vii` rather than a flat tonic `bI`, and the tritone above
|
|
280
|
-
// the tonic spells as `#iv` rather than a flat fifth `bV` (matching the
|
|
281
|
-
// conventional `OFFSET_SPELLING` for offset 6).
|
|
282
|
-
for (let i = 0; i < tones.length; i += 1) {
|
|
283
|
-
const degreeNumber = i + 1;
|
|
284
|
-
if (degreeNumber === 1 || degreeNumber === 5) {
|
|
285
|
-
continue;
|
|
286
|
-
}
|
|
287
|
-
if (mod12((tones[i] ?? 0) - 1) === mod12(rootPc)) {
|
|
288
|
-
return { degreeNumber, accidental: 'b' };
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
for (let i = 0; i < tones.length; i += 1) {
|
|
292
|
-
if (mod12((tones[i] ?? 0) + 1) === mod12(rootPc)) {
|
|
293
|
-
return { degreeNumber: i + 1, accidental: '#' };
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
const [degreeNumber, accidental] = OFFSET_SPELLING[mod12(rootPc - key.rootPc)] ?? [1, ''];
|
|
297
|
-
return { degreeNumber, accidental };
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/** Quality marker (without the seventh digit) used when a figure carries the 7. */
|
|
301
|
-
function baseMarker(quality: ChordQuality): string {
|
|
302
|
-
if (quality === 'dim' || quality === 'dim7') {
|
|
303
|
-
return 'o';
|
|
304
|
-
}
|
|
305
|
-
if (quality === 'm7b5') {
|
|
306
|
-
return 'ø';
|
|
307
|
-
}
|
|
308
|
-
if (quality === 'aug' || quality === 'aug7') {
|
|
309
|
-
return '+';
|
|
310
|
-
}
|
|
311
|
-
if (quality === 'augMaj7') {
|
|
312
|
-
return '+maj7';
|
|
313
|
-
}
|
|
314
|
-
if (quality === 'maj7' || quality === 'minMaj7') {
|
|
315
|
-
return 'maj7';
|
|
316
|
-
}
|
|
317
|
-
return '';
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
const TRIAD_FIGURES: Record<number, string> = { 1: '6', 2: '64' };
|
|
321
|
-
const SEVENTH_FIGURES: Record<number, string> = { 1: '65', 2: '43', 3: '42' };
|
|
322
|
-
|
|
323
|
-
/** Qualities whose inversions render as lossless triad figures (6, 64). */
|
|
324
|
-
const TRIAD_FIGURE_QUALITIES: ReadonlySet<ChordQuality> = new Set(['maj', 'min', 'dim', 'aug']);
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* Qualities carrying a chordal seventh, whose inversions render as seventh
|
|
328
|
-
* figures (65, 43, 42). Membership is decided by the quality itself — a 7th
|
|
329
|
-
* above the root (10 or 11 semitones, or the diminished 7th of `dim7`) — never
|
|
330
|
-
* by interval count, which would turn added-tone chords into false sevenths.
|
|
331
|
-
*/
|
|
332
|
-
const SEVENTH_FIGURE_QUALITIES: ReadonlySet<ChordQuality> = new Set([
|
|
333
|
-
'maj7',
|
|
334
|
-
'min7',
|
|
335
|
-
'dom7',
|
|
336
|
-
'dim7',
|
|
337
|
-
'm7b5',
|
|
338
|
-
'minMaj7',
|
|
339
|
-
'aug7',
|
|
340
|
-
'augMaj7',
|
|
341
|
-
]);
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* Render a chord as a Roman numeral relative to a key.
|
|
345
|
-
*
|
|
346
|
-
* Diatonic roots take their scale-degree numeral directly, so numerals are
|
|
347
|
-
* correct in both major and minor keys (and any custom scale). The quality
|
|
348
|
-
* selects the case and suffix; chromatic roots receive a flat/sharp spelling by
|
|
349
|
-
* convention. When the chord carries a `bassPc` on a chord tone, a figured-bass
|
|
350
|
-
* inversion (`6`, `64`, `65`, `43`, `42`) is emitted for plain triads and true
|
|
351
|
-
* seventh chords; added-tone and extended qualities have no lossless figure and
|
|
352
|
-
* render in root position instead (the bass is dropped, pitch classes are
|
|
353
|
-
* preserved).
|
|
354
|
-
*
|
|
355
|
-
* @param chord The chord to name.
|
|
356
|
-
* @param key The prevailing key.
|
|
357
|
-
* @returns The Roman numeral string.
|
|
358
|
-
* @example
|
|
359
|
-
* ```ts
|
|
360
|
-
* import { chordToRoman, makeChord, majorKey } from '@libraz/libcantus';
|
|
361
|
-
* chordToRoman(makeChord(7, 'dom7'), majorKey(0)); // => 'V7' (G7 in C major)
|
|
362
|
-
* ```
|
|
363
|
-
* @category Functional Harmony
|
|
364
|
-
*/
|
|
365
|
-
export function chordToRoman(chord: Chord, key: KeyScale): string {
|
|
366
|
-
const { degreeNumber, accidental } = romanSpelling(chord.rootPc, key);
|
|
367
|
-
const { lower, suffix } = romanStyle(chord.quality);
|
|
368
|
-
const numeral: string = ROMAN[degreeNumber - 1] ?? 'I';
|
|
369
|
-
const cased = lower ? numeral.toLowerCase() : numeral;
|
|
370
|
-
|
|
371
|
-
let inversion = 0;
|
|
372
|
-
if (chord.bassPc !== undefined) {
|
|
373
|
-
const idx = chord.intervals.findIndex((iv) => mod12(chord.rootPc + iv) === chord.bassPc);
|
|
374
|
-
if (idx > 0) {
|
|
375
|
-
inversion = idx;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
if (inversion > 0) {
|
|
379
|
-
const figure = SEVENTH_FIGURE_QUALITIES.has(chord.quality)
|
|
380
|
-
? SEVENTH_FIGURES[inversion]
|
|
381
|
-
: TRIAD_FIGURE_QUALITIES.has(chord.quality)
|
|
382
|
-
? TRIAD_FIGURES[inversion]
|
|
383
|
-
: undefined;
|
|
384
|
-
if (figure !== undefined) {
|
|
385
|
-
return `${accidental}${cased}${baseMarker(chord.quality)}${figure}`;
|
|
386
|
-
}
|
|
387
|
-
// No lossless figured-bass symbol exists — the quality is an added-tone or
|
|
388
|
-
// extended chord, or the bass falls on a tension beyond the seventh — so
|
|
389
|
-
// fall back to root-position rendering with the quality suffix rather than
|
|
390
|
-
// emitting a figure that would re-parse as a different chord.
|
|
391
|
-
}
|
|
392
|
-
return `${accidental}${cased}${suffix}`;
|
|
393
|
-
}
|
package/src/analyze/index.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Public API of the analyze layer. Re-exports every analyze-layer module;
|
|
3
|
-
* also available from the package root.
|
|
4
|
-
*/
|
|
5
|
-
export type {
|
|
6
|
-
ArrangementAnalysis,
|
|
7
|
-
ArrangementOptions,
|
|
8
|
-
ArrangementTrack,
|
|
9
|
-
Conflict,
|
|
10
|
-
TensionPoint,
|
|
11
|
-
TrackAnalysis,
|
|
12
|
-
TrackRole,
|
|
13
|
-
} from './arrange/index.js';
|
|
14
|
-
export { analyzeArrangement, tensionCurve } from './arrange/index.js';
|
|
15
|
-
export type { ChordMatch, KeyMatch } from './detect/index.js';
|
|
16
|
-
export { detectChord, detectChordBest, detectKey } from './detect/index.js';
|
|
17
|
-
export type {
|
|
18
|
-
BorrowedSource,
|
|
19
|
-
Cadence,
|
|
20
|
-
ChordAnalysis,
|
|
21
|
-
HarmonicFunction,
|
|
22
|
-
} from './functional/index.js';
|
|
23
|
-
export {
|
|
24
|
-
analyzeChord,
|
|
25
|
-
borrowedSource,
|
|
26
|
-
chordToRoman,
|
|
27
|
-
detectCadence,
|
|
28
|
-
functionOf,
|
|
29
|
-
isBorrowedChord,
|
|
30
|
-
isDiatonic,
|
|
31
|
-
isMinorKey,
|
|
32
|
-
parallelKey,
|
|
33
|
-
romanToChord,
|
|
34
|
-
secondaryDominant,
|
|
35
|
-
} from './functional/index.js';
|
|
36
|
-
export type {
|
|
37
|
-
CadenceHit,
|
|
38
|
-
ChordSegment,
|
|
39
|
-
ChordTimeline,
|
|
40
|
-
ChordTimelineOptions,
|
|
41
|
-
ChordTimelineResult,
|
|
42
|
-
} from './timeline/index.js';
|
|
43
|
-
export {
|
|
44
|
-
chordTimelineFromChords,
|
|
45
|
-
chordTimelineFromNotes,
|
|
46
|
-
detectCadences,
|
|
47
|
-
} from './timeline/index.js';
|
|
48
|
-
export type { AnalyzedNote, TheoryLabel, VoiceNote } from './voice/index.js';
|
|
49
|
-
export { analyzeVoice } from './voice/index.js';
|