@libraz/libcantus 0.9.3 → 0.9.5

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 (201) hide show
  1. package/README.md +29 -20
  2. package/README_ja.md +268 -0
  3. package/dist/analyze/index.cjs +39 -1947
  4. package/dist/analyze/index.cjs.map +1 -1
  5. package/dist/analyze/index.d.cts +161 -91
  6. package/dist/analyze/index.d.ts +161 -91
  7. package/dist/analyze/index.js +19 -8
  8. package/dist/chunk-2A2QMA74.cjs +261 -0
  9. package/dist/chunk-2A2QMA74.cjs.map +1 -0
  10. package/dist/chunk-2PTFGVD7.js +261 -0
  11. package/dist/chunk-2PTFGVD7.js.map +1 -0
  12. package/dist/chunk-357ZDPVU.cjs +162 -0
  13. package/dist/chunk-357ZDPVU.cjs.map +1 -0
  14. package/dist/chunk-3KX76RLG.js +1548 -0
  15. package/dist/chunk-3KX76RLG.js.map +1 -0
  16. package/dist/chunk-4VZ5MZAM.cjs +889 -0
  17. package/dist/chunk-4VZ5MZAM.cjs.map +1 -0
  18. package/dist/{chunk-C5XYKUVG.js → chunk-7EONYVI5.js} +471 -171
  19. package/dist/chunk-7EONYVI5.js.map +1 -0
  20. package/dist/{chunk-IT2O4XFE.js → chunk-7JEP3MFY.js} +42 -34
  21. package/dist/chunk-7JEP3MFY.js.map +1 -0
  22. package/dist/{chunk-4MHA432G.js → chunk-AID75RN3.js} +572 -250
  23. package/dist/chunk-AID75RN3.js.map +1 -0
  24. package/dist/chunk-BSLTLGM3.cjs +497 -0
  25. package/dist/chunk-BSLTLGM3.cjs.map +1 -0
  26. package/dist/chunk-CU6VG2YM.cjs +109 -0
  27. package/dist/chunk-CU6VG2YM.cjs.map +1 -0
  28. package/dist/{chunk-EH6EM37U.js → chunk-DZMHIGI4.js} +81 -59
  29. package/dist/chunk-DZMHIGI4.js.map +1 -0
  30. package/dist/{chunk-AKLYPWIN.js → chunk-EDOTEABK.js} +45 -19
  31. package/dist/chunk-EDOTEABK.js.map +1 -0
  32. package/dist/{chunk-2ZWMSJH6.js → chunk-HN2OEUN2.js} +7 -4
  33. package/dist/chunk-HN2OEUN2.js.map +1 -0
  34. package/dist/{chunk-MIWO425M.js → chunk-KBTTEX7Q.js} +128 -43
  35. package/dist/chunk-KBTTEX7Q.js.map +1 -0
  36. package/dist/chunk-KQN2ZYND.cjs +724 -0
  37. package/dist/chunk-KQN2ZYND.cjs.map +1 -0
  38. package/dist/chunk-MPTVJIVG.cjs +3176 -0
  39. package/dist/chunk-MPTVJIVG.cjs.map +1 -0
  40. package/dist/chunk-MTMZTMWM.cjs +53 -0
  41. package/dist/chunk-MTMZTMWM.cjs.map +1 -0
  42. package/dist/{chunk-CHMXELDS.js → chunk-NNB67XA2.js} +372 -197
  43. package/dist/chunk-NNB67XA2.js.map +1 -0
  44. package/dist/chunk-OL3IHHSJ.cjs +1204 -0
  45. package/dist/chunk-OL3IHHSJ.cjs.map +1 -0
  46. package/dist/chunk-PI3UXRWK.cjs +528 -0
  47. package/dist/chunk-PI3UXRWK.cjs.map +1 -0
  48. package/dist/chunk-R2VVFAIN.js +528 -0
  49. package/dist/chunk-R2VVFAIN.js.map +1 -0
  50. package/dist/chunk-T64C7ZD7.cjs +1 -0
  51. package/dist/chunk-T64C7ZD7.cjs.map +1 -0
  52. package/dist/chunk-WFDXOLUB.cjs +337 -0
  53. package/dist/chunk-WFDXOLUB.cjs.map +1 -0
  54. package/dist/chunk-WTAN4ACG.cjs +1548 -0
  55. package/dist/chunk-WTAN4ACG.cjs.map +1 -0
  56. package/dist/chunk-YFJXS3AU.cjs +33 -0
  57. package/dist/chunk-YFJXS3AU.cjs.map +1 -0
  58. package/dist/{chunk-GOAW4VYL.js → chunk-YUE6TJ4M.js} +315 -145
  59. package/dist/chunk-YUE6TJ4M.js.map +1 -0
  60. package/dist/{chunk-62QZKCJQ.js → chunk-ZGLJM4A4.js} +10 -6
  61. package/dist/chunk-ZGLJM4A4.js.map +1 -0
  62. package/dist/core/index.cjs +140 -647
  63. package/dist/core/index.cjs.map +1 -1
  64. package/dist/core/index.d.cts +313 -41
  65. package/dist/core/index.d.ts +313 -41
  66. package/dist/core/index.js +64 -16
  67. package/dist/{function-DVH4Eusr.d.ts → function-CxixTB02.d.cts} +122 -10
  68. package/dist/{function-DYt4iKsn.d.cts → function-DTCt675z.d.ts} +122 -10
  69. package/dist/generate/index.cjs +28 -4085
  70. package/dist/generate/index.cjs.map +1 -1
  71. package/dist/generate/index.d.cts +374 -66
  72. package/dist/generate/index.d.ts +374 -66
  73. package/dist/generate/index.js +23 -9
  74. package/dist/{index-Jc0Ryi79.d.ts → index-B2Ulxxpo.d.cts} +21 -5
  75. package/dist/{index-CpOsP1y9.d.cts → index-BkYJ0xMq.d.cts} +18 -17
  76. package/dist/{index-CxqBQtH1.d.cts → index-BuaB-ypt.d.ts} +21 -5
  77. package/dist/index-CAN7v-kw.d.ts +199 -0
  78. package/dist/{index-Bt4tOUD9.d.ts → index-COw1Ky9g.d.ts} +93 -8
  79. package/dist/{index-Dikst44v.d.cts → index-Cfx8xgH0.d.ts} +14 -11
  80. package/dist/{index-DxvARIP2.d.ts → index-DRtIhlJj.d.ts} +18 -17
  81. package/dist/{index-Cl7mhOFM.d.cts → index-DXd9JikN.d.cts} +92 -10
  82. package/dist/{index-Cl7mhOFM.d.ts → index-DXd9JikN.d.ts} +92 -10
  83. package/dist/index-alrRninU.d.cts +199 -0
  84. package/dist/{index-BNlGP86A.d.cts → index-oTQbYYIs.d.cts} +93 -8
  85. package/dist/index-tR9jTn26.d.cts +275 -0
  86. package/dist/index-tR9jTn26.d.ts +275 -0
  87. package/dist/{index-Bg5dYMmZ.d.ts → index-x2vcsduE.d.cts} +14 -11
  88. package/dist/index.cjs +429 -7383
  89. package/dist/index.cjs.map +1 -1
  90. package/dist/index.d.cts +15 -15
  91. package/dist/index.d.ts +15 -15
  92. package/dist/index.js +121 -27
  93. package/dist/model/index.cjs +8 -2562
  94. package/dist/model/index.cjs.map +1 -1
  95. package/dist/model/index.d.cts +471 -81
  96. package/dist/model/index.d.ts +471 -81
  97. package/dist/model/index.js +6 -7
  98. package/dist/styled-Bl0ZK28h.d.ts +543 -0
  99. package/dist/styled-Crv6SA4S.d.cts +543 -0
  100. package/dist/theory/index.cjs +172 -1822
  101. package/dist/theory/index.cjs.map +1 -1
  102. package/dist/theory/index.d.cts +151 -233
  103. package/dist/theory/index.d.ts +151 -233
  104. package/dist/theory/index.js +30 -7
  105. package/dist/{types-MGP29r3t.d.cts → types-BN6_Q9Kl.d.cts} +11 -2
  106. package/dist/{types-MGP29r3t.d.ts → types-BN6_Q9Kl.d.ts} +11 -2
  107. package/package.json +34 -13
  108. package/dist/chunk-2ZWMSJH6.js.map +0 -1
  109. package/dist/chunk-4MHA432G.js.map +0 -1
  110. package/dist/chunk-62QZKCJQ.js.map +0 -1
  111. package/dist/chunk-AKLYPWIN.js.map +0 -1
  112. package/dist/chunk-C5XYKUVG.js.map +0 -1
  113. package/dist/chunk-CHMXELDS.js.map +0 -1
  114. package/dist/chunk-DYWFNC4A.js +0 -152
  115. package/dist/chunk-DYWFNC4A.js.map +0 -1
  116. package/dist/chunk-EH6EM37U.js.map +0 -1
  117. package/dist/chunk-FBQK3ZQN.js +0 -131
  118. package/dist/chunk-FBQK3ZQN.js.map +0 -1
  119. package/dist/chunk-GOAW4VYL.js.map +0 -1
  120. package/dist/chunk-I5R7ZBJS.js +0 -202
  121. package/dist/chunk-I5R7ZBJS.js.map +0 -1
  122. package/dist/chunk-IT2O4XFE.js.map +0 -1
  123. package/dist/chunk-MIWO425M.js.map +0 -1
  124. package/dist/chunk-SGU7SPLK.js +0 -924
  125. package/dist/chunk-SGU7SPLK.js.map +0 -1
  126. package/dist/index-CGMZNCx6.d.cts +0 -140
  127. package/dist/index-CGMZNCx6.d.ts +0 -140
  128. package/dist/index-CnZCo29u.d.cts +0 -108
  129. package/dist/index-JnF4v9bx.d.ts +0 -108
  130. package/dist/styled-DZ7GjShb.d.ts +0 -282
  131. package/dist/styled-ZTbdaVFM.d.cts +0 -282
  132. package/src/analyze/arrange/index.ts +0 -21
  133. package/src/analyze/arrange/internal.ts +0 -127
  134. package/src/analyze/arrange/tension.ts +0 -199
  135. package/src/analyze/arrange/tracks.ts +0 -312
  136. package/src/analyze/detect/index.ts +0 -272
  137. package/src/analyze/functional/borrowed.ts +0 -84
  138. package/src/analyze/functional/cadence.ts +0 -66
  139. package/src/analyze/functional/function.ts +0 -184
  140. package/src/analyze/functional/index.ts +0 -23
  141. package/src/analyze/functional/internal.ts +0 -29
  142. package/src/analyze/functional/roman.ts +0 -402
  143. package/src/analyze/index.ts +0 -49
  144. package/src/analyze/timeline/index.ts +0 -451
  145. package/src/analyze/voice/index.ts +0 -339
  146. package/src/core/event-index/index.ts +0 -104
  147. package/src/core/index.ts +0 -61
  148. package/src/core/interval/index.ts +0 -81
  149. package/src/core/meter/index.ts +0 -302
  150. package/src/core/pitch/index.ts +0 -311
  151. package/src/core/random/index.ts +0 -76
  152. package/src/core/tuning/index.ts +0 -186
  153. package/src/core/types.ts +0 -29
  154. package/src/core/validation/index.ts +0 -119
  155. package/src/generate/bass/index.ts +0 -373
  156. package/src/generate/countermelody/index.ts +0 -470
  157. package/src/generate/drums/beat.ts +0 -266
  158. package/src/generate/drums/euclid.ts +0 -65
  159. package/src/generate/drums/fills.ts +0 -356
  160. package/src/generate/drums/ghost.ts +0 -119
  161. package/src/generate/drums/hihat.ts +0 -285
  162. package/src/generate/drums/hit.ts +0 -31
  163. package/src/generate/drums/index.ts +0 -361
  164. package/src/generate/drums/internal.ts +0 -257
  165. package/src/generate/drums/kick.ts +0 -160
  166. package/src/generate/drums/percussion.ts +0 -121
  167. package/src/generate/drums/rng.ts +0 -7
  168. package/src/generate/drums/swing.ts +0 -71
  169. package/src/generate/groove/index.ts +0 -351
  170. package/src/generate/harmonize/index.ts +0 -451
  171. package/src/generate/index.ts +0 -58
  172. package/src/generate/motif/index.ts +0 -422
  173. package/src/generate/progression/index.ts +0 -362
  174. package/src/generate/reharmony/index.ts +0 -323
  175. package/src/generate/rhythm/index.ts +0 -175
  176. package/src/index.ts +0 -13
  177. package/src/model/chord.ts +0 -442
  178. package/src/model/index.ts +0 -15
  179. package/src/model/interval.ts +0 -82
  180. package/src/model/key.ts +0 -266
  181. package/src/model/note.ts +0 -176
  182. package/src/model/progression.ts +0 -161
  183. package/src/model/shared.ts +0 -12
  184. package/src/theory/chord/index.ts +0 -375
  185. package/src/theory/chordscale/index.ts +0 -374
  186. package/src/theory/counterpoint/index.ts +0 -230
  187. package/src/theory/harmony/index.ts +0 -77
  188. package/src/theory/index.ts +0 -112
  189. package/src/theory/safety/index.ts +0 -488
  190. package/src/theory/scale/degrees.ts +0 -123
  191. package/src/theory/scale/index.ts +0 -28
  192. package/src/theory/scale/key.ts +0 -56
  193. package/src/theory/scale/masks.ts +0 -153
  194. package/src/theory/spelling/index.ts +0 -249
  195. package/src/theory/symbol/index.ts +0 -268
  196. package/src/theory/voicing/index.ts +0 -5
  197. package/src/theory/voicing/internal.ts +0 -168
  198. package/src/theory/voicing/leading.ts +0 -112
  199. package/src/theory/voicing/satb.ts +0 -216
  200. package/src/theory/voicing/styled.ts +0 -199
  201. package/tsconfig.json +0 -23
