@libraz/libcantus 1.1.0 → 1.3.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 (103) hide show
  1. package/README.md +4 -0
  2. package/README_ja.md +4 -0
  3. package/dist/analyze/index.cjs +31 -7
  4. package/dist/analyze/index.cjs.map +1 -1
  5. package/dist/analyze/index.d.cts +155 -9
  6. package/dist/analyze/index.d.ts +155 -9
  7. package/dist/analyze/index.js +37 -13
  8. package/dist/{chunk-TT6PKMPR.cjs → chunk-35NBV2FT.cjs} +16 -16
  9. package/dist/{chunk-TT6PKMPR.cjs.map → chunk-35NBV2FT.cjs.map} +1 -1
  10. package/dist/{chunk-YPB3A3EY.cjs → chunk-3R3QVKY5.cjs} +314 -285
  11. package/dist/chunk-3R3QVKY5.cjs.map +1 -0
  12. package/dist/{chunk-GDKE6RQW.cjs → chunk-4R2LWV7E.cjs} +691 -413
  13. package/dist/chunk-4R2LWV7E.cjs.map +1 -0
  14. package/dist/{chunk-RVS4G4MR.cjs → chunk-76ZBTRG2.cjs} +198 -198
  15. package/dist/{chunk-RVS4G4MR.cjs.map → chunk-76ZBTRG2.cjs.map} +1 -1
  16. package/dist/{chunk-X6RJAHII.js → chunk-7KG3RTYS.js} +2 -2
  17. package/dist/{chunk-PQL7E5F6.js → chunk-AGOVW7U6.js} +1 -1
  18. package/dist/{chunk-PQL7E5F6.js.map → chunk-AGOVW7U6.js.map} +1 -1
  19. package/dist/{chunk-5KW7DNCJ.cjs → chunk-B2PW6EHN.cjs} +2423 -453
  20. package/dist/chunk-B2PW6EHN.cjs.map +1 -0
  21. package/dist/{chunk-J772DL3B.cjs → chunk-CGBADIO5.cjs} +53 -53
  22. package/dist/{chunk-J772DL3B.cjs.map → chunk-CGBADIO5.cjs.map} +1 -1
  23. package/dist/{chunk-R5VUXQMP.js → chunk-CPMB7P75.js} +1978 -8
  24. package/dist/chunk-CPMB7P75.js.map +1 -0
  25. package/dist/{chunk-VLE5R7PF.js → chunk-GNVN4PPJ.js} +1874 -8
  26. package/dist/chunk-GNVN4PPJ.js.map +1 -0
  27. package/dist/{chunk-Q6R3QAZD.cjs → chunk-IFZDWIKM.cjs} +2199 -333
  28. package/dist/chunk-IFZDWIKM.cjs.map +1 -0
  29. package/dist/{chunk-DKICR7AN.js → chunk-IPEF6NWB.js} +296 -18
  30. package/dist/chunk-IPEF6NWB.js.map +1 -0
  31. package/dist/{chunk-AWEMD747.js → chunk-M5RYMAFI.js} +3 -3
  32. package/dist/{chunk-HSY2VQXZ.js → chunk-MLBPXA4Z.js} +330 -728
  33. package/dist/chunk-MLBPXA4Z.js.map +1 -0
  34. package/dist/{chunk-H66ARFU5.js → chunk-NB25P3EH.js} +3 -3
  35. package/dist/{chunk-5JJ6EHEZ.cjs → chunk-NM7UAMC3.cjs} +62 -62
  36. package/dist/{chunk-5JJ6EHEZ.cjs.map → chunk-NM7UAMC3.cjs.map} +1 -1
  37. package/dist/{chunk-R7B5N2JK.cjs → chunk-PM4XJE2Y.cjs} +47 -47
  38. package/dist/{chunk-R7B5N2JK.cjs.map → chunk-PM4XJE2Y.cjs.map} +1 -1
  39. package/dist/{chunk-7GOKQJTQ.js → chunk-PUKJP2Z5.js} +2 -2
  40. package/dist/{chunk-QCXYKSZS.cjs → chunk-PWC4CRWT.cjs} +19 -19
  41. package/dist/{chunk-QCXYKSZS.cjs.map → chunk-PWC4CRWT.cjs.map} +1 -1
  42. package/dist/{chunk-FPBZFNCD.js → chunk-RFIBF2RR.js} +47 -18
  43. package/dist/{chunk-FPBZFNCD.js.map → chunk-RFIBF2RR.js.map} +1 -1
  44. package/dist/{chunk-XKSO2V5I.cjs → chunk-S5BKZZGM.cjs} +1 -1
  45. package/dist/{chunk-XKSO2V5I.cjs.map → chunk-S5BKZZGM.cjs.map} +1 -1
  46. package/dist/{chunk-HOHFYGKW.js → chunk-UMWZ4ZET.js} +2 -2
  47. package/dist/{chunk-XVMJO3QF.cjs → chunk-YFA7X2F6.cjs} +489 -887
  48. package/dist/chunk-YFA7X2F6.cjs.map +1 -0
  49. package/dist/{chunk-57WB2EDF.js → chunk-ZBUROTJQ.js} +3 -3
  50. package/dist/{coerce-wwdELNYS.d.ts → coerce-DP0vYu-x.d.ts} +77 -1
  51. package/dist/{coerce-CJlgULrQ.d.cts → coerce-DRERzdve.d.cts} +77 -1
  52. package/dist/core/index.cjs +5 -5
  53. package/dist/core/index.d.cts +2 -2
  54. package/dist/core/index.d.ts +2 -2
  55. package/dist/core/index.js +4 -4
  56. package/dist/generate/index.cjs +20 -8
  57. package/dist/generate/index.cjs.map +1 -1
  58. package/dist/generate/index.d.cts +87 -9
  59. package/dist/generate/index.d.ts +87 -9
  60. package/dist/generate/index.js +19 -7
  61. package/dist/{index-BaoKVVhE.d.cts → index-B9QLziDe.d.cts} +2 -2
  62. package/dist/{index-CnHQgqNh.d.ts → index-BHIUyjhZ.d.ts} +2 -2
  63. package/dist/{index-CBCP84rv.d.cts → index-BL5N2Oyz.d.cts} +1 -1
  64. package/dist/{index-D_hzxD8w.d.cts → index-BMweUlm5.d.cts} +3 -0
  65. package/dist/{index-Ci3xyows.d.ts → index-CL4b4gUQ.d.ts} +3 -0
  66. package/dist/{index-BzLNkmA7.d.cts → index-CY-3NVfy.d.cts} +486 -5
  67. package/dist/{index-CnIdP4EZ.d.ts → index-Dw2DP7vm.d.ts} +1 -1
  68. package/dist/{index-DpC-mDlV.d.ts → index-zaZdmnU4.d.ts} +486 -5
  69. package/dist/index.cjs +49 -13
  70. package/dist/index.cjs.map +1 -1
  71. package/dist/index.d.cts +10 -10
  72. package/dist/index.d.ts +10 -10
  73. package/dist/index.js +55 -19
  74. package/dist/{masks-O73Rhj5d.d.ts → masks-Cc7-MzzY.d.ts} +1 -1
  75. package/dist/{masks-C8TWLFIi.d.cts → masks-pADfTOiD.d.cts} +1 -1
  76. package/dist/model/index.cjs +12 -12
  77. package/dist/model/index.d.cts +213 -16
  78. package/dist/model/index.d.ts +213 -16
  79. package/dist/model/index.js +11 -11
  80. package/dist/{index-DTsKaPaC.d.cts → profile-CQMEqdH9.d.cts} +88 -601
  81. package/dist/{index-BUtIf2go.d.ts → profile-DLdlIpS9.d.ts} +88 -601
  82. package/dist/theory/index.cjs +5 -5
  83. package/dist/theory/index.d.cts +7 -7
  84. package/dist/theory/index.d.ts +7 -7
  85. package/dist/theory/index.js +4 -4
  86. package/dist/{index-BpWOhkkE.d.ts → types-D-XgxGvp.d.cts} +1170 -14
  87. package/dist/{index-B3WCj_Hm.d.cts → types-Dh7C064C.d.ts} +1170 -14
  88. package/package.json +6 -5
  89. package/dist/chunk-5KW7DNCJ.cjs.map +0 -1
  90. package/dist/chunk-DKICR7AN.js.map +0 -1
  91. package/dist/chunk-GDKE6RQW.cjs.map +0 -1
  92. package/dist/chunk-HSY2VQXZ.js.map +0 -1
  93. package/dist/chunk-Q6R3QAZD.cjs.map +0 -1
  94. package/dist/chunk-R5VUXQMP.js.map +0 -1
  95. package/dist/chunk-VLE5R7PF.js.map +0 -1
  96. package/dist/chunk-XVMJO3QF.cjs.map +0 -1
  97. package/dist/chunk-YPB3A3EY.cjs.map +0 -1
  98. /package/dist/{chunk-X6RJAHII.js.map → chunk-7KG3RTYS.js.map} +0 -0
  99. /package/dist/{chunk-AWEMD747.js.map → chunk-M5RYMAFI.js.map} +0 -0
  100. /package/dist/{chunk-H66ARFU5.js.map → chunk-NB25P3EH.js.map} +0 -0
  101. /package/dist/{chunk-7GOKQJTQ.js.map → chunk-PUKJP2Z5.js.map} +0 -0
  102. /package/dist/{chunk-HOHFYGKW.js.map → chunk-UMWZ4ZET.js.map} +0 -0
  103. /package/dist/{chunk-57WB2EDF.js.map → chunk-ZBUROTJQ.js.map} +0 -0
