@algo-wasm/algo-wasm 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/README.md +6 -4
  3. package/dist/algo-wasm-error.d.ts +13 -0
  4. package/dist/algo-wasm-player.d.ts +169 -0
  5. package/dist/algo_wasm.wasm +0 -0
  6. package/dist/built-in-profiles.d.ts +5 -0
  7. package/dist/engine-core.d.ts +96 -0
  8. package/dist/events.d.ts +5 -1
  9. package/dist/index.d.ts +3 -4
  10. package/dist/index.js +1 -6
  11. package/dist/integrations/phaser.d.ts +9 -2
  12. package/dist/integrations/phaser.js +1 -16
  13. package/dist/integrations/react.d.ts +8 -2
  14. package/dist/integrations/react.js +1 -28
  15. package/dist/integrations/svelte.d.ts +6 -2
  16. package/dist/integrations/svelte.js +1 -17
  17. package/dist/integrations/vue.d.ts +7 -2
  18. package/dist/integrations/vue.js +1 -16
  19. package/dist/load-wasm.d.ts +92 -0
  20. package/dist/profile-schema.json +317 -228
  21. package/dist/profile-spec.d.ts +178 -0
  22. package/dist/profile-wire.d.ts +50 -0
  23. package/dist/profile.d.ts +25 -1
  24. package/dist/types.d.ts +25 -1
  25. package/dist/wire-decode.d.ts +18 -0
  26. package/dist/worklet/algo-worklet.d.ts +1 -83
  27. package/dist/worklet/algo-worklet.js +1 -471
  28. package/package.json +1 -1
  29. package/dist/AlgoWasmError.d.ts +0 -8
  30. package/dist/AlgoWasmError.d.ts.map +0 -1
  31. package/dist/AlgoWasmError.js +0 -9
  32. package/dist/AlgoWasmError.js.map +0 -1
  33. package/dist/AlgoWasmPlayer.d.ts +0 -48
  34. package/dist/AlgoWasmPlayer.d.ts.map +0 -1
  35. package/dist/AlgoWasmPlayer.js +0 -375
  36. package/dist/AlgoWasmPlayer.js.map +0 -1
  37. package/dist/events.d.ts.map +0 -1
  38. package/dist/events.js +0 -25
  39. package/dist/events.js.map +0 -1
  40. package/dist/index.d.ts.map +0 -1
  41. package/dist/index.js.map +0 -1
  42. package/dist/integrations/phaser.d.ts.map +0 -1
  43. package/dist/integrations/phaser.js.map +0 -1
  44. package/dist/integrations/react.d.ts.map +0 -1
  45. package/dist/integrations/react.js.map +0 -1
  46. package/dist/integrations/svelte.d.ts.map +0 -1
  47. package/dist/integrations/svelte.js.map +0 -1
  48. package/dist/integrations/vue.d.ts.map +0 -1
  49. package/dist/integrations/vue.js.map +0 -1
  50. package/dist/loadWasm.d.ts +0 -47
  51. package/dist/loadWasm.d.ts.map +0 -1
  52. package/dist/loadWasm.js +0 -229
  53. package/dist/loadWasm.js.map +0 -1
  54. package/dist/profile.d.ts.map +0 -1
  55. package/dist/profile.js +0 -525
  56. package/dist/profile.js.map +0 -1
  57. package/dist/types.d.ts.map +0 -1
  58. package/dist/types.js +0 -2
  59. package/dist/types.js.map +0 -1
  60. package/dist/worklet/algo-worklet.d.ts.map +0 -1
  61. package/dist/worklet/algo-worklet.js.map +0 -1
@@ -1,8 +1,13 @@
1
- import type { AlgoWasmPlayer } from '../AlgoWasmPlayer.js';
1
+ import type { AlgoWasmPlayer } from '../algo-wasm-player.js';
2
2
  import type { AlgoWasmSnapshot } from '../types.js';
3
+ /** The handle returned by `createAlgoWasmVueBridge`. */
3
4
  export interface AlgoWasmVueBridge {
4
5
  snapshot: AlgoWasmSnapshot;
5
6
  dispose(): void;
6
7
  }
8
+ /**
9
+ * Calls `assign` with a fresh snapshot now and on each bar, start, and stop,
10
+ * so a Vue ref can mirror the player. Call `dispose` when the component
11
+ * unmounts to remove the listeners.
12
+ */
7
13
  export declare function createAlgoWasmVueBridge(player: AlgoWasmPlayer, assign: (snapshot: AlgoWasmSnapshot) => void): AlgoWasmVueBridge;
