@grame/faust-web-component 0.5.2 → 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/README.md +2 -2
- package/dist/faust-web-component.js +44 -33
- package/package.json +2 -2
- package/src/faust-editor.ts +11 -5
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.
|
4
|
+
"version": "0.5.4",
|
5
5
|
"module": "dist/faust-web-component.js",
|
6
6
|
"files": [
|
7
7
|
"src/",
|
@@ -42,7 +42,7 @@
|
|
42
42
|
"@codemirror/legacy-modes": "^6.3.3",
|
43
43
|
"@fortawesome/fontawesome-svg-core": "^6.4.2",
|
44
44
|
"@fortawesome/free-solid-svg-icons": "^6.4.2",
|
45
|
-
"@grame/faustwasm": "^0.9.
|
45
|
+
"@grame/faustwasm": "^0.9.5",
|
46
46
|
"@shren/faust-ui": "^1.1.16",
|
47
47
|
"codemirror": "^6.0.1",
|
48
48
|
"split.js": "^1.6.5"
|
package/src/faust-editor.ts
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
//
|
436
|
-
if (
|
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) {
|