@grame/faustwasm 0.5.2 → 0.5.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.
package/README.md CHANGED
@@ -61,7 +61,7 @@ will create a set of files: `index.js`, `dsp-module.wasm`, `dsp-meta.json`, `ind
61
61
 
62
62
  #### Creating a Progressive Web Application (PWA) of a Faust DSP
63
63
 
64
- You can create a standalone Progressive Web Application using the same command line:
64
+ You can create a standalone Progressive Web Application using the command line:
65
65
 
66
66
  ```bash
67
67
  node scripts/faust2wasm.js test/rev.dsp test/rev -pwa
@@ -79,7 +79,7 @@ will create a set of files: `icon.png`, `service-worker.js`, `manifest.json`, `i
79
79
 
80
80
  #### Creating a standalone version of a Faust DSP, with audio and MIDI devices selector
81
81
 
82
- You can create a standalone using the same command line:
82
+ You can create a standalone using the command line:
83
83
 
84
84
  ```bash
85
85
  node scripts/faust2wasm.js test/rev.dsp test/rev -standalone
@@ -51,6 +51,7 @@ const createFaustNode = async (audioContext, dspName = "template", voices = 0, s
51
51
  faustDsp.effectModule = await WebAssembly.compileStreaming(await fetch("./effect-module.wasm"));
52
52
  }
53
53
 
54
+ // Create a polyphonic Faust audio node
54
55
  const generator = new FaustPolyDspGenerator();
55
56
  faustNode = await generator.createNode(
56
57
  audioContext,
@@ -62,6 +63,7 @@ const createFaustNode = async (audioContext, dspName = "template", voices = 0, s
62
63
  sp
63
64
  );
64
65
  } else {
66
+ // Create a standard Faust audio node
65
67
  const generator = new FaustMonoDspGenerator();
66
68
  faustNode = await generator.createNode(
67
69
  audioContext,
@@ -81,10 +83,11 @@ const createFaustNode = async (audioContext, dspName = "template", voices = 0, s
81
83
  * @param {AudioContext} audioContext - The Web Audio API AudioContext to which the Faust audio node is connected.
82
84
  * @param {string} id - The ID of the audio input device to connect.
83
85
  * @param {FaustNode} faustNode - The Faust audio node to which the audio input stream will be connected.
84
- * @param {MediaStreamAudioSourceNode} inputStreamNode - The audio input stream node to be connected to the Faust audio node.
86
+ * @param {MediaStreamAudioSourceNode} inputStreamNode - The audio input stream node to be disconnected from the Faust audio node.
85
87
  * @returns {Promise<MediaStreamAudioSourceNode>} - The audio input stream node connected to the Faust audio node.
86
88
  */
87
89
  async function connectToAudioInput(audioContext, id, faustNode, inputStreamNode) {
90
+ // Create an audio input stream node
88
91
  const constraints = {
89
92
  audio: {
90
93
  echoCancellation: false,
@@ -93,6 +96,7 @@ async function connectToAudioInput(audioContext, id, faustNode, inputStreamNode)
93
96
  deviceId: id ? { exact: id } : undefined,
94
97
  },
95
98
  };
99
+ // Get the audio input stream
96
100
  const stream = await navigator.mediaDevices.getUserMedia(constraints);
97
101
  if (stream) {
98
102
  if (inputStreamNode) inputStreamNode.disconnect();
@@ -102,4 +106,33 @@ async function connectToAudioInput(audioContext, id, faustNode, inputStreamNode)
102
106
  return inputStreamNode;
103
107
  };
104
108
 
105
- export { createFaustNode, connectToAudioInput };
109
+ /**
110
+ * @param {FaustAudioWorkletNode} faustNode
111
+ */
112
+ async function createFaustUI(divFaustUI, faustNode) {
113
+ const { FaustUI } = await import("./faust-ui/index.js");
114
+ const $container = document.createElement("div");
115
+ $container.style.margin = "0";
116
+ $container.style.position = "absolute";
117
+ $container.style.overflow = "auto";
118
+ $container.style.display = "flex";
119
+ $container.style.flexDirection = "column";
120
+ $container.style.width = "100%";
121
+ $container.style.height = "100%";
122
+ divFaustUI.appendChild($container);
123
+ const faustUI = new FaustUI({
124
+ ui: faustNode.getUI(),
125
+ root: $container,
126
+ listenWindowMessage: false,
127
+ listenWindowResize: true,
128
+ });
129
+ faustUI.paramChangeByUI = (path, value) => faustNode.setParamValue(path, value);
130
+ faustNode.setOutputParamHandler((path, value) => faustUI.paramChangeByDSP(path, value));
131
+ $container.style.minWidth = `${faustUI.minWidth}px`;
132
+ $container.style.minHeight = `${faustUI.minHeight}px`;
133
+ faustUI.resize();
134
+ };
135
+
136
+ // Export the functions
137
+ export { createFaustNode, createFaustUI, connectToAudioInput };
138
+