@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.
Files changed (198) hide show
  1. package/README.md +2 -2
  2. package/dist/analyze/index.cjs +39 -1947
  3. package/dist/analyze/index.cjs.map +1 -1
  4. package/dist/analyze/index.d.cts +197 -37
  5. package/dist/analyze/index.d.ts +197 -37
  6. package/dist/analyze/index.js +19 -8
  7. package/dist/chunk-36N73KZ3.cjs +246 -0
  8. package/dist/chunk-36N73KZ3.cjs.map +1 -0
  9. package/dist/chunk-4HLLZPXT.cjs +3077 -0
  10. package/dist/chunk-4HLLZPXT.cjs.map +1 -0
  11. package/dist/chunk-7MGZ7D62.cjs +498 -0
  12. package/dist/chunk-7MGZ7D62.cjs.map +1 -0
  13. package/dist/{chunk-4MHA432G.js → chunk-7NKDPF74.js} +403 -180
  14. package/dist/chunk-7NKDPF74.js.map +1 -0
  15. package/dist/chunk-CAN76NCU.cjs +679 -0
  16. package/dist/chunk-CAN76NCU.cjs.map +1 -0
  17. package/dist/{chunk-MIWO425M.js → chunk-D2FAJBYL.js} +101 -34
  18. package/dist/chunk-D2FAJBYL.js.map +1 -0
  19. package/dist/{chunk-SGU7SPLK.js → chunk-EHVEBWM5.js} +1056 -531
  20. package/dist/chunk-EHVEBWM5.js.map +1 -0
  21. package/dist/chunk-FCANXBAT.cjs +30 -0
  22. package/dist/chunk-FCANXBAT.cjs.map +1 -0
  23. package/dist/chunk-FNDWXRRI.cjs +479 -0
  24. package/dist/chunk-FNDWXRRI.cjs.map +1 -0
  25. package/dist/{chunk-IT2O4XFE.js → chunk-GQSGS2N4.js} +43 -24
  26. package/dist/chunk-GQSGS2N4.js.map +1 -0
  27. package/dist/{chunk-62QZKCJQ.js → chunk-HKGYCQ34.js} +10 -6
  28. package/dist/chunk-HKGYCQ34.js.map +1 -0
  29. package/dist/{chunk-AKLYPWIN.js → chunk-I24MV65U.js} +29 -6
  30. package/dist/chunk-I24MV65U.js.map +1 -0
  31. package/dist/{chunk-CHMXELDS.js → chunk-KMHOICIY.js} +311 -181
  32. package/dist/chunk-KMHOICIY.js.map +1 -0
  33. package/dist/chunk-LW53AHQU.cjs +1117 -0
  34. package/dist/chunk-LW53AHQU.cjs.map +1 -0
  35. package/dist/{chunk-2ZWMSJH6.js → chunk-NKIBQ6PT.js} +2 -2
  36. package/dist/chunk-NKIBQ6PT.js.map +1 -0
  37. package/dist/chunk-NP4NA2FB.cjs +106 -0
  38. package/dist/chunk-NP4NA2FB.cjs.map +1 -0
  39. package/dist/chunk-NVE34YGZ.cjs +1449 -0
  40. package/dist/chunk-NVE34YGZ.cjs.map +1 -0
  41. package/dist/{chunk-EH6EM37U.js → chunk-NYYWMV2C.js} +61 -49
  42. package/dist/chunk-NYYWMV2C.js.map +1 -0
  43. package/dist/{chunk-GOAW4VYL.js → chunk-Q2XUP227.js} +243 -117
  44. package/dist/chunk-Q2XUP227.js.map +1 -0
  45. package/dist/chunk-Q6OP4U43.cjs +327 -0
  46. package/dist/chunk-Q6OP4U43.cjs.map +1 -0
  47. package/dist/chunk-RC6GBMCD.cjs +845 -0
  48. package/dist/chunk-RC6GBMCD.cjs.map +1 -0
  49. package/dist/{chunk-C5XYKUVG.js → chunk-RK35RIN7.js} +370 -157
  50. package/dist/chunk-RK35RIN7.js.map +1 -0
  51. package/dist/chunk-RUMU3UA6.cjs +53 -0
  52. package/dist/chunk-RUMU3UA6.cjs.map +1 -0
  53. package/dist/chunk-T64C7ZD7.cjs +1 -0
  54. package/dist/chunk-T64C7ZD7.cjs.map +1 -0
  55. package/dist/chunk-XEBG3G53.js +498 -0
  56. package/dist/chunk-XEBG3G53.js.map +1 -0
  57. package/dist/{chunk-I5R7ZBJS.js → chunk-YLEMGEFH.js} +103 -59
  58. package/dist/chunk-YLEMGEFH.js.map +1 -0
  59. package/dist/chunk-ZEJR4TKL.cjs +173 -0
  60. package/dist/chunk-ZEJR4TKL.cjs.map +1 -0
  61. package/dist/core/index.cjs +130 -647
  62. package/dist/core/index.cjs.map +1 -1
  63. package/dist/core/index.d.cts +301 -39
  64. package/dist/core/index.d.ts +301 -39
  65. package/dist/core/index.js +54 -16
  66. package/dist/{function-DYt4iKsn.d.cts → function-BtiZb9i9.d.ts} +28 -7
  67. package/dist/{function-DVH4Eusr.d.ts → function-DNugAOrt.d.cts} +28 -7
  68. package/dist/generate/index.cjs +28 -4085
  69. package/dist/generate/index.cjs.map +1 -1
  70. package/dist/generate/index.d.cts +370 -62
  71. package/dist/generate/index.d.ts +370 -62
  72. package/dist/generate/index.js +23 -9
  73. package/dist/{index-CxqBQtH1.d.cts → index-6VR8-kit.d.ts} +19 -4
  74. package/dist/index-70p168VM.d.ts +192 -0
  75. package/dist/{index-CpOsP1y9.d.cts → index-Be74mcon.d.cts} +18 -17
  76. package/dist/index-BtXT6UQ0.d.cts +192 -0
  77. package/dist/{index-DxvARIP2.d.ts → index-C5UBbQ4G.d.ts} +18 -17
  78. package/dist/{index-Bt4tOUD9.d.ts → index-C83mZI1P.d.ts} +93 -8
  79. package/dist/{index-Bg5dYMmZ.d.ts → index-D6b6na69.d.cts} +14 -11
  80. package/dist/{index-Cl7mhOFM.d.cts → index-DXd9JikN.d.cts} +92 -10
  81. package/dist/{index-Cl7mhOFM.d.ts → index-DXd9JikN.d.ts} +92 -10
  82. package/dist/index-OG65ocOr.d.cts +272 -0
  83. package/dist/index-OG65ocOr.d.ts +272 -0
  84. package/dist/{index-Jc0Ryi79.d.ts → index-tJhkmQgE.d.cts} +19 -4
  85. package/dist/{index-Dikst44v.d.cts → index-tSQh-xwY.d.ts} +14 -11
  86. package/dist/{index-BNlGP86A.d.cts → index-y_ak9_Hi.d.cts} +93 -8
  87. package/dist/index.cjs +419 -7383
  88. package/dist/index.cjs.map +1 -1
  89. package/dist/index.d.cts +14 -14
  90. package/dist/index.d.ts +14 -14
  91. package/dist/index.js +111 -27
  92. package/dist/model/index.cjs +8 -2562
  93. package/dist/model/index.cjs.map +1 -1
  94. package/dist/model/index.d.cts +433 -75
  95. package/dist/model/index.d.ts +433 -75
  96. package/dist/model/index.js +6 -7
  97. package/dist/styled-DIRkk9Uz.d.ts +506 -0
  98. package/dist/styled-DJbkJQfj.d.cts +506 -0
  99. package/dist/theory/index.cjs +172 -1822
  100. package/dist/theory/index.cjs.map +1 -1
  101. package/dist/theory/index.d.cts +151 -233
  102. package/dist/theory/index.d.ts +151 -233
  103. package/dist/theory/index.js +30 -7
  104. package/dist/{types-MGP29r3t.d.cts → types-BN6_Q9Kl.d.cts} +11 -2
  105. package/dist/{types-MGP29r3t.d.ts → types-BN6_Q9Kl.d.ts} +11 -2
  106. package/package.json +24 -6
  107. package/dist/chunk-2ZWMSJH6.js.map +0 -1
  108. package/dist/chunk-4MHA432G.js.map +0 -1
  109. package/dist/chunk-62QZKCJQ.js.map +0 -1
  110. package/dist/chunk-AKLYPWIN.js.map +0 -1
  111. package/dist/chunk-C5XYKUVG.js.map +0 -1
  112. package/dist/chunk-CHMXELDS.js.map +0 -1
  113. package/dist/chunk-DYWFNC4A.js +0 -152
  114. package/dist/chunk-DYWFNC4A.js.map +0 -1
  115. package/dist/chunk-EH6EM37U.js.map +0 -1
  116. package/dist/chunk-FBQK3ZQN.js +0 -131
  117. package/dist/chunk-FBQK3ZQN.js.map +0 -1
  118. package/dist/chunk-GOAW4VYL.js.map +0 -1
  119. package/dist/chunk-I5R7ZBJS.js.map +0 -1
  120. package/dist/chunk-IT2O4XFE.js.map +0 -1
  121. package/dist/chunk-MIWO425M.js.map +0 -1
  122. package/dist/chunk-SGU7SPLK.js.map +0 -1
  123. package/dist/index-CGMZNCx6.d.cts +0 -140
  124. package/dist/index-CGMZNCx6.d.ts +0 -140
  125. package/dist/index-CnZCo29u.d.cts +0 -108
  126. package/dist/index-JnF4v9bx.d.ts +0 -108
  127. package/dist/styled-DZ7GjShb.d.ts +0 -282
  128. package/dist/styled-ZTbdaVFM.d.cts +0 -282
  129. package/src/analyze/arrange/index.ts +0 -21
  130. package/src/analyze/arrange/internal.ts +0 -127
  131. package/src/analyze/arrange/tension.ts +0 -199
  132. package/src/analyze/arrange/tracks.ts +0 -312
  133. package/src/analyze/detect/index.ts +0 -272
  134. package/src/analyze/functional/borrowed.ts +0 -84
  135. package/src/analyze/functional/cadence.ts +0 -66
  136. package/src/analyze/functional/function.ts +0 -184
  137. package/src/analyze/functional/index.ts +0 -23
  138. package/src/analyze/functional/internal.ts +0 -29
  139. package/src/analyze/functional/roman.ts +0 -402
  140. package/src/analyze/index.ts +0 -49
  141. package/src/analyze/timeline/index.ts +0 -451
  142. package/src/analyze/voice/index.ts +0 -339
  143. package/src/core/event-index/index.ts +0 -104
  144. package/src/core/index.ts +0 -61
  145. package/src/core/interval/index.ts +0 -81
  146. package/src/core/meter/index.ts +0 -302
  147. package/src/core/pitch/index.ts +0 -311
  148. package/src/core/random/index.ts +0 -76
  149. package/src/core/tuning/index.ts +0 -186
  150. package/src/core/types.ts +0 -29
  151. package/src/core/validation/index.ts +0 -119
  152. package/src/generate/bass/index.ts +0 -373
  153. package/src/generate/countermelody/index.ts +0 -470
  154. package/src/generate/drums/beat.ts +0 -266
  155. package/src/generate/drums/euclid.ts +0 -65
  156. package/src/generate/drums/fills.ts +0 -356
  157. package/src/generate/drums/ghost.ts +0 -119
  158. package/src/generate/drums/hihat.ts +0 -285
  159. package/src/generate/drums/hit.ts +0 -31
  160. package/src/generate/drums/index.ts +0 -361
  161. package/src/generate/drums/internal.ts +0 -257
  162. package/src/generate/drums/kick.ts +0 -160
  163. package/src/generate/drums/percussion.ts +0 -121
  164. package/src/generate/drums/rng.ts +0 -7
  165. package/src/generate/drums/swing.ts +0 -71
  166. package/src/generate/groove/index.ts +0 -351
  167. package/src/generate/harmonize/index.ts +0 -451
  168. package/src/generate/index.ts +0 -58
  169. package/src/generate/motif/index.ts +0 -422
  170. package/src/generate/progression/index.ts +0 -362
  171. package/src/generate/reharmony/index.ts +0 -323
  172. package/src/generate/rhythm/index.ts +0 -175
  173. package/src/index.ts +0 -13
  174. package/src/model/chord.ts +0 -442
  175. package/src/model/index.ts +0 -15
  176. package/src/model/interval.ts +0 -82
  177. package/src/model/key.ts +0 -266
  178. package/src/model/note.ts +0 -176
  179. package/src/model/progression.ts +0 -161
  180. package/src/model/shared.ts +0 -12
  181. package/src/theory/chord/index.ts +0 -375
  182. package/src/theory/chordscale/index.ts +0 -374
  183. package/src/theory/counterpoint/index.ts +0 -230
  184. package/src/theory/harmony/index.ts +0 -77
  185. package/src/theory/index.ts +0 -112
  186. package/src/theory/safety/index.ts +0 -488
  187. package/src/theory/scale/degrees.ts +0 -123
  188. package/src/theory/scale/index.ts +0 -28
  189. package/src/theory/scale/key.ts +0 -56
  190. package/src/theory/scale/masks.ts +0 -153
  191. package/src/theory/spelling/index.ts +0 -249
  192. package/src/theory/symbol/index.ts +0 -268
  193. package/src/theory/voicing/index.ts +0 -5
  194. package/src/theory/voicing/internal.ts +0 -168
  195. package/src/theory/voicing/leading.ts +0 -112
  196. package/src/theory/voicing/satb.ts +0 -216
  197. package/src/theory/voicing/styled.ts +0 -199
  198. package/tsconfig.json +0 -23
