@libraz/libcantus 0.9.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 (52) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +291 -0
  3. package/dist/index.cjs +6465 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.cts +2621 -0
  6. package/dist/index.d.ts +2621 -0
  7. package/dist/index.js +6297 -0
  8. package/dist/index.js.map +1 -0
  9. package/package.json +71 -0
  10. package/src/analysis/index.ts +261 -0
  11. package/src/arrange/index.ts +409 -0
  12. package/src/bass/index.ts +301 -0
  13. package/src/chord/index.ts +292 -0
  14. package/src/chordscale/index.ts +316 -0
  15. package/src/countermelody/index.ts +349 -0
  16. package/src/counterpoint/index.ts +209 -0
  17. package/src/detect/index.ts +176 -0
  18. package/src/drums/beat.ts +266 -0
  19. package/src/drums/euclid.ts +58 -0
  20. package/src/drums/fills.ts +345 -0
  21. package/src/drums/ghost.ts +119 -0
  22. package/src/drums/hihat.ts +285 -0
  23. package/src/drums/hit.ts +31 -0
  24. package/src/drums/index.ts +211 -0
  25. package/src/drums/internal.ts +251 -0
  26. package/src/drums/kick.ts +160 -0
  27. package/src/drums/percussion.ts +121 -0
  28. package/src/drums/rng.ts +7 -0
  29. package/src/drums/swing.ts +66 -0
  30. package/src/functional/index.ts +602 -0
  31. package/src/groove/index.ts +230 -0
  32. package/src/harmonize/index.ts +367 -0
  33. package/src/harmony/index.ts +75 -0
  34. package/src/index.ts +233 -0
  35. package/src/interval/index.ts +67 -0
  36. package/src/meter/index.ts +179 -0
  37. package/src/model/index.ts +957 -0
  38. package/src/motif/index.ts +321 -0
  39. package/src/pitch/index.ts +256 -0
  40. package/src/progression/index.ts +336 -0
  41. package/src/random/index.ts +41 -0
  42. package/src/reharmony/index.ts +299 -0
  43. package/src/rhythm/index.ts +131 -0
  44. package/src/safety/index.ts +372 -0
  45. package/src/scale/index.ts +215 -0
  46. package/src/spelling/index.ts +164 -0
  47. package/src/symbol/index.ts +213 -0
  48. package/src/timeline/index.ts +352 -0
  49. package/src/tuning/index.ts +129 -0
  50. package/src/types.ts +29 -0
  51. package/src/voicing/index.ts +523 -0
  52. package/tsconfig.json +23 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 libraz
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,291 @@
1
+ # @libraz/libcantus
2
+
3
+ Pure-TypeScript toolkit for working with music: name notes and chords, analyze
4
+ harmony, recognize what you're hearing, voice and reharmonize progressions, and
5
+ generate parts (bass, countermelody, drums, rhythm) — all with no runtime
6
+ dependencies.
7
+
8
+ [![CI](https://github.com/libraz/libcantus/actions/workflows/ci.yml/badge.svg)](https://github.com/libraz/libcantus/actions/workflows/ci.yml)
9
+ [![codecov](https://codecov.io/gh/libraz/libcantus/branch/main/graph/badge.svg)](https://codecov.io/gh/libraz/libcantus)
10
+ [![TypeScript](https://img.shields.io/badge/TypeScript-strict-3178C6?logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
11
+ [![Node.js](https://img.shields.io/badge/Node.js-%E2%89%A522-339933?logo=node.js&logoColor=white)](https://nodejs.org/)
12
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
13
+
14
+ ## What can you do with it?
15
+
16
+ - **Name and move notes** — parse `C4`, transpose it, convert to/from MIDI, spell
17
+ intervals with correct enharmonics (`F#` vs `Gb`).
18
+ - **Build chords and progressions** — from scale degrees, Roman numerals
19
+ (`V7/V`), or lead-sheet symbols (`Cmaj7`, `F#m7b5`, `C/G`).
20
+ - **Analyze harmony** — Roman-numeral analysis, harmonic function, cadence
21
+ detection, and borrowed / modal-interchange chords.
22
+ - **Recognize what you hear** — notes in, chord or key out (the inverse of the
23
+ builders).
24
+ - **Reharmonize** — tritone subs, chromatic mediants, negative harmony, modal
25
+ interchange palettes.
26
+ - **Voice chords** — smooth 4-voice (SATB) leading, plus drop-2/3, shell, and
27
+ rootless comping styles.
28
+ - **Generate parts** — bass lines, countermelodies, drums, rhythms, motifs, and
29
+ whole progressions; deterministic for a given seed.
30
+ - **Arrange from a DAW / MIDI file** — feed raw multi-track notes, recover the
31
+ harmony, get a whole-piece analysis (with per-note conflicts), and generate the
32
+ missing parts against it.
33
+ - **Work with pitch as sound** — frequencies, cents, EDO, and just intonation.
34
+
35
+ The musical **values** — notes, chords, keys, progressions — come in two
36
+ interchangeable styles: a **fluent, immutable class API** (`Note`, `Chord`,
37
+ `Key`, `Progression`) that reads like music theory, and the underlying
38
+ **tree-shakeable pure functions**. Operations over **collections and timelines**
39
+ (part generation and whole-arrangement analysis) work on arrays of note events,
40
+ so — like `rhythm`, `drums`, and `detectKey` — they are exposed as functions.
41
+
42
+ ## Install
43
+
44
+ ```sh
45
+ yarn add @libraz/libcantus
46
+ ```
47
+
48
+ ## Quick start
49
+
50
+ The class API chains immutably and carries key context, so analysis needs no
51
+ repetition:
52
+
53
+ ```ts
54
+ import { Chord, Key, Note } from '@libraz/libcantus';
55
+
56
+ const c = Key.major('C');
57
+
58
+ c.chord(4, 'dom7').pitchClasses(); // [2, 5, 7, 11] (G7)
59
+ c.roman('V7/V').voice(); // [ ...SATB MIDI ] (secondary dominant, voiced)
60
+ Note.of('C4').transpose(7).name; // 'G4'
61
+
62
+ // A ii–V–I, built and analyzed in one line:
63
+ c.chord(1, 'min').progressionTo(c.chord(4, 'dom7'), c.chord(0, 'maj')).analyze();
64
+ // { chords: [...functional analysis...], cadence: 'authentic' }
65
+
66
+ Chord.detect([60, 64, 67])[0].quality; // 'maj'
67
+ ```
68
+
69
+ Every class wraps a plain object (`Chord.data`, `Note.data`) and delegates to the
70
+ pure functions, so the two styles interoperate freely. The same task with the
71
+ functional API:
72
+
73
+ ```ts
74
+ import { chordFromDegree, chordPitchClasses, classifyInterval, majorKey } from '@libraz/libcantus';
75
+
76
+ const cMajor = majorKey(0);
77
+
78
+ classifyInterval(7); // IntervalQuality.PerfectConsonance
79
+ chordPitchClasses(chordFromDegree(4, 'dom7', cMajor)); // [2, 5, 7, 11] (G7)
80
+ ```
81
+
82
+ ## Name and move notes
83
+
84
+ Parse and format notes, convert to MIDI, and spell intervals so enharmonics the
85
+ pitch-class layer can't tell apart come out right:
86
+
87
+ ```ts
88
+ import { Interval, Note } from '@libraz/libcantus';
89
+
90
+ Note.of('C4').transpose(7).name; // 'G4'
91
+ Note.of('C4').midi; // 60
92
+ Interval.between(Note.of('C4'), Note.of('F#4')).name; // 'A4' (augmented fourth)
93
+ Interval.between(Note.of('C4'), Note.of('Gb4')).name; // 'd5' (diminished fifth)
94
+ ```
95
+
96
+ ## Keys and scales
97
+
98
+ A `KeyScale` is a root pitch class plus a 12-bit `modeMask12` (bit `n` set means
99
+ pitch class `(rootPc + n) % 12` is in the scale). `majorKey`, `minorKey`, and
100
+ `scaleByName` cover the modes, pentatonics, blues, whole-tone, and octatonic
101
+ scales; `MAJOR_MASK` / `NATURAL_MINOR_MASK` let you define custom keys.
102
+
103
+ `nearestScaleTone` snaps a pitch to the closest in-scale MIDI pitch (preferring
104
+ the lower on a tie) — handy when constraining generated notes to a key.
105
+
106
+ ## Build chords and progressions
107
+
108
+ From scale degrees, Roman numerals, or lead-sheet symbols — and back again:
109
+
110
+ ```ts
111
+ import { Chord, Key } from '@libraz/libcantus';
112
+
113
+ const c = Key.major('C');
114
+
115
+ c.roman('V7/V').symbol(); // 'D7' (a secondary dominant)
116
+ c.chord(4, 'dom7').roman(); // 'V7'
117
+ Chord.parse('F#m7b5').pitchClasses(); // [0, 4, 6, 9]
118
+ ```
119
+
120
+ Chord vocabulary spans triads through thirteenths — `dim7`, `m7b5`, `minMaj7`,
121
+ `aug7`, sixths, and altered dominants included.
122
+
123
+ Or generate a progression from a style preset (a collection-level operation, so
124
+ it stays functional):
125
+
126
+ ```ts
127
+ import { generateProgression, majorKey } from '@libraz/libcantus';
128
+
129
+ // One chord per bar, secondary dominants inserted where they fit:
130
+ generateProgression({ key: majorKey(0), style: 'idol', bars: 8, reharmonize: true, seed: 1 });
131
+ ```
132
+
133
+ ## Analyze harmony
134
+
135
+ Turn chords into Roman-numeral analysis with function, cadences, and modal
136
+ interchange — in major and minor, respecting inversions:
137
+
138
+ ```ts
139
+ import { Chord, Key } from '@libraz/libcantus';
140
+
141
+ // A minor iv in a major key reads as a borrowed subdominant:
142
+ Chord.of('F', 'min').analyze(Key.major('C'));
143
+ // { function: 'subdominant', borrowed: true, source: 'parallel-minor', roman: 'iv' }
144
+ ```
145
+
146
+ ## Recognize what you hear
147
+
148
+ Notes in, chord or key out — the inverse of the builders:
149
+
150
+ ```ts
151
+ import { Chord, detectKey } from '@libraz/libcantus';
152
+
153
+ Chord.detect([60, 64, 67])[0].symbol(); // 'C'
154
+ Chord.detectBest([60, 63, 67, 70])?.symbol(); // 'Cm7'
155
+ detectKey([0, 0, 0, 4, 7])[0]; // C major, best fit (key ranking stays functional)
156
+ ```
157
+
158
+ ## Spell chords and scales
159
+
160
+ A `Key` carries a spelled tonic, so the pitch-class core produces letter names,
161
+ correct in major and minor:
162
+
163
+ ```ts
164
+ import { Chord, Key } from '@libraz/libcantus';
165
+
166
+ Key.named('harmonicMinor', 'A').noteNames(); // ['A', 'B', 'C', 'D', 'E', 'F', 'G#']
167
+ Key.minor('E').noteNames(); // ['E', 'F#', 'G', 'A', 'B', 'C', 'D']
168
+
169
+ // Chords spell in a key's context too:
170
+ Key.major('C').chord(4, 'dom7').spell().map((n) => n.name); // ['G', 'B', 'D', 'F']
171
+ ```
172
+
173
+ ## Reharmonize
174
+
175
+ Reflect a chord through negative harmony on the class, or list substitution
176
+ candidates — tritone, relative, borrowed, and chromatic-mediant subs, plus
177
+ modal-interchange palettes — with the functions:
178
+
179
+ ```ts
180
+ import { Chord, Key, majorKey, parseChordSymbol, substituteChord } from '@libraz/libcantus';
181
+
182
+ Key.major('C').chord(4, 'dom7').negativeHarmony().symbol(); // 'Dm7b5'
183
+
184
+ // Substitution/palette search returns lists, so it stays functional:
185
+ substituteChord(parseChordSymbol('G7'), majorKey(0));
186
+ // [{ chord: Db7, type: 'tritone', ... }, ...]
187
+ ```
188
+
189
+ ## Choose scales and tensions
190
+
191
+ Find scales compatible with a chord and its available tensions and avoid notes
192
+ on the class; get a continuity-optimized scale choice across a whole set of
193
+ changes with `scalesForChanges`:
194
+
195
+ ```ts
196
+ import { Chord } from '@libraz/libcantus';
197
+
198
+ Chord.of('C', 'dom7').scales()[0]; // { name: 'mixolydian', rootPc: 0 }
199
+ Chord.of('C', 'maj7').tensions('ionian'); // [2, 9] (9 and 13; the 11 is an avoid note)
200
+ ```
201
+
202
+ ## Voice chords
203
+
204
+ Realize a progression into smooth 4-voice (SATB) MIDI voicings with minimal
205
+ motion, or voice a single chord in a comping style (drop-2/3, shell, rootless):
206
+
207
+ ```ts
208
+ import { Chord, Key } from '@libraz/libcantus';
209
+
210
+ const c = Key.major('C');
211
+
212
+ // A whole progression, voiced with minimal motion:
213
+ c.chord(0, 'maj').progressionTo(c.chord(5, 'maj'), c.chord(4, 'dom7'), c.chord(0, 'maj')).voice();
214
+ // [[...], [...], [...], [...]] (one ascending pitch per voice)
215
+
216
+ // A single chord in a shell comping voicing:
217
+ Chord.of('C', 'maj7').styledVoicing({ style: 'shell' }); // root, third, seventh
218
+ ```
219
+
220
+ `voiceLeadingCost` and `nextVoicing` let you steer the leading, and the
221
+ `counterpoint` predicates (parallel/hidden perfects, spacing, voice crossing,
222
+ leading-tone resolution, …) let you validate it.
223
+
224
+ ## Generate parts
225
+
226
+ Seeded, deterministic generators for melody and accompaniment:
227
+
228
+ ```ts
229
+ import {
230
+ generateBassLine, generateCounterMelody, generateDrums, generateRhythm,
231
+ generateMotif, parseTimeSignature,
232
+ } from '@libraz/libcantus';
233
+
234
+ generateRhythm(parseTimeSignature('4/4'), { seed: 1, density: 0.5 }); // strong-beat-weighted onsets
235
+ generateMotif({ key: majorKey(0), length: 4, contour: 'arch', seed: 1 }); // a short melodic cell
236
+ ```
237
+
238
+ `humanize`, `extractGrooveTemplate`, and `applyGrooveTemplate` add a meter-aware
239
+ feel — or capture the feel of one performance and transplant it onto another.
240
+
241
+ ## Arrange from a DAW or MIDI file
242
+
243
+ The arrangement layer takes raw multi-track `NoteEvent`s, recovers the harmony,
244
+ then analyses and generates against it:
245
+
246
+ ```ts
247
+ import {
248
+ analyzeArrangement, chordTimelineFromNotes, generateBassLine, generateCounterMelody,
249
+ } from '@libraz/libcantus';
250
+
251
+ // Infer a chord progression (and the key) from played notes:
252
+ const { timeline, key } = chordTimelineFromNotes(melodyAndChordNotes);
253
+
254
+ // Whole-piece analysis: inferred chords, cadences, per-note theory labels, and
255
+ // notes that clash with the sounding harmony (with reasons and suggestions):
256
+ const report = analyzeArrangement([
257
+ { role: 'melody', notes: melodyNotes },
258
+ { role: 'harmony', notes: chordNotes },
259
+ ]);
260
+ report.conflicts; // [{ beat, trackName, pitch, safety, reasons, rationale }, ...]
261
+
262
+ // Generate the missing parts from the recovered timeline:
263
+ generateBassLine({ segments: timeline.segments, key, style: 'walking', seed: 1 });
264
+ generateCounterMelody({ melody: melodyNotes, chordAt: timeline.at, key, register: 'below' });
265
+ ```
266
+
267
+ `harmonizeMelody` goes the other way — given a bare melody, it searches for the
268
+ best key, transpose, and chord path (with optional reharmonization) to harmonize
269
+ it.
270
+
271
+ Note events shared across the arrangement and generation modules use one type,
272
+ `NoteEvent` (`{ pitch, startBeat, durationBeat, velocity? }`, MIDI pitch in
273
+ quarter-note beats). Seeded generators (`bass`, `groove`, `countermelody`,
274
+ `rhythm`, `drums`, `motif`, `progression`) are deterministic for a given seed.
275
+
276
+ ## Work with pitch as sound
277
+
278
+ Frequencies, cents, EDO, and just intonation — for tuning, microtonality, and
279
+ analysis:
280
+
281
+ ```ts
282
+ import { frequencyOf, edo, justDeviationCents } from '@libraz/libcantus';
283
+ ```
284
+
285
+ Meter helpers (`TimeSignature`, `parseTimeSignature`, `beatsPerBar`,
286
+ `metricWeight`, `isStrongBeat`, `tuplet`) cover simple and compound meters and
287
+ back the accent-aware generators.
288
+
289
+ ## License
290
+
291
+ Apache-2.0