@grame/faustwasm 0.6.3 → 0.7.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.
@@ -1289,8 +1289,11 @@ export declare class FaustAudioWorkletNode<Poly extends boolean = false> extends
1289
1289
  protected fUICallback: UIHandler;
1290
1290
  protected fDescriptor: FaustUIInputItem[];
1291
1291
  constructor(context: BaseAudioContext, name: string, factory: LooseFaustDspFactory, options?: Partial<FaustAudioWorkletNodeOptions<Poly>>);
1292
+ private handleDeviceMotion;
1293
+ private handleDeviceOrientation;
1292
1294
  /** Setup accelerometer and gyroscope handlers */
1293
- listenSensors(): Promise<void>;
1295
+ startSensors(): Promise<void>;
1296
+ stopSensors(): void;
1294
1297
  setOutputParamHandler(handler: OutputParamHandler | null): void;
1295
1298
  getOutputParamHandler(): OutputParamHandler | null;
1296
1299
  setComputeHandler(handler: ComputeHandler | null): void;
@@ -1353,8 +1356,11 @@ export declare class FaustScriptProcessorNode<Poly extends boolean = false> exte
1353
1356
  protected fInputs: Float32Array[];
1354
1357
  protected fOutputs: Float32Array[];
1355
1358
  init(instance: Poly extends true ? FaustPolyWebAudioDsp : FaustMonoWebAudioDsp): void;
1359
+ private handleDeviceMotion;
1360
+ private handleDeviceOrientation;
1356
1361
  /** Setup accelerometer and gyroscope handlers */
1357
- listenSensors(): Promise<void>;
1362
+ startSensors(): Promise<void>;
1363
+ stopSensors(): void;
1358
1364
  compute(input: Float32Array[], output: Float32Array[]): boolean;
1359
1365
  setOutputParamHandler(handler: OutputParamHandler): void;
1360
1366
  getOutputParamHandler(): OutputParamHandler | null;
@@ -783,8 +783,8 @@ function __generator(thisArg, body) {
783
783
  if (t[0] & 1)
784
784
  throw t[1];
785
785
  return t[1];
786
- }, trys: [], ops: [] }, f, y, t, g;
787
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
786
+ }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
787
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
788
788
  return this;
789
789
  }), g;
790
790
  function verb(n) {
@@ -3696,6 +3696,18 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
3696
3696
  });
3697
3697
  __privateAdd(this, _hasAccInput, false);
3698
3698
  __privateAdd(this, _hasGyrInput, false);
3699
+ // Public API
3700
+ // Accelerometer and gyroscope handlers
3701
+ this.handleDeviceMotion = ({ accelerationIncludingGravity }) => {
3702
+ const isAndroid = /Android/i.test(navigator.userAgent);
3703
+ if (!accelerationIncludingGravity)
3704
+ return;
3705
+ const { x, y, z } = accelerationIncludingGravity;
3706
+ this.propagateAcc({ x, y, z }, isAndroid);
3707
+ };
3708
+ this.handleDeviceOrientation = ({ alpha, beta, gamma }) => {
3709
+ this.propagateGyr({ alpha, beta, gamma });
3710
+ };
3699
3711
  this.fJSONDsp = JSONObj;
3700
3712
  this.fJSON = factory.json;
3701
3713
  this.fOutputHandler = null;
@@ -3727,56 +3739,59 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
3727
3739
  }
3728
3740
  };
3729
3741
  }
3730
- // Public API
3731
3742
  /** Setup accelerometer and gyroscope handlers */
