@grame/faustwasm 0.7.10 → 0.8.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.
Files changed (38) hide show
  1. package/README.md +2 -2
  2. package/assets/standalone/create-node.js +31 -1
  3. package/assets/standalone/faust-ui/index.js +2 -2
  4. package/assets/standalone/faust-ui/index.js.map +1 -1
  5. package/assets/standalone/faustwasm/index.d.ts +76 -9
  6. package/assets/standalone/faustwasm/index.js +272 -107
  7. package/assets/standalone/faustwasm/index.js.map +4 -4
  8. package/assets/standalone/index-pwa.js +132 -98
  9. package/assets/standalone/index-template.js +44 -23
  10. package/assets/standalone/index.js +95 -80
  11. package/assets/standalone/service-worker.js +47 -8
  12. package/dist/cjs/index.d.ts +76 -9
  13. package/dist/cjs/index.js +272 -107
  14. package/dist/cjs/index.js.map +4 -4
  15. package/dist/cjs-bundle/index.d.ts +76 -9
  16. package/dist/cjs-bundle/index.js +272 -107
  17. package/dist/cjs-bundle/index.js.map +4 -4
  18. package/dist/esm/index.d.ts +76 -9
  19. package/dist/esm/index.js +272 -107
  20. package/dist/esm/index.js.map +4 -4
  21. package/dist/esm-bundle/index.d.ts +76 -9
  22. package/dist/esm-bundle/index.js +272 -107
  23. package/dist/esm-bundle/index.js.map +4 -4
  24. package/package.json +2 -2
  25. package/src/FaustAudioWorkletCommunicator.ts +143 -0
  26. package/src/FaustAudioWorkletNode.ts +27 -42
  27. package/src/FaustAudioWorkletProcessor.ts +34 -15
  28. package/src/FaustDspGenerator.ts +20 -2
  29. package/src/FaustFFTAudioWorkletProcessor.ts +31 -2
  30. package/src/FaustOfflineProcessor.ts +6 -0
  31. package/src/FaustScriptProcessorNode.ts +8 -31
  32. package/src/FaustWebAudioDsp.ts +38 -10
  33. package/test/faustlive-wasm/faust-ui/index.js +2 -2
  34. package/test/faustlive-wasm/faust-ui/index.js.map +1 -1
  35. package/test/faustlive-wasm/faustwasm/index.d.ts +76 -9
  36. package/test/faustlive-wasm/faustwasm/index.js +272 -107
  37. package/test/faustlive-wasm/faustwasm/index.js.map +4 -4
  38. package/assets/standalone/coi-serviceworker.js +0 -146
