@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.
Binary file
@@ -7,6 +7,17 @@
7
7
  * @typedef {import("./faustwasm").FaustUIItem} FaustUIItem
8
8
  */
9
9
 
10
+ /**
11
+ * Registers the service worker.
12
+ */
13
+ if ('serviceWorker' in navigator) {
14
+ window.addEventListener('load', () => {
15
+ navigator.serviceWorker.register('./service-worker.js')
16
+ .then(reg => console.log('Service Worker registered', reg))
17
+ .catch(err => console.log('Service Worker registration failed', err));
18
+ });
19
+ }
20
+
10
21
  /** @type {HTMLSpanElement} */
11
22
  const $spanAudioInput = document.getElementById("audio-input");
12
23
  /** @type {HTMLSpanElement} */
@@ -1,6 +1,8 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
3
 
4
+ <link rel="manifest" href="/FAUST_DSP/manifest.json">
5
+
4
6
  <head>
5
7
  <meta charset="UTF-8">
6
8
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
@@ -59,7 +61,7 @@
59
61
  flex-direction: column;
60
62
  }
61
63
  </style>
62
- <link rel="stylesheet" href="./faust-ui/index.css">
64
+ <link rel="stylesheet" href="/FAUST_DSP/faust-ui/index.css">
63
65
  </head>
64
66
 
65
67
  <body>
@@ -78,7 +80,7 @@
78
80
  <div id="div-faust-ui">
79
81
  </div>
80
82
  </main>
81
- <script src="./FAUST_DSP.js"></script>
83
+ <script src="/FAUST_DSP/FAUST_DSP.js"></script>
82
84
  </body>
83
85
 
84
86
  </html>
@@ -7,6 +7,17 @@
7
7
  * @typedef {import("./faustwasm").FaustUIItem} FaustUIItem
8
8
  */
9
9
 
10
+ /**
11
+ * Registers the service worker.
12
+ */
13
+ if ('serviceWorker' in navigator) {
14
+ window.addEventListener('load', () => {
15
+ navigator.serviceWorker.register('./service-worker.js')
16
+ .then(reg => console.log('Service Worker registered', reg))
17
+ .catch(err => console.log('Service Worker registration failed', err));
18
+ });
19
+ }
20
+
10
21
  /** @type {HTMLSpanElement} */
11
22
  const $spanAudioInput = document.getElementById("audio-input");
12
23
  /** @type {HTMLSpanElement} */
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "Faust FAUST_DSP",
3
+ "short_name": "FAUST_DSP",
4
+ "start_url": "/FAUST_DSP/index.html",
5
+ "description": "Progressive Web App for FAUST_DSP",
6
+ "display": "standalone",
7
+ "background_color": "#ffffff",
8
+ "theme_color": "#000000",
9
+ "scope": "/FAUST_DSP/",
10
+ "orientation": "portrait",
11
+ "icons": [
12
+ {
13
+ "src": "icon.png",
14
+ "sizes": "390x390",
15
+ "type": "image/png"
16
+ }
17
+ ]
18
+ }
@@ -0,0 +1,48 @@
1
+
2
+ const CACHE_NAME = 'FAUST_DSP-static'; // Cache name without versioning
3
+
4
+ self.addEventListener('install', event => {
5
+ event.waitUntil(
6
+ caches.open(CACHE_NAME).then(cache => {
7
+ console.log("Service worker installed");
8
+ return cache.addAll([
9
+ '/FAUST_DSP/',
10
+ '/FAUST_DSP/faust-ui/index.js',
11
+ '/FAUST_DSP/faust-ui/index.css',
12
+ '/FAUST_DSP/faustwasm/index.js',
13
+ '/FAUST_DSP/FAUST_DSP.js',
14
+ '/FAUST_DSP/FAUST_DSP.wasm',
15
+ '/FAUST_DSP/FAUST_DSP.json',
16
+ ]).catch(error => {
17
+ // Catch and log any errors during the caching process
18
+ console.error('Failed to cache resources during install:', error);
19
+ });
20
+ })
21
+ );
22
+ });
23
+
24
+ self.addEventListener("activate", event => {
25
+ console.log("Service worker activated");
26
+ });
27
+
28
+ self.addEventListener('fetch', event => {
29
+ event.respondWith((async () => {
30
+ const cache = await caches.open(CACHE_NAME);
31
+ const cachedResponse = await cache.match(event.request);
32
+ if (cachedResponse) {
33
+ return cachedResponse;
34
+ } else {
35
+ try {
36
+ const fetchResponse = await fetch(event.request);
37
+ // Ensure the response is valid before caching it
38
+ if (event.request.method === 'GET' && fetchResponse && fetchResponse.status === 200 && fetchResponse.type === 'basic') {
39
+ cache.put(event.request, fetchResponse.clone());
40
+ }
41
+ return fetchResponse;
42
+ } catch (e) {
43
+ // Network access failure
44
+ console.log('Network access error', e);
45
+ }
46
+ }
47
+ })());
48
+ });
@@ -635,7 +635,7 @@ export interface IFaustBaseWebAudioDsp {
635
635
  /** Indicating if the DSP handles the accelerometer */
636
636
  readonly hasAccInput: boolean;
637
637
  /** Accelerometer handling */
638
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
638
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean): void;
639
639
  /** Indicating if the DSP handles the gyroscope */
