beginning of web demo
This commit is contained in:
parent
8dabd9b3f8
commit
41e603c650
4
templates/web-demo/demo.mk
Normal file
4
templates/web-demo/demo.mk
Normal file
@ -0,0 +1,4 @@
|
||||
ALL += build/index.html
|
||||
|
||||
build/index.html: src/index.html | build
|
||||
cp $^ $@
|
16
templates/web-demo/src/index.html
Normal file
16
templates/web-demo/src/index.html
Normal 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>
|
7
templates/web-demo/tibia-index.js
Normal file
7
templates/web-demo/tibia-index.js
Normal 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`);
|
||||
};
|
@ -18,7 +18,13 @@ LDFLAGS = \
|
||||
-Wl,-z,stack-size=$$((8*1024*1024)) \
|
||||
-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
|
||||
${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
|
||||
cp $^ $@
|
||||
|
||||
build/${BUNDLE_NAME}.js: src/module.js | build
|
||||
cp $^ $@
|
||||
|
||||
build:
|
||||
mkdir -p $@
|
||||
|
||||
|
33
templates/web/src/module.js
Normal file
33
templates/web/src/module.js
Normal 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 }
|
||||
});
|
||||
}
|
||||
}
|
@ -7,4 +7,5 @@ module.exports = function (data, api) {
|
||||
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}processor.js`, `src${sep}processor.js`, data);
|
||||
api.generateFileFromTemplateFile(`src${sep}module.js`, `src${sep}module.js`, data);
|
||||
};
|
||||
|
@ -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-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
|
||||
|
Loading…
Reference in New Issue
Block a user