@grame/faust-web-component 0.3.9 → 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.
@@ -13443,7 +13443,6 @@ const dependencies = {
13443
13443
  let compiler;
13444
13444
  let svgDiagrams;
13445
13445
  const default_generator = new FaustMonoDspGenerator();
13446
- const get_mono_generator = () => new FaustMonoDspGenerator();
13447
13446
  const get_poly_generator = () => new FaustPolyDspGenerator();
13448
13447
  async function loadFaust() {
13449
13448
  const module = await instantiateFaustModuleFromFile_default(jsURL, dataURL, wasmURL);
@@ -36386,12 +36385,12 @@ const dependencies = {
36386
36385
  const code22 = editor.state.doc.toString();
36387
36386
  let generator = null;
36388
36387
  try {
36389
- await default_generator.compile(compiler, "main", code22, "");
36388
+ await default_generator.compile(compiler, "main", code22, "-ftz 2");
36390
36389
  const json = default_generator.getMeta();
36391
36390
  let { midi, nvoices } = extractMidiAndNvoices(json);
36392
36391
  gmidi = midi;
36393
36392
  gnvoices = nvoices;
36394
- generator = nvoices > 0 ? get_poly_generator() : get_mono_generator();
36393
+ generator = nvoices > 0 ? get_poly_generator() : default_generator;
36395
36394
  await generator.compile(compiler, "main", code22, "-ftz 2");
36396
36395
  } catch (e) {
36397
36396
  setError(editor, e);
@@ -36442,7 +36441,6 @@ const dependencies = {
36442
36441
  const faustUI = new distExports.FaustUI({ ui, root: faustUIRoot });
36443
36442
  faustUI.paramChangeByUI = (path, value) => node == null ? void 0 : node.setParamValue(path, value);
36444
36443
  node.setOutputParamHandler((path, value) => faustUI.paramChangeByDSP(path, value));
36445
- setSVG(svgDiagrams.from("main", code22, "")["process.svg"]);
36446
36444
  editorEl.style.height = `${Math.max(125, faustUI.minHeight)}px`;
36447
36445
  faustUIRoot.style.width = faustUI.minWidth * 1.25 + "px";
36448
36446
  faustUIRoot.style.height = faustUI.minHeight * 1.25 + "px";
@@ -36481,7 +36479,14 @@ const dependencies = {
36481
36479
  tabContents[j].classList.remove("active");
36482
36480
  }
36483
36481
  }
36484
- if (i2 === 2) {
36482
+ if (i2 === 1) {
36483
+ if (faustDiagram.innerHTML.trim() === "") {
36484
+ faustDiagram.innerHTML = "<p><center>Computing SVG...</center></p>";
36485
+ setTimeout(() => {
36486
+ setSVG(svgDiagrams.from("main", code2, "")["process.svg"]);
36487
+ }, 0);
36488
+ }
36489
+ } else if (i2 === 2) {
36485
36490
  scope.onResize();
36486
36491
  if (animPlot !== void 0) cancelAnimationFrame(animPlot);
36487
36492
  animPlot = requestAnimationFrame(drawScope);
@@ -36663,12 +36668,12 @@ const dependencies = {
36663
36668
  let sourceNode = void 0;
36664
36669
  const setup = async () => {
36665
36670
  await faustPromise;
36666
- await default_generator.compile(compiler, "main", code2, "");
36671
+ await default_generator.compile(compiler, "main", code2, "-ftz 2");
36667
36672
  const json = default_generator.getMeta();
36668
36673
  let { midi, nvoices } = extractMidiAndNvoices(json);
36669
36674
  gmidi = midi;
36670
36675
  gnvoices = nvoices;
36671
- generator = nvoices > 0 ? get_poly_generator() : get_mono_generator();
36676
+ generator = nvoices > 0 ? get_poly_generator() : default_generator;
36672
36677
  await generator.compile(compiler, "main", code2, "-ftz 2");
36673
36678
  const ui = generator.getUI();
36674
36679
  faustUI = new distExports.FaustUI({ ui, root: faustUIRoot });
@@ -36766,7 +36771,10 @@ const dependencies = {
36766
36771
  }
36767
36772
  };
36768
36773
  audioInputSelector.onchange = connectInput;
36769
- setup();
36774
+ setTimeout(() => {
36775
+ faustUIRoot.innerHTML = "<p><center>Compiling...</center></p>";
36776
+ setup();
36777
+ }, 0);
36770
36778
  }
36771
36779
  }
36772
36780
  customElements.define("faust-editor", FaustEditor);
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.9",
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