kordweb 0.5.5 → 0.5.6

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 (5) hide show
  1. package/README.md +39 -1
  2. package/klib.d.ts +371 -101
  3. package/klib.js +559 -323
  4. package/klib_bg.wasm +0 -0
  5. package/package.json +1 -1
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  # kord
11
11
 
12
- A music theory binary and library for Rust ([capability playground](https://kord.twitchax.com/)).
12
+ A music theory binary and library for Rust / JS (via WASM) ([capability playground](https://kord.twitchax.com/)).
13
13
 
14
14
  ## Binary Usage
15
15
 
@@ -44,6 +44,12 @@ Cargo:
44
44
  $ cargo install kord
45
45
  ```
46
46
 
47
+ NPM:
48
+
49
+ ```bash
50
+ $ npm install --save kordweb
51
+ ```
52
+
47
53
  ### Help Docs
48
54
 
49
55
  ```bash
@@ -193,6 +199,38 @@ use klib::chord::*;
193
199
  assert_eq!(C.into_chord().augmented().major7().chord(), vec![C, E, GSharp, B]);
194
200
  ```
195
201
 
202
+ ## JS Usage
203
+
204
+ The npm package is available [here](https://www.npmjs.com/package/kordweb).
205
+
206
+ First, load the module as you would any other ES module.
207
+
208
+ ```js
209
+ import init, { KordNote, KordChord } from 'kordweb/klib.js';
210
+
211
+ // Run `init` once.
212
+ await init();
213
+ ```
214
+
215
+ Then, you can use the library similarly as you would in Rust.
216
+
217
+ ```js
218
+ // Create a note.
219
+ const note = KordNote.parse('C4');
220
+
221
+ note.name(); // C4
222
+ note.octave(); // 4
223
+
224
+ // Create a chord.
225
+ const chord = KordChord.parse('C7#9');
226
+
227
+ chord.name(); // C7(♯9)
228
+ chord.chordString(); // C4 E4 G4 Bb5 D#5
229
+
230
+ // Easy chaining.
231
+ KordChord.parse("C7b9").withOctave(2).chord().map(n => n.name()); // [ 'C2', 'D♭2', 'E2', 'G2', 'B♭2' ]
232
+ ```
233
+
196
234
  ## Feature Flags
197
235
 
198
236
  The library and binary both support various feature flags. Of most important note are:
package/klib.d.ts CHANGED
@@ -1,6 +1,313 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  /**
4
+ * The main entrypoint which sets up global state.
5
+ */
6
+ export function main(): void;
7
+ /**
8
+ * An enum representing the interval between two notes.
9
+ */
10
+ export enum KordInterval {
11
+ /**
12
+ * A perfect unison interval.
13
+ */
14
+ PerfectUnison = 0,
15
+ /**
16
+ * A diminished second interval.
17
+ */
18
+ DiminishedSecond = 1,
19
+ /**
20
+ * An augmented unison interval.
21
+ */
22
+ AugmentedUnison = 2,
23
+ /**
24
+ * A minor second interval.
25
+ */
26
+ MinorSecond = 3,
27
+ /**
28
+ * A major second interval.
29
+ */
30
+ MajorSecond = 4,
31
+ /**
32
+ * A diminished third interval.
33
+ */
34
+ DiminishedThird = 5,
35
+ /**
36
+ * An augmented second interval.
37
+ */
38
+ AugmentedSecond = 6,
39
+ /**
40
+ * A minor third interval.
41
+ */
42
+ MinorThird = 7,
43
+ /**
44
+ * A major third interval.
45
+ */
46
+ MajorThird = 8,
47
+ /**
48
+ * A diminished fourth interval.
49
+ */
50
+ DiminishedFourth = 9,
51
+ /**
52
+ * An augmented third interval.
53
+ */
54
+ AugmentedThird = 10,
55
+ /**
56
+ * A perfect fourth interval.
57
+ */
58
+ PerfectFourth = 11,
59
+ /**
60
+ * An augmented fourth interval.
61
+ */
62
+ AugmentedFourth = 12,
63
+ /**
64
+ * A diminished fifth interval.
65
+ */
66
+ DiminishedFifth = 13,
67
+ /**
68
+ * A perfect fifth interval.
69
+ */
70
+ PerfectFifth = 14,
71
+ /**
72
+ * A diminished sixth interval.
73
+ */
74
+ DiminishedSixth = 15,
75
+ /**
76
+ * An augmented fifth interval.
77
+ */
78
+ AugmentedFifth = 16,
79
+ /**
80
+ * A minor sixth interval.
81
+ */
82
+ MinorSixth = 17,
83
+ /**
84
+ * A major sixth interval.
85
+ */
86
+ MajorSixth = 18,
87
+ /**
88
+ * A diminished seventh interval.
89
+ */
90
+ DiminishedSeventh = 19,
91
+ /**
92
+ * An augmented sixth interval.
93
+ */
94
+ AugmentedSixth = 20,
95
+ /**
96
+ * A minor seventh interval.
97
+ */
98
+ MinorSeventh = 21,
99
+ /**
100
+ * A major seventh interval.
101
+ */
102
+ MajorSeventh = 22,
103
+ /**
104
+ * A diminished octave interval.
105
+ */
106
+ DiminishedOctave = 23,
107
+ /**
108
+ * An augmented seventh interval.
109
+ */
110
+ AugmentedSeventh = 24,
111
+ /**
112
+ * A perfect octave interval.
113
+ */
114
+ PerfectOctave = 25,
115
+ /**
116
+ * An minor ninth interval.
117
+ */
118
+ MinorNinth = 26,
119
+ /**
120
+ * A major ninth interval.
121
+ */
122
+ MajorNinth = 27,
123
+ /**
124
+ * An augmented ninth interval.
125
+ */
126
+ AugmentedNinth = 28,
127
+ /**
128
+ * A diminished eleventh interval.
129
+ */
130
+ DiminishedEleventh = 29,
131
+ /**
132
+ * A perfect eleventh interval.
133
+ */
134
+ PerfectEleventh = 30,
135
+ /**
136
+ * An augmented eleventh interval.
137
+ */
138
+ AugmentedEleventh = 31,
139
+ /**
140
+ * A minor thirteenth interval.
141
+ */
142
+ MinorThirteenth = 32,
143
+ /**
144
+ * A major thirteenth interval.
145
+ */
146
+ MajorThirteenth = 33,
147
+ /**
148
+ * An augmented thirteenth interval.
149
+ */
150
+ AugmentedThirteenth = 34,
151
+ /**
152
+ * A perfect octave and perfect fifth interval.
153
+ */
154
+ PerfectOctaveAndPerfectFifth = 35,
155
+ /**
156
+ * Two perfect octaves.
157
+ */
158
+ TwoPerfectOctaves = 36,
159
+ /**
160
+ * Two perfect octaves and a major third.
161
+ */
162
+ TwoPerfectOctavesAndMajorThird = 37,
163
+ /**
164
+ * Two perfect octaves and a perfect fifth.
165
+ */
166
+ TwoPerfectOctavesAndPerfectFifth = 38,
167
+ /**
168
+ * Two perfect octaves and a minor sixth.
169
+ */
170
+ TwoPerfectOctavesAndMinorSeventh = 39,
171
+ /**
172
+ * Three perfect octaves.
173
+ */
174
+ ThreePerfectOctaves = 40,
175
+ /**
176
+ * Three perfect octaves and a major second.
177
+ */
178
+ ThreePerfectOctavesAndMajorSecond = 41,
179
+ /**
180
+ * Three perfect octaves and a major third.
181
+ */
182
+ ThreePerfectOctavesAndMajorThird = 42,
183
+ /**
184
+ * Three perfect octaves and an augmented fourth.
185
+ */
186
+ ThreePerfectOctavesAndAugmentedFourth = 43,
187
+ /**
188
+ * Three perfect octaves and a perfect fifth.
189
+ */
190
+ ThreePerfectOctavesAndPerfectFifth = 44,
191
+ /**
192
+ * Three perfect octaves and a minor sixth.
193
+ */
194
+ ThreePerfectOctavesAndMinorSixth = 45,
195
+ /**
196
+ * Three perfect octaves and a minor seventh.
197
+ */
198
+ ThreePerfectOctavesAndMinorSeventh = 46,
199
+ /**
200
+ * Three perfect octaves and a major seventh.
201
+ */
202
+ ThreePerfectOctavesAndMajorSeventh = 47,
203
+ }
204
+ /**
205
+ * The chord modifiers.
206
+ */
207
+ export enum KordModifier {
208
+ /**
209
+ * Minor modifier.
210
+ */
211
+ Minor = 0,
212
+ /**
213
+ * Flat 5 modifier.
214
+ */
215
+ Flat5 = 1,
216
+ /**
217
+ * Sharp 5 modifier.
218
+ */
219
+ Augmented5 = 2,
220
+ /**
221
+ * Major 7 modifier.
222
+ */
223
+ Major7 = 3,
224
+ /**
225
+ * Dominant 7 modifier.
226
+ */
227
+ Dominant7 = 4,
228
+ /**
229
+ * Dominant 9 modifier.
230
+ */
231
+ Dominant9 = 5,
232
+ /**
233
+ * Dominant 11 modifier.
234
+ */
235
+ Dominant11 = 6,
236
+ /**
237
+ * Dominant 13 modifier.
238
+ */
239
+ Dominant13 = 7,
240
+ /**
241
+ * Flat 9 modifier.
242
+ */
243
+ Flat9 = 8,
244
+ /**
245
+ * Sharp 9 modifier.
246
+ */
247
+ Sharp9 = 9,
248
+ /**
249
+ * Sharp 11 modifier.
250
+ */
251
+ Sharp11 = 10,
252
+ /**
253
+ * Diminished modifier.
254
+ */
255
+ Diminished = 11,
256
+ }
257
+ /**
258
+ * An enum representing the extension of a chord.
259
+ *
260
+ * Extensions are not really "special" in the sense that they do not change how the
261
+ * chord is interpreted by the system. E.g., an `add2` just adds a 2 to the chord,
262
+ * and the chord is still interpreted as a major chord.
263
+ */
264
+ export enum KordExtension {
265
+ /**
266
+ * Sus2 extension.
267
+ */
268
+ Sus2 = 0,
269
+ /**
270
+ * Sus4 extension.
271
+ */
272
+ Sus4 = 1,
273
+ /**
274
+ * Flat 11 extension.
275
+ */
276
+ Flat11 = 2,
277
+ /**
278
+ * Flat 13 extension.
279
+ */
280
+ Flat13 = 3,
281
+ /**
282
+ * Sharp 13 extension.
283
+ */
284
+ Sharp13 = 4,
285
+ /**
286
+ * Add2 extension.
287
+ */
288
+ Add2 = 5,
289
+ /**
290
+ * Add4 extension.
291
+ */
292
+ Add4 = 6,
293
+ /**
294
+ * Add6 extension.
295
+ */
296
+ Add6 = 7,
297
+ /**
298
+ * Add9 extension.
299
+ */
300
+ Add9 = 8,
301
+ /**
302
+ * Add11 extension.
303
+ */
304
+ Add11 = 9,
305
+ /**
306
+ * Add13 extension.
307
+ */
308
+ Add13 = 10,
309
+ }
310
+ /**
4
311
  * The [`Chord`] wrapper.
5
312
  */
6
313
  export class KordChord {
@@ -17,15 +324,15 @@ export class KordChord {
17
324
  * The [`Note`]s should be represented as a space-separated string.
18
325
  * E.g., `C E G`.
19
326
  * @param {string} notes
20
- * @returns {KordChords}
327
+ * @returns {Array<any>}
21
328
  */
22
- static fromNotesString(notes: string): KordChords;
329
+ static fromNotesString(notes: string): Array<any>;
23
330
  /**
24
331
  * Creates a new [`Chord`] from a set of [`Note`]s.
25
- * @param {KordNotes} notes
26
- * @returns {KordChords}
332
+ * @param {Array<any>} notes
333
+ * @returns {Array<any>}
27
334
  */
28
- static fromNotes(notes: KordNotes): KordChords;
335
+ static fromNotes(notes: Array<any>): Array<any>;
29
336
  /**
30
337
  * Returns the [`Chord`]'s friendly name.
31
338
  * @returns {string}
@@ -73,9 +380,9 @@ export class KordChord {
73
380
  isCrunchy(): boolean;
74
381
  /**
75
382
  * Returns the [`Chord`]'s chord tones.
76
- * @returns {KordNotes}
383
+ * @returns {Array<any>}
77
384
  */
78
- chord(): KordNotes;
385
+ chord(): Array<any>;
79
386
  /**
80
387
  * Returns the [`Chord`]'s chord tones as a string.
81
388
  * @returns {string}
@@ -83,64 +390,61 @@ export class KordChord {
83
390
  chordString(): string;
84
391
  /**
85
392
  * Returns the [`Chord`]'s scale tones.
86
- * @returns {KordNotes}
393
+ * @returns {Array<any>}
87
394
  */
88
- scale(): KordNotes;
395
+ scale(): Array<any>;
89
396
  /**
90
397
  * Returns the [`Chord`]'s scale tones as a string.
91
398
  * @returns {string}
92
399
  */
93
400
  scaleString(): string;
94
401
  /**
95
- * Plays the [`Chord`].
96
- * @param {number} delay
97
- * @param {number} length
98
- * @param {number} fade_in
99
- * @returns {Promise<void>}
100
- */
101
- play(delay: number, length: number, fade_in: number): Promise<void>;
102
- }
103
- /**
104
- * The [`Chord`]s wrapper.
402
+ * Returns the [`Chord`]'s modifiers.
403
+ * @returns {Array<any>}
105
404
  */
106
- export class KordChords {
107
- free(): void;
405
+ modifiers(): Array<any>;
108
406
  /**
109
- * Gets an item from the collection.
110
- * @param {number} index
111
- * @returns {KordChord | undefined}
407
+ * Returns the [`Chord`]'s extensions.
408
+ * @returns {Array<any>}
112
409
  */
113
- get(index: number): KordChord | undefined;
410
+ extensions(): Array<any>;
114
411
  /**
115
- * Returns the [`Chord`]s as a space-separated string.
116
- * @returns {string}
412
+ * Returns a new [`Chord`] with the inversion set to the provided value.
413
+ * @param {number} inversion
414
+ * @returns {KordChord}
117
415
  */
118
- toString(): string;
416
+ withInversion(inversion: number): KordChord;
119
417
  /**
120
- * Returns the [`Chord`]s as an iterator.
121
- * @returns {KordChordsIterator}
418
+ * Returns a new [`Chord`] with the slash set to the provided value.
419
+ * @param {KordNote} slash
420
+ * @returns {KordChord}
122
421
  */
123
- iterator(): KordChordsIterator;
422
+ withSlash(slash: KordNote): KordChord;
124
423
  /**
125
- * Returns the [`Chord`]s as an array.
126
- * @returns {Array<any>}
424
+ * Returns a new [`Chord`] with the octave of the root set to the provided value.
425
+ * @param {number} octave
426
+ * @returns {KordChord}
127
427
  */
128
- toArray(): Array<any>;
428
+ withOctave(octave: number): KordChord;
129
429
  /**
130
- * Returns the number of items in the collection.
430
+ * Returns a new [`Chord`] with the "crunchiness" to the provided value.
431
+ * @param {boolean} is_crunchy
432
+ * @returns {KordChord}
131
433
  */
132
- readonly length: number;
133
- }
434
+ withCrunchy(is_crunchy: boolean): KordChord;
134
435
  /**
135
- * The [`Chord`]s iterator.
436
+ * Plays the [`Chord`].
437
+ * @param {number} delay
438
+ * @param {number} length
439
+ * @param {number} fade_in
440
+ * @returns {Promise<void>}
136
441
  */
137
- export class KordChordsIterator {
138
- free(): void;
442
+ play(delay: number, length: number, fade_in: number): Promise<void>;
139
443
  /**
140
- * Gets the next item in the collection.
141
- * @returns {any}
444
+ * Returns the clone of the [`Chord`].
445
+ * @returns {KordChord}
142
446
  */
143
- next(): any;
447
+ copy(): KordChord;
144
448
  }
145
449
  /**
146
450
  * The [`Note`] wrapper.
@@ -157,16 +461,16 @@ export class KordNote {
157
461
  * Returns [`Note`]s from audio data.
158
462
  * @param {Float32Array} data
159
463
  * @param {number} length_in_seconds
160
- * @returns {KordNotes}
464
+ * @returns {Array<any>}
161
465
  */
162
- static fromAudio(data: Float32Array, length_in_seconds: number): KordNotes;
466
+ static fromAudio(data: Float32Array, length_in_seconds: number): Array<any>;
163
467
  /**
164
468
  * Returns [`Note`]s from audio data using the ML inference algorithm.
165
469
  * @param {Float32Array} data
166
470
  * @param {number} length_in_seconds
167
- * @returns {KordNotes}
471
+ * @returns {Array<any>}
168
472
  */
169
- static fromAudioMl(data: Float32Array, length_in_seconds: number): KordNotes;
473
+ static fromAudioMl(data: Float32Array, length_in_seconds: number): Array<any>;
170
474
  /**
171
475
  * Returns the [`Note`]'s friendly name.
172
476
  * @returns {string}
@@ -192,48 +496,19 @@ export class KordNote {
192
496
  * @returns {number}
193
497
  */
194
498
  frequency(): number;
195
- }
196
- /**
197
- * The [`Note`]s wrapper.
198
- */
199
- export class KordNotes {
200
- free(): void;
201
- /**
202
- * Gets an item from the collection.
203
- * @param {number} index
204
- * @returns {KordNote | undefined}
205
- */
206
- get(index: number): KordNote | undefined;
207
- /**
208
- * Returns the [`Note`]s as a space-separated string.
209
- * @returns {string}
210
- */
211
- toString(): string;
212
- /**
213
- * Returns the [`Note`]s as an iterator.
214
- * @returns {KordNotesIterator}
215
- */
216
- iterator(): KordNotesIterator;
217
- /**
218
- * Returns the [`Note`]s as an array.
219
- * @returns {Array<any>}
220
- */
221
- toArray(): Array<any>;
222
499
  /**
223
- * Returns the number of items in the collection.
224
- */
225
- readonly length: number;
226
- }
227
- /**
228
- * The [`Note`]s iterator.
500
+ * Adds the given interval to the [`Note`].
501
+ *
502
+ * Clones the underlying note before mutation, producing a _new_ [`KordNote`].
503
+ * @param {number} interval
504
+ * @returns {KordNote}
229
505
  */
230
- export class KordNotesIterator {
231
- free(): void;
506
+ addInterval(interval: number): KordNote;
232
507
  /**
233
- * Gets the next item in the collection.
234
- * @returns {any}
508
+ * Returns the clone of the [`Note`].
509
+ * @returns {KordNote}
235
510
  */
236
- next(): any;
511
+ copy(): KordNote;
237
512
  }
238
513
 
239
514
  export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
@@ -249,13 +524,8 @@ export interface InitOutput {
249
524
  readonly kordnote_pitch: (a: number, b: number) => void;
250
525
  readonly kordnote_octave: (a: number) => number;
251
526
  readonly kordnote_frequency: (a: number) => number;
252
- readonly __wbg_kordnotes_free: (a: number) => void;
253
- readonly kordnotes_get: (a: number, b: number) => number;
254
- readonly kordnotes_toString: (a: number, b: number) => void;
255
- readonly kordnotes_iterator: (a: number) => number;
256
- readonly kordnotes_toArray: (a: number) => number;
257
- readonly __wbg_kordnotesiterator_free: (a: number) => void;
258
- readonly kordnotesiterator_next: (a: number, b: number) => void;
527
+ readonly kordnote_addInterval: (a: number, b: number, c: number) => void;
528
+ readonly kordnote_copy: (a: number) => number;
259
529
  readonly __wbg_kordchord_free: (a: number) => void;
260
530
  readonly kordchord_parse: (a: number, b: number, c: number) => void;
261
531
  readonly kordchord_fromNotesString: (a: number, b: number, c: number) => void;
@@ -272,17 +542,16 @@ export interface InitOutput {
272
542
  readonly kordchord_chordString: (a: number, b: number) => void;
273
543
  readonly kordchord_scale: (a: number) => number;
274
544
  readonly kordchord_scaleString: (a: number, b: number) => void;
545
+ readonly kordchord_modifiers: (a: number) => number;
546
+ readonly kordchord_extensions: (a: number) => number;
547
+ readonly kordchord_withInversion: (a: number, b: number) => number;
548
+ readonly kordchord_withSlash: (a: number, b: number) => number;
549
+ readonly kordchord_withOctave: (a: number, b: number, c: number) => void;
550
+ readonly kordchord_withCrunchy: (a: number, b: number) => number;
275
551
  readonly kordchord_play: (a: number, b: number, c: number, d: number) => number;
276
- readonly __wbg_kordchords_free: (a: number) => void;
277
- readonly kordchords_get: (a: number, b: number) => number;
278
- readonly kordchords_length: (a: number) => number;
279
- readonly kordchords_toString: (a: number, b: number) => void;
280
- readonly kordchords_iterator: (a: number) => number;
281
- readonly kordchords_toArray: (a: number) => number;
282
- readonly __wbg_kordchordsiterator_free: (a: number) => void;
283
- readonly kordchordsiterator_next: (a: number, b: number) => void;
284
- readonly kordnotes_length: (a: number) => number;
552
+ readonly kordchord_copy: (a: number) => number;
285
553
  readonly kordchord_toString: (a: number, b: number) => void;
554
+ readonly main: () => void;
286
555
  readonly __wbindgen_malloc: (a: number) => number;
287
556
  readonly __wbindgen_realloc: (a: number, b: number, c: number) => number;
288
557
  readonly __wbindgen_export_2: WebAssembly.Table;
@@ -292,6 +561,7 @@ export interface InitOutput {
292
561
  readonly __wbindgen_free: (a: number, b: number) => void;
293
562
  readonly __wbindgen_exn_store: (a: number) => void;
294
563
  readonly wasm_bindgen__convert__closures__invoke2_mut__h768f6593dd414d73: (a: number, b: number, c: number, d: number) => void;
564
+ readonly __wbindgen_start: () => void;
295
565
  }
296
566
 
297
567
  export type SyncInitInput = BufferSource | WebAssembly.Module;