@grame/faust-web-component 0.5.3 → 0.5.4

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/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.5.3",
4
+ "version": "0.5.4",
5
5
  "module": "dist/faust-web-component.js",
6
6
  "files": [
7
7
  "src/",
@@ -234,7 +234,7 @@ export default class FaustEditor extends HTMLElement {
234
234
 
235
235
  connectedCallback() {
236
236
  // Initial setup when the component is attached to the DOM
237
- const code = this.innerHTML.replace("<!--", "").replace("-->", "").trim();
237
+ let code = this.innerHTML.replace("<!--", "").replace("-->", "").trim();
238
238
  this.attachShadow({ mode: "open" }).appendChild(template.content.cloneNode(true));
239
239
 
240
240
  // Set up links, buttons, and editor
@@ -291,6 +291,11 @@ export default class FaustEditor extends HTMLElement {
291
291
  let gnvoices = -1;
292
292
  let sourceNode: AudioBufferSourceNode | undefined;
293
293
 
294
+ // Counter for compiled DSP
295
+ let compiledDSPCounter = 0;
296
+ // Counter for compiled SVG
297
+ let compiledSVGCounter = 0;
298
+
294
299
  // Event handler for the run button
295
300
  runButton.onclick = async () => {
296
301
  if (audioCtx.state === "suspended") {
@@ -299,7 +304,7 @@ export default class FaustEditor extends HTMLElement {
299
304
  await faustPromise;
300
305
 
301
306
  // Compile Faust code
302
- const code = editor.state.doc.toString();
307
+ code = editor.state.doc.toString();
303
308
  let generator = null;
304
309
  try {
305
310
  // Compile Faust code to access JSON metadata
@@ -312,6 +317,7 @@ export default class FaustEditor extends HTMLElement {
312
317
  // Build the generator (possibly reusing default_generator which is a FaustMonoDspGenerator)
313
318
  generator = nvoices > 0 ? get_poly_generator() : default_generator;
314
319
  await generator.compile(compiler, "main", code, "-ftz 2");
320
+ compiledDSPCounter++;
315
321
 
316
322
  } catch (e: any) {
317
323
  setError(editor, e);
@@ -432,15 +438,15 @@ export default class FaustEditor extends HTMLElement {
432
438
  }
433
439
  // Check if the clicked tab is the "Block Diagram" tab (index 1)
434
440
  if (i === 1) {
435
- // Only set the SVG if it hasn't been set before (avoiding multiple loads)
436
- if (faustDiagram.innerHTML.trim() === "") {
437
-
441
+ // Check if the SVG has already been compiled for a given DSP
442
+ if (compiledSVGCounter !== compiledDSPCounter) {
438
443
  // Display a "Computing SVG..." message while the SVG is being generated
439
444
  faustDiagram.innerHTML = "<p><center>Computing SVG...</center></p>";
440
445
 
441
446
  // Use setTimeout to defer the SVG rendering to a separate task
442
447
  setTimeout(() => {
443
448
  setSVG(svgDiagrams.from("main", code, "")["process.svg"]);
449
+ compiledSVGCounter = compiledDSPCounter;
444
450
  }, 0);
445
451
  }
446
452
  } else if (i === 2) {