@libraz/libcantus 0.9.3 → 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 +2 -2
- package/dist/analyze/index.cjs +39 -1947
- package/dist/analyze/index.cjs.map +1 -1
- package/dist/analyze/index.d.cts +197 -37
- package/dist/analyze/index.d.ts +197 -37
- 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-4MHA432G.js → chunk-7NKDPF74.js} +403 -180
- 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-MIWO425M.js → chunk-D2FAJBYL.js} +101 -34
- package/dist/chunk-D2FAJBYL.js.map +1 -0
- package/dist/{chunk-SGU7SPLK.js → chunk-EHVEBWM5.js} +1056 -531
- 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-IT2O4XFE.js → chunk-GQSGS2N4.js} +43 -24
- package/dist/chunk-GQSGS2N4.js.map +1 -0
- package/dist/{chunk-62QZKCJQ.js → chunk-HKGYCQ34.js} +10 -6
- package/dist/chunk-HKGYCQ34.js.map +1 -0
- package/dist/{chunk-AKLYPWIN.js → chunk-I24MV65U.js} +29 -6
- package/dist/chunk-I24MV65U.js.map +1 -0
- package/dist/{chunk-CHMXELDS.js → chunk-KMHOICIY.js} +311 -181
- 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-2ZWMSJH6.js → chunk-NKIBQ6PT.js} +2 -2
- 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-EH6EM37U.js → chunk-NYYWMV2C.js} +61 -49
- package/dist/chunk-NYYWMV2C.js.map +1 -0
- package/dist/{chunk-GOAW4VYL.js → chunk-Q2XUP227.js} +243 -117
- 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-C5XYKUVG.js → chunk-RK35RIN7.js} +370 -157
- 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-I5R7ZBJS.js → chunk-YLEMGEFH.js} +103 -59
- 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 -647
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +301 -39
- package/dist/core/index.d.ts +301 -39
- package/dist/core/index.js +54 -16
- package/dist/{function-DYt4iKsn.d.cts → function-BtiZb9i9.d.ts} +28 -7
- package/dist/{function-DVH4Eusr.d.ts → function-DNugAOrt.d.cts} +28 -7
- package/dist/generate/index.cjs +28 -4085
- package/dist/generate/index.cjs.map +1 -1
- package/dist/generate/index.d.cts +370 -62
- package/dist/generate/index.d.ts +370 -62
- package/dist/generate/index.js +23 -9
- package/dist/{index-CxqBQtH1.d.cts → index-6VR8-kit.d.ts} +19 -4
- package/dist/index-70p168VM.d.ts +192 -0
- package/dist/{index-CpOsP1y9.d.cts → index-Be74mcon.d.cts} +18 -17
- package/dist/index-BtXT6UQ0.d.cts +192 -0
- package/dist/{index-DxvARIP2.d.ts → index-C5UBbQ4G.d.ts} +18 -17
- package/dist/{index-Bt4tOUD9.d.ts → index-C83mZI1P.d.ts} +93 -8
- package/dist/{index-Bg5dYMmZ.d.ts → 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-Jc0Ryi79.d.ts → index-tJhkmQgE.d.cts} +19 -4
- package/dist/{index-Dikst44v.d.cts → index-tSQh-xwY.d.ts} +14 -11
- package/dist/{index-BNlGP86A.d.cts → index-y_ak9_Hi.d.cts} +93 -8
- package/dist/index.cjs +419 -7383
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -14
- package/dist/index.d.ts +14 -14
- package/dist/index.js +111 -27
- package/dist/model/index.cjs +8 -2562
- package/dist/model/index.cjs.map +1 -1
- package/dist/model/index.d.cts +433 -75
- package/dist/model/index.d.ts +433 -75
- 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 -1822
- 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 +30 -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 +24 -6
- package/dist/chunk-2ZWMSJH6.js.map +0 -1
- package/dist/chunk-4MHA432G.js.map +0 -1
- package/dist/chunk-62QZKCJQ.js.map +0 -1
- package/dist/chunk-AKLYPWIN.js.map +0 -1
- package/dist/chunk-C5XYKUVG.js.map +0 -1
- package/dist/chunk-CHMXELDS.js.map +0 -1
- package/dist/chunk-DYWFNC4A.js +0 -152
- package/dist/chunk-DYWFNC4A.js.map +0 -1
- package/dist/chunk-EH6EM37U.js.map +0 -1
- package/dist/chunk-FBQK3ZQN.js +0 -131
- package/dist/chunk-FBQK3ZQN.js.map +0 -1
- package/dist/chunk-GOAW4VYL.js.map +0 -1
- package/dist/chunk-I5R7ZBJS.js.map +0 -1
- package/dist/chunk-IT2O4XFE.js.map +0 -1
- package/dist/chunk-MIWO425M.js.map +0 -1
- package/dist/chunk-SGU7SPLK.js.map +0 -1
- package/dist/index-CGMZNCx6.d.cts +0 -140
- package/dist/index-CGMZNCx6.d.ts +0 -140
- package/dist/index-CnZCo29u.d.cts +0 -108
- package/dist/index-JnF4v9bx.d.ts +0 -108
- package/dist/styled-DZ7GjShb.d.ts +0 -282
- package/dist/styled-ZTbdaVFM.d.cts +0 -282
- package/src/analyze/arrange/index.ts +0 -21
- package/src/analyze/arrange/internal.ts +0 -127
- package/src/analyze/arrange/tension.ts +0 -199
- package/src/analyze/arrange/tracks.ts +0 -312
- package/src/analyze/detect/index.ts +0 -272
- 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 -402
- package/src/analyze/index.ts +0 -49
- package/src/analyze/timeline/index.ts +0 -451
- package/src/analyze/voice/index.ts +0 -339
- package/src/core/event-index/index.ts +0 -104
- package/src/core/index.ts +0 -61
- package/src/core/interval/index.ts +0 -81
- package/src/core/meter/index.ts +0 -302
- package/src/core/pitch/index.ts +0 -311
- package/src/core/random/index.ts +0 -76
- package/src/core/tuning/index.ts +0 -186
- package/src/core/types.ts +0 -29
- package/src/core/validation/index.ts +0 -119
- package/src/generate/bass/index.ts +0 -373
- package/src/generate/countermelody/index.ts +0 -470
- package/src/generate/drums/beat.ts +0 -266
- package/src/generate/drums/euclid.ts +0 -65
- 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 -361
- 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 -351
- package/src/generate/harmonize/index.ts +0 -451
- package/src/generate/index.ts +0 -58
- package/src/generate/motif/index.ts +0 -422
- package/src/generate/progression/index.ts +0 -362
- package/src/generate/reharmony/index.ts +0 -323
- package/src/generate/rhythm/index.ts +0 -175
- package/src/index.ts +0 -13
- package/src/model/chord.ts +0 -442
- 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 -375
- package/src/theory/chordscale/index.ts +0 -374
- package/src/theory/counterpoint/index.ts +0 -230
- package/src/theory/harmony/index.ts +0 -77
- package/src/theory/index.ts +0 -112
- package/src/theory/safety/index.ts +0 -488
- 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 -249
- 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 -216
- package/src/theory/voicing/styled.ts +0 -199
- package/tsconfig.json +0 -23
|
@@ -0,0 +1,679 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkFNDWXRRIcjs = require('./chunk-FNDWXRRI.cjs');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
var _chunk7MGZ7D62cjs = require('./chunk-7MGZ7D62.cjs');
|
|
20
|
+
|
|
21
|
+
// src/analyze/detect/index.ts
|
|
22
|
+
function uniquePitchClasses(pitches) {
|
|
23
|
+
return [...new Set(pitches.map(_chunk7MGZ7D62cjs.pitchClassOf))].sort((a, b) => a - b);
|
|
24
|
+
}
|
|
25
|
+
function assertPitches(pitches) {
|
|
26
|
+
_chunk7MGZ7D62cjs.assertGenerationBudget.call(void 0, pitches.length, "detection pitches");
|
|
27
|
+
for (let index = 0; index < pitches.length; index += 1) {
|
|
28
|
+
_chunk7MGZ7D62cjs.assertFiniteNumber.call(void 0, _nullishCoalesce(pitches[index], () => ( Number.NaN)), `pitches[${index}]`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function detectChord(pitches, opts = {}) {
|
|
32
|
+
assertPitches(pitches);
|
|
33
|
+
if (opts.bassPc !== void 0) _chunk7MGZ7D62cjs.assertFiniteNumber.call(void 0, opts.bassPc, "bassPc");
|
|
34
|
+
const input = uniquePitchClasses(pitches);
|
|
35
|
+
if (input.length === 0) {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
const inputKind = opts.input === void 0 || opts.input === "auto" ? pitches.every((pitch) => Number.isInteger(pitch) && pitch >= 0 && pitch <= 11) ? "pitchClass" : "midi" : opts.input;
|
|
39
|
+
const bassPc = opts.bassPc !== void 0 ? _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, opts.bassPc) : inputKind === "midi" ? _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, pitches.reduce((lowest, pitch) => Math.min(lowest, pitch), Infinity)) : void 0;
|
|
40
|
+
const inputSet = new Set(input);
|
|
41
|
+
const matches = [];
|
|
42
|
+
const qualities = _chunkFNDWXRRIcjs.chordQualities.call(void 0, );
|
|
43
|
+
for (const rootPc of input) {
|
|
44
|
+
for (const quality of qualities) {
|
|
45
|
+
const chord = _chunkFNDWXRRIcjs.makeChord.call(void 0, rootPc, quality);
|
|
46
|
+
const tones = _chunkFNDWXRRIcjs.chordPitchClasses.call(void 0, chord);
|
|
47
|
+
const toneSet = new Set(tones);
|
|
48
|
+
const missingPcs = tones.filter((pc) => !inputSet.has(pc));
|
|
49
|
+
const fifthPc = _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, rootPc + 7);
|
|
50
|
+
if (missingPcs.length > 1 || missingPcs.length === 1 && missingPcs[0] !== fifthPc) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const extraPcs = input.filter((pc) => !toneSet.has(pc));
|
|
54
|
+
const bassIndex = bassPc === void 0 ? -1 : chord.intervals.findIndex((iv) => _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, rootPc + iv) === bassPc);
|
|
55
|
+
const inversion = bassPc === void 0 || bassIndex < 0 ? null : bassIndex;
|
|
56
|
+
const match = {
|
|
57
|
+
rootPc,
|
|
58
|
+
quality,
|
|
59
|
+
missingPcs,
|
|
60
|
+
extraPcs,
|
|
61
|
+
exact: extraPcs.length === 0 && missingPcs.length === 0,
|
|
62
|
+
inversion
|
|
63
|
+
};
|
|
64
|
+
if (bassPc !== void 0 && bassPc !== rootPc) {
|
|
65
|
+
match.bassPc = bassPc;
|
|
66
|
+
}
|
|
67
|
+
matches.push(match);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
matches.sort((a, b) => {
|
|
71
|
+
if (a.extraPcs.length !== b.extraPcs.length) {
|
|
72
|
+
return a.extraPcs.length - b.extraPcs.length;
|
|
73
|
+
}
|
|
74
|
+
if (a.missingPcs.length !== b.missingPcs.length) {
|
|
75
|
+
return a.missingPcs.length - b.missingPcs.length;
|
|
76
|
+
}
|
|
77
|
+
if (a.inversion === 0 !== (b.inversion === 0)) {
|
|
78
|
+
return a.inversion === 0 ? -1 : 1;
|
|
79
|
+
}
|
|
80
|
+
const aSize = _chunkFNDWXRRIcjs.chordPitchClasses.call(void 0, _chunkFNDWXRRIcjs.makeChord.call(void 0, a.rootPc, a.quality)).length;
|
|
81
|
+
const bSize = _chunkFNDWXRRIcjs.chordPitchClasses.call(void 0, _chunkFNDWXRRIcjs.makeChord.call(void 0, b.rootPc, b.quality)).length;
|
|
82
|
+
return bSize - aSize;
|
|
83
|
+
});
|
|
84
|
+
return matches;
|
|
85
|
+
}
|
|
86
|
+
function detectChordBest(pitches, opts = {}) {
|
|
87
|
+
const best = detectChord(pitches, opts)[0];
|
|
88
|
+
if (!best) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
return _chunkFNDWXRRIcjs.makeChord.call(void 0, best.rootPc, best.quality, best.bassPc);
|
|
92
|
+
}
|
|
93
|
+
var MINOR_VARIANTS = [
|
|
94
|
+
{ variant: "natural", mask: _chunkFNDWXRRIcjs.NATURAL_MINOR_MASK },
|
|
95
|
+
{ variant: "harmonic", mask: _chunkFNDWXRRIcjs.HARMONIC_MINOR_MASK },
|
|
96
|
+
{ variant: "melodic", mask: _chunkFNDWXRRIcjs.MELODIC_MINOR_MASK }
|
|
97
|
+
];
|
|
98
|
+
var MAJOR_VARIANTS = [{ variant: "major", mask: _chunkFNDWXRRIcjs.MAJOR_MASK }];
|
|
99
|
+
function detectKey(pitches, opts = {}) {
|
|
100
|
+
assertPitches(pitches);
|
|
101
|
+
const input = uniquePitchClasses(pitches);
|
|
102
|
+
if (input.length === 0) {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
const weights = opts.weights;
|
|
106
|
+
if (weights !== void 0 && weights.length !== pitches.length) {
|
|
107
|
+
throw new (0, _chunk7MGZ7D62cjs.InvalidInputError)("weights must have one entry per pitch");
|
|
108
|
+
}
|
|
109
|
+
const counts = /* @__PURE__ */ new Map();
|
|
110
|
+
let total = 0;
|
|
111
|
+
for (let index = 0; index < pitches.length; index += 1) {
|
|
112
|
+
const weight = weights === void 0 ? 1 : _nullishCoalesce(weights[index], () => ( 0));
|
|
113
|
+
_chunk7MGZ7D62cjs.assertFiniteNumber.call(void 0, weight, `weights[${index}]`);
|
|
114
|
+
if (weight <= 0) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const pc = _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, _nullishCoalesce(pitches[index], () => ( 0)));
|
|
118
|
+
counts.set(pc, (_nullishCoalesce(counts.get(pc), () => ( 0))) + weight);
|
|
119
|
+
total += weight;
|
|
120
|
+
}
|
|
121
|
+
if (total === 0) {
|
|
122
|
+
return [];
|
|
123
|
+
}
|
|
124
|
+
const results = [];
|
|
125
|
+
for (let tonic = 0; tonic < 12; tonic += 1) {
|
|
126
|
+
for (const mode of ["major", "minor"]) {
|
|
127
|
+
const variants = mode === "major" ? MAJOR_VARIANTS : MINOR_VARIANTS;
|
|
128
|
+
let inScale = 0;
|
|
129
|
+
let weighted = Number.NEGATIVE_INFINITY;
|
|
130
|
+
let best = variants[0];
|
|
131
|
+
for (const candidate of variants) {
|
|
132
|
+
let variantInScale = 0;
|
|
133
|
+
let variantWeighted = 0;
|
|
134
|
+
for (const pc of input) {
|
|
135
|
+
const offset = (pc - tonic + 12) % 12;
|
|
136
|
+
if (candidate.mask >> offset & 1) {
|
|
137
|
+
variantInScale += 1;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
for (const [pc, count] of counts) {
|
|
141
|
+
const offset = (pc - tonic + 12) % 12;
|
|
142
|
+
if (candidate.mask >> offset & 1) {
|
|
143
|
+
variantWeighted += count;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (variantWeighted > weighted) {
|
|
147
|
+
weighted = variantWeighted;
|
|
148
|
+
inScale = variantInScale;
|
|
149
|
+
best = candidate;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
weighted += (_nullishCoalesce(counts.get(tonic), () => ( 0))) * 0.5;
|
|
153
|
+
results.push({
|
|
154
|
+
key: { rootPc: tonic, modeMask12: best.mask },
|
|
155
|
+
mode,
|
|
156
|
+
variant: best.variant,
|
|
157
|
+
fit: inScale / input.length,
|
|
158
|
+
score: weighted / total
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
results.sort((a, b) => b.score - a.score);
|
|
163
|
+
return results;
|
|
164
|
+
}
|
|
165
|
+
var DEFAULT_VELOCITY = 100;
|
|
166
|
+
function detectKeyFromNotes(notes) {
|
|
167
|
+
const sounding = notes.filter((note) => note.durationBeat > 0);
|
|
168
|
+
return detectKey(
|
|
169
|
+
sounding.map((note) => note.pitch),
|
|
170
|
+
{ weights: sounding.map((note) => note.durationBeat * (_nullishCoalesce(note.velocity, () => ( DEFAULT_VELOCITY)))) }
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
function detectKeyBest(pitches, opts = {}) {
|
|
174
|
+
return _nullishCoalesce(detectKey(pitches, opts)[0], () => ( null));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// src/analyze/functional/internal.ts
|
|
178
|
+
function degreeRootPc(degreeNumber, key) {
|
|
179
|
+
const tones = _chunkFNDWXRRIcjs.scaleTonesInDegreeOrder.call(void 0, key);
|
|
180
|
+
if (tones.length === 0) {
|
|
181
|
+
return _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, key.rootPc);
|
|
182
|
+
}
|
|
183
|
+
const index = ((degreeNumber - 1) % tones.length + tones.length) % tones.length;
|
|
184
|
+
return _nullishCoalesce(tones[index], () => ( _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, key.rootPc)));
|
|
185
|
+
}
|
|
186
|
+
function loweredDegrees(key) {
|
|
187
|
+
const tones = _chunkFNDWXRRIcjs.scaleTonesInDegreeOrder.call(void 0, key);
|
|
188
|
+
const out = /* @__PURE__ */ new Set();
|
|
189
|
+
if (tones.length !== 7) {
|
|
190
|
+
return out;
|
|
191
|
+
}
|
|
192
|
+
const major = _chunkFNDWXRRIcjs.scaleTonesInDegreeOrder.call(void 0, { rootPc: _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, key.rootPc), modeMask12: _chunkFNDWXRRIcjs.MAJOR_MASK });
|
|
193
|
+
for (let index = 0; index < 7; index += 1) {
|
|
194
|
+
const tone = tones[index];
|
|
195
|
+
const majorTone = major[index];
|
|
196
|
+
if (tone !== void 0 && majorTone !== void 0 && _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, majorTone - tone) === 1) {
|
|
197
|
+
out.add(index + 1);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return out;
|
|
201
|
+
}
|
|
202
|
+
function romanReference(key) {
|
|
203
|
+
return _chunkFNDWXRRIcjs.scaleTonesInDegreeOrder.call(void 0, key).length === 7 ? key : _chunkFNDWXRRIcjs.majorKey.call(void 0, _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, key.rootPc));
|
|
204
|
+
}
|
|
205
|
+
function isNeapolitan(chord, key) {
|
|
206
|
+
return _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, chord.rootPc - key.rootPc) === 1 && chord.quality === "maj";
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// src/analyze/functional/roman.ts
|
|
210
|
+
var ROMAN = ["I", "II", "III", "IV", "V", "VI", "VII"];
|
|
211
|
+
var ROMAN_TO_DEGREE = {
|
|
212
|
+
I: 1,
|
|
213
|
+
II: 2,
|
|
214
|
+
III: 3,
|
|
215
|
+
IV: 4,
|
|
216
|
+
V: 5,
|
|
217
|
+
VI: 6,
|
|
218
|
+
VII: 7
|
|
219
|
+
};
|
|
220
|
+
var OFFSET_SPELLING = [
|
|
221
|
+
[1, ""],
|
|
222
|
+
[2, "b"],
|
|
223
|
+
[2, ""],
|
|
224
|
+
[3, "b"],
|
|
225
|
+
[3, ""],
|
|
226
|
+
[4, ""],
|
|
227
|
+
[4, "#"],
|
|
228
|
+
[5, ""],
|
|
229
|
+
[6, "b"],
|
|
230
|
+
[6, ""],
|
|
231
|
+
[7, "b"],
|
|
232
|
+
[7, ""]
|
|
233
|
+
];
|
|
234
|
+
function seventhQuality(base, halfDim) {
|
|
235
|
+
if (halfDim) {
|
|
236
|
+
return "m7b5";
|
|
237
|
+
}
|
|
238
|
+
if (base === "dim") {
|
|
239
|
+
return "dim7";
|
|
240
|
+
}
|
|
241
|
+
if (base === "aug") {
|
|
242
|
+
return "aug7";
|
|
243
|
+
}
|
|
244
|
+
return base === "maj" ? "dom7" : "min7";
|
|
245
|
+
}
|
|
246
|
+
var INVERSION_FIGURES = /* @__PURE__ */ new Set(["6", "64", "65", "43", "42", "2", "7"]);
|
|
247
|
+
var ROMAN_STYLE = {
|
|
248
|
+
maj: { lower: false, suffix: "" },
|
|
249
|
+
min: { lower: true, suffix: "" },
|
|
250
|
+
dim: { lower: true, suffix: "o" },
|
|
251
|
+
aug: { lower: false, suffix: "+" },
|
|
252
|
+
maj7: { lower: false, suffix: "maj7" },
|
|
253
|
+
min7: { lower: true, suffix: "7" },
|
|
254
|
+
dom7: { lower: false, suffix: "7" },
|
|
255
|
+
dim7: { lower: true, suffix: "o7" },
|
|
256
|
+
m7b5: { lower: true, suffix: "\xF87" },
|
|
257
|
+
minMaj7: { lower: true, suffix: "maj7" },
|
|
258
|
+
aug7: { lower: false, suffix: "+7" },
|
|
259
|
+
augMaj7: { lower: false, suffix: "+maj7" },
|
|
260
|
+
majb5: { lower: false, suffix: "b5" },
|
|
261
|
+
"6": { lower: false, suffix: "add6" },
|
|
262
|
+
min6: { lower: true, suffix: "add6" },
|
|
263
|
+
"6/9": { lower: false, suffix: "69" },
|
|
264
|
+
sus2: { lower: false, suffix: "sus2" },
|
|
265
|
+
sus4: { lower: false, suffix: "sus4" },
|
|
266
|
+
add9: { lower: false, suffix: "add9" },
|
|
267
|
+
add11: { lower: false, suffix: "add11" },
|
|
268
|
+
maj9: { lower: false, suffix: "maj9" },
|
|
269
|
+
min9: { lower: true, suffix: "9" },
|
|
270
|
+
dom9: { lower: false, suffix: "9" },
|
|
271
|
+
"7b9": { lower: false, suffix: "7b9" },
|
|
272
|
+
"7#9": { lower: false, suffix: "7#9" },
|
|
273
|
+
"7#11": { lower: false, suffix: "7#11" },
|
|
274
|
+
"7b13": { lower: false, suffix: "7b13" },
|
|
275
|
+
"11": { lower: false, suffix: "11" },
|
|
276
|
+
"13": { lower: false, suffix: "13" },
|
|
277
|
+
"5": { lower: false, suffix: "5" },
|
|
278
|
+
"7sus4": { lower: false, suffix: "7sus4" },
|
|
279
|
+
"7b5": { lower: false, suffix: "7b5" },
|
|
280
|
+
"7alt": { lower: false, suffix: "7alt" },
|
|
281
|
+
"13b9": { lower: false, suffix: "13b9" },
|
|
282
|
+
maj13: { lower: false, suffix: "maj13" },
|
|
283
|
+
"maj7#11": { lower: false, suffix: "maj7#11" },
|
|
284
|
+
min11: { lower: true, suffix: "11" },
|
|
285
|
+
min13: { lower: true, suffix: "13" },
|
|
286
|
+
minAdd9: { lower: true, suffix: "add9" },
|
|
287
|
+
"min6/9": { lower: true, suffix: "69" }
|
|
288
|
+
};
|
|
289
|
+
var SUFFIX_QUALITY = new Map(
|
|
290
|
+
Object.entries(ROMAN_STYLE).map(
|
|
291
|
+
([quality, style]) => [`${style.lower ? "l" : "u"}:${style.suffix}`, quality]
|
|
292
|
+
)
|
|
293
|
+
);
|
|
294
|
+
function parseInversion(figures) {
|
|
295
|
+
if (figures === "65") {
|
|
296
|
+
return { inversion: 1, seventh: true };
|
|
297
|
+
}
|
|
298
|
+
if (figures === "43") {
|
|
299
|
+
return { inversion: 2, seventh: true };
|
|
300
|
+
}
|
|
301
|
+
if (figures === "42" || figures === "2") {
|
|
302
|
+
return { inversion: 3, seventh: true };
|
|
303
|
+
}
|
|
304
|
+
if (figures === "7") {
|
|
305
|
+
return { inversion: 0, seventh: true };
|
|
306
|
+
}
|
|
307
|
+
if (figures === "64") {
|
|
308
|
+
return { inversion: 2, seventh: false };
|
|
309
|
+
}
|
|
310
|
+
if (figures === "6") {
|
|
311
|
+
return { inversion: 1, seventh: false };
|
|
312
|
+
}
|
|
313
|
+
return { inversion: 0, seventh: false };
|
|
314
|
+
}
|
|
315
|
+
function parseSimpleRoman(text, key) {
|
|
316
|
+
const match = /^([b#]?)([iIvV]+)(.*)$/.exec(text.trim());
|
|
317
|
+
if (!match) {
|
|
318
|
+
throw new (0, _chunk7MGZ7D62cjs.InvalidInputError)(`Invalid Roman numeral: ${text}`);
|
|
319
|
+
}
|
|
320
|
+
const accidental = match[1] === "b" ? -1 : match[1] === "#" ? 1 : 0;
|
|
321
|
+
const glyph = (_nullishCoalesce(match[2], () => ( ""))).toUpperCase();
|
|
322
|
+
const degreeNumber = ROMAN_TO_DEGREE[glyph];
|
|
323
|
+
if (degreeNumber === void 0) {
|
|
324
|
+
throw new (0, _chunk7MGZ7D62cjs.InvalidInputError)(`Invalid Roman numeral: ${text}`);
|
|
325
|
+
}
|
|
326
|
+
const isUpper = (_nullishCoalesce(match[2], () => ( "")))[0] === _optionalChain([(_nullishCoalesce(match[2], () => ( ""))), 'access', _ => _[0], 'optionalAccess', _2 => _2.toUpperCase, 'call', _3 => _3()]);
|
|
327
|
+
const suffix = _nullishCoalesce(match[3], () => ( ""));
|
|
328
|
+
const frame = romanReference(key);
|
|
329
|
+
const redundantFlat = accidental === -1 && loweredDegrees(frame).has(degreeNumber);
|
|
330
|
+
const rootPc = _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, degreeRootPc(degreeNumber, frame) + (redundantFlat ? 0 : accidental));
|
|
331
|
+
const canonical = SUFFIX_QUALITY.get(`${isUpper ? "u" : "l"}:${suffix}`);
|
|
332
|
+
if (canonical !== void 0) {
|
|
333
|
+
return { rootPc, quality: canonical, inversion: 0 };
|
|
334
|
+
}
|
|
335
|
+
const parsedSuffix = /^(o|°|dim|ø|\+|aug)?(maj7|M7)?(65|64|43|42|7|6|2)?$/.exec(suffix);
|
|
336
|
+
if (!parsedSuffix) {
|
|
337
|
+
throw new (0, _chunk7MGZ7D62cjs.InvalidInputError)(`Unsupported suffix "${suffix}" in Roman numeral: ${text}`);
|
|
338
|
+
}
|
|
339
|
+
const qualityMarker = _nullishCoalesce(parsedSuffix[1], () => ( ""));
|
|
340
|
+
const isDim = qualityMarker === "o" || qualityMarker === "\xB0" || qualityMarker === "dim";
|
|
341
|
+
const isAug = qualityMarker === "+" || qualityMarker === "aug";
|
|
342
|
+
const isHalfDim = qualityMarker === "\xF8";
|
|
343
|
+
const explicitMaj7 = parsedSuffix[2] !== void 0;
|
|
344
|
+
const figures = _nullishCoalesce(parsedSuffix[3], () => ( ""));
|
|
345
|
+
if (figures !== "" && !INVERSION_FIGURES.has(figures)) {
|
|
346
|
+
throw new (0, _chunk7MGZ7D62cjs.InvalidInputError)(
|
|
347
|
+
`Unsupported figured-bass or extension "${figures}" in Roman numeral: ${text}`
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
const { inversion, seventh } = parseInversion(figures);
|
|
351
|
+
const hasSeventh = explicitMaj7 || seventh || isHalfDim;
|
|
352
|
+
let base;
|
|
353
|
+
if (isDim || isHalfDim) {
|
|
354
|
+
base = "dim";
|
|
355
|
+
} else if (isAug) {
|
|
356
|
+
base = "aug";
|
|
357
|
+
} else {
|
|
358
|
+
base = isUpper ? "maj" : "min";
|
|
359
|
+
}
|
|
360
|
+
let quality;
|
|
361
|
+
if (explicitMaj7) {
|
|
362
|
+
quality = base === "min" ? "minMaj7" : base === "aug" ? "augMaj7" : "maj7";
|
|
363
|
+
} else if (hasSeventh) {
|
|
364
|
+
quality = seventhQuality(base, isHalfDim);
|
|
365
|
+
} else if (base === "dim") {
|
|
366
|
+
quality = "dim";
|
|
367
|
+
} else if (base === "aug") {
|
|
368
|
+
quality = "aug";
|
|
369
|
+
} else {
|
|
370
|
+
quality = base;
|
|
371
|
+
}
|
|
372
|
+
return { rootPc, quality, inversion };
|
|
373
|
+
}
|
|
374
|
+
function chordFromParsed(parsed) {
|
|
375
|
+
const chord = _chunkFNDWXRRIcjs.makeChord.call(void 0, parsed.rootPc, parsed.quality);
|
|
376
|
+
if (parsed.inversion > 0 && parsed.inversion < chord.intervals.length) {
|
|
377
|
+
chord.bassPc = _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, parsed.rootPc + (_nullishCoalesce(chord.intervals[parsed.inversion], () => ( 0))));
|
|
378
|
+
}
|
|
379
|
+
return chord;
|
|
380
|
+
}
|
|
381
|
+
function romanToChord(text, key) {
|
|
382
|
+
const trimmed = text.trim();
|
|
383
|
+
const slash = trimmed.indexOf("/");
|
|
384
|
+
if (slash >= 0) {
|
|
385
|
+
const applied = trimmed.slice(0, slash);
|
|
386
|
+
const target = trimmed.slice(slash + 1);
|
|
387
|
+
const targetRoot = parseSimpleRoman(target, key).rootPc;
|
|
388
|
+
const localKey = _chunkFNDWXRRIcjs.majorKey.call(void 0, targetRoot);
|
|
389
|
+
return chordFromParsed(parseSimpleRoman(applied, localKey));
|
|
390
|
+
}
|
|
391
|
+
return chordFromParsed(parseSimpleRoman(trimmed, key));
|
|
392
|
+
}
|
|
393
|
+
function romanStyle(quality) {
|
|
394
|
+
return ROMAN_STYLE[quality];
|
|
395
|
+
}
|
|
396
|
+
function romanSpelling(rootPc, key) {
|
|
397
|
+
const tones = _chunkFNDWXRRIcjs.scaleTonesInDegreeOrder.call(void 0, romanReference(key));
|
|
398
|
+
const diatonic = tones.indexOf(_chunk7MGZ7D62cjs.pitchClassOf.call(void 0, rootPc));
|
|
399
|
+
if (diatonic >= 0) {
|
|
400
|
+
return { degreeNumber: diatonic + 1, accidental: "" };
|
|
401
|
+
}
|
|
402
|
+
const lowered = loweredDegrees(romanReference(key));
|
|
403
|
+
for (let i = 0; i < tones.length; i += 1) {
|
|
404
|
+
if (lowered.has(i + 1) && _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, (_nullishCoalesce(tones[i], () => ( 0))) + 1) === _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, rootPc)) {
|
|
405
|
+
return { degreeNumber: i + 1, accidental: "#" };
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
for (let i = 0; i < tones.length; i += 1) {
|
|
409
|
+
const degreeNumber2 = i + 1;
|
|
410
|
+
if (degreeNumber2 === 1 || degreeNumber2 === 5) {
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
if (_chunk7MGZ7D62cjs.pitchClassOf.call(void 0, (_nullishCoalesce(tones[i], () => ( 0))) - 1) === _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, rootPc)) {
|
|
414
|
+
return { degreeNumber: degreeNumber2, accidental: "b" };
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
for (let i = 0; i < tones.length; i += 1) {
|
|
418
|
+
if (_chunk7MGZ7D62cjs.pitchClassOf.call(void 0, (_nullishCoalesce(tones[i], () => ( 0))) + 1) === _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, rootPc)) {
|
|
419
|
+
return { degreeNumber: i + 1, accidental: "#" };
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
const [degreeNumber, accidental] = _nullishCoalesce(OFFSET_SPELLING[_chunk7MGZ7D62cjs.pitchClassOf.call(void 0, rootPc - key.rootPc)], () => ( [1, ""]));
|
|
423
|
+
return { degreeNumber, accidental };
|
|
424
|
+
}
|
|
425
|
+
function baseMarker(quality) {
|
|
426
|
+
if (quality === "dim" || quality === "dim7") {
|
|
427
|
+
return "o";
|
|
428
|
+
}
|
|
429
|
+
if (quality === "m7b5") {
|
|
430
|
+
return "\xF8";
|
|
431
|
+
}
|
|
432
|
+
if (quality === "aug" || quality === "aug7") {
|
|
433
|
+
return "+";
|
|
434
|
+
}
|
|
435
|
+
if (quality === "augMaj7") {
|
|
436
|
+
return "+maj7";
|
|
437
|
+
}
|
|
438
|
+
if (quality === "maj7" || quality === "minMaj7") {
|
|
439
|
+
return "maj7";
|
|
440
|
+
}
|
|
441
|
+
return "";
|
|
442
|
+
}
|
|
443
|
+
var TRIAD_FIGURES = { 1: "6", 2: "64" };
|
|
444
|
+
var SEVENTH_FIGURES = { 1: "65", 2: "43", 3: "42" };
|
|
445
|
+
var TRIAD_FIGURE_QUALITIES = /* @__PURE__ */ new Set(["maj", "min", "dim", "aug"]);
|
|
446
|
+
var SEVENTH_FIGURE_QUALITIES = /* @__PURE__ */ new Set([
|
|
447
|
+
"maj7",
|
|
448
|
+
"min7",
|
|
449
|
+
"dom7",
|
|
450
|
+
"dim7",
|
|
451
|
+
"m7b5",
|
|
452
|
+
"minMaj7",
|
|
453
|
+
"aug7",
|
|
454
|
+
"augMaj7"
|
|
455
|
+
]);
|
|
456
|
+
function numeralFor(degreeNumber, lower) {
|
|
457
|
+
const glyph = ROMAN[degreeNumber - 1];
|
|
458
|
+
if (glyph === void 0) {
|
|
459
|
+
throw new (0, _chunk7MGZ7D62cjs.InvalidInputError)(`no Roman numeral for scale degree ${degreeNumber}`);
|
|
460
|
+
}
|
|
461
|
+
return lower ? glyph.toLowerCase() : glyph;
|
|
462
|
+
}
|
|
463
|
+
function isDiatonicChord(chord, key) {
|
|
464
|
+
return _chunkFNDWXRRIcjs.chordPitchClasses.call(void 0, chord).every((pc) => _chunkFNDWXRRIcjs.isScaleTone.call(void 0, pc, key));
|
|
465
|
+
}
|
|
466
|
+
function isAppliedDominantSonority(chord) {
|
|
467
|
+
const has = (semitones) => chord.intervals.some((i) => _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, i) === semitones);
|
|
468
|
+
return chord.quality === "maj" || has(4) && has(10);
|
|
469
|
+
}
|
|
470
|
+
var LEADING_TONE_QUALITIES = /* @__PURE__ */ new Set(["dim", "dim7", "m7b5"]);
|
|
471
|
+
function degreeTriad(tones, index) {
|
|
472
|
+
const root = _nullishCoalesce(tones[index], () => ( 0));
|
|
473
|
+
return {
|
|
474
|
+
third: _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, (_nullishCoalesce(tones[(index + 2) % tones.length], () => ( 0))) - root),
|
|
475
|
+
fifth: _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, (_nullishCoalesce(tones[(index + 4) % tones.length], () => ( 0))) - root)
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
function appliedTarget(chord, key) {
|
|
479
|
+
const dominant = isAppliedDominantSonority(chord);
|
|
480
|
+
const leadingTone = LEADING_TONE_QUALITIES.has(chord.quality);
|
|
481
|
+
if (!dominant && !leadingTone) {
|
|
482
|
+
return null;
|
|
483
|
+
}
|
|
484
|
+
const tones = _chunkFNDWXRRIcjs.scaleTonesInDegreeOrder.call(void 0, romanReference(key));
|
|
485
|
+
for (let index = 1; index < tones.length; index += 1) {
|
|
486
|
+
const targetRoot = tones[index];
|
|
487
|
+
if (targetRoot === void 0) {
|
|
488
|
+
continue;
|
|
489
|
+
}
|
|
490
|
+
const triad = degreeTriad(tones, index);
|
|
491
|
+
if (triad.fifth === 6) {
|
|
492
|
+
continue;
|
|
493
|
+
}
|
|
494
|
+
const expectedRoot = _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, targetRoot + (dominant ? 7 : -1));
|
|
495
|
+
if (expectedRoot === _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, chord.rootPc)) {
|
|
496
|
+
return { degreeNumber: index + 1, rootPc: targetRoot, lower: triad.third === 3 };
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
return null;
|
|
500
|
+
}
|
|
501
|
+
function chordToRoman(chord, key, opts = {}) {
|
|
502
|
+
if (opts.applied === true && !isDiatonicChord(chord, key)) {
|
|
503
|
+
const target = appliedTarget(chord, key);
|
|
504
|
+
if (target !== null) {
|
|
505
|
+
const local = chordToRoman(chord, _chunkFNDWXRRIcjs.majorKey.call(void 0, target.rootPc));
|
|
506
|
+
return `${local}/${numeralFor(target.degreeNumber, target.lower)}`;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
const { degreeNumber, accidental } = romanSpelling(chord.rootPc, key);
|
|
510
|
+
const { lower, suffix } = romanStyle(chord.quality);
|
|
511
|
+
const cased = numeralFor(degreeNumber, lower);
|
|
512
|
+
let inversion = 0;
|
|
513
|
+
if (chord.bassPc !== void 0) {
|
|
514
|
+
const idx = chord.intervals.findIndex((iv) => _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, chord.rootPc + iv) === chord.bassPc);
|
|
515
|
+
if (idx > 0) {
|
|
516
|
+
inversion = idx;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
if (inversion > 0) {
|
|
520
|
+
const figure = SEVENTH_FIGURE_QUALITIES.has(chord.quality) ? SEVENTH_FIGURES[inversion] : TRIAD_FIGURE_QUALITIES.has(chord.quality) ? TRIAD_FIGURES[inversion] : void 0;
|
|
521
|
+
if (figure !== void 0) {
|
|
522
|
+
return `${accidental}${cased}${baseMarker(chord.quality)}${figure}`;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
return `${accidental}${cased}${suffix}`;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
// src/analyze/functional/borrowed.ts
|
|
529
|
+
function isHarmonicMinorAlteration(chord, key) {
|
|
530
|
+
return isMinorKey(key) && isDiatonic(chord, { rootPc: _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, key.rootPc), modeMask12: _chunkFNDWXRRIcjs.HARMONIC_MINOR_MASK });
|
|
531
|
+
}
|
|
532
|
+
function isBorrowedChord(chord, key) {
|
|
533
|
+
if (isDiatonic(chord, key)) {
|
|
534
|
+
return false;
|
|
535
|
+
}
|
|
536
|
+
if (isHarmonicMinorAlteration(chord, key)) {
|
|
537
|
+
return false;
|
|
538
|
+
}
|
|
539
|
+
return isDiatonic(chord, parallelKey(key));
|
|
540
|
+
}
|
|
541
|
+
function borrowedSource(chord, key) {
|
|
542
|
+
if (isDiatonic(chord, key)) {
|
|
543
|
+
return null;
|
|
544
|
+
}
|
|
545
|
+
if (isNeapolitan(chord, key)) {
|
|
546
|
+
return "neapolitan";
|
|
547
|
+
}
|
|
548
|
+
if (isBorrowedChord(chord, key)) {
|
|
549
|
+
return isMinorKey(key) ? "parallelMajor" : "parallelMinor";
|
|
550
|
+
}
|
|
551
|
+
return null;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// src/analyze/functional/function.ts
|
|
555
|
+
var FUNCTION_BY_OFFSET = [
|
|
556
|
+
"tonic",
|
|
557
|
+
// 0 I
|
|
558
|
+
"subdominant",
|
|
559
|
+
// 1 bII (Neapolitan)
|
|
560
|
+
"subdominant",
|
|
561
|
+
// 2 ii
|
|
562
|
+
"tonic",
|
|
563
|
+
// 3 bIII
|
|
564
|
+
"tonic",
|
|
565
|
+
// 4 iii
|
|
566
|
+
"subdominant",
|
|
567
|
+
// 5 IV
|
|
568
|
+
"dominant",
|
|
569
|
+
// 6 #IV / bV
|
|
570
|
+
"dominant",
|
|
571
|
+
// 7 V
|
|
572
|
+
"subdominant",
|
|
573
|
+
// 8 bVI
|
|
574
|
+
"tonic",
|
|
575
|
+
// 9 vi
|
|
576
|
+
"subdominant",
|
|
577
|
+
// 10 bVII
|
|
578
|
+
"dominant"
|
|
579
|
+
// 11 vii
|
|
580
|
+
];
|
|
581
|
+
function isMinorKey(key) {
|
|
582
|
+
const hasMinorThird = key.modeMask12 >> 3 & 1;
|
|
583
|
+
const hasMajorThird2 = key.modeMask12 >> 4 & 1;
|
|
584
|
+
return Boolean(hasMinorThird) && !hasMajorThird2;
|
|
585
|
+
}
|
|
586
|
+
function functionOf(chord, key) {
|
|
587
|
+
const offset = _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, chord.rootPc - key.rootPc);
|
|
588
|
+
if (isNeapolitan(chord, key)) {
|
|
589
|
+
return "subdominant";
|
|
590
|
+
}
|
|
591
|
+
if (isAppliedDominant(chord, key)) {
|
|
592
|
+
return "dominant";
|
|
593
|
+
}
|
|
594
|
+
if (!isMinorKey(key) && hasMajorThird(chord) && (offset === 8 || offset === 10)) {
|
|
595
|
+
return "subdominant";
|
|
596
|
+
}
|
|
597
|
+
return _nullishCoalesce(FUNCTION_BY_OFFSET[offset], () => ( "tonic"));
|
|
598
|
+
}
|
|
599
|
+
function isAppliedDominant(chord, key) {
|
|
600
|
+
if (isDiatonic(chord, key)) {
|
|
601
|
+
return false;
|
|
602
|
+
}
|
|
603
|
+
const root = _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, chord.rootPc);
|
|
604
|
+
const resolvesTo = (step) => _chunkFNDWXRRIcjs.isScaleTone.call(void 0, _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, root + step), key);
|
|
605
|
+
if (hasMajorThird(chord) && chord.intervals.some((i) => _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, i) === 10)) {
|
|
606
|
+
return resolvesTo(5) || resolvesTo(11);
|
|
607
|
+
}
|
|
608
|
+
return isDiminishedQuality(chord.quality) && resolvesTo(1);
|
|
609
|
+
}
|
|
610
|
+
function isDiatonic(chord, key) {
|
|
611
|
+
return _chunkFNDWXRRIcjs.chordPitchClasses.call(void 0, chord).every((pc) => _chunkFNDWXRRIcjs.isScaleTone.call(void 0, pc, key));
|
|
612
|
+
}
|
|
613
|
+
function parallelKey(key) {
|
|
614
|
+
return {
|
|
615
|
+
rootPc: _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, key.rootPc),
|
|
616
|
+
modeMask12: isMinorKey(key) ? _chunkFNDWXRRIcjs.MAJOR_MASK : _chunkFNDWXRRIcjs.NATURAL_MINOR_MASK
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
function isDiminishedQuality(quality) {
|
|
620
|
+
return quality === "dim" || quality === "dim7" || quality === "m7b5";
|
|
621
|
+
}
|
|
622
|
+
function hasMajorThird(chord) {
|
|
623
|
+
return chord.intervals.some((interval) => _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, interval) === 4);
|
|
624
|
+
}
|
|
625
|
+
function analyzeChord(chord, key) {
|
|
626
|
+
const source = borrowedSource(chord, key);
|
|
627
|
+
return {
|
|
628
|
+
function: functionOf(chord, key),
|
|
629
|
+
borrowed: source !== null,
|
|
630
|
+
source,
|
|
631
|
+
roman: chordToRoman(chord, key)
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
function secondaryDominant(targetDegree, key) {
|
|
635
|
+
_chunk7MGZ7D62cjs.assertInteger.call(void 0, targetDegree, "targetDegree", 0, 6);
|
|
636
|
+
const targetRoot = degreeRootPc(targetDegree + 1, key);
|
|
637
|
+
return _chunkFNDWXRRIcjs.makeChord.call(void 0, _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, targetRoot + 7), "dom7");
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
// src/analyze/functional/cadence.ts
|
|
641
|
+
function detectCadence(from, to, key) {
|
|
642
|
+
const tonic = _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, key.rootPc);
|
|
643
|
+
const fromOffset = _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, from.rootPc - tonic);
|
|
644
|
+
const toOffset = _chunk7MGZ7D62cjs.pitchClassOf.call(void 0, to.rootPc - tonic);
|
|
645
|
+
const deceptiveTargets = isMinorKey(key) ? [8] : [8, 9];
|
|
646
|
+
if (fromOffset === 7 && toOffset === 0) {
|
|
647
|
+
return "authentic";
|
|
648
|
+
}
|
|
649
|
+
if (fromOffset === 5 && toOffset === 0) {
|
|
650
|
+
return "plagal";
|
|
651
|
+
}
|
|
652
|
+
if (fromOffset === 7 && deceptiveTargets.includes(toOffset)) {
|
|
653
|
+
return "deceptive";
|
|
654
|
+
}
|
|
655
|
+
if (toOffset === 7 && fromOffset !== 7) {
|
|
656
|
+
return "half";
|
|
657
|
+
}
|
|
658
|
+
return null;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
|
|
678
|
+
exports.detectChord = detectChord; exports.detectChordBest = detectChordBest; exports.detectKey = detectKey; exports.detectKeyFromNotes = detectKeyFromNotes; exports.detectKeyBest = detectKeyBest; exports.romanToChord = romanToChord; exports.chordToRoman = chordToRoman; exports.isMinorKey = isMinorKey; exports.functionOf = functionOf; exports.isDiatonic = isDiatonic; exports.parallelKey = parallelKey; exports.analyzeChord = analyzeChord; exports.secondaryDominant = secondaryDominant; exports.isBorrowedChord = isBorrowedChord; exports.borrowedSource = borrowedSource; exports.detectCadence = detectCadence;
|
|
679
|
+
//# sourceMappingURL=chunk-CAN76NCU.cjs.map
|