@libraz/libcantus-wasm 0.0.0-stage → 1.4.1
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 +75 -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-6X5QS3NE.js +6941 -0
- package/dist/coerce-Cr9AZsTY.d.ts +1322 -0
- package/dist/core/index.d.ts +293 -0
- package/dist/core/index.js +224 -0
- package/dist/generate/index.d.ts +810 -0
- package/dist/generate/index.js +150 -0
- package/dist/index-C1dnzRkt.d.ts +2902 -0
- package/dist/index-C9MYbuKS.d.ts +804 -0
- package/dist/index-CBQLVwv_.d.ts +64 -0
- package/dist/index-COyI6W_w.d.ts +1363 -0
- package/dist/index-Cbs3SQe9.d.ts +665 -0
- package/dist/index-DInQqT8Q.d.ts +66 -0
- package/dist/index-wE8SecK5.d.ts +515 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +802 -0
- package/dist/masks-BDxvQO8b.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-kmJqJ3aO.d.ts +1508 -0
- package/dist/theory/index.d.ts +990 -0
- package/dist/theory/index.js +288 -0
- package/dist/types-DPPzRpc3.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-wE8SecK5.js';
|
|
4
|
+
import { r as SpelledKeyLike } from '../coerce-Cr9AZsTY.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-Cr9AZsTY.js';
|
|
6
|
+
export { r as ScaleName } from '../masks-BDxvQO8b.js';
|
|
7
|
+
import { w as MelodicPhrase, a5 as ReferenceProfile, h as ChordTimeline } from '../types-DPPzRpc3.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-DPPzRpc3.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-kmJqJ3aO.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-6X5QS3NE.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
|
+
};
|
package/dist/cantus.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
async function createCantusModule(moduleArg={}){var Module=moduleArg;var ENVIRONMENT_IS_WEB=!!globalThis.window;var ENVIRONMENT_IS_WORKER=!!globalThis.WorkerGlobalScope;var ENVIRONMENT_IS_NODE=globalThis.process?.versions?.node&&globalThis.process?.type!="renderer";if(ENVIRONMENT_IS_NODE){const{createRequire}=await import(/* webpackIgnore: true */ /* @vite-ignore */ ["node:module"][0]);var require=createRequire(import.meta.url)}var programArgs=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var _scriptName=import.meta.url;var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("node:fs");if(_scriptName.startsWith("file:")){scriptDirectory=require("node:path").dirname(require("node:url").fileURLToPath(_scriptName))+"/"}readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename);return ret};readAsync=async(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename,binary?undefined:"utf8");return ret};if(process.argv.length>1){thisProgram=process.argv[1].replace(/\\/g,"/")}programArgs=process.argv.slice(2);quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){try{scriptDirectory=new URL(".",_scriptName).href}catch{}{if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}readAsync=async url=>{var response=await fetch(url,{credentials:"same-origin"});if(response.ok){return response.arrayBuffer()}throw new Error(response.status+" : "+response.url)}}}else{}var out=console.log.bind(console);var err=console.error.bind(console);var wasmBinary;var ABORT=false;var isFileURI=filename=>filename.startsWith("file://");var runtimeInitialized=false;function getMemoryBuffer(){return wasmMemory.buffer}function updateMemoryViews(){if(HEAP8?.buffer?.resizable)return;var b=getMemoryBuffer();HEAP8=new Int8Array(b);HEAP16=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);HEAPU16=new Uint16Array(b);HEAP32=new Int32Array(b);Module["HEAPU32"]=HEAPU32=new Uint32Array(b);HEAPF32=new Float32Array(b);HEAPF64=new Float64Array(b);HEAP64=new BigInt64Array(b);HEAPU64=new BigUint64Array(b)}function preRun(){var preRun=Module["preRun"];if(preRun){if(typeof preRun=="function")preRun=[preRun];onPreRuns.push(...preRun)}callRuntimeCallbacks(onPreRuns)}function initRuntime(){runtimeInitialized=true;wasmExports["f"]()}function postRun(){var postRun=Module["postRun"];if(postRun){if(typeof postRun=="function")postRun=[postRun];onPostRuns.push(...postRun)}callRuntimeCallbacks(onPostRuns)}function abort(what){Module["onAbort"]?.(what);what=`Aborted(${what})`;err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";if(runtimeInitialized){___trap()}var e=new WebAssembly.RuntimeError(what);throw e}var wasmBinaryFile;function findWasmBinary(){if(Module["locateFile"]){return locateFile("cantus.wasm")}return new URL("cantus.wasm",import.meta.url).href}function getBinarySync(file){if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(!wasmBinary){try{var response=await readAsync(binaryFile);return new Uint8Array(response)}catch{}}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary&&!ENVIRONMENT_IS_NODE){try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation")}}return instantiateArrayBuffer(binaryFile,imports)}function getWasmImports(){var imports={a:wasmImports};return imports}async function createWasm(){function receiveInstance(instance){wasmExports=instance.exports;assignWasmExports(wasmExports);updateMemoryViews();return wasmExports}function receiveInstantiationResult(result){return receiveInstance(result["instance"])}var info=getWasmImports();var instantiateWasm=Module["instantiateWasm"];if(instantiateWasm){return new Promise(resolve=>{instantiateWasm(info,inst=>resolve(receiveInstance(inst)))})}wasmBinaryFile??=findWasmBinary();var result=await instantiateAsync(wasmBinary,wasmBinaryFile,info);var exports=receiveInstantiationResult(result);return exports}class ExitStatus{name="ExitStatus";constructor(status){this.message=`Program terminated with exit(${status})`;this.status=status}}var HEAP16;var HEAP32;var HEAP64;var HEAP8;var HEAPF32;var HEAPF64;var HEAPU16;var HEAPU32;var HEAPU64;var HEAPU8;var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};var onPostRuns=[];var onPreRuns=[];var noExitRuntime=true;var __abort_js=()=>abort("");var getHeapMax=()=>2147483648;var alignMemory=(size,alignment)=>Math.ceil(size/alignment)*alignment;var growMemory=size=>{var oldHeapSize=wasmMemory.buffer.byteLength;var pages=(size-oldHeapSize+65535)/65536|0;try{wasmMemory.grow(pages);updateMemoryViews();return 1}catch(e){}};var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignMemory(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=growMemory(newSize);if(replacement){return true}}return false};var ENV={};var getExecutableName=()=>thisProgram;var getEnvStrings=()=>{if(!getEnvStrings.strings){var lang=(globalThis.navigator?.language??"C").replace("-","_")+".UTF-8";var env={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:lang,_:getExecutableName()};for(var x in ENV){if(ENV[x]===undefined)delete env[x];else env[x]=ENV[x]}var strings=[];for(var x in env){strings.push(`${x}=${env[x]}`)}getEnvStrings.strings=strings}return getEnvStrings.strings};var stringToUTF8Array=(str,heap,outIdx,maxBytesToWrite)=>{if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i<str.length;++i){var u=str.codePointAt(i);if(u<=127){if(outIdx>=endIdx)break;heap[outIdx++]=u}else if(u<=2047){if(outIdx+1>=endIdx)break;heap[outIdx++]=192|u>>6;heap[outIdx++]=128|u&63}else if(u<=65535){if(outIdx+2>=endIdx)break;heap[outIdx++]=224|u>>12;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}else{if(outIdx+3>=endIdx)break;heap[outIdx++]=240|u>>18;heap[outIdx++]=128|u>>12&63;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63;i++}}heap[outIdx]=0;return outIdx-startIdx};var stringToUTF8=(str,outPtr,maxBytesToWrite)=>stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite);var _environ_get=(__environ,environ_buf)=>{var bufSize=0;var envp=0;for(var string of getEnvStrings()){var ptr=environ_buf+bufSize;HEAPU32[__environ+envp>>2]=ptr;bufSize+=stringToUTF8(string,ptr,Infinity)+1;envp+=4}return 0};var lengthBytesUTF8=str=>{var len=0;for(var i=0;i<str.length;++i){var c=str.charCodeAt(i);if(c<=127){len++}else if(c<=2047){len+=2}else if(c>=55296&&c<=57343){len+=4;++i}else{len+=3}}return len};var _environ_sizes_get=(penviron_count,penviron_buf_size)=>{var strings=getEnvStrings();HEAPU32[penviron_count>>2]=strings.length;var bufSize=0;for(var string of strings){bufSize+=lengthBytesUTF8(string)+1}HEAPU32[penviron_buf_size>>2]=bufSize;return 0};var getWasmTableEntry=funcPtr=>wasmTable.get(funcPtr);var updateTableMap=(offset,count)=>{if(functionsInTableMap){for(var i=offset;i<offset+count;i++){var item=getWasmTableEntry(i);if(item){functionsInTableMap.set(item,i)}}}};var functionsInTableMap;var getFunctionAddress=func=>{if(!functionsInTableMap){functionsInTableMap=new WeakMap;updateTableMap(0,wasmTable.length)}return functionsInTableMap.get(func)||0};var freeTableIndexes=[];var getEmptyTableSlot=()=>{if(freeTableIndexes.length){return freeTableIndexes.pop()}return wasmTable["grow"](1)};var setWasmTableEntry=(idx,func)=>wasmTable.set(idx,func);var uleb128EncodeWithLen=arr=>{const n=arr.length;return[n%128|128,n>>7,...arr]};var wasmTypeCodes={i:127,p:127,j:126,f:125,d:124,e:111};var generateTypePack=types=>uleb128EncodeWithLen(Array.from(types,type=>{var code=wasmTypeCodes[type];return code}));var convertJsFunctionToWasm=(func,sig)=>{var bytes=Uint8Array.of(0,97,115,109,1,0,0,0,1,...uleb128EncodeWithLen([1,96,...generateTypePack(sig.slice(1)),...generateTypePack(sig[0]==="v"?"":sig[0])]),2,7,1,1,101,1,102,0,0,7,5,1,1,102,0,0);var module=new WebAssembly.Module(bytes);var instance=new WebAssembly.Instance(module,{e:{f:func}});var wrappedFunc=instance.exports["f"];return wrappedFunc};var addFunction=(func,sig)=>{var rtn=getFunctionAddress(func);if(rtn){return rtn}var ret=getEmptyTableSlot();try{setWasmTableEntry(ret,func)}catch(err){if(!(err instanceof TypeError)){throw err}var wrapped=convertJsFunctionToWasm(func,sig);setWasmTableEntry(ret,wrapped)}functionsInTableMap.set(func,ret);return ret};{if(Module["noExitRuntime"])noExitRuntime=Module["noExitRuntime"];if(Module["print"])out=Module["print"];if(Module["printErr"])err=Module["printErr"];if(Module["arguments"])programArgs=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];var preInit=Module["preInit"];if(preInit){if(typeof preInit=="function")Module["preInit"]=preInit=[preInit];while(preInit.length>0){preInit.shift()()}}}Module["addFunction"]=addFunction;var _cantus_call,_cantus_free,_cantus_release,_cantus_version,_cantus_algorithm_version,_cantus_abi_version,_cantus_list_ops,_malloc,_free,___trap,memory,__indirect_function_table,wasmMemory,wasmTable;function assignWasmExports(wasmExports){_cantus_call=Module["_cantus_call"]=wasmExports["g"];_cantus_free=Module["_cantus_free"]=wasmExports["h"];_cantus_release=Module["_cantus_release"]=wasmExports["i"];_cantus_version=Module["_cantus_version"]=wasmExports["j"];_cantus_algorithm_version=Module["_cantus_algorithm_version"]=wasmExports["k"];_cantus_abi_version=Module["_cantus_abi_version"]=wasmExports["l"];_cantus_list_ops=Module["_cantus_list_ops"]=wasmExports["m"];_malloc=Module["_malloc"]=wasmExports["n"];_free=Module["_free"]=wasmExports["o"];___trap=wasmExports["p"];memory=wasmMemory=wasmExports["e"];__indirect_function_table=wasmTable=wasmExports["q"]}var wasmImports={c:__abort_js,d:_emscripten_resize_heap,a:_environ_get,b:_environ_sizes_get};async function run(){preRun();var setStatus=Module["setStatus"];if(setStatus){setStatus("Running...");await new Promise(resolve=>setTimeout(resolve,1));setTimeout(setStatus,1,"")}if(ABORT)return;initRuntime();Module["onRuntimeInitialized"]?.();postRun()}var wasmExports;wasmExports=await createWasm();await run();
|
|
2
|
+
;return Module}export default createCantusModule;
|
package/dist/cantus.wasm
ADDED
|
Binary file
|