@@ -1,11 +1,20 @@
1
- import { K as KeyScale } from './types-MGP29r3t.cjs';
1
+ import { K as KeyScale } from './types-BN6_Q9Kl.cjs';
2
2
 
3
3
  /**
4
4
  * Chord quality identifiers understood by the chord builder.
5
5
  *
6
6
  * @category Chords
7
7
  */
8
- type ChordQuality = 'maj' | 'min' | 'dim' | 'aug' | 'maj7' | 'min7' | 'dom7' | 'dim7' | 'm7b5' | 'minMaj7' | 'aug7' | 'augMaj7' | 'majb5' | '6' | 'min6' | '6/9' | 'sus2' | 'sus4' | 'add9' | 'add11' | 'maj9' | 'min9' | 'dom9' | '7b9' | '7#9' | '7#11' | '7b13' | '11' | '13' | '5';
8
+ type ChordQuality = 'maj' | 'min' | 'dim' | 'aug' | 'maj7' | 'min7' | 'dom7' | 'dim7' | 'm7b5' | 'minMaj7' | 'minMaj9' | 'minMaj11' | 'minMaj13' | 'aug7' | 'augMaj7' | 'majb5' | '6' | 'min6' | '6/9' | 'sus2' | 'sus4' | 'add9' | 'add11' | 'maj9' | 'min9' | 'dom9' | '7b9' | '7#9' | '7#11' | '7b13' | '11' | '13' | '5' | '7sus4' | '7b5' | '7alt' | '13b9' | 'maj13' | 'maj7#11' | 'min11' | 'min13' | 'minAdd9' | 'min6/9';
9
+ /**
10
+ * The basic role a chord tone plays: the degrees a chord's own template names.
11
+ *
12
+ * The shared vocabulary behind {@link chordToneRole}, the harmony layer's
13
+ * `HarmonyRole`, and the voice analyser's labels, so the three cannot drift.
14
+ *
15
+ * @category Chords
16
+ */
17
+ type ChordToneRole = 'root' | 'third' | 'fifth' | 'sixth' | 'seventh';
9
18
  /**
10
19
  * A bare spelled pitch used as an enharmonic hint: a diatonic letter
11
20
  * (0..6 = C..B) plus a chromatic alteration (-2 double-flat .. +2 double-sharp).
@@ -54,7 +63,26 @@ type ChordSpan = {
54
63
  secondaryDominant?: boolean;
55
64
  };
56
65
  /**
57
- * All chord qualities the builder understands, longest templates last.
66
+ * A chord occupying a half-open beat span `[startBeat, endBeat)`.
67
+ *
68
+ * The exchange record between anything that lays chords out in time — a
69
+ * timeline analysis, a bass-line plan, an accompaniment generator — so those
70
+ * surfaces share one definition instead of agreeing by coincidence.
71
+ *
72
+ * @category Composition
73
+ */
74
+ type ChordSegment = {
75
+ startBeat: number;
76
+ endBeat: number;
77
+ chord: Chord;
78
+ };
79
+ /**
80
+ * All chord qualities the builder understands, in declaration order.
81
+ *
82
+ * The order is stable but carries no meaning: it is neither alphabetical nor
83
+ * sorted by template size. {@link detectChord} uses it as its final tie-break,
84
+ * so it is part of the observable behaviour and does not get reshuffled
85
+ * casually — but do not read it as a ranking.
58
86
  *
59
87
  * @category Chords
60
88
  */
