@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.
@@ -33,7 +33,7 @@ audioContext.suspend();
33
33
 
34
34
  const { createFaustNode } = await import("./create-node.js");
35
35
  // To test the ScriptProcessorNode mode
36
- // const { faustNode, dspMeta: { name } } = await createFaustNode(audioContext, "osc", FAUST_DSP_VOICES, true);
36
+ //const { faustNode, dspMeta: { name } } = await createFaustNode(audioContext, "osc", FAUST_DSP_VOICES, true, 512);
37
37
  const { faustNode, dspMeta: { name } } = await createFaustNode(audioContext, "osc", FAUST_DSP_VOICES);
38
38
  if (!faustNode) throw new Error("Faust DSP not compiled");
39
39
 
@@ -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;
package/dist/cjs/index.js CHANGED
@@ -4013,8 +4013,13 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4013
4013
  var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode || null) {
4014
4014
  constructor() {
4015
4015
  super(...arguments);
4016
- // Public API
4017
- // Accelerometer and gyroscope handlers
4016
+ this.handleDeviceMotion = void 0;
4017
+ this.handleDeviceOrientation = void 0;
4018
+ }
4019
+ init(instance) {
4020
+ this.fDSPCode = instance;
4021
+ this.fInputs = new Array(this.fDSPCode.getNumInputs());
4022
+ this.fOutputs = new Array(this.fDSPCode.getNumOutputs());
4018
4023
  this.handleDeviceMotion = ({ accelerationIncludingGravity }) => {
4019
4024
  const isAndroid = /Android/i.test(navigator.userAgent);
4020
4025
  if (!accelerationIncludingGravity)
@@ -4025,11 +4030,6 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4025
4030
  this.handleDeviceOrientation = ({ alpha, beta, gamma }) => {
4026
4031
  this.propagateGyr({ alpha, beta, gamma });
4027
4032
  };
4028
- }
4029
- init(instance) {
4030
- this.fDSPCode = instance;
4031
- this.fInputs = new Array(this.fDSPCode.getNumInputs());
4032
- this.fOutputs = new Array(this.fDSPCode.getNumOutputs());
4033
4033
  this.onaudioprocess = (e) => {
4034
4034
  for (let chan = 0; chan < this.fDSPCode.getNumInputs(); chan++) {
4035
4035
  this.fInputs[chan] = e.inputBuffer.getChannelData(chan);
@@ -4041,6 +4041,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4041
4041
  };
4042
4042
  this.start();
4043
4043
  }
4044
+ // Public API
4044
4045
  /** Setup accelerometer and gyroscope handlers */
4045
4046
  async startSensors() {
4046
4047
  if (this.hasAccInput) {
@@ -4048,9 +4049,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4048
4049
  if (typeof window.DeviceMotionEvent.requestPermission === "function") {
4049
4050
  try {
4050
4051
  const response = await window.DeviceMotionEvent.requestPermission();
4051
- if (response !== "granted")
4052
+ if (response === "granted") {
4053
+ window.addEventListener("devicemotion", this.handleDeviceMotion, true);
4054
+ } else if (response === "denied") {
4055
+ alert("You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.");
4052
4056
  throw new Error("Unable to access the accelerometer.");
4053
- window.addEventListener("devicemotion", this.handleDeviceMotion, true);
4057
+ }
4054
4058
  } catch (error) {
4055
4059
  console.error(error);
4056
4060
  }
@@ -4066,9 +4070,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4066
4070
  if (typeof window.DeviceOrientationEvent.requestPermission === "function") {
4067
4071
  try {
4068
4072
  const response = await window.DeviceOrientationEvent.requestPermission();
4069
- if (response !== "granted")
4073
+ if (response === "granted") {
4074
+ window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
4075
+ } else if (response === "denied") {
4076
+ alert("You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.");
4070
4077
  throw new Error("Unable to access the gyroscope.");
4071
- window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
4078
+ }
4072
4079
  } catch (error) {
4073
4080
  console.error(error);
4074
4081
  }