@grame/faustwasm 0.7.0 → 0.7.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.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grame/faustwasm",
3
- "version": "0.7.0",
3
+ "version": "0.7.3",
4
4
  "description": "WebAssembly version of Faust Compiler",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/esm/index.d.ts",
@@ -9,6 +9,8 @@ export class FaustScriptProcessorNode<Poly extends boolean = false> extends (glo
9
9
  // Needed for ScriptProcessorNode
10
10
  protected fInputs!: Float32Array[];
11
11
  protected fOutputs!: Float32Array[];
12
+ protected handleDeviceMotion = undefined as any;
13
+ protected handleDeviceOrientation = undefined as any;
12
14
 
13
15
  init(instance: Poly extends true ? FaustPolyWebAudioDsp : FaustMonoWebAudioDsp) {
14
16
  this.fDSPCode = instance;
@@ -16,6 +18,18 @@ export class FaustScriptProcessorNode<Poly extends boolean = false> extends (glo
16
18
  this.fInputs = new Array(this.fDSPCode.getNumInputs());
17
19
  this.fOutputs = new Array(this.fDSPCode.getNumOutputs());
18
20
 
21
+ // Accelerometer and gyroscope handlers
22
+ this.handleDeviceMotion = ({ accelerationIncludingGravity }: DeviceMotionEvent) => {
23
+ const isAndroid: boolean = /Android/i.test(navigator.userAgent);
24
+ if (!accelerationIncludingGravity) return;
25
+ const { x, y, z } = accelerationIncludingGravity;
26
+ this.propagateAcc({ x, y, z }, isAndroid);
27
+ };
28
+
29
+ this.handleDeviceOrientation = ({ alpha, beta, gamma }: DeviceOrientationEvent) => {
30
+ this.propagateGyr({ alpha, beta, gamma });
31
+ };
32
+
19
33
  this.onaudioprocess = (e) => {
20
34
 
21
35
  // Read inputs
@@ -36,18 +50,6 @@ export class FaustScriptProcessorNode<Poly extends boolean = false> extends (glo
36
50
 
37
51
  // Public API
38
52
 
39
- // Accelerometer and gyroscope handlers
40
- private handleDeviceMotion = ({ accelerationIncludingGravity }: DeviceMotionEvent) => {
41
- const isAndroid: boolean = /Android/i.test(navigator.userAgent);
42
- if (!accelerationIncludingGravity) return;
43
- const { x, y, z } = accelerationIncludingGravity;
44
- this.propagateAcc({ x, y, z }, isAndroid);
45
- };
46
-
47
- private handleDeviceOrientation = ({ alpha, beta, gamma }: DeviceOrientationEvent) => {
48
- this.propagateGyr({ alpha, beta, gamma });
49
- };
50
-
51
53
  /** Setup accelerometer and gyroscope handlers */
52
54
  async startSensors() {
53
55
  if (this.hasAccInput) {
@@ -55,8 +57,12 @@ export class FaustScriptProcessorNode<Poly extends boolean = false> extends (glo
55
57
  if (typeof (window.DeviceMotionEvent as any).requestPermission === "function") { // for iOS 13+
56
58
  try {
57
59
  const response = await (window.DeviceMotionEvent as any).requestPermission();
58
- if (response !== "granted") throw new Error("Unable to access the accelerometer.");
59
- window.addEventListener("devicemotion", this.handleDeviceMotion, true);
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
+ }
60
66
  } catch (error) {
61
67
  console.error(error);
62
68
  }
@@ -73,8 +79,12 @@ export class FaustScriptProcessorNode<Poly extends boolean = false> extends (glo
73
79
  if (typeof (window.DeviceOrientationEvent as any).requestPermission === "function") { // for iOS 13+
74
80
  try {
75
81
  const response = await (window.DeviceOrientationEvent as any).requestPermission();
76
- if (response !== "granted") throw new Error("Unable to access the gyroscope.");
77
- window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
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
+ }
78
88
  } catch (error) {
79
89
  console.error(error);
80
90
  }
@@ -497,12 +497,12 @@ export interface IFaustBaseWebAudioDsp {
497
497
  getJSON(): string;
498
498
 
499
499
  /**
500
- * Start the DSP.
500
+ * Start the DSP audio processing.
501
501
  */
502
502
  start(): void;
503
503
 
504
504
  /**
505
- * Stop the DSP.
505
+ * Stop the DSP audio processing.
506
506
  */
507
507
  stop(): void;
508
508
 
@@ -621,11 +621,11 @@ export interface IFaustBaseWebAudioDsp {
621
621
  */
622
622
  getJSON(): string;
623
623
  /**
624
- * Start the DSP.
624
+ * Start the DSP audio processing.
625
625
  */
626
626
  start(): void;
627
627
  /**
628
- * Stop the DSP.
628
+ * Stop the DSP audio processing.
629
629
  */
630
630
  stop(): void;
631
631
  /**
@@ -1355,9 +1355,9 @@ export declare class FaustScriptProcessorNode<Poly extends boolean = false> exte
1355
1355
  protected fDSPCode: Poly extends true ? FaustPolyWebAudioDsp : FaustMonoWebAudioDsp;
1356
1356
  protected fInputs: Float32Array[];
1357
1357
  protected fOutputs: Float32Array[];
1358
+ protected handleDeviceMotion: any;
1359
+ protected handleDeviceOrientation: any;
1358
1360
  init(instance: Poly extends true ? FaustPolyWebAudioDsp : FaustMonoWebAudioDsp): void;
1359
- private handleDeviceMotion;
1360
- private handleDeviceOrientation;
1361
1361
  /** Setup accelerometer and gyroscope handlers */
1362
1362
  startSensors(): Promise<void>;
1363
1363
  stopSensors(): void;
@@ -3983,8 +3983,13 @@ var FaustPolyAudioWorkletNode = class extends FaustAudioWorkletNode {
3983
3983
  var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode || null) {
3984
3984
  constructor() {
3985
3985
  super(...arguments);
3986
- // Public API
3987
- // Accelerometer and gyroscope handlers
3986
+ this.handleDeviceMotion = void 0;
3987
+ this.handleDeviceOrientation = void 0;
3988
+ }
3989
+ init(instance) {
3990
+ this.fDSPCode = instance;
3991
+ this.fInputs = new Array(this.fDSPCode.getNumInputs());
3992
+ this.fOutputs = new Array(this.fDSPCode.getNumOutputs());
3988
3993
  this.handleDeviceMotion = ({ accelerationIncludingGravity }) => {
3989
3994
  const isAndroid = /Android/i.test(navigator.userAgent);
3990
3995
  if (!accelerationIncludingGravity)
@@ -3995,11 +4000,6 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
3995
4000
  this.handleDeviceOrientation = ({ alpha, beta, gamma }) => {
3996
4001
  this.propagateGyr({ alpha, beta, gamma });
3997
4002
  };
3998
- }
3999
- init(instance) {
4000
- this.fDSPCode = instance;
4001
- this.fInputs = new Array(this.fDSPCode.getNumInputs());
4002
- this.fOutputs = new Array(this.fDSPCode.getNumOutputs());
4003
4003
  this.onaudioprocess = (e) => {
4004
4004
  for (let chan = 0; chan < this.fDSPCode.getNumInputs(); chan++) {
4005
4005
  this.fInputs[chan] = e.inputBuffer.getChannelData(chan);
@@ -4011,6 +4011,7 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
4011
4011
  };
4012
4012
  this.start();
4013
4013
  }
4014
+ // Public API
4014
4015
  /** Setup accelerometer and gyroscope handlers */
4015
4016
  async startSensors() {
4016
4017
  if (this.hasAccInput) {
@@ -4018,9 +4019,12 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
4018
4019
  if (typeof window.DeviceMotionEvent.requestPermission === "function") {
4019
4020
  try {
4020
4021
  const response = await window.DeviceMotionEvent.requestPermission();
4021
- if (response !== "granted")
4022
+ if (response === "granted") {
4023
+ window.addEventListener("devicemotion", this.handleDeviceMotion, true);
4024
+ } else if (response === "denied") {
4025
+ alert("You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.");
4022
4026
  throw new Error("Unable to access the accelerometer.");
4023
- window.addEventListener("devicemotion", this.handleDeviceMotion, true);
4027
+ }
4024
4028
  } catch (error) {
4025
4029
  console.error(error);
4026
4030
  }
@@ -4036,9 +4040,12 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
4036
4040
  if (typeof window.DeviceOrientationEvent.requestPermission === "function") {
4037
4041
  try {
4038
4042
  const response = await window.DeviceOrientationEvent.requestPermission();
4039
- if (response !== "granted")
4043
+ if (response === "granted") {
4044
+ window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
4045
+ } else if (response === "denied") {
4046
+ alert("You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.");
4040
4047
  throw new Error("Unable to access the gyroscope.");
4041
- window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
4048
+ }
4042
4049
  } catch (error) {
4043
4050
  console.error(error);
4044
4051
  }