@@ -1,6 +1,6 @@
1
- import { c as ChordLike, K as KeyLike, i as ChordToneRole, q as SpelledKeyLike, b as Chord, n as ResolvedKey, j as KeyRelation, e as ChordSegment, V as VoiceSnapshot, g as ChordSpan } from './coerce-CJlgULrQ.cjs';
2
- import { b as MeterLike } from './index-D_hzxD8w.cjs';
3
- import { h as NoteEvent, e as KeyScale } from './index-Cy15oTvh.cjs';
1
+ import { b as MeterLike, T as TimeSignature, c as MeterMap } from './index-CL4b4gUQ.js';
2
+ import { c as ChordLike, K as KeyLike, i as ChordToneRole, r as SpelledKeyLike, b as Chord, n as ResolvedKey, j as KeyRelation, e as ChordSegment, V as VoiceSnapshot, g as ChordSpan } from './coerce-DP0vYu-x.js';
3
+ import { h as NoteEvent, e as KeyScale, S as SpelledInterval } from './index-Cy15oTvh.js';
4
4
 
5
5
  /**
6
6
  * The vocabulary the analyze layer explains itself in.
@@ -119,21 +119,31 @@ declare function borrowedSource(chord: ChordLike, key: KeyLike): BorrowedSource;
119
119
  * spelled key signature.
120
120
  */
121
121
 
122
+ /**
123
+ * The named cadence types {@link detectCadence} classifies a chord pair as.
124
+ *
125
+ * @category Functional Harmony
126
+ */
127
+ declare const CADENCE_TYPES: readonly ["authentic", "plagal", "half", "deceptive", "phrygian", "modal"];
128
+ /**
129
+ * The cadence a chord pair forms.
130
+ *
131
+ * `'phrygian'` and `'modal'` are the two named species: the first is a
132
+ * specific half cadence and is reported in place of `'half'`, the second is
133
+ * the bVII-to-I arrival that no common-practice type covers. Code counting
134
+ * half cadences has to count `'phrygian'` alongside `'half'`.
135
+ *
136
+ * @category Functional Harmony
137
+ */
138
+ type CadenceType = (typeof CADENCE_TYPES)[number];
122
139
  /**
123
140
  * A recognized cadence, with the voice-leading facts its reading rests on.
124
141
  *
125
142
  * @category Functional Harmony
126
143
  */