3732
- async listenSensors() {
3743
+ async startSensors() {
3733
3744
  if (this.hasAccInput) {
3734
- const isAndroid = /Android/i.test(navigator.userAgent);
3735
- const handleDeviceMotion = ({ accelerationIncludingGravity }) => {
3736
- if (!accelerationIncludingGravity)
3737
- return;
3738
- const { x, y, z } = accelerationIncludingGravity;
3739
- this.propagateAcc({ x, y, z }, isAndroid);
3740
- };
3741
3745
  if (window.DeviceMotionEvent) {
3742
3746
  if (typeof window.DeviceMotionEvent.requestPermission === "function") {
3743
3747
  try {
3744
3748
  const response = await window.DeviceMotionEvent.requestPermission();
3745
- if (response !== "granted")
3749
+ if (response === "granted") {
3750
+ window.addEventListener("devicemotion", this.handleDeviceMotion, true);
3751
+ } else if (response === "denied") {
3752
+ alert("You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.");
3746
3753
  throw new Error("Unable to access the accelerometer.");
3747
- window.addEventListener("devicemotion", handleDeviceMotion, true);
3754
+ }
3748
3755
  } catch (error) {
3749
3756
  console.error(error);
3750
3757
  }
3751
3758
  } else {
3752
- window.addEventListener("devicemotion", handleDeviceMotion, true);
3759
+ window.addEventListener("devicemotion", this.handleDeviceMotion, true);
3753
3760
  }
3754
3761
  } else {
3755
3762
  console.log("Cannot set the accelerometer handler.");
3756
3763
  }
3757
3764
  }
3758
3765
  if (this.hasGyrInput) {
3759
- const handleDeviceOrientation = ({ alpha, beta, gamma }) => {
3760
- this.propagateGyr({ alpha, beta, gamma });
3761
- };
3762
3766
  if (window.DeviceMotionEvent) {
3763
3767
  if (typeof window.DeviceOrientationEvent.requestPermission === "function") {
3764
3768
  try {
3765
3769
  const response = await window.DeviceOrientationEvent.requestPermission();
3766
- if (response !== "granted")
3770
+ if (response === "granted") {
3771
+ window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
3772
+ } else if (response === "denied") {
3773
+ alert("You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.");
3767
3774
  throw new Error("Unable to access the gyroscope.");
3768
- window.addEventListener("deviceorientation", handleDeviceOrientation, true);
3775
+ }
3769
3776
  } catch (error) {
3770
3777
  console.error(error);
3771
3778
  }
3772
3779
  } else {
3773
- window.addEventListener("deviceorientation", handleDeviceOrientation, true);
3780
+ window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
3774
3781
  }
3775
3782
  } else {
3776
3783
  console.log("Cannot set the gyroscope handler.");
3777
3784
  }
3778
3785
  }
3779
3786
  }
3787
+ stopSensors() {
3788
+ if (this.hasAccInput) {
3789
+ window.removeEventListener("devicemotion", this.handleDeviceMotion, true);
3790
+ }
3791
+ if (this.hasGyrInput) {
3792
+ window.removeEventListener("deviceorientation", this.handleDeviceOrientation, true);
3793
+ }
3794
+ }
3780
3795
  setOutputParamHandler(handler) {
3781
3796
  this.fOutputHandler = handler;
3782
3797
  }
@@ -3966,6 +3981,21 @@ var FaustPolyAudioWorkletNode = class extends FaustAudioWorkletNode {
3966
3981
 
3967
3982
  // src/FaustScriptProcessorNode.ts
3968
3983
  var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode || null) {
3984
+ constructor() {
3985
+ super(...arguments);
3986
+ // Public API
3987
+ // Accelerometer and gyroscope handlers
3988
+ this.handleDeviceMotion = ({ accelerationIncludingGravity }) => {
3989
+ const isAndroid = /Android/i.test(navigator.userAgent);
3990
+ if (!accelerationIncludingGravity)
3991
+ return;
3992
+ const { x, y, z } = accelerationIncludingGravity;
3993
+ this.propagateAcc({ x, y, z }, isAndroid);
3994
+ };
3995
+ this.handleDeviceOrientation = ({ alpha, beta, gamma }) => {
3996
+ this.propagateGyr({ alpha, beta, gamma });
3997
+ };
3998
+ }
3969
3999
  init(instance) {
3970
4000
  this.fDSPCode = instance;
3971
4001
  this.fInputs = new Array(this.fDSPCode.getNumInputs());
@@ -3981,56 +4011,53 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
3981
4011
  };
3982
4012
  this.start();
3983
4013
  }
3984
- // Public API
3985
4014
  /** Setup accelerometer and gyroscope handlers */
3986
- async listenSensors() {
4015
+ async startSensors() {
3987
4016
  if (this.hasAccInput) {
3988
- const isAndroid = /Android/i.test(navigator.userAgent);
3989
- const handleDeviceMotion = ({ accelerationIncludingGravity }) => {
3990
- if (!accelerationIncludingGravity)
3991
- return;
3992
- const { x, y, z } = accelerationIncludingGravity;
3993
- this.propagateAcc({ x, y, z }, isAndroid);
3994
- };
3995
4017
  if (window.DeviceMotionEvent) {
3996
4018
  if (typeof window.DeviceMotionEvent.requestPermission === "function") {
3997
4019
  try {
3998
4020
  const response = await window.DeviceMotionEvent.requestPermission();
3999
4021
  if (response !== "granted")
4000
4022
  throw new Error("Unable to access the accelerometer.");
4001
- window.addEventListener("devicemotion", handleDeviceMotion, true);
4023
+ window.addEventListener("devicemotion", this.handleDeviceMotion, true);
4002
4024
  } catch (error) {
4003
4025
  console.error(error);
4004
4026
  }
4005
4027
  } else {
4006
- window.addEventListener("devicemotion", handleDeviceMotion, true);
4028
+ window.addEventListener("devicemotion", this.handleDeviceMotion, true);
4007
4029
  }
4008
4030
  } else {
4009
4031
  console.log("Cannot set the accelerometer handler.");
4010
4032
  }
4011
4033
  }
4012
4034
  if (this.hasGyrInput) {
4013
- const handleDeviceOrientation = ({ alpha, beta, gamma }) => {
4014
- this.propagateGyr({ alpha, beta, gamma });
4015
- };
4016
4035
  if (window.DeviceMotionEvent) {
4017
4036
  if (typeof window.DeviceOrientationEvent.requestPermission === "function") {
4018
4037
  try {
4019
4038
  const response = await window.DeviceOrientationEvent.requestPermission();
4020
4039
  if (response !== "granted")
4021
4040
  throw new Error("Unable to access the gyroscope.");
4022
- window.addEventListener("deviceorientation", handleDeviceOrientation, true);
4041
+ window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
4023
4042
  } catch (error) {
4024
4043
  console.error(error);
4025
4044
  }
4026
4045
  } else {
4027
- window.addEventListener("deviceorientation", handleDeviceOrientation, true);
4046
+ window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
4028
4047
  }
4029
4048
  } else {
4030
4049
  console.log("Cannot set the gyroscope handler.");
4031
4050
  }
4032
4051
  }
4033
4052
  }
4053
+ stopSensors() {
4054
+ if (this.hasAccInput) {
4055
+ window.removeEventListener("devicemotion", this.handleDeviceMotion, true);
4056
+ }
4057
+ if (this.hasGyrInput) {
4058
+ window.removeEventListener("deviceorientation", this.handleDeviceOrientation, true);
4059
+ }
4060
+ }
4034
4061
  compute(input, output) {
4035
4062
  return this.fDSPCode.compute(input, output);
4036
4063
  }