@grame/faustwasm 0.11.0 → 0.11.2
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/assets/standalone/faust-ui/index.js +32 -5
- package/assets/standalone/faust-ui/index.js.map +1 -1
- package/assets/standalone/faustwasm/index.d.ts +1 -34
- package/assets/standalone/faustwasm/index.js +9 -36
- package/assets/standalone/faustwasm/index.js.map +2 -2
- package/dist/cjs/index.d.ts +1 -34
- package/dist/cjs/index.js +9 -36
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs-bundle/index.d.ts +1 -34
- package/dist/cjs-bundle/index.js +18 -43
- package/dist/cjs-bundle/index.js.map +2 -2
- package/dist/esm/index.d.ts +1 -34
- package/dist/esm/index.js +9 -36
- package/dist/esm/index.js.map +2 -2
- package/dist/esm-bundle/index.d.ts +1 -34
- package/dist/esm-bundle/index.js +18 -43
- package/dist/esm-bundle/index.js.map +2 -2
- package/libfaust-wasm/libfaust-wasm.data +0 -0
- package/libfaust-wasm/libfaust-wasm.js +1 -1
- package/libfaust-wasm/libfaust-wasm.wasm +0 -0
- package/package.json +1 -1
- package/src/FaustAudioWorkletNode.ts +1 -1
- package/src/FaustCompiler.ts +3 -3
- package/src/FaustWasmInstantiator.ts +2 -2
- package/src/FaustWebAudioDsp.ts +1 -1
- package/src/instantiateFaustModule.ts +9 -5
- package/src/instantiateFaustModuleFromFile.ts +7 -5
- package/test/faustlive-wasm/faust-ui/index.js +32 -5
- package/test/faustlive-wasm/faust-ui/index.js.map +1 -1
- package/test/faustlive-wasm/faustwasm/index.d.ts +1 -34
- package/test/faustlive-wasm/faustwasm/index.js +9 -36
- package/test/faustlive-wasm/faustwasm/index.js.map +2 -2
|
Binary file
|
package/package.json
CHANGED
|
@@ -132,7 +132,7 @@ export class FaustAudioWorkletNode<Poly extends boolean = false> extends (global
|
|
|
132
132
|
if (this.fOutputHandler) {
|
|
133
133
|
this.fOutputHandler(path, value);
|
|
134
134
|
} else {
|
|
135
|
-
console.warn("No OutputParamHandler set for this
|
|
135
|
+
console.warn("No OutputParamHandler set for this Faust node.");
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
|
package/src/FaustCompiler.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Sha256 } from "@aws-crypto/sha256-js";
|
|
|
2
2
|
import type { ILibFaust } from "./LibFaust";
|
|
3
3
|
import type { FaustDspFactory, IntVector } from "./types";
|
|
4
4
|
|
|
5
|
-
export const ab2str = (buf: Uint8Array) => String.fromCharCode.apply(null, buf);
|
|
5
|
+
export const ab2str = (buf: Uint8Array) => String.fromCharCode.apply(null, Array.from(buf));
|
|
6
6
|
|
|
7
7
|
export const str2ab = (str: string) => {
|
|
8
8
|
const buf = new ArrayBuffer(str.length);
|
|
@@ -231,7 +231,7 @@ class FaustCompiler implements IFaustCompiler {
|
|
|
231
231
|
const mixerBuffer = this.fs().readFile(path, { encoding: "binary" });
|
|
232
232
|
this[bufferKey] = mixerBuffer;
|
|
233
233
|
// Compile mixer
|
|
234
|
-
const mixerModule = await WebAssembly.compile(mixerBuffer);
|
|
234
|
+
const mixerModule = await WebAssembly.compile(new Uint8Array(mixerBuffer));
|
|
235
235
|
this[moduleKey] = mixerModule;
|
|
236
236
|
return { mixerBuffer, mixerModule };
|
|
237
237
|
}
|
|
@@ -243,7 +243,7 @@ class FaustCompiler implements IFaustCompiler {
|
|
|
243
243
|
const mixerBuffer = this.fs().readFile(path, { encoding: "binary" });
|
|
244
244
|
this[bufferKey] = mixerBuffer;
|
|
245
245
|
// Compile mixer
|
|
246
|
-
const mixerModule = new WebAssembly.Module(mixerBuffer);
|
|
246
|
+
const mixerModule = new WebAssembly.Module(new Uint8Array(mixerBuffer));
|
|
247
247
|
this[moduleKey] = mixerModule;
|
|
248
248
|
return { mixerBuffer, mixerModule };
|
|
249
249
|
}
|
|
@@ -123,9 +123,9 @@ class FaustWasmInstantiator {
|
|
|
123
123
|
|
|
124
124
|
static async loadDSPMixer(mixerPath: string, fs?: typeof FS) {
|
|
125
125
|
try {
|
|
126
|
-
let mixerBuffer = null;
|
|
126
|
+
let mixerBuffer: BufferSource | null = null;
|
|
127
127
|
if (fs) {
|
|
128
|
-
mixerBuffer = fs.readFile(mixerPath, { encoding: "binary" });
|
|
128
|
+
mixerBuffer = new Uint8Array(fs.readFile(mixerPath, { encoding: "binary" }));
|
|
129
129
|
} else {
|
|
130
130
|
const mixerFile = await fetch(mixerPath);
|
|
131
131
|
mixerBuffer = await mixerFile.arrayBuffer();
|
package/src/FaustWebAudioDsp.ts
CHANGED
|
@@ -985,7 +985,7 @@ export class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
|
|
|
985
985
|
if (this.fOutputHandler) {
|
|
986
986
|
this.fOutputHandler(path, value);
|
|
987
987
|
} else {
|
|
988
|
-
console.warn("No OutputParamHandler set for this
|
|
988
|
+
console.warn("No OutputParamHandler set for this Faust node.");
|
|
989
989
|
}
|
|
990
990
|
}
|
|
991
991
|
|
|
@@ -12,19 +12,23 @@ export const FaustModuleFactoryData = dataBinary;
|
|
|
12
12
|
const instantiateFaustModule = async (FaustModuleFactoryIn = factoryFn, dataBinaryIn = dataBinary, wasmBinaryIn = wasmBinary) => {
|
|
13
13
|
const g = globalThis as any;
|
|
14
14
|
if (g.AudioWorkletGlobalScope) {
|
|
15
|
-
g.importScripts = () => {};
|
|
15
|
+
g.importScripts = () => { };
|
|
16
16
|
g.self = { location: { href: "" } };
|
|
17
17
|
}
|
|
18
18
|
const faustModule = await FaustModuleFactoryIn({
|
|
19
|
-
|
|
19
|
+
// Create a copy to guarantee a standard ArrayBuffer
|
|
20
|
+
wasmBinary: (new Uint8Array(wasmBinaryIn)).buffer,
|
|
20
21
|
getPreloadedPackage: (remotePackageName: string, remotePackageSize: number) => {
|
|
21
|
-
if (remotePackageName === "libfaust-wasm.data")
|
|
22
|
+
if (remotePackageName === "libfaust-wasm.data") {
|
|
23
|
+
// Create a copy to guarantee a standard ArrayBuffer
|
|
24
|
+
return (new Uint8Array(dataBinaryIn)).buffer;
|
|
25
|
+
}
|
|
22
26
|
return new ArrayBuffer(0);
|
|
23
27
|
}
|
|
24
28
|
});
|
|
25
29
|
if (g.AudioWorkletGlobalScope) {
|
|
26
|
-
|
|
27
|
-
|
|
30
|
+
delete g.importScripts;
|
|
31
|
+
delete g.self;
|
|
28
32
|
}
|
|
29
33
|
return faustModule;
|
|
30
34
|
};
|
|
@@ -9,7 +9,7 @@ import type { FaustModuleFactory } from "./types";
|
|
|
9
9
|
const instantiateFaustModuleFromFile = async (jsFile: string, dataFile = jsFile.replace(/c?js$/, "data"), wasmFile = jsFile.replace(/c?js$/, "wasm")) => {
|
|
10
10
|
let FaustModule: FaustModuleFactory;
|
|
11
11
|
let dataBinary: ArrayBuffer;
|
|
12
|
-
let wasmBinary:
|
|
12
|
+
let wasmBinary: ArrayBuffer;
|
|
13
13
|
const jsCodeHead = /var (.+) = \(/;
|
|
14
14
|
if (typeof window === "object") {
|
|
15
15
|
let jsCode = await (await fetch(jsFile)).text();
|
|
@@ -19,7 +19,7 @@ export default ${jsCode.match(jsCodeHead)?.[1]};
|
|
|
19
19
|
const jsFileMod = URL.createObjectURL(new Blob([jsCode], { type: "text/javascript" }));
|
|
20
20
|
FaustModule = (await import(/* webpackIgnore: true */jsFileMod)).default;
|
|
21
21
|
dataBinary = await (await fetch(dataFile)).arrayBuffer();
|
|
22
|
-
wasmBinary =
|
|
22
|
+
wasmBinary = await (await fetch(wasmFile)).arrayBuffer();
|
|
23
23
|
} else {
|
|
24
24
|
const { promises: fs } = await import("fs");
|
|
25
25
|
const { pathToFileURL } = await import("url");
|
|
@@ -42,15 +42,17 @@ export default ${jsCode.match(jsCodeHead)?.[1]};
|
|
|
42
42
|
await fs.writeFile(jsFileMod, jsCode);
|
|
43
43
|
FaustModule = (await import(/* webpackIgnore: true */pathToFileURL(jsFileMod).href)).default;
|
|
44
44
|
await fs.unlink(jsFileMod);
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
// Using a type assertion `as ArrayBuffer` to satisfy the strict type checking.
|
|
46
|
+
dataBinary = (new Uint8Array(await fs.readFile(dataFile))).buffer as ArrayBuffer;
|
|
47
|
+
wasmBinary = (new Uint8Array(await fs.readFile(wasmFile))).buffer as ArrayBuffer;
|
|
47
48
|
}
|
|
48
49
|
const faustModule = await FaustModule({
|
|
49
50
|
wasmBinary,
|
|
50
51
|
getPreloadedPackage: (remotePackageName: string, remotePackageSize: number) => {
|
|
51
52
|
if (remotePackageName === "libfaust-wasm.data") return dataBinary;
|
|
52
53
|
return new ArrayBuffer(0);
|
|
53
|
-
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
54
56
|
return faustModule;
|
|
55
57
|
};
|
|
56
58
|
|
|
@@ -469,6 +469,14 @@ const _AbstractItem = class _AbstractItem extends _AbstractComponent__WEBPACK_IM
|
|
|
469
469
|
};
|
|
470
470
|
this.handleClick = (e) => {
|
|
471
471
|
};
|
|
472
|
+
/**
|
|
473
|
+
* Handle double-click events to reset the value to its initial state.
|
|
474
|
+
*/
|
|
475
|
+
this.handleDoubleClick = (e) => {
|
|
476
|
+
e.preventDefault();
|
|
477
|
+
e.stopPropagation();
|
|
478
|
+
this.setToInitialValue();
|
|
479
|
+
};
|
|
472
480
|
this.handleMouseDown = (e) => {
|
|
473
481
|
e.preventDefault();
|
|
474
482
|
e.currentTarget.focus();
|
|
@@ -558,6 +566,9 @@ const _AbstractItem = class _AbstractItem extends _AbstractComponent__WEBPACK_IM
|
|
|
558
566
|
if (changed) this.change(value);
|
|
559
567
|
return changed;
|
|
560
568
|
}
|
|
569
|
+
setToInitialValue() {
|
|
570
|
+
this.setValue(this.state.init);
|
|
571
|
+
}
|
|
561
572
|
/**
|
|
562
573
|
* Send value to DSP
|
|
563
574
|
*/
|
|
@@ -698,6 +709,7 @@ _AbstractItem.defaultProps = {
|
|
|
698
709
|
address: "",
|
|
699
710
|
min: 0,
|
|
700
711
|
max: 1,
|
|
712
|
+
init: 0,
|
|
701
713
|
enums: {},
|
|
702
714
|
type: "float",
|
|
703
715
|
unit: "",
|
|
@@ -886,6 +898,14 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
886
898
|
class Group extends _AbstractComponent__WEBPACK_IMPORTED_MODULE_0__["default"] {
|
|
887
899
|
constructor() {
|
|
888
900
|
super(...arguments);
|
|
901
|
+
/**
|
|
902
|
+
* Handle double-click events to reset all children's value to its initial state.
|
|
903
|
+
*/
|
|
904
|
+
this.handleDoubleClick = (e) => {
|
|
905
|
+
e.preventDefault();
|
|
906
|
+
e.stopPropagation();
|
|
907
|
+
this.setToInitialValue();
|
|
908
|
+
};
|
|
889
909
|
this.updateUI = () => {
|
|
890
910
|
this.children = [];
|
|
891
911
|
const { style, type, items, emitter, isRoot } = this.state;
|
|
@@ -946,10 +966,10 @@ class Group extends _AbstractComponent__WEBPACK_IMPORTED_MODULE_0__["default"] {
|
|
|
946
966
|
if (!metaIn) return { metaObject };
|
|
947
967
|
metaIn.forEach((m) => Object.assign(metaObject, m));
|
|
948
968
|
if (metaObject.style) {
|
|
949
|
-
const enumsRegex = /\{(?:
|
|
969
|
+
const enumsRegex = /\{\s*(?:['_\-](.+?)['_\-]\s*:\s*([-+]?[0-9]*\.?[0-9]+)\s*;\s*)+(?:['_\-](.+?)['_\-]\s*:\s*([-+]?[0-9]*\.?[0-9]+))\s*\}/;
|
|
950
970
|
const matched = metaObject.style.match(enumsRegex);
|
|
951
971
|
if (matched) {
|
|
952
|
-
const itemsRegex = /
|
|
972
|
+
const itemsRegex = /['_\-](.+?)['_\-]\s*:\s*([-+]?[0-9]*\.?[0-9]+)\s*/g;
|
|
953
973
|
const enums = {};
|
|
954
974
|
let item;
|
|
955
975
|
while (item = itemsRegex.exec(matched[0])) {
|
|
@@ -1003,7 +1023,8 @@ class Group extends _AbstractComponent__WEBPACK_IMPORTED_MODULE_0__["default"] {
|
|
|
1003
1023
|
min: isFinite(min) ? min : 0,
|
|
1004
1024
|
max: isFinite(max) ? max : 1,
|
|
1005
1025
|
step: "step" in item ? +item.step : 1,
|
|
1006
|
-
value: "init" in item ? +item.init || 0 : 0
|
|
1026
|
+
value: "init" in item ? +item.init || 0 : 0,
|
|
1027
|
+
init: "init" in item ? +item.init || 0 : 0
|
|
1007
1028
|
};
|
|
1008
1029
|
if (type === "button") return new _Button__WEBPACK_IMPORTED_MODULE_5__["default"](props);
|
|
1009
1030
|
if (type === "checkbox") return new _Checkbox__WEBPACK_IMPORTED_MODULE_6__["default"](props);
|
|
@@ -1020,6 +1041,9 @@ class Group extends _AbstractComponent__WEBPACK_IMPORTED_MODULE_0__["default"] {
|
|
|
1020
1041
|
if (type === "led") return new _Led__WEBPACK_IMPORTED_MODULE_10__["default"](props);
|
|
1021
1042
|
return null;
|
|
1022
1043
|
}
|
|
1044
|
+
setToInitialValue() {
|
|
1045
|
+
this.children.forEach((item) => item.setToInitialValue());
|
|
1046
|
+
}
|
|
1023
1047
|
setState(newState) {
|
|
1024
1048
|
let shouldUpdate = false;
|
|
1025
1049
|
for (const key in newState) {
|
|
@@ -1091,7 +1115,7 @@ class Group extends _AbstractComponent__WEBPACK_IMPORTED_MODULE_0__["default"] {
|
|
|
1091
1115
|
return this;
|
|
1092
1116
|
}
|
|
1093
1117
|
componentDidMount() {
|
|
1094
|
-
var _a;
|
|
1118
|
+
var _a, _b;
|
|
1095
1119
|
const handleResize = () => {
|
|
1096
1120
|
const { grid, left, top, width, height } = this.state.style;
|
|
1097
1121
|
if (!this.state.isRoot) this.label.style.height = `${grid * 0.3}px`;
|
|
@@ -1125,7 +1149,8 @@ class Group extends _AbstractComponent__WEBPACK_IMPORTED_MODULE_0__["default"] {
|
|
|
1125
1149
|
};
|
|
1126
1150
|
this.on("label", () => this.schedule(labelChange));
|
|
1127
1151
|
this.paintLabel();
|
|
1128
|
-
|
|
1152
|
+
(_a = this.labelCanvas) == null ? void 0 : _a.addEventListener("dblclick", this.handleDoubleClick);
|
|
1153
|
+
if ((_b = this.tabs) == null ? void 0 : _b.children.length) this.tabs.children[0].click();
|
|
1129
1154
|
this.children.forEach((item) => item.componentDidMount());
|
|
1130
1155
|
return this;
|
|
1131
1156
|
}
|
|
@@ -1446,6 +1471,7 @@ class Knob extends _AbstractItem__WEBPACK_IMPORTED_MODULE_0__["default"] {
|
|
|
1446
1471
|
super.componentDidMount();
|
|
1447
1472
|
this.input.addEventListener("change", this.handleChange);
|
|
1448
1473
|
this.canvas.addEventListener("pointerdown", this.handlePointerDown);
|
|
1474
|
+
this.canvas.addEventListener("dblclick", this.handleDoubleClick);
|
|
1449
1475
|
this.on("style", () => {
|
|
1450
1476
|
this.schedule(this.setStyle);
|
|
1451
1477
|
this.schedule(this.paint);
|
|
@@ -2471,6 +2497,7 @@ class VSlider extends _AbstractItem__WEBPACK_IMPORTED_MODULE_0__["default"] {
|
|
|
2471
2497
|
super.componentDidMount();
|
|
2472
2498
|
this.input.addEventListener("change", this.handleChange);
|
|
2473
2499
|
this.canvas.addEventListener("pointerdown", this.handlePointerDown);
|
|
2500
|
+
this.canvas.addEventListener("dblclick", this.handleDoubleClick);
|
|
2474
2501
|
this.on("style", () => {
|
|
2475
2502
|
this.schedule(this.setStyle);
|
|
2476
2503
|
this.schedule(this.paint);
|