127
144
  type CadenceResult = {
128
- /**
129
- * The cadence the chord pair forms, or null when it forms none.
130
- *
131
- * `'phrygian'` and `'modal'` are the two named species: the first is a
132
- * specific half cadence and is reported in place of `'half'`, the second is
133
- * the bVII-to-I arrival that no common-practice type covers. Code counting
134
- * half cadences has to count `'phrygian'` alongside `'half'`.
135
- */
136
- type: 'authentic' | 'plagal' | 'half' | 'deceptive' | 'phrygian' | 'modal' | null;
145
+ /** The cadence the chord pair forms, or null when it forms none. */
146
+ type: CadenceType | null;
137
147
  /**
138
148
  * How conclusive an authentic cadence is: `'perfect'` when it is a PAC,
139
149
  * `'imperfect'` when it is an IAC.
@@ -499,12 +509,18 @@ declare function explainRoman(chord: ChordLike, key: KeyLike, opts?: ExplainRoma
499
509
  * spelled key signature.
500
510
  */
501
511
 
512
+ /**
513
+ * The harmonic functions {@link functionOf} can assign.
514
+ *
515
+ * @category Functional Harmony
516
+ */
517
+ declare const HARMONIC_FUNCTIONS: readonly ["tonic", "subdominant", "dominant"];
502
518
  /**
503
519
  * The three broad harmonic functions of tonal music.
504
520
  *
505
521
  * @category Functional Harmony
506
522
  */
507
- type HarmonicFunction = 'tonic' | 'subdominant' | 'dominant';
523
+ type HarmonicFunction = (typeof HARMONIC_FUNCTIONS)[number];
508
524
  /**
509
525
  * Whether a key's scale has a minor third and no major third (a minor key).
510
526
  *
@@ -1417,4 +1433,1144 @@ type CadenceHit = {
1417
1433
  */
1418
1434
  declare function detectCadences(timeline: ChordTimeline, key: KeyContext): CadenceHit[];
1419
1435
 
1420
- export { type AnalyzeChordOptions as A, type BorrowedSource as B, type CadenceHit as C, type DetectCadenceOptions as D, type ExplainRomanOptions as E, isDiatonic as F, isMinorKey as G, type HarmonicFunction as H, type IdentifiedVoiceNote as I, keyTimelineFromNotes as J, type KeyContext as K, pivotChords as L, prevailingKeyOf as M, romanToChord as N, secondaryDominant as O, type PivotChord as P, secondaryDominantOf as Q, type RejectedCandidate as R, type SuspensionFigure as S, type TheoryLabel as T, toVoiceNotes as U, type VoiceNote as V, type AnalyzedNote as a, type CadenceResult as b, type ChordAnalysis as c, type ChordSegmentation as d, type ChordTimeline as e, type ChordTimelineOptions as f, type ChordTimelineResult as g, type ChordToRomanOptions as h, type KeyProfileName as i, type KeyProfilePair as j, type KeyRegion as k, type KeyTimelineOptions as l, type RomanExplanation as m, analyzeChord as n, analyzeVoice as o, assertChordTimeline as p, borrowedSource as q, chordTimelineFromChords as r, chordTimelineFromNotes as s, chordToRoman as t, detectCadence as u, detectCadences as v, detectModulations as w, explainRoman as x, functionOf as y, isBorrowedChord as z };
1436
+ /**
1437
+ * Sections: the largest unit this library reads, recovered from repetition.
1438
+ *
1439
+ * A section is found, not named. What the analysis can see is that a span of
1440
+ * music is a restatement of an earlier one, so the spans are labelled by order
1441
+ * of first appearance — A, B, C — and nothing more is claimed. Calling a
1442
+ * repeated span a chorus would be a guess dressed as a finding: repetition
1443
+ * alone cannot tell a chorus from a second verse, and the label a listener
1444
+ * would give depends on lyrics, arrangement and loudness that the notes do not
1445
+ * carry.
1446
+ */
1447
+
1448
+ /**
1449
+ * A span of music labelled by which earlier span it restates.
1450
+ *
1451
+ * @category Arrangement & Analysis
1452
+ */
1453
+ type FormSection = {
1454
+ /**
1455
+ * The section's letter, assigned in order of first appearance: the opening
1456
+ * material is A, the first material unlike it is B, and a later restatement
1457
+ * of A is A again. Past Z the letters double (AA, AB), the way spreadsheet
1458
+ * columns do. No functional name — verse, chorus, bridge — is ever inferred.
1459
+ */
1460
+ label: string;
1461
+ /** First beat of the section; negative when it opens with a pickup. */
1462
+ startBeat: number;
1463
+ /** End of the section, exclusive. */
1464
+ endBeat: number;
1465
+ /** The section's length in bars. */
1466
+ bars: number;
1467
+ /**
1468
+ * Index, in the returned array, of the first section carrying this label; the
1469
+ * section's own index when it is that first appearance.
1470
+ */
1471
+ firstOccurrence: number;
1472
+ /**
1473
+ * How alike this section and its first occurrence are, in [0, 1]; 1 on the
1474
+ * first occurrence itself. The mean over the units the section was merged
1475
+ * from, each scored against the unit it matched.
1476
+ */
1477
+ similarity: number;
1478
+ /** How the section came to carry its label. */
1479
+ rationale: string;
1480
+ };
1481
+ /**
1482
+ * Options for {@link sectionsFromNotes}.
1483
+ *
1484
+ * @category Arrangement & Analysis
1485
+ */
1486
+ type FormSectionOptions = {
1487
+ /**
1488
+ * A single time signature held across the whole span, as sugar for a
1489
+ * one-element `meters`; defaults to 4/4. Giving both is an input error.
1490
+ *
1491
+ * @defaultValue `4/4`
1492
+ */
1493
+ ts?: MeterLike;
1494
+ /**
1495
+ * The meter as it changes over the span, so a piece that changes metre is cut
1496
+ * at its own bar lines.
1497
+ *
1498
+ * @defaultValue 4/4 throughout
1499
+ */
1500
+ meters?: MeterLike;
1501
+ /**
1502
+ * Length of the unit spans are compared in, in bars; defaults to one hyperbar.
1503
+ *
1504
+ * Sections are found by comparing equal units and merging the neighbours that
1505
+ * match, so this is the resolution of the answer rather than the length of a
1506
+ * section: a section is any whole number of units long.
1507
+ *
1508
+ * @defaultValue the inferred hyperbar, in bars
1509
+ */
1510
+ unitBars?: number;
1511
+ /**
1512
+ * How alike two units must be before the later one is called a restatement of
1513
+ * the earlier, in [0, 1].
1514
+ *
1515
+ * @defaultValue `0.8`
1516
+ */
1517
+ threshold?: number;
1518
+ /**
1519
+ * End of the analysed span in beats; defaults to the end of the last note.
1520
+ *
1521
+ * @defaultValue the end of the last note
1522
+ */
1523
+ totalBeats?: number;
1524
+ /**
1525
+ * Upper bound on the work this call may do.
1526
+ *
1527
+ * @defaultValue {@link DEFAULT_GENERATION_BUDGET}
1528
+ */
1529
+ budget?: number;
1530
+ };
1531
+ /**
1532
+ * Recover a piece's sections from what it repeats.
1533
+ *
1534
+ * The span is cut into equal units of `unitBars` bars, each unit is compared
1535
+ * with every unit before it, and a unit alike enough to an earlier one takes
1536
+ * that unit's label. Neighbouring units carrying the same label are then merged,
1537
+ * so an eight-bar section built of two like four-bar units is reported as one
1538
+ * section rather than two.
1539
+ *
1540
+ * Likeness is measured on the melodic line and on the harmonic content
1541
+ * together — the same tune under different harmony is a variation, not a
1542
+ * restatement — and the labels are letters in order of first appearance.
1543
+ * Nothing beyond "this is a restatement of that" is asserted: see
1544
+ * {@link FormSection.label}.
1545
+ *
1546
+ * A pickup belongs to the section it leads into, so material before the first
1547
+ * bar is folded into the opening unit rather than made a section of its own.
1548
+ *
1549
+ * @param notes The piece's notes, in any order. Notes that never sound are
1550
+ * dropped.
1551
+ * @param opts Analysis options; see {@link FormSectionOptions}.
1552
+ * @returns The sections, in time order.
1553
+ * @example
1554
+ * ```ts
1555
+ * import { sectionsFromNotes } from '@libraz/libcantus';
1556
+ * const bar = (pitch: number, at: number) => ({ pitch, startBeat: at, durationBeat: 4 });
1557
+ * const notes = [bar(60, 0), bar(64, 4), bar(67, 8), bar(60, 12)];
1558
+ * sectionsFromNotes(notes, { unitBars: 2 }).map((section) => section.label);
1559
+ * ```
1560
+ * @category Arrangement & Analysis
1561
+ */
1562
+ declare function sectionsFromNotes(notes: readonly NoteEvent[], opts?: FormSectionOptions): FormSection[];
1563
+
1564
+ /**
1565
+ * The recurring cells a melody is built from.
1566
+ *
1567
+ * A motif is the interval contour plus the rhythmic profile, so every statement
1568
+ * of it carries the same identity however far it has been transposed or however
1569
+ * wide its note values are written. What this module does is find them: every
1570
+ * window of the melody is reduced to that identity, windows that agree are
1571
+ * grouped, and a group stated often enough is a motif.
1572
+ */
1573
+
1574
+ /**
1575
+ * One statement of a motif, addressed in the melody it was found in.
1576
+ *
1577
+ * The notes themselves are not repeated here: a statement is the motif's notes
1578
+ * moved by `transpose` and stretched by `timeRatio`, and `noteIndex` addresses
1579
+ * the original array for a caller that wants them exactly.
1580
+ *
1581
+ * @category Arrangement & Analysis
1582
+ */
1583
+ type MotifOccurrence = {
1584
+ /**
1585
+ * Index of the statement's first note among the sounding notes of the melody,
1586
+ * in time order. Notes that never sound are dropped before the search, so this
1587
+ * is not an index into the caller's array unless the caller's array has none.
1588
+ */
1589
+ noteIndex: number;
1590
+ /** Onset of the statement's first note. */
1591
+ startBeat: number;
1592
+ /** End of the statement's last note, exclusive. */
1593
+ endBeat: number;
1594
+ /** Semitones this statement stands above the motif's first statement. */
1595
+ transpose: number;
1596
+ /**
1597
+ * How much this statement is stretched against the motif's first: 2 for a
1598
+ * statement in doubled note values, 0.5 for one in halved values, 1 for one in
1599
+ * the same values.
1600
+ */
1601
+ timeRatio: number;
1602
+ };
1603
+ /**
1604
+ * A recurring melodic cell.
1605
+ *
1606
+ * Identity is the interval sequence plus the rhythmic profile, so every
1607
+ * statement of the motif carries the same `intervals` and `rhythm` however far
1608
+ * it has been transposed or however wide its note values are written. `notes`
1609
+ * holds one statement — the first — exactly as it sounds.
1610
+ *
1611
+ * @category Arrangement & Analysis
1612
+ */
1613
+ type MotifData = {
1614
+ /** The first statement, exactly as it sounds in the melody. */
1615
+ notes: NoteEvent[];
1616
+ /**
1617
+ * Semitones between consecutive notes. This is the transposition-invariant
1618
+ * identity of the cell: two statements a fifth apart share it.
1619
+ */
1620
+ intervals: number[];
1621
+ /**
1622
+ * Onset-to-onset gaps as multiples of the first gap, so an even cell reads
1623
+ * `[1, 1, 1]` whatever the tempo or note values it is written in.
1624
+ */
1625
+ rhythm: number[];
1626
+ /** Every statement found, in time order; the first is `notes`. */
1627
+ occurrences: MotifOccurrence[];
1628
+ /** Why this counts as a motif. */
1629
+ rationale: string;
1630
+ };
1631
+ /**
1632
+ * Options controlling {@link extractMotifs}.
1633
+ *
1634
+ * @category Arrangement & Analysis
1635
+ */
1636
+ type ExtractMotifsOptions = {
1637
+ /**
1638
+ * Shortest cell to report, in notes.
1639
+ *
1640
+ * @defaultValue 3
1641
+ */
1642
+ minNotes?: number;
1643
+ /**
1644
+ * Longest cell to report, in notes.
1645
+ *
1646
+ * @defaultValue 8
1647
+ */
1648
+ maxNotes?: number;
1649
+ /**
1650
+ * How many statements a cell needs before it is reported.
1651
+ *
1652
+ * @defaultValue 2
1653
+ */
1654
+ minOccurrences?: number;
1655
+ /**
1656
+ * Upper bound on the work this call may do.
1657
+ *
1658
+ * @defaultValue {@link DEFAULT_GENERATION_BUDGET}
1659
+ */
1660
+ budget?: number;
1661
+ };
1662
+ /**
1663
+ * Find the cells a melody keeps coming back to.
1664
+ *
1665
+ * Every window of `minNotes` to `maxNotes` consecutive notes is reduced to its
1666
+ * interval sequence and its rhythmic profile, and windows sharing both are
1667
+ * statements of one motif — so a restatement a fifth higher, or one written in
1668
+ * doubled note values, is found as the same cell rather than as a new one.
1669
+ * Overlapping statements of a repetitive figure are counted once, and a cell
1670
+ * whose statements all sit inside the statements of a longer cell that recurs at
1671
+ * least as often is dropped, so the answer names the longest thing that recurs
1672
+ * rather than every fragment of it.
1673
+ *
1674
+ * The melody is expected to be monophonic, as {@link analyzeVoice} expects a
1675
+ * voice to be; split polyphonic material into lines first. Notes struck together
1676
+ * are read as one event, the highest of them standing for it, so a chord is
1677
+ * reduced to its top voice rather than read as a line of its own. Onsets are
1678
+ * expected to be quantised, since two statements must agree on their rhythm to
1679
+ * be recognised as one motif.
1680
+ *
1681
+ * @param notes The melody, in time order. Notes that never sound are dropped.
1682
+ * @param opts Cell-length bounds and the recurrence threshold; see
1683
+ * {@link ExtractMotifsOptions}.
1684
+ * @returns The motifs found, longest first, then by how often they recur, then
1685
+ * by where they first appear. Empty when nothing recurs.
1686
+ * @example
1687
+ * ```ts
1688
+ * import { extractMotifs } from '@libraz/libcantus';
1689
+ * const notes = [
1690
+ * { pitch: 60, startBeat: 0, durationBeat: 1 },
1691
+ * { pitch: 62, startBeat: 1, durationBeat: 1 },
1692
+ * { pitch: 64, startBeat: 2, durationBeat: 1 },
1693
+ * { pitch: 67, startBeat: 4, durationBeat: 1 },
1694
+ * { pitch: 69, startBeat: 5, durationBeat: 1 },
1695
+ * { pitch: 71, startBeat: 6, durationBeat: 1 },
1696
+ * ];
1697
+ * const motifs = extractMotifs(notes);
1698
+ * motifs[0]?.occurrences.map((o) => o.startBeat); // [0, 4]
1699
+ * ```
1700
+ * @category Arrangement & Analysis
1701
+ */
1702
+ declare function extractMotifs(notes: readonly NoteEvent[], opts?: ExtractMotifsOptions): MotifData[];
1703
+ /**
1704
+ * Read a run of notes as a single-statement motif.
1705
+ *
1706
+ * {@link extractMotifs} answers with motifs it found recurring; this is how a
1707
+ * caller names one it already has — a subject, an answer, a phrase lifted out of
1708
+ * a score — so that it can be handed to {@link relateMotifs}.
1709
+ *
1710
+ * The cell is expected to be monophonic, as {@link analyzeVoice} expects a voice
1711
+ * to be. Notes struck together are read as one event, the highest of them
1712
+ * standing for it, so a chord is reduced to its top voice rather than read as a
1713
+ * line of its own.
1714
+ *
1715
+ * @param notes The cell, in time order. Notes that never sound are dropped, and
1716
+ * notes sharing an onset are folded to their top voice.
1717
+ * @returns The motif, carrying exactly one occurrence.
1718
+ * @example
1719
+ * ```ts
1720
+ * import { motifFromNotes, relateMotifs } from '@libraz/libcantus';
1721
+ * const subject = motifFromNotes([
1722
+ * { pitch: 60, startBeat: 0, durationBeat: 1 },
1723
+ * { pitch: 62, startBeat: 1, durationBeat: 1 },
1724
+ * { pitch: 64, startBeat: 2, durationBeat: 1 },
1725
+ * ]);
1726
+ * const answer = motifFromNotes([
1727
+ * { pitch: 67, startBeat: 3, durationBeat: 1 },
1728
+ * { pitch: 69, startBeat: 4, durationBeat: 1 },
1729
+ * { pitch: 71, startBeat: 5, durationBeat: 1 },
1730
+ * ]);
1731
+ * relateMotifs(subject, answer)?.kind; // 'transposition'
1732
+ * ```
1733
+ * @category Arrangement & Analysis
1734
+ */
1735
+ declare function motifFromNotes(notes: readonly NoteEvent[]): MotifData;
1736
+
1737
+ /**
1738
+ * What every reading of a melody has to agree on first.
1739
+ *
1740
+ * A melody is compared, named and classified by three modules here, and all
1741
+ * three start from the same two questions: which notes sound, in what order,
1742
+ * and what the gaps between their onsets are. Answered separately they would
1743
+ * drift — one reading folding a chord to its top voice and another not — so
1744
+ * they are answered once, here.
1745
+ */
1746
+
1747
+ /**
1748
+ * Anything that can be read as a melodic line: a motif, or plain note events.
1749
+ *
1750
+ * @category Arrangement & Analysis
1751
+ */
1752
+ type MelodicPhrase = MotifData | readonly NoteEvent[];
1753
+
1754
+ /**
1755
+ * The shape of a line: which way it moves, and what that adds up to.
1756
+ *
1757
+ * A contour is the melody with its pitches forgotten — the sequence of ups and
1758
+ * downs alone — which is what lets a phrase be called an arch whatever key it
1759
+ * is in and whatever intervals it is built from.
1760
+ */
1761
+
1762
+ /**
1763
+ * Step direction between two consecutive notes.
1764
+ *
1765
+ * @category Arrangement & Analysis
1766
+ */
1767
+ type ContourDirection = 'up' | 'down' | 'same';
1768
+ /**
1769
+ * The overall shapes a line can be read as.
1770
+ *
1771
+ * @category Arrangement & Analysis
1772
+ */
1773
+ declare const MELODIC_CONTOUR_SHAPES: readonly ["arch", "ascending", "descending", "wave", "static"];
1774
+ /**
1775
+ * The overall shape of a line.
1776
+ *
1777
+ * The first four names are the vocabulary the motif generator's contours are
1778
+ * written in, and mean the same here. `'static'` is the shape a generator never
1779
+ * asks for and an analysis regularly meets: a line that does not move. A line
1780
+ * that dips and comes back — an arch upside down — reads as `'wave'`, since the
1781
+ * shared vocabulary has no name of its own for it.
1782
+ *
1783
+ * A wave has to turn more than once to be heard as one, so a cell the generator
1784
+ * writes for `'wave'` reads back as `'wave'` only from three bars up; the one-
1785
+ * and two-bar cells turn once and read as `'arch'`. The other three shapes come
1786
+ * back under their own name at every length.
1787
+ *
1788
+ * @category Arrangement & Analysis
1789
+ */
1790
+ type MelodicContourShape = (typeof MELODIC_CONTOUR_SHAPES)[number];
1791
+ /**
1792
+ * The abstract shape of a line: its step directions and what they add up to.
1793
+ *
1794
+ * @category Arrangement & Analysis
1795
+ */
1796
+ type MelodicContour = {
1797
+ /** One direction per adjacent pair of notes, in time order. */
1798
+ directions: ContourDirection[];
1799
+ /** What the directions add up to. */
1800
+ shape: MelodicContourShape;
1801
+ /** Index of the highest note; ties keep the earliest, and -1 for a line with no notes. */
1802
+ peakIndex: number;
1803
+ /** Index of the lowest note; ties keep the earliest, and -1 for a line with no notes. */
1804
+ troughIndex: number;
1805
+ /** Semitone distance from the lowest note to the highest. */
1806
+ range: number;
1807
+ /** Why the line was given that shape. */
1808
+ rationale: string;
1809
+ };
1810
+ /**
1811
+ * Read the shape of a line.
1812
+ *
1813
+ * The step directions are the literal answer; the shape is what they add up to.
1814
+ * A line is called ascending or descending when most of its motion runs one way,
1815
+ * not only when every step does — a climb with one dip in it is still heard as a
1816
+ * climb — and an arch when it rises to an interior peak and comes back down.
1817
+ * Anything that keeps changing direction is a wave, and a line that does not move
1818
+ * is static.
1819
+ *
1820
+ * The line is expected to be monophonic, as {@link analyzeVoice} expects a voice
1821
+ * to be; split polyphonic material into lines first. Notes struck together are
1822
+ * read as one event, the highest of them standing for it — a chord and the note
1823
+ * after it trace one step, not a climb through the chord — so a piano part read
1824
+ * whole answers for its top voice rather than for a line no one plays.
1825
+ *
1826
+ * @param notes The line: a motif, or plain note events. Notes that never sound
1827
+ * are dropped, and notes sharing an onset are folded to their top voice.
1828
+ * @returns The directions, the shape, the peak and trough, and a rationale. A
1829
+ * line with no sounding notes is static with a range of 0, and its peak and
1830
+ * trough are -1: there is no note for them to point at.
1831
+ * @example
1832
+ * ```ts
1833
+ * import { melodicContour } from '@libraz/libcantus';
1834
+ * const notes = [
1835
+ * { pitch: 60, startBeat: 0, durationBeat: 1 },
1836
+ * { pitch: 64, startBeat: 1, durationBeat: 1 },
1837
+ * { pitch: 60, startBeat: 2, durationBeat: 1 },
1838
+ * ];
1839
+ * melodicContour(notes).shape; // 'arch'
1840
+ * ```
1841
+ * @category Arrangement & Analysis
1842
+ */
1843
+ declare function melodicContour(notes: MelodicPhrase): MelodicContour;
1844
+
1845
+ /**
1846
+ * The transformation between two statements of a motif, named.
1847
+ *
1848
+ * Two cells stand in a relation when one is the other put through a device the
1849
+ * repertoire has a name for — repetition, transposition, inversion, retrograde,
1850
+ * augmentation — and naming it is what turns a pair of similar phrases into an
1851
+ * account of how the second was made from the first.
1852
+ */
1853
+
1854
+ /**
1855
+ * The named transformations {@link relateMotifs} can report between two motif
1856
+ * statements.
1857
+ *
1858
+ * @category Arrangement & Analysis
1859
+ */
1860
+ declare const MOTIF_RELATION_KINDS: readonly ["repetition", "transposition", "tonalTransposition", "inversion", "retrograde", "retrogradeInversion", "augmentation", "diminution"];
1861
+ /**
1862
+ * How one statement of a motif stands to another.
1863
+ *
1864
+ * `'transposition'` is the literal one — every interval preserved, which is what
1865
+ * makes a sequence built on it a *real* sequence. `'tonalTransposition'` shifts
1866
+ * by scale degrees instead and lets the key resize the intervals, which is what
1867
+ * makes a sequence built on it a *tonal* sequence; the two are different devices
1868
+ * and are never reported as one. `'augmentation'` and `'diminution'` name the
1869
+ * relation only when the pitches are untouched, so an inversion in doubled note
1870
+ * values reads as `'inversion'` with a `timeRatio` of 2 rather than losing the
1871
+ * inversion to the stretch.
1872
+ *
1873
+ * @category Arrangement & Analysis
1874
+ */
1875
+ type MotifRelationKind = (typeof MOTIF_RELATION_KINDS)[number];
1876
+ /**
1877
+ * The transformation that turns one motif into another.
1878
+ *
1879
+ * @category Arrangement & Analysis
1880
+ */
1881
+ type MotifRelation = {
1882
+ /** The named transformation. */
1883
+ kind: MotifRelationKind;
1884
+ /**
1885
+ * Whether the second statement begins where the first ends, which is what
1886
+ * separates a sequence from a restatement elsewhere in the piece: a
1887
+ * `'transposition'` that is one is a real sequence, a `'tonalTransposition'`
1888
+ * that is one is a tonal sequence.
1889
+ */
1890
+ sequence: boolean;
1891
+ /** Semitones from the first statement's first note to the second's. */
1892
+ semitones: number;
1893
+ /** The same distance named as a spelled interval. */
1894
+ interval: SpelledInterval;
1895
+ /** Scale degrees the second statement stands above the first, when tonal. */
1896
+ degrees?: number;
1897
+ /**
1898
+ * How much the second statement is stretched against the first: 2 for doubled
1899
+ * note values, 0.5 for halved, 1 for unchanged.
1900
+ *
1901
+ * Measured in the direction the relation names, so a retrograde that kept
1902
+ * every note value reports 1 however uneven those values are: it is compared
1903
+ * against the model played backwards, not against the model as written.
1904
+ */
1905
+ timeRatio: number;
1906
+ /** Why the pair was given that name. */
1907
+ rationale: string;
1908
+ };
1909
+ /**
1910
+ * The part of a {@link MotifRelation} that names the transformation itself,
1911
+ * without the rationale prose that explains it.
1912
+ *
1913
+ * @category Arrangement & Analysis
1914
+ */
1915
+ type MotifRelationSummary = Pick<MotifRelation, 'kind' | 'sequence' | 'semitones' | 'degrees' | 'timeRatio'>;
1916
+ /**
1917
+ * Name how two statements of a motif relate.
1918
+ *
1919
+ * The two are compared as shapes, not as pitches: the interval sequences say
1920
+ * which transformations could name the pair and the onset gaps say which of
1921
+ * them does, so a statement a fourth higher in doubled note values is
1922
+ * recognised for what it is, and a cell that reads as both an inversion and a
1923
+ * retrograde is named by the way its rhythm runs rather than by which name came
1924
+ * to hand first. A pair whose rhythms correspond in neither direction — the same
1925
+ * way round for a repetition or a transposition, the model played backwards for
1926
+ * a retrograde, note values and all — is not a transformation of the motif but a
1927
+ * different figure, and answers null; {@link melodicSimilarity} is what scores
1928
+ * those.
1929
+ *
1930
+ * With a `key` in hand the search also asks whether the second statement is the
1931
+ * first moved by scale degrees rather than by semitones. That is the tonal
1932
+ * answer to the real one, and the two are kept apart: a real transposition keeps
1933
+ * every interval literally, a tonal one lets the key resize them, so a subject
1934
+ * answered a step higher reads as `'transposition'` when its major second stays
1935
+ * major and as `'tonalTransposition'` when the scale turns it minor.
1936
+ *
1937
+ * @param a The model statement.
1938
+ * @param b The statement to name against it.
1939
+ * @param keyLike Key context for the tonal reading. Without one that reading is
1940
+ * unavailable, and a statement holding only diatonically is left unnamed
1941
+ * unless its interval pattern also fits a member of the retrograde family, in
1942
+ * which case it is named there: a triad restated a degree higher swaps two
1943
+ * adjacent interval sizes, which is what a retrograde inversion does to it as
1944
+ * well, and equal note values read the same way round in both directions, so
1945
+ * the notes alone cannot separate the two. A key separates them.
1946
+ * @returns The relation, or null when the two stand in none.
1947
+ * @example
1948
+ * ```ts
1949
+ * import { majorKey, motifFromNotes, relateMotifs } from '@libraz/libcantus';
1950
+ * const model = motifFromNotes([
1951
+ * { pitch: 60, startBeat: 0, durationBeat: 1 },
1952
+ * { pitch: 62, startBeat: 1, durationBeat: 1 },
1953
+ * { pitch: 64, startBeat: 2, durationBeat: 1 },
1954
+ * ]);
1955
+ * const answer = motifFromNotes([
1956
+ * { pitch: 62, startBeat: 3, durationBeat: 1 },
1957
+ * { pitch: 64, startBeat: 4, durationBeat: 1 },
1958
+ * { pitch: 65, startBeat: 5, durationBeat: 1 },
1959
+ * ]);
1960
+ * relateMotifs(model, answer, majorKey(0))?.kind; // 'tonalTransposition'
1961
+ * ```
1962
+ * @category Arrangement & Analysis
1963
+ */
1964
+ declare function relateMotifs(a: MotifData, b: MotifData, keyLike?: SpelledKeyLike): MotifRelation | null;
1965
+
1966
+ /**
1967
+ * How the statements of a melody's motifs derive from one another.
1968
+ *
1969
+ * {@link extractMotifs} groups statements into motifs; this reads across that
1970
+ * grouping and asks, for every statement after the first, which earlier
1971
+ * statement it most plausibly grew out of. The answer is a forest rather than a
1972
+ * graph proper — every statement has at most one parent — because a derivation
1973
+ * only ever has one source, however many statements it could be heard against.
1974
+ */
1975
+
1976
+ /**
1977
+ * Options controlling {@link motifGraph}.
1978
+ *
1979
+ * @category Arrangement & Analysis
1980
+ */
1981
+ type MotifGraphOptions = {
1982
+ /** Key context for the tonal reading `relateMotifs` can offer. */
1983
+ key?: SpelledKeyLike;
1984
+ /**
1985
+ * Lower bound on `melodicSimilarity` for a pair with no named transformation
1986
+ * to still be drawn as a variation.
1987
+ *
1988
+ * @defaultValue 0.75
1989
+ */
1990
+ variationThreshold?: number;
1991
+ /**
1992
+ * Upper bound on the work this call may do.
1993
+ *
1994
+ * @defaultValue {@link DEFAULT_GENERATION_BUDGET}
1995
+ */
1996
+ budget?: number;
1997
+ };
1998
+ /**
1999
+ * One statement of a motif, as a node of {@link MotifGraph}.
2000
+ *
2001
+ * @category Arrangement & Analysis
2002
+ */
2003
+ type MotifGraphNode = {
2004
+ /** Index into the `motifs` array this statement belongs to. */
2005
+ motif: number;
2006
+ /** Index into that motif's `occurrences`. */
2007
+ occurrence: number;
2008
+ /** Onset of the statement's first note. */
2009
+ startBeat: number;
2010
+ /** End of the statement's last note, exclusive. */
2011
+ endBeat: number;
2012
+ };
2013
+ /**
2014
+ * The derivation drawn from one statement to a later one.
2015
+ *
2016
+ * @category Arrangement & Analysis
2017
+ */
2018
+ type MotifGraphEdge = {
2019
+ /** Index of the preceding node this statement derives from. */
2020
+ from: number;
2021
+ /** Index of the derived node. */
2022
+ to: number;
2023
+ /** The named transformation, or null when none explains the pair. */
2024
+ relation: MotifRelationSummary | null;
2025
+ /** `melodicSimilarity` between the two statements. */
2026
+ similarity: number;
2027
+ };
2028
+ /**
2029
+ * How a melody's motif statements derive from one another.
2030
+ *
2031
+ * @category Arrangement & Analysis
2032
+ */
2033
+ type MotifGraph = {
2034
+ /** Every statement of every motif, ordered by `startBeat` then by `motif`. */
2035
+ nodes: MotifGraphNode[];
2036
+ /**
2037
+ * The derivation drawn to each node from an earlier one, ordered by `to`.
2038
+ * Every node has at most one edge into it, so the edges describe a forest.
2039
+ */
2040
+ edges: MotifGraphEdge[];
2041
+ };
2042
+ /**
2043
+ * Read a melody's motif statements as a derivation forest.
2044
+ *
2045
+ * Every statement after the first is compared against every statement that
2046
+ * precedes it: the pair {@link relateMotifs} can name outranks any it cannot,
2047
+ * the closest-scoring precedent among equals outranks the rest, and a
2048
+ * statement whose best precedent is neither named nor close enough by
2049
+ * `melodicSimilarity` is a root — new material, not a derivation of what came
2050
+ * before it. The derivation traced this way explains a subject restated,
2051
+ * transposed, inverted, augmented, or loosely varied by what it grew out of,
2052
+ * and leaves a truly new idea unattached rather than forcing it onto whatever
2053
+ * came earliest.
2054
+ *
2055
+ * `motifs` is read against `line` rather than against its own prime
2056
+ * statements: an occurrence's notes can differ from the motif's first
2057
+ * statement in duration even where their intervals and onset gaps agree, and a
2058
+ * retrograde reading depends on that duration. So every occurrence is read
2059
+ * back off `line` and named fresh, occurrence to occurrence.
2060
+ *
2061
+ * @param line The melody `motifs` was extracted from. Notes that never sound
2062
+ * are dropped, exactly as {@link extractMotifs} drops them, so the two agree
2063
+ * on which note an occurrence's `noteIndex` addresses.
2064
+ * @param motifs The motifs to graph, as {@link extractMotifs} reports them.
2065
+ * @param opts Key context, the variation threshold, and a work budget; see
2066
+ * {@link MotifGraphOptions}.
2067
+ * @returns The statements as nodes, and the derivation drawn to each from an
2068
+ * earlier one.
2069
+ * @example
2070
+ * ```ts
2071
+ * import { extractMotifs, motifGraph } from '@libraz/libcantus';
2072
+ * const notes = [
2073
+ * { pitch: 60, startBeat: 0, durationBeat: 1 },
2074
+ * { pitch: 62, startBeat: 1, durationBeat: 1 },
2075
+ * { pitch: 64, startBeat: 2, durationBeat: 1 },
2076
+ * { pitch: 67, startBeat: 4, durationBeat: 1 },
2077
+ * { pitch: 69, startBeat: 5, durationBeat: 1 },
2078
+ * { pitch: 71, startBeat: 6, durationBeat: 1 },
2079
+ * ];
2080
+ * const graph = motifGraph(notes, extractMotifs(notes));
2081
+ * graph.edges[0]?.relation?.kind; // 'transposition'
2082
+ * ```
2083
+ * @category Arrangement & Analysis
2084
+ */
2085
+ declare function motifGraph(line: readonly NoteEvent[], motifs: readonly MotifData[], opts?: MotifGraphOptions): MotifGraph;
2086
+
2087
+ /**
2088
+ * Harmonic reduction: which chords carry the progression and which decorate it.
2089
+ *
2090
+ * `analyzeVoice` can say that a note is a passing tone; a timeline is flat, so
2091
+ * nothing could say the same of a chord. This is that answer one level up — the
2092
+ * middle chord of `Cmaj7 - C#dim7 - Dm7` is an embellishment, and the frame
2093
+ * under `I - IV - #ivo7 - V - I` is `I - IV - V - I`.
2094
+ *
2095
+ * **The position taken here.** What counts as structural is a theoretical
2096
+ * choice, not a fact, and this module makes the functional one: *a chord is
2097
+ * structural unless it is demonstrably an embellishment of its neighbours*. The
2098
+ * frame is what carries harmonic function in the prevailing key — the tonic, the
2099
+ * dominant, and the chords that cadence — so those are never reduced away; a
2100
+ * chord that tonicizes something other than the tonic is prolonging, not
2101
+ * framing, however dominant its sonority. Everything else keeps its place unless
2102
+ * its root traces one of two figures against the chords around it, the same two
2103
+ * figures {@link analyzeVoice} matches at the note level: a step through
2104
+ * (passing) and a step away and back (neighbor). Defaulting to structural, and
2105
+ * demoting only on evidence, is what keeps a reduction from quietly deleting
2106
+ * harmony it merely failed to recognize.
2107
+ *
2108
+ * The salience reading — that the frame is whatever lasts longest, regardless of
2109
+ * function — is the main alternative, and it is a live one for repertoire where
2110
+ * function is weak. {@link ReduceProgressionOptions.basis} switches to it: the
2111
+ * figures stay the same, only what protects a chord from them changes.
2112
+ *
2113
+ * Both readings are deterministic: the same timeline and key always reduce the
2114
+ * same way.
2115
+ */
2116
+
2117
+ /**
2118
+ * The places a chord can hold in a progression.
2119
+ *
2120
+ * @category Arrangement & Analysis
2121
+ */
2122
+ declare const REDUCTION_LEVELS: readonly ["structural", "passing", "neighbor"];
2123
+ /**
2124
+ * The place a chord holds in a progression.
2125
+ *
2126
+ * `'structural'` is the frame; `'passing'` and `'neighbor'` are the two
2127
+ * embellishing figures, spelled exactly as {@link TheoryLabel} spells them for
2128
+ * a note, so one legend covers both levels of analysis.
2129
+ *
2130
+ * @category Arrangement & Analysis
2131
+ */
2132
+ type ReductionLevel = (typeof REDUCTION_LEVELS)[number];
2133
+ /**
2134
+ * A chord with the place it holds, the beats it holds it for, and a short
2135
+ * rationale.
2136
+ *
2137
+ * One entry per timeline segment, in the same order. The entry carries the
2138
+ * segment's own beat range, so the chords that survive a filter still say when
2139
+ * they sound: holding the structural chords fixed is what a reharmonizer needs,
2140
+ * and it cannot hold a chord at a place the filter threw away.
2141
+ *
2142
+ * @category Arrangement & Analysis
2143
+ */
2144
+ type ReducedChord = {
2145
+ chord: Chord;
2146
+ startBeat: number;
2147
+ endBeat: number;
2148
+ level: ReductionLevel;
2149
+ rationale: string;
2150
+ };
2151
+ /**
2152
+ * What a reduction treats as the frame.
2153
+ *
2154
+ * `'function'` is the functional reading: the tonic, the dominant and the
2155
+ * chords that cadence are the frame. `'duration'` is the salience reading: a
2156
+ * chord is the frame when it outlasts the chords around it — its length beats
2157
+ * the median of the other chords' — whatever function it carries. Nothing
2158
+ * outlasts anything in an even harmonic rhythm, so a loop or a vamp protects no
2159
+ * chord by length and the two figures decide, as they do under either reading.
2160
+ *
2161
+ * @category Arrangement & Analysis
2162
+ */
2163
+ type ReductionBasis = 'function' | 'duration';
2164
+ /**
2165
+ * Options for {@link reduceProgression}.
2166
+ *
2167
+ * @category Arrangement & Analysis
2168
+ */
2169
+ type ReduceProgressionOptions = {
2170
+ /**
2171
+ * Which reading decides what the frame is; see {@link ReductionBasis}.
2172
+ *
2173
+ * @defaultValue `'function'`
2174
+ */
2175
+ basis?: ReductionBasis;
2176
+ };
2177
+ /**
2178
+ * Reduce a chord progression to its frame, labelling every chord.
2179
+ *
2180
+ * One entry comes back per timeline segment, in the same order, so the two read
2181
+ * in step. Filtering the result to `'structural'` is the skeleton view — the
2182
+ * `I - IV - V - I` under a progression that spells far more chords than that —
2183
+ * and holding those chords fixed is what a reharmonizer needs in order to
2184
+ * rewrite the surface without moving the harmony. Each entry carries its own
2185
+ * `startBeat` and `endBeat`, so a filtered chord still knows where it sounds
2186
+ * once the segments it was read against are gone.
2187
+ *
2188
+ * A chord is structural unless one of two figures demotes it: its root stepping
2189
+ * in from the previous chord and on to the next in the same direction (passing),
2190
+ * or stepping away from a harmony that returns (neighbor). Chords carrying the
2191
+ * frame are never demoted, and what carries the frame is the module's stated
2192
+ * theoretical position — see {@link ReductionBasis} for the reading this takes
2193
+ * by default and the one it can be switched to.
2194
+ *
2195
+ * Chords separated by a rest form no figure across it, the way
2196
+ * {@link detectCadences} pairs no chords across one.
2197
+ *
2198
+ * @param timeline The chord timeline to reduce.
2199
+ * @param key The prevailing key, or the key in force at a given beat, for music
2200
+ * that modulates.
2201
+ * @param opts Which reading decides the frame; see
2202
+ * {@link ReduceProgressionOptions}.
2203
+ * @returns One labelled chord per segment, in time order.
2204
+ * @throws If `opts.basis` is not one of the readings {@link ReductionBasis}
2205
+ * names.
2206
+ * @example
2207
+ * ```ts
2208
+ * import { chordTimelineFromChords, majorKey, reduceProgression } from '@libraz/libcantus';
2209
+ * const timeline = chordTimelineFromChords(
2210
+ * [
2211
+ * { rootPc: 0, quality: 'maj7', startBeat: 0 },
2212
+ * { rootPc: 1, quality: 'dim7', startBeat: 4 },
2213
+ * { rootPc: 2, quality: 'min7', startBeat: 8 },
2214
+ * ],
2215
+ * 12,
2216
+ * );
2217
+ * reduceProgression(timeline, majorKey(0)).map((entry) => entry.level);
2218
+ * // ['structural', 'passing', 'structural']
2219
+ * ```
2220
+ * @category Arrangement & Analysis
2221
+ */
2222
+ declare function reduceProgression(timeline: ChordTimeline, key: KeyContext, opts?: ReduceProgressionOptions): ReducedChord[];
2223
+
2224
+ /**
2225
+ * Where a line places its onsets against the meter: how dense they are, which
2226
+ * metric positions they favour, and how far they push against the beat.
2227
+ *
2228
+ * A phrase and a whole piece are read the same way — a run of onsets over a
2229
+ * span of beats — so a single reading serves both a melodic line and a
2230
+ * harmonic-rhythm reading of chord changes turned into onsets of their own.
2231
+ */
2232
+
2233
+ /**
2234
+ * Options for {@link analyzeRhythm}.
2235
+ *
2236
+ * @category Arrangement & Analysis
2237
+ */
2238
+ type RhythmAnalysisOptions = {
2239
+ /**
2240
+ * A single time signature held across the whole span, as sugar for a
2241
+ * one-element `meters`; defaults to 4/4. Giving both is an input error.
2242
+ *
2243
+ * @defaultValue `4/4`
2244
+ */
2245
+ ts?: MeterLike;
2246
+ /**
2247
+ * The meter as it changes over the span, so a piece that changes metre is
2248
+ * read against its own bar lines throughout.
2249
+ *
2250
+ * @defaultValue 4/4 throughout
2251
+ */
2252
+ meters?: MeterLike;
2253
+ /**
2254
+ * End of the analysed span in beats; defaults to the end of the last note.
2255
+ *
2256
+ * @defaultValue the end of the last note
2257
+ */
2258
+ totalBeats?: number;
2259
+ /**
2260
+ * Upper bound on the work this call may do.
2261
+ *
2262
+ * @defaultValue {@link DEFAULT_GENERATION_BUDGET}
2263
+ */
2264
+ budget?: number;
2265
+ };
2266
+ /**
2267
+ * How a line's onsets sit against one time signature: which slot of its bar
2268
+ * they favour, mass-normalized.
2269
+ *
2270
+ * @category Arrangement & Analysis
2271
+ */
2272
+ type BarPositionProfile = {
2273
+ /** The time signature this profile's bar is read in. */
2274
+ ts: TimeSignature;
2275
+ /** Slots in one bar of `ts`, at one twelfth of a quarter-note beat each. */
2276
+ slotsPerBar: number;
2277
+ /** Onset mass per slot, in bar order starting at the downbeat; sums to 1. */
2278
+ shares: number[];
2279
+ /** Onsets read under this signature. */
2280
+ onsets: number;
2281
+ };
2282
+ /**
2283
+ * How a line places its onsets against the meter.
2284
+ *
2285
+ * @category Arrangement & Analysis
2286
+ */
2287
+ type RhythmAnalysis = {
2288
+ /** First beat of the analysed span. */
2289
+ startBeat: number;
2290
+ /** End of the analysed span, exclusive. */
2291
+ endBeat: number;
2292
+ /** The span's length in bars, counted across any meter changes it crosses. */
2293
+ bars: number;
2294
+ /** Onsets read, folding onsets within 0.05 beat of one another into one. */
2295
+ onsets: number;
2296
+ /** Onsets per bar; 0 for a span with no bars. */
2297
+ onsetDensity: number;
2298
+ /** Onsets per bar of the span, one entry per bar including a part bar at either end. */
2299
+ barOnsets: number[];
2300
+ /**
2301
+ * Onset mass by rhythmic level, indexed 0–5: 0 off the first pulse
2302
+ * subdivision, 1 on it, 2–5 on a main pulse (`metricWeight` plus 2). Sums to 1.
2303
+ */
2304
+ onsetLevels: number[];
2305
+ /** Onset placement within the bar, one profile per time signature the span reads under. */
2306
+ barPositions: BarPositionProfile[];
2307
+ /** Inter-onset-interval mass, binned to {@link RHYTHM_IOI_BINS}; sums to 1. */
2308
+ interOnsetShares: number[];
2309
+ /** Share of the span during which nothing sounds. */
2310
+ restRatio: number;
2311
+ /** Longuet-Higgins & Lee syncopation, in [0, 1]. */
2312
+ syncopation: number;
2313
+ /** Share of onsets further than 1/32 beat from the nearest grid slot. */
2314
+ offGridRatio: number;
2315
+ /** Why the line reads as it does. */
2316
+ rationale: string;
2317
+ };
2318
+ /**
2319
+ * Inter-onset intervals, in quarter-note beats, at half-octave steps from a
2320
+ * sixteenth of a beat to sixteen beats.
2321
+ *
2322
+ * @category Arrangement & Analysis
2323
+ */
2324
+ declare const RHYTHM_IOI_BINS: readonly number[];
2325
+ /**
2326
+ * How a line places its onsets against the meter: density, metric placement,
2327
+ * interval spacing, rest, and Longuet-Higgins & Lee syncopation.
2328
+ *
2329
+ * Onsets within 0.05 beat of one another read as one, and an
2330
+ * onset further than 1/32 beat from the nearest twelfth-of-a-beat slot is read
2331
+ * as off grid; every onset is moved to its nearest slot for everything
2332
+ * downstream of it, so an unquantized line reads a real but reduced
2333
+ * syncopation rather than a spurious one from a grid it never intended to sit
2334
+ * on.
2335
+ *
2336
+ * @param notes The line's notes, in any order. Notes that never sound
2337
+ * (`durationBeat <= 0`) are dropped.
2338
+ * @param opts Analysis options; see {@link RhythmAnalysisOptions}.
2339
+ * @returns The rhythm reading; see {@link RhythmAnalysis}.
2340
+ * @example
2341
+ * ```ts
2342
+ * import { analyzeRhythm } from '@libraz/libcantus';
2343
+ * const rhythm = analyzeRhythm(
2344
+ * [
2345
+ * { pitch: 60, startBeat: 0, durationBeat: 1.5 },
2346
+ * { pitch: 62, startBeat: 1.5, durationBeat: 2.5 },
2347
+ * ],
2348
+ * { ts: '4/4' },
2349
+ * );
2350
+ * rhythm.onsets; // 2
2351
+ * rhythm.syncopation > 0; // true
2352
+ * ```
2353
+ * @category Arrangement & Analysis
2354
+ */
2355
+ declare function analyzeRhythm(notes: readonly NoteEvent[], opts?: RhythmAnalysisOptions): RhythmAnalysis;
2356
+
2357
+ /**
2358
+ * A structural fingerprint of a piece: form, phrase shape, harmonic function
2359
+ * and rhythm, and how its motifs derive from one another — everything
2360
+ * `compareReferences` needs to measure two pieces against each other,
2361
+ * dimension by dimension, without carrying the note sequence itself.
2362
+ *
2363
+ * A profile is plain data, JSON-serializable end to end: nothing in it is a
2364
+ * class instance or a function. `profileVersion` gates the shape this file
2365
+ * declares, not the analysis behind it — a schema change bumps it, a reading
2366
+ * that changes only because the analyzer improved does not.
2367
+ */
2368
+
2369
+ /**
2370
+ * Schema version {@link ReferenceProfile} is written at.
2371
+ *
2372
+ * {@link assertReferenceProfile} rejects any other value outright rather than
2373
+ * guess at an older shape a caller's stored JSON might be in.
2374
+ *
2375
+ * @category Arrangement & Analysis
2376
+ */
2377
+ declare const REFERENCE_PROFILE_VERSION = 1;
2378
+ /**
2379
+ * A structural fingerprint of a piece, recovered from its notes and held
2380
+ * without the notes themselves.
2381
+ *
2382
+ * @category Arrangement & Analysis
2383
+ */
2384
+ type ReferenceProfile = {
2385
+ /** Schema version this record is written at; see {@link REFERENCE_PROFILE_VERSION}. */
2386
+ profileVersion: number;
2387
+ /** The analysed span. */
2388
+ span: {
2389
+ startBeat: number;
2390
+ endBeat: number;
2391
+ bars: number;
2392
+ };
2393
+ /** The piece's meter across the analysed span. */
2394
+ meters: MeterMap;
2395
+ /** Sections, phrases and the hypermetric grouping they sit in. */
2396
+ form: ReferenceForm;
2397
+ /** Keys, structural harmony, and harmonic rhythm. */
2398
+ harmony: ReferenceHarmony;
2399
+ /** Register, contour, motifs and their derivations, and melodic rhythm. */
2400
+ melody: ReferenceMelody;
2401
+ };
2402
+ /**
2403
+ * The formal reading of a profiled piece: its hypermetric grouping, the
2404
+ * sections that grouping and repetition reveal, and the phrases within them.
2405
+ *
2406
+ * @category Arrangement & Analysis
2407
+ */
2408
+ type ReferenceForm = {
2409
+ /** The hyperbar grouping the phrase and section boundaries are read against. */
2410
+ hypermeter: {
2411
+ groupBars: number;
2412
+ confidence: number;
2413
+ };
2414
+ /** Sections, labelled by which earlier section they restate. */
2415
+ sections: FormSection[];
2416
+ /** Phrases, in time order. */
2417
+ phrases: ReferencePhrase[];
2418
+ };
2419
+ /**
2420
+ * One phrase: its span, the section it opens in, how it cadences, and the
2421
+ * melodic and motivic content within it.
2422
+ *
2423
+ * @category Arrangement & Analysis
2424
+ */
2425
+ type ReferencePhrase = {
2426
+ /** First beat of the phrase. */
2427
+ startBeat: number;
2428
+ /** End of the phrase, exclusive. */
2429
+ endBeat: number;
2430
+ /** The phrase's length in bars. */
2431
+ bars: number;
2432
+ /** Index into `form.sections` of the section this phrase's start beat falls in. */
2433
+ section: number | null;
2434
+ /** Confidence of the phrase boundary, in [0, 1]. */
2435
+ confidence: number;
2436
+ /** The cadence the phrase ends on, or null when it closes on none. */
2437
+ cadence: ReferenceCadence | null;
2438
+ /** The phrase's melodic descriptors, or null when fewer than two notes sound within it. */
2439
+ melody: ReferencePhraseMelody | null;
2440
+ /** Indices into `melody.graph.nodes` of every motif statement that starts within this phrase. */
2441
+ motifNodes: number[];
2442
+ };
2443
+ /**
2444
+ * How a melodic line reads within one phrase.
2445
+ *
2446
+ * @category Arrangement & Analysis
2447
+ */
2448
+ type ReferencePhraseMelody = {
2449
+ /** The phrase's overall shape. */
2450
+ shape: MelodicContourShape;
2451
+ /** Lowest pitch sounding in the phrase. */
2452
+ low: number;
2453
+ /** Highest pitch sounding in the phrase. */
2454
+ high: number;
2455
+ /** Duration-weighted mean pitch, truncated to the phrase's span. */
2456
+ mean: number;
2457
+ /** Pitch of the phrase's highest note (the first, when several tie). */
2458
+ peakPitch: number;
2459
+ /** Onset of the phrase's peak note, as a fraction of the phrase's length, in [0, 1]. */
2460
+ peakPosition: number;
2461
+ /**
2462
+ * Eight sampled points across the phrase, each the sounding pitch at that
2463
+ * point minus the piece's overall melodic mean, in semitones.
2464
+ */
2465
+ outline: number[];
2466
+ /** Onsets per bar within the phrase; see {@link RhythmAnalysis.onsetDensity}. */
2467
+ onsetDensity: number;
2468
+ /** Share of the phrase during which nothing sounds. */
2469
+ restRatio: number;
2470
+ };
2471
+ /**
2472
+ * A cadence read at a structural boundary.
2473
+ *
2474
+ * @category Arrangement & Analysis
2475
+ */
2476
+ type ReferenceCadence = {
2477
+ /** Beat the cadence arrives at. */
2478
+ atBeat: number;
2479
+ /** The cadence type. */
2480
+ type: CadenceType;
2481
+ /** How strongly the cadence closes the boundary it sits at, in [0, 1]. */
2482
+ weight: number;
2483
+ };
2484
+ /**
2485
+ * The harmonic reading of a profiled piece: its key regions, its structural
2486
+ * chords, and how densely those chords change.
2487
+ *
2488
+ * @category Arrangement & Analysis
2489
+ */
2490
+ type ReferenceHarmony = {
2491
+ /** Key regions across the analysed span. */
2492
+ keys: ReferenceKeyRegion[];
2493
+ /** Chords reduced from the piece's harmony. */
2494
+ chords: ReferenceChord[];
2495
+ /** Onset placement of chord changes, read the way a melodic line's onsets are. */
2496
+ rhythm: RhythmAnalysis;
2497
+ };
2498
+ /**
2499
+ * One span of the piece read in a single key.
2500
+ *
2501
+ * @category Arrangement & Analysis
2502
+ */
2503
+ type ReferenceKeyRegion = {
2504
+ /** First beat of the region. */
2505
+ startBeat: number;
2506
+ /** End of the region, exclusive. */
2507
+ endBeat: number;
2508
+ /** The key the region is read in. */
2509
+ key: ResolvedKey;
2510
+ /** Confidence of the key reading, in [0, 1]. */
2511
+ confidence: number;
2512
+ };
2513
+ /**
2514
+ * One reduced chord, named against the key region it falls in.
2515
+ *
2516
+ * @category Arrangement & Analysis
2517
+ */
2518
+ type ReferenceChord = {
2519
+ /** First beat of the chord. */
2520
+ startBeat: number;
2521
+ /** End of the chord, exclusive. */
2522
+ endBeat: number;
2523
+ /** Index into `harmony.keys` of the region this chord is read against. */
2524
+ key: number;
2525
+ /** The chord, as a Roman numeral in the region's key. */
2526
+ roman: string;
2527
+ /** The chord's harmonic function. */
2528
+ function: HarmonicFunction;
2529
+ /** How the chord survived harmonic reduction. */
2530
+ level: ReductionLevel;
2531
+ };
2532
+ /**
2533
+ * The melodic reading of a profiled piece: register and contour, its motifs
2534
+ * and how they derive from one another, and its rhythm.
2535
+ *
2536
+ * @category Arrangement & Analysis
2537
+ */
2538
+ type ReferenceMelody = {
2539
+ /** The melodic line's pitch range and mean, or null when no note sounds. */
2540
+ register: {
2541
+ low: number;
2542
+ high: number;
2543
+ mean: number;
2544
+ } | null;
2545
+ /** The melodic line's overall shape, or null when fewer than two notes sound. */
2546
+ shape: MelodicContourShape | null;
2547
+ /** Motifs found in the melodic line. */
2548
+ motifs: ReferenceMotif[];
2549
+ /** How the motifs' statements derive from one another. */
2550
+ graph: MotifGraph;
2551
+ /** Onset placement of the melodic line. */
2552
+ rhythm: RhythmAnalysis;
2553
+ };
2554
+ /**
2555
+ * One motif, held as the interval and rhythm ratios it repeats under
2556
+ * transformation rather than as the notes of any one statement.
2557
+ *
2558
+ * @category Arrangement & Analysis
2559
+ */
2560
+ type ReferenceMotif = {
2561
+ /** Semitones between consecutive notes of the first statement (`MotifData.intervals`). */
2562
+ intervals: number[];
2563
+ /** Onset-to-onset ratios of the first statement (`MotifData.rhythm`), each gap over the first. */
2564
+ rhythm: number[];
2565
+ /**
2566
+ * Onset gap between the first two notes of the first statement, in beats:
2567
+ * the unit `rhythm` is measured in. 0 for a one-note motif.
2568
+ */
2569
+ unitBeats: number;
2570
+ /** Length of the first statement, in beats. */
2571
+ spanBeats: number;
2572
+ /** How many statements of this motif were found. */
2573
+ occurrences: number;
2574
+ };
2575
+
2576
+ export { type ReferenceHarmony as $, type AnalyzeChordOptions as A, type BarPositionProfile as B, CADENCE_TYPES as C, type DetectCadenceOptions as D, type ExplainRomanOptions as E, type FormSection as F, type MotifGraphNode as G, HARMONIC_FUNCTIONS as H, type IdentifiedVoiceNote as I, type MotifGraphOptions as J, type KeyContext as K, type MotifOccurrence as L, MELODIC_CONTOUR_SHAPES as M, type MotifRelation as N, type MotifRelationKind as O, type MotifRelationSummary as P, type PivotChord as Q, REDUCTION_LEVELS as R, REFERENCE_PROFILE_VERSION as S, RHYTHM_IOI_BINS as T, type ReduceProgressionOptions as U, type ReducedChord as V, type ReductionBasis as W, type ReductionLevel as X, type ReferenceCadence as Y, type ReferenceChord as Z, type ReferenceForm as _, type AnalyzedNote as a, type ReferenceKeyRegion as a0, type ReferenceMelody as a1, type ReferenceMotif as a2, type ReferencePhrase as a3, type ReferencePhraseMelody as a4, type ReferenceProfile as a5, type RejectedCandidate as a6, type RhythmAnalysis as a7, type RhythmAnalysisOptions as a8, type RomanExplanation as a9, reduceProgression as aA, relateMotifs as aB, romanToChord as aC, secondaryDominant as aD, secondaryDominantOf as aE, sectionsFromNotes as aF, toVoiceNotes as aG, type SuspensionFigure as aa, type TheoryLabel as ab, type VoiceNote as ac, analyzeChord as ad, analyzeRhythm as ae, analyzeVoice as af, assertChordTimeline as ag, borrowedSource as ah, chordTimelineFromChords as ai, chordTimelineFromNotes as aj, chordToRoman as ak, detectCadence as al, detectCadences as am, detectModulations as an, explainRoman as ao, extractMotifs as ap, functionOf as aq, isBorrowedChord as ar, isDiatonic as as, isMinorKey as at, keyTimelineFromNotes as au, melodicContour as av, motifFromNotes as aw, motifGraph as ax, pivotChords as ay, prevailingKeyOf as az, type BorrowedSource as b, type CadenceHit as c, type CadenceResult as d, type CadenceType as e, type ChordAnalysis as f, type ChordSegmentation as g, type ChordTimeline as h, type ChordTimelineOptions as i, type ChordTimelineResult as j, type ChordToRomanOptions as k, type ContourDirection as l, type ExtractMotifsOptions as m, type FormSectionOptions as n, type HarmonicFunction as o, type KeyProfileName as p, type KeyProfilePair as q, type KeyRegion as r, type KeyTimelineOptions as s, MOTIF_RELATION_KINDS as t, type MelodicContour as u, type MelodicContourShape as v, type MelodicPhrase as w, type MotifData as x, type MotifGraph as y, type MotifGraphEdge as z };