@webmusic/kernel 0.2.0 → 0.4.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.
- package/LICENSE +202 -21
- package/NOTICE +2 -0
- package/README.md +103 -64
- package/dist/audio-context.cjs.map +1 -1
- package/dist/build-receipt.json +3 -3
- package/dist/chunk-27LH6QLZ.cjs +277 -0
- package/dist/chunk-27LH6QLZ.cjs.map +1 -0
- package/dist/chunk-3INDOVUC.cjs.map +1 -1
- package/dist/chunk-3RR2VIKA.js +393 -0
- package/dist/chunk-3RR2VIKA.js.map +1 -0
- package/dist/chunk-3YTKIKKX.cjs +378 -0
- package/dist/chunk-3YTKIKKX.cjs.map +1 -0
- package/dist/chunk-4RG4WQKC.js +360 -0
- package/dist/chunk-4RG4WQKC.js.map +1 -0
- package/dist/chunk-5AHVQXTF.cjs +620 -0
- package/dist/chunk-5AHVQXTF.cjs.map +1 -0
- package/dist/chunk-624KWJWZ.js +170 -0
- package/dist/chunk-624KWJWZ.js.map +1 -0
- package/dist/chunk-6HGFEKD3.cjs +851 -0
- package/dist/chunk-6HGFEKD3.cjs.map +1 -0
- package/dist/chunk-7ZTZZ5PN.cjs.map +1 -1
- package/dist/chunk-ALWV4P7D.js +726 -0
- package/dist/chunk-ALWV4P7D.js.map +1 -0
- package/dist/chunk-BADJJ6DV.cjs +143 -0
- package/dist/chunk-BADJJ6DV.cjs.map +1 -0
- package/dist/chunk-C3LMS36L.cjs +393 -0
- package/dist/chunk-C3LMS36L.cjs.map +1 -0
- package/dist/chunk-C3YWUZW3.cjs.map +1 -1
- package/dist/chunk-CR6OUWBJ.cjs +726 -0
- package/dist/chunk-CR6OUWBJ.cjs.map +1 -0
- package/dist/chunk-CYWDZLWC.js +2141 -0
- package/dist/chunk-CYWDZLWC.js.map +1 -0
- package/dist/chunk-DDOGX2D5.js +378 -0
- package/dist/chunk-DDOGX2D5.js.map +1 -0
- package/dist/chunk-DVN6E5U3.js +620 -0
- package/dist/chunk-DVN6E5U3.js.map +1 -0
- package/dist/chunk-EURMRU2S.js +208 -0
- package/dist/chunk-EURMRU2S.js.map +1 -0
- package/dist/chunk-EXDCK2VL.cjs +20 -0
- package/dist/chunk-EXDCK2VL.cjs.map +1 -0
- package/dist/chunk-G5EIUP52.js +114 -0
- package/dist/chunk-G5EIUP52.js.map +1 -0
- package/dist/chunk-GB4DGKLZ.js +143 -0
- package/dist/chunk-GB4DGKLZ.js.map +1 -0
- package/dist/chunk-GPOEAYOW.js +2147 -0
- package/dist/chunk-GPOEAYOW.js.map +1 -0
- package/dist/chunk-I4YMA5VM.cjs +120 -0
- package/dist/chunk-I4YMA5VM.cjs.map +1 -0
- package/dist/chunk-IVWHMDCB.cjs +4383 -0
- package/dist/chunk-IVWHMDCB.cjs.map +1 -0
- package/dist/chunk-JFCBJMA7.cjs +2147 -0
- package/dist/chunk-JFCBJMA7.cjs.map +1 -0
- package/dist/chunk-JLVSAZ3K.cjs +813 -0
- package/dist/chunk-JLVSAZ3K.cjs.map +1 -0
- package/dist/chunk-K7FYH6UG.cjs +208 -0
- package/dist/chunk-K7FYH6UG.cjs.map +1 -0
- package/dist/chunk-L4MYCETM.cjs +970 -0
- package/dist/chunk-L4MYCETM.cjs.map +1 -0
- package/dist/chunk-MNCMYNYL.js +970 -0
- package/dist/chunk-MNCMYNYL.js.map +1 -0
- package/dist/chunk-NT2BZ3QM.js +120 -0
- package/dist/chunk-NT2BZ3QM.js.map +1 -0
- package/dist/chunk-O7SA5GLC.js +277 -0
- package/dist/chunk-O7SA5GLC.js.map +1 -0
- package/dist/chunk-OCKAHITL.cjs +548 -0
- package/dist/chunk-OCKAHITL.cjs.map +1 -0
- package/dist/chunk-OTXYWCLA.js +206 -0
- package/dist/chunk-OTXYWCLA.js.map +1 -0
- package/dist/chunk-P6ZA63J7.js +548 -0
- package/dist/chunk-P6ZA63J7.js.map +1 -0
- package/dist/chunk-QLF3BOST.js +20 -0
- package/dist/chunk-QLF3BOST.js.map +1 -0
- package/dist/chunk-RCWFRZDR.js +4383 -0
- package/dist/chunk-RCWFRZDR.js.map +1 -0
- package/dist/chunk-RZBLPM3L.cjs +206 -0
- package/dist/chunk-RZBLPM3L.cjs.map +1 -0
- package/dist/chunk-TA3TNJZU.cjs +360 -0
- package/dist/chunk-TA3TNJZU.cjs.map +1 -0
- package/dist/chunk-TZSRPTQL.cjs +2141 -0
- package/dist/chunk-TZSRPTQL.cjs.map +1 -0
- package/dist/chunk-UMTPJ76S.cjs.map +1 -1
- package/dist/chunk-UY77FXDW.js +813 -0
- package/dist/chunk-UY77FXDW.js.map +1 -0
- package/dist/chunk-VFU3S7OC.js +851 -0
- package/dist/chunk-VFU3S7OC.js.map +1 -0
- package/dist/chunk-VY6WWZSW.cjs.map +1 -1
- package/dist/chunk-WN5DZOVT.cjs +170 -0
- package/dist/chunk-WN5DZOVT.cjs.map +1 -0
- package/dist/chunk-WOPW6WLR.cjs.map +1 -1
- package/dist/chunk-XBSIYUHM.cjs +114 -0
- package/dist/chunk-XBSIYUHM.cjs.map +1 -0
- package/dist/chunk-ZMU72HJS.cjs.map +1 -1
- package/dist/context-DSa0ymyN.d.cts +664 -0
- package/dist/context-DaxfAg3b.d.ts +664 -0
- package/dist/effect-chain-Cu03O5Y0.d.ts +91 -0
- package/dist/effect-chain-Do75T7uK.d.cts +91 -0
- package/dist/effect.cjs +16 -1
- package/dist/effect.cjs.map +1 -1
- package/dist/effect.d.cts +56 -14
- package/dist/effect.d.ts +56 -14
- package/dist/effect.js +16 -1
- package/dist/elements.cjs +37 -2
- package/dist/elements.cjs.map +1 -1
- package/dist/elements.d.cts +197 -8
- package/dist/elements.d.ts +197 -8
- package/dist/elements.js +36 -1
- package/dist/events.cjs.map +1 -1
- package/dist/index.cjs +555 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -4
- package/dist/index.d.ts +16 -4
- package/dist/index.js +566 -19
- package/dist/message.cjs +104 -0
- package/dist/message.cjs.map +1 -0
- package/dist/message.d.cts +738 -0
- package/dist/message.d.ts +738 -0
- package/dist/message.js +104 -0
- package/dist/meter.cjs.map +1 -1
- package/dist/module-control-C25BMtH7.d.ts +61 -0
- package/dist/module-control-yH6nTJM9.d.cts +61 -0
- package/dist/module-plugin-BnPmq1VP.d.ts +198 -0
- package/dist/module-plugin-CHb-5W0Y.d.cts +198 -0
- package/dist/module.cjs +263 -0
- package/dist/module.cjs.map +1 -0
- package/dist/module.d.cts +1112 -0
- package/dist/module.d.ts +1112 -0
- package/dist/module.js +263 -0
- package/dist/parameter-DwQzFmBR.d.cts +172 -0
- package/dist/parameter-DwQzFmBR.d.ts +172 -0
- package/dist/player.cjs.map +1 -1
- package/dist/processor-worklet.cjs +18 -0
- package/dist/processor-worklet.cjs.map +1 -0
- package/dist/processor-worklet.d.cts +166 -0
- package/dist/processor-worklet.d.ts +166 -0
- package/dist/processor-worklet.js +18 -0
- package/dist/processor-worklet.js.map +1 -0
- package/dist/processor.cjs +51 -0
- package/dist/processor.cjs.map +1 -0
- package/dist/processor.d.cts +397 -0
- package/dist/processor.d.ts +397 -0
- package/dist/processor.js +51 -0
- package/dist/processor.js.map +1 -0
- package/dist/project-types-BU4awMnL.d.ts +323 -0
- package/dist/project-types-DufCV8Ma.d.cts +323 -0
- package/dist/ring-C-i9N90a.d.cts +139 -0
- package/dist/ring-DkcMt2Eg.d.ts +139 -0
- package/dist/sequence.cjs +68 -0
- package/dist/sequence.cjs.map +1 -0
- package/dist/sequence.d.cts +303 -0
- package/dist/sequence.d.ts +303 -0
- package/dist/sequence.js +68 -0
- package/dist/sequence.js.map +1 -0
- package/dist/session.cjs +16 -0
- package/dist/session.cjs.map +1 -0
- package/dist/session.d.cts +407 -0
- package/dist/session.d.ts +407 -0
- package/dist/session.js +16 -0
- package/dist/session.js.map +1 -0
- package/dist/tick.cjs.map +1 -1
- package/dist/transport.cjs +50 -2
- package/dist/transport.cjs.map +1 -1
- package/dist/transport.d.cts +145 -1
- package/dist/transport.d.ts +145 -1
- package/dist/transport.js +51 -3
- package/dist/worker.cjs.map +1 -1
- package/package.json +61 -10
- package/dist/chunk-53YD73OY.js +0 -162
- package/dist/chunk-53YD73OY.js.map +0 -1
- package/dist/chunk-54JYWB5X.cjs +0 -1051
- package/dist/chunk-54JYWB5X.cjs.map +0 -1
- package/dist/chunk-BR63OD53.cjs +0 -1
- package/dist/chunk-BR63OD53.cjs.map +0 -1
- package/dist/chunk-ON64FRCF.js +0 -1051
- package/dist/chunk-ON64FRCF.js.map +0 -1
- package/dist/chunk-SM5YPDDI.cjs +0 -162
- package/dist/chunk-SM5YPDDI.cjs.map +0 -1
- package/dist/chunk-TEM2I2NN.js +0 -1
- package/dist/chunk-VVZX7DQ6.cjs +0 -254
- package/dist/chunk-VVZX7DQ6.cjs.map +0 -1
- package/dist/chunk-WNFGDB7B.js +0 -254
- package/dist/chunk-WNFGDB7B.js.map +0 -1
- package/dist/sync.cjs +0 -12
- package/dist/sync.cjs.map +0 -1
- package/dist/sync.d.cts +0 -307
- package/dist/sync.d.ts +0 -307
- package/dist/sync.js +0 -12
- /package/dist/{chunk-TEM2I2NN.js.map → message.js.map} +0 -0
- /package/dist/{sync.js.map → module.js.map} +0 -0
|
@@ -0,0 +1,813 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkRZBLPM3Lcjs = require('./chunk-RZBLPM3L.cjs');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
var _chunkOCKAHITLcjs = require('./chunk-OCKAHITL.cjs');
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
var _chunkK7FYH6UGcjs = require('./chunk-K7FYH6UG.cjs');
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
var _chunk5AHVQXTFcjs = require('./chunk-5AHVQXTF.cjs');
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
var _chunkI4YMA5VMcjs = require('./chunk-I4YMA5VM.cjs');
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
var _chunk7ZTZZ5PNcjs = require('./chunk-7ZTZZ5PN.cjs');
|
|
33
|
+
|
|
34
|
+
// src/processor/prepare.ts
|
|
35
|
+
var ProcessorUnavailableError = class extends Error {
|
|
36
|
+
constructor(message = "AudioWorklet is unavailable in this audio context.") {
|
|
37
|
+
super(message);
|
|
38
|
+
this.name = "ProcessorUnavailableError";
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var preparations = /* @__PURE__ */ new WeakMap();
|
|
42
|
+
async function compileWasm(input) {
|
|
43
|
+
const wasm = globalThis.WebAssembly;
|
|
44
|
+
if (!wasm) throw new ProcessorUnavailableError("WebAssembly is unavailable in this environment.");
|
|
45
|
+
if (input instanceof wasm.Module) return input;
|
|
46
|
+
if (typeof input === "string" || input instanceof URL) {
|
|
47
|
+
const response = await fetch(String(input));
|
|
48
|
+
if (!response.ok) throw new Error(`Processor WebAssembly ${String(input)} failed to load (${response.status}).`);
|
|
49
|
+
return wasm.compile(await response.arrayBuffer());
|
|
50
|
+
}
|
|
51
|
+
return wasm.compile(input);
|
|
52
|
+
}
|
|
53
|
+
async function load(context, definition, source, entry) {
|
|
54
|
+
if (_optionalChain([definition, 'access', _2 => _2.sharedRing, 'optionalAccess', _3 => _3.required]) && !_chunkRZBLPM3Lcjs.processorCapabilities.call(void 0, ).sharedMemory) {
|
|
55
|
+
throw new ProcessorUnavailableError(`Processor ${definition.name} requires a shared ring, which needs a cross-origin isolated page.`);
|
|
56
|
+
}
|
|
57
|
+
if (definition.wasm && _optionalChain([source, 'optionalAccess', _4 => _4.wasm]) === void 0) {
|
|
58
|
+
throw new TypeError(`Processor ${definition.name} declares wasm, so its source needs wasm.`);
|
|
59
|
+
}
|
|
60
|
+
if (_optionalChain([source, 'optionalAccess', _5 => _5.wasm]) !== void 0) entry.wasm = await compileWasm(source.wasm);
|
|
61
|
+
if ("register" in source) {
|
|
62
|
+
if (typeof source.register !== "function") throw new TypeError("Processor source register must be a function.");
|
|
63
|
+
await source.register(context);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (!(typeof _optionalChain([source, 'optionalAccess', _6 => _6.module]) === "string" && source.module) && !(_optionalChain([source, 'optionalAccess', _7 => _7.module]) instanceof URL)) {
|
|
67
|
+
throw new TypeError("Processor source needs a module URL or a register function.");
|
|
68
|
+
}
|
|
69
|
+
const worklet = context.audioWorklet;
|
|
70
|
+
if (typeof _optionalChain([worklet, 'optionalAccess', _8 => _8.addModule]) !== "function") throw new ProcessorUnavailableError();
|
|
71
|
+
await worklet.addModule(String(source.module));
|
|
72
|
+
}
|
|
73
|
+
function prepareProcessor(context, definition, source) {
|
|
74
|
+
let resolved, signature;
|
|
75
|
+
try {
|
|
76
|
+
if (!context || typeof context !== "object") throw new TypeError("prepareProcessor needs an audio context.");
|
|
77
|
+
resolved = _chunkRZBLPM3Lcjs.resolveProcessorDefinition.call(void 0, definition);
|
|
78
|
+
signature = _chunkRZBLPM3Lcjs.processorSignature.call(void 0, resolved);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
return Promise.reject(error);
|
|
81
|
+
}
|
|
82
|
+
const byName = _nullishCoalesce(preparations.get(context), () => ( /* @__PURE__ */ new Map()));
|
|
83
|
+
preparations.set(context, byName);
|
|
84
|
+
const existing = byName.get(resolved.name);
|
|
85
|
+
if (existing) {
|
|
86
|
+
return existing.signature === signature ? existing.promise : Promise.reject(new Error(
|
|
87
|
+
`Processor ${resolved.name} is already prepared in this context with a different definition; change its version.`
|
|
88
|
+
));
|
|
89
|
+
}
|
|
90
|
+
const entry = { signature, ready: false, wasm: void 0 };
|
|
91
|
+
entry.promise = load(context, resolved, source, entry).then(
|
|
92
|
+
() => {
|
|
93
|
+
entry.ready = true;
|
|
94
|
+
},
|
|
95
|
+
(error) => {
|
|
96
|
+
if (byName.get(resolved.name) === entry) byName.delete(resolved.name);
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
byName.set(resolved.name, entry);
|
|
101
|
+
return entry.promise;
|
|
102
|
+
}
|
|
103
|
+
function isProcessorPrepared(context, definition) {
|
|
104
|
+
const resolved = _chunkRZBLPM3Lcjs.resolveProcessorDefinition.call(void 0, definition);
|
|
105
|
+
const entry = _optionalChain([preparations, 'access', _9 => _9.get, 'call', _10 => _10(context), 'optionalAccess', _11 => _11.get, 'call', _12 => _12(resolved.name)]);
|
|
106
|
+
return _optionalChain([entry, 'optionalAccess', _13 => _13.ready]) === true && entry.signature === _chunkRZBLPM3Lcjs.processorSignature.call(void 0, resolved);
|
|
107
|
+
}
|
|
108
|
+
function preparedWasm(context, definition) {
|
|
109
|
+
return _optionalChain([preparations, 'access', _14 => _14.get, 'call', _15 => _15(context), 'optionalAccess', _16 => _16.get, 'call', _17 => _17(definition.name), 'optionalAccess', _18 => _18.wasm]);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// src/processor/node.ts
|
|
113
|
+
function defaultNodeFactory(context, name, options) {
|
|
114
|
+
const Constructor = globalThis.AudioWorkletNode;
|
|
115
|
+
if (typeof Constructor !== "function") throw new ProcessorUnavailableError("AudioWorkletNode is unavailable in this environment.");
|
|
116
|
+
return new Constructor(context, name, options);
|
|
117
|
+
}
|
|
118
|
+
function createProcessorNode(audio, definition, options) {
|
|
119
|
+
const wasm = preparedWasm(audio, definition);
|
|
120
|
+
const ring = definition.sharedRing && options.ring !== false && _chunkRZBLPM3Lcjs.processorCapabilities.call(void 0, ).sharedMemory ? _chunkRZBLPM3Lcjs.ProcessorRing.create(definition.sharedRing.capacity) : void 0;
|
|
121
|
+
const processorOptions = {
|
|
122
|
+
protocol: _chunkRZBLPM3Lcjs.PROCESSOR_PROTOCOL_VERSION,
|
|
123
|
+
name: definition.name,
|
|
124
|
+
config: options.config,
|
|
125
|
+
...wasm && { wasm },
|
|
126
|
+
...ring && { ring: ring.buffer }
|
|
127
|
+
};
|
|
128
|
+
const node = (_nullishCoalesce(options.createNode, () => ( defaultNodeFactory)))(audio, definition.name, {
|
|
129
|
+
numberOfInputs: definition.audioInputs.length,
|
|
130
|
+
numberOfOutputs: definition.audioOutputs.length,
|
|
131
|
+
outputChannelCount: definition.audioOutputs.map((port) => port.channels),
|
|
132
|
+
...options.inputChannels !== void 0 && {
|
|
133
|
+
channelCount: options.inputChannels,
|
|
134
|
+
channelCountMode: "explicit",
|
|
135
|
+
channelInterpretation: "speakers"
|
|
136
|
+
},
|
|
137
|
+
parameterData: { ...options.baseValues },
|
|
138
|
+
processorOptions
|
|
139
|
+
});
|
|
140
|
+
if (ring) rings.set(node, ring);
|
|
141
|
+
return node;
|
|
142
|
+
}
|
|
143
|
+
var rings = /* @__PURE__ */ new WeakMap();
|
|
144
|
+
function processorRingOf(node) {
|
|
145
|
+
return rings.get(node);
|
|
146
|
+
}
|
|
147
|
+
function listenToProcessor(node, handlers) {
|
|
148
|
+
node.port.onmessage = (event) => {
|
|
149
|
+
const message = event.data;
|
|
150
|
+
if (_optionalChain([message, 'optionalAccess', _19 => _19.type]) === "error") handlers.fail(String(message.message));
|
|
151
|
+
else if (_optionalChain([message, 'optionalAccess', _20 => _20.type]) === "late") _optionalChain([handlers, 'access', _21 => _21.late, 'optionalCall', _22 => _22(Number(message.count) || 0)]);
|
|
152
|
+
else if (_optionalChain([message, 'optionalAccess', _23 => _23.type]) === "data" && handlers.data) {
|
|
153
|
+
try {
|
|
154
|
+
handlers.data(message.data);
|
|
155
|
+
} catch (error) {
|
|
156
|
+
try {
|
|
157
|
+
_optionalChain([handlers, 'access', _24 => _24.report, 'optionalCall', _25 => _25(error)]);
|
|
158
|
+
} catch (e) {
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
node.onprocessorerror = () => handlers.fail("The processor stopped with an uncaught error.");
|
|
164
|
+
return () => {
|
|
165
|
+
const close = { type: "close" };
|
|
166
|
+
node.port.postMessage(close);
|
|
167
|
+
node.port.onmessage = null;
|
|
168
|
+
node.onprocessorerror = null;
|
|
169
|
+
node.port.close();
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function processorParam(node, definition, id) {
|
|
173
|
+
const param = node.parameters.get(id);
|
|
174
|
+
if (!param) throw new Error(`Processor ${definition.name} node has no AudioParam ${id}; its worklet file may use another definition.`);
|
|
175
|
+
return param;
|
|
176
|
+
}
|
|
177
|
+
function nativeModulation(descriptor) {
|
|
178
|
+
return descriptor.modulation === "audio-rate" || descriptor.modulation === "control-rate";
|
|
179
|
+
}
|
|
180
|
+
function bindProcessorParams(audio, node, definition, handles, cleanups) {
|
|
181
|
+
for (const handle of handles) {
|
|
182
|
+
const param = processorParam(node, definition, handle.descriptor.id);
|
|
183
|
+
if (nativeModulation(handle.descriptor)) {
|
|
184
|
+
const lease = handle.bindAudioParam(audio, param, { lazy: true });
|
|
185
|
+
cleanups.push(() => lease.release());
|
|
186
|
+
} else {
|
|
187
|
+
param.value = handle.snapshot.baseValue;
|
|
188
|
+
const stop = handle.subscribe((snapshot) => {
|
|
189
|
+
if (!snapshot.disposed) param.setValueAtTime(snapshot.baseValue, audio.currentTime);
|
|
190
|
+
});
|
|
191
|
+
cleanups.push(stop);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// src/processor/module.ts
|
|
197
|
+
var defaultProcessorNoteTime = (event) => event.axis === "audio-context-seconds" ? event.time : event.axis === "performance-seconds" ? "now" : void 0;
|
|
198
|
+
var _occurrences, _next, _closed, _ProcessorNoteBridge_instances, post_fn;
|
|
199
|
+
var ProcessorNoteBridge = class {
|
|
200
|
+
constructor(node, sampleRate, time, name) {
|
|
201
|
+
this.node = node;
|
|
202
|
+
this.sampleRate = sampleRate;
|
|
203
|
+
this.time = time;
|
|
204
|
+
this.name = name;
|
|
205
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _ProcessorNoteBridge_instances);
|
|
206
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _occurrences, /* @__PURE__ */ new Map());
|
|
207
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _next, 1);
|
|
208
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _closed, false);
|
|
209
|
+
}
|
|
210
|
+
accept(event) {
|
|
211
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _closed)) return;
|
|
212
|
+
const at = this.time(event);
|
|
213
|
+
if (at === void 0) throw new TypeError(`Processor ${this.name} cannot place notes on the ${event.axis} axis; supply noteTime.`);
|
|
214
|
+
if (at !== "now" && !Number.isFinite(at)) throw new RangeError(`Processor ${this.name} note time must be finite seconds or 'now'.`);
|
|
215
|
+
const key = `${event.sourceId}\0${event.occurrenceId}`;
|
|
216
|
+
let occurrence = _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _occurrences), 'access', _26 => _26.get, 'call', _27 => _27(key), 'optionalAccess', _28 => _28.occurrence]);
|
|
217
|
+
if (event.gate === "on") {
|
|
218
|
+
if (occurrence !== void 0) return;
|
|
219
|
+
occurrence = _chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _next)._++;
|
|
220
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _occurrences).set(key, { occurrence, scheduled: at !== "now" });
|
|
221
|
+
} else {
|
|
222
|
+
if (occurrence === void 0) return;
|
|
223
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _occurrences).delete(key);
|
|
224
|
+
}
|
|
225
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ProcessorNoteBridge_instances, post_fn).call(this, {
|
|
226
|
+
type: "note",
|
|
227
|
+
gate: event.gate,
|
|
228
|
+
occurrence,
|
|
229
|
+
midi: event.pitch.midi,
|
|
230
|
+
cents: _nullishCoalesce(event.pitch.cents, () => ( 0)),
|
|
231
|
+
velocity: event.velocity,
|
|
232
|
+
frame: at === "now" ? _chunkRZBLPM3Lcjs.PROCESSOR_IMMEDIATE_FRAME : Math.max(0, Math.round(at * this.sampleRate)),
|
|
233
|
+
epoch: event.epoch
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* The Session invalidated its schedule: forget scheduled occurrences (the
|
|
238
|
+
* processor cancels them) so a producer's later release of one is ignored.
|
|
239
|
+
*/
|
|
240
|
+
flush(epoch) {
|
|
241
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _closed)) return;
|
|
242
|
+
for (const [key, entry] of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _occurrences)) if (entry.scheduled) _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _occurrences).delete(key);
|
|
243
|
+
this.node.port.postMessage({ type: "flush", epoch });
|
|
244
|
+
}
|
|
245
|
+
/** Cancel every note this bridge started, then stop accepting. */
|
|
246
|
+
close() {
|
|
247
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _closed)) return;
|
|
248
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _closed, true);
|
|
249
|
+
for (const { occurrence } of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _occurrences).values()) {
|
|
250
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ProcessorNoteBridge_instances, post_fn).call(this, { type: "note", gate: "cancel", occurrence, midi: 0, cents: 0, velocity: 0, frame: _chunkRZBLPM3Lcjs.PROCESSOR_IMMEDIATE_FRAME, epoch: 0 });
|
|
251
|
+
}
|
|
252
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _occurrences).clear();
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
_occurrences = new WeakMap();
|
|
256
|
+
_next = new WeakMap();
|
|
257
|
+
_closed = new WeakMap();
|
|
258
|
+
_ProcessorNoteBridge_instances = new WeakSet();
|
|
259
|
+
post_fn = function(message) {
|
|
260
|
+
this.node.port.postMessage(message);
|
|
261
|
+
};
|
|
262
|
+
function followSession(binding, node, audio, definition, notes) {
|
|
263
|
+
const post = (message) => node.port.postMessage(message);
|
|
264
|
+
const held = () => {
|
|
265
|
+
try {
|
|
266
|
+
return binding.positionAt(audio.currentTime);
|
|
267
|
+
} catch (e2) {
|
|
268
|
+
return binding.snapshot.originPosition;
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
return binding.subscribe((event) => {
|
|
272
|
+
const { snapshot } = event;
|
|
273
|
+
if (event.type === "invalidate") _optionalChain([notes, 'optionalAccess', _29 => _29.flush, 'call', _30 => _30(snapshot.epoch)]);
|
|
274
|
+
if (!definition.transport) return;
|
|
275
|
+
const running = event.type === "anchor" && snapshot.phase === "ready" && !snapshot.paused;
|
|
276
|
+
post({
|
|
277
|
+
type: "transport",
|
|
278
|
+
originFrame: Math.round(snapshot.originTime * audio.sampleRate),
|
|
279
|
+
originSeconds: running ? snapshot.originPosition : held(),
|
|
280
|
+
rate: snapshot.rate,
|
|
281
|
+
running,
|
|
282
|
+
loop: snapshot.loop ? { startSeconds: snapshot.loop.startSeconds, endSeconds: snapshot.loop.endSeconds } : null,
|
|
283
|
+
epoch: snapshot.epoch
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
var _inputs, _outputs, _ports, _cleanups, _listeners, _onCleanupError, _state, _error, _lateNotes, _ProcessorModule_instances, report_fn;
|
|
288
|
+
var ProcessorModule = class {
|
|
289
|
+
/** @internal Use {@link createProcessorModule}. */
|
|
290
|
+
constructor(parts) {
|
|
291
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _ProcessorModule_instances);
|
|
292
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _inputs);
|
|
293
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _outputs);
|
|
294
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _ports);
|
|
295
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _cleanups);
|
|
296
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _listeners);
|
|
297
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _onCleanupError);
|
|
298
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _state, "ready");
|
|
299
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _error);
|
|
300
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _lateNotes, 0);
|
|
301
|
+
this.id = parts.id;
|
|
302
|
+
this.definition = parts.definition;
|
|
303
|
+
this.node = parts.node;
|
|
304
|
+
this.params = parts.params;
|
|
305
|
+
this.latencySeconds = parts.latencySeconds;
|
|
306
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _inputs, parts.inputs);
|
|
307
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _outputs, parts.outputs);
|
|
308
|
+
this.notes = parts.notes;
|
|
309
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _ports, Object.freeze([
|
|
310
|
+
...parts.inputs,
|
|
311
|
+
...parts.notes ? [parts.notes] : [],
|
|
312
|
+
...parts.outputs,
|
|
313
|
+
...parts.control ? [parts.control] : []
|
|
314
|
+
]));
|
|
315
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _cleanups, parts.cleanups);
|
|
316
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _onCleanupError, parts.onCleanupError);
|
|
317
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _listeners, new (0, _chunkI4YMA5VMcjs.PortListeners)(parts.onCleanupError));
|
|
318
|
+
}
|
|
319
|
+
/** The reader side of the node's shared ring; absent unless the definition requests one and memory can be shared. */
|
|
320
|
+
get ring() {
|
|
321
|
+
return processorRingOf(this.node);
|
|
322
|
+
}
|
|
323
|
+
get state() {
|
|
324
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _state);
|
|
325
|
+
}
|
|
326
|
+
/** The processor's failure message while `state` is `error`. */
|
|
327
|
+
get error() {
|
|
328
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _error);
|
|
329
|
+
}
|
|
330
|
+
/** Note changes the processor played after their frame, as reported so far. Zero means every note was on time. */
|
|
331
|
+
get lateNotes() {
|
|
332
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _lateNotes);
|
|
333
|
+
}
|
|
334
|
+
/** Every port: audio inputs, `notes` with note input, audio outputs, then `params` when the definition has parameters. */
|
|
335
|
+
ports() {
|
|
336
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _ports);
|
|
337
|
+
}
|
|
338
|
+
/** An audio output by its definition ID. */
|
|
339
|
+
getPort(name) {
|
|
340
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _outputs).find((port) => port.id === name);
|
|
341
|
+
}
|
|
342
|
+
/** An audio input by its definition ID. */
|
|
343
|
+
getInput(name) {
|
|
344
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _inputs).find((port) => port.id === name);
|
|
345
|
+
}
|
|
346
|
+
/** Post configuration to the processor's `message` callback. Not for per-block control; use parameters. */
|
|
347
|
+
configure(data) {
|
|
348
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _state) === "detached") throw new Error("Processor module is disposed.");
|
|
349
|
+
const message = { type: "config", data };
|
|
350
|
+
this.node.port.postMessage(message);
|
|
351
|
+
}
|
|
352
|
+
/** Called after a state change and after a late-note report. */
|
|
353
|
+
subscribe(listener) {
|
|
354
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _state) === "detached") return () => {
|
|
355
|
+
};
|
|
356
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners).add(listener);
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Release routes, registration, ports, parameter bindings and the node, in
|
|
360
|
+
* reverse order of acquisition. Continues after an individual failure and is
|
|
361
|
+
* safe to repeat. The audio context stays open.
|
|
362
|
+
*/
|
|
363
|
+
dispose() {
|
|
364
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _state) === "detached") return;
|
|
365
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _state, "detached");
|
|
366
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _error, void 0);
|
|
367
|
+
for (const cleanup of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _cleanups).splice(0).reverse()) {
|
|
368
|
+
try {
|
|
369
|
+
cleanup();
|
|
370
|
+
} catch (error) {
|
|
371
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ProcessorModule_instances, report_fn).call(this, error);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners).emit();
|
|
375
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners).clear();
|
|
376
|
+
}
|
|
377
|
+
/** @internal Processor failure; routes stay so the graph remains valid and silent on this branch. */
|
|
378
|
+
fail(message) {
|
|
379
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _state) !== "ready") return;
|
|
380
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _state, "error");
|
|
381
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _error, message);
|
|
382
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners).emit();
|
|
383
|
+
}
|
|
384
|
+
/** @internal Late-note report from the processor. */
|
|
385
|
+
late(count) {
|
|
386
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _state) === "detached" || count <= 0) return;
|
|
387
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _lateNotes, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _lateNotes) + count);
|
|
388
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners).emit();
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
_inputs = new WeakMap();
|
|
392
|
+
_outputs = new WeakMap();
|
|
393
|
+
_ports = new WeakMap();
|
|
394
|
+
_cleanups = new WeakMap();
|
|
395
|
+
_listeners = new WeakMap();
|
|
396
|
+
_onCleanupError = new WeakMap();
|
|
397
|
+
_state = new WeakMap();
|
|
398
|
+
_error = new WeakMap();
|
|
399
|
+
_lateNotes = new WeakMap();
|
|
400
|
+
_ProcessorModule_instances = new WeakSet();
|
|
401
|
+
report_fn = function(error) {
|
|
402
|
+
var _a;
|
|
403
|
+
try {
|
|
404
|
+
(_a = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _onCleanupError)) == null ? void 0 : _a.call(this, error);
|
|
405
|
+
} catch (e3) {
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
function createProcessorModule(context, definition, options) {
|
|
409
|
+
const resolved = _chunkRZBLPM3Lcjs.resolveProcessorDefinition.call(void 0, definition);
|
|
410
|
+
if (typeof _optionalChain([options, 'optionalAccess', _31 => _31.id]) !== "string") throw new TypeError("Processor module needs an id.");
|
|
411
|
+
const route = _nullishCoalesce(options.route, () => ( "default"));
|
|
412
|
+
const sessionMode = _nullishCoalesce(options.session, () => ( "context"));
|
|
413
|
+
if (sessionMode !== "context" && sessionMode !== "none") throw new TypeError(`Unknown processor session mode: ${String(sessionMode)}`);
|
|
414
|
+
if (route !== "default" && route !== "none") throw new TypeError(`Unknown processor route: ${String(route)}`);
|
|
415
|
+
const audio = context.audio.peek();
|
|
416
|
+
if (!audio) throw new Error("Processor module needs a prepared audio context; prepare the environment and the processor first.");
|
|
417
|
+
if (!isProcessorPrepared(audio, resolved)) {
|
|
418
|
+
throw new Error(`Processor ${resolved.name} is not prepared in this audio context; await prepareProcessor first.`);
|
|
419
|
+
}
|
|
420
|
+
const initial = _nullishCoalesce(options.params, () => ( {}));
|
|
421
|
+
for (const key of Object.keys(initial)) {
|
|
422
|
+
if (!resolved.params.some((param) => param.id === key)) throw new TypeError(`Processor ${resolved.name} has no parameter ${key}.`);
|
|
423
|
+
}
|
|
424
|
+
const handles = [];
|
|
425
|
+
const cleanups = [];
|
|
426
|
+
const rollback = (error) => {
|
|
427
|
+
for (const cleanup of cleanups.splice(0).reverse()) {
|
|
428
|
+
try {
|
|
429
|
+
cleanup();
|
|
430
|
+
} catch (e4) {
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
throw error;
|
|
434
|
+
};
|
|
435
|
+
try {
|
|
436
|
+
for (const descriptor of resolved.params) {
|
|
437
|
+
const handle = new (0, _chunk5AHVQXTFcjs.ParamHandle)(descriptor, { baseValue: initial[descriptor.id] });
|
|
438
|
+
handles.push(handle);
|
|
439
|
+
cleanups.push(() => handle.dispose());
|
|
440
|
+
}
|
|
441
|
+
const node = createProcessorNode(audio, resolved, {
|
|
442
|
+
config: options.config,
|
|
443
|
+
createNode: options.createNode,
|
|
444
|
+
baseValues: Object.fromEntries(handles.map((handle) => [handle.descriptor.id, handle.snapshot.baseValue]))
|
|
445
|
+
});
|
|
446
|
+
cleanups.push(() => node.disconnect());
|
|
447
|
+
const owner = {};
|
|
448
|
+
cleanups.push(listenToProcessor(node, {
|
|
449
|
+
fail: (message) => _optionalChain([owner, 'access', _32 => _32.module, 'optionalAccess', _33 => _33.fail, 'call', _34 => _34(message)]),
|
|
450
|
+
late: (count) => _optionalChain([owner, 'access', _35 => _35.module, 'optionalAccess', _36 => _36.late, 'call', _37 => _37(count)]),
|
|
451
|
+
data: options.onReport,
|
|
452
|
+
report: options.onCleanupError
|
|
453
|
+
}));
|
|
454
|
+
bindProcessorParams(audio, node, resolved, handles, cleanups);
|
|
455
|
+
const latencySeconds = resolved.latencySamples / audio.sampleRate;
|
|
456
|
+
const inputs = resolved.audioInputs.map((port, index) => {
|
|
457
|
+
const entry = audio.createGain();
|
|
458
|
+
entry.channelCount = port.channels;
|
|
459
|
+
entry.channelCountMode = "explicit";
|
|
460
|
+
entry.channelInterpretation = "speakers";
|
|
461
|
+
entry.connect(node, 0, index);
|
|
462
|
+
cleanups.push(() => entry.disconnect());
|
|
463
|
+
const input = new (0, _chunkOCKAHITLcjs.AudioInputPort)(entry, { id: port.id, latencySeconds });
|
|
464
|
+
cleanups.push(() => input.dispose());
|
|
465
|
+
return input;
|
|
466
|
+
});
|
|
467
|
+
const outputs = resolved.audioOutputs.map((port, index) => {
|
|
468
|
+
const exit = audio.createGain();
|
|
469
|
+
node.connect(exit, index, 0);
|
|
470
|
+
cleanups.push(() => exit.disconnect());
|
|
471
|
+
const output = new (0, _chunkOCKAHITLcjs.AudioOutputPort)(exit, { id: port.id, onCleanupError: options.onCleanupError });
|
|
472
|
+
cleanups.push(() => output.dispose());
|
|
473
|
+
return output;
|
|
474
|
+
});
|
|
475
|
+
let notes;
|
|
476
|
+
let bridge;
|
|
477
|
+
if (resolved.noteInput) {
|
|
478
|
+
const created2 = new ProcessorNoteBridge(node, audio.sampleRate, _nullishCoalesce(options.noteTime, () => ( defaultProcessorNoteTime)), resolved.name);
|
|
479
|
+
bridge = created2;
|
|
480
|
+
cleanups.push(() => created2.close());
|
|
481
|
+
const port = new (0, _chunkK7FYH6UGcjs.NoteInputPort)(created2, { id: "notes" });
|
|
482
|
+
cleanups.push(() => port.dispose());
|
|
483
|
+
notes = port;
|
|
484
|
+
}
|
|
485
|
+
const binding = sessionMode === "context" && (resolved.noteInput || resolved.transport) ? _optionalChain([context, 'access', _38 => _38.session, 'optionalAccess', _39 => _39.scheduling]) : void 0;
|
|
486
|
+
if (binding) cleanups.push(followSession(binding, node, audio, resolved, bridge));
|
|
487
|
+
const params = new (0, _chunk5AHVQXTFcjs.ParamSurface)(handles);
|
|
488
|
+
const created = new ProcessorModule({
|
|
489
|
+
id: options.id,
|
|
490
|
+
definition: resolved,
|
|
491
|
+
node,
|
|
492
|
+
params,
|
|
493
|
+
latencySeconds,
|
|
494
|
+
inputs,
|
|
495
|
+
outputs,
|
|
496
|
+
control: handles.length ? _chunkOCKAHITLcjs.createControlPort.call(void 0, params) : void 0,
|
|
497
|
+
notes,
|
|
498
|
+
cleanups,
|
|
499
|
+
onCleanupError: options.onCleanupError
|
|
500
|
+
});
|
|
501
|
+
owner.module = created;
|
|
502
|
+
const registration = context.registry.register(created);
|
|
503
|
+
cleanups.push(() => registration.release());
|
|
504
|
+
if (route === "default") {
|
|
505
|
+
const lease = _chunkOCKAHITLcjs.routeModuleOutput.call(void 0, context, created, outputs[0]);
|
|
506
|
+
cleanups.push(() => lease.release());
|
|
507
|
+
}
|
|
508
|
+
return created;
|
|
509
|
+
} catch (error) {
|
|
510
|
+
return rollback(error);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
// src/processor/effect.ts
|
|
515
|
+
function processorEffect(definition, options = {}) {
|
|
516
|
+
const resolved = _chunkRZBLPM3Lcjs.resolveProcessorDefinition.call(void 0, definition);
|
|
517
|
+
if (resolved.audioInputs.length === 0) throw new TypeError(`Processor ${resolved.name} has no audio input, so it cannot be an insert effect.`);
|
|
518
|
+
if (resolved.noteInput) throw new TypeError(`Processor ${resolved.name} requests note input, which an insert cannot carry; use createProcessorModule.`);
|
|
519
|
+
if (resolved.transport) throw new TypeError(`Processor ${resolved.name} requests transport, which an insert cannot carry; use createProcessorModule.`);
|
|
520
|
+
const parameterDescriptors = Object.freeze(Object.fromEntries(resolved.params.map(({ id, ...descriptor }) => [id, Object.freeze({ ...descriptor, modulation: _nullishCoalesce(descriptor.modulation, () => ( "none")) })])));
|
|
521
|
+
const baseValues = Object.freeze(Object.fromEntries(resolved.params.map((param) => [param.id, param.defaultValue])));
|
|
522
|
+
return Object.freeze({
|
|
523
|
+
label: _nullishCoalesce(options.label, () => ( resolved.id)),
|
|
524
|
+
parameterDescriptors,
|
|
525
|
+
createAudioNodes(context) {
|
|
526
|
+
if (!isProcessorPrepared(context, resolved)) {
|
|
527
|
+
throw new Error(`Processor ${resolved.name} is not prepared in this audio context; await prepareProcessor first.`);
|
|
528
|
+
}
|
|
529
|
+
const node = createProcessorNode(context, resolved, {
|
|
530
|
+
config: options.config,
|
|
531
|
+
createNode: options.createNode,
|
|
532
|
+
baseValues,
|
|
533
|
+
inputChannels: resolved.audioInputs[0].channels,
|
|
534
|
+
// No owner could read an insert's ring, so it gets none.
|
|
535
|
+
ring: false
|
|
536
|
+
});
|
|
537
|
+
let stop;
|
|
538
|
+
try {
|
|
539
|
+
let failed = false;
|
|
540
|
+
stop = listenToProcessor(node, {
|
|
541
|
+
fail: (message) => {
|
|
542
|
+
if (failed) return;
|
|
543
|
+
failed = true;
|
|
544
|
+
_optionalChain([options, 'access', _40 => _40.onError, 'optionalCall', _41 => _41(message)]);
|
|
545
|
+
},
|
|
546
|
+
data: options.onReport
|
|
547
|
+
});
|
|
548
|
+
const params = Object.fromEntries(resolved.params.map((param) => [param.id, processorParam(node, resolved, param.id)]));
|
|
549
|
+
let disposed = false;
|
|
550
|
+
return {
|
|
551
|
+
input: node,
|
|
552
|
+
output: node,
|
|
553
|
+
params,
|
|
554
|
+
dispose() {
|
|
555
|
+
if (disposed) return;
|
|
556
|
+
disposed = true;
|
|
557
|
+
let failure;
|
|
558
|
+
try {
|
|
559
|
+
node.disconnect();
|
|
560
|
+
} catch (error) {
|
|
561
|
+
failure = error;
|
|
562
|
+
}
|
|
563
|
+
try {
|
|
564
|
+
_optionalChain([stop, 'optionalCall', _42 => _42()]);
|
|
565
|
+
} catch (error) {
|
|
566
|
+
_nullishCoalesce(failure, () => ( (failure = error)));
|
|
567
|
+
}
|
|
568
|
+
if (failure !== void 0) throw failure;
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
} catch (error) {
|
|
572
|
+
try {
|
|
573
|
+
_optionalChain([stop, 'optionalCall', _43 => _43()]);
|
|
574
|
+
} catch (e5) {
|
|
575
|
+
}
|
|
576
|
+
try {
|
|
577
|
+
node.disconnect();
|
|
578
|
+
} catch (e6) {
|
|
579
|
+
}
|
|
580
|
+
throw error;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
// src/processor/instrument.ts
|
|
587
|
+
var _audio, _cleanups2, _next2, _state2, _error2, _lateNotes2, _ProcessorInstrument_instances, post_fn2;
|
|
588
|
+
var ProcessorInstrument = class {
|
|
589
|
+
/** @internal Use {@link createProcessorInstrument}. */
|
|
590
|
+
constructor(parts) {
|
|
591
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _ProcessorInstrument_instances);
|
|
592
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _audio);
|
|
593
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _cleanups2);
|
|
594
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _next2, 1);
|
|
595
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _state2, "ready");
|
|
596
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _error2);
|
|
597
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _lateNotes2, 0);
|
|
598
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _audio, parts.audio);
|
|
599
|
+
this.definition = parts.definition;
|
|
600
|
+
this.node = parts.node;
|
|
601
|
+
this.params = parts.params;
|
|
602
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _cleanups2, parts.cleanups);
|
|
603
|
+
}
|
|
604
|
+
/** The reader side of the node's shared ring; absent unless the definition requests one and memory can be shared. */
|
|
605
|
+
get ring() {
|
|
606
|
+
return processorRingOf(this.node);
|
|
607
|
+
}
|
|
608
|
+
get state() {
|
|
609
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _state2);
|
|
610
|
+
}
|
|
611
|
+
get error() {
|
|
612
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _error2);
|
|
613
|
+
}
|
|
614
|
+
/** Note changes played after their frame, as reported so far. */
|
|
615
|
+
get lateNotes() {
|
|
616
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _lateNotes2);
|
|
617
|
+
}
|
|
618
|
+
/** Start a note at `time` (AudioContext seconds) and return its occurrence. */
|
|
619
|
+
start(midi, velocity, time, cents = 0) {
|
|
620
|
+
if (!Number.isFinite(midi) || midi < 0 || midi > 127) throw new RangeError("midi must be within 0\u2013127");
|
|
621
|
+
if (!Number.isFinite(velocity) || velocity < 0 || velocity > 1) throw new RangeError("velocity must be within 0\u20131");
|
|
622
|
+
if (!Number.isFinite(cents)) throw new RangeError("cents must be finite");
|
|
623
|
+
const occurrence = _chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _next2)._++;
|
|
624
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ProcessorInstrument_instances, post_fn2).call(this, "on", occurrence, time, midi, cents, velocity);
|
|
625
|
+
return occurrence;
|
|
626
|
+
}
|
|
627
|
+
/** Release `occurrence` at `time`, replacing a release still queued. */
|
|
628
|
+
release(occurrence, time) {
|
|
629
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ProcessorInstrument_instances, post_fn2).call(this, "off", occurrence, time);
|
|
630
|
+
}
|
|
631
|
+
/** Stop `occurrence` at `time` without a release phase; before its onset, it never sounds. */
|
|
632
|
+
cancel(occurrence, time) {
|
|
633
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ProcessorInstrument_instances, post_fn2).call(this, "cancel", occurrence, time);
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* Stop the processor and release its node and parameter bindings, in
|
|
637
|
+
* reverse order of acquisition. Continues after an individual failure,
|
|
638
|
+
* rethrows the first, and is safe to repeat. The audio context stays open.
|
|
639
|
+
*/
|
|
640
|
+
dispose() {
|
|
641
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _state2) === "detached") return;
|
|
642
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _state2, "detached");
|
|
643
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _error2, void 0);
|
|
644
|
+
let failure;
|
|
645
|
+
for (const cleanup of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _cleanups2).splice(0).reverse()) {
|
|
646
|
+
try {
|
|
647
|
+
cleanup();
|
|
648
|
+
} catch (error) {
|
|
649
|
+
_nullishCoalesce(failure, () => ( (failure = error)));
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
if (failure !== void 0) throw failure;
|
|
653
|
+
}
|
|
654
|
+
/** @internal */
|
|
655
|
+
fail(message) {
|
|
656
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _state2) !== "ready") return false;
|
|
657
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _state2, "error");
|
|
658
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _error2, message);
|
|
659
|
+
return true;
|
|
660
|
+
}
|
|
661
|
+
/** @internal */
|
|
662
|
+
late(count) {
|
|
663
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _state2) === "detached" || count <= 0) return false;
|
|
664
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _lateNotes2, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _lateNotes2) + count);
|
|
665
|
+
return true;
|
|
666
|
+
}
|
|
667
|
+
};
|
|
668
|
+
_audio = new WeakMap();
|
|
669
|
+
_cleanups2 = new WeakMap();
|
|
670
|
+
_next2 = new WeakMap();
|
|
671
|
+
_state2 = new WeakMap();
|
|
672
|
+
_error2 = new WeakMap();
|
|
673
|
+
_lateNotes2 = new WeakMap();
|
|
674
|
+
_ProcessorInstrument_instances = new WeakSet();
|
|
675
|
+
post_fn2 = function(gate, occurrence, time, midi = 0, cents = 0, velocity = 0) {
|
|
676
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _state2) === "detached") throw new Error("Processor instrument is disposed.");
|
|
677
|
+
if (!Number.isInteger(occurrence) || occurrence < 1) throw new TypeError("occurrence must be one returned by start()");
|
|
678
|
+
if (!Number.isFinite(time)) throw new RangeError("time must be finite");
|
|
679
|
+
const audio = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _audio);
|
|
680
|
+
const message = {
|
|
681
|
+
type: "note",
|
|
682
|
+
gate,
|
|
683
|
+
occurrence,
|
|
684
|
+
midi,
|
|
685
|
+
cents,
|
|
686
|
+
velocity,
|
|
687
|
+
epoch: 0,
|
|
688
|
+
frame: time <= audio.currentTime ? _chunkRZBLPM3Lcjs.PROCESSOR_IMMEDIATE_FRAME : Math.round(time * audio.sampleRate)
|
|
689
|
+
};
|
|
690
|
+
this.node.port.postMessage(message);
|
|
691
|
+
};
|
|
692
|
+
function createProcessorInstrument(audio, definition, options = {}) {
|
|
693
|
+
const resolved = _chunkRZBLPM3Lcjs.resolveProcessorDefinition.call(void 0, definition);
|
|
694
|
+
if (!resolved.noteInput) throw new TypeError(`Processor ${resolved.name} has no note input, so it cannot be an instrument.`);
|
|
695
|
+
if (!isProcessorPrepared(audio, resolved)) {
|
|
696
|
+
throw new Error(`Processor ${resolved.name} is not prepared in this audio context; await prepareProcessor first.`);
|
|
697
|
+
}
|
|
698
|
+
const borrowed = options.params;
|
|
699
|
+
const handles = [];
|
|
700
|
+
const cleanups = [];
|
|
701
|
+
if (borrowed) {
|
|
702
|
+
for (const descriptor of resolved.params) {
|
|
703
|
+
const handle = borrowed.get(descriptor.id);
|
|
704
|
+
if (!handle) throw new TypeError(`Processor ${resolved.name} parameter ${descriptor.id} has no handle in params.`);
|
|
705
|
+
if ((_nullishCoalesce(handle.descriptor.modulation, () => ( "none"))) !== (_nullishCoalesce(descriptor.modulation, () => ( "none")))) {
|
|
706
|
+
throw new TypeError(`Processor ${resolved.name} parameter ${descriptor.id} needs a handle with ${_nullishCoalesce(descriptor.modulation, () => ( "no"))} modulation.`);
|
|
707
|
+
}
|
|
708
|
+
handles.push(handle);
|
|
709
|
+
}
|
|
710
|
+
} else {
|
|
711
|
+
const values = _nullishCoalesce(options.values, () => ( {}));
|
|
712
|
+
for (const key of Object.keys(values)) {
|
|
713
|
+
if (!resolved.params.some((param) => param.id === key)) throw new TypeError(`Processor ${resolved.name} has no parameter ${key}.`);
|
|
714
|
+
}
|
|
715
|
+
for (const descriptor of resolved.params) {
|
|
716
|
+
const handle = new (0, _chunk5AHVQXTFcjs.ParamHandle)(descriptor, { baseValue: values[descriptor.id] });
|
|
717
|
+
handles.push(handle);
|
|
718
|
+
cleanups.push(() => handle.dispose());
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
try {
|
|
722
|
+
const node = createProcessorNode(audio, resolved, {
|
|
723
|
+
config: options.config,
|
|
724
|
+
createNode: options.createNode,
|
|
725
|
+
baseValues: Object.fromEntries(handles.map((handle) => [handle.descriptor.id, handle.snapshot.baseValue]))
|
|
726
|
+
});
|
|
727
|
+
cleanups.push(() => node.disconnect());
|
|
728
|
+
const owner = {};
|
|
729
|
+
cleanups.push(listenToProcessor(node, {
|
|
730
|
+
fail: (message) => {
|
|
731
|
+
if (_optionalChain([owner, 'access', _44 => _44.instrument, 'optionalAccess', _45 => _45.fail, 'call', _46 => _46(message)])) _optionalChain([options, 'access', _47 => _47.onError, 'optionalCall', _48 => _48(message)]);
|
|
732
|
+
},
|
|
733
|
+
late: (count) => {
|
|
734
|
+
if (_optionalChain([owner, 'access', _49 => _49.instrument, 'optionalAccess', _50 => _50.late, 'call', _51 => _51(count)])) _optionalChain([options, 'access', _52 => _52.onLateNotes, 'optionalCall', _53 => _53(count)]);
|
|
735
|
+
},
|
|
736
|
+
data: options.onReport
|
|
737
|
+
}));
|
|
738
|
+
bindProcessorParams(audio, node, resolved, handles, cleanups);
|
|
739
|
+
const instrument = new ProcessorInstrument({
|
|
740
|
+
audio,
|
|
741
|
+
definition: resolved,
|
|
742
|
+
node,
|
|
743
|
+
cleanups,
|
|
744
|
+
params: _nullishCoalesce(borrowed, () => ( new (0, _chunk5AHVQXTFcjs.ParamSurface)(handles)))
|
|
745
|
+
});
|
|
746
|
+
owner.instrument = instrument;
|
|
747
|
+
return instrument;
|
|
748
|
+
} catch (error) {
|
|
749
|
+
for (const cleanup of cleanups.splice(0).reverse()) {
|
|
750
|
+
try {
|
|
751
|
+
cleanup();
|
|
752
|
+
} catch (e7) {
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
throw error;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
// src/processor/plugin.ts
|
|
760
|
+
function processorPlugin(definition, options = {}) {
|
|
761
|
+
const resolved = _chunkRZBLPM3Lcjs.resolveProcessorDefinition.call(void 0, definition);
|
|
762
|
+
const ports = Object.freeze([
|
|
763
|
+
...resolved.audioInputs.map((port) => Object.freeze({ id: port.id, kind: "audio", direction: "input" })),
|
|
764
|
+
...resolved.noteInput ? [Object.freeze({ id: "notes", kind: "note", direction: "input" })] : [],
|
|
765
|
+
...resolved.audioOutputs.map((port) => Object.freeze({ id: port.id, kind: "audio", direction: "output" }))
|
|
766
|
+
]);
|
|
767
|
+
return Object.freeze({
|
|
768
|
+
id: resolved.id,
|
|
769
|
+
version: resolved.version,
|
|
770
|
+
async create({ record, context, signal }) {
|
|
771
|
+
const audio = context.audio.prepare();
|
|
772
|
+
if (!isProcessorPrepared(audio, resolved)) {
|
|
773
|
+
if (!options.source) {
|
|
774
|
+
throw new (0, _chunkI4YMA5VMcjs.ProjectModuleUnavailableError)(`Processor ${resolved.name} is not prepared in this audio context and the plugin has no source.`);
|
|
775
|
+
}
|
|
776
|
+
try {
|
|
777
|
+
await prepareProcessor(audio, resolved, options.source);
|
|
778
|
+
} catch (error) {
|
|
779
|
+
if (signal.aborted) throw error;
|
|
780
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
781
|
+
throw new (0, _chunkI4YMA5VMcjs.ProjectModuleUnavailableError)(`Processor ${resolved.name} could not be prepared: ${reason}`, { cause: error });
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
if (signal.aborted) throw _nullishCoalesce(signal.reason, () => ( new Error("Project restoration was aborted.")));
|
|
785
|
+
const module = createProcessorModule(context, resolved, {
|
|
786
|
+
id: record.id,
|
|
787
|
+
config: record.config,
|
|
788
|
+
createNode: options.createNode,
|
|
789
|
+
onReport: options.onReport ? (data) => options.onReport(record.id, data) : void 0
|
|
790
|
+
});
|
|
791
|
+
return {
|
|
792
|
+
module,
|
|
793
|
+
ports,
|
|
794
|
+
getInput: (name) => _optionalChain([module, 'access', _54 => _54.getInput, 'call', _55 => _55(name), 'optionalAccess', _56 => _56.node]),
|
|
795
|
+
dispose: () => module.dispose()
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
exports.ProcessorUnavailableError = ProcessorUnavailableError; exports.prepareProcessor = prepareProcessor; exports.isProcessorPrepared = isProcessorPrepared; exports.defaultProcessorNoteTime = defaultProcessorNoteTime; exports.ProcessorModule = ProcessorModule; exports.createProcessorModule = createProcessorModule; exports.processorEffect = processorEffect; exports.ProcessorInstrument = ProcessorInstrument; exports.createProcessorInstrument = createProcessorInstrument; exports.processorPlugin = processorPlugin;
|
|
813
|
+
//# sourceMappingURL=chunk-JLVSAZ3K.cjs.map
|