@grame/faustwasm 0.8.0 → 0.9.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.
Files changed (67) hide show
  1. package/assets/standalone/create-node.js +46 -9
  2. package/assets/standalone/faust-ui/index.js +2 -2
  3. package/assets/standalone/faust-ui/index.js.map +1 -1
  4. package/assets/standalone/faustwasm/index.d.ts +42 -2
  5. package/assets/standalone/faustwasm/index.js +117 -66
  6. package/assets/standalone/faustwasm/index.js.map +2 -2
  7. package/assets/standalone/index-pwa.js +125 -90
  8. package/assets/standalone/index-template.js +43 -22
  9. package/assets/standalone/index.js +36 -19
  10. package/assets/standalone/service-worker.js +58 -5
  11. package/dist/cjs/index.d.ts +42 -2
  12. package/dist/cjs/index.js +117 -66
  13. package/dist/cjs/index.js.map +2 -2
  14. package/dist/cjs-bundle/index.d.ts +42 -2
  15. package/dist/cjs-bundle/index.js +117 -66
  16. package/dist/cjs-bundle/index.js.map +2 -2
  17. package/dist/esm/index.d.ts +42 -2
  18. package/dist/esm/index.js +117 -66
  19. package/dist/esm/index.js.map +2 -2
  20. package/dist/esm-bundle/index.d.ts +42 -2
  21. package/dist/esm-bundle/index.js +117 -66
  22. package/dist/esm-bundle/index.js.map +2 -2
  23. package/package.json +2 -2
  24. package/src/FaustAudioWorkletNode.ts +14 -30
  25. package/src/FaustAudioWorkletProcessor.ts +16 -0
  26. package/src/FaustOfflineProcessor.ts +2 -0
  27. package/src/FaustScriptProcessorNode.ts +6 -30
  28. package/src/FaustWebAudioDsp.ts +88 -0
  29. package/src/copyWebStandaloneAssets.js +14 -0
  30. package/test/faustlive-wasm/faust-ui/index.js +2 -2
  31. package/test/faustlive-wasm/faust-ui/index.js.map +1 -1
  32. package/test/faustlive-wasm/faustwasm/index.d.ts +42 -2
  33. package/test/faustlive-wasm/faustwasm/index.js +117 -66
  34. package/test/faustlive-wasm/faustwasm/index.js.map +2 -2
  35. package/test/midi/create-node.js +177 -0
  36. package/test/midi/dsp-meta.json +133 -0
  37. package/test/midi/dsp-module.wasm +0 -0
  38. package/test/midi/faust-ui/index.css +442 -0
  39. package/test/midi/faust-ui/index.css.map +1 -0
  40. package/test/midi/faust-ui/index.d.ts +1 -0
  41. package/test/midi/faust-ui/index.js +3729 -0
  42. package/test/midi/faust-ui/index.js.map +1 -0
  43. package/test/midi/faustwasm/index.d.ts +1680 -0
  44. package/test/midi/faustwasm/index.js +4884 -0
  45. package/test/midi/faustwasm/index.js.map +7 -0
  46. package/test/midi/icon.png +0 -0
  47. package/test/midi/index.html +76 -0
  48. package/test/midi/index.js +183 -0
  49. package/test/midi/manifest.json +17 -0
  50. package/test/midi/service-worker.js +165 -0
  51. package/test/midi.dsp +8 -1
  52. package/test/organ1/create-node.js +177 -0
  53. package/test/organ1/dsp-meta.json +126 -0
  54. package/test/organ1/dsp-module.wasm +0 -0
  55. package/test/organ1/faust-ui/index.css +442 -0
  56. package/test/organ1/faust-ui/index.css.map +1 -0
  57. package/test/organ1/faust-ui/index.d.ts +1 -0
  58. package/test/organ1/faust-ui/index.js +3729 -0
  59. package/test/organ1/faust-ui/index.js.map +1 -0
  60. package/test/organ1/faustwasm/index.d.ts +1656 -0
  61. package/test/organ1/faustwasm/index.js +4783 -0
  62. package/test/organ1/faustwasm/index.js.map +7 -0
  63. package/test/organ1/icon.png +0 -0
  64. package/test/organ1/index.html +76 -0
  65. package/test/organ1/index.js +203 -0
  66. package/test/organ1/manifest.json +17 -0
  67. package/test/organ1/service-worker.js +181 -0
@@ -80,15 +80,15 @@ const createFaustNode = async (audioContext, dspName = "template", voices = 0, s
80
80
  }
81
81
 
82
82
  /**
83
- * Connects an audio input stream to a Faust audio node.
83
+ * Connects an audio input stream to a Faust WebAudio node.
84
84
  *
85
85
  * @param {AudioContext} audioContext - The Web Audio API AudioContext to which the Faust audio node is connected.
86
86
  * @param {string} id - The ID of the audio input device to connect.
87
87
  * @param {FaustNode} faustNode - The Faust audio node to which the audio input stream will be connected.
88
- * @param {MediaStreamAudioSourceNode} inputStreamNode - The audio input stream node to be disconnected from the Faust audio node.
89
- * @returns {Promise<MediaStreamAudioSourceNode>} - The audio input stream node connected to the Faust audio node.
88
+ * @param {MediaStreamAudioSourceNode} oldInputStreamNode - The old audio input stream node to be disconnected from the Faust audio node.
89
+ * @returns {Promise<MediaStreamAudioSourceNode>} - The new audio input stream node connected to the Faust audio node.
90
90
  */