640
640
  readonly hasGyrInput: boolean;
641
641
  /** Gyroscope handling */
@@ -724,7 +724,7 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
724
724
  /** Split the soundfile names and return an array of names */
725
725
  static splitSoundfileNames(input: string): string[];
726
726
  get hasAccInput(): boolean;
727
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
727
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert?: boolean): void;
728
728
  get hasGyrInput(): boolean;
729
729
  propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
730
730
  /** Build the accelerometer handler */
@@ -1123,7 +1123,7 @@ export declare class FaustOfflineProcessor<Poly extends boolean = false> {
1123
1123
  stop(): void;
1124
1124
  destroy(): void;
1125
1125
  get hasAccInput(): boolean;
1126
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
1126
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert?: boolean): void;
1127
1127
  get hasGyrInput(): boolean;
1128
1128
  propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
1129
1129
  /**
@@ -1211,6 +1211,12 @@ export declare class WavDecoder {
1211
1211
  /** Read metadata and fetch soundfiles */
1212
1212
  export declare class SoundfileReader {
1213
1213
  static get fallbackPaths(): string[];
1214
+ /**
1215
+ * Extract the parent URL from an URL.
1216
+ * @param url : the URL
1217
+ * @returns : the parent URL
1218
+ */
1219
+ private static getParentUrl;
1214
1220
  /**
1215
1221
  * Convert an audio buffer to audio data.
1216
1222
  *
@@ -1293,7 +1299,7 @@ export declare class FaustAudioWorkletNode<Poly extends boolean = false> extends
1293
1299
  ctrlChange(channel: number, ctrl: number, value: number): void;
1294
1300
  pitchWheel(channel: number, wheel: number): void;
1295
1301
  get hasAccInput(): boolean;
1296
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
1302
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert?: boolean): void;
1297
1303
  get hasGyrInput(): boolean;
1298
1304
  propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
1299
1305
  setParamValue(path: string, value: number): void;
@@ -1366,7 +1372,7 @@ export declare class FaustScriptProcessorNode<Poly extends boolean = false> exte
1366
1372
  stop(): void;
1367
1373
  destroy(): void;
1368
1374
  get hasAccInput(): boolean;
1369
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
1375
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert?: boolean): void;
1370
1376
  get hasGyrInput(): boolean;
1371
1377
  propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
1372
1378
  }
package/dist/cjs/index.js CHANGED
@@ -168,7 +168,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
168
168
  const msg = e.data;
169
169
  switch (msg.type) {
170
170
  case "acc": {
171
- this.propagateAcc(msg.data);
171
+ this.propagateAcc(msg.data, msg.invert);
172
172
  break;
173
173
  }
174
174
  case "gyr": {
@@ -229,8 +229,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
229
229
  pitchWheel(channel, wheel) {
230
230
  this.fDSPCode.pitchWheel(channel, wheel);
231
231
  }
232
- propagateAcc(accelerationIncludingGravity) {
233
- this.fDSPCode.propagateAcc(accelerationIncludingGravity);
232
+ propagateAcc(accelerationIncludingGravity, invert = false) {
233
+ this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
234
234
  }
235
235
  propagateGyr(event) {
236
236
  this.fDSPCode.propagateGyr(event);
@@ -2133,14 +2133,23 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2133
2133
  get hasAccInput() {
2134
2134
  return this.fAcc.x.length + this.fAcc.y.length + this.fAcc.z.length > 0;
2135
2135
  }
2136
- propagateAcc(accelerationIncludingGravity) {
2136
+ propagateAcc(accelerationIncludingGravity, invert = false) {
2137
2137
  const { x, y, z } = accelerationIncludingGravity;
2138
- if (x !== null)
2139
- this.fAcc.x.forEach((handler) => handler(x));
2140
- if (y !== null)
2141
- this.fAcc.y.forEach((handler) => handler(y));
2142
- if (z !== null)
2143
- this.fAcc.z.forEach((handler) => handler(z));
2138
+ if (invert) {
2139
+ if (x !== null)
2140
+ this.fAcc.x.forEach((handler) => handler(-x));
2141
+ if (y !== null)
2142
+ this.fAcc.y.forEach((handler) => handler(-y));
2143
+ if (z !== null)
2144
+ this.fAcc.z.forEach((handler) => handler(-z));
2145
+ } else {
2146
+ if (x !== null)
2147
+ this.fAcc.x.forEach((handler) => handler(x));
2148
+ if (y !== null)
2149
+ this.fAcc.y.forEach((handler) => handler(y));
2150
+ if (z !== null)
2151
+ this.fAcc.z.forEach((handler) => handler(z));
2152
+ }
2144
2153
  }
2145
2154
  get hasGyrInput() {
2146
2155
  return this.fGyr.x.length + this.fGyr.y.length + this.fGyr.z.length > 0;
@@ -3000,8 +3009,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3000
3009
  get hasAccInput() {
3001
3010
  return this.fDSPCode.hasAccInput;
3002
3011
  }
3003
- propagateAcc(accelerationIncludingGravity) {
3004
- this.fDSPCode.propagateAcc(accelerationIncludingGravity);
3012
+ propagateAcc(accelerationIncludingGravity, invert = false) {
3013
+ this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
3005
3014
  }
3006
3015
  get hasGyrInput() {
3007
3016
  return this.fDSPCode.hasGyrInput;
@@ -3517,8 +3526,17 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3517
3526
 
3518
3527
  // src/SoundfileReader.ts
3519
3528
  var SoundfileReader = class {
3529
+ // Set the fallback paths
3520
3530
  static get fallbackPaths() {
3521
- return [location.href, location.origin];
3531
+ return [location.href, this.getParentUrl(location.href), location.origin];
3532
+ }
3533
+ /**
3534
+ * Extract the parent URL from an URL.
3535
+ * @param url : the URL
3536
+ * @returns : the parent URL
3537
+ */
3538
+ static getParentUrl(url) {
3539
+ return url.substring(0, url.lastIndexOf("/") + 1);
3522
3540
  }
3523
3541
  /**
3524
3542
  * Convert an audio buffer to audio data.
@@ -3559,7 +3577,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3559
3577
  static async checkFileExists(url) {
3560
3578
  try {
3561
3579
  console.log(`"checkFileExists" url: ${url}`);
3562
- const response = await fetch(url, { method: "HEAD" });
3580
+ const response = await fetch(url);
3581
+ console.log(`"checkFileExists" response.ok: ${response.ok}`);
3563
3582
  return response.ok;
3564
3583
  } catch (error) {
3565
3584
  console.error("Fetch error:", error);
@@ -3679,12 +3698,23 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3679
3698
  /** Setup accelerometer and gyroscope handlers */
3680
3699
  async listenSensors() {
3681
3700
  if (this.hasAccInput) {
3682
- const handleDeviceMotion = ({ accelerationIncludingGravity }) => {
3683
- if (!accelerationIncludingGravity)
3684
- return;
3685
- const { x, y, z } = accelerationIncludingGravity;
3686
- this.propagateAcc({ x, y, z });
3687
- };
3701
+ const isAndroid = /Android/i.test(navigator.userAgent);
3702
+ let handleDeviceMotion = null;
3703
+ if (isAndroid) {
3704
+ handleDeviceMotion = ({ accelerationIncludingGravity }) => {
3705
+ if (!accelerationIncludingGravity)
3706
+ return;
3707
+ const { x, y, z } = accelerationIncludingGravity;
3708
+ this.propagateAcc({ x, y, z }, true);
3709
+ };
3710
+ } else {
3711
+ handleDeviceMotion = ({ accelerationIncludingGravity }) => {
3712
+ if (!accelerationIncludingGravity)
3713
+ return;
3714
+ const { x, y, z } = accelerationIncludingGravity;
3715
+ this.propagateAcc({ x, y, z });
3716
+ };
3717
+ }
3688
3718
  if (window.DeviceMotionEvent) {
3689
3719
  if (typeof window.DeviceMotionEvent.requestPermission === "function") {
3690
3720
  try {
@@ -3785,10 +3815,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3785
3815
  get hasAccInput() {
3786
3816
  return __privateGet(this, _hasAccInput);
3787
3817
  }
3788
- propagateAcc(accelerationIncludingGravity) {
3818
+ propagateAcc(accelerationIncludingGravity, invert = false) {
3789
3819
  if (!accelerationIncludingGravity)
3790
3820
  return;
3791
- const e = { type: "acc", data: accelerationIncludingGravity };
3821
+ const e = { type: "acc", data: accelerationIncludingGravity, invert };
3792
3822
  this.port.postMessage(e);
3793
3823
  }
3794
3824
  get hasGyrInput() {
@@ -3937,12 +3967,23 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3937
3967
  /** Setup accelerometer and gyroscope handlers */
3938
3968
  async listenSensors() {
3939
3969
  if (this.hasAccInput) {
3940
- const handleDeviceMotion = ({ accelerationIncludingGravity }) => {
3941
- if (!accelerationIncludingGravity)
3942
- return;
3943
- const { x, y, z } = accelerationIncludingGravity;
3944
- this.propagateAcc({ x, y, z });
3945
- };
3970
+ const isAndroid = /Android/i.test(navigator.userAgent);
3971
+ let handleDeviceMotion = null;
3972
+ if (isAndroid) {
3973
+ handleDeviceMotion = ({ accelerationIncludingGravity }) => {
3974
+ if (!accelerationIncludingGravity)
3975
+ return;
3976
+ const { x, y, z } = accelerationIncludingGravity;
3977
+ this.propagateAcc({ x, y, z }, true);
3978
+ };
3979
+ } else {
3980
+ handleDeviceMotion = ({ accelerationIncludingGravity }) => {
3981
+ if (!accelerationIncludingGravity)
3982
+ return;
3983
+ const { x, y, z } = accelerationIncludingGravity;
3984
+ this.propagateAcc({ x, y, z });
3985
+ };
3986
+ }
3946
3987
  if (window.DeviceMotionEvent) {
3947
3988
  if (typeof window.DeviceMotionEvent.requestPermission === "function") {
3948
3989
  try {
@@ -4053,8 +4094,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4053
4094
  get hasAccInput() {
4054
4095
  return this.fDSPCode.hasAccInput;
4055
4096
  }
4056
- propagateAcc(accelerationIncludingGravity) {
4057
- this.fDSPCode.propagateAcc(accelerationIncludingGravity);
4097
+ propagateAcc(accelerationIncludingGravity, invert = false) {
4098
+ this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
4058
4099
  }
4059
4100
  get hasGyrInput() {
4060
4101
  return this.fDSPCode.hasGyrInput;