@libraz/libcantus-wasm 0.0.0-stage → 1.4.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.
- package/LICENSE +201 -0
- package/NOTICE +63 -0
- package/README.md +65 -2
- package/dist/analyze/index.d.ts +341 -0
- package/dist/analyze/index.js +128 -0
- package/dist/backend.js +140 -0
- package/dist/cantus.js +2 -0
- package/dist/cantus.wasm +0 -0
- package/dist/chunk-4LABHUBW.js +6940 -0
- package/dist/coerce-CUhHc3Tu.d.ts +1337 -0
- package/dist/core/index.d.ts +293 -0
- package/dist/core/index.js +224 -0
- package/dist/generate/index.d.ts +808 -0
- package/dist/generate/index.js +150 -0
- package/dist/index-BLuDesVG.d.ts +1339 -0
- package/dist/index-Bf0Sv8a9.d.ts +514 -0
- package/dist/index-C7KCaTRz.d.ts +64 -0
- package/dist/index-C9MYbuKS.d.ts +804 -0
- package/dist/index-DInQqT8Q.d.ts +66 -0
- package/dist/index-Dg-SAfhz.d.ts +663 -0
- package/dist/index-jgeug9EA.d.ts +2894 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +802 -0
- package/dist/masks-tycmkrgs.d.ts +493 -0
- package/dist/model/index.d.ts +5964 -0
- package/dist/model/index.js +46 -0
- package/dist/positional-DLnfUgqG.d.ts +365 -0
- package/dist/profile-B4WqcM4H.d.ts +1508 -0
- package/dist/theory/index.d.ts +992 -0
- package/dist/theory/index.js +288 -0
- package/dist/types-7mGFwvMm.d.ts +2599 -0
- package/package.json +93 -4
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { i as NoteLike, h as NoteEvent, g as Note } from '../index-C9MYbuKS.js';
|
|
2
|
+
export { a as Articulation, I as IntervalData, c as IntervalQualityLabel, e as KeyScale, S as SpelledInterval } from '../index-C9MYbuKS.js';
|
|
3
|
+
export { M as MeterChange, b as MeterLike, c as MeterMap, T as TimeSignature } from '../index-Bf0Sv8a9.js';
|
|
4
|
+
import { r as SpelledKeyLike } from '../coerce-CUhHc3Tu.js';
|
|
5
|
+
export { b as ChordData, c as ChordLike, d as ChordQuality, e as ChordSegment, g as ChordSpan, i as ChordToneRole, K as KeyLike, j as KeyRelation, k as KeyVariant, N as NoteSafety, l as PitchSpelling, n as ResolvedKey, o as SafetyProfile, s as SpelledKeyScale, V as VoiceSnapshot } from '../coerce-CUhHc3Tu.js';
|
|
6
|
+
export { r as ScaleName } from '../masks-tycmkrgs.js';
|
|
7
|
+
import { w as MelodicPhrase, a5 as ReferenceProfile, h as ChordTimeline } from '../types-7mGFwvMm.js';
|
|
8
|
+
export { A as AnalyzeChordOptions, a as AnalyzedNote, B as BarPositionProfile, b as BorrowedSource, C as CADENCE_TYPES, c as CadenceHit, d as CadenceResult, e as CadenceType, f as ChordAnalysis, g as ChordSegmentation, i as ChordTimelineOptions, j as ChordTimelineResult, k as ChordToRomanOptions, l as ContourDirection, D as DetectCadenceOptions, E as ExplainRomanOptions, m as ExtractMotifsOptions, F as FormSection, n as FormSectionOptions, H as HARMONIC_FUNCTIONS, o as HarmonicFunction, I as IdentifiedVoiceNote, K as KeyContext, p as KeyProfileName, q as KeyProfilePair, r as KeyRegion, s as KeyTimelineOptions, M as MELODIC_CONTOUR_SHAPES, t as MOTIF_RELATION_KINDS, u as MelodicContour, v as MelodicContourShape, x as MotifData, y as MotifGraph, z as MotifGraphEdge, G as MotifGraphNode, J as MotifGraphOptions, L as MotifOccurrence, N as MotifRelation, O as MotifRelationKind, P as MotifRelationSummary, Q as PivotChord, R as REDUCTION_LEVELS, S as REFERENCE_PROFILE_VERSION, T as RHYTHM_IOI_BINS, U as ReduceProgressionOptions, V as ReducedChord, W as ReductionBasis, X as ReductionLevel, Y as ReferenceCadence, Z as ReferenceChord, _ as ReferenceForm, $ as ReferenceHarmony, a0 as ReferenceKeyRegion, a1 as ReferenceMelody, a2 as ReferenceMotif, a3 as ReferencePhrase, a4 as ReferencePhraseMelody, a6 as RejectedCandidate, a7 as RhythmAnalysis, a8 as RhythmAnalysisOptions, a9 as RomanExplanation, aa as SuspensionFigure, ab as TheoryLabel, ac as VoiceNote, ad as analyzeChord, ae as analyzeRhythm, af as analyzeVoice, ag as assertChordTimeline, ah as borrowedSource, ai as chordTimelineFromChords, aj as chordTimelineFromNotes, ak as chordToRoman, al as detectCadence, am as detectCadences, an as detectModulations, ao as explainRoman, ap as extractMotifs, aq as functionOf, ar as isBorrowedChord, as as isDiatonic, at as isMinorKey, au as keyTimelineFromNotes, av as melodicContour, aw as motifFromNotes, ax as motifGraph, ay as pivotChords, az as prevailingKeyOf, aA as reduceProgression, aB as relateMotifs, aC as romanToChord, aD as secondaryDominant, aE as secondaryDominantOf, aF as sectionsFromNotes, aG as toVoiceNotes } from '../types-7mGFwvMm.js';
|
|
9
|
+
export { A as ArrangementAnalysis, a as ArrangementOptions, b as ArrangementSession, c as ArrangementTrack, d as AugmentedSixthKind, C as ChordMatch, e as Conflict, f as ConflictPartner, D as DetectChordOptions, g as DetectKeyOptions, H as Hypermeter, h as HypermeterOptions, K as KeyMatch, M as MODAL_SCALE_NAMES, i as ModalCandidate, j as ModalScaleName, P as Phrase, k as PhraseOptions, l as PhraseSignal, R as ReferenceProfileOptions, S as StructuralCadence, T as TensionPoint, m as TrackAnalysis, n as TrackEdit, o as TrackRole, p as analyzeArrangement, q as analyzePolyphony, r as analyzeReference, s as augmentedSixthChord, t as augmentedSixthFromPitchClasses, u as augmentedSixthKind, v as createArrangementSession, w as detectChord, x as detectChordBest, y as detectKey, z as detectKeyBest, B as detectKeyFromNotes, E as hypermeter, F as phrasesFromTimeline, G as spellAugmentedSixth, I as structuralCadences, J as tensionCurve, L as tensionCurveFrom } from '../profile-B4WqcM4H.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* How alike two phrases are, when they stand in no named relation.
|
|
13
|
+
*
|
|
14
|
+
* A device the repertoire names is an account of how one phrase was made from
|
|
15
|
+
* another; a similarity score is what is left to say when there is no such
|
|
16
|
+
* account — that the two are near, and how near. The reading is an edit
|
|
17
|
+
* distance over the intervals and over the onset gaps, so a phrase answered by
|
|
18
|
+
* a slightly ornamented version of itself still reads as close.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* How alike two lines are, and how the answer was reached.
|
|
23
|
+
*
|
|
24
|
+
* @category Arrangement & Analysis
|
|
25
|
+
*/
|
|
26
|
+
type MelodicComparison = {
|
|
27
|
+
/** Overall likeness in [0, 1]; 1 for the same line, transposition included. */
|
|
28
|
+
similarity: number;
|
|
29
|
+
/** Likeness of the interval sequences alone, in [0, 1]. */
|
|
30
|
+
pitchSimilarity: number;
|
|
31
|
+
/** Likeness of the rhythmic profiles alone, in [0, 1]. */
|
|
32
|
+
rhythmSimilarity: number;
|
|
33
|
+
/** Why the lines scored what they did. */
|
|
34
|
+
rationale: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Compare two lines and say why they scored what they did.
|
|
38
|
+
*
|
|
39
|
+
* The metric is a normalised edit distance over the interval sequence, weighted
|
|
40
|
+
* against the same over the rhythmic profile. Intervals rather than pitches,
|
|
41
|
+
* because the same tune in another key is the same tune; edit distance rather
|
|
42
|
+
* than a step-by-step correlation, because a variant that adds a passing note or
|
|
43
|
+
* drops one still has to line up with its model, and only an alignment-based
|
|
44
|
+
* measure can do that. Substituting one interval for another costs by how far
|
|
45
|
+
* apart they are rather than a flat step, so an answer that widens a third to a
|
|
46
|
+
* fourth stays close to its model while one that replaces it with a leap does
|
|
47
|
+
* not. The rhythm carries the smaller share: a melody is recognised mostly by
|
|
48
|
+
* its pitch shape, but a figure in a wholly different rhythm is a different
|
|
49
|
+
* figure.
|
|
50
|
+
*
|
|
51
|
+
* Both lines are expected to be monophonic, as {@link analyzeVoice} expects a
|
|
52
|
+
* voice to be. Notes struck together are read as one event, the highest of them
|
|
53
|
+
* standing for it, so a chord is reduced to its top voice rather than read as a
|
|
54
|
+
* line of its own.
|
|
55
|
+
*
|
|
56
|
+
* @param a The first line: a motif, or plain note events.
|
|
57
|
+
* @param b The second line.
|
|
58
|
+
* @returns The overall likeness, the two terms behind it, and a rationale.
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* import { compareMelodies } from '@libraz/libcantus';
|
|
62
|
+
* const line = [
|
|
63
|
+
* { pitch: 60, startBeat: 0, durationBeat: 1 },
|
|
64
|
+
* { pitch: 62, startBeat: 1, durationBeat: 1 },
|
|
65
|
+
* { pitch: 64, startBeat: 2, durationBeat: 1 },
|
|
66
|
+
* ];
|
|
67
|
+
* compareMelodies(line, line).similarity; // 1
|
|
68
|
+
* ```
|
|
69
|
+
* @category Arrangement & Analysis
|
|
70
|
+
*/
|
|
71
|
+
declare function compareMelodies(a: MelodicPhrase, b: MelodicPhrase): MelodicComparison;
|
|
72
|
+
/**
|
|
73
|
+
* How alike two lines are, in [0, 1].
|
|
74
|
+
*
|
|
75
|
+
* The number {@link compareMelodies} reaches, for callers that only want to rank
|
|
76
|
+
* phrases: 1 for the same line — a transposition of it included, since the
|
|
77
|
+
* measure is built on intervals — and lower the further two lines are from being
|
|
78
|
+
* each other's variant. Symmetric in its arguments, and deterministic.
|
|
79
|
+
*
|
|
80
|
+
* @param a The first line: a motif, or plain note events.
|
|
81
|
+
* @param b The second line.
|
|
82
|
+
* @returns The likeness in [0, 1].
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* import { melodicSimilarity } from '@libraz/libcantus';
|
|
86
|
+
* const line = [
|
|
87
|
+
* { pitch: 60, startBeat: 0, durationBeat: 1 },
|
|
88
|
+
* { pitch: 62, startBeat: 1, durationBeat: 1 },
|
|
89
|
+
* { pitch: 64, startBeat: 2, durationBeat: 1 },
|
|
90
|
+
* ];
|
|
91
|
+
* melodicSimilarity(line, line); // 1
|
|
92
|
+
* ```
|
|
93
|
+
* @category Arrangement & Analysis
|
|
94
|
+
*/
|
|
95
|
+
declare function melodicSimilarity(a: MelodicPhrase, b: MelodicPhrase): number;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Comparing two {@link ReferenceProfile}s dimension by dimension.
|
|
99
|
+
*
|
|
100
|
+
* The answer is never folded into one number: each field names the aspect it
|
|
101
|
+
* measures, so "a different song built the same way" reads as high structural
|
|
102
|
+
* fields beside a low surface one. Only `melody.surfaceSimilarity` reads the
|
|
103
|
+
* motifs' intervals; every other field is invariant under transposition, tempo
|
|
104
|
+
* and a change of motif intervals.
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Options for {@link compareReferences}.
|
|
109
|
+
*
|
|
110
|
+
* @category Arrangement & Analysis
|
|
111
|
+
*/
|
|
112
|
+
type ReferenceComparisonOptions = {
|
|
113
|
+
/**
|
|
114
|
+
* Upper bound on the cells of the progression alignment.
|
|
115
|
+
*
|
|
116
|
+
* @defaultValue {@link DEFAULT_GENERATION_BUDGET}
|
|
117
|
+
*/
|
|
118
|
+
budget?: number;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* How alike two profiled pieces are, one field per aspect.
|
|
122
|
+
*
|
|
123
|
+
* Every value is in [0, 1] and symmetric in the two profiles. A value is
|
|
124
|
+
* `null` when neither profile has anything to measure it on, and 0 when only
|
|
125
|
+
* one does.
|
|
126
|
+
*
|
|
127
|
+
* @category Arrangement & Analysis
|
|
128
|
+
*/
|
|
129
|
+
type ReferenceComparison = {
|
|
130
|
+
/** Formal layout. */
|
|
131
|
+
form: {
|
|
132
|
+
/** Likeness of the section-label sequences. */
|
|
133
|
+
sectionSequenceSimilarity: number | null;
|
|
134
|
+
/** Likeness of the phrase-length sequences. */
|
|
135
|
+
phraseLengthSimilarity: number | null;
|
|
136
|
+
};
|
|
137
|
+
/** Harmony. */
|
|
138
|
+
harmony: {
|
|
139
|
+
/** Likeness of the structural Roman-numeral progressions. */
|
|
140
|
+
progressionSimilarity: number | null;
|
|
141
|
+
/** Likeness of how long each harmonic function is held. */
|
|
142
|
+
functionSimilarity: number | null;
|
|
143
|
+
/** Likeness of the phrase-by-phrase cadence sequences. */
|
|
144
|
+
cadenceSimilarity: number | null;
|
|
145
|
+
/** Likeness of the key plans, read relative to each piece's first key. */
|
|
146
|
+
keyPlanSimilarity: number | null;
|
|
147
|
+
/** Likeness of where in the bar the chords change. */
|
|
148
|
+
harmonicRhythmOnsetSimilarity: number | null;
|
|
149
|
+
/** Likeness of how often the chords change. */
|
|
150
|
+
harmonicRhythmDensitySimilarity: number | null;
|
|
151
|
+
};
|
|
152
|
+
/** Melody. */
|
|
153
|
+
melody: {
|
|
154
|
+
/** Likeness of the motifs' interval content: the one field that reads the surface. */
|
|
155
|
+
surfaceSimilarity: number | null;
|
|
156
|
+
/** Likeness of how the motifs derive from one another. */
|
|
157
|
+
motifStructureSimilarity: number | null;
|
|
158
|
+
/** Likeness of the phrases' melodic outlines, each scaled by its own range. */
|
|
159
|
+
contourSimilarity: number | null;
|
|
160
|
+
/** Likeness of the phrases' registers, each relative to its piece's melodic mean. */
|
|
161
|
+
registerSimilarity: number | null;
|
|
162
|
+
};
|
|
163
|
+
/** Melodic rhythm. */
|
|
164
|
+
rhythm: {
|
|
165
|
+
/** Likeness of where in the bar the melody's onsets fall. */
|
|
166
|
+
onsetSimilarity: number | null;
|
|
167
|
+
/** Likeness of the melodies' onsets per bar. */
|
|
168
|
+
densitySimilarity: number | null;
|
|
169
|
+
/** Likeness of the melodies' inter-onset-interval distributions. */
|
|
170
|
+
durationSimilarity: number | null;
|
|
171
|
+
/** Likeness of the melodies' syncopation. */
|
|
172
|
+
syncopationSimilarity: number | null;
|
|
173
|
+
};
|
|
174
|
+
/** The two most and the two least alike fields, by name. */
|
|
175
|
+
rationale: string;
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Compare two profiled pieces aspect by aspect: form, harmony, melody and
|
|
179
|
+
* melodic rhythm.
|
|
180
|
+
*
|
|
181
|
+
* Sequences — sections, phrase lengths, cadences, key plans, structural
|
|
182
|
+
* chords, phrase contours and registers — are aligned by a graded edit
|
|
183
|
+
* distance; distributions — harmonic function, onset placement, inter-onset
|
|
184
|
+
* intervals, motif derivations — by histogram intersection. The surface field
|
|
185
|
+
* compares the motifs' interval cells, so a transposition of the same piece
|
|
186
|
+
* reads 1 on every field. No aggregate is returned: which aspects agree is the
|
|
187
|
+
* answer.
|
|
188
|
+
*
|
|
189
|
+
* @param a The first profile.
|
|
190
|
+
* @param b The second profile.
|
|
191
|
+
* @param opts The work budget.
|
|
192
|
+
* @returns One likeness per aspect, and a rationale naming the extremes.
|
|
193
|
+
* @throws {InvalidInputError} If either profile or the options cannot be read.
|
|
194
|
+
* @throws {BudgetExceededError} If the progression alignment would exceed the budget.
|
|
195
|
+
* @category Arrangement & Analysis
|
|
196
|
+
*/
|
|
197
|
+
declare function compareReferences(a: ReferenceProfile, b: ReferenceProfile, opts?: ReferenceComparisonOptions): ReferenceComparison;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Boundary validation for {@link ReferenceProfile}: a caller can hand this a
|
|
201
|
+
* value restored from JSON, a config file, or a plugin host, and every field
|
|
202
|
+
* is checked before anything downstream reads it. A violation names the path
|
|
203
|
+
* to the offending field, so a malformed document is diagnosed at the field
|
|
204
|
+
* that is wrong rather than wherever the first bad read happens to land.
|
|
205
|
+
*/
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Reject a value that is not a {@link ReferenceProfile}.
|
|
209
|
+
*
|
|
210
|
+
* A profile is the shape a caller's stored JSON, a config file, or a plugin
|
|
211
|
+
* host most plausibly hands back malformed: a missing field, a distribution
|
|
212
|
+
* that no longer sums to 1, an index a later edit left dangling, a numeral no
|
|
213
|
+
* reader can parse. Every field is checked before {@link compareReferences} or
|
|
214
|
+
* a caller's own code reads it, and a violation names the path to the field
|
|
215
|
+
* that is wrong.
|
|
216
|
+
*
|
|
217
|
+
* @param value The value to check.
|
|
218
|
+
* @param name What the value is, for the error message.
|
|
219
|
+
* @returns The same profile.
|
|
220
|
+
* @throws {InvalidInputError} If the value is not a valid reference profile.
|
|
221
|
+
* @example
|
|
222
|
+
* ```ts
|
|
223
|
+
* import { assertReferenceProfile } from '@libraz/libcantus';
|
|
224
|
+
* const emptyRhythm = {
|
|
225
|
+
* startBeat: 0, endBeat: 0, bars: 0, onsets: 0, onsetDensity: 0,
|
|
226
|
+
* barOnsets: [], onsetLevels: [0, 0, 0, 0, 0, 0], barPositions: [],
|
|
227
|
+
* interOnsetShares: new Array(17).fill(0), restRatio: 0, syncopation: 0,
|
|
228
|
+
* offGridRatio: 0, rationale: 'nothing sounds',
|
|
229
|
+
* };
|
|
230
|
+
* const profile = {
|
|
231
|
+
* profileVersion: 1,
|
|
232
|
+
* span: { startBeat: 0, endBeat: 0, bars: 0 },
|
|
233
|
+
* meters: [{ startBeat: 0, ts: { numerator: 4, denominator: 4 } }],
|
|
234
|
+
* form: { hypermeter: { groupBars: 1, confidence: 0 }, sections: [], phrases: [] },
|
|
235
|
+
* harmony: { keys: [], chords: [], rhythm: emptyRhythm },
|
|
236
|
+
* melody: { register: null, shape: null, motifs: [], graph: { nodes: [], edges: [] }, rhythm: emptyRhythm },
|
|
237
|
+
* };
|
|
238
|
+
* assertReferenceProfile(profile); // the profile, unchanged
|
|
239
|
+
* ```
|
|
240
|
+
* @category Arrangement & Analysis
|
|
241
|
+
*/
|
|
242
|
+
declare function assertReferenceProfile(value: unknown, name?: string): ReferenceProfile;
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Line spelling: name every note of a melodic line in one pass.
|
|
246
|
+
*
|
|
247
|
+
* {@link spellPitch} decides one note from the key, the root of the chord under
|
|
248
|
+
* it and its two immediate neighbours. That is enough for a single note, but a
|
|
249
|
+
* line spelled note by note can zig-zag between the two readings of one idea —
|
|
250
|
+
* a rising whole-tone figure comes out F# Ab Bb, with a diminished third in the
|
|
251
|
+
* middle of it.
|
|
252
|
+
*
|
|
253
|
+
* This module solves the whole line at once. The theory layer's own judgment
|
|
254
|
+
* becomes the cost of emitting a spelling, the melodic rules become the cost of
|
|
255
|
+
* moving from one spelling to the next, and a dynamic program takes the
|
|
256
|
+
* cheapest path across the line. Nothing here re-decides what
|
|
257
|
+
* {@link spellPitchClass} and {@link spellChord} already decide: it only weighs
|
|
258
|
+
* their answers against the shape of the line they sit in.
|
|
259
|
+
*/
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Options for {@link spellLine}.
|
|
263
|
+
*
|
|
264
|
+
* @category Arrangement & Analysis
|
|
265
|
+
*/
|
|
266
|
+
type SpellLineOptions = {
|
|
267
|
+
/**
|
|
268
|
+
* Tonic spelling to anchor the key, for a caller that already knows how the
|
|
269
|
+
* piece is written. It must sound the key's own root pitch class; anything
|
|
270
|
+
* else is rejected rather than spelled. Defaults to the conventional
|
|
271
|
+
* spelling the key itself is written with. Accepted as a note name, a MIDI
|
|
272
|
+
* number, note data, or a `Note`.
|
|
273
|
+
*/
|
|
274
|
+
tonic?: NoteLike;
|
|
275
|
+
/** Upper bound on the work the line may cost; defaults to the generation budget. */
|
|
276
|
+
budget?: number;
|
|
277
|
+
};
|
|
278
|
+
/**
|
|
279
|
+
* Spell a whole melodic line at once, so its notes agree with each other.
|
|
280
|
+
*
|
|
281
|
+
* Every note is spelled together with the rest of the line rather than one at a
|
|
282
|
+
* time: each pitch offers the three spellings a double accidental allows, the
|
|
283
|
+
* chord and the key price them, the intervals between neighbours price the
|
|
284
|
+
* pairs, and the cheapest reading of the whole line wins. Ties fall to the
|
|
285
|
+
* spelling {@link spellPitchClass} would have chosen alone, so the answer never
|
|
286
|
+
* drifts from the theory layer without a reason.
|
|
287
|
+
*
|
|
288
|
+
* Four rules decide, in this order:
|
|
289
|
+
*
|
|
290
|
+
* 1. A note the sounding chord names takes that chord's spelling of it, even
|
|
291
|
+
* when the key spells the pitch otherwise — the seventh of a Db7 reads Cb in
|
|
292
|
+
* C major, not B.
|
|
293
|
+
* 2. Anything else the key spells as its own — a scale tone, or the raised
|
|
294
|
+
* sixth and seventh of a minor key — keeps its key spelling, so the leading
|
|
295
|
+
* tone of A minor reads G# even where the line falls through it.
|
|
296
|
+
* 3. A chromatic note is spelled so the written intervals around it match the
|
|
297
|
+
* sounding ones, and then so a rising step carries a sharp and a falling
|
|
298
|
+
* step a flat.
|
|
299
|
+
* 4. Failing all of that, the key's own chromatic spelling stands, and the
|
|
300
|
+
* fewest accidentals win.
|
|
301
|
+
*
|
|
302
|
+
* Without a timeline — pass `null` — rules 2 to 4 still apply in full, so a
|
|
303
|
+
* diatonic line and a chromatic run come out the same. What is lost is rule 1:
|
|
304
|
+
* a chromatic chord can no longer name its own tones, so the tones of a
|
|
305
|
+
* borrowed or altered chord fall back to the key's convention (that Cb becomes
|
|
306
|
+
* B), and an enharmonically ambiguous tone under a chord that would have fixed
|
|
307
|
+
* it is decided by the line's direction instead.
|
|
308
|
+
*
|
|
309
|
+
* @param notes The line, monophonic and in time order. Notes sharing an onset
|
|
310
|
+
* are read as consecutive, so split polyphonic material into voices first.
|
|
311
|
+
* @param timeline The chords sounding under the line, or null when only the key
|
|
312
|
+
* is known. Each note is judged against the chord at its own onset.
|
|
313
|
+
* @param key The key the line is written in, as a key name, a key/scale, or a
|
|
314
|
+
* `Key`.
|
|
315
|
+
* @param opts Optional tonic spelling and work budget.
|
|
316
|
+
* @returns One spelled note per input note, in input order, each carrying the
|
|
317
|
+
* octave that reproduces its pitch.
|
|
318
|
+
* @throws If `opts.tonic` does not sound the key's root pitch class, if a note
|
|
319
|
+
* event is malformed, or if the line is longer than the budget allows.
|
|
320
|
+
* @example
|
|
321
|
+
* ```ts
|
|
322
|
+
* import { chordTimelineFromChords, majorKey, noteNames, spellLine } from '@libraz/libcantus';
|
|
323
|
+
* // A chromatic ascent spells with sharps, whatever the key would say alone.
|
|
324
|
+
* const rising = [60, 61, 62, 63, 64].map((pitch, index) => ({
|
|
325
|
+
* pitch,
|
|
326
|
+
* startBeat: index,
|
|
327
|
+
* durationBeat: 1,
|
|
328
|
+
* }));
|
|
329
|
+
* noteNames(spellLine(rising, null, majorKey(0)));
|
|
330
|
+
* // ['C4', 'C#4', 'D4', 'D#4', 'E4']
|
|
331
|
+
* // Under a Db7 the same B sounds as the chord's seventh.
|
|
332
|
+
* const timeline = chordTimelineFromChords([{ rootPc: 1, quality: 'dom7', startBeat: 0 }], 4);
|
|
333
|
+
* noteNames(spellLine([{ pitch: 71, startBeat: 0, durationBeat: 1 }], timeline, majorKey(0)));
|
|
334
|
+
* // ['Cb5']
|
|
335
|
+
* ```
|
|
336
|
+
* @category Arrangement & Analysis
|
|
337
|
+
*/
|
|
338
|
+
declare function spellLine(notes: readonly NoteEvent[], timeline: ChordTimeline | null, key: SpelledKeyLike, opts?: SpellLineOptions): Note[];
|
|
339
|
+
|
|
340
|
+
export { ChordTimeline, MelodicPhrase, Note as NoteData, NoteEvent, NoteLike, ReferenceProfile, SpelledKeyLike, assertReferenceProfile, compareMelodies, compareReferences, melodicSimilarity, spellLine };
|
|
341
|
+
export type { MelodicComparison, ReferenceComparison, ReferenceComparisonOptions, SpellLineOptions };
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CADENCE_TYPES,
|
|
3
|
+
HARMONIC_FUNCTIONS,
|
|
4
|
+
MELODIC_CONTOUR_SHAPES,
|
|
5
|
+
MODAL_SCALE_NAMES,
|
|
6
|
+
MOTIF_RELATION_KINDS,
|
|
7
|
+
NoteSafety,
|
|
8
|
+
REDUCTION_LEVELS,
|
|
9
|
+
REFERENCE_PROFILE_VERSION,
|
|
10
|
+
RHYTHM_IOI_BINS,
|
|
11
|
+
analyzeArrangement,
|
|
12
|
+
analyzeChord,
|
|
13
|
+
analyzePolyphony,
|
|
14
|
+
analyzeReference,
|
|
15
|
+
analyzeRhythm,
|
|
16
|
+
analyzeVoice,
|
|
17
|
+
assertChordTimeline,
|
|
18
|
+
assertReferenceProfile,
|
|
19
|
+
augmentedSixthChord,
|
|
20
|
+
augmentedSixthFromPitchClasses,
|
|
21
|
+
augmentedSixthKind,
|
|
22
|
+
borrowedSource,
|
|
23
|
+
chordTimelineFromChords,
|
|
24
|
+
chordTimelineFromNotes,
|
|
25
|
+
chordToRoman,
|
|
26
|
+
compareMelodies,
|
|
27
|
+
compareReferences,
|
|
28
|
+
createArrangementSession,
|
|
29
|
+
detectCadence,
|
|
30
|
+
detectCadences,
|
|
31
|
+
detectChord,
|
|
32
|
+
detectChordBest,
|
|
33
|
+
detectKey,
|
|
34
|
+
detectKeyBest,
|
|
35
|
+
detectKeyFromNotes,
|
|
36
|
+
detectModulations,
|
|
37
|
+
explainRoman,
|
|
38
|
+
extractMotifs,
|
|
39
|
+
functionOf,
|
|
40
|
+
hypermeter,
|
|
41
|
+
isBorrowedChord,
|
|
42
|
+
isDiatonic,
|
|
43
|
+
isMinorKey,
|
|
44
|
+
keyTimelineFromNotes,
|
|
45
|
+
melodicContour,
|
|
46
|
+
melodicSimilarity,
|
|
47
|
+
motifFromNotes,
|
|
48
|
+
motifGraph,
|
|
49
|
+
phrasesFromTimeline,
|
|
50
|
+
pivotChords,
|
|
51
|
+
prevailingKeyOf,
|
|
52
|
+
reduceProgression,
|
|
53
|
+
relateMotifs,
|
|
54
|
+
romanToChord,
|
|
55
|
+
secondaryDominant,
|
|
56
|
+
secondaryDominantOf,
|
|
57
|
+
sectionsFromNotes,
|
|
58
|
+
spellAugmentedSixth,
|
|
59
|
+
spellLine,
|
|
60
|
+
structuralCadences,
|
|
61
|
+
tensionCurve,
|
|
62
|
+
tensionCurveFrom,
|
|
63
|
+
toVoiceNotes
|
|
64
|
+
} from "../chunk-4LABHUBW.js";
|
|
65
|
+
export {
|
|
66
|
+
CADENCE_TYPES,
|
|
67
|
+
HARMONIC_FUNCTIONS,
|
|
68
|
+
MELODIC_CONTOUR_SHAPES,
|
|
69
|
+
MODAL_SCALE_NAMES,
|
|
70
|
+
MOTIF_RELATION_KINDS,
|
|
71
|
+
NoteSafety,
|
|
72
|
+
REDUCTION_LEVELS,
|
|
73
|
+
REFERENCE_PROFILE_VERSION,
|
|
74
|
+
RHYTHM_IOI_BINS,
|
|
75
|
+
analyzeArrangement,
|
|
76
|
+
analyzeChord,
|
|
77
|
+
analyzePolyphony,
|
|
78
|
+
analyzeReference,
|
|
79
|
+
analyzeRhythm,
|
|
80
|
+
analyzeVoice,
|
|
81
|
+
assertChordTimeline,
|
|
82
|
+
assertReferenceProfile,
|
|
83
|
+
augmentedSixthChord,
|
|
84
|
+
augmentedSixthFromPitchClasses,
|
|
85
|
+
augmentedSixthKind,
|
|
86
|
+
borrowedSource,
|
|
87
|
+
chordTimelineFromChords,
|
|
88
|
+
chordTimelineFromNotes,
|
|
89
|
+
chordToRoman,
|
|
90
|
+
compareMelodies,
|
|
91
|
+
compareReferences,
|
|
92
|
+
createArrangementSession,
|
|
93
|
+
detectCadence,
|
|
94
|
+
detectCadences,
|
|
95
|
+
detectChord,
|
|
96
|
+
detectChordBest,
|
|
97
|
+
detectKey,
|
|
98
|
+
detectKeyBest,
|
|
99
|
+
detectKeyFromNotes,
|
|
100
|
+
detectModulations,
|
|
101
|
+
explainRoman,
|
|
102
|
+
extractMotifs,
|
|
103
|
+
functionOf,
|
|
104
|
+
hypermeter,
|
|
105
|
+
isBorrowedChord,
|
|
106
|
+
isDiatonic,
|
|
107
|
+
isMinorKey,
|
|
108
|
+
keyTimelineFromNotes,
|
|
109
|
+
melodicContour,
|
|
110
|
+
melodicSimilarity,
|
|
111
|
+
motifFromNotes,
|
|
112
|
+
motifGraph,
|
|
113
|
+
phrasesFromTimeline,
|
|
114
|
+
pivotChords,
|
|
115
|
+
prevailingKeyOf,
|
|
116
|
+
reduceProgression,
|
|
117
|
+
relateMotifs,
|
|
118
|
+
romanToChord,
|
|
119
|
+
secondaryDominant,
|
|
120
|
+
secondaryDominantOf,
|
|
121
|
+
sectionsFromNotes,
|
|
122
|
+
spellAugmentedSixth,
|
|
123
|
+
spellLine,
|
|
124
|
+
structuralCadences,
|
|
125
|
+
tensionCurve,
|
|
126
|
+
tensionCurveFrom,
|
|
127
|
+
toVoiceNotes
|
|
128
|
+
};
|
package/dist/backend.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// bindings/wasm/src/calls.ts
|
|
2
|
+
var HOST_FAILED = 1;
|
|
3
|
+
var LONE_SURROGATE = /\p{Cs}/u;
|
|
4
|
+
var OUT_PARAMS_SIZE = 8;
|
|
5
|
+
var encoder = new TextEncoder();
|
|
6
|
+
var decoder = new TextDecoder();
|
|
7
|
+
function wtf8(s) {
|
|
8
|
+
if (!LONE_SURROGATE.test(s)) return encoder.encode(s);
|
|
9
|
+
const bytes = [];
|
|
10
|
+
for (let i = 0; i < s.length; i += 1) {
|
|
11
|
+
let c = s.charCodeAt(i);
|
|
12
|
+
if (c >= 55296 && c <= 56319 && i + 1 < s.length) {
|
|
13
|
+
const next = s.charCodeAt(i + 1);
|
|
14
|
+
if (next >= 56320 && next <= 57343) {
|
|
15
|
+
c = 65536 + (c - 55296 << 10) + (next - 56320);
|
|
16
|
+
i += 1;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (c < 128) {
|
|
20
|
+
bytes.push(c);
|
|
21
|
+
} else if (c < 2048) {
|
|
22
|
+
bytes.push(192 | c >> 6, 128 | c & 63);
|
|
23
|
+
} else if (c < 65536) {
|
|
24
|
+
bytes.push(224 | c >> 12, 128 | c >> 6 & 63, 128 | c & 63);
|
|
25
|
+
} else {
|
|
26
|
+
bytes.push(
|
|
27
|
+
240 | c >> 18,
|
|
28
|
+
128 | c >> 12 & 63,
|
|
29
|
+
128 | c >> 6 & 63,
|
|
30
|
+
128 | c & 63
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return Uint8Array.from(bytes);
|
|
35
|
+
}
|
|
36
|
+
function wasmBackend(wasm2) {
|
|
37
|
+
function allocate(size) {
|
|
38
|
+
const ptr = wasm2._malloc(size);
|
|
39
|
+
if (ptr === 0) throw new RangeError("libcantus wasm: out of memory");
|
|
40
|
+
return ptr;
|
|
41
|
+
}
|
|
42
|
+
function store(s) {
|
|
43
|
+
const bytes = wtf8(s);
|
|
44
|
+
const ptr = allocate(Math.max(bytes.length, 1));
|
|
45
|
+
wasm2.HEAPU8.set(bytes, ptr);
|
|
46
|
+
return { ptr, len: bytes.length };
|
|
47
|
+
}
|
|
48
|
+
function load(ptr, len) {
|
|
49
|
+
return decoder.decode(wasm2.HEAPU8.subarray(ptr, ptr + len));
|
|
50
|
+
}
|
|
51
|
+
const frames = [];
|
|
52
|
+
const trampoline = wasm2.addFunction(
|
|
53
|
+
(ctx, id, argsPtr, argsLen, outPtr, lenPtr) => {
|
|
54
|
+
const frame = frames[ctx];
|
|
55
|
+
if (frame === void 0) return HOST_FAILED;
|
|
56
|
+
let out;
|
|
57
|
+
try {
|
|
58
|
+
const result = frame.cb(id, load(argsPtr, argsLen));
|
|
59
|
+
if (result === void 0) return HOST_FAILED;
|
|
60
|
+
out = store(result);
|
|
61
|
+
} catch {
|
|
62
|
+
return HOST_FAILED;
|
|
63
|
+
}
|
|
64
|
+
frame.buffers.push(out.ptr);
|
|
65
|
+
wasm2.HEAPU32[outPtr >>> 2] = out.ptr;
|
|
66
|
+
wasm2.HEAPU32[lenPtr >>> 2] = out.len;
|
|
67
|
+
return 0;
|
|
68
|
+
},
|
|
69
|
+
"iiiiiii"
|
|
70
|
+
);
|
|
71
|
+
return {
|
|
72
|
+
call(op, argsJson, cb) {
|
|
73
|
+
let name = 0;
|
|
74
|
+
let args = 0;
|
|
75
|
+
let out = 0;
|
|
76
|
+
let frame;
|
|
77
|
+
try {
|
|
78
|
+
const storedName = store(op);
|
|
79
|
+
name = storedName.ptr;
|
|
80
|
+
const storedArgs = store(argsJson);
|
|
81
|
+
args = storedArgs.ptr;
|
|
82
|
+
out = allocate(OUT_PARAMS_SIZE);
|
|
83
|
+
let ctx = 0;
|
|
84
|
+
if (cb !== null) {
|
|
85
|
+
frame = { cb, buffers: [] };
|
|
86
|
+
ctx = frames.length;
|
|
87
|
+
frames.push(frame);
|
|
88
|
+
}
|
|
89
|
+
const status = wasm2._cantus_call(
|
|
90
|
+
name,
|
|
91
|
+
storedName.len,
|
|
92
|
+
args,
|
|
93
|
+
storedArgs.len,
|
|
94
|
+
cb === null ? 0 : trampoline,
|
|
95
|
+
ctx,
|
|
96
|
+
out,
|
|
97
|
+
out + 4
|
|
98
|
+
);
|
|
99
|
+
const ptr = wasm2.HEAPU32[out >>> 2];
|
|
100
|
+
const len = wasm2.HEAPU32[out + 4 >>> 2];
|
|
101
|
+
if (ptr === 0) {
|
|
102
|
+
return {
|
|
103
|
+
status,
|
|
104
|
+
json: '{"code":"INTERNAL","name":"Error","message":"cantus_call returned no output"}'
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
return { status, json: load(ptr, len) };
|
|
109
|
+
} finally {
|
|
110
|
+
wasm2._cantus_free(ptr);
|
|
111
|
+
}
|
|
112
|
+
} finally {
|
|
113
|
+
if (frame !== void 0) {
|
|
114
|
+
frames.pop();
|
|
115
|
+
for (const p of frame.buffers) wasm2._free(p);
|
|
116
|
+
}
|
|
117
|
+
if (out !== 0) wasm2._free(out);
|
|
118
|
+
if (args !== 0) wasm2._free(args);
|
|
119
|
+
if (name !== 0) wasm2._free(name);
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
release(handle) {
|
|
123
|
+
wasm2._cantus_release(BigInt(handle));
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// bindings/wasm/src/backend.ts
|
|
129
|
+
import createCantusModule from "./cantus.js";
|
|
130
|
+
var ABI_VERSION = 1;
|
|
131
|
+
var wasm = await createCantusModule();
|
|
132
|
+
if (wasm._cantus_abi_version() !== ABI_VERSION) {
|
|
133
|
+
throw new Error(
|
|
134
|
+
`libcantus wasm reports ABI version ${wasm._cantus_abi_version()}, expected ${ABI_VERSION}`
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
var backend = wasmBackend(wasm);
|
|
138
|
+
export {
|
|
139
|
+
backend
|
|
140
|
+
};
|