@grame/faustwasm 0.6.4 → 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.
@@ -1296,8 +1296,11 @@ export declare class FaustAudioWorkletNode<Poly extends boolean = false> extends
1296
1296
  protected fUICallback: UIHandler;
1297
1297
  protected fDescriptor: FaustUIInputItem[];
1298
1298
  constructor(context: BaseAudioContext, name: string, factory: LooseFaustDspFactory, options?: Partial<FaustAudioWorkletNodeOptions<Poly>>);
1299
+ private handleDeviceMotion;
1300
+ private handleDeviceOrientation;
1299
1301
  /** Setup accelerometer and gyroscope handlers */
1300
- listenSensors(): Promise<void>;
1302
+ startSensors(): Promise<void>;
1303
+ stopSensors(): void;
1301
1304
  setOutputParamHandler(handler: OutputParamHandler | null): void;
1302
1305
  getOutputParamHandler(): OutputParamHandler | null;
1303
1306
  setComputeHandler(handler: ComputeHandler | null): void;
@@ -1360,8 +1363,11 @@ export declare class FaustScriptProcessorNode<Poly extends boolean = false> exte
1360
1363
  protected fInputs: Float32Array[];
1361
1364
  protected fOutputs: Float32Array[];
1362
1365
  init(instance: Poly extends true ? FaustPolyWebAudioDsp : FaustMonoWebAudioDsp): void;
1366
+ private handleDeviceMotion;
1367
+ private handleDeviceOrientation;
1363
1368
  /** Setup accelerometer and gyroscope handlers */
1364
- listenSensors(): Promise<void>;
1369
+ startSensors(): Promise<void>;
1370
+ stopSensors(): void;
1365
1371
  compute(input: Float32Array[], output: Float32Array[]): boolean;
1366
1372
  setOutputParamHandler(handler: OutputParamHandler): void;
1367
1373
  getOutputParamHandler(): OutputParamHandler | null;
@@ -9743,6 +9743,18 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9743
9743
  });
9744
9744
  __privateAdd(this, _hasAccInput, false);
9745
9745
  __privateAdd(this, _hasGyrInput, false);
9746
+ // Public API
9747
+ // Accelerometer and gyroscope handlers
9748
+ this.handleDeviceMotion = ({ accelerationIncludingGravity }) => {
9749
+ const isAndroid = /Android/i.test(navigator.userAgent);
9750
+ if (!accelerationIncludingGravity)
9751
+ return;
9752
+ const { x, y, z } = accelerationIncludingGravity;
9753
+ this.propagateAcc({ x, y, z }, isAndroid);
9754
+ };
9755
+ this.handleDeviceOrientation = ({ alpha, beta, gamma }) => {
9756
+ this.propagateGyr({ alpha, beta, gamma });
9757
+ };
9746
9758
  this.fJSONDsp = JSONObj;
9747
9759
  this.fJSON = factory.json;
9748
9760
  this.fOutputHandler = null;
@@ -9774,56 +9786,59 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9774
9786
  }
9775
9787
  };
9776
9788
  }
9777
- // Public API
9778
9789
  /** Setup accelerometer and gyroscope handlers */
9779
- async listenSensors() {
9790
+ async startSensors() {
9780
9791
  if (this.hasAccInput) {
9781
- const isAndroid = /Android/i.test(navigator.userAgent);
9782
- const handleDeviceMotion = ({ accelerationIncludingGravity }) => {
9783
- if (!accelerationIncludingGravity)
9784
- return;
9785
- const { x, y, z } = accelerationIncludingGravity;
9786
- this.propagateAcc({ x, y, z }, isAndroid);
9787
- };
9788
9792
  if (window.DeviceMotionEvent) {
9789
9793
  if (typeof window.DeviceMotionEvent.requestPermission === "function") {
9790
9794
  try {
9791
9795
  const response = await window.DeviceMotionEvent.requestPermission();
9792
- if (response !== "granted")
9796
+ if (response === "granted") {
9797
+ window.addEventListener("devicemotion", this.handleDeviceMotion, true);
9798
+ } else if (response === "denied") {
9799
+ alert("You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.");
9793
9800
  throw new Error("Unable to access the accelerometer.");
9794
- window.addEventListener("devicemotion", handleDeviceMotion, true);
9801
+ }
9795
9802
  } catch (error) {
9796
9803
  console.error(error);
9797
9804
  }
9798
9805
  } else {
9799
- window.addEventListener("devicemotion", handleDeviceMotion, true);
9806
+ window.addEventListener("devicemotion", this.handleDeviceMotion, true);
9800
9807
  }
9801
9808
  } else {
9802
9809
  console.log("Cannot set the accelerometer handler.");
9803
9810
  }
9804
9811
  }
9805
9812
  if (this.hasGyrInput) {
9806
- const handleDeviceOrientation = ({ alpha, beta, gamma }) => {
9807
- this.propagateGyr({ alpha, beta, gamma });
9808
- };
9809
9813
  if (window.DeviceMotionEvent) {
9810
9814
  if (typeof window.DeviceOrientationEvent.requestPermission === "function") {
9811
9815
  try {
9812
9816
  const response = await window.DeviceOrientationEvent.requestPermission();
9813
- if (response !== "granted")
9817
+ if (response === "granted") {
9818
+ window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
9819
+ } else if (response === "denied") {
9820
+ alert("You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.");
9814
9821
  throw new Error("Unable to access the gyroscope.");
9815
- window.addEventListener("deviceorientation", handleDeviceOrientation, true);
9822
+ }
9816
9823
  } catch (error) {
9817
9824
  console.error(error);
9818
9825
  }
9819
9826
  } else {
9820
- window.addEventListener("deviceorientation", handleDeviceOrientation, true);
9827
+ window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
9821
9828
  }
9822
9829
  } else {
9823
9830
  console.log("Cannot set the gyroscope handler.");
9824
9831
  }
9825
9832
  }
9826
9833
  }
9834
+ stopSensors() {
9835
+ if (this.hasAccInput) {
9836
+ window.removeEventListener("devicemotion", this.handleDeviceMotion, true);
9837
+ }
9838
+ if (this.hasGyrInput) {
9839
+ window.removeEventListener("deviceorientation", this.handleDeviceOrientation, true);
9840
+ }
9841
+ }
9827
9842
  setOutputParamHandler(handler) {
9828
9843
  this.fOutputHandler = handler;
9829
9844
  }
@@ -10013,6 +10028,21 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
10013
10028
 
10014
10029
  // src/FaustScriptProcessorNode.ts
10015
10030
  var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode || null) {
10031
+ constructor() {
10032
+ super(...arguments);
10033
+ // Public API
10034
+ // Accelerometer and gyroscope handlers
10035
+ this.handleDeviceMotion = ({ accelerationIncludingGravity }) => {
10036
+ const isAndroid = /Android/i.test(navigator.userAgent);
10037
+ if (!accelerationIncludingGravity)
10038
+ return;
10039
+ const { x, y, z } = accelerationIncludingGravity;
10040
+ this.propagateAcc({ x, y, z }, isAndroid);
10041
+ };
10042
+ this.handleDeviceOrientation = ({ alpha, beta, gamma }) => {
10043
+ this.propagateGyr({ alpha, beta, gamma });
10044
+ };
10045
+ }
10016
10046
  init(instance) {
10017
10047
  this.fDSPCode = instance;
10018
10048
  this.fInputs = new Array(this.fDSPCode.getNumInputs());
@@ -10028,56 +10058,53 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
10028
10058
  };
10029
10059
  this.start();
10030
10060
  }
