@grame/faustwasm 0.4.9 → 0.5.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.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grame/faustwasm",
3
- "version": "0.4.9",
3
+ "version": "0.5.0",
4
4
  "description": "WebAssembly version of Faust Compiler",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/esm/index.d.ts",
@@ -2,13 +2,13 @@
2
2
  //@ts-check
3
3
  import * as process from "process";
4
4
  import faust2wasmFiles from "../src/faust2wasmFiles.js";
5
- import { copyWebStandaloneAssets, copyWebTemplateAssets } from "../src/copyWebStandaloneAssets.js";
5
+ import { copyWebStandaloneAssets, copyWebPWAAssets, copyWebTemplateAssets } from "../src/copyWebStandaloneAssets.js";
6
6
 
7
7
  const argv = process.argv.slice(2);
8
8
 
9
9
  if (argv[0] === "-help" || argv[0] === "-h") {
10
10
  console.log(`
11
- faust2wasm.js <file.dsp> <outputDir> [-poly] [-standalone] [-no-template]
11
+ faust2wasm.js <file.dsp> <outputDir> [-poly] [-standalone] [-pwa] [-no-template]
12
12
  Generates WebAssembly and metadata JSON files of a given Faust DSP.
13
13
  `);
14
14
  process.exit();
@@ -22,6 +22,10 @@ const $standalone = argv.indexOf("-standalone");
22
22
  const standalone = $standalone !== -1;
23
23
  if (standalone) argv.splice($standalone, 1);
24
24
 
25
+ const $pwa = argv.indexOf("-pwa");
26
+ const pwa = $pwa !== -1;
27
+ if (pwa) argv.splice($pwa, 1);
28
+
25
29
  const $noTemplate = argv.indexOf("-no-template");
26
30
  const noTemplate = $noTemplate !== -1;
27
31
  if (noTemplate) argv.splice($noTemplate, 1);
@@ -35,6 +39,8 @@ const dspName = fileName.replace(/\.dsp$/, '');
35
39
  const { dspMeta, effectMeta } = await faust2wasmFiles(inputFile, outputDir, argvFaust, poly);
36
40
  if (standalone) {
37
41
  copyWebStandaloneAssets(outputDir, dspName, poly, !!effectMeta);
42
+ } else if (pwa) {
43
+ copyWebPWAAssets(outputDir, dspName, poly, !!effectMeta);
38
44
  } else if (!noTemplate) {
39
45
  copyWebTemplateAssets(outputDir, dspName, poly, !!effectMeta);
40
46
  }
@@ -1,4 +1,5 @@
1
1
  declare const copyWebStandaloneAssets: (outputDir: string, dspName: string, poly?: boolean, effect?: boolean) => void;
2
+ declare const copyWebPWAAssets: (outputDir: string, dspName: string, poly?: boolean, effect?: boolean) => void;
2
3
  declare const copyWebTemplateAssets: (outputDir: string, dspName: string, poly?: boolean, effect?: boolean) => void;
3
4
 
4
- export { copyWebStandaloneAssets, copyWebTemplateAssets };
5
+ export { copyWebStandaloneAssets, copyWebPWAAssets, copyWebTemplateAssets };
@@ -15,7 +15,6 @@ const __filename = fileURLToPath(import.meta.url);
15
15
  */
16
16
  const copyWebStandaloneAssets = (outputDir, dspName, poly = false, effect = false) => {
17
17
  console.log(`Writing assets files.`)
18
- const assetsPath = path.join(__dirname, "../assets/standalone");
19
18
  if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir);
20
19
 
21
20
  const findAndReplace = ["FAUST_DSP_NAME", dspName];
@@ -30,7 +29,6 @@ const copyWebStandaloneAssets = (outputDir, dspName, poly = false, effect = fals
30
29
  cpSyncModify(templateJSPath, outputDir + `/index.js`, ...findAndReplace);
31
30
 
32
31
  const templateHTMLPath = path.join(__dirname, "../assets/standalone/index.html");
33
- //cpSyncModify(templateHTMLPath, outputDir + `/${dspName}.html`, "FAUST_DSP_NAME", dspName);
34
32
  cpSyncModify(templateHTMLPath, outputDir + `/index.html`, ...findAndReplace);
35
33
 
36
34
  const templateWorkerPath = path.join(__dirname, "../assets/standalone/service-worker.js");
@@ -49,6 +47,45 @@ const copyWebStandaloneAssets = (outputDir, dspName, poly = false, effect = fals
49
47
  cpSyncModify(templateManifestPath, outputDir + `/manifest.json`, ...findAndReplace);
50
48
  };
51
49
 
50
+ /**
51
+ * @param {string} outputDir - The output directory.
52
+ * @param {string} dspName - The name of the DSP to be loaded.
53
+ * @param {boolean} [poly] - Whether the DSP is polyphonic.
54
+ * @param {boolean} [effect] - Whether the DSP has an effect module.
55
+ */
56
+ const copyWebPWAAssets = (outputDir, dspName, poly = false, effect = false) => {
57
+ console.log(`Writing assets files.`)
58
+ if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir);
59
+
60
+ const findAndReplace = ["FAUST_DSP_NAME", dspName];
61
+ if (poly) findAndReplace.push("FAUST_DSP_VOICES = 0", "FAUST_DSP_VOICES = 16");
62
+ if (poly && effect) findAndReplace.push("FAUST_DSP_HAS_EFFECT = false", "FAUST_DSP_HAS_EFFECT = true");
63
+
64
+ // Copy some files
65
+ const createNodeJSPath = path.join(__dirname, "../assets/standalone/create-node.js");
66
+ cpSyncModify(createNodeJSPath, outputDir + `/create-node.js`, ...findAndReplace);
67
+
68
+ const templateJSPath = path.join(__dirname, "../assets/standalone/index-pwa.js");
69
+ cpSyncModify(templateJSPath, outputDir + `/index.js`, ...findAndReplace);
70
+
71
+ const templateHTMLPath = path.join(__dirname, "../assets/standalone/index-pwa.html");
72
+ cpSyncModify(templateHTMLPath, outputDir + `/index.html`, ...findAndReplace);
73
+
74
+ const templateWorkerPath = path.join(__dirname, "../assets/standalone/service-worker.js");
75
+ cpSyncModify(templateWorkerPath, outputDir + `/service-worker.js`, ...findAndReplace);
76
+
77
+ const templateIconPath = path.join(__dirname, "../assets/standalone/icon.png");
78
+ cpSync(templateIconPath, outputDir + `/icon.png`);
79
+
80
+ const faustwasmPath = path.join(__dirname, "../assets/standalone/faustwasm");
81
+ cpSync(faustwasmPath, outputDir + "/faustwasm");
82
+
83
+ const faustuiPath = path.join(__dirname, "../assets/standalone/faust-ui");
84
+ cpSync(faustuiPath, outputDir + "/faust-ui");
85
+
86
+ const templateManifestPath = path.join(__dirname, "../assets/standalone/manifest.json");
87
+ cpSyncModify(templateManifestPath, outputDir + `/manifest.json`, ...findAndReplace);
88
+ };
52
89
  /**
53
90
  * @param {string} outputDir - The output directory.
54
91
  * @param {string} dspName - The name of the DSP to be loaded.
@@ -78,5 +115,5 @@ const copyWebTemplateAssets = (outputDir, dspName, poly = false, effect = false)
78
115
  cpSync(faustwasmPath, outputDir + "/faustwasm");
79
116
  };
80
117
 
81
- export { copyWebStandaloneAssets, copyWebTemplateAssets };
118
+ export { copyWebStandaloneAssets, copyWebPWAAssets, copyWebTemplateAssets };
82
119