@@ -1,6 +1,10 @@
1
1
  import {
2
+ BASS_STYLES,
3
+ BORROWED_DEGREES,
4
+ DRUM_NOTES,
2
5
  applyGrooveTemplate,
3
6
  developMotif,
7
+ drumVoiceOf,
4
8
  extractGrooveTemplate,
5
9
  generateBassLine,
6
10
  generateCounterMelody,
@@ -10,27 +14,34 @@ import {
10
14
  generateRhythm,
11
15
  harmonizeMelody,
12
16
  humanize,
17
+ motifToNoteEvents,
13
18
  onsetWeightCurve,
19
+ pickProgressionPreset,
14
20
  progressions,
15
21
  progressionsByStyle,
16
22
  rhythmDensity,
23
+ rhythmToNoteEvents,
17
24
  transformMotif
18
- } from "../chunk-4MHA432G.js";
19
- import "../chunk-62QZKCJQ.js";
20
- import "../chunk-I5R7ZBJS.js";
25
+ } from "../chunk-7NKDPF74.js";
26
+ import "../chunk-HKGYCQ34.js";
27
+ import "../chunk-YLEMGEFH.js";
21
28
  import {
22
29
  modalInterchangePalette,
23
30
  negativeHarmonyMirror,
24
31
  substituteChord
25
- } from "../chunk-IT2O4XFE.js";
26
- import "../chunk-CHMXELDS.js";
27
- import "../chunk-2ZWMSJH6.js";
28
- import "../chunk-EH6EM37U.js";
29
- import "../chunk-MIWO425M.js";
30
- import "../chunk-FBQK3ZQN.js";
32
+ } from "../chunk-GQSGS2N4.js";
33
+ import "../chunk-KMHOICIY.js";
34
+ import "../chunk-NKIBQ6PT.js";
35
+ import "../chunk-NYYWMV2C.js";
36
+ import "../chunk-D2FAJBYL.js";
37
+ import "../chunk-XEBG3G53.js";
31
38
  export {
39
+ BASS_STYLES,
40
+ BORROWED_DEGREES,
41
+ DRUM_NOTES,
32
42
  applyGrooveTemplate,
33
43
  developMotif,
44
+ drumVoiceOf,
34
45
  extractGrooveTemplate,
35
46
  generateBassLine,
36
47
  generateCounterMelody,
@@ -41,11 +52,14 @@ export {
41
52
  harmonizeMelody,
42
53
  humanize,
43
54
  modalInterchangePalette,
55
+ motifToNoteEvents,
44
56
  negativeHarmonyMirror,
45
57
  onsetWeightCurve,
58
+ pickProgressionPreset,
46
59
  progressions,
47
60
  progressionsByStyle,
48
61
  rhythmDensity,
62
+ rhythmToNoteEvents,
49
63
  substituteChord,
50
64
  transformMotif
51
65
  };
@@ -1,5 +1,5 @@
1
- import { K as KeyScale } from './types-MGP29r3t.cjs';
2
- import { C as Chord } from './index-BNlGP86A.cjs';
1
+ import { K as KeyScale } from './types-BN6_Q9Kl.js';
2
+ import { C as Chord } from './index-C83mZI1P.js';
3
3
 
4
4
  /**
5
5
  * Severity policy: `strict` counterpoint vs. lenient `pop` voice-leading.
@@ -102,7 +102,22 @@ type SafetyResult = {
102
102
  * ```
103
103
  * @category Arrangement & Analysis
104
104
  */
105
- declare function evaluateSafety(q: SafetyQuery): SafetyResult;
105
+ declare function evaluateSafety(q: SafetyQuery, opts?: EvaluateSafetyOptions): SafetyResult;
106
+ /**
107
+ * Options for {@link evaluateSafety}.
108
+ *
109
+ * @category Arrangement & Analysis
110
+ */
111
+ type EvaluateSafetyOptions = {
112
+ /**
113
+ * Whether to search for safe replacement pitches when the verdict is not
114
+ * safe. Turning it off skips up to two dozen extra evaluations per rejected
115
+ * pitch, which is worth doing when only the verdict is wanted.
116
+ *
117
+ * @defaultValue true
118
+ */
119
+ suggestions?: boolean;
120
+ };
106
121
  /**
107
122
  * Enumerate placeable pitches in a range, chord tones first, descending.
108
123
  *
@@ -125,4 +140,4 @@ declare function evaluateSafety(q: SafetyQuery): SafetyResult;
125
140
  */
126
141
  declare function enumerateSafePitches(q: Omit<SafetyQuery, 'candidatePitch'>, pitchLow: number, pitchHigh: number): number[];
127
142
 
128
- export { NoteSafety as N, ReasonFlag as R, type SafetyProfile as S, type VoiceSnapshot as V, type SafetyQuery as a, type SafetyResult as b, evaluateSafety as c, enumerateSafePitches as e };
143
+ export { type EvaluateSafetyOptions as E, NoteSafety as N, ReasonFlag as R, type SafetyProfile as S, type VoiceSnapshot as V, type SafetyQuery as a, type SafetyResult as b, evaluateSafety as c, enumerateSafePitches as e };
@@ -0,0 +1,192 @@
1
+ import { K as KeyScale, N as NoteEvent } from './types-BN6_Q9Kl.js';
2
+ import { a as ChordQuality, C as Chord } from './index-C83mZI1P.js';
3
+
4
+ /**
5
+ * Recognition: infer a chord name from a set of pitches, or a key from a set of
6
+ * pitch classes. This is the inverse direction of the chord/scale builders,
7
+ * which only go name -> notes.
8
+ */
9
+
10
+ /**
11
+ * A candidate chord interpretation of a pitch set.
12
+ *
13
+ * @category Recognition
14
+ */
15
+ type ChordMatch = {
16
+ rootPc: number;
17
+ quality: ChordQuality;
18
+ /** Chord tones absent from the input (an incomplete voicing). */
19
+ missingPcs: number[];
20
+ /** Input pitch classes not belonging to the chord. */
21
+ extraPcs: number[];
22
+ /** True when the input pitch-class set equals the chord exactly. */
23
+ exact: boolean;
24
+ /**
25
+ * Inversion implied by a known bass: 0 for root position, 1..n for an
26
+ * inversion. Null when no inversion can be named — either the input is an
27
+ * unordered pitch-class set with no bass, or the bass is not a chord tone (a
28
+ * pedal or passing bass), in which case `bassPc` still reports it.
29
+ */
30
+ inversion: number | null;
31
+ /** Bass pitch class when the lowest note is not the root. */
32
+ bassPc?: number;
33
+ };
34
+ /**
35
+ * Input interpretation for {@link detectChord} and {@link detectChordBest}.
36
+ *
37
+ * @category Recognition
38
+ */
39
+ type DetectChordOptions = {
40
+ /**
41
+ * `midi` uses the numerically lowest pitch as bass; `pitchClass` treats the
42
+ * input as unordered. `auto` (default) selects pitch-class mode only when all
43
+ * values lie in 0..11.
44
+ */
45
+ input?: 'auto' | 'midi' | 'pitchClass';
46
+ /** Explicit bass pitch class, including for an unordered pitch-class set. */
47
+ bassPc?: number;
48
+ };
49
+ /**
50
+ * A candidate key interpretation of a pitch-class set.
51
+ *
52
+ * @category Recognition
53
+ */
54
+ type KeyMatch = {
55
+ /** The scale that scored best for this tonic and mode, `variant` included. */
56
+ key: KeyScale;
57
+ mode: 'major' | 'minor';
58
+ /** Which scale form `key` uses; minor keys pick the best-scoring of the three. */
59
+ variant: KeyVariant;
60
+ /**
61
+ * Fraction of the distinct input pitch classes that belong to `key`, in
62
+ * [0, 1]. Measured against the returned scale, so it always agrees with
63
+ * `isScaleTone(pc, match.key)`. This is a coverage figure, not the ranking:
64
+ * see `score`.
65
+ */
66
+ fit: number;
67
+ /**
68
+ * The value the results are ranked by, in [0, 1.5]. Unlike `fit` it counts
69
+ * every occurrence rather than every distinct pitch class, so a repeated tone
70
+ * weighs more, and it adds half a count per sounding of the tonic itself to
71
+ * break ties between keys that contain the same notes.
72
+ */
73
+ score: number;
74
+ };
75
+ /**
76
+ * Which form of a scale a {@link KeyMatch} settled on.
77
+ *
78
+ * @category Recognition
79
+ */
80
+ type KeyVariant = 'major' | 'natural' | 'harmonic' | 'melodic';
81
+ /**
82
+ * Input weighting for {@link detectKey}.
83
+ *
84
+ * @category Recognition
85
+ */
86
+ type DetectKeyOptions = {
87
+ /**
88
+ * How much each pitch counts toward the histogram, one entry per pitch.
89
+ * Defaults to one per pitch, which weighs a thirty-second-note ornament as
90
+ * heavily as the whole note under it. {@link detectKeyFromNotes} supplies
91
+ * duration times velocity, matching how chord inference weighs its own
92
+ * histogram.
93
+ */
94
+ weights?: readonly number[];
95
+ };
96
+ /**
97
+ * Identify chords matching a set of pitches.
98
+ *
99
+ * Every input pitch class is tried as a root against every known chord quality.
100
+ * A match is reported when all of the chord's tones are present in the input, or
101
+ * when the only absent tone is the perfect fifth (a common omission in shell
102
+ * voicings); matches are ranked best-first by fewest extra notes, then fewest
103
+ * missing notes, then most specific (largest) chord. An exact match (no extras,
104
+ * no missing) is flagged and ranked first.
105
+ *
106
+ * @param pitches MIDI pitches or bare pitch classes (octave-agnostic).
107
+ * @returns Ranked chord interpretations (may be empty).
108
+ * @example
109
+ * ```ts
110
+ * import { detectChord } from '@libraz/libcantus';
111
+ * const matches = detectChord([60, 64, 67]); // C E G
112
+ * matches[0]; // { rootPc: 0, quality: 'maj', exact: true, ... }
113
+ * ```
114
+ * @category Recognition
115
+ */
116
+ declare function detectChord(pitches: readonly number[], opts?: DetectChordOptions): ChordMatch[];
117
+ /**
118
+ * The single best chord interpretation of a pitch set, or null if none.
119
+ *
120
+ * @param pitches MIDI pitches or bare pitch classes.
121
+ * @returns The top-ranked chord, or null when nothing matches.
122
+ * @example
123
+ * ```ts
124
+ * import { detectChordBest } from '@libraz/libcantus';
125
+ * detectChordBest([60, 64, 67]); // C major triad: { rootPc: 0, quality: 'maj', ... }
126
+ * ```
127
+ * @category Recognition
128
+ */
129
+ declare function detectChordBest(pitches: readonly number[], opts?: DetectChordOptions): Chord | null;
130
+ /**
131
+ * Rank major and minor keys by how well they contain a set of pitch classes.
132
+ *
133
+ * Ranking is by `score`, which counts repetitions and adds a tonic weight so
134
+ * that, among equally-fitting keys, the one whose root is actually sounded is
135
+ * preferred. Minor candidates are scored against the natural, harmonic, and
136
+ * melodic minor variants and keep the best of the three, so a minor cadence
137
+ * containing the leading tone still resolves to its own tonic; the winning
138
+ * variant is what `key` and `variant` report, so `fit` describes the scale the
139
+ * caller receives. Returns all 24 keys ranked best-first, or an empty array for
140
+ * an empty input (mirroring {@link detectChord}).
141
+ *
142
+ * @param pitches MIDI pitches or bare pitch classes.
143
+ * @returns Ranked key interpretations (empty for an empty input).
144
+ * @example
145
+ * ```ts
146
+ * import { detectKey } from '@libraz/libcantus';
147
+ * const keys = detectKey([60, 62, 64, 65, 67, 69, 71]); // C major scale
148
+ * keys[0].mode; // 'major', with keys[0].key.rootPc === 0
149
+ * ```
150
+ * @category Recognition
151
+ */
152
+ declare function detectKey(pitches: readonly number[], opts?: DetectKeyOptions): KeyMatch[];
153
+ /**
154
+ * Rank keys by how well they contain a set of note events, weighting each note
155
+ * by how much of the music it actually occupies.
156
+ *
157
+ * {@link detectKey} counts every pitch once, which lets a run of fast ornamental
158
+ * notes outvote the sustained harmony that establishes the key. This weighs
159
+ * each note by duration times velocity, the same measure chord inference uses,
160
+ * so the two agree on what the music emphasises. Notes that never sound (zero
161
+ * or negative duration) are ignored.
162
+ *
163
+ * @param notes The note events to weigh.
164
+ * @returns Ranked key interpretations (empty when nothing sounds).
165
+ * @example
166
+ * ```ts
167
+ * import { detectKeyFromNotes } from '@libraz/libcantus';
168
+ * detectKeyFromNotes([{ pitch: 60, startBeat: 0, durationBeat: 4 }])[0]?.key.rootPc; // 0
169
+ * ```
170
+ * @category Recognition
171
+ */
172
+ declare function detectKeyFromNotes(notes: readonly NoteEvent[]): KeyMatch[];
173
+ /**
174
+ * The single best key interpretation of a pitch set.
175
+ *
176
+ * The counterpart of {@link detectChordBest}: the ranked list is the general
177
+ * answer, but a caller that just wants "what key is this" should not have to
178
+ * index into it and assert the result is there.
179
+ *
180
+ * @param pitches MIDI pitches or bare pitch classes.
181
+ * @param opts How to weigh the input; see {@link DetectKeyOptions}.
182
+ * @returns The top-ranked key, or null when nothing sounds.
183
+ * @example
184
+ * ```ts
185
+ * import { detectKeyBest } from '@libraz/libcantus';
186
+ * detectKeyBest([0, 2, 4, 5, 7, 9, 11])?.mode; // 'major'
187
+ * ```
188
+ * @category Recognition
189
+ */
190
+ declare function detectKeyBest(pitches: readonly number[], opts?: DetectKeyOptions): KeyMatch | null;
191
+
192
+ export { type ChordMatch as C, type DetectChordOptions as D, type KeyMatch as K, type DetectKeyOptions as a, type KeyVariant as b, detectChordBest as c, detectChord as d, detectKey as e, detectKeyBest as f, detectKeyFromNotes as g };
@@ -1,18 +1,8 @@
1
- import { T as TimeSignature } from './index-Cl7mhOFM.cjs';
2
- import { K as KeyScale, N as NoteEvent } from './types-MGP29r3t.cjs';
3
- import { C as Chord, b as ChordSpan } from './index-BNlGP86A.cjs';
4
- import { C as Cadence } from './function-DYt4iKsn.cjs';
1
+ import { T as TimeSignature } from './index-DXd9JikN.cjs';
2
+ import { K as KeyScale, N as NoteEvent } from './types-BN6_Q9Kl.cjs';
3
+ import { C as Chord, b as ChordSegment, c as ChordSpan } from './index-y_ak9_Hi.cjs';
4
+ import { C as Cadence } from './function-DNugAOrt.cjs';
5
5
 
6
- /**
7
- * A chord occupying a half-open beat span.
8
- *
9
- * @category Arrangement & Analysis
10
- */
11
- type ChordSegment = {
12
- startBeat: number;
13
- endBeat: number;
14
- chord: Chord;
15
- };
16
6
  /**
17
7
  * A beat-indexed sequence of chord segments.
18
8
  *
@@ -36,14 +26,14 @@ type ChordTimeline = {
36
26
  * @returns A queryable chord timeline.
37
27
  * @category Arrangement & Analysis
38
28
  */
39
- declare function chordTimelineFromChords(chords: ChordSpan[], totalBeats: number): ChordTimeline;
29
+ declare function chordTimelineFromChords(chords: readonly ChordSpan[], totalBeats: number): ChordTimeline;
40
30
  /**
41
31
  * Options controlling {@link chordTimelineFromNotes}.
42
32
  *
43
33
  * @category Arrangement & Analysis
44
34
  */
45
35
  type ChordTimelineOptions = {
46
- /** Key context; inferred from the notes with {@link detectKey} when omitted. */
36
+ /** Key context; inferred from the notes with {@link detectKeyFromNotes} when omitted. */
47
37
  key?: KeyScale;
48
38
  /**
49
39
  * Time signature used for metric accents; defaults to 4/4.
@@ -63,6 +53,17 @@ type ChordTimelineOptions = {
63
53
  * @defaultValue the end of the last note
64
54
  */
65
55
  totalBeats?: number;
56
+ /**
57
+ * Upper bound on the work this call may do — note counts, windows, and
58
+ * candidate counts are each checked against it before anything is allocated.
59
+ *
60
+ * Raise it to analyse a piece larger than the default allows; the default is
61
+ * {@link DEFAULT_GENERATION_BUDGET}, chosen so a runaway input fails fast
62
+ * rather than blocking the thread.
63
+ *
64
+ * @defaultValue {@link DEFAULT_GENERATION_BUDGET}
65
+ */
66
+ budget?: number;
66
67
  };
67
68
  /**
68
69
  * The result of {@link chordTimelineFromNotes}.
@@ -148,4 +149,4 @@ type CadenceHit = {
148
149
  */
149
150
  declare function detectCadences(timeline: ChordTimeline, key: KeyScale): CadenceHit[];
150
151
 
151
- export { type CadenceHit as C, type ChordSegment as a, type ChordTimeline as b, type ChordTimelineOptions as c, type ChordTimelineResult as d, chordTimelineFromChords as e, chordTimelineFromNotes as f, detectCadences as g };
152
+ export { type CadenceHit as C, type ChordTimeline as a, type ChordTimelineOptions as b, type ChordTimelineResult as c, chordTimelineFromChords as d, chordTimelineFromNotes as e, detectCadences as f };
@@ -0,0 +1,192 @@
1
+ import { K as KeyScale, N as NoteEvent } from './types-BN6_Q9Kl.cjs';
2
+ import { a as ChordQuality, C as Chord } from './index-y_ak9_Hi.cjs';
3
+
4
+ /**
5
+ * Recognition: infer a chord name from a set of pitches, or a key from a set of
6
+ * pitch classes. This is the inverse direction of the chord/scale builders,
7
+ * which only go name -> notes.
8
+ */
9
+
10
+ /**
11
+ * A candidate chord interpretation of a pitch set.
12
+ *
13
+ * @category Recognition
14
+ */
15
+ type ChordMatch = {
16
+ rootPc: number;
17
+ quality: ChordQuality;
18
+ /** Chord tones absent from the input (an incomplete voicing). */
19
+ missingPcs: number[];
20
+ /** Input pitch classes not belonging to the chord. */
21
+ extraPcs: number[];
22
+ /** True when the input pitch-class set equals the chord exactly. */
23
+ exact: boolean;
24
+ /**
25
+ * Inversion implied by a known bass: 0 for root position, 1..n for an
26
+ * inversion. Null when no inversion can be named — either the input is an
27
+ * unordered pitch-class set with no bass, or the bass is not a chord tone (a
28
+ * pedal or passing bass), in which case `bassPc` still reports it.
29
+ */
30
+ inversion: number | null;
31
+ /** Bass pitch class when the lowest note is not the root. */
32
+ bassPc?: number;
33
+ };
34
+ /**
35
+ * Input interpretation for {@link detectChord} and {@link detectChordBest}.
36
+ *
37
+ * @category Recognition
38
+ */
39
+ type DetectChordOptions = {
40
+ /**
41
+ * `midi` uses the numerically lowest pitch as bass; `pitchClass` treats the
42
+ * input as unordered. `auto` (default) selects pitch-class mode only when all
43
+ * values lie in 0..11.
44
+ */
45
+ input?: 'auto' | 'midi' | 'pitchClass';
46
+ /** Explicit bass pitch class, including for an unordered pitch-class set. */
47
+ bassPc?: number;
48
+ };
49
+ /**
50
+ * A candidate key interpretation of a pitch-class set.
51
+ *
52
+ * @category Recognition
53
+ */
54
+ type KeyMatch = {
55
+ /** The scale that scored best for this tonic and mode, `variant` included. */
56
+ key: KeyScale;
57
+ mode: 'major' | 'minor';
58
+ /** Which scale form `key` uses; minor keys pick the best-scoring of the three. */
59
+ variant: KeyVariant;
60
+ /**
61
+ * Fraction of the distinct input pitch classes that belong to `key`, in
62
+ * [0, 1]. Measured against the returned scale, so it always agrees with
63
+ * `isScaleTone(pc, match.key)`. This is a coverage figure, not the ranking:
64
+ * see `score`.
65
+ */
66
+ fit: number;
67
+ /**
68
+ * The value the results are ranked by, in [0, 1.5]. Unlike `fit` it counts
69
+ * every occurrence rather than every distinct pitch class, so a repeated tone
70
+ * weighs more, and it adds half a count per sounding of the tonic itself to
71
+ * break ties between keys that contain the same notes.
72
+ */
73
+ score: number;
74
+ };
75
+ /**
76
+ * Which form of a scale a {@link KeyMatch} settled on.
77
+ *
78
+ * @category Recognition
79
+ */
80
+ type KeyVariant = 'major' | 'natural' | 'harmonic' | 'melodic';
81
+ /**
82
+ * Input weighting for {@link detectKey}.
83
+ *
84
+ * @category Recognition
85
+ */
86
+ type DetectKeyOptions = {
87
+ /**
88
+ * How much each pitch counts toward the histogram, one entry per pitch.
89
+ * Defaults to one per pitch, which weighs a thirty-second-note ornament as
90
+ * heavily as the whole note under it. {@link detectKeyFromNotes} supplies
91
+ * duration times velocity, matching how chord inference weighs its own
92
+ * histogram.
93
+ */
94
+ weights?: readonly number[];
95
+ };
96
+ /**
97
+ * Identify chords matching a set of pitches.
98
+ *
99
+ * Every input pitch class is tried as a root against every known chord quality.
100
+ * A match is reported when all of the chord's tones are present in the input, or
101
+ * when the only absent tone is the perfect fifth (a common omission in shell
102
+ * voicings); matches are ranked best-first by fewest extra notes, then fewest
103
+ * missing notes, then most specific (largest) chord. An exact match (no extras,
104
+ * no missing) is flagged and ranked first.
105
+ *
106
+ * @param pitches MIDI pitches or bare pitch classes (octave-agnostic).
107
+ * @returns Ranked chord interpretations (may be empty).
108
+ * @example
109
+ * ```ts
110
+ * import { detectChord } from '@libraz/libcantus';
111
+ * const matches = detectChord([60, 64, 67]); // C E G
112
+ * matches[0]; // { rootPc: 0, quality: 'maj', exact: true, ... }
113
+ * ```
114
+ * @category Recognition
115
+ */
116
+ declare function detectChord(pitches: readonly number[], opts?: DetectChordOptions): ChordMatch[];
117
+ /**
118
+ * The single best chord interpretation of a pitch set, or null if none.
119
+ *
120
+ * @param pitches MIDI pitches or bare pitch classes.
121
+ * @returns The top-ranked chord, or null when nothing matches.
122
+ * @example
123
+ * ```ts
124
+ * import { detectChordBest } from '@libraz/libcantus';
125
+ * detectChordBest([60, 64, 67]); // C major triad: { rootPc: 0, quality: 'maj', ... }
126
+ * ```
127
+ * @category Recognition
128
+ */
129
+ declare function detectChordBest(pitches: readonly number[], opts?: DetectChordOptions): Chord | null;
130
+ /**
131
+ * Rank major and minor keys by how well they contain a set of pitch classes.
132
+ *
133
+ * Ranking is by `score`, which counts repetitions and adds a tonic weight so
134
+ * that, among equally-fitting keys, the one whose root is actually sounded is
135
+ * preferred. Minor candidates are scored against the natural, harmonic, and
136
+ * melodic minor variants and keep the best of the three, so a minor cadence
137
+ * containing the leading tone still resolves to its own tonic; the winning
138
+ * variant is what `key` and `variant` report, so `fit` describes the scale the
139
+ * caller receives. Returns all 24 keys ranked best-first, or an empty array for
140
+ * an empty input (mirroring {@link detectChord}).
141
+ *
142
+ * @param pitches MIDI pitches or bare pitch classes.
143
+ * @returns Ranked key interpretations (empty for an empty input).
144
+ * @example
145
+ * ```ts
146
+ * import { detectKey } from '@libraz/libcantus';
147
+ * const keys = detectKey([60, 62, 64, 65, 67, 69, 71]); // C major scale
148
+ * keys[0].mode; // 'major', with keys[0].key.rootPc === 0
149
+ * ```
150
+ * @category Recognition
151
+ */
152
+ declare function detectKey(pitches: readonly number[], opts?: DetectKeyOptions): KeyMatch[];
153
+ /**
154
+ * Rank keys by how well they contain a set of note events, weighting each note
155
+ * by how much of the music it actually occupies.
156
+ *
157
+ * {@link detectKey} counts every pitch once, which lets a run of fast ornamental
158
+ * notes outvote the sustained harmony that establishes the key. This weighs
159
+ * each note by duration times velocity, the same measure chord inference uses,
160
+ * so the two agree on what the music emphasises. Notes that never sound (zero
161
+ * or negative duration) are ignored.
162
+ *
163
+ * @param notes The note events to weigh.
164
+ * @returns Ranked key interpretations (empty when nothing sounds).
165
+ * @example
166
+ * ```ts
167
+ * import { detectKeyFromNotes } from '@libraz/libcantus';
168
+ * detectKeyFromNotes([{ pitch: 60, startBeat: 0, durationBeat: 4 }])[0]?.key.rootPc; // 0
169
+ * ```
170
+ * @category Recognition
171
+ */
172
+ declare function detectKeyFromNotes(notes: readonly NoteEvent[]): KeyMatch[];
173
+ /**
174
+ * The single best key interpretation of a pitch set.
175
+ *
176
+ * The counterpart of {@link detectChordBest}: the ranked list is the general
177
+ * answer, but a caller that just wants "what key is this" should not have to
178
+ * index into it and assert the result is there.
179
+ *
180
+ * @param pitches MIDI pitches or bare pitch classes.
181
+ * @param opts How to weigh the input; see {@link DetectKeyOptions}.
182
+ * @returns The top-ranked key, or null when nothing sounds.
183
+ * @example
184
+ * ```ts
185
+ * import { detectKeyBest } from '@libraz/libcantus';
186
+ * detectKeyBest([0, 2, 4, 5, 7, 9, 11])?.mode; // 'major'
187
+ * ```
188
+ * @category Recognition
189
+ */
190
+ declare function detectKeyBest(pitches: readonly number[], opts?: DetectKeyOptions): KeyMatch | null;
191
+
192
+ export { type ChordMatch as C, type DetectChordOptions as D, type KeyMatch as K, type DetectKeyOptions as a, type KeyVariant as b, detectChordBest as c, detectChord as d, detectKey as e, detectKeyBest as f, detectKeyFromNotes as g };
@@ -1,18 +1,8 @@
1
- import { T as TimeSignature } from './index-Cl7mhOFM.js';
2
- import { K as KeyScale, N as NoteEvent } from './types-MGP29r3t.js';
3
- import { C as Chord, b as ChordSpan } from './index-Bt4tOUD9.js';
4
- import { C as Cadence } from './function-DVH4Eusr.js';
1
+ import { T as TimeSignature } from './index-DXd9JikN.js';
2
+ import { K as KeyScale, N as NoteEvent } from './types-BN6_Q9Kl.js';
3
+ import { C as Chord, b as ChordSegment, c as ChordSpan } from './index-C83mZI1P.js';
4
+ import { C as Cadence } from './function-BtiZb9i9.js';
5
5
 
6
- /**
7
- * A chord occupying a half-open beat span.
8
- *
9
- * @category Arrangement & Analysis
10
- */
11
- type ChordSegment = {
12
- startBeat: number;
13
- endBeat: number;
14
- chord: Chord;
15
- };
16
6
  /**
17
7
  * A beat-indexed sequence of chord segments.
18
8
  *
@@ -36,14 +26,14 @@ type ChordTimeline = {
36
26
  * @returns A queryable chord timeline.
37
27
  * @category Arrangement & Analysis
38
28
  */
39
- declare function chordTimelineFromChords(chords: ChordSpan[], totalBeats: number): ChordTimeline;
29
+ declare function chordTimelineFromChords(chords: readonly ChordSpan[], totalBeats: number): ChordTimeline;
40
30
  /**
41
31
  * Options controlling {@link chordTimelineFromNotes}.
42
32
  *
43
33
  * @category Arrangement & Analysis
44
34
  */
45
35
  type ChordTimelineOptions = {
46
- /** Key context; inferred from the notes with {@link detectKey} when omitted. */
36
+ /** Key context; inferred from the notes with {@link detectKeyFromNotes} when omitted. */
47
37
  key?: KeyScale;
48
38
  /**
49
39
  * Time signature used for metric accents; defaults to 4/4.
@@ -63,6 +53,17 @@ type ChordTimelineOptions = {
63
53
  * @defaultValue the end of the last note
64
54
  */
65
55
  totalBeats?: number;
56
+ /**
57
+ * Upper bound on the work this call may do — note counts, windows, and
58
+ * candidate counts are each checked against it before anything is allocated.
59
+ *
60
+ * Raise it to analyse a piece larger than the default allows; the default is
61
+ * {@link DEFAULT_GENERATION_BUDGET}, chosen so a runaway input fails fast
62
+ * rather than blocking the thread.
63
+ *
64
+ * @defaultValue {@link DEFAULT_GENERATION_BUDGET}
65
+ */
66
+ budget?: number;
66
67
  };
67
68
  /**
68
69
  * The result of {@link chordTimelineFromNotes}.
@@ -148,4 +149,4 @@ type CadenceHit = {
148
149
  */
149
150
  declare function detectCadences(timeline: ChordTimeline, key: KeyScale): CadenceHit[];
150
151
 
151
- export { type CadenceHit as C, type ChordSegment as a, type ChordTimeline as b, type ChordTimelineOptions as c, type ChordTimelineResult as d, chordTimelineFromChords as e, chordTimelineFromNotes as f, detectCadences as g };
152
+ export { type CadenceHit as C, type ChordTimeline as a, type ChordTimelineOptions as b, type ChordTimelineResult as c, chordTimelineFromChords as d, chordTimelineFromNotes as e, detectCadences as f };