@@ -50,25 +50,12 @@ export class FaustScriptProcessorNode<Poly extends boolean = false> extends (glo
50
50
 
51
51
  // Public API
52
52
 
53
- /** Setup accelerometer and gyroscope handlers */
53
+ /** Start accelerometer and gyroscope handlers */
54
54
  async startSensors() {
55
55
  if (this.hasAccInput) {
56
56
  if (window.DeviceMotionEvent) {
57
- if (typeof (window.DeviceMotionEvent as any).requestPermission === "function") { // for iOS 13+
58
- try {
59
- const response = await (window.DeviceMotionEvent as any).requestPermission();
60
- if (response === "granted") {
61
- window.addEventListener("devicemotion", this.handleDeviceMotion, true);
62
- } else if (response === "denied") {
63
- alert('You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.');
64
- throw new Error("Unable to access the accelerometer.");
65
- }
66
- } catch (error) {
67
- console.error(error);
68
- }
69
- } else {
70
- window.addEventListener("devicemotion", this.handleDeviceMotion, true);
71
- }
57
+ // iOS 13+ requires a user gesture to enable DeviceMotionEvent, to be done in the main thread
58
+ window.addEventListener("devicemotion", this.handleDeviceMotion, true);
72
59
  } else {
73
60
  // Browser doesn't support DeviceMotionEvent
74
61
  console.log("Cannot set the accelerometer handler.");
@@ -76,21 +63,8 @@ export class FaustScriptProcessorNode<Poly extends boolean = false> extends (glo
76
63
  }
77
64
  if (this.hasGyrInput) {
78
65
  if (window.DeviceMotionEvent) {
79
- if (typeof (window.DeviceOrientationEvent as any).requestPermission === "function") { // for iOS 13+
80
- try {
81
- const response = await (window.DeviceOrientationEvent as any).requestPermission();
82
- if (response === "granted") {
83
- window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
84
- } else if (response === "denied") {
85
- alert('You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.');
86
- throw new Error("Unable to access the gyroscope.");
87
- }
88
- } catch (error) {
89
- console.error(error);
90
- }
91
- } else {
92
- window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
93
- }
66
+ // iOS 13+ requires a user gesture to enable DeviceMotionEvent, to be done in the main thread
67
+ window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
94
68
  } else {
95
69
  // Browser doesn't support DeviceMotionEvent
96
70
  console.log("Cannot set the gyroscope handler.");
@@ -98,6 +72,7 @@ export class FaustScriptProcessorNode<Poly extends boolean = false> extends (glo
98
72
  }
99
73
  }
100
74
 
75
+ /** Stop accelerometer and gyroscope handlers */
101
76
  stopSensors() {
102
77
  if (this.hasAccInput) {
103
78
  window.removeEventListener("devicemotion", this.handleDeviceMotion, true);
@@ -143,11 +118,13 @@ export class FaustScriptProcessorNode<Poly extends boolean = false> extends (glo
143
118
  destroy() { this.fDSPCode.destroy(); }
144
119
 
145
120
  get hasAccInput() { return this.fDSPCode.hasAccInput; }
121
+
146
122
  propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean = false) {
147
123
  this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
148
124
  }
149
125
 
150
126
  get hasGyrInput() { return this.fDSPCode.hasGyrInput; }
127
+
151
128
  propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">) {
152
129
  this.fDSPCode.propagateGyr(event);
153
130
  }
@@ -496,6 +496,35 @@ export interface IFaustBaseWebAudioDsp {
496
496
  */
497
497
  getJSON(): string;
498
498
 
499
+ /**
500
+ * Start accelerometer and gyroscope handlers.
501
+ */
502
+ startSensors(): void;
503
+
504
+ /**
505
+ * Stop accelerometer and gyroscope handlers.
506
+ */
507
+ stopSensors(): void;
508
+
509
+ /** Indicating if the DSP handles the accelerometer */
510
+ readonly hasAccInput: boolean;
511
+
512
+ /**
513
+ * Accelerometer handling.
514
+ * accelerationIncludingGravity: DeviceMotionEvent["accelerationIncludingGravity"]
515
+ * invert: boolean
516
+ */
517
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean): void;
518
+
519
+ /** Indicating if the DSP handles the gyroscope */
520
+ readonly hasGyrInput: boolean;
521
+
522
+ /**
523
+ * Gyroscope handling.
524
+ * event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">
525
+ */
526
+ propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
527
+
499
528
  /**
500
529
  * Start the DSP audio processing.
501
530
  */
@@ -510,16 +539,6 @@ export interface IFaustBaseWebAudioDsp {
510
539
  * Destroy the DSP.
511
540
  */
512
541
  destroy(): void;
513
-
514
- /** Indicating if the DSP handles the accelerometer */
515
- readonly hasAccInput: boolean;
516
- /** Accelerometer handling */
517
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean): void;
518
-
519
- /** Indicating if the DSP handles the gyroscope */
520
- readonly hasGyrInput: boolean;
521
- /** Gyroscope handling */
522
- propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
523
542
  }
524
543
 
525
544
  export interface IFaustMonoWebAudioDsp extends IFaustBaseWebAudioDsp { }
@@ -984,6 +1003,14 @@ export class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
984
1003
 
985
1004
  hasSoundfiles() { return this.fSoundfiles.length > 0; }
986
1005
 
1006
+ startSensors(): void {
1007
+ this.startSensors();
1008
+ }
1009
+
1010
+ stopSensors(): void {
1011
+ this.stopSensors();
1012
+ }
1013
+
987
1014
  start() {
988
1015
  this.fProcessing = true;
989
1016
  }
@@ -998,6 +1025,7 @@ export class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
998
1025
  this.fComputeHandler = null;
999
1026
  this.fPlotHandler = null;
1000
1027
  }
1028
+
1001
1029
  }
1002
1030
 
1003
1031
  export class FaustMonoWebAudioDsp extends FaustBaseWebAudioDsp implements IFaustMonoWebAudioDsp {
@@ -946,10 +946,10 @@ class Group extends _AbstractComponent__WEBPACK_IMPORTED_MODULE_0__["default"] {
946
946
  if (!metaIn) return { metaObject };
947
947
  metaIn.forEach((m) => Object.assign(metaObject, m));
948
948
  if (metaObject.style) {
949
- const enumsRegex = /\{(?:(?:'|_|-)(.+?)(?:'|_|-):([-+]?[0-9]*\.?[0-9]+?);)+(?:(?:'|_|-)(.+?)(?:'|_|-):([-+]?[0-9]*\.?[0-9]+?))\}/;
949
+ const enumsRegex = /\{(?:(?:'|_|-)(.+?)(?:'|_|-):([-+]?[0-9]*\.?[0-9]+);)+(?:(?:'|_|-)(.+?)(?:'|_|-):([-+]?[0-9]*\.?[0-9]+))\}/;
950
950
  const matched = metaObject.style.match(enumsRegex);
951
951
  if (matched) {
952
- const itemsRegex = /(?:(?:'|_|-)(.+?)(?:'|_|-):([-+]?[0-9]*\.?[0-9]+?))/g;
952
+ const itemsRegex = /(?:(?:'|_|-)(.+?)(?:'|_|-):([-+]?[0-9]*\.?[0-9]+))/g;
953
953
  const enums = {};
954
954
  let item;
955
955
  while (item = itemsRegex.exec(matched[0])) {