@grame/faustwasm 0.12.2 → 0.13.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.
Files changed (81) hide show
  1. package/.prettierrc +5 -0
  2. package/README.md +21 -3
  3. package/assets/standalone/faustwasm/index.d.ts +38 -16
  4. package/assets/standalone/faustwasm/index.js +1574 -404
  5. package/assets/standalone/faustwasm/index.js.map +2 -2
  6. package/dist/cjs/index.d.ts +38 -16
  7. package/dist/cjs/index.js +1573 -404
  8. package/dist/cjs/index.js.map +2 -2
  9. package/dist/cjs-bundle/index.d.ts +38 -16
  10. package/dist/cjs-bundle/index.js +1576 -406
  11. package/dist/cjs-bundle/index.js.map +2 -2
  12. package/dist/esm/index.d.ts +38 -16
  13. package/dist/esm/index.js +1574 -404
  14. package/dist/esm/index.js.map +2 -2
  15. package/dist/esm-bundle/index.d.ts +38 -16
  16. package/dist/esm-bundle/index.js +1576 -406
  17. package/dist/esm-bundle/index.js.map +2 -2
  18. package/eslint.config.js +11 -0
  19. package/package.json +57 -51
  20. package/sound.cpp +163 -0
  21. package/sound.dsp +4 -0
  22. package/sound.json +1 -0
  23. package/sound.wasm +0 -0
  24. package/src/FaustAudioWorkletCommunicator.ts +150 -143
  25. package/src/FaustAudioWorkletNode.ts +173 -75
  26. package/src/FaustAudioWorkletProcessor.ts +218 -90
  27. package/src/FaustCmajor.ts +9 -3
  28. package/src/FaustCompiler.ts +112 -35
  29. package/src/FaustDspGenerator.ts +561 -117
  30. package/src/FaustDspInstance.ts +58 -24
  31. package/src/FaustFFTAudioWorkletProcessor.ts +822 -612
  32. package/src/FaustOfflineProcessor.ts +187 -56
  33. package/src/FaustScriptProcessorNode.ts +156 -49
  34. package/src/FaustSensors.ts +426 -96
  35. package/src/FaustSvgDiagrams.ts +18 -5
  36. package/src/FaustWasmInstantiator.ts +224 -70
  37. package/src/FaustWebAudioDsp.ts +1060 -349
  38. package/src/LibFaust.ts +13 -4
  39. package/src/SoundfileReader.ts +175 -131
  40. package/src/WavDecoder.ts +42 -20
  41. package/src/WavEncoder.ts +35 -21
  42. package/src/copyWebStandaloneAssets.d.ts +20 -5
  43. package/src/copyWebStandaloneAssets.js +203 -75
  44. package/src/exports-bundle.ts +5 -5
  45. package/src/exports.ts +24 -24
  46. package/src/faust2CmajorFiles.d.ts +7 -3
  47. package/src/faust2cmajorFiles.js +10 -8
  48. package/src/faust2svgFiles.d.ts +7 -3
  49. package/src/faust2svgFiles.js +9 -7
  50. package/src/faust2wasmFiles.d.ts +10 -5
  51. package/src/faust2wasmFiles.js +34 -17
  52. package/src/faust2wavFiles.d.ts +12 -3
  53. package/src/faust2wavFiles.js +25 -12
  54. package/src/index-bundle-iife.ts +2 -2
  55. package/src/index-bundle.ts +1 -1
  56. package/src/index.ts +1 -1
  57. package/src/instantiateFaustModule.ts +43 -36
  58. package/src/instantiateFaustModuleFromFile.ts +30 -14
  59. package/src/types.ts +101 -25
  60. package/test/faustlive-wasm/faustwasm/index.d.ts +38 -16
  61. package/test/faustlive-wasm/faustwasm/index.js +1574 -404
  62. package/test/faustlive-wasm/faustwasm/index.js.map +2 -2
  63. package/test/web/create-faust-node.html +53 -0
  64. package/test/web/create-faust-node.js +186 -0
  65. package/test/organ/create-node.js +0 -252
  66. package/test/organ/dsp-meta.json +0 -131
  67. package/test/organ/dsp-module.wasm +0 -0
  68. package/test/organ/faust-pwa.js +0 -344
  69. package/test/organ/faust-ui/index.css +0 -442
  70. package/test/organ/faust-ui/index.css.map +0 -1
  71. package/test/organ/faust-ui/index.d.ts +0 -1
  72. package/test/organ/faust-ui/index.js +0 -3756
  73. package/test/organ/faust-ui/index.js.map +0 -1
  74. package/test/organ/faustwasm/index.d.ts +0 -1705
  75. package/test/organ/faustwasm/index.js +0 -4773
  76. package/test/organ/faustwasm/index.js.map +0 -7
  77. package/test/organ/icon.png +0 -0
  78. package/test/organ/index.html +0 -76
  79. package/test/organ/index.js +0 -69
  80. package/test/organ/manifest.json +0 -17
  81. package/test/organ/service-worker.js +0 -165
