beginning of web demo

This commit is contained in:
Stefano D'Angelo 2024-01-18 18:13:31 +01:00
parent 8dabd9b3f8
commit 41e603c650
7 changed files with 72 additions and 1 deletions

View File

@ -0,0 +1,4 @@
ALL += build/index.html
build/index.html: src/index.html | build
cp $^ $@

View File

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<title>{{=it.product.name}}</title>
<script type="module">
import * as demo from "./{{=it.product.bundleName}}.js";
window.demo = demo;
</script>
<script>
</script>
</head>
<body>
<h1>{{=it.product.name}}</h1>
<input id="start" type="button" value="Start">
</body>
</html>

View File

@ -0,0 +1,7 @@
var path = require("path");
var sep = path.sep;
module.exports = function (data, api) {
api.generateFileFromTemplateFile(`src${sep}index.html`, `src${sep}index.html`, data);
api.copyFile(`demo.mk`, `demo.mk`);
};

View File

@ -18,7 +18,13 @@ LDFLAGS = \
-Wl,-z,stack-size=$$((8*1024*1024)) \ -Wl,-z,stack-size=$$((8*1024*1024)) \
-nostdlib -nostdlib
all: build/${BUNDLE_NAME}.wasm build/${BUNDLE_NAME}_processor.js ALL = build/${BUNDLE_NAME}.wasm build/${BUNDLE_NAME}_processor.js build/${BUNDLE_NAME}.js
default: all
-include demo.mk
all: ${ALL}
build/${BUNDLE_NAME}.wasm: src/data.h src/memset.h src/plugin.h src/walloc.h src/processor.c | build build/${BUNDLE_NAME}.wasm: src/data.h src/memset.h src/plugin.h src/walloc.h src/processor.c | build
${CC} src/processor.c -o $@ ${CFLAGS} ${LDFLAGS} ${CFLAGS_EXTRA} ${LIBS_EXTRA} ${CC} src/processor.c -o $@ ${CFLAGS} ${LDFLAGS} ${CFLAGS_EXTRA} ${LIBS_EXTRA}
@ -26,6 +32,9 @@ build/${BUNDLE_NAME}.wasm: src/data.h src/memset.h src/plugin.h src/walloc.h src
build/${BUNDLE_NAME}_processor.js: src/processor.js | build build/${BUNDLE_NAME}_processor.js: src/processor.js | build
cp $^ $@ cp $^ $@
build/${BUNDLE_NAME}.js: src/module.js | build
cp $^ $@
build: build:
mkdir -p $@ mkdir -p $@

View File

@ -0,0 +1,33 @@
const data = {{=JSON.stringify(it, null, 2)}};
export class Module {
static get data() { return data; }
async init(context, processorJsPath, wasmPath) {
var wasmBytes = await fetch(wasmPath)
.then(response => response.arrayBuffer())
.then(bytes => bytes);
if (!wasmBytes.byteLength)
throw "Could not fetch WebAssembly module";
await context.audioWorklet.addModule(processorJsPath);
this.context = context;
this.wasmBytes = wasmBytes;
}
context = null;
wasmBytes = null;
}
export class Node extends AudioWorkletNode {
constructor(module) {
super(module.context, data.product.bundleName,
{
numberOfInputs: data.product.buses.filter(b => b.type == "audio" && b.direction == "input").length,
numberOfOutputs: data.product.buses.filter(b => b.type == "audio" && b.direction == "output").length,
outputChannelCount: data.product.buses.filter(b => b.type == "audio" && b.direction == "output").map(b => b.channels == "mono" ? 1 : 2),
processorOptions: { wasmBytes: module.wasmBytes }
});
}
}

View File

@ -7,4 +7,5 @@ module.exports = function (data, api) {
api.copyFile(`src${sep}processor.c`, `src${sep}processor.c`); api.copyFile(`src${sep}processor.c`, `src${sep}processor.c`);
api.generateFileFromTemplateFile(`src${sep}data.h`, `src${sep}data.h`, data); api.generateFileFromTemplateFile(`src${sep}data.h`, `src${sep}data.h`, data);
api.generateFileFromTemplateFile(`src${sep}processor.js`, `src${sep}processor.js`, data); api.generateFileFromTemplateFile(`src${sep}processor.js`, `src${sep}processor.js`, data);
api.generateFileFromTemplateFile(`src${sep}module.js`, `src${sep}module.js`, data);
}; };

View File

@ -11,4 +11,5 @@ cp $dir/plugin.h $dir/../out/lv2/src
$dir/../tibia $dir/product.json,$dir/company.json $dir/../templates/web $dir/../out/web $dir/../tibia $dir/product.json,$dir/company.json $dir/../templates/web $dir/../out/web
$dir/../tibia $dir/product.json,$dir/company.json $dir/../templates/web-make $dir/../out/web $dir/../tibia $dir/product.json,$dir/company.json $dir/../templates/web-make $dir/../out/web
$dir/../tibia $dir/product.json,$dir/company.json $dir/../templates/web-demo $dir/../out/web
cp $dir/plugin.h $dir/../out/web/src cp $dir/plugin.h $dir/../out/web/src