8
- //# sourceMappingURL=vue.d.ts.map
@@ -1,16 +1 @@
1
- export function createAlgoWasmVueBridge(player, assign) {
2
- const update = () => assign(player.getSnapshot());
3
- const offBar = player.on('bar', update);
4
- const offStarted = player.on('started', update);
5
- const offStopped = player.on('stopped', update);
6
- update();
7
- return {
8
- snapshot: player.getSnapshot(),
9
- dispose() {
10
- offBar();
11
- offStarted();
12
- offStopped();
13
- }
14
- };
15
- }
16
- //# sourceMappingURL=vue.js.map
1
+ function e(e,t){let n=()=>t(e.getSnapshot()),r=e.on(`bar`,n),i=e.on(`started`,n),a=e.on(`stopped`,n);return n(),{snapshot:e.getSnapshot(),dispose(){r(),i(),a()}}}export{e as createAlgoWasmVueBridge};
@@ -0,0 +1,92 @@
1
+ import { EngineCore } from './engine-core.js';
2
+ import type { AlgoWasmGeneratedEvent, AlgoWasmMood, AlgoWasmProfile, AlgoWasmSnapshot, AlgoWasmTrackId } from './types.js';
3
+ /** A compiled and instantiated AlgoWASM binary. */
4
+ export interface AlgoWasmInstantiation {
5
+ instance: WebAssembly.Instance;
6
+ module: WebAssembly.Module;
7
+ }
8
+ /**
9
+ * Fetches and instantiates the AlgoWASM binary.
10
+ *
11
+ * Streaming compilation is used when the server sends `application/wasm`. If
12
+ * the MIME type is wrong, as on some local servers, the file is fetched again
13
+ * and compiled from bytes instead.
14
+ *
15
+ * @throws {AlgoWasmError} With code `wasm_load_failed` when the file cannot
16
+ * be fetched or compiled.
17
+ */
18
+ export declare function instantiateAlgoWasm(wasmUrl: string | URL): Promise<AlgoWasmInstantiation>;
19
+ /**
20
+ * Converts a mood id to its engine index.
21
+ *
22
+ * @throws {TypeError} When the mood is not recognised.
23
+ */
24
+ export declare function moodIndex(mood: AlgoWasmMood): number;
25
+ /**
26
+ * Converts a track id to its engine index.
27
+ *
28
+ * @throws {TypeError} When the track id is not recognised.
29
+ */
30
+ export declare function trackIndex(trackId: AlgoWasmTrackId): number;
31
+ /**
32
+ * Typed binding to one engine inside a WASM instance, for use outside an
33
+ * `AlgoWasmPlayer`, for example to render audio offline.
34
+ *
35
+ * Memory ownership: the binding owns the WASM buffers it allocates. Call
36
+ * `destroy` when finished to free them.
37
+ *
38
+ * ```ts
39
+ * const { instance } = await instantiateAlgoWasm(wasmUrl);
40
+ * const binding = new AlgoWasmEngineBinding(instance);
41
+ *
42
+ * try {
43
+ * binding.create(48000, 42n, builtInProfiles.dubstep());
44
+ * binding.start();
45
+ * binding.renderTo(output);
46
+ * } finally {
47
+ * binding.destroy();
48
+ * }
49
+ * ```
50
+ */
51
+ export declare class AlgoWasmEngineBinding extends EngineCore {
52
+ /**
53
+ * Validates the profile and creates the engine.
54
+ *
55
+ * @throws {AlgoWasmError} With code `profile_invalid` or `engine_failed`.
56
+ */
57
+ create(sampleRate: number, seed: bigint, profile: AlgoWasmProfile): void;
58
+ /** Re-seeds the engine and restarts the song. */
59
+ setSeed(seed: bigint): void;
60
+ /**
61
+ * Validates and applies a new profile, then restarts the song.
62
+ *
63
+ * @throws {AlgoWasmError} With code `profile_invalid` or `engine_failed`.
64
+ */
65
+ setProfile(profile: AlgoWasmProfile): void;
66
+ /**
67
+ * Sets the mood.
68
+ *
69
+ * @throws {TypeError} When the mood is not recognised.
70
+ */
71
+ setMood(value: AlgoWasmMood): void;
72
+ /**
73
+ * Mutes or unmutes a track.
74
+ *
75
+ * @throws {TypeError} When the track id is not recognised.
76
+ */
77
+ setMuted(trackId: AlgoWasmTrackId, muted: boolean): void;
78
+ /**
79
+ * Solos or unsolos a track.
80
+ *
81
+ * @throws {TypeError} When the track id is not recognised.
82
+ */
83
+ setSolo(trackId: AlgoWasmTrackId, solo: boolean): void;
84
+ /** Returns the engine's current state. */
85
+ snapshot(): AlgoWasmSnapshot;
86
+ /**
87
+ * Returns the events generated since the last call, and removes them from
88
+ * the engine's buffer. The buffer holds up to 512 events, so call this
89
+ * often enough that it does not fill.
90
+ */
91
+ events(): AlgoWasmGeneratedEvent[];
92
+ }