@grame/faustwasm 0.3.1 → 0.4.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.
@@ -642,7 +642,7 @@ export interface IFaustBaseWebAudioDsp {
642
642
  /** Indicating if the DSP handles the accelerometer */
643
643
  readonly hasAccInput: boolean;
644
644
  /** Accelerometer handling */
645
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
645
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean): void;
646
646
  /** Indicating if the DSP handles the gyroscope */
647
647
  readonly hasGyrInput: boolean;
648
648
  /** Gyroscope handling */
@@ -731,7 +731,7 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
731
731
  /** Split the soundfile names and return an array of names */
732
732
  static splitSoundfileNames(input: string): string[];
733
733
  get hasAccInput(): boolean;
734
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
734
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert?: boolean): void;
735
735
  get hasGyrInput(): boolean;
736
736
  propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
737
737
  /** Build the accelerometer handler */
@@ -1130,7 +1130,7 @@ export declare class FaustOfflineProcessor<Poly extends boolean = false> {
1130
1130
  stop(): void;
1131
1131
  destroy(): void;
1132
1132
  get hasAccInput(): boolean;
1133
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
1133
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert?: boolean): void;
1134
1134
  get hasGyrInput(): boolean;
1135
1135
  propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
1136
1136
  /**
@@ -1218,6 +1218,12 @@ export declare class WavDecoder {
1218
1218
  /** Read metadata and fetch soundfiles */
