@grame/faust-web-component 0.2.4 → 0.2.6

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,9 +1,16 @@
1
1
  {
2
2
  "name": "@grame/faust-web-component",
3
3
  "description": "Web component embedding the Faust Compiler",
4
- "version": "0.2.4",
4
+ "version": "0.2.6",
5
5
  "module": "dist/faust-web-component.js",
6
- "files": ["src/", "public/", "index.html", "tsconfig.json", "vite.config.js", "dist/faust-web-component.js"],
6
+ "files": [
7
+ "src/",
8
+ "public/",
9
+ "index.html",
10
+ "tsconfig.json",
11
+ "vite.config.js",
12
+ "dist/faust-web-component.js"
13
+ ],
7
14
  "type": "module",
8
15
  "scripts": {
9
16
  "dev": "vite",
@@ -35,7 +42,7 @@
35
42
  "@fortawesome/fontawesome-svg-core": "^6.4.2",
36
43
  "@fortawesome/free-solid-svg-icons": "^6.4.2",
37
44
  "@grame/faustwasm": "^0.0.34",
38
- "@shren/faust-ui": "^1.1.2",
45
+ "@shren/faust-ui": "^1.1.4",
39
46
  "codemirror": "^6.0.1",
40
47
  "split.js": "^1.6.5"
41
48
  }
package/src/common.ts CHANGED
@@ -11,8 +11,9 @@ for (const icon of [faPlay, faStop, faUpRightFromSquare, faSquareCaretLeft, faAn
11
11
 
12
12
  export let compiler: FaustCompiler
13
13
  export let svgDiagrams: FaustSvgDiagrams
14
- export const mono_generator = new FaustMonoDspGenerator() // TODO: Support polyphony
15
- export const poly_generator = new FaustPolyDspGenerator() // TODO: Support polyphony
14
+ export const default_generator = new FaustMonoDspGenerator()
15
+ export const get_mono_generator = () => new FaustMonoDspGenerator()
16
+ export const get_poly_generator = () => new FaustPolyDspGenerator()
16
17
 
17
18
  async function loadFaust() {
18
19
  // Setup Faust
@@ -1,9 +1,9 @@
1
1
  import { icon } from "@fortawesome/fontawesome-svg-core"
2
- import { IFaustMonoWebAudioNode } from "@grame/faustwasm"
2
+ import { FaustMonoDspGenerator, FaustPolyDspGenerator, IFaustMonoWebAudioNode } from "@grame/faustwasm"
3
3
  import { FaustUI } from "@shren/faust-ui"
4
4
  import faustCSS from "@shren/faust-ui/dist/esm/index.css?inline"
5
5
  import Split from "split.js"
6
- import { faustPromise, audioCtx, compiler, svgDiagrams, mono_generator, poly_generator, getInputDevices, deviceUpdateCallbacks, accessMIDIDevice, midiInputCallback, extractMidiAndNvoices } from "./common"
6
+ import { faustPromise, audioCtx, compiler, svgDiagrams, default_generator, get_mono_generator, get_poly_generator, getInputDevices, deviceUpdateCallbacks, accessMIDIDevice, midiInputCallback, extractMidiAndNvoices } from "./common"
7
7
  import { createEditor, setError, clearError } from "./editor"
8
8
  import { Scope } from "./scope"
9
9
  import faustSvg from "./faustText.svg"
@@ -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 mono_generator.compile(compiler, "main", code, "")
283
- const json = mono_generator.getMeta()
282
+ await default_generator.compile(compiler, "main", code, "")
283
+ const json = default_generator.getMeta()
284
284
  let { midi, nvoices } = extractMidiAndNvoices(json);
285
285
  gmidi = midi;
286
286
  gnvoices = nvoices;
287
287
 
288
288
  // Build the generator
289
- generator = nvoices > 0 ? poly_generator : mono_generator;
289
+ generator = nvoices > 0 ? get_poly_generator() : get_mono_generator();
290
290
  await generator.compile(compiler, "main", code, "");
291
291
 
292
292
  } catch (e: any) {
@@ -299,9 +299,9 @@ export default class FaustEditor extends HTMLElement {
299
299
  // Create an audio node from compiled Faust
300
300
  if (node !== undefined) node.disconnect()
301
301
  if (gnvoices > 0) {
302
- node = (await poly_generator.createNode(audioCtx, gnvoices))!
302
+ node = (await (generator as FaustPolyDspGenerator).createNode(audioCtx, gnvoices))!
303
303
  } else {
304
- node = (await mono_generator.createNode(audioCtx))!
304
+ node = (await (generator as FaustMonoDspGenerator).createNode(audioCtx))!
305
305
  }
306
306
  if (node.numberOfInputs > 0) {
307
307
  audioInputSelector.disabled = false
@@ -1,10 +1,10 @@
1
1
  import { icon } from "@fortawesome/fontawesome-svg-core"
2
2
  import faustCSS from "@shren/faust-ui/dist/esm/index.css?inline"
3
3
  import faustSvg from "./faustText.svg"
4
- import { IFaustMonoWebAudioNode } from "@grame/faustwasm"
4
+ import { FaustMonoDspGenerator, FaustPolyDspGenerator, IFaustMonoWebAudioNode } from "@grame/faustwasm"
5
5
  import { IFaustPolyWebAudioNode } from "@grame/faustwasm"
6
6
  import { FaustUI } from "@shren/faust-ui"
7
- import { faustPromise, audioCtx, mono_generator, poly_generator, compiler, getInputDevices, deviceUpdateCallbacks, accessMIDIDevice, midiInputCallback, extractMidiAndNvoices } from "./common"
7
+ import { faustPromise, audioCtx, get_mono_generator, get_poly_generator, compiler, getInputDevices, deviceUpdateCallbacks, accessMIDIDevice, midiInputCallback, extractMidiAndNvoices, default_generator } from "./common"
8
8
 
9
9
  const template = document.createElement("template")
10
10
  template.innerHTML = `
@@ -116,18 +116,19 @@ export default class FaustWidget extends HTMLElement {
116
116
  let node: IFaustMonoWebAudioNode | IFaustPolyWebAudioNode
117
117
  let input: MediaStreamAudioSourceNode | undefined
118
118
  let faustUI: FaustUI
119
+ let generator: FaustMonoDspGenerator | FaustPolyDspGenerator
119
120
 
120
121
  const setup = async () => {
121
122
  await faustPromise
122
123
  // Compile Faust code to access JSON metadata
123
- await mono_generator.compile(compiler, "main", code, "")
124
- const json = mono_generator.getMeta()
124
+ await default_generator.compile(compiler, "main", code, "")
125
+ const json = default_generator.getMeta()
125
126
  let { midi, nvoices } = extractMidiAndNvoices(json);
126
127
  gmidi = midi;
127
128
  gnvoices = nvoices;
128
129
 
129
130
  // Build the generator and generate UI
130
- const generator = nvoices > 0 ? poly_generator : mono_generator;
131
+ generator = nvoices > 0 ? get_poly_generator() : get_mono_generator();
131
132
  await generator.compile(compiler, "main", code, "");
132
133
  const ui = generator.getUI();
133
134
 
@@ -145,9 +146,9 @@ export default class FaustWidget extends HTMLElement {
145
146
  // Create an audio node from compiled Faust
146
147
  if (node === undefined) {
147
148
  if (gnvoices > 0) {
148
- node = (await poly_generator.createNode(audioCtx, gnvoices))!
149
+ node = (await (generator as FaustPolyDspGenerator).createNode(audioCtx, gnvoices))!
149
150
  } else {
150
- node = (await mono_generator.createNode(audioCtx))!
151
+ node = (await (generator as FaustMonoDspGenerator).createNode(audioCtx))!
151
152
  }
152
153
  }
153
154
 
package/vite.config.js CHANGED
@@ -9,5 +9,6 @@ export default defineConfig({
9
9
  formats: ["iife"],
10
10
  fileName: () => "faust-web-component.js",
11
11
  },
12
+ sourcemap: true,
12
13
  },
13
14
  })
package/dist/index.html DELETED
@@ -1,26 +0,0 @@
1
- <p><em>Here's an embedded editor!</em></p>
2
-
3
- <faust-editor>
4
- <!--
5
- import("stdfaust.lib");
6
- ctFreq = hslider("cutoffFrequency",500,50,10000,0.01);
7
- q = hslider("q",5,1,30,0.1);
8
- gain = hslider("gain",1,0,1,0.01);
9
- process = no.noise : fi.resonlp(ctFreq,q,gain);
10
- -->
11
- </faust-editor>
12
-
13
- <p><em>And here's a simple DSP widget!</em></p>
14
-
15
- <faust-widget>
16
- <!--
17
- import("stdfaust.lib");
18
-
19
- declare options "[midi:on][nvoices:12]";
20
-
21
- process = pm.clarinet_ui_MIDI <: _,_;
22
- -->
23
- </faust-widget>
24
-
25
- <script src="https://cdn.jsdelivr.net/npm/@grame/faust-web-component@0.2.3/dist/faust-web-component.js"></script>
26
-