91
- async function connectToAudioInput(audioContext, id, faustNode, inputStreamNode) {
91
+ async function connectToAudioInput(audioContext, id, faustNode, oldInputStreamNode) {
92
92
  // Create an audio input stream node
93
93
  const constraints = {
94
94
  audio: {
@@ -101,14 +101,18 @@ async function connectToAudioInput(audioContext, id, faustNode, inputStreamNode)
101
101
  // Get the audio input stream
102
102
  const stream = await navigator.mediaDevices.getUserMedia(constraints);
103
103
  if (stream) {
104
- if (inputStreamNode) inputStreamNode.disconnect();
105
- inputStreamNode = audioContext.createMediaStreamSource(stream);
106
- inputStreamNode.connect(faustNode);
104
+ if (oldInputStreamNode) oldInputStreamNode.disconnect();
105
+ const newInputStreamNode = audioContext.createMediaStreamSource(stream);
106
+ newInputStreamNode.connect(faustNode);
107
+ return newInputStreamNode;
108
+ } else {
109
+ return oldInputStreamNode;
107
110
  }
108
- return inputStreamNode;
109
111
  };
110
112
 
111
113
  /**
114
+ * Creates a Faust UI for a Faust audio node.
115
+ *
112
116
  * @param {FaustAudioWorkletNode} faustNode
113
117
  */
114
118
  async function createFaustUI(divFaustUI, faustNode) {
@@ -135,6 +139,39 @@ async function createFaustUI(divFaustUI, faustNode) {
135
139
  faustUI.resize();
136
140
  };
137
141
 
142
+ /**
143
+ * Request permission to use motion and orientation sensors.
144
+ */
145
+ async function requestPermissions() {
146
+
147
+ // Explicitly request permission on iOS before calling startSensors()
148
+ if (typeof window.DeviceMotionEvent !== "undefined" && typeof window.DeviceMotionEvent.requestPermission === "function") {
149
+ try {
150
+ const permissionState = await window.DeviceMotionEvent.requestPermission();
151
+ if (permissionState !== "granted") {
152
+ console.warn("Motion sensor permission denied.");
153
+ } else {
154
+ console.log("Motion sensor permission granted.");
155
+ }
156
+ } catch (error) {
157
+ console.error("Error requesting motion sensor permission:", error);
158
+ }
159
+ }
160
+
161
+ if (typeof window.DeviceOrientationEvent !== "undefined" && typeof window.DeviceOrientationEvent.requestPermission === "function") {
162
+ try {
163
+ const permissionState = await window.DeviceOrientationEvent.requestPermission();
164
+ if (permissionState !== "granted") {
165
+ console.warn("Orientation sensor permission denied.");
166
+ } else {
167
+ console.log("Orientation sensor permission granted.");
168
+ }
169
+ } catch (error) {
170
+ console.error("Error requesting orientation sensor permission:", error);
171
+ }
172
+ }
173
+ }
174
+
138
175
  // Export the functions
139
- export { createFaustNode, createFaustUI, connectToAudioInput };
176
+ export { createFaustNode, createFaustUI, connectToAudioInput, requestPermissions };
140
177
 
@@ -946,10 +946,10 @@ class Group extends _AbstractComponent__WEBPACK_IMPORTED_MODULE_0__["default"] {
946
946
  if (!metaIn) return { metaObject };
947
947
  metaIn.forEach((m) => Object.assign(metaObject, m));
948
948
  if (metaObject.style) {
949
- const enumsRegex = /\{(?:(?:'|_|-)(.+?)(?:'|_|-):([-+]?[0-9]*\.?[0-9]+?);)+(?:(?:'|_|-)(.+?)(?:'|_|-):([-+]?[0-9]*\.?[0-9]+?))\}/;
949
+ const enumsRegex = /\{(?:(?:'|_|-)(.+?)(?:'|_|-):([-+]?[0-9]*\.?[0-9]+);)+(?:(?:'|_|-)(.+?)(?:'|_|-):([-+]?[0-9]*\.?[0-9]+))\}/;
950
950
  const matched = metaObject.style.match(enumsRegex);
951
951
  if (matched) {
952
- const itemsRegex = /(?:(?:'|_|-)(.+?)(?:'|_|-):([-+]?[0-9]*\.?[0-9]+?))/g;
952
+ const itemsRegex = /(?:(?:'|_|-)(.+?)(?:'|_|-):([-+]?[0-9]*\.?[0-9]+))/g;
953
953
  const enums = {};
954
954
  let item;
955
955
  while (item = itemsRegex.exec(matched[0])) {