@@ -0,0 +1,53 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>createFaustNode Test</title>
7
+ <!-- Ensure root-relative resolution for libfaust assets -->
8
+ <base href="/" />
9
+ <style>
10
+ body { font-family: sans-serif; margin: 1.5rem; }
11
+ button { padding: 0.5rem 1rem; margin-top: 1rem; }
12
+ pre { background: #f6f6f6; padding: 1rem; border-radius: 4px; }
13
+ </style>
14
+ </head>
15
+ <body>
16
+ <h1>createFaustNode Test</h1>
17
+ <p>This page exercises <code>createFaustNode</code> for mono and poly DSP snippets. Serve the repo root (so <code>dist/</code> and <code>libfaust-wasm/</code> are reachable) and run <code>npm run build</code> first.</p>
18
+ <button id="run">Run tests</button>
19
+ <pre id="log"></pre>
20
+
21
+ <script type="module">
22
+ import { runTests } from '/test/web/create-faust-node.js';
23
+
24
+ const logEl = document.getElementById('log');
25
+ const runBtn = document.getElementById('run');
26
+
27
+ const originalLog = console.log.bind(console);
28
+ const originalErr = console.error.bind(console);
29
+ const append = (label, msg) => {
30
+ logEl.textContent += `${label}: ${msg}\n`;
31
+ logEl.scrollTop = logEl.scrollHeight;
32
+ };
33
+ console.log = (...args) => {
34
+ append('LOG', args.join(' '));
35
+ originalLog(...args);
36
+ };
37
+ console.error = (...args) => {
38
+ append('ERR', args.join(' '));
39
+ originalErr(...args);
40
+ };
41
+
42
+ runBtn.addEventListener('click', async () => {
43
+ append('INFO', 'Starting tests…');
44
+ try {
45
+ await runTests();
46
+ append('INFO', 'Tests triggered (check audio/console logs).');
47
+ } catch (e) {
48
+ append('ERR', `Failed to start tests: ${e.message || e}`);
49
+ }
50
+ });
51
+ </script>
52
+ </body>
53
+ </html>
@@ -0,0 +1,186 @@
1
+ // Simple browser-side sanity test for `createFaustNode` in `FaustDspGenerator`.
2
+ // Serve the repository root (e.g. `python -m http.server` from repo root) so that
3
+ // `dist/` and `libfaust-wasm/` are reachable. Then open `test/web/create-faust-node.html`.
4
+
5
+ const monoCode = `
6
+ import("stdfaust.lib");
7
+ process = os.osc(220) * 0.05;
8
+ `;
9
+
10
+ const polyCode = `
11
+ declare options "[nvoices:4][midi:on]";
12
+ import("stdfaust.lib");
13
+ freq = hslider("freq", 440, 50, 2000, 1);
14
+ gain = hslider("gain", 0.5, 0, 1, 0.01);
15
+ gate = button("gate");
16
+ process = gain * os.osc(freq) * gate;
17
+ `;
18
+
19
+ const polyEffectCode = `
20
+ declare options "[nvoices:4][midi:on]";
21
+ import("stdfaust.lib");
22
+ freq = hslider("freq", 440, 50, 2000, 1);
23
+ gain = hslider("gain", 0.5, 0, 1, 0.01);
24
+ gate = button("gate");
25
+ synth = gain * os.osc(freq) * gate;
26
+ process = synth, synth : dm.zita_light;
27
+ `;
28
+
29
+ const audioContext = new AudioContext({ latencyHint: 'interactive' });
30
+ const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
31
+
32
+ async function runMonoPolyTest(modeLabel, sp = false, bufferSize) {
33
+ const { FaustDspGenerator } = await import(
34
+ new URL('../../dist/esm/index.js', import.meta.url)
35
+ );
36
+
37
+ if (sp && typeof audioContext.createScriptProcessor !== 'function') {
38
+ console.warn('[test]', 'ScriptProcessor not supported; skipping test');
39
+ return;
40
+ }
41
+
42
+ const log = (...args) => console.log('[test]', ...args);
43
+ const error = (...args) => console.error('[test]', ...args);
44
+
45
+ try {
46
+ log(`Starting ${modeLabel} mono test for 5 seconds…`);
47
+ const monoGenerator = new FaustDspGenerator();
48
+ const monoNode = await monoGenerator.createFaustNode(
49
+ audioContext,
50
+ `${modeLabel}_mono_test`,
51
+ monoCode,
52
+ sp,
53
+ bufferSize
54
+ );
55
+ if (!monoNode) {
56
+ error(`${modeLabel} mono createFaustNode failed`);
57
+ return;
58
+ }
59
+ monoNode.connect(audioContext.destination);
60
+ log(
61
+ `${modeLabel} mono running; inputs/outputs =`,
62
+ monoNode.numberOfInputs,
63
+ monoNode.numberOfOutputs
64
+ );
65
+
66
+ await wait(5000);
67
+ monoNode.disconnect();
68
+ log(`${modeLabel} mono stopped after 5 seconds; starting poly test…`);
69
+
70
+ const polyGenerator = new FaustDspGenerator();
71
+ const polyNode = await polyGenerator.createFaustNode(
72
+ audioContext,
73
+ `${modeLabel}_poly_test`,
74
+ polyCode,
75
+ sp,
76
+ bufferSize
77
+ );
78
+ if (!polyNode) {
79
+ error(`${modeLabel} poly createFaustNode failed`);
80
+ return;
81
+ }
82
+ polyNode.connect(audioContext.destination);
83
+ log(
84
+ `${modeLabel} poly running; inputs/outputs =`,
85
+ polyNode.numberOfInputs,
86
+ polyNode.numberOfOutputs
87
+ );
88
+
89
+ // Play a short sequence: three consecutive notes, then a triad chord.
90
+ const noteSeq = [
91
+ { note: 60, vel: 100, dur: 500 },
92
+ { note: 64, vel: 100, dur: 500 },
93
+ { note: 67, vel: 100, dur: 500 }
94
+ ];
95
+ for (const { note, vel, dur } of noteSeq) {
96
+ log(`${modeLabel} poly keyOn note ${note}`);
97
+ polyNode.keyOn(0, note, vel);
98
+ await wait(dur);
99
+ polyNode.keyOff(0, note, 0);
100
+ log(`${modeLabel} poly keyOff note ${note}`);
101
+ await wait(100);
102
+ }
103
+
104
+ const chord = [60, 64, 67];
105
+ log(`${modeLabel} poly chord on (C major)`);
106
+ chord.forEach((n) => polyNode.keyOn(0, n, 100));
107
+ await wait(2000);
108
+ chord.forEach((n) => polyNode.keyOff(0, n, 0));
109
+ log(`${modeLabel} poly chord off`);
110
+ polyNode.disconnect();
111
+ log(`${modeLabel} poly stopped`);
112
+ } catch (e) {
113
+ error(`${modeLabel} test error:`, e);
114
+ }
115
+ }
116
+
117
+ async function runPolyEffectTest(modeLabel, sp = false, bufferSize) {
118
+ const { FaustDspGenerator } = await import(
119
+ new URL('../../dist/esm/index.js', import.meta.url)
120
+ );
121
+
122
+ if (sp && typeof audioContext.createScriptProcessor !== 'function') {
123
+ console.warn('[test]', 'ScriptProcessor not supported; skipping test');
124
+ return;
125
+ }
126
+
127
+ const log = (...args) => console.log('[test]', ...args);
128
+ const error = (...args) => console.error('[test]', ...args);
129
+
130
+ try {
131
+ log(`Starting ${modeLabel} poly+effect test…`);
132
+ const generator = new FaustDspGenerator();
133
+ const node = await generator.createFaustNode(
134
+ audioContext,
135
+ `${modeLabel}_poly_effect_test`,
136
+ polyEffectCode,
137
+ sp,
138
+ bufferSize
139
+ );
140
+ if (!node) {
141
+ error(`${modeLabel} poly+effect createFaustNode failed`);
142
+ return;
143
+ }
144
+ node.connect(audioContext.destination);
145
+ log(
146
+ `${modeLabel} poly+effect running; inputs/outputs =`,
147
+ node.numberOfInputs,
148
+ node.numberOfOutputs
149
+ );
150
+
151
+ const noteSeq = [
152
+ { note: 60, vel: 100, dur: 600 },
153
+ { note: 64, vel: 100, dur: 600 },
154
+ { note: 67, vel: 100, dur: 600 }
155
+ ];
156
+ for (const { note, vel, dur } of noteSeq) {
157
+ log(`${modeLabel} poly+effect keyOn note ${note}`);
158
+ node.keyOn(0, note, vel);
159
+ await wait(dur);
160
+ node.keyOff(0, note, 0);
161
+ log(`${modeLabel} poly+effect keyOff note ${note}`);
162
+ await wait(150);
163
+ }
164
+
165
+ const chord = [60, 64, 67];
166
+ log(`${modeLabel} poly+effect chord on (C major)`);
167
+ chord.forEach((n) => node.keyOn(0, n, 100));
168
+ await wait(2500);
169
+ chord.forEach((n) => node.keyOff(0, n, 0));
170
+ log(`${modeLabel} poly+effect chord off`);
171
+ node.disconnect();
172
+ log(`${modeLabel} poly+effect stopped`);
173
+ } catch (e) {
174
+ error(`${modeLabel} poly+effect test error:`, e);
175
+ }
176
+ }
177
+
178
+ export async function runTests() {
179
+ await audioContext.resume();
180
+
181
+ // AudioWorklet (default) + ScriptProcessor fallback
182
+ await runMonoPolyTest('AudioWorklet');
183
+ await runPolyEffectTest('AudioWorklet');
184
+ await runMonoPolyTest('ScriptProcessor', true, 1024);
185
+ await runPolyEffectTest('ScriptProcessor', true, 1024);
186
+ }
@@ -1,252 +0,0 @@
1
- // @ts-check
2
-
3
- /**
4
- * @typedef {{ dspModule: WebAssembly.Module; dspMeta: FaustDspMeta; effectModule?: WebAssembly.Module; effectMeta?: FaustDspMeta; mixerModule?: WebAssembly.Module }} FaustDspDistribution
5
- * @typedef {import("./faustwasm").FaustDspMeta} FaustDspMeta
6
- * @typedef {import("./faustwasm").FaustMonoAudioWorkletNode} FaustMonoAudioWorkletNode
7
- * @typedef {import("./faustwasm").FaustPolyAudioWorkletNode} FaustPolyAudioWorkletNode
8
- * @typedef {import("./faustwasm").FaustMonoScriptProcessorNode} FaustMonoScriptProcessorNode
9
- * @typedef {import("./faustwasm").FaustPolyScriptProcessorNode} FaustPolyScriptProcessorNode
10
- * @typedef {FaustMonoAudioWorkletNode | FaustPolyAudioWorkletNode | FaustMonoScriptProcessorNode | FaustPolyScriptProcessorNode} FaustNode
11
- */
12
-
13
- /**
14
- * Creates a Faust audio node for use in the Web Audio API.
15
- *
16
- * @param {AudioContext} audioContext - The Web Audio API AudioContext to which the Faust audio node will be connected.
17
- * @param {string} [dspName] - The name of the DSP to be loaded.
18
- * @param {number} [voices] - The number of voices to be used for polyphonic DSPs.
19
- * @param {boolean} [sp] - Whether to create a ScriptProcessorNode instead of an AudioWorkletNode.
20
- * @returns {Promise<{ faustNode: FaustNode | null; dspMeta: FaustDspMeta }>} - An object containing the Faust audio node and the DSP metadata.
21
- */
22
- const createFaustNode = async (audioContext, dspName = "template", voices = 0, sp = false, bufferSize = 512) => {
23
- // Set to true if the DSP has an effect
24
- const FAUST_DSP_HAS_EFFECT = false;
25
-
26
- // Import necessary Faust modules and data
27
- const { FaustMonoDspGenerator, FaustPolyDspGenerator } = await import("./faustwasm/index.js");
28
-
29
- // Load DSP metadata from JSON
30
- /** @type {FaustDspMeta} */
31
- const dspMeta = await (await fetch("./dsp-meta.json")).json();
32
-
33
- // Compile the DSP module from WebAssembly binary data
34
- const dspModule = await WebAssembly.compileStreaming(await fetch("./dsp-module.wasm"));
35
-
36
- // Create an object representing Faust DSP with metadata and module
37
- /** @type {FaustDspDistribution} */
38
- const faustDsp = { dspMeta, dspModule };
39
-
40
- /** @type {FaustNode | null} */
41
- let faustNode = null;
42
-
43
- // Create either a polyphonic or monophonic Faust audio node based on the number of voices
44
- if (voices > 0) {
45
-
46
- // Try to load optional mixer and effect modules
47
- faustDsp.mixerModule = await WebAssembly.compileStreaming(await fetch("./mixer-module.wasm"));
48
-
49
- if (FAUST_DSP_HAS_EFFECT) {
50
- faustDsp.effectMeta = await (await fetch("./effect-meta.json")).json();
51
- faustDsp.effectModule = await WebAssembly.compileStreaming(await fetch("./effect-module.wasm"));
52
- }
53
-
54
- // Create a polyphonic Faust audio node
55
- const generator = new FaustPolyDspGenerator();
56
- faustNode = await generator.createNode(
57
- audioContext,
58
- voices,
59
- dspName,
60
- { module: faustDsp.dspModule, json: JSON.stringify(faustDsp.dspMeta), soundfiles: {} },
61
- faustDsp.mixerModule,
62
- faustDsp.effectModule ? { module: faustDsp.effectModule, json: JSON.stringify(faustDsp.effectMeta), soundfiles: {} } : undefined,
63
- sp,
64
- bufferSize
65
- );
66
- } else {
67
- // Create a standard Faust audio node
68
- const generator = new FaustMonoDspGenerator();
69
- faustNode = await generator.createNode(
70
- audioContext,
71
- dspName,
72
- { module: faustDsp.dspModule, json: JSON.stringify(faustDsp.dspMeta), soundfiles: {} },
73
- sp,
74
- bufferSize
75
- );
76
- }
77
-
78
- // Return an object with the Faust audio node and the DSP metadata
79
- return { faustNode, dspMeta };
80
- }
81
-
82
- /**
83
- * Connects an audio input stream to a Faust WebAudio node.
84
- *
85
- * @param {AudioContext} audioContext - The Web Audio API AudioContext to which the Faust audio node is connected.
86
- * @param {string} id - The ID of the audio input device to connect.
87
- * @param {FaustNode} faustNode - The Faust audio node to which the audio input stream will be connected.
88
- * @param {MediaStreamAudioSourceNode} oldInputStreamNode - The old audio input stream node to be disconnected from the Faust audio node.
89
- * @returns {Promise<MediaStreamAudioSourceNode>} - The new audio input stream node connected to the Faust audio node.
90
- */
91
- async function connectToAudioInput(audioContext, id, faustNode, oldInputStreamNode) {
92
- // Create an audio input stream node
93
- const constraints = {
94
- audio: {
95
- echoCancellation: false,
96
- noiseSuppression: false,
97
- autoGainControl: false,
98
- deviceId: id ? { exact: id } : undefined,
99
- },
100
- };
101
- // Get the audio input stream
102
- const stream = await navigator.mediaDevices.getUserMedia(constraints);
103
- if (stream) {
104
- if (oldInputStreamNode) oldInputStreamNode.disconnect();
105
- const newInputStreamNode = audioContext.createMediaStreamSource(stream);
106
- newInputStreamNode.connect(faustNode);
107
- return newInputStreamNode;
108
- } else {
109
- return oldInputStreamNode;
110
- }
111
- };
112
-
113
- /**
114
- * Creates a Faust UI for a Faust audio node.
115
- *
116
- * @param {FaustAudioWorkletNode} faustNode
117
- */
118
- async function createFaustUI(divFaustUI, faustNode) {
119
- const { FaustUI } = await import("./faust-ui/index.js");
120
- const $container = document.createElement("div");
121
- $container.style.margin = "0";
122
- $container.style.position = "absolute";
123
- $container.style.overflow = "auto";
124
- $container.style.display = "flex";
125
- $container.style.flexDirection = "column";
126
- $container.style.width = "100%";
127
- $container.style.height = "100%";
128
- divFaustUI.appendChild($container);
129
- const faustUI = new FaustUI({
130
- ui: faustNode.getUI(),
131
- root: $container,
132
- listenWindowMessage: false,
133
- listenWindowResize: true,
134
- });
135
- faustUI.paramChangeByUI = (path, value) => faustNode.setParamValue(path, value);
136
- faustNode.setOutputParamHandler((path, value) => faustUI.paramChangeByDSP(path, value));
137
- $container.style.minWidth = `${faustUI.minWidth}px`;
138
- $container.style.minHeight = `${faustUI.minHeight}px`;
139
- faustUI.resize();
140
- };
141
-
142
- /**
143
- * Request permission to use motion and orientation sensors.
144
- */
145
- async function requestPermissions() {
146
-
147
- // Explicitly request permission on iOS before calling startSensors()
148
- if (typeof window.DeviceMotionEvent !== "undefined" && typeof window.DeviceMotionEvent.requestPermission === "function") {
149
- try {
150
- const permissionState = await window.DeviceMotionEvent.requestPermission();
151
- if (permissionState !== "granted") {
152
- console.warn("Motion sensor permission denied.");
153
- } else {
154
- console.log("Motion sensor permission granted.");
155
- }
156
- } catch (error) {
157
- console.error("Error requesting motion sensor permission:", error);
158
- }
159
- }
160
-
161
- if (typeof window.DeviceOrientationEvent !== "undefined" && typeof window.DeviceOrientationEvent.requestPermission === "function") {
162
- try {
163
- const permissionState = await window.DeviceOrientationEvent.requestPermission();
164
- if (permissionState !== "granted") {
165
- console.warn("Orientation sensor permission denied.");
166
- } else {
167
- console.log("Orientation sensor permission granted.");
168
- }
169
- } catch (error) {
170
- console.error("Error requesting orientation sensor permission:", error);
171
- }
172
- }
173
- }
174
-
175
- /**
176
- * Key2Midi: maps keyboard input to MIDI messages.
177
- */
178
- class Key2Midi {
179
- static KEY_MAP = {
180
- a: 0, w: 1, s: 2, e: 3, d: 4, f: 5, t: 6, g: 7,
181
- y: 8, h: 9, u: 10, j: 11, k: 12, o: 13, l: 14, p: 15, ";": 16,
182
- z: "PREV", x: "NEXT", c: "VELDOWN", v: "VELUP"
183
- };
184
-
185
- constructor({ keyMap = Key2Midi.KEY_MAP, offset = 60, velocity = 100, handler = console.log } = {}) {
186
- this.keyMap = keyMap;
187
- this.offset = offset;
188
- this.velocity = velocity;
189
- this.velMap = [20, 40, 60, 80, 100, 127];
190
- this.handler = handler;
191
- this.pressed = {};
192
-
193
- this.onKeyDown = this.onKeyDown.bind(this);
194
- this.onKeyUp = this.onKeyUp.bind(this);
195
- }
196
-
197
- start() {
198
- window.addEventListener("keydown", this.onKeyDown);
199
- window.addEventListener("keyup", this.onKeyUp);
200
- }
201
-
202
- stop() {
203
- window.removeEventListener("keydown", this.onKeyDown);
204
- window.removeEventListener("keyup", this.onKeyUp);
205
- }
206
-
207
- onKeyDown(e) {
208
- const key = e.key.toLowerCase();
209
- if (this.pressed[key]) return;
210
- this.pressed[key] = true;
211
-
212
- const val = this.keyMap[key];
213
- if (typeof val === "number") {
214
- const note = val + this.offset;
215
- this.handler([0x90, note, this.velocity]);
216
- } else if (val === "PREV") {
217
- this.offset -= 1;
218
- } else if (val === "NEXT") {
219
- this.offset += 1;
220
- } else if (val === "VELDOWN") {
221
- const idx = Math.max(0, this.velMap.indexOf(this.velocity) - 1);
222
- this.velocity = this.velMap[idx];
223
- } else if (val === "VELUP") {
224
- const idx = Math.min(this.velMap.length - 1, this.velMap.indexOf(this.velocity) + 1);
225
- this.velocity = this.velMap[idx];
226
- }
227
- }
228
-
229
- onKeyUp(e) {
230
- const key = e.key.toLowerCase();
231
- const val = this.keyMap[key];
232
- if (typeof val === "number") {
233
- const note = val + this.offset;
234
- this.handler([0x80, note, this.velocity]);
235
- }
236
- delete this.pressed[key];
237
- }
238
- }
239
-
240
- /**
241
- * Creates a Key2Midi instance.
242
- *
243
- * @param {function} handler - The function to handle MIDI messages.
244
- * @returns {Key2Midi} - The Key2Midi instance.
245
- */
246
- function createKey2MIDI(handler) {
247
- return new Key2Midi({ handler: handler });
248
- }
249
-
250
- // Export the functions
251
- export { createFaustNode, createFaustUI, createKey2MIDI, connectToAudioInput, requestPermissions };
252
-
@@ -1,131 +0,0 @@
1
- {
2
- "name": "organ",
3
- "filename": "organ",
4
- "version": "2.81.10",
5
- "compile_options": "-lang wasm-i -ct 1 -es 1 -mcd 16 -mdd 1024 -mdy 33 -single -ftz 2",
6
- "library_list": [
7
- "/usr/share/faust/stdfaust.lib",
8
- "/usr/share/faust/oscillators.lib",
9
- "/usr/share/faust/platform.lib",
10
- "/usr/share/faust/maths.lib",
11
- "/usr/share/faust/basics.lib",
12
- "/usr/share/faust/envelopes.lib"
13
- ],
14
- "include_pathnames": [
15
- "/share/faust",
16
- "/usr/local/share/faust",
17
- "/usr/share/faust",
18
- "."
19
- ],
20
- "size": 262264,
21
- "code": "SFzN",
22
- "inputs": 0,
23
- "outputs": 1,
24
- "meta": [
25
- {
26
- "basics.lib/name": "Faust Basic Element Library"
27
- },
28
- {
29
- "basics.lib/version": "1.22.0"
30
- },
31
- {
32
- "compile_options": "-lang wasm-i -ct 1 -es 1 -mcd 16 -mdd 1024 -mdy 33 -single -ftz 2"
33
- },
34
- {
35
- "envelopes.lib/adsr:author": "Yann Orlarey and Andrey Bundin"
36
- },
37
- {
38
- "envelopes.lib/author": "GRAME"
39
- },
40
- {
41
- "envelopes.lib/copyright": "GRAME"
42
- },
43
- {
44
- "envelopes.lib/license": "LGPL with exception"
45
- },
46
- {
47
- "envelopes.lib/name": "Faust Envelope Library"
48
- },
49
- {
50
- "envelopes.lib/version": "1.3.0"
51
- },
52
- {
53
- "filename": "organ"
54
- },
55
- {
56
- "maths.lib/author": "GRAME"
57
- },
58
- {
59
- "maths.lib/copyright": "GRAME"
60
- },
61
- {
62
- "maths.lib/license": "LGPL with exception"
63
- },
64
- {
65
- "maths.lib/name": "Faust Math Library"
66
- },
67
- {
68
- "maths.lib/version": "2.9.0"
69
- },
70
- {
71
- "name": "organ"
72
- },
73
- {
74
- "oscillators.lib/name": "Faust Oscillator Library"
75
- },
76
- {
77
- "oscillators.lib/version": "1.6.0"
78
- },
79
- {
80
- "platform.lib/name": "Generic Platform Library"
81
- },
82
- {
83
- "platform.lib/version": "1.3.0"
84
- }
85
- ],
86
- "ui": [
87
- {
88
- "type": "vgroup",
89
- "label": "organ",
90
- "items": [
91
- {
92
- "type": "hslider",
93
- "label": "freq",
94
- "varname": "fHslider1",
95
- "shortname": "freq",
96
- "address": "/organ/freq",
97
- "index": 262168,
98
- "meta": [
99
- {
100
- "midi": "ctrl 7"
101
- }
102
- ],
103
- "init": 440,
104
- "min": 20,
105
- "max": 3000,
106
- "step": 1
107
- },
108
- {
109
- "type": "hslider",
110
- "label": "gain",
111
- "varname": "fHslider0",
112
- "shortname": "gain",
113
- "address": "/organ/gain",
114
- "index": 262144,
115
- "init": 0.5,
116
- "min": 0,
117
- "max": 1,
118
- "step": 0.01
119
- },
120
- {
121
- "type": "button",
122
- "label": "gate",
123
- "varname": "fButton0",
124
- "shortname": "gate",
125
- "address": "/organ/gate",
126
- "index": 262212
127
- }
128
- ]
129
- }
130
- ]
131
- }
Binary file