@opendaw/studio-core-wasm 0.0.2 → 0.0.3

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.
@@ -133,7 +133,7 @@ export var WasmEngine;
133
133
  };
134
134
  const target = {
135
135
  sendUpdates: (tasks) => {
136
- sender.applyUpdates(serializeUpdateTasks(tasks, project.boxGraph));
136
+ sender.applyUpdates(serializeUpdateTasks(tasks));
137
137
  verifyChecksum();
138
138
  },
139
139
  checksum: (value) => sender.checksum(value)
@@ -1 +1 @@
1
- {"version":3,"file":"engine-modules.d.ts","sourceRoot":"","sources":["../src/engine-modules.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,aAAa,GAAG;IACxB,OAAO,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAG7E,mBAAmB,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAC;IAE3E,eAAe,EAAE,MAAM,CAAC;IAGxB,YAAY,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAC7C,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IACxB,YAAY,EAAE,WAAW,CAAC,MAAM,CAAA;IAChC,aAAa,EAAE,aAAa,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IAChD,cAAc,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IACrC,UAAU,EAAE,aAAa,CAAC,aAAa,CAAC,CAAA;CAC3C,CAAA;AAMD,eAAO,MAAM,kBAAkB,QAAO,WAAW,CAAC,MACsB,CAAA;AAMxE,eAAO,MAAM,OAAO,EAAE,aAAa,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CA0BnE,CAAA;AAKD,eAAO,MAAM,UAAU,EAAE,aAAa,CAAC,aAAa,CAWnD,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAU,OAAM,MAAW,KAAG,OAAO,CAAC,aAAa,CAOhF,CAAA"}
1
+ {"version":3,"file":"engine-modules.d.ts","sourceRoot":"","sources":["../src/engine-modules.ts"],"names":[],"mappings":"AAUA,MAAM,MAAM,aAAa,GAAG;IACxB,OAAO,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAG7E,mBAAmB,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAC;IAE3E,eAAe,EAAE,MAAM,CAAC;IAGxB,YAAY,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAC7C,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IACxB,YAAY,EAAE,WAAW,CAAC,MAAM,CAAA;IAChC,aAAa,EAAE,aAAa,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IAChD,cAAc,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IACrC,UAAU,EAAE,aAAa,CAAC,aAAa,CAAC,CAAA;CAC3C,CAAA;AAWD,eAAO,MAAM,kBAAkB,QAAO,WAAW,CAAC,MASjD,CAAA;AAMD,eAAO,MAAM,OAAO,EAAE,aAAa,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CA0BnE,CAAA;AAKD,eAAO,MAAM,UAAU,EAAE,aAAa,CAAC,aAAa,CAWnD,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAU,OAAM,MAAW,KAAG,OAAO,CAAC,aAAa,CAOhF,CAAA"}
@@ -1,11 +1,25 @@
1
- // Fetch + compile the wasm modules the engine worklet needs: the engine (the dynamic-linker host) and
2
- // the device PLUGINS (PIC side modules the engine loads at host-assigned bases). All are handed to the
3
- // "engine" AudioWorkletProcessor via processorOptions; the worklet links the devices into the engine.
1
+ import { Option } from "@opendaw/lib-std";
4
2
  // The engine's single linear memory: SHARED, so the main thread can see the WASM heap (e.g. to write
5
- // decoded sample data straight into it at an engine-allocated offset). wasm32 caps at 65536 pages (4 GiB),
6
- // so that is the maximum; pages commit lazily on grow. Needs cross-origin isolation (COOP/COEP, set in
7
- // vite.config). Created on the main thread and passed into the worklet via processorOptions.
8
- export const createEngineMemory = () => new WebAssembly.Memory({ initial: 256, maximum: 65536, shared: true });
3
+ // decoded sample data straight into it at an engine-allocated offset). A SHARED memory cannot be reallocated
4
+ // on grow (its base must stay fixed for every thread), so the runtime RESERVES the entire `maximum` as VIRTUAL
5
+ // address space at creation — physical pages still commit lazily on grow, but that reservation itself can fail
6
+ // on a memory-constrained device (a low-end Chromebook reported `RangeError: could not allocate memory`, #1030).
7
+ // So request the wasm32 ceiling (65536 pages = 4 GiB) and fall back to smaller maxima until one is accepted; the
8
+ // talc allocator grows on demand up to whatever ceiling succeeded. The engine.wasm memory import declares
9
+ // max=65536, and a smaller provided max still satisfies it (verified: it instantiates down to 8192).
10
+ // Needs cross-origin isolation (COOP/COEP, set in vite.config). Passed into the worklet via processorOptions.
11
+ export const createEngineMemory = () => {
12
+ const initial = 256;
13
+ for (const maximum of [65536, 32768, 16384, 8192]) {
14
+ console.debug(`Try ${maximum} bytes for engine memory...`);
15
+ const memory = Option.tryCatch(() => new WebAssembly.Memory({ initial, maximum, shared: true }));
16
+ if (memory.nonEmpty()) {
17
+ return memory.unwrap();
18
+ }
19
+ }
20
+ // Smallest workable ceiling; if even this throws, the device genuinely cannot host the engine.
21
+ return new WebAssembly.Memory({ initial, maximum: 4096, shared: true });
22
+ };
9
23
  // The device PIC side modules to load: each wasm plus the device-BOX TYPE it realizes. This is the device
10
24
  // table the engine uses to instantiate a device box: when the box graph presents e.g. an ArpeggioDeviceBox,
11
25
  // the engine looks up its type here to find its plugin under /wasm/plugins/. Load order is irrelevant now (the engine reads
@@ -1,4 +1,4 @@
1
- import { BoxGraph, UpdateTask } from "@opendaw/lib-box";
1
+ import { UpdateTask } from "@opendaw/lib-box";
2
2
  import { BoxIO } from "@opendaw/studio-boxes";
3
- export declare const serializeUpdateTasks: (tasks: ReadonlyArray<UpdateTask<BoxIO.TypeMap>>, source: BoxGraph<BoxIO.TypeMap>) => ArrayBuffer;
3
+ export declare const serializeUpdateTasks: (tasks: ReadonlyArray<UpdateTask<BoxIO.TypeMap>>) => ArrayBuffer;
4
4
  //# sourceMappingURL=serialize-update-tasks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"serialize-update-tasks.d.ts","sourceRoot":"","sources":["../../src/sync/serialize-update-tasks.ts"],"names":[],"mappings":"AAKA,OAAO,EAAU,QAAQ,EAAmC,UAAU,EAAC,MAAM,kBAAkB,CAAA;AAC/F,OAAO,EAAC,KAAK,EAAC,MAAM,uBAAuB,CAAA;AAE3C,eAAO,MAAM,oBAAoB,GAC7B,OAAO,aAAa,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,EAC/C,QAAQ,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,KAAG,WA8BrC,CAAA"}
1
+ {"version":3,"file":"serialize-update-tasks.d.ts","sourceRoot":"","sources":["../../src/sync/serialize-update-tasks.ts"],"names":[],"mappings":"AAOA,OAAO,EAA2B,UAAU,EAAqB,MAAM,kBAAkB,CAAA;AACzF,OAAO,EAAC,KAAK,EAAC,MAAM,uBAAuB,CAAA;AAE3C,eAAO,MAAM,oBAAoB,GAAI,OAAO,aAAa,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,KAAG,WA4BtF,CAAA"}
@@ -1,9 +1,11 @@
1
1
  // Serialize SyncSource's forward-only UpdateTask[] into the byte stream the Rust engine's
2
- // decode_forward consumes. Primitive value types are resolved from the source graph's schema, so
3
- // this must run where that graph lives (the main thread), not in the wasm-only worklet.
2
+ // decode_forward consumes. Each update-primitive task carries the field's codec (primitiveType) captured
3
+ // at emission time, so the stream is self-contained: a later task in the same batch may have deleted the
4
+ // box (e.g. undo trims a region, then unstages it — #287), and re-resolving the field against the live
5
+ // graph here would throw "no field at". Everything is written on the main thread's ordered channel.
4
6
  import { ByteArrayOutput, isDefined, UUID } from "@opendaw/lib-std";
5
- import { Address } from "@opendaw/lib-box";
6
- export const serializeUpdateTasks = (tasks, source) => {
7
+ import { Address, ValueSerialization } from "@opendaw/lib-box";
8
+ export const serializeUpdateTasks = (tasks) => {
7
9
  const output = ByteArrayOutput.create();
8
10
  output.writeInt(tasks.length);
9
11
  tasks.forEach(task => {
@@ -15,10 +17,8 @@ export const serializeUpdateTasks = (tasks, source) => {
15
17
  output.writeBytes(new Int8Array(task.buffer));
16
18
  }
17
19
  else if (task.type === "update-primitive") {
18
- const address = Address.reconstruct(task.address);
19
- address.write(output);
20
- const field = source.findVertex(address).unwrap(() => `no field at ${address}`);
21
- const serialization = field.serialization();
20
+ Address.reconstruct(task.address).write(output);
21
+ const serialization = ValueSerialization[task.primitiveType];
22
22
  output.writeString(serialization.type);
23
23
  serialization.encode(output, task.value);
24
24
  }
Binary file
Binary file
Binary file
Binary file
Binary file