From b79381e85ff4b050864eb259f21965c0cd3702c7 Mon Sep 17 00:00:00 2001 From: Stefano D'Angelo Date: Fri, 19 Jan 2024 15:33:53 +0100 Subject: [PATCH] web demo working (no midi yet) --- templates/web-demo/src/index.html | 184 ++++++++++++++++++++++++++++++ templates/web-make/Makefile | 6 +- templates/web/src/module.js | 5 +- templates/web/src/processor.js | 23 ++-- 4 files changed, 201 insertions(+), 17 deletions(-) diff --git a/templates/web-demo/src/index.html b/templates/web-demo/src/index.html index f950156..2a9a58e 100644 --- a/templates/web-demo/src/index.html +++ b/templates/web-demo/src/index.html @@ -7,10 +7,194 @@ import * as demo from "./{{=it.product.bundleName}}.js"; window.demo = demo;

{{=it.product.name}}

+ + diff --git a/templates/web-make/Makefile b/templates/web-make/Makefile index 9379f41..4ca0f07 100644 --- a/templates/web-make/Makefile +++ b/templates/web-make/Makefile @@ -10,9 +10,9 @@ LDFLAGS = \ -Wl,--export-table \ -Wl,--export=processor_new \ -Wl,--export=processor_free \ - -Wl,--export=processor_get_ins \ - -Wl,--export=processor_get_outs \ - -Wl,--export=processor_get_param_values \ + -Wl,--export=processor_get_x_buf \ + -Wl,--export=processor_get_y_buf \ + -Wl,--export=processor_get_out_params \ -Wl,--export=processor_process \ -Wl,--export=processor_set_parameter \ -Wl,-z,stack-size=$$((8*1024*1024)) \ diff --git a/templates/web/src/module.js b/templates/web/src/module.js index 122748a..a06236b 100644 --- a/templates/web/src/module.js +++ b/templates/web/src/module.js @@ -1,4 +1,7 @@ -const data = {{=JSON.stringify(it, null, 2)}}; +const data = { + company: {{=JSON.stringify(it.company, null, 2)}}, + product: {{=JSON.stringify(it.product, null, 2)}} +}; export class Module { static get data() { return data; } diff --git a/templates/web/src/processor.js b/templates/web/src/processor.js index 0e36b5a..1315cea 100644 --- a/templates/web/src/processor.js +++ b/templates/web/src/processor.js @@ -6,11 +6,6 @@ var buses = {{=JSON.stringify(it.product.buses, null, 2)}}; var parameters = {{=JSON.stringify(it.product.parameters, null, 2)}}; class Processor extends AudioWorkletProcessor { - throwError(msg) { - this.port.postMessage({ type: "error", msg: msg); - throw msg; - } - constructor(options) { super(); @@ -20,12 +15,12 @@ class Processor extends AudioWorkletProcessor { this.instance = this.module.processor_new(sampleRate); if (!this.instance) - this.throwError("Could not instantiate processor module"); + throw "Could not instantiate processor module"; function getBuffers(p, output) { var ret = []; for (var i = 0; i < buses.length; i++) { - if ((output && buses[i].direction == "input") || (!output && buses[i].direction == "output")) + if (buses[i].type != "audio" || (output && buses[i].direction == "input") || (!output && buses[i].direction == "output")) continue; if (buses[i].channels == "mono") { ret.push([ new Float32Array(this.module.memory.buffer, p, 128) ]); @@ -59,15 +54,15 @@ class Processor extends AudioWorkletProcessor { this.paramOutChangeMsg = { type: "paramOutChange", index: NaN, value: NaN }; } - process(input, outputs, params) { + process(inputs, outputs, params) { for (var i = 0; i < this.parametersIn.length; i++) { var index = this.parametersIn[i].index; var parameter = parameters[index]; var name = parameter.name; - var value = params[p.name][0]; + var value = params[name][0]; if (value != this.parametersIn[i].value) { if (parameter.isBypass || parameter.toggled) - value = value > 0 ? 0 : 1; + value = value > 0 ? 1 : 0; else if (parameter.integer) value = Math.round(value); value = Math.min(Math.max(value, parameter.minimum), parameter.maximum); @@ -102,7 +97,7 @@ class Processor extends AudioWorkletProcessor { for (var j = 0; j < this.y.length; j++) { var output = outputs[j]; for (var k = 0; k < this.y[j].length; k++) - this.y[j][k].set(output[k].subarray(i, s)); + output[k].set(this.y[j][k].subarray(i, s)); } i += s; @@ -124,8 +119,10 @@ class Processor extends AudioWorkletProcessor { static get parameterDescriptors() { var ret = []; - for (var i = 0; i < this.parametersIn.length; i++) { - var p = parameters[this.parametersIn[i].index]; + for (var i = 0; i < parameters.length; i++) { + var p = parameters[i]; + if (p.direction == "output") + continue; ret.push({ name: p.name, minValue: p.minimum, maxValue: p.maximum, defaultValue: p.defaultValue, automationRate: "k-rate" }); } return ret;