@grame/faustwasm 0.16.4 → 0.16.5
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/assets/standalone/create-node.js +304 -250
- package/assets/standalone/faust-pwa.js +63 -12
- package/assets/standalone/index-pwa.js +12 -5
- package/package.json +1 -1
- package/test/organ/create-node.js +0 -253
- package/test/organ/dsp-meta.json +0 -132
- package/test/organ/dsp-module.wasm +0 -0
- package/test/organ/faust-pwa.js +0 -344
- package/test/organ/faust-ui/index.css +0 -442
- package/test/organ/faust-ui/index.css.map +0 -1
- package/test/organ/faust-ui/index.d.ts +0 -1
- package/test/organ/faust-ui/index.js +0 -3756
- package/test/organ/faust-ui/index.js.map +0 -1
- package/test/organ/faustwasm/index.d.ts +0 -1824
- package/test/organ/faustwasm/index.js +0 -6178
- package/test/organ/faustwasm/index.js.map +0 -7
- package/test/organ/icon.png +0 -0
- package/test/organ/index.html +0 -76
- package/test/organ/index.js +0 -69
- package/test/organ/manifest.json +0 -17
- package/test/organ/service-worker.js +0 -165
package/test/organ/icon.png
DELETED
|
Binary file
|
package/test/organ/index.html
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
|
|
4
|
-
<link rel="manifest" href="./manifest.json">
|
|
5
|
-
|
|
6
|
-
<head>
|
|
7
|
-
<meta charset="UTF-8">
|
|
8
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
9
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
10
|
-
<title>Faust DSP</title>
|
|
11
|
-
<style>
|
|
12
|
-
body {
|
|
13
|
-
color: #b0b0b0;
|
|
14
|
-
background-color: #1f1f1f;
|
|
15
|
-
display: flex;
|
|
16
|
-
top: 0;
|
|
17
|
-
left: 0;
|
|
18
|
-
width: 100%;
|
|
19
|
-
height: 100%;
|
|
20
|
-
margin: 0;
|
|
21
|
-
position: absolute;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
main {
|
|
25
|
-
margin: 20px;
|
|
26
|
-
display: flex;
|
|
27
|
-
flex-direction: column;
|
|
28
|
-
flex: 1 1 100%;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
main span {
|
|
32
|
-
position: relative;
|
|
33
|
-
display: flex;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
main span[hidden] {
|
|
37
|
-
display: none;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
main span span {
|
|
41
|
-
margin: 0px 10px;
|
|
42
|
-
flex: 1;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
main span select {
|
|
46
|
-
flex: 2;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
#dsp-switch {
|
|
50
|
-
margin: 20px auto;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
#button-dsp {
|
|
54
|
-
padding: 10px;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
#div-faust-ui {
|
|
58
|
-
flex: 1 1 auto;
|
|
59
|
-
display: flex;
|
|
60
|
-
position: relative;
|
|
61
|
-
flex-direction: column;
|
|
62
|
-
color: black;
|
|
63
|
-
}
|
|
64
|
-
</style>
|
|
65
|
-
<link rel="stylesheet" href="./faust-ui/index.css">
|
|
66
|
-
</head>
|
|
67
|
-
|
|
68
|
-
<body>
|
|
69
|
-
<main>
|
|
70
|
-
<div id="div-faust-ui">
|
|
71
|
-
</div>
|
|
72
|
-
</main>
|
|
73
|
-
<script src="./index.js"></script>
|
|
74
|
-
</body>
|
|
75
|
-
|
|
76
|
-
</html>
|
package/test/organ/index.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @file index-pwa.js
|
|
4
|
-
* Entry point for initializing and managing the Faust PWA instance.
|
|
5
|
-
*
|
|
6
|
-
* ## Overview
|
|
7
|
-
* This script dynamically imports {@link createFaustPWA} from `faust-pwa.js`,
|
|
8
|
-
* creates the Faust PWA controller, and manages user-activation of the
|
|
9
|
-
* Web Audio API (click/touch) as well as visibility-based suspension.
|
|
10
|
-
*
|
|
11
|
-
* ## Responsibilities
|
|
12
|
-
* - Dynamically import `createFaustPWA` (ES module)
|
|
13
|
-
* - Create the PWA instance for the selected DSP
|
|
14
|
-
* - Resume/suspend AudioContext on user interaction or page visibility changes
|
|
15
|
-
* - Activate/deactivate MIDI and sensors
|
|
16
|
-
*
|
|
17
|
-
* ## Emitted Events (from FaustPWA)
|
|
18
|
-
* - `created` — DSP and UI successfully initialized
|
|
19
|
-
* - `started` — Audio, MIDI, and sensors activated
|
|
20
|
-
* - `stopped` — Audio, MIDI, and sensors deactivated
|
|
21
|
-
* - `destroy` — Resources released
|
|
22
|
-
* - `error` — Operational error; see event.detail.error
|
|
23
|
-
*
|
|
24
|
-
* @module index-pwa
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
// Set to > 0 if the DSP is polyphonic
|
|
28
|
-
const FAUST_DSP_VOICES = 0;
|
|
29
|
-
|
|
30
|
-
(async () => {
|
|
31
|
-
|
|
32
|
-
const { FaustPWA } = await import("./faust-pwa.js");
|
|
33
|
-
|
|
34
|
-
/** @type {HTMLDivElement} */
|
|
35
|
-
const divFaustUI = document.getElementById("div-faust-ui");
|
|
36
|
-
|
|
37
|
-
// Declare faustNode as a global variable
|
|
38
|
-
const pwa = new FaustPWA({ dspName: "organ", voices: FAUST_DSP_VOICES, uiContainer: divFaustUI });
|
|
39
|
-
|
|
40
|
-
// Create PWA and UI
|
|
41
|
-
await pwa.create();
|
|
42
|
-
|
|
43
|
-
// Event listener to handle user interaction
|
|
44
|
-
function handleUserInteraction() {
|
|
45
|
-
|
|
46
|
-
// Resume AudioContext synchronously
|
|
47
|
-
pwa.resumeAudioContext();
|
|
48
|
-
|
|
49
|
-
// Activate MIDI and Sensors
|
|
50
|
-
pwa.activateMIDISensors()
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Activate AudioContext, MIDI and Sensors on user interaction
|
|
54
|
-
window.addEventListener('click', handleUserInteraction);
|
|
55
|
-
window.addEventListener('touchstart', handleUserInteraction);
|
|
56
|
-
|
|
57
|
-
// Deactivate AudioContext, MIDI and Sensors on user interaction
|
|
58
|
-
window.addEventListener('visibilitychange', function () {
|
|
59
|
-
if (window.visibilityState === 'hidden') {
|
|
60
|
-
|
|
61
|
-
// Suspend AudioContext
|
|
62
|
-
pwa.suspendAudioContext();
|
|
63
|
-
|
|
64
|
-
// Deactivate MIDI and Sensors
|
|
65
|
-
pwa.deactivateMIDISensors();
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
})();
|
package/test/organ/manifest.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "Faust organ",
|
|
3
|
-
"short_name": "organ",
|
|
4
|
-
"start_url": "./index.html",
|
|
5
|
-
"description": "Progressive Web App for organ",
|
|
6
|
-
"display": "standalone",
|
|
7
|
-
"background_color": "#ffffff",
|
|
8
|
-
"theme_color": "#000000",
|
|
9
|
-
"orientation": "portrait",
|
|
10
|
-
"icons": [
|
|
11
|
-
{
|
|
12
|
-
"src": "./icon.png",
|
|
13
|
-
"sizes": "390x390",
|
|
14
|
-
"type": "image/png"
|
|
15
|
-
}
|
|
16
|
-
]
|
|
17
|
-
}
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
/// <reference lib="webworker" />
|
|
2
|
-
|
|
3
|
-
// Set to > 0 if the DSP is polyphonic
|
|
4
|
-
const FAUST_DSP_VOICES = 0;
|
|
5
|
-
// Set to true if the DSP has an effect
|
|
6
|
-
const FAUST_DSP_HAS_EFFECT = false;
|
|
7
|
-
|
|
8
|
-
const CACHE_NAME = "organ_20260614-1752"; // Cache name with versioning
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* List of essential resources required for the **Mono DSP** version of the application.
|
|
12
|
-
*
|
|
13
|
-
* - These files are cached to enable offline functionality and improve loading speed.
|
|
14
|
-
* - Includes the main HTML, JavaScript, and CSS files required for the app.
|
|
15
|
-
* - Contains Faust-related files needed for DSP processing.
|
|
16
|
-
*/
|
|
17
|
-
const MONO_RESOURCES = [
|
|
18
|
-
"./index.html",
|
|
19
|
-
"./index.js",
|
|
20
|
-
"./create-node.js",
|
|
21
|
-
"./faust-ui/index.js",
|
|
22
|
-
"./faust-ui/index.css",
|
|
23
|
-
"./faustwasm/index.js",
|
|
24
|
-
"./dsp-module.wasm",
|
|
25
|
-
"./dsp-meta.json"
|
|
26
|
-
];
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* List of resources for the **Polyphonic DSP** version of the application.
|
|
30
|
-
*
|
|
31
|
-
* - Extends the mono resource list by adding a **mixer module**.
|
|
32
|
-
* - The mixer module is required to handle multiple simultaneous voices used in a polyphonic instrument.
|
|
33
|
-
*/
|
|
34
|
-
const POLY_RESOURCES = [
|
|
35
|
-
...MONO_RESOURCES,
|
|
36
|
-
"./mixer-module.wasm",
|
|
37
|
-
];
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* List of resources for the **Polyphonic DSP with Effects** version.
|
|
41
|
-
*
|
|
42
|
-
* - Extends the polyphonic resource list by adding an **effect module**.
|
|
43
|
-
* - The effect module allows applying audio effects to the polyphonic instrument.
|
|
44
|
-
*/
|
|
45
|
-
const POLY_EFFECT_RESOURCES = [
|
|
46
|
-
...POLY_RESOURCES,
|
|
47
|
-
"./effect-module.wasm",
|
|
48
|
-
"./effect-meta.json",
|
|
49
|
-
];
|
|
50
|
-
|
|
51
|
-
/** @type {ServiceWorkerGlobalScope} */
|
|
52
|
-
const serviceWorkerGlobalScope = self;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Install the service worker, cache essential resources, and prepare for immediate activation.
|
|
56
|
-
*
|
|
57
|
-
* - Opens the cache and stores required assets based on the app's configuration.
|
|
58
|
-
* - Ensures resources are preloaded for offline access.
|
|
59
|
-
*/
|
|
60
|
-
serviceWorkerGlobalScope.addEventListener("install", (event) => {
|
|
61
|
-
console.log("Service worker installed");
|
|
62
|
-
event.waitUntil((async () => {
|
|
63
|
-
const cache = await caches.open(CACHE_NAME);
|
|
64
|
-
const resources = (FAUST_DSP_VOICES && FAUST_DSP_HAS_EFFECT) ? POLY_EFFECT_RESOURCES : (FAUST_DSP_VOICES ? POLY_RESOURCES : MONO_RESOURCES);
|
|
65
|
-
try {
|
|
66
|
-
return cache.addAll(resources);
|
|
67
|
-
} catch (error) {
|
|
68
|
-
console.error("Failed to cache resources during install:", error);
|
|
69
|
-
}
|
|
70
|
-
})());
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Handles the activation of the Service Worker.
|
|
75
|
-
*
|
|
76
|
-
* - Claims control over all clients immediately, bypassing the default behavior that
|
|
77
|
-
* requires a page reload before the new service worker takes effect.
|
|
78
|
-
* - Once claimed, it finds all active window clients and reloads them to ensure they are
|
|
79
|
-
* controlled by the latest version of the service worker.
|
|
80
|
-
* - This approach ensures that updates to the service worker take effect immediately
|
|
81
|
-
* across all open pages, preventing potential inconsistencies.
|
|
82
|
-
*/
|
|
83
|
-
serviceWorkerGlobalScope.addEventListener("activate", (event) => {
|
|
84
|
-
console.log("Service worker activated");
|
|
85
|
-
event.waitUntil(
|
|
86
|
-
clients.claim().then(() => {
|
|
87
|
-
return clients.matchAll({ type: "window" }).then((clients) => {
|
|
88
|
-
clients.forEach((client) => {
|
|
89
|
-
client.navigate(client.url);
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
})
|
|
93
|
-
);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Adjusts response headers to enforce Cross-Origin Opener Policy (COOP) and Cross-Origin Embedder Policy (COEP).
|
|
98
|
-
*
|
|
99
|
-
* - Ensures that the response is served with `Cross-Origin-Opener-Policy: same-origin`
|
|
100
|
-
* and `Cross-Origin-Embedder-Policy: require-corp`.
|
|
101
|
-
* - Required for enabling **cross-origin isolated** environments in web applications.
|
|
102
|
-
* - Necessary for features like **SharedArrayBuffer**, WebAssembly threads, and
|
|
103
|
-
* high-performance APIs that require isolation.
|
|
104
|
-
* - Creates a new `Response` object with the modified headers while preserving
|
|
105
|
-
* the original response body and status.
|
|
106
|
-
*
|
|
107
|
-
* @param {Response} response - The original HTTP response object.
|
|
108
|
-
* @returns {Response} A new response with updated security headers.
|
|
109
|
-
*/
|
|
110
|
-
const getCrossOriginIsolatedResponse = (response) => {
|
|
111
|
-
// Modify headers to include COOP & COEP
|
|
112
|
-
const headers = new Headers(response.headers);
|
|
113
|
-
headers.set("Cross-Origin-Opener-Policy", "same-origin");
|
|
114
|
-
headers.set("Cross-Origin-Embedder-Policy", "require-corp");
|
|
115
|
-
|
|
116
|
-
// Create a new response with the modified headers
|
|
117
|
-
const modifiedResponse = new Response(response.body, {
|
|
118
|
-
status: response.status,
|
|
119
|
-
statusText: response.statusText,
|
|
120
|
-
headers
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
return modifiedResponse;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Intercepts fetch requests and enforces COOP and COEP headers for security.
|
|
128
|
-
*
|
|
129
|
-
* - Checks if the requested resource is available in the cache:
|
|
130
|
-
* - If found, returns a cached response with `Cross-Origin-Opener-Policy` and `Cross-Origin-Embedder-Policy` headers.
|
|
131
|
-
* - If not found, fetches the resource from the network, applies COOP/COEP headers, and caches the response (for GET requests).
|
|
132
|
-
* - Ensures cross-origin isolation, required for APIs like `SharedArrayBuffer` and WebAssembly threading.
|
|
133
|
-
* - Handles network errors gracefully by returning a 503 "Service Unavailable" response when needed.
|
|
134
|
-
*
|
|
135
|
-
* @param {FetchEvent} event - The fetch event triggered by the browser.
|
|
136
|
-
*/
|
|
137
|
-
serviceWorkerGlobalScope.addEventListener("fetch", (event) => {
|
|
138
|
-
|
|
139
|
-
event.respondWith((async () => {
|
|
140
|
-
const cache = await caches.open(CACHE_NAME);
|
|
141
|
-
const cachedResponse = await cache.match(event.request);
|
|
142
|
-
|
|
143
|
-
if (cachedResponse) {
|
|
144
|
-
return getCrossOriginIsolatedResponse(cachedResponse);
|
|
145
|
-
} else {
|
|
146
|
-
try {
|
|
147
|
-
const fetchResponse = await fetch(event.request);
|
|
148
|
-
|
|
149
|
-
if (event.request.method === "GET" && fetchResponse && fetchResponse.status === 200 && fetchResponse.type === "basic") {
|
|
150
|
-
const modifiedResponse = getCrossOriginIsolatedResponse(fetchResponse);
|
|
151
|
-
// Store the modified response in the cache
|
|
152
|
-
await cache.put(event.request, modifiedResponse.clone());
|
|
153
|
-
// Return the modified response to the browser
|
|
154
|
-
return modifiedResponse;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return fetchResponse;
|
|
158
|
-
} catch (error) {
|
|
159
|
-
console.error("Network access error", error);
|
|
160
|
-
return new Response("Network error", { status: 503, statusText: "Service Unavailable" });
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
})());
|
|
164
|
-
});
|
|
165
|
-
|