10031
- // Public API
10032
10061
  /** Setup accelerometer and gyroscope handlers */
10033
- async listenSensors() {
10062
+ async startSensors() {
10034
10063
  if (this.hasAccInput) {
10035
- const isAndroid = /Android/i.test(navigator.userAgent);
10036
- const handleDeviceMotion = ({ accelerationIncludingGravity }) => {
10037
- if (!accelerationIncludingGravity)
10038
- return;
10039
- const { x, y, z } = accelerationIncludingGravity;
10040
- this.propagateAcc({ x, y, z }, isAndroid);
10041
- };
10042
10064
  if (window.DeviceMotionEvent) {
10043
10065
  if (typeof window.DeviceMotionEvent.requestPermission === "function") {
10044
10066
  try {
10045
10067
  const response = await window.DeviceMotionEvent.requestPermission();
10046
10068
  if (response !== "granted")
10047
10069
  throw new Error("Unable to access the accelerometer.");
10048
- window.addEventListener("devicemotion", handleDeviceMotion, true);
10070
+ window.addEventListener("devicemotion", this.handleDeviceMotion, true);
10049
10071
  } catch (error) {
10050
10072
  console.error(error);
10051
10073
  }
10052
10074
  } else {
10053
- window.addEventListener("devicemotion", handleDeviceMotion, true);
10075
+ window.addEventListener("devicemotion", this.handleDeviceMotion, true);
10054
10076
  }
10055
10077
  } else {
10056
10078
  console.log("Cannot set the accelerometer handler.");
10057
10079
  }
10058
10080
  }
10059
10081
  if (this.hasGyrInput) {
10060
- const handleDeviceOrientation = ({ alpha, beta, gamma }) => {
10061
- this.propagateGyr({ alpha, beta, gamma });
10062
- };
10063
10082
  if (window.DeviceMotionEvent) {
10064
10083
  if (typeof window.DeviceOrientationEvent.requestPermission === "function") {
10065
10084
  try {
10066
10085
  const response = await window.DeviceOrientationEvent.requestPermission();
10067
10086
  if (response !== "granted")
10068
10087
  throw new Error("Unable to access the gyroscope.");
10069
- window.addEventListener("deviceorientation", handleDeviceOrientation, true);
10088
+ window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
10070
10089
  } catch (error) {
10071
10090
  console.error(error);
10072
10091
  }
10073
10092
  } else {
10074
- window.addEventListener("deviceorientation", handleDeviceOrientation, true);
10093
+ window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
10075
10094
  }
10076
10095
  } else {
10077
10096
  console.log("Cannot set the gyroscope handler.");
10078
10097
  }
10079
10098
  }
10080
10099
  }
10100
+ stopSensors() {
10101
+ if (this.hasAccInput) {
10102
+ window.removeEventListener("devicemotion", this.handleDeviceMotion, true);
10103
+ }
10104
+ if (this.hasGyrInput) {
10105
+ window.removeEventListener("deviceorientation", this.handleDeviceOrientation, true);
10106
+ }
10107
+ }
10081
10108
  compute(input, output) {
10082
10109
  return this.fDSPCode.compute(input, output);
10083
10110
  }