1219
1219
  export declare class SoundfileReader {
1220
1220
  static get fallbackPaths(): string[];
1221
+ /**
1222
+ * Extract the parent URL from an URL.
1223
+ * @param url : the URL
1224
+ * @returns : the parent URL
1225
+ */
1226
+ private static getParentUrl;
1221
1227
  /**
1222
1228
  * Convert an audio buffer to audio data.
1223
1229
  *
@@ -1300,7 +1306,7 @@ export declare class FaustAudioWorkletNode<Poly extends boolean = false> extends
1300
1306
  ctrlChange(channel: number, ctrl: number, value: number): void;
1301
1307
  pitchWheel(channel: number, wheel: number): void;
1302
1308
  get hasAccInput(): boolean;
1303
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
1309
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert?: boolean): void;
1304
1310
  get hasGyrInput(): boolean;
1305
1311
  propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
1306
1312
  setParamValue(path: string, value: number): void;
@@ -1373,7 +1379,7 @@ export declare class FaustScriptProcessorNode<Poly extends boolean = false> exte
1373
1379
  stop(): void;
1374
1380
  destroy(): void;
1375
1381
  get hasAccInput(): boolean;
1376
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
1382
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert?: boolean): void;
1377
1383
  get hasGyrInput(): boolean;
1378
1384
  propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
1379
1385
  }
@@ -6185,7 +6185,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6185
6185
  const msg = e.data;
6186
6186
  switch (msg.type) {
6187
6187
  case "acc": {
6188
- this.propagateAcc(msg.data);
6188
+ this.propagateAcc(msg.data, msg.invert);
6189
6189
  break;
6190
6190
  }
6191
6191
  case "gyr": {
@@ -6246,8 +6246,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6246
6246
  pitchWheel(channel, wheel) {
6247
6247
  this.fDSPCode.pitchWheel(channel, wheel);
6248
6248
  }
6249
- propagateAcc(accelerationIncludingGravity) {
6250
- this.fDSPCode.propagateAcc(accelerationIncludingGravity);
6249
+ propagateAcc(accelerationIncludingGravity, invert = false) {
6250
+ this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
6251
6251
  }
6252
6252
  propagateGyr(event) {
6253
6253
  this.fDSPCode.propagateGyr(event);
@@ -8150,14 +8150,23 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8150
8150
  get hasAccInput() {
8151
8151
  return this.fAcc.x.length + this.fAcc.y.length + this.fAcc.z.length > 0;
8152
8152
  }
8153
- propagateAcc(accelerationIncludingGravity) {
8153
+ propagateAcc(accelerationIncludingGravity, invert = false) {
8154
8154
  const { x, y, z } = accelerationIncludingGravity;
8155
- if (x !== null)
8156
- this.fAcc.x.forEach((handler) => handler(x));
8157
- if (y !== null)
8158
- this.fAcc.y.forEach((handler) => handler(y));
8159
- if (z !== null)
8160
- this.fAcc.z.forEach((handler) => handler(z));
8155
+ if (invert) {
8156
+ if (x !== null)
8157
+ this.fAcc.x.forEach((handler) => handler(-x));
8158
+ if (y !== null)
8159
+ this.fAcc.y.forEach((handler) => handler(-y));
8160
+ if (z !== null)
8161
+ this.fAcc.z.forEach((handler) => handler(-z));
8162
+ } else {
8163
+ if (x !== null)
8164
+ this.fAcc.x.forEach((handler) => handler(x));
8165
+ if (y !== null)
8166
+ this.fAcc.y.forEach((handler) => handler(y));
8167
+ if (z !== null)
8168
+ this.fAcc.z.forEach((handler) => handler(z));
8169
+ }
8161
8170
  }
8162
8171
  get hasGyrInput() {
8163
8172
  return this.fGyr.x.length + this.fGyr.y.length + this.fGyr.z.length > 0;
@@ -9017,8 +9026,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9017
9026
  get hasAccInput() {
9018
9027
  return this.fDSPCode.hasAccInput;
9019
9028
  }
9020
- propagateAcc(accelerationIncludingGravity) {
9021
- this.fDSPCode.propagateAcc(accelerationIncludingGravity);
9029
+ propagateAcc(accelerationIncludingGravity, invert = false) {
9030
+ this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
9022
9031
  }
9023
9032
  get hasGyrInput() {
9024
9033
  return this.fDSPCode.hasGyrInput;
@@ -9534,8 +9543,17 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9534
9543
 
9535
9544
  // src/SoundfileReader.ts
9536
9545
  var SoundfileReader = class {
9546
+ // Set the fallback paths
9537
9547
  static get fallbackPaths() {
9538
- return [location.href, location.origin];
9548
+ return [location.href, this.getParentUrl(location.href), location.origin];
9549
+ }
9550
+ /**
9551
+ * Extract the parent URL from an URL.
9552
+ * @param url : the URL
9553
+ * @returns : the parent URL
9554
+ */
9555
+ static getParentUrl(url) {
9556
+ return url.substring(0, url.lastIndexOf("/") + 1);
9539
9557
  }
9540
9558
  /**
9541
9559
  * Convert an audio buffer to audio data.
@@ -9576,7 +9594,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9576
9594
  static async checkFileExists(url) {
9577
9595
  try {
9578
9596
  console.log(`"checkFileExists" url: ${url}`);
9579
- const response = await fetch(url, { method: "HEAD" });
9597
+ const response = await fetch(url);
9598
+ console.log(`"checkFileExists" response.ok: ${response.ok}`);
9580
9599
  return response.ok;
9581
9600
  } catch (error) {
9582
9601
  console.error("Fetch error:", error);
@@ -9696,12 +9715,23 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9696
9715
  /** Setup accelerometer and gyroscope handlers */
9697
9716
  async listenSensors() {
9698
9717
  if (this.hasAccInput) {
9699
- const handleDeviceMotion = ({ accelerationIncludingGravity }) => {
9700
- if (!accelerationIncludingGravity)
9701
- return;
9702
- const { x, y, z } = accelerationIncludingGravity;
9703
- this.propagateAcc({ x, y, z });
9704
- };
9718
+ const isAndroid = /Android/i.test(navigator.userAgent);
9719
+ let handleDeviceMotion = null;
9720
+ if (isAndroid) {
9721
+ handleDeviceMotion = ({ accelerationIncludingGravity }) => {
9722
+ if (!accelerationIncludingGravity)
9723
+ return;
9724
+ const { x, y, z } = accelerationIncludingGravity;
9725
+ this.propagateAcc({ x, y, z }, true);
9726
+ };
9727
+ } else {
9728
+ handleDeviceMotion = ({ accelerationIncludingGravity }) => {
9729
+ if (!accelerationIncludingGravity)
9730
+ return;
9731
+ const { x, y, z } = accelerationIncludingGravity;
9732
+ this.propagateAcc({ x, y, z });
9733
+ };
9734
+ }
9705
9735
  if (window.DeviceMotionEvent) {
9706
9736
  if (typeof window.DeviceMotionEvent.requestPermission === "function") {
9707
9737
  try {
@@ -9802,10 +9832,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9802
9832
  get hasAccInput() {
9803
9833
  return __privateGet(this, _hasAccInput);
9804
9834
  }
9805
- propagateAcc(accelerationIncludingGravity) {
9835
+ propagateAcc(accelerationIncludingGravity, invert = false) {
9806
9836
  if (!accelerationIncludingGravity)
9807
9837
  return;
9808
- const e = { type: "acc", data: accelerationIncludingGravity };
9838
+ const e = { type: "acc", data: accelerationIncludingGravity, invert };
9809
9839
  this.port.postMessage(e);
9810
9840
  }
9811
9841
  get hasGyrInput() {
@@ -9954,12 +9984,23 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9954
9984
  /** Setup accelerometer and gyroscope handlers */
9955
9985
  async listenSensors() {
9956
9986
  if (this.hasAccInput) {
9957
- const handleDeviceMotion = ({ accelerationIncludingGravity }) => {
9958
- if (!accelerationIncludingGravity)
9959
- return;
9960
- const { x, y, z } = accelerationIncludingGravity;
9961
- this.propagateAcc({ x, y, z });
9962
- };
9987
+ const isAndroid = /Android/i.test(navigator.userAgent);
9988
+ let handleDeviceMotion = null;
9989
+ if (isAndroid) {
9990
+ handleDeviceMotion = ({ accelerationIncludingGravity }) => {
9991
+ if (!accelerationIncludingGravity)
9992
+ return;
9993
+ const { x, y, z } = accelerationIncludingGravity;
9994
+ this.propagateAcc({ x, y, z }, true);
9995
+ };
9996
+ } else {
9997
+ handleDeviceMotion = ({ accelerationIncludingGravity }) => {
9998
+ if (!accelerationIncludingGravity)
9999
+ return;
10000
+ const { x, y, z } = accelerationIncludingGravity;
10001
+ this.propagateAcc({ x, y, z });
10002
+ };
10003
+ }
9963
10004
  if (window.DeviceMotionEvent) {
9964
10005
  if (typeof window.DeviceMotionEvent.requestPermission === "function") {
9965
10006
  try {
@@ -10070,8 +10111,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
10070
10111
  get hasAccInput() {
10071
10112
  return this.fDSPCode.hasAccInput;
10072
10113
  }
10073
- propagateAcc(accelerationIncludingGravity) {
10074
- this.fDSPCode.propagateAcc(accelerationIncludingGravity);
10114
+ propagateAcc(accelerationIncludingGravity, invert = false) {
10115
+ this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
10075
10116
  }
10076
10117
  get hasGyrInput() {
10077
10118
  return this.fDSPCode.hasGyrInput;