@grame/faust-web-component 0.3.8 → 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.
package/index.html CHANGED
@@ -8,11 +8,14 @@
8
8
 
9
9
  <faust-editor>
10
10
  <!--
11
+ declare name "Vocal FOF MIDI";
12
+ declare description "MIDI-controllable FOF vocal synthesizer.";
13
+ declare license "MIT";
14
+ declare copyright "(c)Mike Olsen, CCRMA (Stanford University)";
15
+
11
16
  import("stdfaust.lib");
12
- ctFreq = hslider("cutoffFrequency",500,50,10000,0.01);
13
- q = hslider("q",5,1,30,0.1);
14
- gain = hslider("gain",1,0,1,0.01);
15
- process = no.noise : fi.resonlp(ctFreq,q,gain);
17
+
18
+ process = pm.SFFormantModelFofSmooth_ui_MIDI <: _,_;
16
19
  -->
17
20
  </faust-editor>
18
21
  <center>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@grame/faust-web-component",
3
3
  "description": "Web component embedding the Faust Compiler",
4
- "version": "0.3.8",
4
+ "version": "0.4.0",
5
5
  "module": "dist/faust-web-component.js",
6
6
  "files": [
7
7
  "src/",
@@ -279,14 +279,14 @@ export default class FaustEditor extends HTMLElement {
279
279
  let generator = null
280
280
  try {
281
281
  // Compile Faust code to access JSON metadata
282
- await default_generator.compile(compiler, "main", code, "")
282
+ await default_generator.compile(compiler, "main", code, "-ftz 2")
283
283
  const json = default_generator.getMeta()
284
284
  let { midi, nvoices } = extractMidiAndNvoices(json);
285
285
  gmidi = midi;
286
286
  gnvoices = nvoices;
287
287
 
288
- // Build the generator
289
- generator = nvoices > 0 ? get_poly_generator() : get_mono_generator();
288
+ // Build the generator (possibly reusing default_generator which is a FaustMonoDspGenerator)
289
+ generator = nvoices > 0 ? get_poly_generator() : default_generator;
290
290
  await generator.compile(compiler, "main", code, "-ftz 2");
291
291
 
292
292
  } catch (e: any) {
@@ -350,9 +350,6 @@ export default class FaustEditor extends HTMLElement {
350
350
  faustUI.paramChangeByUI = (path, value) => node?.setParamValue(path, value)
351
351
  node.setOutputParamHandler((path, value) => faustUI.paramChangeByDSP(path, value))
352
352
 
353
- // Create SVG block diagram
354
- setSVG(svgDiagrams.from("main", code, "")["process.svg"])
355
-
356
353
  // Set editor size to fit UI size
357
354
  editorEl.style.height = `${Math.max(125, faustUI.minHeight)}px`;
358
355
  faustUIRoot.style.width = faustUI.minWidth * 1.25 + "px"
@@ -373,6 +370,7 @@ export default class FaustEditor extends HTMLElement {
373
370
  }
374
371
 
375
372
  let animPlot: number | undefined
373
+
376
374
  const drawScope = () => {
377
375
  scope!.renderScope([{
378
376
  analyser: analyser!,
@@ -397,7 +395,20 @@ export default class FaustEditor extends HTMLElement {
397
395
  tabContents[j].classList.remove("active")
398
396
  }
399
397
  }
400
- if (i === 2) {
398
+ // Check if the clicked tab is the "Block Diagram" tab (index 1)
399
+ if (i === 1) {
400
+ // Only set the SVG if it hasn't been set before (avoiding multiple loads)
401
+ if (faustDiagram.innerHTML.trim() === "") {
402
+
403
+ // Display a "Computing SVG..." message while the SVG is being generated
404
+ faustDiagram.innerHTML = "<p><center>Computing SVG...</center></p>";
405
+
406
+ // Use setTimeout to defer the SVG rendering to a separate task
407
+ setTimeout(() => {
408
+ setSVG(svgDiagrams.from("main", code, "")["process.svg"]);
409
+ }, 0);
410
+ }
411
+ } else if (i === 2) {
401
412
  scope!.onResize()
402
413
  if (animPlot !== undefined) cancelAnimationFrame(animPlot)
403
414
  animPlot = requestAnimationFrame(drawScope)
@@ -121,15 +121,16 @@ export default class FaustWidget extends HTMLElement {
121
121
 
122
122
  const setup = async () => {
123
123
  await faustPromise
124
- // Compile Faust code to access JSON metadata
125
- await default_generator.compile(compiler, "main", code, "")
124
+ // Compile Faust code to access JSON metadata
125
+ await default_generator.compile(compiler, "main", code, "-ftz 2")
126
126
  const json = default_generator.getMeta()
127
127
  let { midi, nvoices } = extractMidiAndNvoices(json);
128
128
  gmidi = midi;
129
129
  gnvoices = nvoices;
130
130
 
131
- // Build the generator and generate UI
132
- generator = nvoices > 0 ? get_poly_generator() : get_mono_generator();
131
+ // Build the generator (possibly reusing default_generator which is a FaustMonoDspGenerator)
132
+ // and generate UI
133
+ generator = nvoices > 0 ? get_poly_generator() : default_generator;
133
134
  await generator.compile(compiler, "main", code, "-ftz 2");
134
135
  const ui = generator.getUI();
135
136
 
@@ -249,7 +250,12 @@ export default class FaustWidget extends HTMLElement {
249
250
 
250
251
  audioInputSelector.onchange = connectInput
251
252
 
252
- setup()
253
+ setTimeout(() => {
254
+ // Display a "Compiling..." message while Faust is compiling
255
+ faustUIRoot.innerHTML = "<p><center>Compiling...</center></p>";
256
+ setup();
257
+ }, 0);
258
+
253
259
  }
254
260
  }
255
261