@libraz/libcantus 0.9.4 → 1.0.0

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 (186) hide show
  1. package/README.md +61 -261
  2. package/README_ja.md +115 -0
  3. package/dist/analyze/index.cjs +54 -7
  4. package/dist/analyze/index.cjs.map +1 -1
  5. package/dist/analyze/index.d.cts +213 -456
  6. package/dist/analyze/index.d.ts +213 -456
  7. package/dist/analyze/index.js +56 -9
  8. package/dist/chunk-3JXCW6DX.cjs +3220 -0
  9. package/dist/chunk-3JXCW6DX.cjs.map +1 -0
  10. package/dist/chunk-4A2RMUCC.js +7647 -0
  11. package/dist/chunk-4A2RMUCC.js.map +1 -0
  12. package/dist/chunk-6XPTBE7Y.cjs +49 -0
  13. package/dist/chunk-6XPTBE7Y.cjs.map +1 -0
  14. package/dist/chunk-AFM2ULJH.cjs +5121 -0
  15. package/dist/chunk-AFM2ULJH.cjs.map +1 -0
  16. package/dist/chunk-E3F4AHAH.cjs +690 -0
  17. package/dist/chunk-E3F4AHAH.cjs.map +1 -0
  18. package/dist/chunk-ELCTZUJJ.js +379 -0
  19. package/dist/chunk-ELCTZUJJ.js.map +1 -0
  20. package/dist/chunk-FVSI36UV.js +690 -0
  21. package/dist/chunk-FVSI36UV.js.map +1 -0
  22. package/dist/chunk-GEDTJHAC.cjs +1 -0
  23. package/dist/chunk-GEDTJHAC.cjs.map +1 -0
  24. package/dist/chunk-GOZG57ER.js +3220 -0
  25. package/dist/chunk-GOZG57ER.js.map +1 -0
  26. package/dist/chunk-H3VORETI.js +2243 -0
  27. package/dist/chunk-H3VORETI.js.map +1 -0
  28. package/dist/chunk-H42UHPYW.js +1577 -0
  29. package/dist/chunk-H42UHPYW.js.map +1 -0
  30. package/dist/chunk-HFPS7JFD.js +1 -0
  31. package/dist/chunk-INHVXP6Z.js +3053 -0
  32. package/dist/chunk-INHVXP6Z.js.map +1 -0
  33. package/dist/chunk-K4ZJUGF4.cjs +379 -0
  34. package/dist/chunk-K4ZJUGF4.cjs.map +1 -0
  35. package/dist/chunk-KNJEKLKV.js +49 -0
  36. package/dist/chunk-KNJEKLKV.js.map +1 -0
  37. package/dist/chunk-M4CWTJWJ.cjs +7647 -0
  38. package/dist/chunk-M4CWTJWJ.cjs.map +1 -0
  39. package/dist/chunk-MXO72PLY.cjs +211 -0
  40. package/dist/chunk-MXO72PLY.cjs.map +1 -0
  41. package/dist/chunk-NLEU4QSE.cjs +360 -0
  42. package/dist/chunk-NLEU4QSE.cjs.map +1 -0
  43. package/dist/chunk-OE6WK2Y2.cjs +1577 -0
  44. package/dist/chunk-OE6WK2Y2.cjs.map +1 -0
  45. package/dist/chunk-Q2WGKJNN.cjs +1064 -0
  46. package/dist/chunk-Q2WGKJNN.cjs.map +1 -0
  47. package/dist/chunk-QYQQ5J6E.js +1 -0
  48. package/dist/chunk-QYQQ5J6E.js.map +1 -0
  49. package/dist/chunk-RHIJ3S4I.cjs +1 -0
  50. package/dist/chunk-RHIJ3S4I.cjs.map +1 -0
  51. package/dist/chunk-TTCLJX6D.js +211 -0
  52. package/dist/chunk-TTCLJX6D.js.map +1 -0
  53. package/dist/chunk-UADYAYAT.cjs +3053 -0
  54. package/dist/chunk-UADYAYAT.cjs.map +1 -0
  55. package/dist/chunk-VOHZB45S.js +5121 -0
  56. package/dist/chunk-VOHZB45S.js.map +1 -0
  57. package/dist/chunk-VTI6FOLB.js +1064 -0
  58. package/dist/chunk-VTI6FOLB.js.map +1 -0
  59. package/dist/chunk-WWURE4XT.cjs +2243 -0
  60. package/dist/chunk-WWURE4XT.cjs.map +1 -0
  61. package/dist/chunk-YH3BIKHH.js +360 -0
  62. package/dist/chunk-YH3BIKHH.js.map +1 -0
  63. package/dist/core/index.cjs +103 -6
  64. package/dist/core/index.cjs.map +1 -1
  65. package/dist/core/index.d.cts +96 -345
  66. package/dist/core/index.d.ts +96 -345
  67. package/dist/core/index.js +104 -7
  68. package/dist/generate/index.cjs +89 -10
  69. package/dist/generate/index.cjs.map +1 -1
  70. package/dist/generate/index.d.cts +437 -1095
  71. package/dist/generate/index.d.ts +437 -1095
  72. package/dist/generate/index.js +94 -15
  73. package/dist/index-9wcMhG73.d.ts +1095 -0
  74. package/dist/{index-D6b6na69.d.cts → index-B4o55NDr.d.cts} +13 -9
  75. package/dist/index-B9MNZboQ.d.cts +770 -0
  76. package/dist/index-B9MNZboQ.d.ts +770 -0
  77. package/dist/index-BGFW-8P2.d.cts +2307 -0
  78. package/dist/index-BO6xE9YU.d.cts +1804 -0
  79. package/dist/index-BkGmlyI3.d.cts +470 -0
  80. package/dist/index-CCNJRG-P.d.cts +1095 -0
  81. package/dist/index-CGpRv5sl.d.cts +643 -0
  82. package/dist/index-C_8o--VE.d.cts +1242 -0
  83. package/dist/index-CgHqxdps.d.ts +2307 -0
  84. package/dist/index-Chbst3Jx.d.ts +1343 -0
  85. package/dist/index-Cj49F892.d.ts +470 -0
  86. package/dist/{index-tSQh-xwY.d.ts → index-CunYKLiu.d.ts} +13 -9
  87. package/dist/index-D57QRbVn.d.ts +1804 -0
  88. package/dist/index-DInQqT8Q.d.cts +66 -0
  89. package/dist/index-DInQqT8Q.d.ts +66 -0
  90. package/dist/index-Dzr13q3d.d.cts +1343 -0
  91. package/dist/index-G1uwGGWQ.d.ts +643 -0
  92. package/dist/index-szBv3496.d.ts +1242 -0
  93. package/dist/index.cjs +358 -15
  94. package/dist/index.cjs.map +1 -1
  95. package/dist/index.d.cts +17 -15
  96. package/dist/index.d.ts +17 -15
  97. package/dist/index.js +407 -64
  98. package/dist/masks-DYbE485J.d.cts +445 -0
  99. package/dist/masks-DYbE485J.d.ts +445 -0
  100. package/dist/model/index.cjs +39 -7
  101. package/dist/model/index.cjs.map +1 -1
  102. package/dist/model/index.d.cts +4685 -243
  103. package/dist/model/index.d.ts +4685 -243
  104. package/dist/model/index.js +40 -8
  105. package/dist/positional-Cptlj-xs.d.ts +287 -0
  106. package/dist/positional-DvH_sd8u.d.cts +287 -0
  107. package/dist/theory/index.cjs +101 -7
  108. package/dist/theory/index.cjs.map +1 -1
  109. package/dist/theory/index.d.cts +513 -173
  110. package/dist/theory/index.d.ts +513 -173
  111. package/dist/theory/index.js +118 -24
  112. package/package.json +16 -11
  113. package/dist/chunk-36N73KZ3.cjs +0 -246
  114. package/dist/chunk-36N73KZ3.cjs.map +0 -1
  115. package/dist/chunk-4HLLZPXT.cjs +0 -3077
  116. package/dist/chunk-4HLLZPXT.cjs.map +0 -1
  117. package/dist/chunk-7MGZ7D62.cjs +0 -498
  118. package/dist/chunk-7MGZ7D62.cjs.map +0 -1
  119. package/dist/chunk-7NKDPF74.js +0 -3077
  120. package/dist/chunk-7NKDPF74.js.map +0 -1
  121. package/dist/chunk-CAN76NCU.cjs +0 -679
  122. package/dist/chunk-CAN76NCU.cjs.map +0 -1
  123. package/dist/chunk-D2FAJBYL.js +0 -479
  124. package/dist/chunk-D2FAJBYL.js.map +0 -1
  125. package/dist/chunk-EHVEBWM5.js +0 -1449
  126. package/dist/chunk-EHVEBWM5.js.map +0 -1
  127. package/dist/chunk-FCANXBAT.cjs +0 -30
  128. package/dist/chunk-FCANXBAT.cjs.map +0 -1
  129. package/dist/chunk-FNDWXRRI.cjs +0 -479
  130. package/dist/chunk-FNDWXRRI.cjs.map +0 -1
  131. package/dist/chunk-GQSGS2N4.js +0 -173
  132. package/dist/chunk-GQSGS2N4.js.map +0 -1
  133. package/dist/chunk-HKGYCQ34.js +0 -53
  134. package/dist/chunk-HKGYCQ34.js.map +0 -1
  135. package/dist/chunk-I24MV65U.js +0 -106
  136. package/dist/chunk-I24MV65U.js.map +0 -1
  137. package/dist/chunk-KMHOICIY.js +0 -679
  138. package/dist/chunk-KMHOICIY.js.map +0 -1
  139. package/dist/chunk-LW53AHQU.cjs +0 -1117
  140. package/dist/chunk-LW53AHQU.cjs.map +0 -1
  141. package/dist/chunk-N6IHQUOX.js +0 -1
  142. package/dist/chunk-NKIBQ6PT.js +0 -30
  143. package/dist/chunk-NKIBQ6PT.js.map +0 -1
  144. package/dist/chunk-NP4NA2FB.cjs +0 -106
  145. package/dist/chunk-NP4NA2FB.cjs.map +0 -1
  146. package/dist/chunk-NVE34YGZ.cjs +0 -1449
  147. package/dist/chunk-NVE34YGZ.cjs.map +0 -1
  148. package/dist/chunk-NYYWMV2C.js +0 -327
  149. package/dist/chunk-NYYWMV2C.js.map +0 -1
  150. package/dist/chunk-Q2XUP227.js +0 -845
  151. package/dist/chunk-Q2XUP227.js.map +0 -1
  152. package/dist/chunk-Q6OP4U43.cjs +0 -327
  153. package/dist/chunk-Q6OP4U43.cjs.map +0 -1
  154. package/dist/chunk-RC6GBMCD.cjs +0 -845
  155. package/dist/chunk-RC6GBMCD.cjs.map +0 -1
  156. package/dist/chunk-RK35RIN7.js +0 -1117
  157. package/dist/chunk-RK35RIN7.js.map +0 -1
  158. package/dist/chunk-RUMU3UA6.cjs +0 -53
  159. package/dist/chunk-RUMU3UA6.cjs.map +0 -1
  160. package/dist/chunk-T64C7ZD7.cjs +0 -1
  161. package/dist/chunk-T64C7ZD7.cjs.map +0 -1
  162. package/dist/chunk-XEBG3G53.js +0 -498
  163. package/dist/chunk-XEBG3G53.js.map +0 -1
  164. package/dist/chunk-YLEMGEFH.js +0 -246
  165. package/dist/chunk-YLEMGEFH.js.map +0 -1
  166. package/dist/chunk-ZEJR4TKL.cjs +0 -173
  167. package/dist/chunk-ZEJR4TKL.cjs.map +0 -1
  168. package/dist/function-BtiZb9i9.d.ts +0 -208
  169. package/dist/function-DNugAOrt.d.cts +0 -208
  170. package/dist/index-6VR8-kit.d.ts +0 -143
  171. package/dist/index-70p168VM.d.ts +0 -192
  172. package/dist/index-Be74mcon.d.cts +0 -152
  173. package/dist/index-BtXT6UQ0.d.cts +0 -192
  174. package/dist/index-C5UBbQ4G.d.ts +0 -152
  175. package/dist/index-C83mZI1P.d.ts +0 -242
  176. package/dist/index-DXd9JikN.d.cts +0 -246
  177. package/dist/index-DXd9JikN.d.ts +0 -246
  178. package/dist/index-OG65ocOr.d.cts +0 -272
  179. package/dist/index-OG65ocOr.d.ts +0 -272
  180. package/dist/index-tJhkmQgE.d.cts +0 -143
  181. package/dist/index-y_ak9_Hi.d.cts +0 -242
  182. package/dist/styled-DIRkk9Uz.d.ts +0 -506
  183. package/dist/styled-DJbkJQfj.d.cts +0 -506
  184. package/dist/types-BN6_Q9Kl.d.cts +0 -39
  185. package/dist/types-BN6_Q9Kl.d.ts +0 -39
  186. /package/dist/{chunk-N6IHQUOX.js.map → chunk-HFPS7JFD.js.map} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/model/interval.ts","../src/model/note.ts","../src/model/shared.ts","../src/model/key.ts","../src/model/progression.ts","../src/model/chord.ts"],"sourcesContent":["import { InvalidInputError } from '../core/errors/index.js';\nimport { isConsonantInterval } from '../core/interval/index.js';\nimport type { IntervalQualityLabel, SpelledInterval } from '../core/pitch/index.js';\nimport { intervalSemitones, parseInterval } from '../core/pitch/index.js';\nimport type { Note } from './note.js';\n\n/** Number of diatonic degrees an interval and its inversion span together. */\nconst INVERSION_SUM = 9;\n\n/** The quality an interval's inversion carries. */\nfunction invertQuality(quality: IntervalQualityLabel): IntervalQualityLabel {\n if (quality === 'P') {\n return 'P';\n }\n if (quality === 'M') {\n return 'm';\n }\n if (quality === 'm') {\n return 'M';\n }\n return quality.startsWith('A')\n ? (`d${'d'.repeat(quality.length - 1)}` as IntervalQualityLabel)\n : (`A${'A'.repeat(quality.length - 1)}` as IntervalQualityLabel);\n}\n\n/**\n * An immutable spelled interval value: a diatonic number, a quality label, and\n * a signed semitone span. A thin convenience wrapper over the pitch module's\n * plain interval result.\n *\n * @category Class API\n * @example\n * ```ts\n * import { Interval, Note } from '@libraz/libcantus';\n * Interval.between(Note.of('C4'), Note.of('G4')).name; // 'P5'\n * ```\n */\nexport class Interval {\n readonly #number: number;\n readonly #quality: IntervalQualityLabel;\n readonly #semitones: number;\n\n private constructor(numberValue: number, quality: IntervalQualityLabel, semitones: number) {\n this.#number = numberValue;\n this.#quality = quality;\n this.#semitones = semitones;\n }\n\n /**\n * The spelled interval between two notes.\n *\n * @param a The first note.\n * @param b The second note.\n * @returns The interval from `a` to `b`.\n */\n static between(a: Note, b: Note): Interval {\n return a.intervalTo(b);\n }\n\n /**\n * Build an interval from explicit components.\n *\n * @param numberValue Diatonic size: 1 = unison, 2 = second, ... 8 = octave.\n * @param quality Quality label: `'P'`, `'M'`, `'m'`, or repeated `'A'`/`'d'`.\n * @param semitones Signed semitone span; its magnitude must be the span the\n * number and quality describe.\n * @returns The interval.\n * @throws If the three components do not describe the same interval — a\n * `P5` spanning 8 semitones is not a value any other method can produce.\n */\n static of(numberValue: number, quality: IntervalQualityLabel, semitones: number): Interval {\n const expected = intervalSemitones(numberValue, quality);\n if (Math.abs(semitones) !== expected) {\n throw new InvalidInputError(\n `${quality}${numberValue} spans ${expected} semitones; received ${semitones}`,\n );\n }\n return new Interval(numberValue, quality, semitones);\n }\n\n /**\n * Wrap a plain spelled interval, as returned by the pitch module.\n *\n * @param data The plain interval.\n * @returns The wrapped interval.\n */\n static fromData(data: SpelledInterval): Interval {\n return new Interval(data.number, data.quality, data.semitones);\n }\n\n /**\n * Rebuild an interval from its {@link Interval.toJSON} output.\n *\n * @param data The serialized interval.\n * @returns The wrapped interval.\n */\n static fromJSON(data: SpelledInterval): Interval {\n return Interval.fromData(data);\n }\n\n /**\n * Parse an interval name such as `'P5'`, `'m3'`, or `'AA4'`.\n *\n * @param name The interval name.\n * @returns The ascending interval of that name.\n * @throws If the name is not a quality label followed by a diatonic number.\n */\n static parse(name: string): Interval {\n return Interval.fromData(parseInterval(name));\n }\n\n /** Diatonic size: 1 = unison, 2 = second, ... 8 = octave, and beyond. */\n get number(): number {\n return this.#number;\n }\n\n /** Quality label: `'P'`, `'M'`, `'m'`, or repeated `'A'`/`'d'`. */\n get quality(): IntervalQualityLabel {\n return this.#quality;\n }\n\n /** Signed semitone span. */\n get semitones(): number {\n return this.#semitones;\n }\n\n /** A readable label composed of quality and number, e.g. `'P5'` or `'M3'`. */\n get name(): string {\n return `${this.#quality}${this.#number}`;\n }\n\n /**\n * The interval's inversion: the complement that completes the octave.\n *\n * A compound interval is reduced to its simple form first, and the result is\n * always ascending — an inversion answers \"what is left of the octave\",\n * which has no direction of its own.\n *\n * @returns The inverted interval, e.g. `M3` becomes `m6`.\n */\n invert(): Interval {\n const simple = ((this.#number - 1) % 7) + 1;\n const numberValue = INVERSION_SUM - simple;\n const quality = invertQuality(this.#quality);\n return Interval.of(numberValue, quality, intervalSemitones(numberValue, quality));\n }\n\n /**\n * Whether the interval is consonant.\n *\n * @param twoVoice When true, the perfect fourth counts as a dissonance,\n * matching two-voice counterpoint.\n * @returns True if the interval is consonant in that context.\n */\n isConsonant(twoVoice = true): boolean {\n return isConsonantInterval(this.#semitones, twoVoice);\n }\n\n /**\n * Whether another interval is spelled identically.\n *\n * Enharmonic equivalents are not equal: an augmented second and a minor\n * third span the same distance but are different intervals.\n *\n * @param other The interval to compare with.\n * @returns True when number, quality, and span all match.\n */\n equals(other: Interval): boolean {\n return (\n this.#number === other.number &&\n this.#quality === other.quality &&\n this.#semitones === other.semitones\n );\n }\n\n /**\n * The plain interval data, for JSON serialization.\n *\n * Private class fields do not serialize, so an explicit `toJSON` keeps\n * `JSON.stringify(interval)` from collapsing to `{}`.\n *\n * @returns The diatonic number, quality, and semitone span.\n */\n toJSON(): SpelledInterval {\n return { number: this.#number, quality: this.#quality, semitones: this.#semitones };\n }\n\n /**\n * The interval's name, so a template literal or a log line reads as the\n * interval.\n *\n * @returns The name, e.g. `'M3'`.\n */\n toString(): string {\n return this.name;\n }\n}\n","import { InvalidInputError } from '../core/errors/index.js';\nimport {\n formatNote,\n midiToNote,\n type Note as NoteData,\n noteToMidi,\n noteToPitchClass,\n parseNote,\n spelledInterval,\n transposeByInterval,\n transposeNote,\n} from '../core/pitch/index.js';\nimport { Interval } from './interval.js';\n\n/**\n * Defensive copy of a plain note, with the letter checked.\n *\n * Formatting and pitch-class arithmetic reduce the letter modulo 7, but\n * `equals` compares it directly: an unreduced letter produces two notes that\n * print the same name and report the same pitch class yet compare unequal.\n */\nfunction copyNote(data: NoteData): NoteData {\n if (!Number.isInteger(data.letter) || data.letter < 0 || data.letter > 6) {\n throw new InvalidInputError(\n `note letter must be an integer in [0, 6]; received ${data.letter}`,\n );\n }\n const copy: NoteData = { letter: data.letter, alter: data.alter };\n if (data.octave !== undefined) {\n copy.octave = data.octave;\n }\n return copy;\n}\n\n/**\n * An immutable spelled note: a diatonic letter plus a chromatic alteration and\n * an optional octave. Wraps the plain note object and delegates to the pitch\n * module; every transformation returns a new instance.\n *\n * @category Class API\n * @example\n * ```ts\n * import { Note } from '@libraz/libcantus';\n * Note.of('C4').transpose(7).name; // 'G4'\n * ```\n */\nexport class Note {\n readonly #data: NoteData;\n\n /**\n * Wrap a plain note object.\n *\n * @param data The spelled note; it is copied, never retained or mutated.\n * @throws If `letter` is not an integer in 0..6.\n */\n constructor(data: NoteData) {\n this.#data = copyNote(data);\n }\n\n /**\n * Parse scientific pitch notation (e.g. `'C#4'`, `'Bb'`, `'F##3'`).\n *\n * @param name The note text.\n * @returns The parsed note.\n * @throws If the text is not a valid note.\n */\n static of(name: string): Note {\n return new Note(parseNote(name));\n }\n\n /**\n * Name a MIDI number (middle C = C4 = 60) as a note.\n *\n * @param midi The MIDI number.\n * @param spelling Whether to prefer sharps or flats for black keys.\n * @returns The spelled note, with octave.\n */\n static fromMidi(midi: number, spelling: 'sharp' | 'flat' = 'sharp'): Note {\n return new Note(midiToNote(midi, spelling));\n }\n\n /**\n * Wrap an existing plain note object.\n *\n * @param data The plain note.\n * @returns The wrapped note.\n * @throws If `letter` is not an integer in 0..6.\n */\n static fromData(data: NoteData): Note {\n return new Note(data);\n }\n\n /** The note rendered as scientific pitch notation, e.g. `'G4'` or `'Bb'`. */\n get name(): string {\n return formatNote(this.#data);\n }\n\n /** The pitch class (0..11), ignoring octave. */\n get pitchClass(): number {\n return noteToPitchClass(this.#data);\n }\n\n /**\n * The MIDI number (middle C = C4 = 60).\n *\n * @throws If the note has no octave and therefore no fixed pitch.\n */\n get midi(): number {\n if (this.#data.octave === undefined) {\n throw new InvalidInputError(`note ${this.name} has no octave, so it has no MIDI number`);\n }\n return noteToMidi(this.#data);\n }\n\n /** The diatonic letter number: 0..6 for C..B. */\n get letter(): number {\n return this.#data.letter;\n }\n\n /** The chromatic alteration in semitones: -1 flat, 0 natural, +1 sharp, ... */\n get alter(): number {\n return this.#data.alter;\n }\n\n /** The octave (scientific pitch notation), or undefined for a bare pitch class. */\n get octave(): number | undefined {\n return this.#data.octave;\n }\n\n /** A copy of the underlying plain note object. */\n get data(): NoteData {\n return copyNote(this.#data);\n }\n\n /**\n * Transpose by a signed number of semitones, keeping the spelling.\n *\n * The letter moves by the diatonic distance of the conventional interval for\n * that many semitones, so `Ab4` up a major second is `Bb4` rather than `A#4`\n * and a flat key stays on the flat side. An octave-less note stays\n * octave-less: only its pitch class is moved. Transposing by zero is the\n * identity: the original spelling is preserved (no enharmonic respelling).\n *\n * @param semitones The signed semitone offset.\n * @param opts `spelling` forces the result onto the sharp or flat side\n * instead of following this note's letter.\n * @returns The transposed note.\n * @example\n * ```ts\n * import { Note } from '@libraz/libcantus';\n * Note.of('Ab4').transpose(2).name; // 'Bb4'\n * Note.of('Ab4').transpose(2, { spelling: 'sharp' }).name; // 'A#4'\n * ```\n */\n transpose(semitones: number, opts?: { spelling?: 'sharp' | 'flat' }): Note {\n if (semitones === 0 && opts?.spelling === undefined) {\n return new Note(this.#data);\n }\n return new Note(transposeNote(this.#data, semitones, opts));\n }\n\n /**\n * The spelled interval from this note to another.\n *\n * @param other The second note.\n * @returns The interval, which {@link Interval.toJSON} unwraps to plain data.\n */\n intervalTo(other: Note): Interval {\n // Read the other note through its public accessor rather than its private\n // field: a bundler that emits two copies of this class — as a CommonJS\n // build without shared chunks does for the root and /model entries — would\n // otherwise throw on the brand check.\n return Interval.fromData(spelledInterval(this.#data, other.data));\n }\n\n /**\n * Transpose by a spelled interval, keeping the spelling the interval names.\n *\n * Unlike {@link Note.transpose}, which picks a letter from the semitone\n * count, the interval's diatonic number decides the letter: C up an\n * augmented second is D#, not Eb.\n *\n * @param interval The interval to apply; a descending interval moves down.\n * @returns The transposed note.\n * @example\n * ```ts\n * import { Interval, Note } from '@libraz/libcantus';\n * Note.of('C4').transposeBy(Interval.parse('A2')).name; // 'D#4'\n * ```\n */\n transposeBy(interval: Interval): Note {\n return new Note(transposeByInterval(this.#data, interval.toJSON()));\n }\n\n /**\n * Rebuild a note from its {@link Note.toJSON} output.\n *\n * @param data The serialized note.\n * @returns The wrapped note.\n * @throws If `letter` is not an integer in 0..6.\n */\n static fromJSON(data: NoteData): Note {\n return new Note(data);\n }\n\n /**\n * Whether another note has the same letter, alteration, and octave.\n *\n * @param other The note to compare.\n * @returns True if the spellings are identical.\n */\n equals(other: Note): boolean {\n const b = other.data;\n return (\n this.#data.letter === b.letter &&\n this.#data.alter === b.alter &&\n this.#data.octave === b.octave\n );\n }\n\n /**\n * The plain note data, for JSON serialization.\n *\n * Private class fields do not serialize, so an explicit `toJSON` keeps\n * `JSON.stringify(note)` from collapsing to `{}`.\n *\n * @returns A copy of the underlying plain note object.\n */\n toJSON(): NoteData {\n return this.data;\n }\n\n /**\n * The note's name, so a template literal or a log line reads as the note.\n *\n * @returns The spelled name, e.g. `'Bb3'`.\n */\n toString(): string {\n return this.name;\n }\n}\n","import { midiToNote, pitchClassOf as mod12, type Note as NoteData } from '../core/pitch/index.js';\n\nexport { pitchClassOf as mod12 } from '../core/pitch/index.js';\n\n/** Spell a bare pitch class as an octave-less note with a sharp/flat preference. */\nexport function spellPitchClassBare(pc: number, spelling: 'sharp' | 'flat'): NoteData {\n const spelled = midiToNote(60 + mod12(pc), spelling);\n return { letter: spelled.letter, alter: spelled.alter };\n}\n","import type { DetectKeyOptions } from '../analyze/detect/index.js';\nimport { detectKey, detectKeyBest } from '../analyze/detect/index.js';\nimport { isMinorKey, romanToChord } from '../analyze/functional/index.js';\nimport { InvalidInputError } from '../core/errors/index.js';\nimport type { Note as NoteData } from '../core/pitch/index.js';\nimport type { KeyScale } from '../core/types.js';\nimport { assertFiniteNumber } from '../core/validation/index.js';\nimport {\n type ChordQuality,\n chordFromDegree,\n diatonicSeventh,\n diatonicTriad,\n} from '../theory/chord/index.js';\nimport {\n isScaleTone,\n majorKey,\n minorKey,\n scaleByName,\n scaleTonesInDegreeOrder,\n} from '../theory/scale/index.js';\nimport { spellScale } from '../theory/spelling/index.js';\nimport { Chord } from './chord.js';\nimport { Note } from './note.js';\nimport { mod12, spellPitchClassBare } from './shared.js';\n\n/** Total accidentals a spelled tonic produces across a key's whole scale. */\nfunction accidentalLoad(tonic: NoteData, scale: KeyScale): number {\n return spellScale(tonic, scale).reduce((sum, note) => sum + Math.abs(note.alter), 0);\n}\n\n/**\n * Choose the tonic spelling (sharp- or flat-side) that spells `scale` with the\n * fewest accidentals, so a numeric root never yields a double-flat/double-sharp\n * scale (e.g. pitch class 6 minor spells as F# minor, not Gb minor with Bbb).\n */\nfunction bestTonicForScale(rootPc: number, scale: KeyScale): Note {\n const sharp = spellPitchClassBare(rootPc, 'sharp');\n const flat = spellPitchClassBare(rootPc, 'flat');\n if (sharp.letter === flat.letter && sharp.alter === flat.alter) {\n return new Note(sharp);\n }\n return accidentalLoad(flat, scale) <= accidentalLoad(sharp, scale)\n ? new Note(flat)\n : new Note(sharp);\n}\n\n/**\n * An immutable key/scale: a `KeyScale` (root pitch class plus mode mask) paired\n * with a spelled tonic that anchors letter-name spelling. Acts as the factory\n * for key-aware chords.\n *\n * @category Class API\n * @example\n * ```ts\n * import { Key } from '@libraz/libcantus';\n * Key.major('C').chord(4).symbol(); // 'G' (the diatonic triad on scale degree 4)\n * ```\n */\nexport class Key {\n readonly #scale: KeyScale;\n readonly #tonic: Note;\n\n /**\n * Wrap a key/scale and its spelled tonic.\n *\n * @param scale The key/scale; its root is normalized to a pitch class.\n * @param tonic The spelled tonic anchoring letter-name spelling.\n */\n constructor(scale: KeyScale, tonic: Note) {\n const rootPc = mod12(scale.rootPc);\n if (tonic.pitchClass !== rootPc) {\n throw new InvalidInputError(\n `tonic ${tonic.name} does not match the scale root pitch class ${rootPc}; ` +\n 'pass a tonic that spells the scale root, or omit it to have one chosen',\n );\n }\n this.#scale = { rootPc, modeMask12: scale.modeMask12 };\n this.#tonic = tonic;\n }\n\n /**\n * A major key.\n *\n * @param root Tonic as a note name (e.g. `'Eb'`) or a pitch class; a numeric\n * root is spelled with whichever accidental side yields the fewest\n * accidentals across the scale.\n * @returns The major key.\n */\n static major(root: string | number): Key {\n if (typeof root === 'string') {\n const tonic = Note.of(root);\n return new Key(majorKey(tonic.pitchClass), tonic);\n }\n const scale = majorKey(root);\n return new Key(scale, bestTonicForScale(root, scale));\n }\n\n /**\n * A natural-minor key.\n *\n * @param root Tonic as a note name or a pitch class; a numeric root is\n * spelled with whichever accidental side yields the fewest accidentals\n * across the scale.\n * @returns The minor key.\n */\n static minor(root: string | number): Key {\n if (typeof root === 'string') {\n const tonic = Note.of(root);\n return new Key(minorKey(tonic.pitchClass), tonic);\n }\n const scale = minorKey(root);\n return new Key(scale, bestTonicForScale(root, scale));\n }\n\n /**\n * A key on a named scale (e.g. `'dorian'`, `'harmonicMinor'`).\n *\n * @param name The scale name, a key of the scale module's named-scale table.\n * @param root Tonic as a note name or a pitch class; a numeric root is\n * spelled with whichever accidental side yields the fewest accidentals\n * across the scale, exactly as {@link Key.major} does.\n * @returns The key.\n * @throws If the name is not a known scale.\n */\n static named(name: string, root: string | number): Key {\n if (typeof root === 'string') {\n const tonic = Note.of(root);\n return new Key(scaleByName(name, tonic.pitchClass), tonic);\n }\n const scale = scaleByName(name, mod12(root));\n return new Key(scale, bestTonicForScale(mod12(root), scale));\n }\n\n /**\n * Wrap an existing `KeyScale`, synthesizing a spelled tonic when none is\n * given.\n *\n * The synthesized tonic is chosen the same way as for a numeric root\n * elsewhere: whichever accidental side spells the scale with the fewest\n * accidentals. This is what keeps `Key.of(detectKey(...).scale)` from handing\n * every downstream chord a double-sharp spelling.\n *\n * @param scale The key/scale to wrap.\n * @param tonic Optional spelled tonic; must spell the scale's root pitch class.\n * @returns The key.\n * @throws If the given tonic is not the scale's root pitch class.\n */\n static of(scale: KeyScale, tonic?: Note): Key {\n return new Key(scale, tonic ?? bestTonicForScale(mod12(scale.rootPc), scale));\n }\n\n /**\n * Rebuild a key from its {@link Key.toJSON} output.\n *\n * @param data The serialized key and tonic.\n * @returns The key.\n */\n static fromJSON(data: { scale: KeyScale; tonic: NoteData }): Key {\n return new Key(data.scale, new Note(data.tonic));\n }\n\n /**\n * Identify the keys a set of pitches fits, best interpretation first.\n *\n * The counterpart of {@link Chord.detect}.\n *\n * @param pitches MIDI pitches or bare pitch classes.\n * @param opts How to weigh the input; see {@link DetectKeyOptions}.\n * @returns Ranked keys (may be empty).\n */\n static detect(pitches: readonly number[], opts?: DetectKeyOptions): Key[] {\n return detectKey(pitches, opts).map((match) => Key.of(match.key));\n }\n\n /**\n * The single best key interpretation of a pitch set.\n *\n * @param pitches MIDI pitches or bare pitch classes.\n * @param opts How to weigh the input; see {@link DetectKeyOptions}.\n * @returns The top-ranked key, or null when nothing matches.\n * @example\n * ```ts\n * import { Key } from '@libraz/libcantus';\n * Key.detectBest([0, 2, 4, 5, 7, 9, 11])?.toString(); // 'C major'\n * ```\n */\n static detectBest(pitches: readonly number[], opts?: DetectKeyOptions): Key | null {\n const best = detectKeyBest(pitches, opts);\n return best === null ? null : Key.of(best.key);\n }\n\n /**\n * Whether another key has the same tonic pitch class and mode.\n *\n * The spelled tonic is not compared: C# major and Db major are the same key\n * written two ways.\n *\n * @param other The key to compare.\n * @returns True when tonic and mode mask both match.\n */\n equals(other: Key): boolean {\n const scale = other.scale;\n return this.#scale.rootPc === scale.rootPc && this.#scale.modeMask12 === scale.modeMask12;\n }\n\n /** A copy of the underlying plain `KeyScale`. */\n get scale(): KeyScale {\n return { rootPc: this.#scale.rootPc, modeMask12: this.#scale.modeMask12 };\n }\n\n /** The spelled tonic. */\n get tonic(): Note {\n return this.#tonic;\n }\n\n /** The tonic pitch class (0..11). */\n get rootPc(): number {\n return this.#scale.rootPc;\n }\n\n /** Whether the scale has a minor third and no major third. */\n get isMinor(): boolean {\n return isMinorKey(this.#scale);\n }\n\n /**\n * The scale's pitch classes in ascending scale-degree order (degree 0 first).\n *\n * @returns One pitch class per scale degree.\n */\n pitchClasses(): number[] {\n return scaleTonesInDegreeOrder(this.#scale);\n }\n\n /**\n * Transpose the key by a number of semitones.\n *\n * The mode mask is unchanged, so the scale keeps its shape; only the tonic\n * moves. The new tonic is spelled the way that key is conventionally written\n * — D major, not C## major.\n *\n * @param semitones The signed semitone offset.\n * @returns The transposed key.\n * @example\n * ```ts\n * import { Key } from '@libraz/libcantus';\n * Key.major('C').transpose(2).toString(); // 'D major'\n * ```\n */\n transpose(semitones: number): Key {\n assertFiniteNumber(semitones, 'semitones');\n const rootPc = mod12(this.#scale.rootPc + Math.round(semitones));\n return Key.of({ rootPc, modeMask12: this.#scale.modeMask12 });\n }\n\n /**\n * The spelled scale, one note per degree (e.g. C D E F G A B for C major).\n *\n * @returns Spelled octave-less notes in scale-degree order.\n */\n notes(): Note[] {\n return spellScale(this.#tonic.data, this.#scale).map((note) => new Note(note));\n }\n\n /**\n * Alias of {@link Key.notes}.\n *\n * @returns Spelled octave-less notes in scale-degree order.\n */\n spell(): Note[] {\n return this.notes();\n }\n\n /**\n * The spelled scale as letter-name strings.\n *\n * @returns One name per scale degree.\n */\n noteNames(): string[] {\n return this.notes().map((note) => note.name);\n }\n\n /**\n * Build a chord on a scale degree, carrying this key as context.\n *\n * With an explicit quality the quality's interval template is attached to the\n * degree's diatonic root; without one the scale-correct diatonic triad is\n * stacked (e.g. a diminished triad on the leading tone of a major key).\n *\n * @param degree 0-based scale degree of the chord root.\n * @param quality Optional chord quality.\n * @returns The chord, with this key attached.\n * @throws Without a `quality`, if this key's scale is not heptatonic —\n * stacking thirds needs seven degrees, so the pentatonic, blues,\n * whole-tone, octatonic and chromatic scales have no diatonic triad. Pass\n * an explicit `quality` for those.\n */\n chord(degree: number, quality?: ChordQuality): Chord {\n const data =\n quality === undefined\n ? diatonicTriad(degree, this.#scale)\n : chordFromDegree(degree, quality, this.#scale);\n return new Chord(data, this);\n }\n\n /**\n * The diatonic triad on a scale degree, carrying this key as context.\n *\n * @param degree 0-based scale degree of the chord root.\n * @returns The triad, with this key attached.\n * @throws If this key's scale is not heptatonic; stacking thirds needs seven\n * degrees. Use {@link Key.chord} with an explicit quality instead.\n */\n diatonicTriad(degree: number): Chord {\n return new Chord(diatonicTriad(degree, this.#scale), this);\n }\n\n /**\n * The diatonic seventh chord on a scale degree, carrying this key as context.\n *\n * @param degree 0-based scale degree of the chord root.\n * @returns The seventh chord, with this key attached.\n * @throws If this key's scale is not heptatonic; stacking thirds needs seven\n * degrees. Use {@link Key.chord} with an explicit quality instead.\n */\n diatonicSeventh(degree: number): Chord {\n return new Chord(diatonicSeventh(degree, this.#scale), this);\n }\n\n /**\n * Build the chord denoted by a Roman numeral in this key (including applied\n * chords such as `'V7/V'`), carrying this key as context.\n *\n * @param text The Roman numeral.\n * @returns The chord, with this key attached.\n * @throws If the numeral is not valid.\n */\n roman(text: string): Chord {\n return new Chord(romanToChord(text, this.#scale), this);\n }\n\n /**\n * Whether a pitch belongs to the scale.\n *\n * @param x A MIDI pitch, bare pitch class, or note.\n * @returns True if the pitch class is a scale tone.\n */\n contains(x: number | Note): boolean {\n return isScaleTone(typeof x === 'number' ? x : x.pitchClass, this.#scale);\n }\n\n /**\n * The plain key data, for JSON serialization.\n *\n * Private class fields do not serialize, so an explicit `toJSON` keeps\n * `JSON.stringify(key)` from collapsing to `{}`. The result pairs the\n * `KeyScale` with the spelled tonic, enough to reconstruct the key via\n * {@link Key.of}.\n *\n * @returns The key/scale and its spelled tonic.\n */\n toJSON(): { scale: KeyScale; tonic: NoteData } {\n return { scale: this.scale, tonic: this.#tonic.data };\n }\n\n /**\n * The key's tonic and mode, so a template literal or a log line reads as the\n * key. Only the major/minor distinction is named, since a mask does not carry\n * a scale name.\n *\n * @returns The name, e.g. `'C major'` or `'A minor'`.\n */\n toString(): string {\n return `${this.#tonic.name} ${this.isMinor ? 'minor' : 'major'}`;\n }\n}\n","import {\n type Cadence,\n type ChordAnalysis,\n detectCadence,\n type HarmonicFunction,\n} from '../analyze/functional/index.js';\nimport { InvalidInputError } from '../core/errors/index.js';\nimport type { Note as NoteData } from '../core/pitch/index.js';\nimport type { KeyScale } from '../core/types.js';\nimport type { Chord as ChordData, ChordSpan } from '../theory/chord/index.js';\nimport { makeChord } from '../theory/chord/index.js';\nimport { type VoicingOptions, voiceProgression } from '../theory/voicing/index.js';\nimport type { Chord } from './chord.js';\nimport { Chord as ChordClass } from './chord.js';\nimport type { Key } from './key.js';\nimport { Key as KeyClass } from './key.js';\n\n/**\n * An immutable ordered sequence of chords, optionally carrying a {@link Key}\n * context shared by its analysis methods.\n *\n * @category Class API\n * @example\n * ```ts\n * import { Key } from '@libraz/libcantus';\n * const key = Key.major('C');\n * key.chord(1).progressionTo(key.chord(4), key.chord(0)).roman();\n * // ['ii', 'V', 'I']\n * ```\n */\nexport class Progression {\n readonly #chords: readonly Chord[];\n readonly #key: Key | undefined;\n\n /**\n * Wrap a chord sequence.\n *\n * @param chords The chords in order; the array is copied.\n * @param key Optional key context for analysis methods.\n */\n constructor(chords: readonly Chord[], key?: Key) {\n this.#chords = Object.freeze([...chords]);\n this.#key = key;\n }\n\n /**\n * Build a progression from the {@link ChordSpan} records the generators\n * return, keeping their order.\n *\n * The spans' `startBeat`, `degree`, and `secondaryDominant` are analysis\n * annotations that a chord sequence does not carry; only the harmony crosses\n * over. Keep the spans themselves if the timing matters.\n *\n * @param spans The chord spans, in order.\n * @param key Optional key context for the analysis methods.\n * @returns The progression.\n * @example\n * ```ts\n * import { generateProgression, Key, Progression } from '@libraz/libcantus';\n * const key = Key.major('C');\n * const spans = generateProgression({ key: key.scale, style: 'dance', bars: 4 });\n * Progression.fromSpans(spans, key).roman();\n * ```\n */\n static fromSpans(spans: readonly ChordSpan[], key?: Key): Progression {\n const chords = spans.map((span) => {\n const chord = ChordClass.from(makeChord(span.rootPc, span.quality, span.bassPc));\n return key === undefined ? chord : chord.withKey(key);\n });\n return key === undefined ? new Progression(chords) : new Progression(chords, key);\n }\n\n /**\n * Rebuild a progression from its {@link Progression.toJSON} output.\n *\n * @param data The serialized chords and key.\n * @returns The progression.\n */\n static fromJSON(data: {\n chords: ChordData[];\n key?: { scale: KeyScale; tonic: NoteData } | undefined;\n }): Progression {\n const key = data.key === undefined ? undefined : KeyClass.fromJSON(data.key);\n const chords = data.chords.map((chord) => ChordClass.fromJSON(chord));\n return key === undefined ? new Progression(chords) : new Progression(chords, key);\n }\n\n /**\n * The chord sequence.\n *\n * The array is the progression's own and is frozen rather than copied, so\n * reading it in a loop stays linear.\n */\n get chords(): readonly Chord[] {\n return this.#chords;\n }\n\n /** The carried key context, if any. */\n get key(): Key | undefined {\n return this.#key;\n }\n\n /** The number of chords. */\n get length(): number {\n return this.#chords.length;\n }\n\n /**\n * The chord at an index.\n *\n * @param index 0-based position; a negative index counts from the end.\n * @returns The chord, or undefined when the index is out of range.\n */\n at(index: number): Chord | undefined {\n return this.#chords.at(index);\n }\n\n /** Iterate the chords in order, so a progression works with `for...of`. */\n [Symbol.iterator](): IterableIterator<Chord> {\n return this.#chords[Symbol.iterator]();\n }\n\n /**\n * Whether another progression holds the same chords in the same order.\n *\n * The key context is not compared: it is an analysis lens, not part of the\n * harmony. Chord equality follows {@link Chord.equals}.\n *\n * @param other The progression to compare.\n * @returns True when the chord sequences match.\n */\n equals(other: Progression): boolean {\n if (this.#chords.length !== other.length) {\n return false;\n }\n return this.#chords.every((chord, index) => {\n const theirs = other.at(index);\n return theirs !== undefined && chord.equals(theirs);\n });\n }\n\n /**\n * A copy of this progression with a chord appended.\n *\n * @param chord The chord to append.\n * @returns The new progression.\n */\n add(chord: Chord): Progression {\n return new Progression([...this.#chords, chord], this.#key);\n }\n\n /**\n * A copy of this progression carrying the given key context.\n *\n * @param key The key context to attach.\n * @returns The new progression.\n */\n withKey(key: Key): Progression {\n return new Progression(this.#chords, key);\n }\n\n /**\n * Voice the progression with smooth voice leading.\n *\n * @param opts Voicing options; defaults to four SATB voices.\n * @returns One ascending voicing (MIDI pitches) per chord.\n * @throws If any chord admits no voicing within the given ranges.\n */\n voice(opts?: VoicingOptions): number[][] {\n return voiceProgression(\n this.#chords.map((chord) => chord.data),\n opts,\n );\n }\n\n /**\n * The Roman numeral of each chord in a key.\n *\n * @param key Key to analyze in; falls back to the carried context.\n * @returns One numeral per chord.\n * @throws If no key is given and none is carried.\n */\n roman(key?: Key): string[] {\n const resolved = this.#resolveKey(key);\n return this.#chords.map((chord) => chord.roman(resolved));\n }\n\n /**\n * The harmonic function of each chord in a key.\n *\n * @param key Key to analyze in; falls back to the carried context.\n * @returns One function per chord.\n * @throws If no key is given and none is carried.\n */\n functions(key?: Key): HarmonicFunction[] {\n const resolved = this.#resolveKey(key);\n return this.#chords.map((chord) => chord.function(resolved));\n }\n\n /**\n * Analyze every chord and classify the closing cadence.\n *\n * The cadence is detected on the final chord pair and is null when the\n * progression has fewer than two chords.\n *\n * @param key Key to analyze in; falls back to the carried context.\n * @returns Per-chord analyses and the closing cadence.\n * @throws If no key is given and none is carried.\n */\n analyze(key?: Key): { chords: ChordAnalysis[]; cadence: Cadence } {\n const resolved = this.#resolveKey(key);\n const chords = this.#chords.map((chord) => chord.analyze(resolved));\n const from = this.#chords[this.#chords.length - 2];\n const to = this.#chords[this.#chords.length - 1];\n const cadence =\n from !== undefined && to !== undefined\n ? detectCadence(from.data, to.data, resolved.scale)\n : null;\n return { chords, cadence };\n }\n\n /**\n * The plain progression data, for JSON serialization.\n *\n * Private class fields do not serialize, so an explicit `toJSON` keeps\n * `JSON.stringify(progression)` from collapsing to `{}`. The chords are\n * emitted as plain data and the carried key, when present, as its own data.\n *\n * @returns The chord data sequence and the carried key, if any.\n */\n /**\n * Transpose every chord by a number of semitones.\n *\n * A carried key moves with the chords, so the progression keeps its degrees\n * and functions in the new key.\n *\n * @param semitones The signed semitone offset.\n * @returns The transposed progression.\n * @example\n * ```ts\n * import { Chord, Progression } from '@libraz/libcantus';\n * new Progression([Chord.parse('C'), Chord.parse('G')]).transpose(2).toString(); // 'D A'\n * ```\n */\n transpose(semitones: number): Progression {\n const key = this.#key?.transpose(semitones);\n const chords = this.#chords.map((chord) => {\n const moved = chord.transpose(semitones);\n // A chord that carried no key of its own is spelled by this progression's\n // key, so it has to receive the transposed one or it would fall back to\n // sharps in a flat key.\n return key !== undefined && moved.key === undefined ? moved.withKey(key) : moved;\n });\n return key === undefined ? new Progression(chords) : new Progression(chords, key);\n }\n\n /**\n * The chord symbols separated by spaces, so a template literal or a log line\n * reads as the progression.\n *\n * @returns The symbols in order, e.g. `'C Am F G'`.\n */\n toString(): string {\n return this.#chords.map((chord) => chord.symbol()).join(' ');\n }\n\n toJSON(): { chords: ChordData[]; key: { scale: KeyScale; tonic: NoteData } | undefined } {\n return {\n chords: this.#chords.map((chord) => chord.data),\n key: this.#key?.toJSON(),\n };\n }\n\n /** Resolve the key for an analysis method: explicit first, then carried. */\n #resolveKey(key?: Key): Key {\n const resolved = key ?? this.#key;\n if (resolved === undefined) {\n throw new InvalidInputError(\n 'progression has no key context; pass a Key or attach one with withKey()',\n );\n }\n return resolved;\n }\n}\n","import type { ChordMatch, DetectChordOptions } from '../analyze/detect/index.js';\nimport { detectChord, detectChordBest } from '../analyze/detect/index.js';\nimport {\n analyzeChord,\n type BorrowedSource,\n borrowedSource,\n type ChordAnalysis,\n chordToRoman,\n functionOf,\n type HarmonicFunction,\n isBorrowedChord,\n} from '../analyze/functional/index.js';\nimport { InvalidInputError } from '../core/errors/index.js';\nimport type { Note as NoteData } from '../core/pitch/index.js';\nimport { noteToPitchClass } from '../core/pitch/index.js';\nimport { negativeHarmonyMirror } from '../generate/reharmony/index.js';\nimport {\n type Chord as ChordData,\n type ChordQuality,\n chordPitchClasses,\n makeChord,\n type PitchSpelling,\n transposeChord,\n} from '../theory/chord/index.js';\nimport {\n availableTensions,\n avoidNotes,\n type ChordScaleMatch,\n chordScales,\n} from '../theory/chordscale/index.js';\nimport type { ScaleNameInput } from '../theory/scale/index.js';\nimport { spellChord, spellChordFromRoot, spellPitchClass } from '../theory/spelling/index.js';\nimport { formatChordSymbol, parseChordSymbol } from '../theory/symbol/index.js';\nimport {\n type StyledVoicingOptions,\n type VoicingOptions,\n voiceChord,\n voiceChordStyled,\n} from '../theory/voicing/index.js';\nimport type { Key } from './key.js';\nimport { Note } from './note.js';\nimport { Progression } from './progression.js';\nimport { mod12 } from './shared.js';\n\n/** Whether a spelling hint still names the pitch class it is attached to. */\nfunction hintMatches(hint: PitchSpelling | undefined, pc: number | undefined): boolean {\n return hint !== undefined && pc !== undefined && mod12(noteToPitchClass(hint)) === mod12(pc);\n}\n\n/**\n * Defensive copy of a plain chord.\n *\n * Enharmonic spelling hints (`rootSpelling`/`bassSpelling`, populated by\n * `parseChordSymbol`) are carried through so a flat-named chord round-trips\n * through the class API — but only while they still name their own pitch\n * class. A stale hint is dropped here rather than passed on, so that everything\n * downstream, including the derived bass spelling, reads a hint it can trust.\n */\nfunction copyChord(data: ChordData): ChordData {\n const copy: ChordData = {\n rootPc: data.rootPc,\n quality: data.quality,\n intervals: [...data.intervals],\n };\n if (data.bassPc !== undefined) {\n copy.bassPc = data.bassPc;\n }\n if (hintMatches(data.rootSpelling, data.rootPc) && data.rootSpelling !== undefined) {\n copy.rootSpelling = { letter: data.rootSpelling.letter, alter: data.rootSpelling.alter };\n }\n if (hintMatches(data.bassSpelling, data.bassPc) && data.bassSpelling !== undefined) {\n copy.bassSpelling = { letter: data.bassSpelling.letter, alter: data.bassSpelling.alter };\n }\n return copy;\n}\n\n/**\n * Spell the slash bass of a chord whose root spelling is already settled.\n *\n * A bass that is one of the chord's own tones takes that tone's spelling, so\n * `Eb/Bb` never renders as `Eb/A#`; a bass outside the chord is spelled by the\n * key when one is available.\n */\nfunction deriveBassSpelling(chord: ChordData, key: Key | undefined): PitchSpelling | undefined {\n const bassPc = chord.bassPc;\n if (bassPc === undefined) {\n return undefined;\n }\n const root = chord.rootSpelling;\n if (root !== undefined) {\n const index = chord.intervals.findIndex((i) => mod12(chord.rootPc + i) === bassPc);\n const tone = index >= 0 ? spellChordFromRoot(chord, root)[index] : undefined;\n if (tone !== undefined) {\n return { letter: tone.letter, alter: tone.alter };\n }\n }\n if (key === undefined) {\n return undefined;\n }\n const spelled = spellPitchClass(bassPc, key.tonic.data, key.scale);\n return { letter: spelled.letter, alter: spelled.alter };\n}\n\n/**\n * An immutable chord: a root pitch class, quality, interval template, and\n * optional slash bass, optionally carrying a {@link Key} context. Analysis\n * methods (`roman`, `function`, `analyze`, ...) use an explicitly passed key\n * first and fall back to the carried context.\n *\n * @category Class API\n * @example\n * ```ts\n * import { Chord } from '@libraz/libcantus';\n * Chord.parse('Cmaj7').invert(1).symbol(); // 'Cmaj7/E' (third in the bass)\n * ```\n */\nexport class Chord {\n /** Exactly what the caller supplied: any spelling here is the caller's own. */\n readonly #given: ChordData;\n readonly #key: Key | undefined;\n\n /**\n * Wrap a plain chord object.\n *\n * @param data The chord; it is copied, never retained or mutated.\n * @param key Optional key context for analysis methods.\n */\n constructor(data: ChordData, key?: Key) {\n this.#given = copyChord(data);\n this.#key = key;\n }\n\n /**\n * The chord data with any missing spelling hint filled in from the key.\n *\n * Derived spellings are computed on read rather than baked in at construction,\n * so re-attaching a different key re-spells the chord instead of carrying the\n * first key's letters forever. A spelling the caller supplied always wins.\n */\n get #data(): ChordData {\n const out = copyChord(this.#given);\n const key = this.#key;\n if (out.rootSpelling === undefined && key !== undefined) {\n out.rootSpelling = spellPitchClass(out.rootPc, key.tonic.data, key.scale);\n }\n if (out.bassSpelling === undefined) {\n const bass = deriveBassSpelling(out, key);\n if (bass !== undefined) {\n out.bassSpelling = bass;\n }\n }\n return out;\n }\n\n /**\n * Build a chord from a root and quality.\n *\n * @param root Root as a note name (e.g. `'Eb'`) or a pitch class.\n * @param quality The chord quality.\n * @param bass Optional slash-chord bass, as a note name (e.g. `'Bb'`) or a\n * pitch class. A named bass keeps its own spelling.\n * @returns The chord (without key context).\n */\n static of(root: string | number, quality: ChordQuality, bass?: string | number): Chord {\n const bassNote = typeof bass === 'string' ? Note.of(bass) : undefined;\n const bassPc = bassNote !== undefined ? bassNote.pitchClass : (bass as number | undefined);\n const rootNote = typeof root === 'string' ? Note.of(root) : undefined;\n const data = makeChord(\n rootNote !== undefined ? rootNote.pitchClass : (root as number),\n quality,\n bassPc,\n );\n if (rootNote !== undefined) {\n data.rootSpelling = { letter: rootNote.letter, alter: rootNote.alter };\n }\n if (bassNote !== undefined) {\n data.bassSpelling = { letter: bassNote.letter, alter: bassNote.alter };\n }\n return new Chord(data);\n }\n\n /**\n * Wrap an existing plain chord object.\n *\n * @param data The plain chord.\n * @returns The wrapped chord (without key context).\n */\n static from(data: ChordData): Chord {\n return new Chord(data);\n }\n\n /**\n * Alias of {@link Chord.from}, matching the `fromData` factory on the other\n * classes.\n *\n * @param data The plain chord.\n * @returns The wrapped chord (without key context).\n */\n static fromData(data: ChordData): Chord {\n return new Chord(data);\n }\n\n /**\n * Rebuild a chord from its {@link Chord.toJSON} output.\n *\n * The key context is not serialized, so the result carries none; re-attach\n * one with {@link Chord.withKey}.\n *\n * @param data The serialized chord.\n * @returns The wrapped chord.\n */\n static fromJSON(data: ChordData): Chord {\n return new Chord(data);\n }\n\n /**\n * Parse a lead-sheet chord symbol (e.g. `'Cmaj7'`, `'F#m7b5'`, `'C/G'`).\n *\n * @param symbol The chord symbol.\n * @returns The chord (without key context).\n * @throws If the root or quality is not recognized.\n */\n static parse(symbol: string): Chord {\n return new Chord(parseChordSymbol(symbol));\n }\n\n /**\n * Identify the chords matching a set of pitches, best interpretation first.\n *\n * @param pitches MIDI pitches or bare pitch classes.\n * @param opts How to interpret the input; see {@link DetectChordOptions}.\n * @returns Ranked chord interpretations (may be empty).\n */\n static detect(pitches: readonly number[], opts?: DetectChordOptions): Chord[] {\n return detectChord(pitches, opts).map(\n (match) => new Chord(makeChord(match.rootPc, match.quality, match.bassPc)),\n );\n }\n\n /**\n * Identify the chords matching a set of pitches, keeping each match's\n * recognition metadata beside the chord.\n *\n * {@link Chord.detect} discards the confidence signals a recognition UI needs\n * — whether the set matched exactly, which chord tones were missing, which\n * input notes were foreign, and which inversion the bass implies.\n *\n * @param pitches MIDI pitches or bare pitch classes.\n * @param opts How to interpret the input; see {@link DetectChordOptions}.\n * @returns Ranked interpretations, each with its chord and its match record.\n * @example\n * ```ts\n * import { Chord } from '@libraz/libcantus';\n * const [best] = Chord.detectMatches([60, 64, 67]);\n * best?.match.exact; // true\n * ```\n */\n static detectMatches(\n pitches: readonly number[],\n opts?: DetectChordOptions,\n ): { chord: Chord; match: ChordMatch }[] {\n return detectChord(pitches, opts).map((match) => ({\n chord: new Chord(makeChord(match.rootPc, match.quality, match.bassPc)),\n match,\n }));\n }\n\n /**\n * The single best chord interpretation of a pitch set.\n *\n * @param pitches MIDI pitches or bare pitch classes.\n * @param opts How to interpret the input; see {@link DetectChordOptions}.\n * @returns The top-ranked chord, or null when nothing matches.\n */\n static detectBest(pitches: readonly number[], opts?: DetectChordOptions): Chord | null {\n const best = detectChordBest(pitches, opts);\n return best === null ? null : new Chord(best);\n }\n\n /** The root pitch class (0..11). */\n get rootPc(): number {\n return this.#data.rootPc;\n }\n\n /** The chord quality. */\n get quality(): ChordQuality {\n return this.#data.quality;\n }\n\n /** A copy of the semitone offsets above the root. */\n get intervals(): number[] {\n return [...this.#data.intervals];\n }\n\n /** The slash-chord bass pitch class, or undefined in root position. */\n get bassPc(): number | undefined {\n return this.#data.bassPc;\n }\n\n /**\n * A copy of the underlying plain chord object, including the spellings\n * derived from any attached key.\n */\n get data(): ChordData {\n return this.#data;\n }\n\n /** The carried key context, if any. */\n get key(): Key | undefined {\n return this.#key;\n }\n\n /**\n * A copy of this chord carrying the given key context.\n *\n * Only a spelling the caller supplied (via `Chord.parse`, `Chord.of` with a\n * named root, or plain data carrying a hint) survives; a spelling that came\n * from a previously attached key is re-derived, so re-keying a progression\n * during a modulation does not keep the old key's letters and the order of\n * `withKey` calls does not affect the result.\n *\n * @param key The key context to attach.\n * @returns The new chord.\n */\n withKey(key: Key): Chord {\n return new Chord(this.#given, key);\n }\n\n /**\n * The chord's sorted, deduplicated pitch classes.\n *\n * @returns Pitch classes ascending in [0, 11].\n */\n pitchClasses(): number[] {\n return chordPitchClasses(this.#data);\n }\n\n /**\n * The chord's Roman numeral in a key.\n *\n * @param key Key to analyze in; falls back to the carried context.\n * @returns The Roman numeral string.\n * @throws If no key is given and none is carried.\n */\n roman(key?: Key): string {\n return chordToRoman(this.#data, this.#resolveKey(key).scale);\n }\n\n /**\n * The chord's harmonic function (tonic / subdominant / dominant) in a key.\n *\n * @param key Key to analyze in; falls back to the carried context.\n * @returns The harmonic function.\n * @throws If no key is given and none is carried.\n */\n function(key?: Key): HarmonicFunction {\n return functionOf(this.#data, this.#resolveKey(key).scale);\n }\n\n /**\n * Full functional analysis: function, borrowing, and Roman numeral.\n *\n * @param key Key to analyze in; falls back to the carried context.\n * @returns The chord analysis.\n * @throws If no key is given and none is carried.\n */\n analyze(key?: Key): ChordAnalysis {\n return analyzeChord(this.#data, this.#resolveKey(key).scale);\n }\n\n /**\n * Whether the chord is borrowed from the parallel mode (modal interchange).\n *\n * @param key Key to analyze in; falls back to the carried context.\n * @returns True if the chord is borrowed.\n * @throws If no key is given and none is carried.\n */\n isBorrowed(key?: Key): boolean {\n return isBorrowedChord(this.#data, this.#resolveKey(key).scale);\n }\n\n /**\n * The origin of a non-diatonic chord (parallel mode or Neapolitan), or null.\n *\n * @param key Key to analyze in; falls back to the carried context.\n * @returns The borrowing source, or null.\n * @throws If no key is given and none is carried.\n */\n borrowedSource(key?: Key): BorrowedSource {\n return borrowedSource(this.#data, this.#resolveKey(key).scale);\n }\n\n /**\n * The chord rendered as a lead-sheet symbol (e.g. `'Cmaj7'`, `'F#m7'`, `'C/G'`).\n *\n * @param opts Set `flats: true` to spell the root/bass with flats.\n * @returns The chord symbol.\n */\n symbol(opts?: { flats?: boolean }): string {\n return formatChordSymbol(this.#data, opts);\n }\n\n /**\n * Realize the chord as one MIDI pitch per voice, ascending.\n *\n * A chord that carries a key passes it to the voicer, so the leading tone is\n * not doubled; an explicit `opts.key` overrides it.\n *\n * @param opts Voicing options; defaults to four SATB voices.\n * @returns MIDI pitches, ascending, one per voice.\n * @throws If no voicing fits the given ranges.\n */\n voice(opts?: VoicingOptions): number[] {\n const key = opts?.key ?? this.#key?.scale;\n return voiceChord(this.#data, key === undefined ? opts : { ...opts, key });\n }\n\n /**\n * Realize the chord as a single styled voicing (`close`, `drop2`, `drop3`,\n * `shell`, or `rootless`), optionally constraining the top voice.\n *\n * @param opts Styled-voicing options; defaults to a close-position voicing.\n * @returns MIDI pitches, ascending.\n */\n styledVoicing(opts?: StyledVoicingOptions): number[] {\n return voiceChordStyled(this.#data, opts);\n }\n\n /**\n * The negative-harmony mirror of the chord about the key's tonic–dominant\n * axis (major becomes minor and vice versa).\n *\n * @param key Key providing the reflection axis; falls back to the carried\n * context.\n * @returns The mirrored chord, keeping any key context.\n * @throws If no key is given and none is carried.\n */\n negativeHarmony(key?: Key): Chord {\n const resolved = this.#resolveKey(key);\n // Retain the key that anchored the reflection (explicit first, then carried)\n // so a later no-arg analysis method still has a key context.\n return new Chord(negativeHarmonyMirror(this.#data, resolved.scale), key ?? this.#key);\n }\n\n /**\n * The n-th inversion: a copy whose bass is the chord tone `n` steps above the\n * root in the interval template (`invert(1)` puts the third in the bass).\n * `n` wraps around the template length; negative values count backwards.\n *\n * `invert(0)` (and any `n` that wraps to it) is root position, so it carries\n * no slash bass and equals the original chord.\n *\n * @param n The inversion number.\n * @returns The inverted chord, keeping any key context.\n * @throws If the chord has no intervals.\n */\n invert(n: number): Chord {\n const data = copyChord(this.#given);\n const intervals = data.intervals;\n const length = intervals.length;\n if (length === 0) {\n throw new InvalidInputError('cannot invert a chord with no intervals');\n }\n const index = ((n % length) + length) % length;\n // The bass spelling follows from the root spelling in force at read time, so\n // it is derived rather than frozen in here.\n delete data.bassSpelling;\n if (index === 0) {\n delete data.bassPc;\n } else {\n data.bassPc = mod12(data.rootPc + (intervals[index] ?? 0));\n }\n return new Chord(data, this.#key);\n }\n\n /**\n * Transpose the chord by a number of semitones.\n *\n * The quality and interval template are carried over, so a chord that a\n * symbol round-trip could not express — a custom interval set, an inversion —\n * survives. A carried key moves with the chord, so the transposed chord keeps\n * the same degree and function inside the transposed key.\n *\n * @param semitones The signed semitone offset.\n * @returns The transposed chord, in the transposed key when one is carried.\n * @example\n * ```ts\n * import { Chord } from '@libraz/libcantus';\n * Chord.parse('C/G').transpose(2).symbol(); // 'D/A'\n * ```\n */\n transpose(semitones: number): Chord {\n const moved = transposeChord(this.#given, semitones);\n return new Chord(moved, this.#key?.transpose(semitones));\n }\n\n /**\n * The named scales that fit over this chord, best fit first, rooted on the\n * chord root.\n *\n * @returns The matching scales.\n */\n scales(): ChordScaleMatch[] {\n return chordScales(this.#data);\n }\n\n /**\n * The available tensions (usable non-chord, non-avoid scale tones) of a\n * scale over this chord.\n *\n * @param scaleName A named scale, rooted on the chord root.\n * @returns Tension pitch classes, ascending in [0, 11].\n * @throws If `scaleName` is not a built-in scale.\n */\n tensions(scaleName: ScaleNameInput): number[] {\n return availableTensions(this.#data, scaleName);\n }\n\n /**\n * The avoid notes (scale tones a semitone above a chord tone) of a scale\n * over this chord.\n *\n * @param scaleName A named scale, rooted on the chord root.\n * @returns Avoid-note pitch classes, ascending in [0, 11].\n * @throws If `scaleName` is not a built-in scale.\n */\n avoidNotes(scaleName: ScaleNameInput): number[] {\n return avoidNotes(this.#data, scaleName);\n }\n\n /**\n * Spell the chord tones with letter names, root first, in the key's spelling.\n *\n * A chord that already knows how its root is spelled — one from\n * `Chord.parse`, or `Chord.of` with a named root — can spell itself with no\n * key at all; a key is only needed to choose a spelling for a bare pitch\n * class.\n *\n * A slash bass outside the chord tones is appended, so the spelled notes\n * are the notes the chord sounds — the same set {@link Chord.pitchClasses}\n * reports.\n *\n * @param key Key providing the spelled tonic; falls back to the carried\n * context, then to the chord's own root spelling.\n * @returns Spelled octave-less notes in the chord's own (tertian) order,\n * with any foreign slash bass last.\n * @throws If no key is given, none is carried, and the chord has no root\n * spelling of its own.\n */\n spell(key?: Key): Note[] {\n const data = this.#data;\n const resolved = key ?? this.#key;\n let tones: NoteData[];\n if (resolved === undefined) {\n const root = data.rootSpelling;\n if (root === undefined) {\n throw new InvalidInputError(\n 'chord has no key context and no root spelling; pass a Key, attach one with withKey(), or build the chord from a symbol',\n );\n }\n tones = spellChordFromRoot(data, root);\n } else {\n tones = spellChord(data, resolved.tonic.data, resolved.scale);\n }\n const bassPc = data.bassPc;\n const bass = data.bassSpelling;\n if (\n bassPc !== undefined &&\n bass !== undefined &&\n !tones.some((tone) => mod12(noteToPitchClass(tone)) === mod12(bassPc))\n ) {\n tones = [...tones, { letter: bass.letter, alter: bass.alter }];\n }\n return tones.map((note) => new Note(note));\n }\n\n /**\n * Start a progression with this chord followed by others, carrying this\n * chord's key context (if any).\n *\n * @param others The chords following this one.\n * @returns The progression.\n */\n progressionTo(...others: Chord[]): Progression {\n return new Progression([this, ...others], this.#key);\n }\n\n /**\n * Whether another chord has the same root, quality, intervals, and bass.\n * Key context is not compared.\n *\n * @param other The chord to compare.\n * @returns True if the chord data is identical.\n */\n equals(other: Chord): boolean {\n const a = this.#data;\n const b = other.data;\n return (\n a.rootPc === b.rootPc &&\n a.quality === b.quality &&\n a.bassPc === b.bassPc &&\n a.intervals.length === b.intervals.length &&\n a.intervals.every((interval, i) => interval === b.intervals[i])\n );\n }\n\n /**\n * The plain chord data, for JSON serialization.\n *\n * @returns A copy of the underlying plain chord object.\n */\n toJSON(): ChordData {\n return this.data;\n }\n\n /**\n * The chord symbol, so a template literal or a log line reads as the chord.\n *\n * @returns The symbol, e.g. `'Cmaj7'`.\n */\n toString(): string {\n return this.symbol();\n }\n\n /** Resolve the key for an analysis method: explicit first, then carried. */\n #resolveKey(key?: Key): Key {\n const resolved = key ?? this.#key;\n if (resolved === undefined) {\n throw new InvalidInputError(\n 'chord has no key context; pass a Key or attach one with withKey()',\n );\n }\n return resolved;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,IAAM,gBAAgB;AAGtB,SAAS,cAAc,SAAqD;AAC1E,MAAI,YAAY,KAAK;AACnB,WAAO;AAAA,EACT;AACA,MAAI,YAAY,KAAK;AACnB,WAAO;AAAA,EACT;AACA,MAAI,YAAY,KAAK;AACnB,WAAO;AAAA,EACT;AACA,SAAO,QAAQ,WAAW,GAAG,IACxB,IAAI,IAAI,OAAO,QAAQ,SAAS,CAAC,CAAC,KAClC,IAAI,IAAI,OAAO,QAAQ,SAAS,CAAC,CAAC;AACzC;AAcO,IAAM,WAAN,MAAM,UAAS;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EAED,YAAY,aAAqB,SAA+B,WAAmB;AACzF,SAAK,UAAU;AACf,SAAK,WAAW;AAChB,SAAK,aAAa;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,OAAO,QAAQ,GAAS,GAAmB;AACzC,WAAO,EAAE,WAAW,CAAC;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,OAAO,GAAG,aAAqB,SAA+B,WAA6B;AACzF,UAAM,WAAW,kBAAkB,aAAa,OAAO;AACvD,QAAI,KAAK,IAAI,SAAS,MAAM,UAAU;AACpC,YAAM,IAAI;AAAA,QACR,GAAG,OAAO,GAAG,WAAW,UAAU,QAAQ,wBAAwB,SAAS;AAAA,MAC7E;AAAA,IACF;AACA,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WACE,EAAE,WAAW,EAAE,UACf,EAAE,YAAY,EAAE,WAChB,EAAE,WAAW,EAAE,UACf,EAAE,UAAU,WAAW,EAAE,UAAU,UACnC,EAAE,UAAU,MAAM,CAAC,UAAU,MAAM,aAAa,EAAE,UAAU,CAAC,CAAC;AAAA,EAElE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,SAAoB;AAClB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAmB;AACjB,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA;AAAA,EAGA,YAAY,KAAgB;AAC1B,UAAM,WAAW,OAAO,KAAK;AAC7B,QAAI,aAAa,QAAW;AAC1B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -1,30 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunkFNDWXRRIcjs = require('./chunk-FNDWXRRI.cjs');
4
-
5
- // src/theory/harmony/index.ts
6
- function roleOf(pitch, chord, chordId = 0) {
7
- const interval = ((Math.trunc(pitch) - chord.rootPc) % 12 + 12) % 12;
8
- const tones = new Set(chord.intervals.map((i) => (i % 12 + 12) % 12));
9
- const hasThird = tones.has(3) || tones.has(4);
10
- const isSuspendedTone = !hasThird && (interval === 5 && tones.has(5) || interval === 2 && tones.has(2));
11
- const chordRole = _chunkFNDWXRRIcjs.chordToneRole.call(void 0, pitch, chord);
12
- let role;
13
- let lock;
14
- if (isSuspendedTone) {
15
- role = "third";
16
- lock = "quality";
17
- } else if (chordRole !== null) {
18
- role = chordRole;
19
- lock = chordRole === "root" ? "identity" : chordRole === "third" ? "quality" : "voicing";
20
- } else {
21
- role = "tension";
22
- lock = "voicing";
23
- }
24
- return { role, lock, belongsToChordId: chordId };
25
- }
26
-
27
-
28
-
29
- exports.roleOf = roleOf;
30
- //# sourceMappingURL=chunk-FCANXBAT.cjs.map
@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AAY,SAAA;AAAA,EACjF,EAAA,KAAO;AACL,IAAA,KAAA,EAAO,SAAA;AACP,IAAA,KAAA,EAAO,SAAA;AAAA,EACT;AACA,EAAA,OAAO,EAAE,IAAA,EAAM,IAAA,EAAM,gBAAA,EAAkB,QAAQ,CAAA;AACjD;ADtDA;AACA;AACE;AACF,wBAAC","file":"/home/runner/work/libcantus/libcantus/dist/chunk-FCANXBAT.cjs","sourcesContent":[null,"import { type Chord, type ChordToneRole, chordToneRole } from '../chord/index.js';\n\n/**\n * Harmonic role a pitch plays within a chord.\n *\n * @category Functional Harmony\n */\nexport type HarmonyRole = ChordToneRole | 'tension' | 'doubling';\n\n/**\n * How firmly a pitch is locked to the chord's identity.\n *\n * - `identity`: moving it produces a different chord (the root).\n * - `quality`: moving it flips the chord quality (the third).\n * - `voicing`: it can move freely without changing chord identity or quality.\n *\n * @category Functional Harmony\n */\nexport type LockLevel = 'identity' | 'quality' | 'voicing';\n\n/**\n * A pitch's role, lock level, and owning chord.\n *\n * @category Functional Harmony\n */\nexport type VoicedRole = {\n role: HarmonyRole;\n lock: LockLevel;\n belongsToChordId: number;\n};\n\n/**\n * Classify a pitch's harmonic role and lock level within a chord.\n *\n * The role comes from the pitch's interval class above the chord root, read\n * against the chord's own template: root (0), third (3/4), fifth (6/7/8),\n * sixth or seventh (9/10/11). Every pitch the template does not claim is\n * `'tension'` — including one that is simply foreign to the chord, which this\n * single-pitch query cannot tell from a colour tone. The root locks the chord\n * identity, the third locks its quality, and everything else is free voicing.\n * In a suspended chord (a chord whose intervals include a 4th (5) or 2nd (2)\n * but no third), the suspended tone takes the third's place as the\n * quality-defining tone and is locked to `quality`, since moving it changes the\n * chord. Detecting an octave doubling requires the surrounding voicing, which\n * this query does not carry, so `'doubling'` is part of the type — the shared\n * vocabulary of harmonic roles — but is never returned here.\n *\n * @param pitch MIDI pitch or bare pitch class.\n * @param chord The chord providing the root reference.\n * @param chordId Identifier stored on the result (defaults to 0).\n * @returns The pitch's role, lock level, and owning chord id.\n * @example\n * ```ts\n * import { roleOf, makeChord } from '@libraz/libcantus';\n * roleOf(64, makeChord(0, 'maj')); // E over C major\n * // { role: 'third', lock: 'quality', belongsToChordId: 0 }\n * ```\n * @category Functional Harmony\n */\nexport function roleOf(pitch: number, chord: Chord, chordId = 0): VoicedRole {\n const interval = (((Math.trunc(pitch) - chord.rootPc) % 12) + 12) % 12;\n const tones = new Set(chord.intervals.map((i) => ((i % 12) + 12) % 12));\n const hasThird = tones.has(3) || tones.has(4);\n const isSuspendedTone =\n !hasThird && ((interval === 5 && tones.has(5)) || (interval === 2 && tones.has(2)));\n const chordRole = chordToneRole(pitch, chord);\n let role: HarmonyRole;\n let lock: LockLevel;\n if (isSuspendedTone) {\n role = 'third'; // suspended tone occupies the third's quality-defining slot\n lock = 'quality';\n } else if (chordRole !== null) {\n role = chordRole;\n lock = chordRole === 'root' ? 'identity' : chordRole === 'third' ? 'quality' : 'voicing';\n } else {\n role = 'tension';\n lock = 'voicing';\n }\n return { role, lock, belongsToChordId: chordId };\n}\n"]}