@@ -92,21 +120,73 @@ declare function chordFromDegree(degree: number, ext: ChordQuality, key: KeyScal
92
120
  * @category Chords
93
121
  */
94
122
  declare function makeChord(rootPc: number, quality: ChordQuality, bassPc?: number): Chord;
123
+ /**
124
+ * Transpose a chord by a number of semitones.
125
+ *
126
+ * The interval template is carried over untouched, so a chord whose intervals
127
+ * were customised keeps them, and a slash bass moves with the root. Enharmonic
128
+ * spelling hints are dropped rather than shifted: the letter a transposed root
129
+ * should take depends on the destination key, which a semitone count does not
130
+ * carry. Pass the result through {@link spellChord} to respell it.
131
+ *
132
+ * @param chord The chord to transpose.
133
+ * @param semitones The signed semitone offset.
134
+ * @returns The transposed chord.
135
+ * @throws If `semitones` is not finite.
136
+ *
137
+ * @example
138
+ * ```ts
139
+ * import { formatChordSymbol, parseChordSymbol, transposeChord } from '@libraz/libcantus';
140
+ * formatChordSymbol(transposeChord(parseChordSymbol('C/G'), 2)); // 'D/A'
141
+ * ```
142
+ *
143
+ * @category Chords
144
+ */
145
+ declare function transposeChord(chord: Chord, semitones: number): Chord;
95
146
  /**
96
147
  * Get the sorted, deduplicated pitch classes of a chord.
97
148
  *
149
+ * A slash bass is one of them: `F/G` sounds a G, the voicers put it in the
150
+ * bass, and a set that omitted it would not re-detect as the chord it came
151
+ * from. Pass `includeBass: false` to enumerate the interval template alone.
152
+ *
98
153
  * @param chord The chord to enumerate.
154
+ * @param opts Set `includeBass: false` to omit a slash bass.
99
155
  * @returns The chord's pitch classes, sorted ascending in [0, 11].
100
156
  *
101
157
  * @example
102
158
  * ```ts
103
159
  * import { makeChord, chordPitchClasses } from '@libraz/libcantus';
104
160
  * chordPitchClasses(makeChord(0, 'maj7')); // [0, 4, 7, 11]
161
+ * chordPitchClasses(makeChord(5, 'maj', 7)); // [0, 5, 7, 9] — F/G, G included
105
162
  * ```
106
163
  *
107
164
  * @category Chords
108
165
  */
109
- declare function chordPitchClasses(chord: Chord): number[];
166
+ declare function chordPitchClasses(chord: Chord, opts?: {
167
+ includeBass?: boolean;
168
+ }): number[];
169
+ /**
170
+ * A pitch's interval class above the chord root, in [0, 11].
171
+ *
172
+ * The shared reading of "where does this pitch sit in the chord", used by the
173
+ * safety evaluator and the voice analyser alike so they cannot disagree.
174
+ *
175
+ * @param pitch MIDI pitch or bare pitch class.
176
+ * @param chord The chord providing the root reference.
177
+ * @returns The interval class above the root.
178
+ * @category Chords
179
+ */
180
+ declare function intervalAboveRoot(pitch: number, chord: Chord): number;
181
+ /**
182
+ * Whether a pitch is one of a chord's tones, ignoring octave.
183
+ *
184
+ * @param pitch MIDI pitch or bare pitch class.
185
+ * @param chord The chord, or null for no sounding harmony.
186
+ * @returns True when the pitch class belongs to the chord.
187
+ * @category Chords
188
+ */
189
+ declare function isChordMember(pitch: number, chord: Chord | null): boolean;
110
190
  /**
111
191
  * Determine a pitch's harmonic role within a chord.
112
192
  *
@@ -121,18 +201,21 @@ declare function chordPitchClasses(chord: Chord): number[];
121
201
  *
122
202
  * @category Chords
123
203
  */
124
- declare function chordToneRole(pitch: number, chord: Chord): 'root' | 'third' | 'fifth' | 'sixth' | 'seventh' | null;
204
+ declare function chordToneRole(pitch: number, chord: Chord): ChordToneRole | null;
125
205
  /**
126
206
  * Build the diatonic triad rooted on a scale degree by stacking scale thirds.
127
207
  *
128
208
  * Unlike {@link chordFromDegree}, the chord quality is derived from the scale
129
209
  * rather than supplied, so degrees yield their scale-correct triads (e.g. a
130
- * diminished triad on the leading tone of a major key). Intended for heptatonic
131
- * scales; other scales stack by scale step regardless.
210
+ * diminished triad on the leading tone of a major key).
132
211
  *
133
212
  * @param degree 0-based scale degree of the chord root.
134
213
  * @param key Key/scale context.
135
214
  * @returns The diatonic triad.
215
+ * @throws If the scale is not heptatonic. Stacking thirds means skipping every
216
+ * other degree, which only lands on a triad when there are seven of them, so
217
+ * the pentatonic, blues, whole-tone, octatonic and chromatic scales have no
218
+ * diatonic triad; use {@link chordFromDegree} with an explicit quality there.
136
219
  *
137
220
  * @example
138
221
  * ```ts
@@ -149,9 +232,11 @@ declare function diatonicTriad(degree: number, key: KeyScale): Chord;
149
232
  * @param degree 0-based scale degree of the chord root.
150
233
  * @param key Key/scale context.
151
234
  * @returns The diatonic seventh chord.
235
+ * @throws If the scale is not heptatonic, for the reason given on
236
+ * {@link diatonicTriad}.
152
237
  *
153
238
  * @category Chords
154
239
  */
155
240
  declare function diatonicSeventh(degree: number, key: KeyScale): Chord;
156
241
 
157
- export { type Chord as C, type PitchSpelling as P, type ChordQuality as a, type ChordSpan as b, chordFromDegree as c, chordPitchClasses as d, chordQualities as e, chordToneRole as f, diatonicSeventh as g, diatonicTriad as h, makeChord as m };
242
+ export { type Chord as C, type PitchSpelling as P, type ChordQuality as a, type ChordSegment as b, type ChordSpan as c, type ChordToneRole as d, chordFromDegree as e, chordPitchClasses as f, chordQualities as g, chordToneRole as h, diatonicSeventh as i, diatonicTriad as j, intervalAboveRoot as k, isChordMember as l, makeChord as m, transposeChord as t };
@@ -0,0 +1,275 @@
1
+ /**
2
+ * Pitch spelling: letter-name notes, enharmonic-aware conversion, and spelled
3
+ * intervals.
4
+ *
5
+ * The rest of the library works in pitch classes (0..11), which cannot tell a
6
+ * G# from an Ab or an augmented fourth from a diminished fifth. This module adds
7
+ * an explicit spelling layer — a note is a diatonic letter plus a chromatic
8
+ * alteration — so interval quality (P/M/m/A/d) and enharmonic identity are
9
+ * preserved.
10
+ */
11
+ /**
12
+ * A spelled note: a diatonic letter, a chromatic alteration, and an optional
13
+ * octave.
14
+ *
15
+ * - `letter` is 0..6 for C..B.
16
+ * - `alter` is the number of semitones of alteration: -2 double-flat, -1 flat,
17
+ * 0 natural, +1 sharp, +2 double-sharp.
18
+ * - `octave` follows scientific pitch notation (middle C = C4 = MIDI 60). When
19
+ * absent, the note denotes a bare pitch class.
20
+ *
21
+ * @category Pitch & Intervals
22
+ */
23
+ type Note = {
24
+ letter: number;
25
+ alter: number;
26
+ octave?: number;
27
+ };
28
+ /**
29
+ * The quality label of a spelled interval: perfect, major, minor, or one or
30
+ * more augmentations or diminutions.
31
+ *
32
+ * This names how an interval is *spelled*. It is a different notion from
33
+ * {@link ConsonanceClass}, which classifies how an interval *sounds* against
34
+ * another voice.
35
+ *
36
+ * @see {@link ConsonanceClass}
37
+ * @category Pitch & Intervals
38
+ */
39
+ type IntervalQualityLabel = 'P' | 'M' | 'm' | `A${string}` | `d${string}`;
40
+ /**
41
+ * A spelled interval: a diatonic number, a quality label, and its semitone span.
42
+ *
43
+ * @category Pitch & Intervals
44
+ */
45
+ type SpelledInterval = {
46
+ /** Diatonic size: 1 = unison, 2 = second, ... 8 = octave, and beyond. */
47
+ number: number;
48
+ /** Quality label: 'P', 'M', 'm', or repeated 'A'/'d' for (multiply) aug/dim. */
49
+ quality: IntervalQualityLabel;
50
+ /** Signed semitone distance from the first note to the second. */
51
+ semitones: number;
52
+ /** True when the diatonic letter movement is descending despite a zero span. */
53
+ descending?: boolean;
54
+ };
55
+ /**
56
+ * Reduce a MIDI pitch, a bare pitch class, or any signed offset to a pitch
57
+ * class in [0, 11].
58
+ *
59
+ * This is the library's single definition of pitch-class arithmetic: every
60
+ * layer routes through it so a fractional pitch reduces the same way
61
+ * everywhere. A non-integral input is rounded to the nearest semitone first, so
62
+ * a microtonal 60.6 reads as C# rather than C.
63
+ *
64
+ * @param value A MIDI pitch, pitch class, or signed semitone offset.
65
+ * @returns The pitch class in [0, 11].
66
+ * @example
67
+ * ```ts
68
+ * import { pitchClassOf } from '@libraz/libcantus';
69
+ * pitchClassOf(61); // 1
70
+ * pitchClassOf(-1); // 11
71
+ * pitchClassOf(60.6); // 1
72
+ * ```
73
+ * @category Pitch & Intervals
74
+ */
75
+ declare function pitchClassOf(value: number): number;
76
+ /**
77
+ * Reduce a letter number or letter offset to a diatonic letter in [0, 6]
78
+ * (0 = C .. 6 = B).
79
+ *
80
+ * @param value A letter number or signed letter offset.
81
+ * @returns The diatonic letter in [0, 6].
82
+ * @category Pitch & Intervals
83
+ */
84
+ declare function diatonicLetterOf(value: number): number;
85
+ /**
86
+ * The pitch class of a diatonic letter with no accidental (C = 0, D = 2, ...).
87
+ *
88
+ * @param letter A letter number or signed letter offset; reduced to [0, 6].
89
+ * @returns The natural pitch class of that letter.
90
+ * @category Pitch & Intervals
91
+ */
92
+ declare function naturalPitchClassOf(letter: number): number;
93
+ /**
94
+ * Parse scientific pitch notation into a {@link Note}.
95
+ *
96
+ * Accepts a letter (case-insensitive) followed by any number of same-direction
97
+ * accidentals and an optional octave, e.g. `"C"`, `"C#4"`, `"Bb"`, `"F##3"`,
98
+ * `"Ebb2"`. Both `#` and `x` (double-sharp) are accepted for sharps; `b` for
99
+ * flats. Mixing sharps and flats (e.g. `"C#b"`) is rejected.
100
+ *
101
+ * @param text The note text.
102
+ * @returns The parsed note.
103
+ * @throws If the text is not a valid note.
104
+ * @example
105
+ * ```ts
106
+ * import { parseNote, noteToMidi } from '@libraz/libcantus';
107
+ * const n = parseNote('C#4');
108
+ * noteToMidi(n); // 61
109
+ * ```
110
+ * @category Pitch & Intervals
111
+ */
112
+ declare function parseNote(text: string): Note;
113
+ /**
114
+ * Render a {@link Note} as scientific pitch notation.
115
+ *
116
+ * @param note The note to format.
117
+ * @returns The note text, including the octave when present.
118
+ * @example
119
+ * ```ts
120
+ * import { formatNote, parseNote } from '@libraz/libcantus';
121
+ * formatNote(parseNote('C#4')); // 'C#4'
122
+ * ```
123
+ * @category Pitch & Intervals
124
+ */
125
+ declare function formatNote(note: Note): string;
126
+ /**
127
+ * Pitch class (0..11) of a note, ignoring octave.
128
+ *
129
+ * @param note The note.
130
+ * @returns The pitch class.
131
+ * @example
132
+ * ```ts
133
+ * import { noteToPitchClass, parseNote } from '@libraz/libcantus';
134
+ * noteToPitchClass(parseNote('Db')); // 1
135
+ * ```
136
+ * @category Pitch & Intervals
137
+ */
138
+ declare function noteToPitchClass(note: Note): number;
139
+ /**
140
+ * MIDI number of a note (middle C = C4 = 60).
141
+ *
142
+ * @param note The note; must carry an octave.
143
+ * @returns The MIDI number.
144
+ * @throws If the note has no octave.
145
+ * @example
146
+ * ```ts
147
+ * import { noteToMidi, parseNote } from '@libraz/libcantus';
148
+ * noteToMidi(parseNote('A4')); // 69
149
+ * ```
150
+ * @category Pitch & Intervals
151
+ */
152
+ declare function noteToMidi(note: Note): number;
153
+ /**
154
+ * Name a MIDI number as a {@link Note}, choosing sharp or flat spelling.
155
+ *
156
+ * The input is rounded to the nearest integer but is not clamped to the MIDI
157
+ * range 0..127: out-of-range values extrapolate linearly (e.g. `-1` -> `B-2`,
158
+ * `128` -> `G#9`) and remain an exact inverse of {@link noteToMidi}.
159
+ *
160
+ * @param midi The MIDI number.
161
+ * @param spelling Whether to prefer sharps or flats for black keys.
162
+ * @returns The spelled note, with octave.
163
+ * @example
164
+ * ```ts
165
+ * import { midiToNote, formatNote } from '@libraz/libcantus';
166
+ * formatNote(midiToNote(61)); // 'C#4'
167
+ * formatNote(midiToNote(61, 'flat')); // 'Db4'
168
+ * ```
169
+ * @category Pitch & Intervals
170
+ */
171
+ declare function midiToNote(midi: number, spelling?: 'sharp' | 'flat'): Note;
172
+ /**
173
+ * Transpose a note by a signed number of semitones, keeping its spelling.
174
+ *
175
+ * The letter moves by the diatonic distance of the conventional interval for
176
+ * that many semitones and the accidental is recomputed for the new letter, so
177
+ * enharmonic identity survives: `Ab4` up a major second is `Bb4`, not `A#4`, and
178
+ * the operation is an exact inverse of itself. An octave-less note stays
179
+ * octave-less.
180
+ *
181
+ * A bare semitone count cannot distinguish an augmented fourth from a diminished
182
+ * fifth; pass `spelling` to override the letter distance when the enharmonic
183
+ * choice matters.
184
+ *
185
+ * @param note The note to transpose.
186
+ * @param semitones The signed semitone offset.
187
+ * @param opts `spelling` forces the result onto the sharp or flat side instead
188
+ * of following the source note's letter.
189
+ * @returns The transposed note.
190
+ * @example
191
+ * ```ts
192
+ * import { transposeNote, formatNote, parseNote } from '@libraz/libcantus';
193
+ * formatNote(transposeNote(parseNote('Ab4'), 2)); // 'Bb4'
194
+ * formatNote(transposeNote(parseNote('Ab4'), 2, { spelling: 'sharp' })); // 'A#4'
195
+ * ```
196
+ * @category Pitch & Intervals
197
+ */
198
+ declare function transposeNote(note: Note, semitones: number, opts?: {
199
+ spelling?: 'sharp' | 'flat';
200
+ }): Note;
201
+ /**
202
+ * The semitone span of the interval named by a diatonic number and a quality.
203
+ *
204
+ * The inverse of the quality derivation in {@link spelledInterval}: it turns a
205
+ * name back into a distance, which is what transposing by a named interval or
206
+ * parsing one from text needs.
207
+ *
208
+ * @param numberValue Diatonic size: 1 = unison, 2 = second, ... 8 = octave.
209
+ * @param quality Quality label: `'P'`, `'M'`, `'m'`, or repeated `'A'`/`'d'`.
210
+ * @returns The unsigned semitone span.
211
+ * @throws If the quality cannot apply to the number, such as a major fifth.
212
+ * @example
213
+ * ```ts
214
+ * import { intervalSemitones } from '@libraz/libcantus';
215
+ * intervalSemitones(5, 'P'); // 7
216
+ * ```
217
+ * @category Pitch & Intervals
218
+ */
219
+ declare function intervalSemitones(numberValue: number, quality: IntervalQualityLabel): number;
220
+ /**
221
+ * Parse an interval name such as `'P5'`, `'m3'`, or `'AA4'`.
222
+ *
223
+ * @param name The interval name: a quality label followed by a diatonic number.
224
+ * @returns The spelled interval. Diminished unisons have a descending
225
+ * (negative) semitone span; all other supported names are ascending.
226
+ * @throws If the name is not a quality label followed by a number, or the two
227
+ * cannot describe the same interval.
228
+ * @example
229
+ * ```ts
230
+ * import { parseInterval } from '@libraz/libcantus';
231
+ * parseInterval('m3'); // { number: 3, quality: 'm', semitones: 3 }
232
+ * ```
233
+ * @category Pitch & Intervals
234
+ */
235
+ declare function parseInterval(name: string): SpelledInterval;
236
+ /**
237
+ * Transpose a note by a spelled interval, keeping the spelling the interval
238
+ * names.
239
+ *
240
+ * Unlike {@link transposeNote}, which picks a letter from the semitone count,
241
+ * the diatonic number decides the letter here: transposing C by an augmented
242
+ * second gives D#, not Eb.
243
+ *
244
+ * @param note The note to transpose.
245
+ * @param interval The interval to apply; a negative span transposes downward.
246
+ * @returns The transposed note, octave-less if the source was.
247
+ * @example
248
+ * ```ts
249
+ * import { formatNote, parseInterval, parseNote, transposeByInterval } from '@libraz/libcantus';
250
+ * formatNote(transposeByInterval(parseNote('C4'), parseInterval('A2'))); // 'D#4'
251
+ * ```
252
+ * @category Pitch & Intervals
253
+ */
254
+ declare function transposeByInterval(note: Note, interval: SpelledInterval): Note;
255
+ /**
256
+ * The spelled interval from one note to another.
257
+ *
258
+ * When both notes carry octaves, the interval reflects their full signed
259
+ * distance (so `C4 -> C5` is a perfect octave). When either lacks an octave the
260
+ * interval is measured within a single ascending octave from `a` to `b`.
261
+ *
262
+ * @param a The lower/first note.
263
+ * @param b The upper/second note.
264
+ * @returns The diatonic number, quality, and semitone span.
265
+ * @example
266
+ * ```ts
267
+ * import { spelledInterval, parseNote } from '@libraz/libcantus';
268
+ * spelledInterval(parseNote('C4'), parseNote('G4'));
269
+ * // { number: 5, quality: 'P', semitones: 7 }
270
+ * ```
271
+ * @category Pitch & Intervals
272
+ */
273
+ declare function spelledInterval(a: Note, b: Note): SpelledInterval;
274
+
275
+ export { type IntervalQualityLabel as I, type Note as N, type SpelledInterval as S, noteToMidi as a, noteToPitchClass as b, parseNote as c, diatonicLetterOf as d, pitchClassOf as e, formatNote as f, transposeNote as g, intervalSemitones as i, midiToNote as m, naturalPitchClassOf as n, parseInterval as p, spelledInterval as s, transposeByInterval as t };