@webmusic/kernel 0.1.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 +138 -101
- 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-HOKRTYPV.js → chunk-OPBHDUZK.js} +39 -1
- package/dist/chunk-OPBHDUZK.js.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-HZQX4J2J.cjs → chunk-WOPW6WLR.cjs} +40 -2
- package/dist/chunk-WOPW6WLR.cjs.map +1 -0
- 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 +556 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -5
- package/dist/index.d.ts +17 -5
- package/dist/index.js +567 -20
- 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 +2 -2
- package/dist/meter.cjs.map +1 -1
- package/dist/meter.d.cts +9 -1
- package/dist/meter.d.ts +9 -1
- package/dist/meter.js +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 +62 -11
- package/dist/chunk-53YD73OY.js +0 -162
- package/dist/chunk-53YD73OY.js.map +0 -1
- package/dist/chunk-BR63OD53.cjs +0 -1
- package/dist/chunk-BR63OD53.cjs.map +0 -1
- package/dist/chunk-HOKRTYPV.js.map +0 -1
- package/dist/chunk-HZQX4J2J.cjs.map +0 -1
- package/dist/chunk-JNXB74G3.cjs +0 -987
- package/dist/chunk-JNXB74G3.cjs.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/chunk-XBJBY4J5.js +0 -987
- package/dist/chunk-XBJBY4J5.js.map +0 -1
- package/dist/sync.cjs +0 -12
- package/dist/sync.cjs.map +0 -1
- package/dist/sync.d.cts +0 -304
- package/dist/sync.d.ts +0 -304
- 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,620 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createConnectionLease
|
|
3
|
+
} from "./chunk-QLF3BOST.js";
|
|
4
|
+
|
|
5
|
+
// src/module/param-audio.ts
|
|
6
|
+
var targetBuses = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
function valueAt(events, baseline, startTime, time) {
|
|
8
|
+
let previous = baseline, previousTime = startTime;
|
|
9
|
+
for (const event of events) {
|
|
10
|
+
if (time < event.time) {
|
|
11
|
+
if (event.type === "set" || time <= previousTime) return previous;
|
|
12
|
+
const ratio = (time - previousTime) / (event.time - previousTime);
|
|
13
|
+
return event.type === "linear" ? previous + (event.value - previous) * ratio : previous * Math.pow(event.value / previous, ratio);
|
|
14
|
+
}
|
|
15
|
+
previous = event.value;
|
|
16
|
+
previousTime = event.time;
|
|
17
|
+
}
|
|
18
|
+
return previous;
|
|
19
|
+
}
|
|
20
|
+
var ParamAudioBus = class {
|
|
21
|
+
constructor(context, baseValue, rate, changed = () => {
|
|
22
|
+
}) {
|
|
23
|
+
this.changed = changed;
|
|
24
|
+
this.bindings = /* @__PURE__ */ new Map();
|
|
25
|
+
this.connections = /* @__PURE__ */ new Set();
|
|
26
|
+
this.events = Object.freeze([]);
|
|
27
|
+
this.startTime = 0;
|
|
28
|
+
this.disposed = false;
|
|
29
|
+
this.changing = false;
|
|
30
|
+
this.context = context;
|
|
31
|
+
this.rate = rate;
|
|
32
|
+
this.baseline = baseValue;
|
|
33
|
+
this.source = context.createConstantSource();
|
|
34
|
+
this.validateOffset(baseValue);
|
|
35
|
+
this.source.offset.value = baseValue;
|
|
36
|
+
if ("automationRate" in this.source.offset) this.source.offset.automationRate = rate;
|
|
37
|
+
try {
|
|
38
|
+
this.source.start();
|
|
39
|
+
} catch (error) {
|
|
40
|
+
this.source.disconnect();
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
get active() {
|
|
45
|
+
return !this.disposed;
|
|
46
|
+
}
|
|
47
|
+
get automation() {
|
|
48
|
+
return this.events;
|
|
49
|
+
}
|
|
50
|
+
get mappings() {
|
|
51
|
+
return Object.freeze([...this.connections]);
|
|
52
|
+
}
|
|
53
|
+
get estimatedRange() {
|
|
54
|
+
let min = this.baseValueAt(this.context.currentTime), max = min;
|
|
55
|
+
for (const mapping of this.connections) {
|
|
56
|
+
const low = mapping.polarity === "bipolar" ? -mapping.depth : 0;
|
|
57
|
+
min += Math.min(low, mapping.depth);
|
|
58
|
+
max += Math.max(low, mapping.depth);
|
|
59
|
+
}
|
|
60
|
+
return Object.freeze({ min, max });
|
|
61
|
+
}
|
|
62
|
+
/** Exact model of this bus's scheduled base; not a sample of effective CV. */
|
|
63
|
+
baseValueAt(time) {
|
|
64
|
+
return valueAt(this.events, this.baseline, this.startTime, time);
|
|
65
|
+
}
|
|
66
|
+
bind(param) {
|
|
67
|
+
this.assertLive();
|
|
68
|
+
if (this.changing) throw new Error("CV bus changes cannot re-enter.");
|
|
69
|
+
const existing = targetBuses.get(param);
|
|
70
|
+
if (existing && existing !== this) throw new Error("AudioParam already belongs to another CV bus.");
|
|
71
|
+
if ("automationRate" in param && param.automationRate !== this.rate) {
|
|
72
|
+
throw new Error(`Parameter requires ${this.rate}; native AudioParam declares ${param.automationRate}.`);
|
|
73
|
+
}
|
|
74
|
+
let entry = this.bindings.get(param);
|
|
75
|
+
if (!entry) {
|
|
76
|
+
this.changing = true;
|
|
77
|
+
const original = param.value;
|
|
78
|
+
let compensation;
|
|
79
|
+
try {
|
|
80
|
+
this.source.connect(param);
|
|
81
|
+
if (this.disposed) throw new Error("CV bus disposed while binding.");
|
|
82
|
+
param.cancelScheduledValues(this.context.currentTime);
|
|
83
|
+
param.value = 0;
|
|
84
|
+
if (param.value !== 0) {
|
|
85
|
+
compensation = this.context.createConstantSource();
|
|
86
|
+
compensation.offset.value = -param.value;
|
|
87
|
+
compensation.connect(param);
|
|
88
|
+
compensation.start();
|
|
89
|
+
}
|
|
90
|
+
if (this.disposed) throw new Error("CV bus disposed while binding.");
|
|
91
|
+
entry = { leases: /* @__PURE__ */ new Set(), compensation };
|
|
92
|
+
this.bindings.set(param, entry);
|
|
93
|
+
targetBuses.set(param, this);
|
|
94
|
+
} catch (error) {
|
|
95
|
+
if (compensation) {
|
|
96
|
+
try {
|
|
97
|
+
compensation.disconnect();
|
|
98
|
+
} catch {
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
compensation.stop();
|
|
102
|
+
} catch {
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
this.source.disconnect(param);
|
|
107
|
+
} catch {
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
param.value = original;
|
|
111
|
+
} catch {
|
|
112
|
+
}
|
|
113
|
+
throw error;
|
|
114
|
+
} finally {
|
|
115
|
+
this.changing = false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const owned = entry;
|
|
119
|
+
const lease = createConnectionLease(() => {
|
|
120
|
+
owned.leases.delete(lease);
|
|
121
|
+
if (owned.leases.size || this.bindings.get(param) !== owned) return;
|
|
122
|
+
this.bindings.delete(param);
|
|
123
|
+
if (targetBuses.get(param) === this) targetBuses.delete(param);
|
|
124
|
+
let failure;
|
|
125
|
+
try {
|
|
126
|
+
this.source.disconnect(param);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
failure = error;
|
|
129
|
+
}
|
|
130
|
+
if (owned.compensation) {
|
|
131
|
+
try {
|
|
132
|
+
owned.compensation.disconnect();
|
|
133
|
+
} catch (error) {
|
|
134
|
+
failure ?? (failure = error);
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
owned.compensation.stop();
|
|
138
|
+
} catch (error) {
|
|
139
|
+
failure ?? (failure = error);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
param.value = this.baseValueAt(this.context.currentTime);
|
|
144
|
+
} catch (error) {
|
|
145
|
+
failure ?? (failure = error);
|
|
146
|
+
}
|
|
147
|
+
if (failure) throw failure;
|
|
148
|
+
});
|
|
149
|
+
owned.leases.add(lease);
|
|
150
|
+
return lease;
|
|
151
|
+
}
|
|
152
|
+
connect(signal, options) {
|
|
153
|
+
this.assertLive();
|
|
154
|
+
if (this.changing) throw new Error("CV bus changes cannot re-enter.");
|
|
155
|
+
const { min, max } = signal.range;
|
|
156
|
+
if (!Number.isFinite(min) || !Number.isFinite(max) || min >= max) throw new RangeError("Control signal requires a finite nonempty range.");
|
|
157
|
+
if (signal.output.context !== this.context) throw new Error("Control signal and parameter must share an AudioContext.");
|
|
158
|
+
if (signal.rate !== "a-rate" && signal.rate !== "k-rate") throw new TypeError("Unknown control signal rate.");
|
|
159
|
+
if (this.rate === "a-rate" && signal.rate !== "a-rate") throw new Error("An a-rate parameter requires an a-rate control signal.");
|
|
160
|
+
if (!Number.isFinite(options.depth)) throw new RangeError("Modulation depth must be finite.");
|
|
161
|
+
const polarity = options.polarity ?? "bipolar";
|
|
162
|
+
if (polarity !== "bipolar" && polarity !== "unipolar") throw new TypeError("Unknown modulation polarity.");
|
|
163
|
+
let depth = options.depth;
|
|
164
|
+
let scale;
|
|
165
|
+
let offset;
|
|
166
|
+
const factor = polarity === "bipolar" ? 2 : 1;
|
|
167
|
+
const zero = polarity === "bipolar" ? -(max + min) / (max - min) : -min / (max - min);
|
|
168
|
+
this.changing = true;
|
|
169
|
+
try {
|
|
170
|
+
scale = this.context.createGain();
|
|
171
|
+
offset = this.context.createConstantSource();
|
|
172
|
+
this.assertLive();
|
|
173
|
+
scale.gain.value = depth * factor / (max - min);
|
|
174
|
+
offset.offset.value = depth * zero;
|
|
175
|
+
signal.output.connect(scale);
|
|
176
|
+
scale.connect(this.source.offset);
|
|
177
|
+
offset.connect(this.source.offset);
|
|
178
|
+
offset.start();
|
|
179
|
+
if (this.disposed) throw new Error("CV bus disposed during modulation connection.");
|
|
180
|
+
} catch (error) {
|
|
181
|
+
if (scale) {
|
|
182
|
+
try {
|
|
183
|
+
signal.output.disconnect(scale);
|
|
184
|
+
} catch {
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
scale?.disconnect();
|
|
189
|
+
} catch {
|
|
190
|
+
}
|
|
191
|
+
try {
|
|
192
|
+
offset?.disconnect();
|
|
193
|
+
} catch {
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
offset?.stop();
|
|
197
|
+
} catch {
|
|
198
|
+
}
|
|
199
|
+
throw error;
|
|
200
|
+
} finally {
|
|
201
|
+
this.changing = false;
|
|
202
|
+
}
|
|
203
|
+
const scaleNode = scale;
|
|
204
|
+
const offsetNode = offset;
|
|
205
|
+
const lease = createConnectionLease(() => {
|
|
206
|
+
this.connections.delete(mapping);
|
|
207
|
+
try {
|
|
208
|
+
signal.output.disconnect(scaleNode);
|
|
209
|
+
} catch {
|
|
210
|
+
}
|
|
211
|
+
let failure;
|
|
212
|
+
try {
|
|
213
|
+
scaleNode.disconnect();
|
|
214
|
+
} catch (error) {
|
|
215
|
+
failure = error;
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
offsetNode.disconnect();
|
|
219
|
+
} catch (error) {
|
|
220
|
+
failure ?? (failure = error);
|
|
221
|
+
}
|
|
222
|
+
try {
|
|
223
|
+
offsetNode.stop();
|
|
224
|
+
} catch (error) {
|
|
225
|
+
failure ?? (failure = error);
|
|
226
|
+
}
|
|
227
|
+
this.changed();
|
|
228
|
+
if (failure) throw failure;
|
|
229
|
+
});
|
|
230
|
+
const mapping = Object.freeze({
|
|
231
|
+
get active() {
|
|
232
|
+
return lease.active;
|
|
233
|
+
},
|
|
234
|
+
get depth() {
|
|
235
|
+
return depth;
|
|
236
|
+
},
|
|
237
|
+
polarity,
|
|
238
|
+
setDepth: (value) => {
|
|
239
|
+
this.assertLive();
|
|
240
|
+
if (!lease.active) throw new Error("Modulation mapping is released.");
|
|
241
|
+
if (!Number.isFinite(value)) throw new RangeError("Modulation depth must be finite.");
|
|
242
|
+
if (this.changing) throw new Error("CV bus changes cannot re-enter.");
|
|
243
|
+
this.changing = true;
|
|
244
|
+
try {
|
|
245
|
+
scaleNode.gain.value = value * factor / (max - min);
|
|
246
|
+
offsetNode.offset.value = value * zero;
|
|
247
|
+
this.assertLive();
|
|
248
|
+
if (!lease.active) throw new Error("Modulation mapping was released during update.");
|
|
249
|
+
} finally {
|
|
250
|
+
this.changing = false;
|
|
251
|
+
}
|
|
252
|
+
depth = value;
|
|
253
|
+
this.changed();
|
|
254
|
+
},
|
|
255
|
+
release: () => lease.release()
|
|
256
|
+
});
|
|
257
|
+
this.connections.add(mapping);
|
|
258
|
+
this.changed();
|
|
259
|
+
return mapping;
|
|
260
|
+
}
|
|
261
|
+
setBaseValue(value) {
|
|
262
|
+
this.assertLive();
|
|
263
|
+
this.validateOffset(value);
|
|
264
|
+
this.source.offset.cancelScheduledValues(this.context.currentTime);
|
|
265
|
+
this.source.offset.setValueAtTime(value, this.context.currentTime);
|
|
266
|
+
this.baseline = value;
|
|
267
|
+
this.startTime = this.context.currentTime;
|
|
268
|
+
this.events = Object.freeze([]);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Replaces base automation anchored at the modeled base at referenceTime.
|
|
272
|
+
* referenceTime is absolute seconds on this bus's AudioContext clock.
|
|
273
|
+
* Capture referenceTime before planning; it defaults to this call's audio time.
|
|
274
|
+
* Events must be ordered at or after that finite, nonnegative, nonfuture time.
|
|
275
|
+
* Elapsed portions are evaluated at submission, preserving future ramp endpoints.
|
|
276
|
+
* An empty schedule holds the current base instead.
|
|
277
|
+
* Native clock crossings receive bounded repair; prolonged stalls can underrun.
|
|
278
|
+
*/
|
|
279
|
+
schedule(events, referenceTime = this.context.currentTime) {
|
|
280
|
+
this.assertLive();
|
|
281
|
+
if (!Number.isFinite(referenceTime) || referenceTime < 0 || referenceTime > this.context.currentTime) {
|
|
282
|
+
throw new RangeError("Automation reference time must be finite, nonnegative and no later than the current audio time.");
|
|
283
|
+
}
|
|
284
|
+
const referenceBase = this.baseValueAt(referenceTime);
|
|
285
|
+
let time = referenceTime, value = referenceBase;
|
|
286
|
+
for (const event of events) {
|
|
287
|
+
if (!["set", "linear", "exponential"].includes(event.type)) throw new TypeError("Unknown automation event type.");
|
|
288
|
+
this.validateOffset(event.value);
|
|
289
|
+
if (!Number.isFinite(event.time) || event.time < time) throw new RangeError("Automation events require finite values and nondecreasing future times.");
|
|
290
|
+
if (event.type === "exponential" && (value <= 0 || event.value <= 0)) throw new RangeError("Exponential automation requires positive endpoints.");
|
|
291
|
+
time = event.time;
|
|
292
|
+
value = event.value;
|
|
293
|
+
}
|
|
294
|
+
const planned = Object.freeze(events.map((event) => Object.freeze({ ...event })));
|
|
295
|
+
let now = this.context.currentTime, base = referenceBase;
|
|
296
|
+
let candidate = planned;
|
|
297
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
298
|
+
base = planned.length ? now > referenceTime ? valueAt(planned, referenceBase, referenceTime, now) : referenceBase : this.baseValueAt(now);
|
|
299
|
+
candidate = planned.length && now > referenceTime ? Object.freeze([Object.freeze({ type: "set", value: base, time: now }), ...planned.filter((event) => event.time > now)]) : planned;
|
|
300
|
+
this.source.offset.cancelScheduledValues(now);
|
|
301
|
+
this.source.offset.setValueAtTime(base, now);
|
|
302
|
+
for (const event of candidate) {
|
|
303
|
+
if (event.type === "set") this.source.offset.setValueAtTime(event.value, event.time);
|
|
304
|
+
else if (event.type === "linear") this.source.offset.linearRampToValueAtTime(event.value, event.time);
|
|
305
|
+
else this.source.offset.exponentialRampToValueAtTime(event.value, event.time);
|
|
306
|
+
}
|
|
307
|
+
const submittedAt = this.context.currentTime;
|
|
308
|
+
if (submittedAt === now || attempt === 2) break;
|
|
309
|
+
now = submittedAt;
|
|
310
|
+
}
|
|
311
|
+
this.baseline = base;
|
|
312
|
+
this.startTime = now;
|
|
313
|
+
this.events = candidate;
|
|
314
|
+
this.changed();
|
|
315
|
+
}
|
|
316
|
+
dispose() {
|
|
317
|
+
if (this.disposed) return;
|
|
318
|
+
this.disposed = true;
|
|
319
|
+
let failure;
|
|
320
|
+
const attempt = (action) => {
|
|
321
|
+
try {
|
|
322
|
+
action();
|
|
323
|
+
} catch (error) {
|
|
324
|
+
failure ?? (failure = error);
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
for (const mapping of [...this.connections]) attempt(() => mapping.release());
|
|
328
|
+
for (const entry of [...this.bindings.values()]) for (const lease of [...entry.leases]) attempt(() => lease.release());
|
|
329
|
+
attempt(() => this.source.disconnect());
|
|
330
|
+
attempt(() => this.source.stop());
|
|
331
|
+
this.events = Object.freeze([]);
|
|
332
|
+
if (failure) throw failure;
|
|
333
|
+
}
|
|
334
|
+
validateOffset(value) {
|
|
335
|
+
const { minValue, maxValue } = this.source.offset;
|
|
336
|
+
if (!Number.isFinite(value) || value < minValue || value > maxValue) throw new RangeError("CV base exceeds the native ConstantSource range.");
|
|
337
|
+
}
|
|
338
|
+
assertLive() {
|
|
339
|
+
if (this.disposed) throw new Error("CV bus is disposed.");
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
// src/module/parameter.ts
|
|
344
|
+
var nativeOwners = /* @__PURE__ */ new WeakMap();
|
|
345
|
+
var unavailable = Object.freeze({ status: "unavailable" });
|
|
346
|
+
var ParamHandle = class {
|
|
347
|
+
constructor(descriptor, options = {}) {
|
|
348
|
+
this.applying = false;
|
|
349
|
+
this.releasingAudio = false;
|
|
350
|
+
this.preparingAudio = false;
|
|
351
|
+
this.bindingAudio = false;
|
|
352
|
+
this.audioTargets = /* @__PURE__ */ new Set();
|
|
353
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
354
|
+
const { min, max } = descriptor.range;
|
|
355
|
+
if (!descriptor.id || !descriptor.unit || !Number.isFinite(min) || !Number.isFinite(max) || min > max) {
|
|
356
|
+
throw new TypeError("A parameter requires an id, unit and finite ordered range.");
|
|
357
|
+
}
|
|
358
|
+
if (descriptor.step !== void 0 && (!Number.isFinite(descriptor.step) || descriptor.step <= 0)) {
|
|
359
|
+
throw new RangeError("Parameter step must be finite and positive.");
|
|
360
|
+
}
|
|
361
|
+
if (descriptor.scale === "logarithmic" && min <= 0) {
|
|
362
|
+
throw new RangeError("A logarithmic parameter requires a positive range.");
|
|
363
|
+
}
|
|
364
|
+
const displayRange = descriptor.displayRange;
|
|
365
|
+
if (displayRange && (!Number.isFinite(displayRange.min) || !Number.isFinite(displayRange.max) || displayRange.min > displayRange.max || displayRange.min < min || displayRange.max > max)) {
|
|
366
|
+
throw new RangeError("Parameter displayRange must be a finite ordered subset of its legal range.");
|
|
367
|
+
}
|
|
368
|
+
this.descriptor = Object.freeze({
|
|
369
|
+
...descriptor,
|
|
370
|
+
range: Object.freeze({ min, max }),
|
|
371
|
+
...displayRange && { displayRange: Object.freeze({ ...displayRange }) }
|
|
372
|
+
});
|
|
373
|
+
this.validate(descriptor.defaultValue);
|
|
374
|
+
const baseValue = options.baseValue ?? descriptor.defaultValue;
|
|
375
|
+
this.validate(baseValue);
|
|
376
|
+
this.apply = options.apply;
|
|
377
|
+
this.value = Object.freeze({ baseValue, revision: 0, baseRevision: 0, disposed: false, effectiveReadback: unavailable });
|
|
378
|
+
}
|
|
379
|
+
get snapshot() {
|
|
380
|
+
if (!this.bus?.active) return this.value;
|
|
381
|
+
return Object.freeze({
|
|
382
|
+
...this.value,
|
|
383
|
+
baseValue: this.bus.baseValueAt(this.bus.context.currentTime),
|
|
384
|
+
modulationRange: this.bus.estimatedRange,
|
|
385
|
+
automation: this.bus.automation
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
/** Lazily prepares one context's full-value CV bus. */
|
|
389
|
+
audio(context) {
|
|
390
|
+
this.assertAudio(context);
|
|
391
|
+
if (this.bus?.active) return this.bus;
|
|
392
|
+
const previousContext = this.audioContext;
|
|
393
|
+
let bus;
|
|
394
|
+
this.preparingAudio = true;
|
|
395
|
+
try {
|
|
396
|
+
bus = new ParamAudioBus(
|
|
397
|
+
context,
|
|
398
|
+
this.value.baseValue,
|
|
399
|
+
this.descriptor.modulation === "control-rate" ? "k-rate" : "a-rate",
|
|
400
|
+
() => this.audioChanged()
|
|
401
|
+
);
|
|
402
|
+
if (this.value.disposed) throw new Error("Parameter was disposed while preparing audio.");
|
|
403
|
+
this.bus = bus;
|
|
404
|
+
this.audioContext = context;
|
|
405
|
+
for (const target of this.audioTargets) target.binding = bus.bind(target.param);
|
|
406
|
+
if (this.value.disposed || !bus.active) throw new Error("Parameter was disposed while preparing audio.");
|
|
407
|
+
return bus;
|
|
408
|
+
} catch (error) {
|
|
409
|
+
this.bus = void 0;
|
|
410
|
+
this.audioContext = this.value.disposed ? void 0 : previousContext;
|
|
411
|
+
try {
|
|
412
|
+
bus?.dispose();
|
|
413
|
+
} catch {
|
|
414
|
+
}
|
|
415
|
+
throw error;
|
|
416
|
+
} finally {
|
|
417
|
+
this.preparingAudio = false;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
/** Borrow a native target; lazy bindings need no nodes until modulation starts. */
|
|
421
|
+
bindAudioParam(context, param, options = {}) {
|
|
422
|
+
this.assertAudio(context);
|
|
423
|
+
const owner = nativeOwners.get(param);
|
|
424
|
+
if (owner && owner !== this) throw new Error("AudioParam already belongs to another parameter handle.");
|
|
425
|
+
const rate = this.descriptor.modulation === "control-rate" ? "k-rate" : "a-rate";
|
|
426
|
+
if ("automationRate" in param && param.automationRate !== rate) throw new Error(`Parameter requires ${rate}; native AudioParam declares ${param.automationRate}.`);
|
|
427
|
+
const target = {
|
|
428
|
+
param,
|
|
429
|
+
lease: createConnectionLease(() => {
|
|
430
|
+
this.audioTargets.delete(target);
|
|
431
|
+
if (![...this.audioTargets].some((candidate) => candidate.param === param) && nativeOwners.get(param) === this) nativeOwners.delete(param);
|
|
432
|
+
target.binding?.release();
|
|
433
|
+
})
|
|
434
|
+
};
|
|
435
|
+
const bus = !options.lazy || this.bus?.active ? this.audio(context) : void 0;
|
|
436
|
+
this.bindingAudio = true;
|
|
437
|
+
try {
|
|
438
|
+
if (bus) target.binding = bus.bind(param);
|
|
439
|
+
else param.value = this.value.baseValue;
|
|
440
|
+
if (this.value.disposed || bus && !bus.active) throw new Error("Parameter was disposed while binding audio.");
|
|
441
|
+
this.audioContext = context;
|
|
442
|
+
this.audioTargets.add(target);
|
|
443
|
+
nativeOwners.set(param, this);
|
|
444
|
+
return target.lease;
|
|
445
|
+
} catch (error) {
|
|
446
|
+
try {
|
|
447
|
+
target.binding?.release();
|
|
448
|
+
} catch {
|
|
449
|
+
}
|
|
450
|
+
throw error;
|
|
451
|
+
} finally {
|
|
452
|
+
this.bindingAudio = false;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
connectModulation(signal, options) {
|
|
456
|
+
return this.audio(signal.output.context).connect(signal, options);
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Replaces base automation using a clock captured before planning the events.
|
|
460
|
+
* referenceTime is absolute AudioContext seconds and defaults to call entry;
|
|
461
|
+
* it must be finite, nonnegative and no
|
|
462
|
+
* later than context.currentTime. Events must be ordered at or after it.
|
|
463
|
+
* Clock advance during submission evaluates elapsed ramps and retains their
|
|
464
|
+
* future endpoints. An empty schedule holds the current modeled base.
|
|
465
|
+
* Native clock crossings receive bounded repair; prolonged stalls can underrun.
|
|
466
|
+
*/
|
|
467
|
+
scheduleAutomation(context, events, referenceTime = context.currentTime) {
|
|
468
|
+
if (this.descriptor.updateTiming !== "scheduled") throw new Error("Parameter does not support scheduled automation.");
|
|
469
|
+
this.assertAudio(context);
|
|
470
|
+
if (!Number.isFinite(referenceTime) || referenceTime < 0 || referenceTime > context.currentTime) {
|
|
471
|
+
throw new RangeError("Automation reference time must be finite, nonnegative and no later than the current audio time.");
|
|
472
|
+
}
|
|
473
|
+
let time = referenceTime;
|
|
474
|
+
let value = this.bus?.baseValueAt(referenceTime) ?? this.value.baseValue;
|
|
475
|
+
for (const event of events) {
|
|
476
|
+
this.validate(event.value);
|
|
477
|
+
if (!["set", "linear", "exponential"].includes(event.type)) throw new TypeError("Unknown automation event type.");
|
|
478
|
+
if (!Number.isFinite(event.time) || event.time < time) throw new RangeError("Automation events require nondecreasing finite future times.");
|
|
479
|
+
if (event.type === "exponential" && (value <= 0 || event.value <= 0)) throw new RangeError("Exponential automation requires positive endpoints.");
|
|
480
|
+
time = event.time;
|
|
481
|
+
value = event.value;
|
|
482
|
+
}
|
|
483
|
+
this.audio(context).schedule(events, referenceTime);
|
|
484
|
+
}
|
|
485
|
+
/** Cancels the future trajectory and holds its current modeled base. */
|
|
486
|
+
cancelAutomation() {
|
|
487
|
+
if (this.value.disposed) throw new Error("Parameter is disposed.");
|
|
488
|
+
if (!this.bus?.active || !this.bus.automation.length) return;
|
|
489
|
+
this.setBaseValue(this.bus.baseValueAt(this.bus.context.currentTime));
|
|
490
|
+
}
|
|
491
|
+
/** Dispose only this context's CV graph, keeping the shared parameter reusable. */
|
|
492
|
+
releaseAudio(context) {
|
|
493
|
+
if (this.audioContext !== context || this.releasingAudio) return;
|
|
494
|
+
this.releasingAudio = true;
|
|
495
|
+
const bus = this.bus;
|
|
496
|
+
const baseValue = bus?.baseValueAt(context.currentTime) ?? this.value.baseValue;
|
|
497
|
+
this.bus = void 0;
|
|
498
|
+
this.audioContext = void 0;
|
|
499
|
+
this.value = Object.freeze({ ...this.value, baseValue });
|
|
500
|
+
let failure;
|
|
501
|
+
for (const target of [...this.audioTargets]) {
|
|
502
|
+
try {
|
|
503
|
+
target.lease.release();
|
|
504
|
+
} catch (error) {
|
|
505
|
+
failure ?? (failure = error);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
try {
|
|
509
|
+
bus?.dispose();
|
|
510
|
+
} catch (error) {
|
|
511
|
+
failure ?? (failure = error);
|
|
512
|
+
}
|
|
513
|
+
this.releasingAudio = false;
|
|
514
|
+
this.audioChanged();
|
|
515
|
+
if (failure) throw failure;
|
|
516
|
+
}
|
|
517
|
+
setBaseValue(value) {
|
|
518
|
+
if (this.value.disposed) throw new Error("Parameter is disposed.");
|
|
519
|
+
if (this.applying) throw new Error("Parameter updates cannot re-enter a backend write.");
|
|
520
|
+
this.validate(value);
|
|
521
|
+
if (value === this.value.baseValue && !this.bus?.automation.length) return;
|
|
522
|
+
this.applying = true;
|
|
523
|
+
try {
|
|
524
|
+
const result = this.apply?.(value);
|
|
525
|
+
if (result != null && typeof result.then === "function") {
|
|
526
|
+
void Promise.resolve(result).catch(() => {
|
|
527
|
+
});
|
|
528
|
+
throw new TypeError("Parameter apply must be synchronous.");
|
|
529
|
+
}
|
|
530
|
+
if (this.value.disposed) throw new Error("Parameter was disposed during its backend write.");
|
|
531
|
+
if (this.bus?.active) this.bus.setBaseValue(value);
|
|
532
|
+
else for (const target of this.audioTargets) target.param.value = value;
|
|
533
|
+
if (this.value.disposed) throw new Error("Parameter was disposed during its backend write.");
|
|
534
|
+
this.value = Object.freeze({
|
|
535
|
+
...this.value,
|
|
536
|
+
baseValue: value,
|
|
537
|
+
revision: this.value.revision + 1,
|
|
538
|
+
baseRevision: this.value.baseRevision + 1
|
|
539
|
+
});
|
|
540
|
+
} finally {
|
|
541
|
+
this.applying = false;
|
|
542
|
+
}
|
|
543
|
+
this.notify();
|
|
544
|
+
}
|
|
545
|
+
subscribe(listener) {
|
|
546
|
+
if (this.value.disposed) return () => {
|
|
547
|
+
};
|
|
548
|
+
const subscription = { listener };
|
|
549
|
+
this.listeners.add(subscription);
|
|
550
|
+
return () => {
|
|
551
|
+
this.listeners.delete(subscription);
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
dispose() {
|
|
555
|
+
if (this.value.disposed) return;
|
|
556
|
+
this.value = Object.freeze({ ...this.value, disposed: true, revision: this.value.revision + 1 });
|
|
557
|
+
try {
|
|
558
|
+
if (this.audioContext) this.releaseAudio(this.audioContext);
|
|
559
|
+
} finally {
|
|
560
|
+
this.notify();
|
|
561
|
+
this.listeners.clear();
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
assertAudio(context) {
|
|
565
|
+
if (this.value.disposed) throw new Error("Parameter is disposed.");
|
|
566
|
+
if (this.applying || this.releasingAudio || this.preparingAudio || this.bindingAudio) throw new Error("Parameter audio cannot re-enter a backend write, preparation, binding or release.");
|
|
567
|
+
if (!this.descriptor.modulation || this.descriptor.modulation === "none") throw new Error("Parameter does not support native modulation.");
|
|
568
|
+
if (this.audioContext && this.audioContext !== context) throw new Error("Parameter is already attached to another AudioContext; release it explicitly first.");
|
|
569
|
+
}
|
|
570
|
+
audioChanged() {
|
|
571
|
+
if (this.value.disposed || this.releasingAudio) return;
|
|
572
|
+
this.value = Object.freeze({ ...this.value, revision: this.value.revision + 1 });
|
|
573
|
+
this.notify();
|
|
574
|
+
}
|
|
575
|
+
validate(value) {
|
|
576
|
+
if (!Number.isFinite(value) || value < this.descriptor.range.min || value > this.descriptor.range.max) {
|
|
577
|
+
throw new RangeError(`Parameter ${this.descriptor.id} requires a finite value in its declared range.`);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
notify() {
|
|
581
|
+
const value = this.value;
|
|
582
|
+
const snapshot = this.snapshot;
|
|
583
|
+
for (const subscription of [...this.listeners]) {
|
|
584
|
+
if (value !== this.value) break;
|
|
585
|
+
if (!this.listeners.has(subscription)) continue;
|
|
586
|
+
try {
|
|
587
|
+
const result = subscription.listener(snapshot);
|
|
588
|
+
if (result != null && typeof result.then === "function") {
|
|
589
|
+
void Promise.resolve(result).catch(() => {
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
} catch {
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
var ParamSurface = class {
|
|
598
|
+
constructor(handles) {
|
|
599
|
+
this.byId = /* @__PURE__ */ new Map();
|
|
600
|
+
const entries = [...handles];
|
|
601
|
+
for (const handle of entries) {
|
|
602
|
+
if (this.byId.has(handle.descriptor.id)) throw new Error(`Duplicate parameter id: ${handle.descriptor.id}`);
|
|
603
|
+
this.byId.set(handle.descriptor.id, handle);
|
|
604
|
+
}
|
|
605
|
+
this.handles = Object.freeze(entries);
|
|
606
|
+
}
|
|
607
|
+
get(id) {
|
|
608
|
+
return this.byId.get(id);
|
|
609
|
+
}
|
|
610
|
+
[Symbol.iterator]() {
|
|
611
|
+
return this.handles[Symbol.iterator]();
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
export {
|
|
616
|
+
ParamAudioBus,
|
|
617
|
+
ParamHandle,
|
|
618
|
+
ParamSurface
|
|
619
|
+
};
|
|
620
|
+
//# sourceMappingURL=chunk-DVN6E5U3.js.map
|