@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,4383 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } 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
|
+
|
|
9
|
+
var _chunkOCKAHITLcjs = require('./chunk-OCKAHITL.cjs');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var _chunkK7FYH6UGcjs = require('./chunk-K7FYH6UG.cjs');
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
var _chunkJFCBJMA7cjs = require('./chunk-JFCBJMA7.cjs');
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
var _chunkC3LMS36Lcjs = require('./chunk-C3LMS36L.cjs');
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
var _chunk5AHVQXTFcjs = require('./chunk-5AHVQXTF.cjs');
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
var _chunkXBSIYUHMcjs = require('./chunk-XBSIYUHM.cjs');
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
var _chunkWN5DZOVTcjs = require('./chunk-WN5DZOVT.cjs');
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
var _chunkCR6OUWBJcjs = require('./chunk-CR6OUWBJ.cjs');
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
var _chunkI4YMA5VMcjs = require('./chunk-I4YMA5VM.cjs');
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
var _chunkTA3TNJZUcjs = require('./chunk-TA3TNJZU.cjs');
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
var _chunkBADJJ6DVcjs = require('./chunk-BADJJ6DV.cjs');
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
var _chunkEXDCK2VLcjs = require('./chunk-EXDCK2VL.cjs');
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
var _chunk7ZTZZ5PNcjs = require('./chunk-7ZTZZ5PN.cjs');
|
|
77
|
+
|
|
78
|
+
// src/module/preset.ts
|
|
79
|
+
var _slots;
|
|
80
|
+
var PresetBank = class {
|
|
81
|
+
constructor(initial) {
|
|
82
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _slots, /* @__PURE__ */ new Map());
|
|
83
|
+
for (const [slot, values] of Object.entries(_nullishCoalesce(initial, () => ( {})))) this.store(Number(slot), values);
|
|
84
|
+
}
|
|
85
|
+
/** Stored slot numbers, ascending. */
|
|
86
|
+
get slots() {
|
|
87
|
+
return [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _slots).keys()].sort((a, b) => a - b);
|
|
88
|
+
}
|
|
89
|
+
has(slot) {
|
|
90
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _slots).has(slot);
|
|
91
|
+
}
|
|
92
|
+
store(slot, values) {
|
|
93
|
+
if (!Number.isInteger(slot) || slot < 1) throw new RangeError("A preset slot is a positive integer.");
|
|
94
|
+
const copy = {};
|
|
95
|
+
for (const [key, value] of Object.entries(values)) {
|
|
96
|
+
if (Array.isArray(value)) {
|
|
97
|
+
if (value.every(Number.isFinite)) copy[key] = Object.freeze([...value]);
|
|
98
|
+
} else if (Number.isFinite(value)) copy[key] = value;
|
|
99
|
+
}
|
|
100
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _slots).set(slot, Object.freeze(copy));
|
|
101
|
+
}
|
|
102
|
+
recall(slot) {
|
|
103
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _slots).get(slot);
|
|
104
|
+
}
|
|
105
|
+
clear(slot) {
|
|
106
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _slots).delete(slot);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Blend stored slots by weight. Weights are normalized; a key present in
|
|
110
|
+
* only some slots takes those slots' share. Numbers and arrays of equal
|
|
111
|
+
* length blend linearly; anything else takes the heaviest slot's value.
|
|
112
|
+
*/
|
|
113
|
+
interpolate(weights) {
|
|
114
|
+
const entries = Object.entries(weights).map(([slot, weight]) => [_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _slots).get(Number(slot)), Math.max(0, weight)]).filter((entry) => !!entry[0] && entry[1] > 0);
|
|
115
|
+
const result = {};
|
|
116
|
+
if (!entries.length) return result;
|
|
117
|
+
const keys = new Set(entries.flatMap(([values]) => Object.keys(values)));
|
|
118
|
+
for (const key of keys) {
|
|
119
|
+
const present = entries.filter(([values]) => values[key] !== void 0);
|
|
120
|
+
const total = present.reduce((sum, [, weight]) => sum + weight, 0);
|
|
121
|
+
const first = present[0][0][key];
|
|
122
|
+
if (typeof first === "number" && present.every(([values]) => typeof values[key] === "number")) {
|
|
123
|
+
result[key] = present.reduce((sum, [values, weight]) => sum + values[key] * weight, 0) / total;
|
|
124
|
+
} else if (Array.isArray(first) && present.every(([values]) => Array.isArray(values[key]) && values[key].length === first.length)) {
|
|
125
|
+
result[key] = first.map((_, index) => present.reduce((sum, [values, weight]) => sum + values[key][index] * weight, 0) / total);
|
|
126
|
+
} else {
|
|
127
|
+
result[key] = [...present].sort((a, b) => b[1] - a[1])[0][0][key];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
/** Blend two slots: `fraction` 0 is `from`, 1 is `to`. */
|
|
133
|
+
between(from, to, fraction) {
|
|
134
|
+
const amount = Math.min(1, Math.max(0, fraction));
|
|
135
|
+
return this.interpolate(from === to ? { [from]: 1 } : { [from]: 1 - amount, [to]: amount });
|
|
136
|
+
}
|
|
137
|
+
toJSON() {
|
|
138
|
+
return Object.fromEntries(this.slots.map((slot) => [String(slot), Object.fromEntries(Object.entries(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _slots).get(slot)).map(([key, value]) => [key, Array.isArray(value) ? [...value] : value]))]));
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
_slots = new WeakMap();
|
|
142
|
+
function captureParameters(modules) {
|
|
143
|
+
const values = {};
|
|
144
|
+
for (const module of modules) {
|
|
145
|
+
for (const handle of _nullishCoalesce(module.params, () => ( []))) {
|
|
146
|
+
if (!handle.snapshot.disposed) values[`${module.id}.${handle.descriptor.id}`] = handle.snapshot.baseValue;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return values;
|
|
150
|
+
}
|
|
151
|
+
function applyParameters(modules, values) {
|
|
152
|
+
let applied = 0;
|
|
153
|
+
for (const module of modules) {
|
|
154
|
+
for (const handle of _nullishCoalesce(module.params, () => ( []))) {
|
|
155
|
+
const value = values[`${module.id}.${handle.descriptor.id}`];
|
|
156
|
+
if (typeof value !== "number" || handle.snapshot.disposed) continue;
|
|
157
|
+
const { min, max } = handle.descriptor.range;
|
|
158
|
+
try {
|
|
159
|
+
handle.setBaseValue(Math.min(max, Math.max(min, value)));
|
|
160
|
+
applied++;
|
|
161
|
+
} catch (e) {
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return applied;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// src/module/mapping.ts
|
|
169
|
+
function controlFraction(event) {
|
|
170
|
+
switch (event.kind) {
|
|
171
|
+
case "cc":
|
|
172
|
+
case "program":
|
|
173
|
+
case "pressure":
|
|
174
|
+
return Math.min(1, Math.max(0, event.value / 127));
|
|
175
|
+
case "pitchbend":
|
|
176
|
+
return Math.min(1, Math.max(0, (event.value + 8192) / 16383));
|
|
177
|
+
case "key":
|
|
178
|
+
return event.down ? 1 : void 0;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function controlSource(event) {
|
|
182
|
+
switch (event.kind) {
|
|
183
|
+
case "cc":
|
|
184
|
+
return { kind: "cc", controller: event.controller, channel: event.channel };
|
|
185
|
+
case "pitchbend":
|
|
186
|
+
return { kind: "pitchbend", channel: event.channel };
|
|
187
|
+
case "program":
|
|
188
|
+
return { kind: "program", channel: event.channel };
|
|
189
|
+
case "pressure":
|
|
190
|
+
return { kind: "pressure", channel: event.channel };
|
|
191
|
+
case "key":
|
|
192
|
+
return { kind: "key", key: event.key };
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function sourceMatches(source, event) {
|
|
196
|
+
if (source.kind !== event.kind) return false;
|
|
197
|
+
if (source.kind === "key") return event.kind === "key" && source.key === event.key;
|
|
198
|
+
if (source.kind === "cc" && (event.kind !== "cc" || source.controller !== event.controller)) return false;
|
|
199
|
+
return source.channel === void 0 || event.kind !== "key" && source.channel === event.channel;
|
|
200
|
+
}
|
|
201
|
+
function describeSource(source) {
|
|
202
|
+
const channel = "channel" in source && source.channel !== void 0 ? ` ch ${source.channel + 1}` : "";
|
|
203
|
+
switch (source.kind) {
|
|
204
|
+
case "cc":
|
|
205
|
+
return `CC ${source.controller}${channel}`;
|
|
206
|
+
case "pitchbend":
|
|
207
|
+
return `Bend${channel}`;
|
|
208
|
+
case "program":
|
|
209
|
+
return `Program${channel}`;
|
|
210
|
+
case "pressure":
|
|
211
|
+
return `Pressure${channel}`;
|
|
212
|
+
case "key":
|
|
213
|
+
return `Key ${source.key.length === 1 ? source.key.toUpperCase() : source.key}`;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
var _mappings, _learning, _keyState, _options, _listeners, _ControlMappings_instances, notify_fn;
|
|
217
|
+
var ControlMappings = class {
|
|
218
|
+
constructor(options, mappings2 = []) {
|
|
219
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _ControlMappings_instances);
|
|
220
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _mappings, []);
|
|
221
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _learning);
|
|
222
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _keyState, /* @__PURE__ */ new Map());
|
|
223
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _options);
|
|
224
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _listeners, /* @__PURE__ */ new Set());
|
|
225
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _options, options);
|
|
226
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _mappings, mappings2);
|
|
227
|
+
}
|
|
228
|
+
get mappings() {
|
|
229
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _mappings);
|
|
230
|
+
}
|
|
231
|
+
/** The target waiting for its next control event, if any. */
|
|
232
|
+
get learning() {
|
|
233
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _learning);
|
|
234
|
+
}
|
|
235
|
+
/** Replace the list, as when a project opens. */
|
|
236
|
+
set(mappings2) {
|
|
237
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _mappings, mappings2);
|
|
238
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _keyState).clear();
|
|
239
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ControlMappings_instances, notify_fn).call(this);
|
|
240
|
+
}
|
|
241
|
+
/** The next control event maps to `target`, replacing that target's previous mapping. */
|
|
242
|
+
learn(target) {
|
|
243
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _learning, target);
|
|
244
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ControlMappings_instances, notify_fn).call(this);
|
|
245
|
+
}
|
|
246
|
+
cancelLearn() {
|
|
247
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _learning)) {
|
|
248
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _learning, void 0);
|
|
249
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ControlMappings_instances, notify_fn).call(this);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
remove(id) {
|
|
253
|
+
const next = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _mappings).filter((mapping) => mapping.id !== id);
|
|
254
|
+
if (next.length === _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _mappings).length) return;
|
|
255
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _mappings, next);
|
|
256
|
+
_optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options), 'access', _2 => _2.onChange, 'optionalCall', _3 => _3(next)]);
|
|
257
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ControlMappings_instances, notify_fn).call(this);
|
|
258
|
+
}
|
|
259
|
+
/** Apply one event. Returns true when it learned a mapping or set at least one parameter. */
|
|
260
|
+
handle(event) {
|
|
261
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _learning) && (event.kind !== "key" || event.down)) {
|
|
262
|
+
const target = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _learning);
|
|
263
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _learning, void 0);
|
|
264
|
+
const source = controlSource(event);
|
|
265
|
+
const kept = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _mappings).filter((mapping) => !(mapping.target.moduleId === target.moduleId && mapping.target.param === target.param));
|
|
266
|
+
let index = 1;
|
|
267
|
+
const used = new Set(kept.map((mapping) => mapping.id));
|
|
268
|
+
while (used.has(`map${index}`)) index++;
|
|
269
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _mappings, [...kept, { id: `map${index}`, source, target }]);
|
|
270
|
+
_optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options), 'access', _4 => _4.onChange, 'optionalCall', _5 => _5(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _mappings))]);
|
|
271
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ControlMappings_instances, notify_fn).call(this);
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
274
|
+
let applied = false;
|
|
275
|
+
for (const mapping of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _mappings)) {
|
|
276
|
+
if (!sourceMatches(mapping.source, event)) continue;
|
|
277
|
+
const handle = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options).resolve(mapping.target);
|
|
278
|
+
if (!handle || handle.snapshot.disposed) continue;
|
|
279
|
+
const range = _nullishCoalesce(handle.descriptor.displayRange, () => ( handle.descriptor.range));
|
|
280
|
+
const min = _nullishCoalesce(mapping.min, () => ( range.min)), max = _nullishCoalesce(mapping.max, () => ( range.max));
|
|
281
|
+
let fraction = controlFraction(event);
|
|
282
|
+
if (event.kind === "key") {
|
|
283
|
+
if (!event.down) continue;
|
|
284
|
+
const on = !(_nullishCoalesce(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _keyState).get(mapping.id), () => ( false)));
|
|
285
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _keyState).set(mapping.id, on);
|
|
286
|
+
fraction = on ? 1 : 0;
|
|
287
|
+
}
|
|
288
|
+
if (fraction === void 0) continue;
|
|
289
|
+
const value = min + fraction * (max - min);
|
|
290
|
+
const { min: legalMin, max: legalMax } = handle.descriptor.range;
|
|
291
|
+
try {
|
|
292
|
+
handle.setBaseValue(Math.min(legalMax, Math.max(legalMin, value)));
|
|
293
|
+
applied = true;
|
|
294
|
+
} catch (e2) {
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return applied;
|
|
298
|
+
}
|
|
299
|
+
subscribe(listener) {
|
|
300
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners).add(listener);
|
|
301
|
+
return () => {
|
|
302
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners).delete(listener);
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
_mappings = new WeakMap();
|
|
307
|
+
_learning = new WeakMap();
|
|
308
|
+
_keyState = new WeakMap();
|
|
309
|
+
_options = new WeakMap();
|
|
310
|
+
_listeners = new WeakMap();
|
|
311
|
+
_ControlMappings_instances = new WeakSet();
|
|
312
|
+
notify_fn = function() {
|
|
313
|
+
for (const listener of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners)]) {
|
|
314
|
+
try {
|
|
315
|
+
listener();
|
|
316
|
+
} catch (e3) {
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
// src/module/voices.ts
|
|
322
|
+
var _held, _order, _next;
|
|
323
|
+
var VoiceAllocator = class {
|
|
324
|
+
constructor(voices, steal = "oldest") {
|
|
325
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _held, /* @__PURE__ */ new Map());
|
|
326
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _order, []);
|
|
327
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _next, 0);
|
|
328
|
+
if (!Number.isInteger(voices) || voices < 1 || voices > 256) throw new RangeError("A voice allocator needs 1 to 256 voices.");
|
|
329
|
+
this.voices = voices;
|
|
330
|
+
this.steal = steal;
|
|
331
|
+
}
|
|
332
|
+
/** Keys currently holding a voice, oldest first. */
|
|
333
|
+
get held() {
|
|
334
|
+
return [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _order)];
|
|
335
|
+
}
|
|
336
|
+
/** The voice playing `key`, if any. */
|
|
337
|
+
voiceOf(key) {
|
|
338
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _held).get(key);
|
|
339
|
+
}
|
|
340
|
+
/** Give `key` a voice: a free one in turn, or the oldest held voice when all are busy. */
|
|
341
|
+
noteOn(key) {
|
|
342
|
+
const existing = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _held).get(key);
|
|
343
|
+
if (existing !== void 0) return { voice: existing };
|
|
344
|
+
const busy = new Set(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _held).values());
|
|
345
|
+
for (let offset = 0; offset < this.voices; offset++) {
|
|
346
|
+
const voice2 = (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _next) + offset) % this.voices;
|
|
347
|
+
if (busy.has(voice2)) continue;
|
|
348
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _next, (voice2 + 1) % this.voices);
|
|
349
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _held).set(key, voice2);
|
|
350
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _order).push(key);
|
|
351
|
+
return { voice: voice2 };
|
|
352
|
+
}
|
|
353
|
+
if (this.steal === "none") return { voice: void 0 };
|
|
354
|
+
const stolen = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _order).shift();
|
|
355
|
+
const voice = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _held).get(stolen);
|
|
356
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _held).delete(stolen);
|
|
357
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _held).set(key, voice);
|
|
358
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _order).push(key);
|
|
359
|
+
return { voice, stolen };
|
|
360
|
+
}
|
|
361
|
+
/** Free the voice of `key`; returns it, or undefined when the key held none. */
|
|
362
|
+
noteOff(key) {
|
|
363
|
+
const voice = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _held).get(key);
|
|
364
|
+
if (voice === void 0) return void 0;
|
|
365
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _held).delete(key);
|
|
366
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _order).splice(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _order).indexOf(key), 1);
|
|
367
|
+
return voice;
|
|
368
|
+
}
|
|
369
|
+
/** Free every voice. */
|
|
370
|
+
clear() {
|
|
371
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _held).clear();
|
|
372
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _order).length = 0;
|
|
373
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _next, 0);
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
_held = new WeakMap();
|
|
377
|
+
_order = new WeakMap();
|
|
378
|
+
_next = new WeakMap();
|
|
379
|
+
|
|
380
|
+
// src/module/observe.ts
|
|
381
|
+
var _clock, _watchpoints, _listeners2, _stop, _holding, _last, _disposed, _MessageDebugger_instances, check_fn;
|
|
382
|
+
var MessageDebugger = class {
|
|
383
|
+
constructor(runtime, clock) {
|
|
384
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _MessageDebugger_instances);
|
|
385
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _clock);
|
|
386
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _watchpoints, /* @__PURE__ */ new Map());
|
|
387
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _listeners2, /* @__PURE__ */ new Set());
|
|
388
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _stop);
|
|
389
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _holding, false);
|
|
390
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _last);
|
|
391
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _disposed, false);
|
|
392
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _clock, clock);
|
|
393
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _stop, runtime.observe((event) => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _MessageDebugger_instances, check_fn).call(this, event)));
|
|
394
|
+
}
|
|
395
|
+
get watchpoints() {
|
|
396
|
+
return [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _watchpoints).values()];
|
|
397
|
+
}
|
|
398
|
+
/** True while a break holds the clock. */
|
|
399
|
+
get paused() {
|
|
400
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _holding) && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _clock).held;
|
|
401
|
+
}
|
|
402
|
+
/** The latest hit, for a debugger view. */
|
|
403
|
+
get lastHit() {
|
|
404
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _last);
|
|
405
|
+
}
|
|
406
|
+
set(watchpoint) {
|
|
407
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) throw new Error("The debugger is disposed.");
|
|
408
|
+
if (watchpoint.mode !== "trace" && watchpoint.mode !== "break") throw new TypeError("A watchpoint traces or breaks.");
|
|
409
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _watchpoints).set(watchpoint.id, Object.freeze({ ...watchpoint }));
|
|
410
|
+
}
|
|
411
|
+
remove(id) {
|
|
412
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _watchpoints).delete(id);
|
|
413
|
+
}
|
|
414
|
+
onHit(listener) {
|
|
415
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners2).add(listener);
|
|
416
|
+
return () => {
|
|
417
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners2).delete(listener);
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
continue() {
|
|
421
|
+
if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _holding)) return;
|
|
422
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _holding, false);
|
|
423
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _clock).resume();
|
|
424
|
+
}
|
|
425
|
+
/** Deliver one held event; false when none is waiting. */
|
|
426
|
+
step() {
|
|
427
|
+
return this.paused ? _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _clock).step() : false;
|
|
428
|
+
}
|
|
429
|
+
dispose() {
|
|
430
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
|
|
431
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _disposed, true);
|
|
432
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _stop).call(this);
|
|
433
|
+
this.continue();
|
|
434
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners2).clear();
|
|
435
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _watchpoints).clear();
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
_clock = new WeakMap();
|
|
439
|
+
_watchpoints = new WeakMap();
|
|
440
|
+
_listeners2 = new WeakMap();
|
|
441
|
+
_stop = new WeakMap();
|
|
442
|
+
_holding = new WeakMap();
|
|
443
|
+
_last = new WeakMap();
|
|
444
|
+
_disposed = new WeakMap();
|
|
445
|
+
_MessageDebugger_instances = new WeakSet();
|
|
446
|
+
check_fn = function(event) {
|
|
447
|
+
for (const watchpoint of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _watchpoints).values()) {
|
|
448
|
+
if (watchpoint.connectionId !== event.connectionId) continue;
|
|
449
|
+
let hit;
|
|
450
|
+
try {
|
|
451
|
+
hit = watchpoint.condition ? watchpoint.condition(event) === true : true;
|
|
452
|
+
} catch (e4) {
|
|
453
|
+
hit = false;
|
|
454
|
+
}
|
|
455
|
+
if (!hit) continue;
|
|
456
|
+
const found = Object.freeze({ watchpoint, event });
|
|
457
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _last, found);
|
|
458
|
+
if (watchpoint.mode === "break" && !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _clock).held) {
|
|
459
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _holding, true);
|
|
460
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _clock).hold();
|
|
461
|
+
}
|
|
462
|
+
for (const listener of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners2)]) {
|
|
463
|
+
try {
|
|
464
|
+
listener(found);
|
|
465
|
+
} catch (e5) {
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
// src/module/wam.ts
|
|
472
|
+
var WAM_MODULE = _chunkI4YMA5VMcjs.createCapabilityKey.call(void 0, "webmusic.wam-module");
|
|
473
|
+
async function defaultLoad(url) {
|
|
474
|
+
const module = await Promise.resolve().then(() => _interopRequireWildcard(require(
|
|
475
|
+
/* @vite-ignore */
|
|
476
|
+
url
|
|
477
|
+
)));
|
|
478
|
+
if (!module.default || typeof module.default.createInstance !== "function") throw new (0, _chunkI4YMA5VMcjs.ProjectModuleUnavailableError)(`${url} is not a Web Audio Module.`);
|
|
479
|
+
return module.default;
|
|
480
|
+
}
|
|
481
|
+
var MIDI_AXIS = "audio-context-seconds";
|
|
482
|
+
function wamPlugin(options) {
|
|
483
|
+
const groups = /* @__PURE__ */ new WeakMap();
|
|
484
|
+
const allow = _nullishCoalesce(options.allow, () => ( ((url) => /^https?:\/\//i.test(url) || url.startsWith("/") || url.startsWith("./"))));
|
|
485
|
+
return Object.freeze({
|
|
486
|
+
id: _nullishCoalesce(options.id, () => ( "webmusic.wam")),
|
|
487
|
+
version: "1.0.0",
|
|
488
|
+
async create(request) {
|
|
489
|
+
const { record, context, signal } = request;
|
|
490
|
+
const url = typeof record.config.url === "string" ? record.config.url : "";
|
|
491
|
+
if (!url) throw new (0, _chunkI4YMA5VMcjs.ProjectModuleUnavailableError)("Give the Web Audio Module a URL.");
|
|
492
|
+
if (!allow(url)) throw new (0, _chunkI4YMA5VMcjs.ProjectModuleUnavailableError)(`This page does not load Web Audio Modules from ${url}.`);
|
|
493
|
+
const audio = context.audio.prepare();
|
|
494
|
+
let group = groups.get(audio);
|
|
495
|
+
if (!group) {
|
|
496
|
+
group = Promise.resolve(options.hostGroup(audio));
|
|
497
|
+
groups.set(audio, group);
|
|
498
|
+
}
|
|
499
|
+
let instance;
|
|
500
|
+
try {
|
|
501
|
+
const constructor = await (_nullishCoalesce(options.load, () => ( defaultLoad)))(url);
|
|
502
|
+
signal.throwIfAborted();
|
|
503
|
+
instance = await constructor.createInstance(await group, audio, record.config.state);
|
|
504
|
+
} catch (error) {
|
|
505
|
+
if (_optionalChain([error, 'optionalAccess', _6 => _6.name]) === "AbortError") throw error;
|
|
506
|
+
throw new (0, _chunkI4YMA5VMcjs.ProjectModuleUnavailableError)(`The Web Audio Module did not load: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
507
|
+
}
|
|
508
|
+
const node = instance.audioNode;
|
|
509
|
+
const destroy = () => {
|
|
510
|
+
try {
|
|
511
|
+
node.disconnect();
|
|
512
|
+
} catch (e6) {
|
|
513
|
+
}
|
|
514
|
+
try {
|
|
515
|
+
_optionalChain([node, 'access', _7 => _7.destroy, 'optionalCall', _8 => _8()]);
|
|
516
|
+
} catch (e7) {
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
try {
|
|
520
|
+
signal.throwIfAborted();
|
|
521
|
+
const info = await node.getParameterInfo();
|
|
522
|
+
const values = await node.getParameterValues(false).catch(() => ({}));
|
|
523
|
+
signal.throwIfAborted();
|
|
524
|
+
let state = record.config.state;
|
|
525
|
+
const refreshState = () => {
|
|
526
|
+
void _optionalChain([node, 'access', _9 => _9.getState, 'optionalCall', _10 => _10(), 'access', _11 => _11.then, 'call', _12 => _12((next) => {
|
|
527
|
+
try {
|
|
528
|
+
state = JSON.parse(JSON.stringify(_nullishCoalesce(next, () => ( null))));
|
|
529
|
+
} catch (e8) {
|
|
530
|
+
}
|
|
531
|
+
}, () => {
|
|
532
|
+
})]);
|
|
533
|
+
};
|
|
534
|
+
const handles = Object.values(info).map((param) => {
|
|
535
|
+
const min = Number(param.minValue), max = Number(param.maxValue);
|
|
536
|
+
const integer = param.type === "int" || param.type === "boolean" || param.type === "choice";
|
|
537
|
+
return new (0, _chunk5AHVQXTFcjs.ParamHandle)({
|
|
538
|
+
id: param.id,
|
|
539
|
+
label: param.label || param.id,
|
|
540
|
+
unit: param.units || (integer ? "step" : "value"),
|
|
541
|
+
range: { min, max },
|
|
542
|
+
defaultValue: Number(param.defaultValue),
|
|
543
|
+
...integer ? { step: 1 } : param.discreteStep ? { step: param.discreteStep } : {},
|
|
544
|
+
...param.exponent && param.exponent !== 0 ? { scale: "logarithmic" } : {}
|
|
545
|
+
}, {
|
|
546
|
+
baseValue: _nullishCoalesce(_optionalChain([values, 'access', _13 => _13[param.id], 'optionalAccess', _14 => _14.value]), () => ( Number(param.defaultValue))),
|
|
547
|
+
apply: (value) => {
|
|
548
|
+
void node.setParameterValues({ [param.id]: { id: param.id, value, normalized: false } }).then(refreshState, () => {
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
});
|
|
553
|
+
const params = new (0, _chunk5AHVQXTFcjs.ParamSurface)(handles);
|
|
554
|
+
const descriptor = _nullishCoalesce(instance.descriptor, () => ( {}));
|
|
555
|
+
const output = descriptor.hasAudioOutput === false ? void 0 : new (0, _chunkOCKAHITLcjs.AudioOutputPort)(node, { id: "output" });
|
|
556
|
+
const notes = descriptor.hasMidiInput ? new (0, _chunkK7FYH6UGcjs.NoteInputPort)({ accept: (event) => {
|
|
557
|
+
const time = event.axis === MIDI_AXIS ? Math.max(audio.currentTime, event.time) : audio.currentTime;
|
|
558
|
+
const pitch = Math.max(0, Math.min(127, Math.round(event.pitch.midi)));
|
|
559
|
+
const on = event.gate === "on";
|
|
560
|
+
node.scheduleEvents({ type: "wam-midi", time, data: { bytes: on ? [144, pitch, Math.max(1, Math.round(event.velocity * 127))] : [128, pitch, 0] } });
|
|
561
|
+
} }, { id: "notes" }) : void 0;
|
|
562
|
+
const lend = Object.freeze({
|
|
563
|
+
instance,
|
|
564
|
+
name: descriptor.name || url,
|
|
565
|
+
createGui: () => _optionalChain([instance, 'access', _15 => _15.createGui, 'optionalCall', _16 => _16()]),
|
|
566
|
+
destroyGui: (gui) => {
|
|
567
|
+
try {
|
|
568
|
+
_optionalChain([instance, 'access', _17 => _17.destroyGui, 'optionalCall', _18 => _18(gui)]);
|
|
569
|
+
} catch (e9) {
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
let route;
|
|
574
|
+
let disposed = false;
|
|
575
|
+
const module = {
|
|
576
|
+
id: record.id,
|
|
577
|
+
params,
|
|
578
|
+
capabilities: new (0, _chunkI4YMA5VMcjs.ModuleCapabilities)().with(WAM_MODULE, lend),
|
|
579
|
+
ports: () => notes ? [notes] : [],
|
|
580
|
+
getPort: (id) => id === "output" ? output : void 0,
|
|
581
|
+
prepare: () => {
|
|
582
|
+
if (!disposed && output && !route) route = _chunkOCKAHITLcjs.routeModuleOutput.call(void 0, context, module, output);
|
|
583
|
+
}
|
|
584
|
+
};
|
|
585
|
+
const registration = context.registry.register(module);
|
|
586
|
+
const ports = [
|
|
587
|
+
...descriptor.hasAudioInput === false ? [] : [{ id: "input", label: "audio in", kind: "audio", direction: "input" }],
|
|
588
|
+
...notes ? [{ id: "notes", label: "notes", kind: "note", direction: "input" }] : [],
|
|
589
|
+
...output ? [{ id: "output", label: "audio out", kind: "audio", direction: "output" }] : []
|
|
590
|
+
];
|
|
591
|
+
return {
|
|
592
|
+
module,
|
|
593
|
+
ports,
|
|
594
|
+
getInput: (id) => id === "input" && descriptor.hasAudioInput !== false ? node : void 0,
|
|
595
|
+
exportConfig: () => ({ ...record.config, ...state === void 0 ? {} : { state } }),
|
|
596
|
+
dispose: () => {
|
|
597
|
+
if (disposed) return;
|
|
598
|
+
disposed = true;
|
|
599
|
+
registration.release();
|
|
600
|
+
_optionalChain([route, 'optionalAccess', _19 => _19.release, 'call', _20 => _20()]);
|
|
601
|
+
_optionalChain([notes, 'optionalAccess', _21 => _21.dispose, 'call', _22 => _22()]);
|
|
602
|
+
_optionalChain([output, 'optionalAccess', _23 => _23.dispose, 'call', _24 => _24()]);
|
|
603
|
+
for (const handle of handles) handle.dispose();
|
|
604
|
+
destroy();
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
} catch (error) {
|
|
608
|
+
destroy();
|
|
609
|
+
throw error;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// src/module/multichannel.ts
|
|
616
|
+
var MAX_MC_CHANNELS = 32;
|
|
617
|
+
function channelCount(value) {
|
|
618
|
+
const channels = Math.trunc(Number(_nullishCoalesce(value, () => ( 2))));
|
|
619
|
+
if (!(channels >= 1 && channels <= MAX_MC_CHANNELS)) throw new (0, _chunkI4YMA5VMcjs.ProjectModuleUnavailableError)(`A multichannel module takes 1 to ${MAX_MC_CHANNELS} channels.`);
|
|
620
|
+
return channels;
|
|
621
|
+
}
|
|
622
|
+
function multichannelPlugin(inner, id = `${inner.id.replace(/^(.*\.)?/, "$1mc.")}`) {
|
|
623
|
+
return Object.freeze({
|
|
624
|
+
id,
|
|
625
|
+
version: inner.version,
|
|
626
|
+
async create(request) {
|
|
627
|
+
const { record, context } = request;
|
|
628
|
+
const channels = channelCount(record.config.channels);
|
|
629
|
+
const audio = context.audio.prepare();
|
|
630
|
+
const splitter = audio.createChannelSplitter(channels);
|
|
631
|
+
const merger = audio.createChannelMerger(channels);
|
|
632
|
+
const taps = Array.from({ length: channels }, () => audio.createGain());
|
|
633
|
+
taps.forEach((tap, channel) => tap.connect(merger, 0, channel));
|
|
634
|
+
const instances = [];
|
|
635
|
+
const registries = [];
|
|
636
|
+
const leases = [];
|
|
637
|
+
const cleanup = () => {
|
|
638
|
+
for (const lease of leases.splice(0)) {
|
|
639
|
+
try {
|
|
640
|
+
lease.release();
|
|
641
|
+
} catch (e10) {
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
for (const instance of instances.splice(0)) {
|
|
645
|
+
try {
|
|
646
|
+
instance.dispose();
|
|
647
|
+
} catch (e11) {
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
for (const registry of registries.splice(0)) {
|
|
651
|
+
try {
|
|
652
|
+
registry.dispose();
|
|
653
|
+
} catch (e12) {
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
for (const node of [splitter, merger, ...taps]) node.disconnect();
|
|
657
|
+
};
|
|
658
|
+
try {
|
|
659
|
+
for (let channel = 0; channel < channels; channel++) {
|
|
660
|
+
const registry = new (0, _chunkBADJJ6DVcjs.ModuleRegistry)();
|
|
661
|
+
registries.push(registry);
|
|
662
|
+
const scoped = context.derive({ id: `${context.id}/${record.id}.${channel}`, registry, admit: null, destination: () => taps[channel] });
|
|
663
|
+
const config = _nullishCoalesce(record.config.config, () => ( {}));
|
|
664
|
+
instances.push(await inner.create({ ...request, context: scoped, record: { ...record, id: `${record.id}.${channel}`, config } }));
|
|
665
|
+
}
|
|
666
|
+
} catch (error) {
|
|
667
|
+
cleanup();
|
|
668
|
+
throw error;
|
|
669
|
+
}
|
|
670
|
+
const port = new (0, _chunkOCKAHITLcjs.AudioOutputPort)(merger, { id: "output" });
|
|
671
|
+
const first = instances[0].module;
|
|
672
|
+
let disposed = false;
|
|
673
|
+
let mirroring = false;
|
|
674
|
+
const module = {
|
|
675
|
+
id: record.id,
|
|
676
|
+
get params() {
|
|
677
|
+
return first.params;
|
|
678
|
+
},
|
|
679
|
+
getPort: (name) => name === "output" ? port : void 0,
|
|
680
|
+
prepare: async () => {
|
|
681
|
+
if (disposed) return;
|
|
682
|
+
for (const instance of instances) await _optionalChain([instance, 'access', _25 => _25.module, 'access', _26 => _26.prepare, 'optionalCall', _27 => _27()]);
|
|
683
|
+
instances.forEach((instance, channel) => {
|
|
684
|
+
const input = _optionalChain([instance, 'access', _28 => _28.getInput, 'optionalCall', _29 => _29("input")]);
|
|
685
|
+
if (input) {
|
|
686
|
+
splitter.connect(input, channel, 0);
|
|
687
|
+
leases.push(_chunkEXDCK2VLcjs.createConnectionLease.call(void 0, () => {
|
|
688
|
+
try {
|
|
689
|
+
splitter.disconnect(input);
|
|
690
|
+
} catch (e13) {
|
|
691
|
+
}
|
|
692
|
+
}));
|
|
693
|
+
}
|
|
694
|
+
});
|
|
695
|
+
for (const handle of _nullishCoalesce(first.params, () => ( []))) {
|
|
696
|
+
leases.push(_chunkEXDCK2VLcjs.createConnectionLease.call(void 0, handle.subscribe((snapshot) => {
|
|
697
|
+
if (mirroring || snapshot.disposed) return;
|
|
698
|
+
mirroring = true;
|
|
699
|
+
try {
|
|
700
|
+
for (const instance of instances.slice(1)) _optionalChain([instance, 'access', _30 => _30.module, 'access', _31 => _31.params, 'optionalAccess', _32 => _32.get, 'call', _33 => _33(handle.descriptor.id), 'optionalAccess', _34 => _34.setBaseValue, 'call', _35 => _35(snapshot.baseValue)]);
|
|
701
|
+
} finally {
|
|
702
|
+
mirroring = false;
|
|
703
|
+
}
|
|
704
|
+
})));
|
|
705
|
+
}
|
|
706
|
+
leases.push(_chunkOCKAHITLcjs.routeModuleOutput.call(void 0, context, module, port));
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
const registration = context.registry.register(module);
|
|
710
|
+
return {
|
|
711
|
+
module,
|
|
712
|
+
ports: [{ id: "input", label: `${channels} channels in`, kind: "audio", direction: "input" }, { id: "output", label: `${channels} channels out`, kind: "audio", direction: "output" }],
|
|
713
|
+
getInput: (name) => name === "input" ? splitter : void 0,
|
|
714
|
+
exportConfig: () => record.config,
|
|
715
|
+
dispose: () => {
|
|
716
|
+
if (disposed) return;
|
|
717
|
+
disposed = true;
|
|
718
|
+
registration.release();
|
|
719
|
+
port.dispose();
|
|
720
|
+
cleanup();
|
|
721
|
+
}
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
var _inputs, _merger, _port;
|
|
727
|
+
var _ChannelPack = class _ChannelPack extends _chunkCR6OUWBJcjs.GraphModule {
|
|
728
|
+
constructor(options = {}) {
|
|
729
|
+
super(_ChannelPack.type, options);
|
|
730
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _inputs);
|
|
731
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _merger);
|
|
732
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _port);
|
|
733
|
+
const channels = this.channels = channelCount(options.channels);
|
|
734
|
+
const audio = this.audio();
|
|
735
|
+
const merger = _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _merger, audio.createChannelMerger(channels));
|
|
736
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _inputs, Array.from({ length: channels }, (_, channel) => {
|
|
737
|
+
const gain = audio.createGain();
|
|
738
|
+
gain.channelCount = 1;
|
|
739
|
+
gain.channelCountMode = "explicit";
|
|
740
|
+
gain.connect(merger, 0, channel);
|
|
741
|
+
this.addPort(void 0, { id: _chunkCR6OUWBJcjs.numberedPort.call(void 0, "in", channel), label: `channel ${channel + 1}`, kind: "audio", direction: "input" });
|
|
742
|
+
return gain;
|
|
743
|
+
}));
|
|
744
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _port, new (0, _chunkOCKAHITLcjs.AudioOutputPort)(merger, { id: "output" }));
|
|
745
|
+
this.addPort(void 0, { id: "output", label: `${channels} channels`, kind: "audio", direction: "output" });
|
|
746
|
+
}
|
|
747
|
+
getPort(name) {
|
|
748
|
+
return name === "output" ? _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _port) : void 0;
|
|
749
|
+
}
|
|
750
|
+
getInput(name) {
|
|
751
|
+
return /^in\d+$/.test(name) ? _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _inputs)[Number(name.slice(2))] : void 0;
|
|
752
|
+
}
|
|
753
|
+
exportOptions() {
|
|
754
|
+
return { channels: this.channels };
|
|
755
|
+
}
|
|
756
|
+
onDispose() {
|
|
757
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _port).dispose();
|
|
758
|
+
for (const node of [_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _merger), ..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _inputs)]) node.disconnect();
|
|
759
|
+
}
|
|
760
|
+
};
|
|
761
|
+
_inputs = new WeakMap();
|
|
762
|
+
_merger = new WeakMap();
|
|
763
|
+
_port = new WeakMap();
|
|
764
|
+
_ChannelPack.type = "webmusic.mc.pack";
|
|
765
|
+
var ChannelPack = _ChannelPack;
|
|
766
|
+
var _splitter, _outputs, _ports;
|
|
767
|
+
var _ChannelUnpack = class _ChannelUnpack extends _chunkCR6OUWBJcjs.GraphModule {
|
|
768
|
+
constructor(options = {}) {
|
|
769
|
+
super(_ChannelUnpack.type, options);
|
|
770
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _splitter);
|
|
771
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _outputs);
|
|
772
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _ports);
|
|
773
|
+
const channels = this.channels = channelCount(options.channels);
|
|
774
|
+
const audio = this.audio();
|
|
775
|
+
const splitter = _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _splitter, audio.createChannelSplitter(channels));
|
|
776
|
+
this.addPort(void 0, { id: "input", label: `${channels} channels`, kind: "audio", direction: "input" });
|
|
777
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _outputs, Array.from({ length: channels }, (_, channel) => {
|
|
778
|
+
const gain = audio.createGain();
|
|
779
|
+
splitter.connect(gain, channel, 0);
|
|
780
|
+
return gain;
|
|
781
|
+
}));
|
|
782
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _ports, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _outputs).map((gain, channel) => {
|
|
783
|
+
this.addPort(void 0, { id: _chunkCR6OUWBJcjs.numberedPort.call(void 0, "out", channel), label: `channel ${channel + 1}`, kind: "audio", direction: "output" });
|
|
784
|
+
return new (0, _chunkOCKAHITLcjs.AudioOutputPort)(gain, { id: _chunkCR6OUWBJcjs.numberedPort.call(void 0, "out", channel) });
|
|
785
|
+
}));
|
|
786
|
+
}
|
|
787
|
+
getPort(name) {
|
|
788
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _ports).find((port) => port.id === name);
|
|
789
|
+
}
|
|
790
|
+
getInput(name) {
|
|
791
|
+
return name === "input" ? _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _splitter) : void 0;
|
|
792
|
+
}
|
|
793
|
+
exportOptions() {
|
|
794
|
+
return { channels: this.channels };
|
|
795
|
+
}
|
|
796
|
+
onDispose() {
|
|
797
|
+
for (const port of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _ports)) port.dispose();
|
|
798
|
+
for (const node of [_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _splitter), ..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _outputs)]) node.disconnect();
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
_splitter = new WeakMap();
|
|
802
|
+
_outputs = new WeakMap();
|
|
803
|
+
_ports = new WeakMap();
|
|
804
|
+
_ChannelUnpack.type = "webmusic.mc.unpack";
|
|
805
|
+
var ChannelUnpack = _ChannelUnpack;
|
|
806
|
+
|
|
807
|
+
// src/module/note-maker.ts
|
|
808
|
+
var text = (atom) => atom.type === "symbol" ? atom.value : String(atom.value);
|
|
809
|
+
var _velocity, _duration, _authored, _count, _timed, _NoteMaker_instances, play_fn;
|
|
810
|
+
var _NoteMaker = class _NoteMaker extends _chunkCR6OUWBJcjs.GraphModule {
|
|
811
|
+
constructor(options = {}) {
|
|
812
|
+
super(_NoteMaker.type, options);
|
|
813
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _NoteMaker_instances);
|
|
814
|
+
this.inputs = {
|
|
815
|
+
pitch: this.input("pitch", "pitch, or pitch velocity duration", (value) => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _NoteMaker_instances, play_fn).call(this, value)),
|
|
816
|
+
velocity: this.input("velocity", "velocity", (value) => {
|
|
817
|
+
const n = _chunkCR6OUWBJcjs.numberOf.call(void 0, value);
|
|
818
|
+
if (n !== void 0) _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _velocity, n);
|
|
819
|
+
}),
|
|
820
|
+
duration: this.input("duration", "duration (ms or a time value)", (value) => {
|
|
821
|
+
const atom = _chunkCR6OUWBJcjs.atomsOf.call(void 0, value)[0];
|
|
822
|
+
if (atom) _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _duration, text(atom));
|
|
823
|
+
})
|
|
824
|
+
};
|
|
825
|
+
/** The notes it plays, on the audio clock. */
|
|
826
|
+
this.notes = new (0, _chunkK7FYH6UGcjs.NoteOutputPort)({ id: "notes" });
|
|
827
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _velocity);
|
|
828
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _duration);
|
|
829
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _authored);
|
|
830
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _count, 0);
|
|
831
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _timed, false);
|
|
832
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _velocity, typeof options.velocity === "number" && Number.isFinite(options.velocity) ? options.velocity : 100);
|
|
833
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _duration, options.duration === void 0 ? "250" : String(options.duration));
|
|
834
|
+
const duration = Number(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _duration));
|
|
835
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _authored, { velocity: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _velocity), duration: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _duration).trim() !== "" && Number.isFinite(duration) ? duration : _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _duration) });
|
|
836
|
+
this.addPort(this.notes, { id: "notes", label: "notes", kind: "note", direction: "output" });
|
|
837
|
+
}
|
|
838
|
+
/** Velocity of the next note, 0 to 127. */
|
|
839
|
+
get velocity() {
|
|
840
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _velocity);
|
|
841
|
+
}
|
|
842
|
+
set velocity(value) {
|
|
843
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _velocity, value);
|
|
844
|
+
}
|
|
845
|
+
/** Duration of the next note: milliseconds as text, or a time value. */
|
|
846
|
+
get duration() {
|
|
847
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _duration);
|
|
848
|
+
}
|
|
849
|
+
set duration(value) {
|
|
850
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _duration, String(value));
|
|
851
|
+
}
|
|
852
|
+
/** Play `pitch` (MIDI 0 to 127) at `time` (now by default) with the current velocity and duration. */
|
|
853
|
+
play(pitch, time) {
|
|
854
|
+
if (this.disposed || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _velocity) <= 0 || pitch < 0 || pitch > 127) return;
|
|
855
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _timed, true);
|
|
856
|
+
const start = _nullishCoalesce(time, () => ( this.clock.now()));
|
|
857
|
+
const seconds = _chunkTA3TNJZUcjs.timeValueSeconds.call(void 0, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _duration), _optionalChain([this, 'access', _36 => _36.musicalTime, 'optionalAccess', _37 => _37.tempo, 'call', _38 => _38()]));
|
|
858
|
+
const occurrenceId = `${this.id}-${++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _count)._}`;
|
|
859
|
+
const base = { occurrenceId, sourceId: this.id, pitch: { midi: Math.round(pitch) }, axis: "audio-context-seconds", epoch: _nullishCoalesce(_optionalChain([this, 'access', _39 => _39.context, 'optionalAccess', _40 => _40.session, 'optionalAccess', _41 => _41.scheduling, 'access', _42 => _42.epoch]), () => ( 0)) };
|
|
860
|
+
this.notes.emit({ ...base, velocity: Math.min(1, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _velocity) / 127), gate: "on", time: start });
|
|
861
|
+
this.clock.schedule(start + Math.max(1e-3, seconds), (when) => {
|
|
862
|
+
if (this.notes.held.some((event) => event.occurrenceId === occurrenceId)) this.notes.emit({ ...base, velocity: 0, gate: "off", time: when });
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
/** The options it was made with; a velocity or duration set later is not saved. */
|
|
866
|
+
exportOptions() {
|
|
867
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _authored);
|
|
868
|
+
}
|
|
869
|
+
// Held notes are cancelled at the clock's time when it was ever read.
|
|
870
|
+
onDispose() {
|
|
871
|
+
this.notes.dispose(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _timed) ? this.clock.now() : void 0);
|
|
872
|
+
}
|
|
873
|
+
};
|
|
874
|
+
_velocity = new WeakMap();
|
|
875
|
+
_duration = new WeakMap();
|
|
876
|
+
_authored = new WeakMap();
|
|
877
|
+
_count = new WeakMap();
|
|
878
|
+
_timed = new WeakMap();
|
|
879
|
+
_NoteMaker_instances = new WeakSet();
|
|
880
|
+
play_fn = function(value) {
|
|
881
|
+
const atoms = _chunkCR6OUWBJcjs.atomsOf.call(void 0, value).filter(_chunkCR6OUWBJcjs.isNumberAtom);
|
|
882
|
+
const pitch = _optionalChain([atoms, 'access', _43 => _43[0], 'optionalAccess', _44 => _44.value]);
|
|
883
|
+
if (pitch === void 0) return;
|
|
884
|
+
if (atoms[1]) _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _velocity, atoms[1].value);
|
|
885
|
+
if (atoms[2]) _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _duration, String(atoms[2].value));
|
|
886
|
+
this.play(pitch, value.time);
|
|
887
|
+
};
|
|
888
|
+
_NoteMaker.type = "webmusic.note-maker";
|
|
889
|
+
var NoteMaker = _NoteMaker;
|
|
890
|
+
|
|
891
|
+
// src/module/nested.ts
|
|
892
|
+
var BOUNDARY_KINDS = ["message", "audio", "note", "source"];
|
|
893
|
+
var COMPONENT_BOUNDARY = _chunkI4YMA5VMcjs.createCapabilityKey.call(void 0, "webmusic.component-boundary");
|
|
894
|
+
var POLY_VOICE = _chunkI4YMA5VMcjs.createCapabilityKey.call(void 0, "webmusic.poly-voice");
|
|
895
|
+
function kinds(value, name) {
|
|
896
|
+
if (value === void 0) return [];
|
|
897
|
+
if (!Array.isArray(value) || value.some((item) => !BOUNDARY_KINDS.includes(item))) {
|
|
898
|
+
throw new TypeError(`component ${name} must list message, audio, note or source channels.`);
|
|
899
|
+
}
|
|
900
|
+
return value;
|
|
901
|
+
}
|
|
902
|
+
function requireContext(module, context) {
|
|
903
|
+
if (!context) throw new Error(`${module} needs a module context.`);
|
|
904
|
+
return context;
|
|
905
|
+
}
|
|
906
|
+
var repeat = (relay) => (event) => {
|
|
907
|
+
if (relay.disposed) return;
|
|
908
|
+
if (event.gate !== "on" && !relay.held.some((held) => held.occurrenceId === event.occurrenceId)) return;
|
|
909
|
+
relay.emit(event);
|
|
910
|
+
};
|
|
911
|
+
var _inlets, _outlets, _disposers, _leases, _voicePorts, _voicesLent, _audio;
|
|
912
|
+
var _NestedComponent = class _NestedComponent extends _chunkCR6OUWBJcjs.GraphModule {
|
|
913
|
+
/** `type` and `voices` are for {@link PolyComponent}: voices make the shell own one child context per voice. */
|
|
914
|
+
constructor(options = {}, type = _NestedComponent.type, voices = 0) {
|
|
915
|
+
super(type, options);
|
|
916
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _inlets);
|
|
917
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _outlets);
|
|
918
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _disposers, []);
|
|
919
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _leases, []);
|
|
920
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _voicePorts);
|
|
921
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _voicesLent, 0);
|
|
922
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _audio);
|
|
923
|
+
requireContext(type, this.context);
|
|
924
|
+
this.inlets = Object.freeze(kinds(options.inlets, "inlets"));
|
|
925
|
+
this.outlets = Object.freeze(kinds(options.outlets, "outlets"));
|
|
926
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _voicePorts, Array.from({ length: voices }, (_, index) => new (0, _chunkK7FYH6UGcjs.NoteOutputPort)({ id: `voice-${index}` })));
|
|
927
|
+
if (voices) {
|
|
928
|
+
const allocator = new VoiceAllocator(voices);
|
|
929
|
+
const held = /* @__PURE__ */ new Map();
|
|
930
|
+
const ports = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _voicePorts);
|
|
931
|
+
this.voiceInput = new (0, _chunkK7FYH6UGcjs.NoteInputPort)({ accept: (event) => {
|
|
932
|
+
if (event.gate === "on") {
|
|
933
|
+
const { voice: voice2, stolen } = allocator.noteOn(event.occurrenceId);
|
|
934
|
+
if (voice2 === void 0) return;
|
|
935
|
+
if (stolen) {
|
|
936
|
+
const previous = held.get(stolen);
|
|
937
|
+
held.delete(stolen);
|
|
938
|
+
const port2 = ports[voice2];
|
|
939
|
+
if (previous && port2.held.some((item) => item.occurrenceId === stolen)) port2.emit({ ...previous, gate: "cancel", time: event.time, axis: event.axis });
|
|
940
|
+
}
|
|
941
|
+
held.set(event.occurrenceId, event);
|
|
942
|
+
ports[voice2].emit(event);
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
const voice = allocator.noteOff(event.occurrenceId);
|
|
946
|
+
held.delete(event.occurrenceId);
|
|
947
|
+
const port = voice === void 0 ? void 0 : ports[voice];
|
|
948
|
+
if (_optionalChain([port, 'optionalAccess', _45 => _45.held, 'access', _46 => _46.some, 'call', _47 => _47((item) => item.occurrenceId === event.occurrenceId)])) port.emit(event);
|
|
949
|
+
} }, { id: "notes" });
|
|
950
|
+
this.addPort(this.voiceInput, { id: "notes", label: "notes, one voice each", kind: "note", direction: "input" });
|
|
951
|
+
}
|
|
952
|
+
const audio = () => _nullishCoalesce(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _audio), () => ( _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _audio, this.audio())));
|
|
953
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _inlets, this.inlets.map((kind, index) => {
|
|
954
|
+
const id = _chunkCR6OUWBJcjs.numberedPort.call(void 0, "in", index);
|
|
955
|
+
const label = `${kind} in ${index + 1}`;
|
|
956
|
+
if (kind === "note") {
|
|
957
|
+
const relay2 = new (0, _chunkK7FYH6UGcjs.NoteOutputPort)({ id: `inner-${id}` });
|
|
958
|
+
const port = new (0, _chunkK7FYH6UGcjs.NoteInputPort)({ accept: repeat(relay2) }, { id, multiplicity: "sum" });
|
|
959
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposers).push(() => {
|
|
960
|
+
port.dispose();
|
|
961
|
+
relay2.dispose();
|
|
962
|
+
});
|
|
963
|
+
this.addPort(port, { id, label, kind, direction: "input" });
|
|
964
|
+
return { kind, channel: { kind, notes: relay2 } };
|
|
965
|
+
}
|
|
966
|
+
if (kind === "source") {
|
|
967
|
+
const relay2 = new (0, _chunkXBSIYUHMcjs.SourceRelay)(`${this.id}:${id}`);
|
|
968
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposers).push(() => relay2.dispose());
|
|
969
|
+
this.addPort(void 0, { id, label, kind, direction: "input" });
|
|
970
|
+
return { kind, relay: relay2, channel: { kind, source: relay2 } };
|
|
971
|
+
}
|
|
972
|
+
if (kind === "message") {
|
|
973
|
+
const relay2 = new (0, _chunkCR6OUWBJcjs.MessageOutputPort)({ id: `inner-${id}` });
|
|
974
|
+
const port = new (0, _chunkCR6OUWBJcjs.MessageInputPort)((value) => relay2.send(value), { id });
|
|
975
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposers).push(() => {
|
|
976
|
+
port.dispose();
|
|
977
|
+
relay2.dispose();
|
|
978
|
+
});
|
|
979
|
+
this.addPort(port, { id, label, kind, direction: "input" });
|
|
980
|
+
return { kind, channel: { kind, messages: relay2 } };
|
|
981
|
+
}
|
|
982
|
+
const node = audio().createGain();
|
|
983
|
+
const relay = new (0, _chunkOCKAHITLcjs.AudioOutputPort)(node, { id: `inner-${id}` });
|
|
984
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposers).push(() => {
|
|
985
|
+
relay.dispose();
|
|
986
|
+
node.disconnect();
|
|
987
|
+
});
|
|
988
|
+
this.addPort(void 0, { id, label, kind, direction: "input" });
|
|
989
|
+
return { kind, node, channel: { kind, audio: relay } };
|
|
990
|
+
}));
|
|
991
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _outlets, this.outlets.map((kind, index) => {
|
|
992
|
+
const id = _chunkCR6OUWBJcjs.numberedPort.call(void 0, "out", index);
|
|
993
|
+
const label = `${kind} out ${index + 1}`;
|
|
994
|
+
if (kind === "note") {
|
|
995
|
+
const port2 = new (0, _chunkK7FYH6UGcjs.NoteOutputPort)({ id });
|
|
996
|
+
const inner = new (0, _chunkK7FYH6UGcjs.NoteInputPort)({ accept: repeat(port2) }, { id: `inner-${id}`, multiplicity: "sum" });
|
|
997
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposers).push(() => {
|
|
998
|
+
inner.dispose();
|
|
999
|
+
port2.dispose();
|
|
1000
|
+
});
|
|
1001
|
+
this.addPort(port2, { id, label, kind, direction: "output" });
|
|
1002
|
+
return { kind, channel: { kind, notes: inner } };
|
|
1003
|
+
}
|
|
1004
|
+
if (kind === "source") {
|
|
1005
|
+
const relay = new (0, _chunkXBSIYUHMcjs.SourceRelay)(`${this.id}:${id}`);
|
|
1006
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposers).push(() => relay.dispose());
|
|
1007
|
+
this.addPort(void 0, { id, label, kind, direction: "output" });
|
|
1008
|
+
return { kind, relay, channel: { kind, source: relay } };
|
|
1009
|
+
}
|
|
1010
|
+
if (kind === "message") {
|
|
1011
|
+
const port2 = new (0, _chunkCR6OUWBJcjs.MessageOutputPort)({ id });
|
|
1012
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposers).push(() => port2.dispose());
|
|
1013
|
+
this.addPort(port2, { id, label, kind, direction: "output" });
|
|
1014
|
+
return { kind, channel: { kind, send: (value) => port2.send(value) } };
|
|
1015
|
+
}
|
|
1016
|
+
const node = audio().createGain();
|
|
1017
|
+
const port = new (0, _chunkOCKAHITLcjs.AudioOutputPort)(node, { id });
|
|
1018
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposers).push(() => {
|
|
1019
|
+
port.dispose();
|
|
1020
|
+
node.disconnect();
|
|
1021
|
+
});
|
|
1022
|
+
this.addPort(void 0, { id, label, kind, direction: "output" });
|
|
1023
|
+
return { kind, node, port, channel: { kind, input: node } };
|
|
1024
|
+
}));
|
|
1025
|
+
this.boundary = Object.freeze({
|
|
1026
|
+
inlet: (index) => _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _inlets), 'access', _48 => _48[index], 'optionalAccess', _49 => _49.channel]),
|
|
1027
|
+
outlet: (index) => _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _outlets), 'access', _50 => _50[index], 'optionalAccess', _51 => _51.channel])
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
getPort(name) {
|
|
1031
|
+
return _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _outlets), 'access', _52 => _52.find, 'call', _53 => _53((item, index) => item.kind === "audio" && _chunkCR6OUWBJcjs.numberedPort.call(void 0, "out", index) === name), 'optionalAccess', _54 => _54.port]);
|
|
1032
|
+
}
|
|
1033
|
+
/** The first audio outlet follows the context's default route, like any other audio module. */
|
|
1034
|
+
prepare() {
|
|
1035
|
+
if (this.disposed || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _leases).length) return;
|
|
1036
|
+
const first = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _outlets).find((item) => item.kind === "audio");
|
|
1037
|
+
if (_optionalChain([first, 'optionalAccess', _55 => _55.port])) _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _leases).push(_chunkOCKAHITLcjs.routeModuleOutput.call(void 0, requireContext(this.type, this.context), this, first.port));
|
|
1038
|
+
}
|
|
1039
|
+
getInput(name) {
|
|
1040
|
+
return _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _inlets), 'access', _56 => _56.find, 'call', _57 => _57((item, index) => item.kind === "audio" && _chunkCR6OUWBJcjs.numberedPort.call(void 0, "in", index) === name), 'optionalAccess', _58 => _58.node]);
|
|
1041
|
+
}
|
|
1042
|
+
/** A source cord into an inlet is followed by that inlet's relay. */
|
|
1043
|
+
connectSource(name, upstream) {
|
|
1044
|
+
return _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _inlets), 'access', _59 => _59.find, 'call', _60 => _60((item, index) => item.kind === "source" && _chunkCR6OUWBJcjs.numberedPort.call(void 0, "in", index) === name), 'optionalAccess', _61 => _61.relay, 'optionalAccess', _62 => _62.follow, 'call', _63 => _63(upstream)]);
|
|
1045
|
+
}
|
|
1046
|
+
/** A source cord from an outlet carries the outlet's relay. */
|
|
1047
|
+
sourceOutput(name) {
|
|
1048
|
+
return _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _outlets), 'access', _64 => _64.find, 'call', _65 => _65((item, index) => item.kind === "source" && _chunkCR6OUWBJcjs.numberedPort.call(void 0, "out", index) === name), 'optionalAccess', _66 => _66.relay]);
|
|
1049
|
+
}
|
|
1050
|
+
/**
|
|
1051
|
+
* Inner modules keep the parent's destination and admission, so a module
|
|
1052
|
+
* not wired to an audio outlet sounds through the parent's default route.
|
|
1053
|
+
*/
|
|
1054
|
+
childContext(child) {
|
|
1055
|
+
let capabilities = child.capabilities.with(COMPONENT_BOUNDARY, this.boundary);
|
|
1056
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _voicePorts).length) {
|
|
1057
|
+
const index = _chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _voicesLent)._++;
|
|
1058
|
+
const port = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _voicePorts)[index];
|
|
1059
|
+
if (port) capabilities = capabilities.with(POLY_VOICE, Object.freeze({ index, voices: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _voicePorts).length, notes: port }));
|
|
1060
|
+
}
|
|
1061
|
+
return child.derive({ id: child.id, registry: child.registry, capabilities });
|
|
1062
|
+
}
|
|
1063
|
+
exportOptions() {
|
|
1064
|
+
return { inlets: [...this.inlets], outlets: [...this.outlets] };
|
|
1065
|
+
}
|
|
1066
|
+
onDispose() {
|
|
1067
|
+
for (const lease of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _leases).splice(0)) lease.release();
|
|
1068
|
+
_optionalChain([this, 'access', _67 => _67.voiceInput, 'optionalAccess', _68 => _68.dispose, 'call', _69 => _69()]);
|
|
1069
|
+
for (const port of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _voicePorts)) port.dispose();
|
|
1070
|
+
for (const dispose of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposers).splice(0)) dispose();
|
|
1071
|
+
}
|
|
1072
|
+
};
|
|
1073
|
+
_inlets = new WeakMap();
|
|
1074
|
+
_outlets = new WeakMap();
|
|
1075
|
+
_disposers = new WeakMap();
|
|
1076
|
+
_leases = new WeakMap();
|
|
1077
|
+
_voicePorts = new WeakMap();
|
|
1078
|
+
_voicesLent = new WeakMap();
|
|
1079
|
+
_audio = new WeakMap();
|
|
1080
|
+
_NestedComponent.type = "webmusic.nested";
|
|
1081
|
+
var NestedComponent = _NestedComponent;
|
|
1082
|
+
var _PolyComponent = class _PolyComponent extends NestedComponent {
|
|
1083
|
+
constructor(options = {}) {
|
|
1084
|
+
const voices = Math.trunc(Number(_nullishCoalesce(options.voices, () => ( 4))));
|
|
1085
|
+
if (!(voices >= 1 && voices <= 64)) throw new RangeError("poly needs 1 to 64 voices.");
|
|
1086
|
+
super(options, _PolyComponent.type, voices);
|
|
1087
|
+
this.voices = voices;
|
|
1088
|
+
}
|
|
1089
|
+
/** Notes in, one voice each. */
|
|
1090
|
+
get notes() {
|
|
1091
|
+
return this.voiceInput;
|
|
1092
|
+
}
|
|
1093
|
+
exportOptions() {
|
|
1094
|
+
return { ...super.exportOptions(), voices: this.voices };
|
|
1095
|
+
}
|
|
1096
|
+
};
|
|
1097
|
+
_PolyComponent.type = "webmusic.poly";
|
|
1098
|
+
var PolyComponent = _PolyComponent;
|
|
1099
|
+
function boundaryOptions(options) {
|
|
1100
|
+
const kind = _nullishCoalesce(options.kind, () => ( "message"));
|
|
1101
|
+
if (!BOUNDARY_KINDS.includes(kind)) throw new TypeError("A boundary carries message, audio, note or source.");
|
|
1102
|
+
const index = options.index;
|
|
1103
|
+
if (index !== void 0 && !(typeof index === "number" && Number.isFinite(index))) throw new TypeError("A boundary index is a number.");
|
|
1104
|
+
return { kind, index: Math.max(0, Math.trunc(_nullishCoalesce(index, () => ( 0)))) };
|
|
1105
|
+
}
|
|
1106
|
+
var what = (kind) => kind === "message" ? "messages" : kind === "audio" ? "audio" : kind === "note" ? "notes" : "a source";
|
|
1107
|
+
var _channel, _port2, _release;
|
|
1108
|
+
var _InletModule = class _InletModule extends _chunkCR6OUWBJcjs.GraphModule {
|
|
1109
|
+
constructor(options = {}) {
|
|
1110
|
+
super(_InletModule.type, options);
|
|
1111
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _channel);
|
|
1112
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _port2);
|
|
1113
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _release, []);
|
|
1114
|
+
const { kind, index } = boundaryOptions(options);
|
|
1115
|
+
this.kind = kind;
|
|
1116
|
+
this.index = index;
|
|
1117
|
+
const found = _optionalChain([requireContext, 'call', _70 => _70(_InletModule.type, this.context), 'access', _71 => _71.capabilities, 'access', _72 => _72.get, 'call', _73 => _73(COMPONENT_BOUNDARY), 'optionalAccess', _74 => _74.inlet, 'call', _75 => _75(index)]);
|
|
1118
|
+
const channel = _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _channel, _optionalChain([found, 'optionalAccess', _76 => _76.kind]) === kind ? found : void 0);
|
|
1119
|
+
const descriptor = { id: "output", label: `${what(kind)} from outside`, kind, direction: "output" };
|
|
1120
|
+
if (kind === "message") {
|
|
1121
|
+
const port = new (0, _chunkCR6OUWBJcjs.MessageOutputPort)({ id: "output", onListenerError: (error) => this.fail(error) });
|
|
1122
|
+
const stop = _optionalChain([channel, 'optionalAccess', _77 => _77.messages, 'optionalAccess', _78 => _78.subscribe, 'call', _79 => _79((value) => port.send(value))]);
|
|
1123
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _release).push(() => _optionalChain([stop, 'optionalCall', _80 => _80()]));
|
|
1124
|
+
this.addPort(port, descriptor);
|
|
1125
|
+
} else if (kind === "note") {
|
|
1126
|
+
const notes = new (0, _chunkK7FYH6UGcjs.NoteOutputPort)({ id: "output" });
|
|
1127
|
+
const stop = _optionalChain([channel, 'optionalAccess', _81 => _81.notes, 'optionalAccess', _82 => _82.subscribe, 'call', _83 => _83(repeat(notes))]);
|
|
1128
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _release).push(() => {
|
|
1129
|
+
_optionalChain([stop, 'optionalCall', _84 => _84()]);
|
|
1130
|
+
notes.dispose();
|
|
1131
|
+
});
|
|
1132
|
+
this.addPort(notes, descriptor);
|
|
1133
|
+
} else if (kind === "audio") {
|
|
1134
|
+
const node = this.audio().createGain();
|
|
1135
|
+
const lease = _nullishCoalesce(_optionalChain([channel, 'optionalAccess', _85 => _85.audio, 'optionalAccess', _86 => _86.send, 'call', _87 => _87(node)]), () => ( _chunkEXDCK2VLcjs.createConnectionLease.call(void 0, () => {
|
|
1136
|
+
})));
|
|
1137
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _port2, new (0, _chunkOCKAHITLcjs.AudioOutputPort)(node, { id: "output" }));
|
|
1138
|
+
const port = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _port2);
|
|
1139
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _release).push(() => {
|
|
1140
|
+
lease.release();
|
|
1141
|
+
port.dispose();
|
|
1142
|
+
node.disconnect();
|
|
1143
|
+
});
|
|
1144
|
+
this.addPort(void 0, descriptor);
|
|
1145
|
+
} else this.addPort(void 0, descriptor);
|
|
1146
|
+
}
|
|
1147
|
+
getPort(name) {
|
|
1148
|
+
return name === "output" ? _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _port2) : void 0;
|
|
1149
|
+
}
|
|
1150
|
+
/** A source inlet carries the component's inlet relay. */
|
|
1151
|
+
sourceOutput(name) {
|
|
1152
|
+
return name === "output" && this.kind === "source" ? _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _channel), 'optionalAccess', _88 => _88.source]) : void 0;
|
|
1153
|
+
}
|
|
1154
|
+
exportOptions() {
|
|
1155
|
+
return { kind: this.kind, index: this.index };
|
|
1156
|
+
}
|
|
1157
|
+
onDispose() {
|
|
1158
|
+
for (const release of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _release).splice(0)) release();
|
|
1159
|
+
}
|
|
1160
|
+
};
|
|
1161
|
+
_channel = new WeakMap();
|
|
1162
|
+
_port2 = new WeakMap();
|
|
1163
|
+
_release = new WeakMap();
|
|
1164
|
+
_InletModule.type = "webmusic.inlet";
|
|
1165
|
+
var InletModule = _InletModule;
|
|
1166
|
+
var _channel2, _node, _release2;
|
|
1167
|
+
var _OutletModule = class _OutletModule extends _chunkCR6OUWBJcjs.GraphModule {
|
|
1168
|
+
constructor(options = {}) {
|
|
1169
|
+
super(_OutletModule.type, options);
|
|
1170
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _channel2);
|
|
1171
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _node);
|
|
1172
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _release2, []);
|
|
1173
|
+
const { kind, index } = boundaryOptions(options);
|
|
1174
|
+
this.kind = kind;
|
|
1175
|
+
this.index = index;
|
|
1176
|
+
const found = _optionalChain([requireContext, 'call', _89 => _89(_OutletModule.type, this.context), 'access', _90 => _90.capabilities, 'access', _91 => _91.get, 'call', _92 => _92(COMPONENT_BOUNDARY), 'optionalAccess', _93 => _93.outlet, 'call', _94 => _94(index)]);
|
|
1177
|
+
const channel = _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _channel2, _optionalChain([found, 'optionalAccess', _95 => _95.kind]) === kind ? found : void 0);
|
|
1178
|
+
const label = `${what(kind)} to send outside`;
|
|
1179
|
+
if (kind === "message") this.input("input", label, (value) => _optionalChain([channel, 'optionalAccess', _96 => _96.send, 'optionalCall', _97 => _97(value)]));
|
|
1180
|
+
else if (kind === "note") {
|
|
1181
|
+
const notes = new (0, _chunkK7FYH6UGcjs.NoteInputPort)({ accept: (event) => _optionalChain([channel, 'optionalAccess', _98 => _98.notes, 'optionalAccess', _99 => _99.accept, 'call', _100 => _100(event)]) }, { id: "input", multiplicity: "sum" });
|
|
1182
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _release2).push(() => notes.dispose());
|
|
1183
|
+
this.addPort(notes, { id: "input", label, kind, direction: "input" });
|
|
1184
|
+
} else if (kind === "audio") {
|
|
1185
|
+
const node = _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _node, this.audio().createGain());
|
|
1186
|
+
const target = _optionalChain([channel, 'optionalAccess', _101 => _101.input]);
|
|
1187
|
+
if (target) node.connect(target);
|
|
1188
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _release2).push(() => {
|
|
1189
|
+
if (target) {
|
|
1190
|
+
try {
|
|
1191
|
+
node.disconnect(target);
|
|
1192
|
+
} catch (e14) {
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
node.disconnect();
|
|
1196
|
+
});
|
|
1197
|
+
this.addPort(void 0, { id: "input", label, kind, direction: "input" });
|
|
1198
|
+
} else this.addPort(void 0, { id: "input", label, kind, direction: "input" });
|
|
1199
|
+
}
|
|
1200
|
+
getInput(name) {
|
|
1201
|
+
return name === "input" ? _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _node) : void 0;
|
|
1202
|
+
}
|
|
1203
|
+
/** A source outlet hands what reaches it to the component's outlet relay. */
|
|
1204
|
+
connectSource(name, upstream) {
|
|
1205
|
+
return name === "input" && this.kind === "source" ? _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _channel2), 'optionalAccess', _102 => _102.source, 'optionalAccess', _103 => _103.follow, 'call', _104 => _104(upstream)]) : void 0;
|
|
1206
|
+
}
|
|
1207
|
+
exportOptions() {
|
|
1208
|
+
return { kind: this.kind, index: this.index };
|
|
1209
|
+
}
|
|
1210
|
+
onDispose() {
|
|
1211
|
+
for (const release of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _release2).splice(0)) release();
|
|
1212
|
+
}
|
|
1213
|
+
};
|
|
1214
|
+
_channel2 = new WeakMap();
|
|
1215
|
+
_node = new WeakMap();
|
|
1216
|
+
_release2 = new WeakMap();
|
|
1217
|
+
_OutletModule.type = "webmusic.outlet";
|
|
1218
|
+
var OutletModule = _OutletModule;
|
|
1219
|
+
var _release3;
|
|
1220
|
+
var _VoiceNotes = class _VoiceNotes extends _chunkCR6OUWBJcjs.GraphModule {
|
|
1221
|
+
constructor(options = {}) {
|
|
1222
|
+
super(_VoiceNotes.type, options);
|
|
1223
|
+
this.notes = new (0, _chunkK7FYH6UGcjs.NoteOutputPort)({ id: "notes" });
|
|
1224
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _release3);
|
|
1225
|
+
this.voice = requireContext(_VoiceNotes.type, this.context).capabilities.get(POLY_VOICE);
|
|
1226
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _release3, _optionalChain([this, 'access', _105 => _105.voice, 'optionalAccess', _106 => _106.notes, 'access', _107 => _107.subscribe, 'call', _108 => _108(repeat(this.notes))]));
|
|
1227
|
+
this.addPort(this.notes, { id: "notes", label: `notes for voice ${this.voice ? this.voice.index + 1 : "\u2014"}`, kind: "note", direction: "output" });
|
|
1228
|
+
}
|
|
1229
|
+
exportOptions() {
|
|
1230
|
+
return {};
|
|
1231
|
+
}
|
|
1232
|
+
onDispose() {
|
|
1233
|
+
var _a;
|
|
1234
|
+
(_a = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _release3)) == null ? void 0 : _a.call(this);
|
|
1235
|
+
}
|
|
1236
|
+
};
|
|
1237
|
+
_release3 = new WeakMap();
|
|
1238
|
+
_VoiceNotes.type = "webmusic.voice";
|
|
1239
|
+
var VoiceNotes = _VoiceNotes;
|
|
1240
|
+
|
|
1241
|
+
// src/module/preset-modules.ts
|
|
1242
|
+
function controlValue(module) {
|
|
1243
|
+
const control = _optionalChain([module, 'access', _109 => _109.capabilities, 'optionalAccess', _110 => _110.get, 'call', _111 => _111(_chunkWN5DZOVTcjs.MODULE_CONTROL)]);
|
|
1244
|
+
const snapshot = _optionalChain([control, 'optionalAccess', _112 => _112.snapshot, 'call', _113 => _113()]);
|
|
1245
|
+
if (!control || !snapshot || typeof snapshot !== "object") return void 0;
|
|
1246
|
+
const float = snapshot.float === true;
|
|
1247
|
+
const number2 = (value) => float ? _chunkCR6OUWBJcjs.floatAtom.call(void 0, value) : _chunkCR6OUWBJcjs.intAtom.call(void 0, Math.round(value));
|
|
1248
|
+
switch (control.kind) {
|
|
1249
|
+
case "toggle":
|
|
1250
|
+
return { value: snapshot.on ? 1 : 0, restore: (value) => _chunkCR6OUWBJcjs.message.call(void 0, "int", [_chunkCR6OUWBJcjs.intAtom.call(void 0, Number(value) >= 0.5 ? 1 : 0)]) };
|
|
1251
|
+
case "number":
|
|
1252
|
+
case "slider":
|
|
1253
|
+
case "dial":
|
|
1254
|
+
return typeof snapshot.value === "number" ? { value: snapshot.value, restore: (value) => _chunkCR6OUWBJcjs.message.call(void 0, float ? "float" : "int", [number2(Number(value))]) } : void 0;
|
|
1255
|
+
case "menu":
|
|
1256
|
+
case "tab":
|
|
1257
|
+
return typeof snapshot.index === "number" ? { value: snapshot.index, restore: (value) => _chunkCR6OUWBJcjs.message.call(void 0, "int", [_chunkCR6OUWBJcjs.intAtom.call(void 0, Math.round(Number(value)))]) } : void 0;
|
|
1258
|
+
case "multislider":
|
|
1259
|
+
return Array.isArray(snapshot.values) ? { value: snapshot.values.map(Number), restore: (value) => _chunkCR6OUWBJcjs.message.call(void 0, "list", value.map(number2)) } : void 0;
|
|
1260
|
+
default:
|
|
1261
|
+
return void 0;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
var _current, _PresetModule_instances, others_fn, capture_fn, apply_fn;
|
|
1265
|
+
var _PresetModule = class _PresetModule extends _chunkWN5DZOVTcjs.ControlModule {
|
|
1266
|
+
constructor(options = {}) {
|
|
1267
|
+
super(_PresetModule.type, options);
|
|
1268
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _PresetModule_instances);
|
|
1269
|
+
this.kind = "preset";
|
|
1270
|
+
this.inputs = { control: this.input("control", "slot to recall, store n, clear n, interp a b f, weights \u2026", (value) => this.receive(value)) };
|
|
1271
|
+
this.outputs = { slot: this.output("slot", "the slot recalled") };
|
|
1272
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _current, 0);
|
|
1273
|
+
const count = options.count;
|
|
1274
|
+
if (count !== void 0 && !(typeof count === "number" && Number.isFinite(count))) throw new TypeError("A preset count is a number.");
|
|
1275
|
+
this.count = Math.max(1, Math.min(64, Math.trunc(_nullishCoalesce(count, () => ( 16)))));
|
|
1276
|
+
this.bank = new PresetBank(options.slots && typeof options.slots === "object" ? options.slots : void 0);
|
|
1277
|
+
}
|
|
1278
|
+
/** The slot last stored or recalled; 0 after a blend. */
|
|
1279
|
+
get current() {
|
|
1280
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _current);
|
|
1281
|
+
}
|
|
1282
|
+
/** Capture the other modules into `slot`. */
|
|
1283
|
+
store(slot) {
|
|
1284
|
+
if (slot < 1 || slot > this.count) return;
|
|
1285
|
+
this.bank.store(slot, _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _PresetModule_instances, capture_fn).call(this));
|
|
1286
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _current, slot);
|
|
1287
|
+
this.changed();
|
|
1288
|
+
}
|
|
1289
|
+
/** Apply a stored slot and report it. */
|
|
1290
|
+
recall(slot, time) {
|
|
1291
|
+
const values = this.bank.recall(slot);
|
|
1292
|
+
if (!values) return;
|
|
1293
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _current, slot);
|
|
1294
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _PresetModule_instances, apply_fn).call(this, values);
|
|
1295
|
+
this.changed();
|
|
1296
|
+
this.outputs.slot.send(_chunkCR6OUWBJcjs.message.call(void 0, "int", [_chunkCR6OUWBJcjs.intAtom.call(void 0, slot)], time));
|
|
1297
|
+
}
|
|
1298
|
+
/** Apply a blend of stored slots. */
|
|
1299
|
+
blend(values) {
|
|
1300
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _PresetModule_instances, apply_fn).call(this, values);
|
|
1301
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _current, 0);
|
|
1302
|
+
this.changed();
|
|
1303
|
+
}
|
|
1304
|
+
snapshot() {
|
|
1305
|
+
return { count: this.count, stored: [...this.bank.slots], current: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _current) };
|
|
1306
|
+
}
|
|
1307
|
+
exportOptions() {
|
|
1308
|
+
return { count: this.count, slots: this.bank.toJSON() };
|
|
1309
|
+
}
|
|
1310
|
+
receive(value) {
|
|
1311
|
+
const numbers = _chunkCR6OUWBJcjs.atomsOf.call(void 0, value).filter(_chunkCR6OUWBJcjs.isNumberAtom).map((atom) => atom.value);
|
|
1312
|
+
switch (value.selector) {
|
|
1313
|
+
case "int":
|
|
1314
|
+
case "float":
|
|
1315
|
+
this.recall(Math.trunc(numbers[0]), value.time);
|
|
1316
|
+
return;
|
|
1317
|
+
case "bang":
|
|
1318
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _current)) this.recall(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _current), value.time);
|
|
1319
|
+
return;
|
|
1320
|
+
case "store":
|
|
1321
|
+
this.store(Math.trunc(_nullishCoalesce(numbers[0], () => ( 0))));
|
|
1322
|
+
return;
|
|
1323
|
+
case "clear":
|
|
1324
|
+
this.bank.clear(Math.trunc(_nullishCoalesce(numbers[0], () => ( 0))));
|
|
1325
|
+
this.changed();
|
|
1326
|
+
return;
|
|
1327
|
+
case "interp": {
|
|
1328
|
+
const [from, to, fraction] = numbers;
|
|
1329
|
+
if (from === void 0 || to === void 0 || fraction === void 0) return;
|
|
1330
|
+
this.blend(this.bank.between(Math.trunc(from), Math.trunc(to), fraction));
|
|
1331
|
+
return;
|
|
1332
|
+
}
|
|
1333
|
+
case "weights":
|
|
1334
|
+
this.blend(this.bank.interpolate(Object.fromEntries(numbers.map((weight, index) => [index + 1, weight]))));
|
|
1335
|
+
return;
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
};
|
|
1339
|
+
_current = new WeakMap();
|
|
1340
|
+
_PresetModule_instances = new WeakSet();
|
|
1341
|
+
others_fn = function() {
|
|
1342
|
+
return (_nullishCoalesce(_optionalChain([this, 'access', _114 => _114.context, 'optionalAccess', _115 => _115.registry, 'access', _116 => _116.snapshot, 'call', _117 => _117()]), () => ( []))).filter((module) => module.id !== this.id);
|
|
1343
|
+
};
|
|
1344
|
+
capture_fn = function() {
|
|
1345
|
+
const modules = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _PresetModule_instances, others_fn).call(this);
|
|
1346
|
+
const values = captureParameters(modules);
|
|
1347
|
+
for (const module of modules) {
|
|
1348
|
+
const held = controlValue(module);
|
|
1349
|
+
if (held) values[`${module.id}#value`] = held.value;
|
|
1350
|
+
}
|
|
1351
|
+
return values;
|
|
1352
|
+
};
|
|
1353
|
+
apply_fn = function(values) {
|
|
1354
|
+
const modules = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _PresetModule_instances, others_fn).call(this);
|
|
1355
|
+
applyParameters(modules, values);
|
|
1356
|
+
for (const module of modules) {
|
|
1357
|
+
const value = values[`${module.id}#value`];
|
|
1358
|
+
const held = value === void 0 ? void 0 : controlValue(module);
|
|
1359
|
+
if (held) _optionalChain([module, 'access', _118 => _118.capabilities, 'optionalAccess', _119 => _119.get, 'call', _120 => _120(_chunkWN5DZOVTcjs.MODULE_CONTROL), 'optionalAccess', _121 => _121.interact, 'call', _122 => _122(held.restore(value))]);
|
|
1360
|
+
}
|
|
1361
|
+
};
|
|
1362
|
+
_PresetModule.type = "webmusic.preset";
|
|
1363
|
+
var PresetModule = _PresetModule;
|
|
1364
|
+
function nodeWeights(nodes, cursor) {
|
|
1365
|
+
const raw = nodes.map((node) => Math.max(0, 1 - Math.hypot(cursor.x - node.x, cursor.y - node.y) / node.radius));
|
|
1366
|
+
const total = raw.reduce((sum, weight) => sum + weight, 0);
|
|
1367
|
+
return total > 0 ? raw.map((weight) => weight / total) : raw;
|
|
1368
|
+
}
|
|
1369
|
+
var _nodes, _cursor, _NodesModule_instances, send_fn;
|
|
1370
|
+
var _NodesModule = class _NodesModule extends _chunkWN5DZOVTcjs.ControlModule {
|
|
1371
|
+
constructor(options = {}) {
|
|
1372
|
+
super(_NodesModule.type, options);
|
|
1373
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _NodesModule_instances);
|
|
1374
|
+
this.kind = "nodes";
|
|
1375
|
+
this.inputs = { control: this.input("control", "cursor x y, node i x y", (value) => this.receive(value)) };
|
|
1376
|
+
this.outputs = { weights: this.output("weights", "weights, one per node") };
|
|
1377
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _nodes);
|
|
1378
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _cursor);
|
|
1379
|
+
if (options.count !== void 0 && !(typeof options.count === "number" && Number.isFinite(options.count))) throw new TypeError("A node count is a number.");
|
|
1380
|
+
const count = Math.max(2, Math.min(12, Math.trunc(_nullishCoalesce(options.count, () => ( 4)))));
|
|
1381
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _nodes, Array.isArray(options.nodes) && options.nodes.length === count ? options.nodes.map((node) => ({ ...node })) : Array.from({ length: count }, (_, index) => {
|
|
1382
|
+
const angle = index / count * Math.PI * 2 - Math.PI / 2;
|
|
1383
|
+
return { x: 0.5 + 0.3 * Math.cos(angle), y: 0.5 + 0.3 * Math.sin(angle), radius: 0.45 };
|
|
1384
|
+
}));
|
|
1385
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _cursor, options.cursor && Number.isFinite(options.cursor.x) ? { ...options.cursor } : { x: 0.5, y: 0.5 });
|
|
1386
|
+
}
|
|
1387
|
+
get nodes() {
|
|
1388
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _nodes).map((node) => ({ ...node }));
|
|
1389
|
+
}
|
|
1390
|
+
get cursor() {
|
|
1391
|
+
return { ..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _cursor) };
|
|
1392
|
+
}
|
|
1393
|
+
/** The weight of each node for the cursor where it is. */
|
|
1394
|
+
get weights() {
|
|
1395
|
+
return nodeWeights(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _nodes), _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _cursor));
|
|
1396
|
+
}
|
|
1397
|
+
/** Move the cursor and send the weights. */
|
|
1398
|
+
moveCursor(x, y, time) {
|
|
1399
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _cursor, { x: clamp(x), y: clamp(y) });
|
|
1400
|
+
this.changed();
|
|
1401
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _NodesModule_instances, send_fn).call(this, time);
|
|
1402
|
+
}
|
|
1403
|
+
/** Move a node, and resize it when `radius` is given, and send the weights. */
|
|
1404
|
+
moveNode(index, x, y, radius, time) {
|
|
1405
|
+
const node = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _nodes)[Math.trunc(index)];
|
|
1406
|
+
if (!node) return;
|
|
1407
|
+
node.x = clamp(x);
|
|
1408
|
+
node.y = clamp(y);
|
|
1409
|
+
if (radius !== void 0 && radius > 0) node.radius = Math.min(1, radius);
|
|
1410
|
+
this.changed();
|
|
1411
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _NodesModule_instances, send_fn).call(this, time);
|
|
1412
|
+
}
|
|
1413
|
+
snapshot() {
|
|
1414
|
+
return { nodes: this.nodes, cursor: { ..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _cursor) }, weights: this.weights };
|
|
1415
|
+
}
|
|
1416
|
+
exportOptions() {
|
|
1417
|
+
return { count: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _nodes).length, nodes: this.nodes, cursor: { ..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _cursor) } };
|
|
1418
|
+
}
|
|
1419
|
+
receive(value) {
|
|
1420
|
+
const numbers = _chunkCR6OUWBJcjs.atomsOf.call(void 0, value).filter(_chunkCR6OUWBJcjs.isNumberAtom).map((atom) => atom.value);
|
|
1421
|
+
if (value.selector === "cursor" && numbers.length >= 2) {
|
|
1422
|
+
this.moveCursor(numbers[0], numbers[1], value.time);
|
|
1423
|
+
return;
|
|
1424
|
+
}
|
|
1425
|
+
if (value.selector === "node" && numbers.length >= 3) {
|
|
1426
|
+
this.moveNode(numbers[0], numbers[1], numbers[2], numbers[3], value.time);
|
|
1427
|
+
return;
|
|
1428
|
+
}
|
|
1429
|
+
if (value.selector === "bang") _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _NodesModule_instances, send_fn).call(this, value.time);
|
|
1430
|
+
}
|
|
1431
|
+
};
|
|
1432
|
+
_nodes = new WeakMap();
|
|
1433
|
+
_cursor = new WeakMap();
|
|
1434
|
+
_NodesModule_instances = new WeakSet();
|
|
1435
|
+
send_fn = function(time) {
|
|
1436
|
+
this.outputs.weights.send(_chunkCR6OUWBJcjs.message.call(void 0, "list", this.weights.map((weight) => _chunkCR6OUWBJcjs.floatAtom.call(void 0, weight)), time));
|
|
1437
|
+
};
|
|
1438
|
+
_NodesModule.type = "webmusic.nodes";
|
|
1439
|
+
var NodesModule = _NodesModule;
|
|
1440
|
+
var clamp = (value) => Math.min(1, Math.max(0, value));
|
|
1441
|
+
|
|
1442
|
+
// src/module/structure-plugins.ts
|
|
1443
|
+
function createStructurePlugins(environment = {}) {
|
|
1444
|
+
const classes = [NoteMaker, NestedComponent, PolyComponent, InletModule, OutletModule, VoiceNotes, PresetModule, NodesModule, ChannelPack, ChannelUnpack];
|
|
1445
|
+
return Object.freeze(classes.map((Type) => _chunkCR6OUWBJcjs.modulePlugin.call(void 0, Type.type, (options) => new Type(options), environment)));
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
// src/module/source-port.ts
|
|
1449
|
+
var SOURCE_SCHEMAS = Object.freeze({
|
|
1450
|
+
score: "webmusic.score",
|
|
1451
|
+
scoreDocument: "webmusic.score-document",
|
|
1452
|
+
audioClip: "webmusic.audio-clip",
|
|
1453
|
+
audioDocument: "webmusic.audio-document"
|
|
1454
|
+
});
|
|
1455
|
+
var _listeners3, _snapshot, _disposed2, _SourcePublisher_instances, commit_fn;
|
|
1456
|
+
var SourcePublisher = class {
|
|
1457
|
+
constructor(schemaId, options = {}) {
|
|
1458
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _SourcePublisher_instances);
|
|
1459
|
+
this.family = "source";
|
|
1460
|
+
this.direction = "output";
|
|
1461
|
+
this.multiplicity = "single";
|
|
1462
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _listeners3);
|
|
1463
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _snapshot, Object.freeze({ revision: 0, readiness: "empty" }));
|
|
1464
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _disposed2, false);
|
|
1465
|
+
if (typeof schemaId !== "string" || !schemaId.trim()) throw new TypeError("Source schemaId must be a nonempty string");
|
|
1466
|
+
const version = _nullishCoalesce(options.schemaVersion, () => ( 1));
|
|
1467
|
+
if (!Number.isInteger(version) || version < 1) throw new TypeError("Port schemaVersion must be a positive integer");
|
|
1468
|
+
this.schemaId = schemaId;
|
|
1469
|
+
this.schemaVersion = version;
|
|
1470
|
+
this.id = _nullishCoalesce(options.id, () => ( "source"));
|
|
1471
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _listeners3, new (0, _chunkI4YMA5VMcjs.PortListeners)(options.onListenerError));
|
|
1472
|
+
Object.freeze(this);
|
|
1473
|
+
}
|
|
1474
|
+
get disposed() {
|
|
1475
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2);
|
|
1476
|
+
}
|
|
1477
|
+
get readiness() {
|
|
1478
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2) ? "detached" : "ready";
|
|
1479
|
+
}
|
|
1480
|
+
get revision() {
|
|
1481
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _snapshot).revision;
|
|
1482
|
+
}
|
|
1483
|
+
snapshot() {
|
|
1484
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _snapshot);
|
|
1485
|
+
}
|
|
1486
|
+
subscribe(listener) {
|
|
1487
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2)) throw new Error("SourcePublisher is disposed");
|
|
1488
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners3).add(listener);
|
|
1489
|
+
}
|
|
1490
|
+
/** Mark a replacement as pending; returns the revision a later result must still match. */
|
|
1491
|
+
loading() {
|
|
1492
|
+
return _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SourcePublisher_instances, commit_fn).call(this, { readiness: "loading" });
|
|
1493
|
+
}
|
|
1494
|
+
ready(value) {
|
|
1495
|
+
return _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SourcePublisher_instances, commit_fn).call(this, { readiness: "ready", value });
|
|
1496
|
+
}
|
|
1497
|
+
fail(error) {
|
|
1498
|
+
return _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SourcePublisher_instances, commit_fn).call(this, { readiness: "error", error });
|
|
1499
|
+
}
|
|
1500
|
+
clear() {
|
|
1501
|
+
return _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SourcePublisher_instances, commit_fn).call(this, { readiness: "empty" });
|
|
1502
|
+
}
|
|
1503
|
+
/** Detach every consumer. The last snapshot stays readable; no further revision is published. */
|
|
1504
|
+
dispose() {
|
|
1505
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2)) return;
|
|
1506
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _disposed2, true);
|
|
1507
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners3).clear();
|
|
1508
|
+
}
|
|
1509
|
+
};
|
|
1510
|
+
_listeners3 = new WeakMap();
|
|
1511
|
+
_snapshot = new WeakMap();
|
|
1512
|
+
_disposed2 = new WeakMap();
|
|
1513
|
+
_SourcePublisher_instances = new WeakSet();
|
|
1514
|
+
commit_fn = function(next) {
|
|
1515
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2)) throw new Error("SourcePublisher is disposed");
|
|
1516
|
+
const snapshot = Object.freeze({ ...next, revision: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _snapshot).revision + 1 });
|
|
1517
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _snapshot, snapshot);
|
|
1518
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners3).emit(snapshot);
|
|
1519
|
+
return snapshot.revision;
|
|
1520
|
+
};
|
|
1521
|
+
|
|
1522
|
+
// src/module/conformance.ts
|
|
1523
|
+
function message2(error) {
|
|
1524
|
+
return error instanceof Error ? error.message : String(error);
|
|
1525
|
+
}
|
|
1526
|
+
async function checkModuleConformance(create, options = {}) {
|
|
1527
|
+
const failures = [];
|
|
1528
|
+
const fail = (check, error) => {
|
|
1529
|
+
failures.push(Object.freeze({ check, message: message2(error) }));
|
|
1530
|
+
};
|
|
1531
|
+
const repetitions = _nullishCoalesce(options.repetitions, () => ( 2));
|
|
1532
|
+
if (!Number.isInteger(repetitions) || repetitions < 1) throw new RangeError("repetitions must be a positive integer");
|
|
1533
|
+
let instances = 0;
|
|
1534
|
+
for (let index = 0; index < repetitions; index++) {
|
|
1535
|
+
let subject;
|
|
1536
|
+
try {
|
|
1537
|
+
subject = await create();
|
|
1538
|
+
} catch (error) {
|
|
1539
|
+
fail("create", error);
|
|
1540
|
+
continue;
|
|
1541
|
+
}
|
|
1542
|
+
instances++;
|
|
1543
|
+
const { module } = subject;
|
|
1544
|
+
try {
|
|
1545
|
+
_chunkBADJJ6DVcjs.assertModuleId.call(void 0, module.id);
|
|
1546
|
+
} catch (error) {
|
|
1547
|
+
fail("id", error);
|
|
1548
|
+
}
|
|
1549
|
+
if (options.expectedId !== void 0 && module.id !== options.expectedId) {
|
|
1550
|
+
fail("id", `Expected module ID ${options.expectedId}, received ${module.id}`);
|
|
1551
|
+
}
|
|
1552
|
+
try {
|
|
1553
|
+
const handle = _chunkBADJJ6DVcjs.createModuleHandle.call(void 0, module);
|
|
1554
|
+
if (!Object.isFrozen(handle)) fail("handle", "createModuleHandle must return a frozen view");
|
|
1555
|
+
if (handle.params !== module.params || handle.inserts !== module.inserts || handle.capabilities !== module.capabilities) {
|
|
1556
|
+
fail("handle", "Handle getters must delegate to the module");
|
|
1557
|
+
}
|
|
1558
|
+
} catch (error) {
|
|
1559
|
+
fail("handle", error);
|
|
1560
|
+
}
|
|
1561
|
+
let ports = [];
|
|
1562
|
+
try {
|
|
1563
|
+
ports = _nullishCoalesce(_optionalChain([module, 'access', _123 => _123.ports, 'optionalCall', _124 => _124()]), () => ( []));
|
|
1564
|
+
if (!Array.isArray(ports)) throw new TypeError("ports() must return an array");
|
|
1565
|
+
const keys = /* @__PURE__ */ new Set();
|
|
1566
|
+
for (const port of ports) {
|
|
1567
|
+
try {
|
|
1568
|
+
_chunkI4YMA5VMcjs.assertPortInfo.call(void 0, port);
|
|
1569
|
+
} catch (error) {
|
|
1570
|
+
fail(`port:${String(_optionalChain([port, 'optionalAccess', _125 => _125.id]))}`, error);
|
|
1571
|
+
continue;
|
|
1572
|
+
}
|
|
1573
|
+
const key = `${port.family}/${port.direction}/${port.id}`;
|
|
1574
|
+
if (keys.has(key)) fail("ports", `Duplicate port ${key}`);
|
|
1575
|
+
keys.add(key);
|
|
1576
|
+
}
|
|
1577
|
+
const again = _nullishCoalesce(_optionalChain([module, 'access', _126 => _126.ports, 'optionalCall', _127 => _127()]), () => ( []));
|
|
1578
|
+
if (again.length !== ports.length || again.some((port, position) => port !== ports[position])) {
|
|
1579
|
+
fail("ports", "ports() must return the same port objects while nothing changed");
|
|
1580
|
+
}
|
|
1581
|
+
for (const port of ports) {
|
|
1582
|
+
if (port.family !== "audio" || port.direction !== "output" || !module.getPort) continue;
|
|
1583
|
+
const shortcut = module.getPort(port.id);
|
|
1584
|
+
if (shortcut !== void 0 && shortcut !== port) fail("ports", `getPort(${port.id}) differs from ports()`);
|
|
1585
|
+
}
|
|
1586
|
+
} catch (error) {
|
|
1587
|
+
fail("ports", error);
|
|
1588
|
+
}
|
|
1589
|
+
if (module.subscribe) {
|
|
1590
|
+
try {
|
|
1591
|
+
const stop = module.subscribe(() => {
|
|
1592
|
+
});
|
|
1593
|
+
if (typeof stop !== "function") throw new TypeError("subscribe() must return an unsubscribe function");
|
|
1594
|
+
stop();
|
|
1595
|
+
stop();
|
|
1596
|
+
} catch (error) {
|
|
1597
|
+
fail("subscribe", error);
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
if (options.prepare && module.prepare) {
|
|
1601
|
+
try {
|
|
1602
|
+
await module.prepare();
|
|
1603
|
+
await module.prepare();
|
|
1604
|
+
} catch (error) {
|
|
1605
|
+
fail("prepare", error);
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
if (subject.dispose) {
|
|
1609
|
+
try {
|
|
1610
|
+
await subject.dispose();
|
|
1611
|
+
await subject.dispose();
|
|
1612
|
+
} catch (error) {
|
|
1613
|
+
fail("dispose", error);
|
|
1614
|
+
}
|
|
1615
|
+
const borrowed = new Set(_nullishCoalesce(options.borrowedPorts, () => ( [])));
|
|
1616
|
+
for (const port of ports) {
|
|
1617
|
+
if (borrowed.has(`${port.family}/${port.id}`)) continue;
|
|
1618
|
+
try {
|
|
1619
|
+
if (port.readiness !== "detached") fail("dispose", `Port ${port.family}/${port.id} is still ${port.readiness} after disposal`);
|
|
1620
|
+
} catch (error) {
|
|
1621
|
+
fail("dispose", error);
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
return Object.freeze({ passed: failures.length === 0, instances, failures: Object.freeze(failures) });
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
// src/module/control.ts
|
|
1630
|
+
var ControlLFO = class {
|
|
1631
|
+
constructor(context, options = {}) {
|
|
1632
|
+
this.disposed = false;
|
|
1633
|
+
const frequency = _nullishCoalesce(options.frequency, () => ( 1));
|
|
1634
|
+
if (!Number.isFinite(frequency) || frequency < 0 || frequency > context.sampleRate / 2) throw new RangeError("LFO frequency must be between zero and Nyquist.");
|
|
1635
|
+
const waveform = _nullishCoalesce(options.waveform, () => ( "sine"));
|
|
1636
|
+
validateWaveform(waveform);
|
|
1637
|
+
this.oscillator = context.createOscillator();
|
|
1638
|
+
this.oscillator.type = waveform;
|
|
1639
|
+
this.oscillator.frequency.value = frequency;
|
|
1640
|
+
this.frequency = new (0, _chunk5AHVQXTFcjs.ParamHandle)({
|
|
1641
|
+
id: "frequency",
|
|
1642
|
+
label: "Rate",
|
|
1643
|
+
unit: "Hz",
|
|
1644
|
+
range: { min: 0, max: context.sampleRate / 2 },
|
|
1645
|
+
displayRange: { min: 0, max: Math.min(20, context.sampleRate / 2) },
|
|
1646
|
+
defaultValue: 1,
|
|
1647
|
+
updateTiming: "scheduled",
|
|
1648
|
+
modulation: "audio-rate"
|
|
1649
|
+
}, { baseValue: frequency });
|
|
1650
|
+
this.frequency.bindAudioParam(context, this.oscillator.frequency, { lazy: true });
|
|
1651
|
+
this.signal = Object.freeze({ output: this.oscillator, rate: "a-rate", range: Object.freeze({ min: -1, max: 1 }) });
|
|
1652
|
+
try {
|
|
1653
|
+
this.oscillator.start();
|
|
1654
|
+
} catch (error) {
|
|
1655
|
+
this.frequency.dispose();
|
|
1656
|
+
this.oscillator.disconnect();
|
|
1657
|
+
throw error;
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
get waveform() {
|
|
1661
|
+
return this.oscillator.type;
|
|
1662
|
+
}
|
|
1663
|
+
setWaveform(waveform) {
|
|
1664
|
+
if (this.disposed) throw new Error("LFO is disposed.");
|
|
1665
|
+
validateWaveform(waveform);
|
|
1666
|
+
this.oscillator.type = waveform;
|
|
1667
|
+
}
|
|
1668
|
+
dispose() {
|
|
1669
|
+
if (this.disposed) return;
|
|
1670
|
+
this.disposed = true;
|
|
1671
|
+
let failure;
|
|
1672
|
+
try {
|
|
1673
|
+
this.frequency.dispose();
|
|
1674
|
+
} catch (error) {
|
|
1675
|
+
failure = error;
|
|
1676
|
+
}
|
|
1677
|
+
try {
|
|
1678
|
+
this.oscillator.stop();
|
|
1679
|
+
} catch (error) {
|
|
1680
|
+
_nullishCoalesce(failure, () => ( (failure = error)));
|
|
1681
|
+
}
|
|
1682
|
+
try {
|
|
1683
|
+
this.oscillator.disconnect();
|
|
1684
|
+
} catch (error) {
|
|
1685
|
+
_nullishCoalesce(failure, () => ( (failure = error)));
|
|
1686
|
+
}
|
|
1687
|
+
if (failure) throw failure;
|
|
1688
|
+
}
|
|
1689
|
+
};
|
|
1690
|
+
function validateWaveform(waveform) {
|
|
1691
|
+
if (!["sine", "square", "sawtooth", "triangle"].includes(waveform)) throw new TypeError("Unsupported LFO waveform.");
|
|
1692
|
+
}
|
|
1693
|
+
var ControlEnvelope = class {
|
|
1694
|
+
constructor(context, options = {}) {
|
|
1695
|
+
this.context = context;
|
|
1696
|
+
this.points = [{ time: 0, value: 0, linear: false }];
|
|
1697
|
+
this.disposed = false;
|
|
1698
|
+
this.options = { attack: _nullishCoalesce(options.attack, () => ( 0.01)), decay: _nullishCoalesce(options.decay, () => ( 0.1)), sustain: _nullishCoalesce(options.sustain, () => ( 0.7)), release: _nullishCoalesce(options.release, () => ( 0.2)) };
|
|
1699
|
+
for (const [name, value] of Object.entries(this.options)) {
|
|
1700
|
+
if (!Number.isFinite(value) || value < 0 || name === "sustain" && value > 1) throw new RangeError("Envelope times must be nonnegative and sustain must be in [0, 1].");
|
|
1701
|
+
}
|
|
1702
|
+
this.source = context.createConstantSource();
|
|
1703
|
+
this.source.offset.value = 0;
|
|
1704
|
+
this.signal = Object.freeze({ output: this.source, rate: "a-rate", range: Object.freeze({ min: 0, max: 1 }) });
|
|
1705
|
+
try {
|
|
1706
|
+
this.source.start();
|
|
1707
|
+
} catch (error) {
|
|
1708
|
+
this.source.disconnect();
|
|
1709
|
+
throw error;
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
trigger(time, velocity = 1) {
|
|
1713
|
+
const now = this.context.currentTime;
|
|
1714
|
+
time = time === void 0 ? now : time;
|
|
1715
|
+
this.validateTime(time, now);
|
|
1716
|
+
if (!Number.isFinite(velocity) || velocity < 0 || velocity > 1) throw new RangeError("Envelope velocity must be in [0, 1].");
|
|
1717
|
+
const held = this.valueAt(time);
|
|
1718
|
+
const peak = time + this.options.attack;
|
|
1719
|
+
const sustain = peak + this.options.decay;
|
|
1720
|
+
this.replace(time, [
|
|
1721
|
+
{ time, value: held, linear: false },
|
|
1722
|
+
{ time: peak, value: velocity, linear: this.options.attack > 0 },
|
|
1723
|
+
{ time: sustain, value: velocity * this.options.sustain, linear: this.options.decay > 0 }
|
|
1724
|
+
], now);
|
|
1725
|
+
}
|
|
1726
|
+
release(time) {
|
|
1727
|
+
const now = this.context.currentTime;
|
|
1728
|
+
time = time === void 0 ? now : time;
|
|
1729
|
+
this.validateTime(time, now);
|
|
1730
|
+
this.replace(time, [
|
|
1731
|
+
{ time, value: this.valueAt(time), linear: false },
|
|
1732
|
+
{ time: time + this.options.release, value: 0, linear: this.options.release > 0 }
|
|
1733
|
+
], now);
|
|
1734
|
+
}
|
|
1735
|
+
dispose() {
|
|
1736
|
+
if (this.disposed) return;
|
|
1737
|
+
this.disposed = true;
|
|
1738
|
+
try {
|
|
1739
|
+
this.source.stop();
|
|
1740
|
+
} finally {
|
|
1741
|
+
this.source.disconnect();
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
valueAt(time) {
|
|
1745
|
+
let previous = this.points[0];
|
|
1746
|
+
for (let index = 1; index < this.points.length; index++) {
|
|
1747
|
+
const point = this.points[index];
|
|
1748
|
+
if (time < point.time) {
|
|
1749
|
+
return point.linear ? previous.value + (point.value - previous.value) * (time - previous.time) / (point.time - previous.time) : previous.value;
|
|
1750
|
+
}
|
|
1751
|
+
previous = point;
|
|
1752
|
+
}
|
|
1753
|
+
return previous.value;
|
|
1754
|
+
}
|
|
1755
|
+
replace(time, points, now) {
|
|
1756
|
+
const prefix = this.points.filter((point) => point.time < time);
|
|
1757
|
+
const anchors = [{ ...points[0], linear: false }];
|
|
1758
|
+
if (time > now) {
|
|
1759
|
+
const previous = prefix[prefix.length - 1];
|
|
1760
|
+
const next = this.points.find((point) => point.time >= time);
|
|
1761
|
+
if (previous && _optionalChain([next, 'optionalAccess', _128 => _128.linear])) {
|
|
1762
|
+
const incoming = previous.value + (next.value - previous.value) * (time - previous.time) / (next.time - previous.time);
|
|
1763
|
+
anchors[0] = { time, value: incoming, linear: true };
|
|
1764
|
+
if (incoming !== points[0].value) anchors.push({ ...points[0], linear: false });
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
this.source.offset.cancelScheduledValues(time);
|
|
1768
|
+
const replacement = [...anchors, ...points.slice(1)];
|
|
1769
|
+
for (const point of replacement) {
|
|
1770
|
+
if (point.linear) this.source.offset.linearRampToValueAtTime(point.value, point.time);
|
|
1771
|
+
else this.source.offset.setValueAtTime(point.value, point.time);
|
|
1772
|
+
}
|
|
1773
|
+
const timeline = [...prefix, ...replacement];
|
|
1774
|
+
let first = 0;
|
|
1775
|
+
while (first + 1 < timeline.length && timeline[first + 1].time <= now) first++;
|
|
1776
|
+
this.points = first > 0 ? timeline.slice(first) : timeline;
|
|
1777
|
+
}
|
|
1778
|
+
validateTime(time, now) {
|
|
1779
|
+
if (this.disposed) throw new Error("Envelope is disposed.");
|
|
1780
|
+
if (!Number.isFinite(time) || time < now) throw new RangeError("Envelope time must be a finite current or future context time.");
|
|
1781
|
+
}
|
|
1782
|
+
};
|
|
1783
|
+
var EnvelopeFollower = class {
|
|
1784
|
+
constructor(context, options = {}) {
|
|
1785
|
+
this.disposed = false;
|
|
1786
|
+
const cutoff = _nullishCoalesce(options.smoothingHz, () => ( 20));
|
|
1787
|
+
if (!Number.isFinite(cutoff) || cutoff <= 0 || cutoff >= context.sampleRate / 2) throw new RangeError("Follower smoothing frequency must be positive and below Nyquist.");
|
|
1788
|
+
this.input = context.createGain();
|
|
1789
|
+
this.rectifier = context.createWaveShaper();
|
|
1790
|
+
const curve = new Float32Array(2049);
|
|
1791
|
+
for (let i = 0; i < curve.length; i++) curve[i] = Math.abs(i * 2 / (curve.length - 1) - 1);
|
|
1792
|
+
this.rectifier.curve = curve;
|
|
1793
|
+
const pole = Math.exp(-2 * Math.PI * cutoff / context.sampleRate);
|
|
1794
|
+
if (pole >= 1) throw new RangeError("Follower smoothing frequency is below native precision.");
|
|
1795
|
+
this.smoother = context.createIIRFilter([1 - pole], [1, -pole]);
|
|
1796
|
+
this.limiter = context.createWaveShaper();
|
|
1797
|
+
this.limiter.curve = new Float32Array([0, 0, 1]);
|
|
1798
|
+
try {
|
|
1799
|
+
this.input.connect(this.rectifier);
|
|
1800
|
+
this.rectifier.connect(this.smoother);
|
|
1801
|
+
this.smoother.connect(this.limiter);
|
|
1802
|
+
} catch (error) {
|
|
1803
|
+
for (const node of [this.input, this.rectifier, this.smoother, this.limiter]) {
|
|
1804
|
+
try {
|
|
1805
|
+
node.disconnect();
|
|
1806
|
+
} catch (e15) {
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
throw error;
|
|
1810
|
+
}
|
|
1811
|
+
this.signal = Object.freeze({ output: this.limiter, rate: "a-rate", range: Object.freeze({ min: 0, max: 1 }) });
|
|
1812
|
+
}
|
|
1813
|
+
dispose() {
|
|
1814
|
+
if (this.disposed) return;
|
|
1815
|
+
this.disposed = true;
|
|
1816
|
+
let failure;
|
|
1817
|
+
for (const node of [this.input, this.rectifier, this.smoother, this.limiter]) {
|
|
1818
|
+
try {
|
|
1819
|
+
node.disconnect();
|
|
1820
|
+
} catch (error) {
|
|
1821
|
+
_nullishCoalesce(failure, () => ( (failure = error)));
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
if (failure) throw failure;
|
|
1825
|
+
}
|
|
1826
|
+
};
|
|
1827
|
+
|
|
1828
|
+
// src/module/param-macro.ts
|
|
1829
|
+
var ParamMacro = class {
|
|
1830
|
+
constructor(targets, options = {}) {
|
|
1831
|
+
this.disposed = false;
|
|
1832
|
+
this.applying = false;
|
|
1833
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
1834
|
+
const entries = [...targets];
|
|
1835
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1836
|
+
for (const entry of entries) {
|
|
1837
|
+
if (seen.has(entry.target)) throw new Error("A macro cannot map one parameter twice.");
|
|
1838
|
+
seen.add(entry.target);
|
|
1839
|
+
const { min, max } = entry.target.descriptor.range;
|
|
1840
|
+
if (!Number.isFinite(entry.min) || !Number.isFinite(entry.max) || Math.min(entry.min, entry.max) < min || Math.max(entry.min, entry.max) > max) throw new RangeError("Macro mapping endpoints must fit the target legal range.");
|
|
1841
|
+
if (entry.target.snapshot.disposed) throw new Error("Macro target is disposed.");
|
|
1842
|
+
}
|
|
1843
|
+
this.current = _nullishCoalesce(options.value, () => ( 0));
|
|
1844
|
+
this.validate(this.current);
|
|
1845
|
+
this.targets = Object.freeze(entries.map((entry) => Object.freeze({ ...entry })));
|
|
1846
|
+
}
|
|
1847
|
+
get value() {
|
|
1848
|
+
return this.current;
|
|
1849
|
+
}
|
|
1850
|
+
setValue(value) {
|
|
1851
|
+
if (this.disposed) throw new Error("Macro is disposed.");
|
|
1852
|
+
if (this.applying) throw new Error("Macro updates cannot re-enter.");
|
|
1853
|
+
this.validate(value);
|
|
1854
|
+
const changes = this.targets.map((entry) => {
|
|
1855
|
+
if (entry.target.snapshot.disposed) throw new Error("Macro target is disposed.");
|
|
1856
|
+
return { target: entry.target, before: entry.target.snapshot.baseValue, after: entry.min + value * (entry.max - entry.min) };
|
|
1857
|
+
});
|
|
1858
|
+
this.applying = true;
|
|
1859
|
+
let applied = 0;
|
|
1860
|
+
try {
|
|
1861
|
+
for (const change of changes) {
|
|
1862
|
+
change.target.setBaseValue(change.after);
|
|
1863
|
+
applied++;
|
|
1864
|
+
if (this.disposed) throw new Error("Macro disposed during update.");
|
|
1865
|
+
}
|
|
1866
|
+
this.current = value;
|
|
1867
|
+
} catch (error) {
|
|
1868
|
+
for (const change of changes.slice(0, applied).reverse()) {
|
|
1869
|
+
try {
|
|
1870
|
+
change.target.setBaseValue(change.before);
|
|
1871
|
+
} catch (e16) {
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
throw error;
|
|
1875
|
+
} finally {
|
|
1876
|
+
this.applying = false;
|
|
1877
|
+
}
|
|
1878
|
+
for (const entry of [...this.listeners]) {
|
|
1879
|
+
if (this.current !== value || this.disposed) break;
|
|
1880
|
+
if (!this.listeners.has(entry)) continue;
|
|
1881
|
+
try {
|
|
1882
|
+
const result = entry.listener(value);
|
|
1883
|
+
if (result != null && typeof result.then === "function") void Promise.resolve(result).catch(() => {
|
|
1884
|
+
});
|
|
1885
|
+
} catch (e17) {
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
subscribe(listener) {
|
|
1890
|
+
if (this.disposed) return () => {
|
|
1891
|
+
};
|
|
1892
|
+
const entry = { listener };
|
|
1893
|
+
this.listeners.add(entry);
|
|
1894
|
+
return () => {
|
|
1895
|
+
this.listeners.delete(entry);
|
|
1896
|
+
};
|
|
1897
|
+
}
|
|
1898
|
+
dispose() {
|
|
1899
|
+
this.disposed = true;
|
|
1900
|
+
this.listeners.clear();
|
|
1901
|
+
}
|
|
1902
|
+
validate(value) {
|
|
1903
|
+
if (!Number.isFinite(value) || value < 0 || value > 1) throw new RangeError("Macro value must be in [0, 1].");
|
|
1904
|
+
}
|
|
1905
|
+
};
|
|
1906
|
+
|
|
1907
|
+
// src/module/project-schema.ts
|
|
1908
|
+
var MAX_BYTES = 2 * 1024 * 1024;
|
|
1909
|
+
var MAX_NODES = 5e4;
|
|
1910
|
+
var MAX_ITEMS = 1e4;
|
|
1911
|
+
var forbiddenKeys = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
1912
|
+
function copyProjectJson(input) {
|
|
1913
|
+
const ancestors = /* @__PURE__ */ new Set();
|
|
1914
|
+
let nodes = 0;
|
|
1915
|
+
let bytes = 0;
|
|
1916
|
+
const copy = (value, depth) => {
|
|
1917
|
+
if (++nodes > MAX_NODES || depth > 32) throw new RangeError("Project JSON exceeds structural limits.");
|
|
1918
|
+
if (value === null || typeof value === "boolean") return value;
|
|
1919
|
+
if (typeof value === "string") {
|
|
1920
|
+
bytes += value.length * 2;
|
|
1921
|
+
if (value.length > 65536 || bytes > MAX_BYTES) throw new RangeError("Project JSON exceeds string limits.");
|
|
1922
|
+
return value;
|
|
1923
|
+
}
|
|
1924
|
+
if (typeof value === "number") {
|
|
1925
|
+
if (!Number.isFinite(value)) throw new TypeError("Project numbers must be finite.");
|
|
1926
|
+
return value;
|
|
1927
|
+
}
|
|
1928
|
+
if (typeof value !== "object") throw new TypeError("Project values must be plain JSON data.");
|
|
1929
|
+
if (ancestors.has(value)) throw new TypeError("Project JSON cannot contain object cycles.");
|
|
1930
|
+
const prototype = Object.getPrototypeOf(value);
|
|
1931
|
+
const array = Array.isArray(value);
|
|
1932
|
+
if (!array && prototype !== Object.prototype && prototype !== null) throw new TypeError("Project objects must have plain prototypes.");
|
|
1933
|
+
if (array && value.length > MAX_ITEMS) throw new RangeError("Project array exceeds item limit.");
|
|
1934
|
+
ancestors.add(value);
|
|
1935
|
+
try {
|
|
1936
|
+
const output = array ? [] : {};
|
|
1937
|
+
const keys = Reflect.ownKeys(value);
|
|
1938
|
+
if (keys.length > MAX_ITEMS + 1) throw new RangeError("Project object exceeds item limit.");
|
|
1939
|
+
for (const key of keys) {
|
|
1940
|
+
if (array && key === "length") continue;
|
|
1941
|
+
if (typeof key !== "string" || forbiddenKeys.has(key)) throw new TypeError("Project JSON contains an unsafe property key.");
|
|
1942
|
+
if (array && (!/^(0|[1-9][0-9]*)$/.test(key) || Number(key) >= value.length)) throw new TypeError("Project arrays must contain only indexed values.");
|
|
1943
|
+
bytes += key.length * 2;
|
|
1944
|
+
if (bytes > MAX_BYTES) throw new RangeError("Project JSON exceeds size limit.");
|
|
1945
|
+
const property = Object.getOwnPropertyDescriptor(value, key);
|
|
1946
|
+
if (!property.enumerable || !("value" in property)) throw new TypeError("Project JSON must not contain accessors or hidden properties.");
|
|
1947
|
+
output[key] = copy(property.value, depth + 1);
|
|
1948
|
+
}
|
|
1949
|
+
if (array && output.length !== value.length) throw new TypeError("Project arrays must not contain holes.");
|
|
1950
|
+
if (array && Object.keys(output).length !== value.length) throw new TypeError("Project arrays must not contain holes.");
|
|
1951
|
+
return Object.freeze(output);
|
|
1952
|
+
} finally {
|
|
1953
|
+
ancestors.delete(value);
|
|
1954
|
+
}
|
|
1955
|
+
};
|
|
1956
|
+
return copy(input, 0);
|
|
1957
|
+
}
|
|
1958
|
+
function object(value, path) {
|
|
1959
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new TypeError(`${path} must be an object.`);
|
|
1960
|
+
return value;
|
|
1961
|
+
}
|
|
1962
|
+
function fields(data, allowed, path) {
|
|
1963
|
+
for (const key of Object.keys(data)) if (!allowed.includes(key)) throw new TypeError(`${path}.${key} is not a supported field.`);
|
|
1964
|
+
}
|
|
1965
|
+
function text2(value, path, max = 256) {
|
|
1966
|
+
if (typeof value !== "string" || !value || value !== value.trim() || value.length > max) throw new TypeError(`${path} must be a nonempty trimmed string of at most ${max} characters.`);
|
|
1967
|
+
return value;
|
|
1968
|
+
}
|
|
1969
|
+
function number(value, path, min = -Infinity, max = Infinity) {
|
|
1970
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < min || value > max) throw new TypeError(`${path} must be a finite number in range.`);
|
|
1971
|
+
return value;
|
|
1972
|
+
}
|
|
1973
|
+
function list(value, path) {
|
|
1974
|
+
if (value === void 0) return [];
|
|
1975
|
+
if (!Array.isArray(value)) throw new TypeError(`${path} must be an array.`);
|
|
1976
|
+
return value;
|
|
1977
|
+
}
|
|
1978
|
+
function enumeration(value, choices, path) {
|
|
1979
|
+
if (!choices.includes(value)) throw new TypeError(`${path} has an unsupported value.`);
|
|
1980
|
+
return value;
|
|
1981
|
+
}
|
|
1982
|
+
function optionalText(data, key, path) {
|
|
1983
|
+
return data[key] === void 0 ? void 0 : text2(data[key], `${path}.${key}`, key === "label" ? 1024 : 256);
|
|
1984
|
+
}
|
|
1985
|
+
function unique(items, path) {
|
|
1986
|
+
const result = /* @__PURE__ */ new Map();
|
|
1987
|
+
for (const item of items) {
|
|
1988
|
+
if (result.has(item.id)) throw new TypeError(`${path} contains duplicate ID ${item.id}.`);
|
|
1989
|
+
result.set(item.id, item);
|
|
1990
|
+
}
|
|
1991
|
+
return result;
|
|
1992
|
+
}
|
|
1993
|
+
function endpoint(value, path) {
|
|
1994
|
+
const data = object(value, path);
|
|
1995
|
+
fields(data, ["moduleId", "port"], path);
|
|
1996
|
+
return { moduleId: text2(data.moduleId, `${path}.moduleId`), port: text2(data.port, `${path}.port`) };
|
|
1997
|
+
}
|
|
1998
|
+
function parameter(value, path) {
|
|
1999
|
+
const data = object(value, path);
|
|
2000
|
+
fields(data, ["moduleId", "param"], path);
|
|
2001
|
+
return { moduleId: text2(data.moduleId, `${path}.moduleId`), param: text2(data.param, `${path}.param`) };
|
|
2002
|
+
}
|
|
2003
|
+
function layout(value) {
|
|
2004
|
+
const data = object(_nullishCoalesce(value, () => ( {})), "layout");
|
|
2005
|
+
fields(data, ["modules", "presentation", "comments", "groups", "style", "page"], "layout");
|
|
2006
|
+
const modules = positions(data.modules, "layout.modules");
|
|
2007
|
+
const presentation = data.presentation === void 0 ? void 0 : positions(data.presentation, "layout.presentation");
|
|
2008
|
+
const commentIds = /* @__PURE__ */ new Set();
|
|
2009
|
+
const comments = data.comments === void 0 ? void 0 : list(data.comments, "layout.comments").map((entry, index) => {
|
|
2010
|
+
const path = `layout.comments[${index}]`, item = object(entry, path);
|
|
2011
|
+
fields(item, ["id", "contextId", "text", "x", "y"], path);
|
|
2012
|
+
const id = text2(item.id, `${path}.id`);
|
|
2013
|
+
if (commentIds.has(id)) throw new TypeError(`Duplicate layout comment ${id}.`);
|
|
2014
|
+
commentIds.add(id);
|
|
2015
|
+
if (typeof item.text !== "string" || item.text.length > 4e3) throw new TypeError(`${path}.text must be a string of at most 4000 characters.`);
|
|
2016
|
+
return { id, contextId: text2(item.contextId, `${path}.contextId`), text: item.text, x: number(item.x, `${path}.x`, -1e7, 1e7), y: number(item.y, `${path}.y`, -1e7, 1e7) };
|
|
2017
|
+
});
|
|
2018
|
+
const groupIds = /* @__PURE__ */ new Set();
|
|
2019
|
+
const grouped = /* @__PURE__ */ new Set();
|
|
2020
|
+
const groups = data.groups === void 0 ? void 0 : list(data.groups, "layout.groups").map((entry, index) => {
|
|
2021
|
+
const path = `layout.groups[${index}]`, item = object(entry, path);
|
|
2022
|
+
fields(item, ["id", "moduleIds"], path);
|
|
2023
|
+
const id = text2(item.id, `${path}.id`);
|
|
2024
|
+
if (groupIds.has(id)) throw new TypeError(`Duplicate layout group ${id}.`);
|
|
2025
|
+
groupIds.add(id);
|
|
2026
|
+
const moduleIds = list(item.moduleIds, `${path}.moduleIds`).map((moduleId, member) => text2(moduleId, `${path}.moduleIds[${member}]`));
|
|
2027
|
+
if (moduleIds.length < 2) throw new TypeError(`${path} must group at least two modules.`);
|
|
2028
|
+
for (const moduleId of moduleIds) {
|
|
2029
|
+
if (grouped.has(moduleId)) throw new TypeError(`Module ${moduleId} belongs to more than one group.`);
|
|
2030
|
+
grouped.add(moduleId);
|
|
2031
|
+
}
|
|
2032
|
+
return { id, moduleIds };
|
|
2033
|
+
});
|
|
2034
|
+
const style = data.style === void 0 ? void 0 : customProperties(data.style, "layout.style");
|
|
2035
|
+
const page = data.page === void 0 ? void 0 : object(data.page, "layout.page");
|
|
2036
|
+
return {
|
|
2037
|
+
modules,
|
|
2038
|
+
...presentation ? { presentation } : {},
|
|
2039
|
+
...comments ? { comments } : {},
|
|
2040
|
+
...groups ? { groups } : {},
|
|
2041
|
+
...style && Object.keys(style).length ? { style } : {},
|
|
2042
|
+
...page ? { page } : {}
|
|
2043
|
+
};
|
|
2044
|
+
}
|
|
2045
|
+
var CUSTOM_PROPERTY = /^--[a-z0-9][a-z0-9-]{0,126}$/;
|
|
2046
|
+
function customProperties(value, path) {
|
|
2047
|
+
const entries = Object.entries(object(value, path));
|
|
2048
|
+
if (entries.length > 256) throw new RangeError(`${path} holds at most 256 properties.`);
|
|
2049
|
+
const out = {};
|
|
2050
|
+
for (const [name, item] of entries) {
|
|
2051
|
+
if (!CUSTOM_PROPERTY.test(name)) throw new TypeError(`${path} names must be custom properties: two hyphens, then lowercase letters, digits and hyphens.`);
|
|
2052
|
+
if (typeof item !== "string" || !item.trim() || item.length > 256) throw new TypeError(`${path}.${name} must be a nonempty string of at most 256 characters.`);
|
|
2053
|
+
out[name] = item;
|
|
2054
|
+
}
|
|
2055
|
+
return out;
|
|
2056
|
+
}
|
|
2057
|
+
function mappings(value) {
|
|
2058
|
+
if (value === void 0) return void 0;
|
|
2059
|
+
const ids = /* @__PURE__ */ new Set();
|
|
2060
|
+
return list(value, "mappings").map((entry, index) => {
|
|
2061
|
+
const path = `mappings[${index}]`, item = object(entry, path);
|
|
2062
|
+
fields(item, ["id", "source", "target", "min", "max"], path);
|
|
2063
|
+
const id = text2(item.id, `${path}.id`);
|
|
2064
|
+
if (ids.has(id)) throw new TypeError(`Duplicate mapping ${id}.`);
|
|
2065
|
+
ids.add(id);
|
|
2066
|
+
const sourceData = object(item.source, `${path}.source`);
|
|
2067
|
+
const kind = enumeration(sourceData.kind, ["cc", "pitchbend", "program", "pressure", "key"], `${path}.source.kind`);
|
|
2068
|
+
const channel = () => sourceData.channel === void 0 ? {} : { channel: number(sourceData.channel, `${path}.source.channel`, 0, 15) };
|
|
2069
|
+
let source;
|
|
2070
|
+
if (kind === "cc") {
|
|
2071
|
+
fields(sourceData, ["kind", "controller", "channel"], `${path}.source`);
|
|
2072
|
+
source = { kind, controller: number(sourceData.controller, `${path}.source.controller`, 0, 127), ...channel() };
|
|
2073
|
+
} else if (kind === "key") {
|
|
2074
|
+
fields(sourceData, ["kind", "key"], `${path}.source`);
|
|
2075
|
+
source = { kind, key: text2(sourceData.key, `${path}.source.key`) };
|
|
2076
|
+
} else {
|
|
2077
|
+
fields(sourceData, ["kind", "channel"], `${path}.source`);
|
|
2078
|
+
source = { kind, ...channel() };
|
|
2079
|
+
}
|
|
2080
|
+
return {
|
|
2081
|
+
id,
|
|
2082
|
+
source,
|
|
2083
|
+
target: parameter(item.target, `${path}.target`),
|
|
2084
|
+
...item.min !== void 0 ? { min: number(item.min, `${path}.min`) } : {},
|
|
2085
|
+
...item.max !== void 0 ? { max: number(item.max, `${path}.max`) } : {}
|
|
2086
|
+
};
|
|
2087
|
+
});
|
|
2088
|
+
}
|
|
2089
|
+
function positions(value, name) {
|
|
2090
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2091
|
+
return list(value, name).map((entry, index) => {
|
|
2092
|
+
const path = `${name}[${index}]`, item = object(entry, path);
|
|
2093
|
+
fields(item, ["moduleId", "x", "y", "collapsed", "width", "height"], path);
|
|
2094
|
+
const moduleId = text2(item.moduleId, `${path}.moduleId`);
|
|
2095
|
+
if (seen.has(moduleId)) throw new TypeError(`Duplicate layout module ${moduleId}.`);
|
|
2096
|
+
seen.add(moduleId);
|
|
2097
|
+
if (item.collapsed !== void 0 && typeof item.collapsed !== "boolean") throw new TypeError(`${path}.collapsed must be boolean.`);
|
|
2098
|
+
return {
|
|
2099
|
+
moduleId,
|
|
2100
|
+
x: number(item.x, `${path}.x`, -1e7, 1e7),
|
|
2101
|
+
y: number(item.y, `${path}.y`, -1e7, 1e7),
|
|
2102
|
+
...item.collapsed !== void 0 ? { collapsed: item.collapsed } : {},
|
|
2103
|
+
...item.width !== void 0 ? { width: number(item.width, `${path}.width`, 1, 1e5) } : {},
|
|
2104
|
+
...item.height !== void 0 ? { height: number(item.height, `${path}.height`, 1, 1e5) } : {}
|
|
2105
|
+
};
|
|
2106
|
+
});
|
|
2107
|
+
}
|
|
2108
|
+
function session(value) {
|
|
2109
|
+
const data = object(_nullishCoalesce(value, () => ( {})), "session");
|
|
2110
|
+
fields(data, ["positionSeconds", "rate", "loop", "tempo"], "session");
|
|
2111
|
+
let tempo;
|
|
2112
|
+
if (data.tempo !== void 0) {
|
|
2113
|
+
const value2 = object(data.tempo, "session.tempo");
|
|
2114
|
+
fields(value2, ["bpm", "beatsPerBar", "beatUnit"], "session.tempo");
|
|
2115
|
+
const beatUnit = number(_nullishCoalesce(value2.beatUnit, () => ( 4)), "session.tempo.beatUnit", 1, 32);
|
|
2116
|
+
if (![1, 2, 4, 8, 16, 32].includes(beatUnit)) throw new TypeError("session.tempo.beatUnit must be 1, 2, 4, 8, 16 or 32.");
|
|
2117
|
+
const beatsPerBar = number(_nullishCoalesce(value2.beatsPerBar, () => ( 4)), "session.tempo.beatsPerBar", 1, 64);
|
|
2118
|
+
if (!Number.isInteger(beatsPerBar)) throw new TypeError("session.tempo.beatsPerBar must be an integer.");
|
|
2119
|
+
tempo = { bpm: number(value2.bpm, "session.tempo.bpm", Number.MIN_VALUE, 1e3), beatsPerBar, beatUnit };
|
|
2120
|
+
}
|
|
2121
|
+
let loop;
|
|
2122
|
+
if (data.loop === null) loop = null;
|
|
2123
|
+
else if (data.loop !== void 0) {
|
|
2124
|
+
const region = object(data.loop, "session.loop");
|
|
2125
|
+
fields(region, ["startSeconds", "endSeconds"], "session.loop");
|
|
2126
|
+
const startSeconds = number(region.startSeconds, "session.loop.startSeconds", 0);
|
|
2127
|
+
const endSeconds = number(region.endSeconds, "session.loop.endSeconds", 0);
|
|
2128
|
+
if (endSeconds <= startSeconds) throw new TypeError("Session loop end must follow start.");
|
|
2129
|
+
loop = { startSeconds, endSeconds };
|
|
2130
|
+
}
|
|
2131
|
+
return {
|
|
2132
|
+
positionSeconds: number(_nullishCoalesce(data.positionSeconds, () => ( 0)), "session.positionSeconds", 0),
|
|
2133
|
+
rate: number(_nullishCoalesce(data.rate, () => ( 1)), "session.rate", Number.MIN_VALUE),
|
|
2134
|
+
...loop !== void 0 ? { loop } : {},
|
|
2135
|
+
...tempo ? { tempo } : {}
|
|
2136
|
+
};
|
|
2137
|
+
}
|
|
2138
|
+
function parseModuleProject(input) {
|
|
2139
|
+
if (typeof input === "string") {
|
|
2140
|
+
if (input.length > MAX_BYTES) throw new RangeError("Project JSON text exceeds size limit.");
|
|
2141
|
+
input = JSON.parse(input);
|
|
2142
|
+
}
|
|
2143
|
+
const data = object(copyProjectJson(input), "project");
|
|
2144
|
+
fields(data, ["schema", "version", "id", "contexts", "modules", "assets", "connections", "modulations", "macros", "automation", "session", "layout", "mappings"], "project");
|
|
2145
|
+
if (data.schema !== "webmusic.module-project" || data.version !== 1) throw new TypeError("Unsupported module project schema/version.");
|
|
2146
|
+
const contexts = list(data.contexts, "contexts").map((entry, index) => {
|
|
2147
|
+
const path = `contexts[${index}]`, item = object(entry, path);
|
|
2148
|
+
fields(item, ["id", "parentId", "ownerModuleId"], path);
|
|
2149
|
+
const parentId = optionalText(item, "parentId", path), ownerModuleId = optionalText(item, "ownerModuleId", path);
|
|
2150
|
+
return { id: text2(item.id, `${path}.id`), ...parentId ? { parentId } : {}, ...ownerModuleId ? { ownerModuleId } : {} };
|
|
2151
|
+
});
|
|
2152
|
+
const assets = list(data.assets, "assets").map((entry, index) => {
|
|
2153
|
+
const path = `assets[${index}]`, item = object(entry, path);
|
|
2154
|
+
fields(item, ["id", "uri", "mediaType", "integrity"], path);
|
|
2155
|
+
const mediaType = optionalText(item, "mediaType", path), integrity = optionalText(item, "integrity", path);
|
|
2156
|
+
return { id: text2(item.id, `${path}.id`), uri: text2(item.uri, `${path}.uri`, 8192), ...mediaType ? { mediaType } : {}, ...integrity ? { integrity } : {} };
|
|
2157
|
+
});
|
|
2158
|
+
const modules = list(data.modules, "modules").map((entry, index) => {
|
|
2159
|
+
const path = `modules[${index}]`, item = object(entry, path);
|
|
2160
|
+
fields(item, ["id", "plugin", "contextId", "label", "config", "assets", "params"], path);
|
|
2161
|
+
const plugin = object(item.plugin, `${path}.plugin`);
|
|
2162
|
+
fields(plugin, ["id", "version"], `${path}.plugin`);
|
|
2163
|
+
const label = optionalText(item, "label", path);
|
|
2164
|
+
const config = object(_nullishCoalesce(item.config, () => ( {})), `${path}.config`);
|
|
2165
|
+
let roles, params;
|
|
2166
|
+
if (item.assets !== void 0) {
|
|
2167
|
+
roles = {};
|
|
2168
|
+
for (const [role, value] of Object.entries(object(item.assets, `${path}.assets`))) roles[text2(role, `${path}.asset role`)] = text2(value, `${path}.assets.${role}`);
|
|
2169
|
+
}
|
|
2170
|
+
if (item.params !== void 0) {
|
|
2171
|
+
params = {};
|
|
2172
|
+
for (const [id, value] of Object.entries(object(item.params, `${path}.params`))) params[text2(id, `${path}.parameter ID`)] = number(value, `${path}.params.${id}`);
|
|
2173
|
+
}
|
|
2174
|
+
return {
|
|
2175
|
+
id: text2(item.id, `${path}.id`),
|
|
2176
|
+
contextId: text2(item.contextId, `${path}.contextId`),
|
|
2177
|
+
plugin: { id: text2(plugin.id, `${path}.plugin.id`), version: text2(plugin.version, `${path}.plugin.version`) },
|
|
2178
|
+
config,
|
|
2179
|
+
...label ? { label } : {},
|
|
2180
|
+
...roles ? { assets: roles } : {},
|
|
2181
|
+
...params ? { params } : {}
|
|
2182
|
+
};
|
|
2183
|
+
});
|
|
2184
|
+
const connections = list(data.connections, "connections").map((entry, index) => {
|
|
2185
|
+
const path = `connections[${index}]`, item = object(entry, path);
|
|
2186
|
+
fields(item, ["id", "kind", "from", "to", "mode"], path);
|
|
2187
|
+
const kind = enumeration(item.kind, ["audio", "control", "note", "transport", "source", "message"], `${path}.kind`);
|
|
2188
|
+
const mode = item.mode === void 0 ? void 0 : enumeration(item.mode, ["replace", "send", "tap"], `${path}.mode`);
|
|
2189
|
+
if (kind !== "audio" && mode !== void 0) throw new TypeError("Only audio connections have routing modes.");
|
|
2190
|
+
return { id: text2(item.id, `${path}.id`), kind, from: endpoint(item.from, `${path}.from`), to: endpoint(item.to, `${path}.to`), ...mode ? { mode } : {} };
|
|
2191
|
+
});
|
|
2192
|
+
const modulations = list(data.modulations, "modulations").map((entry, index) => {
|
|
2193
|
+
const path = `modulations[${index}]`, item = object(entry, path);
|
|
2194
|
+
fields(item, ["id", "source", "target", "depth", "polarity"], path);
|
|
2195
|
+
const polarity = item.polarity === void 0 ? void 0 : enumeration(item.polarity, ["bipolar", "unipolar"], `${path}.polarity`);
|
|
2196
|
+
return { id: text2(item.id, `${path}.id`), source: endpoint(item.source, `${path}.source`), target: parameter(item.target, `${path}.target`), depth: number(item.depth, `${path}.depth`), ...polarity ? { polarity } : {} };
|
|
2197
|
+
});
|
|
2198
|
+
const macros = list(data.macros, "macros").map((entry, index) => {
|
|
2199
|
+
const path = `macros[${index}]`, item = object(entry, path);
|
|
2200
|
+
fields(item, ["id", "label", "value", "targets"], path);
|
|
2201
|
+
const label = optionalText(item, "label", path);
|
|
2202
|
+
const targets = list(item.targets, `${path}.targets`).map((target, targetIndex) => {
|
|
2203
|
+
const place = `${path}.targets[${targetIndex}]`, targetData = object(target, place);
|
|
2204
|
+
fields(targetData, ["moduleId", "param", "min", "max"], place);
|
|
2205
|
+
return { ...parameter({ moduleId: targetData.moduleId, param: targetData.param }, place), min: number(targetData.min, `${place}.min`), max: number(targetData.max, `${place}.max`) };
|
|
2206
|
+
});
|
|
2207
|
+
return { id: text2(item.id, `${path}.id`), value: number(item.value, `${path}.value`, 0, 1), targets, ...label ? { label } : {} };
|
|
2208
|
+
});
|
|
2209
|
+
const automation = list(data.automation, "automation").map((entry, index) => {
|
|
2210
|
+
const path = `automation[${index}]`, item = object(entry, path);
|
|
2211
|
+
fields(item, ["id", "target", "points", "loop", "enabled", "initialValue"], path);
|
|
2212
|
+
if (item.enabled !== void 0 && typeof item.enabled !== "boolean") throw new TypeError(`${path}.enabled must be boolean.`);
|
|
2213
|
+
let previous = -Infinity;
|
|
2214
|
+
const points = list(item.points, `${path}.points`).map((point, pointIndex) => {
|
|
2215
|
+
const place = `${path}.points[${pointIndex}]`, event = object(point, place);
|
|
2216
|
+
fields(event, ["type", "value", "timeSeconds"], place);
|
|
2217
|
+
const type = enumeration(event.type, ["set", "linear", "exponential"], `${place}.type`);
|
|
2218
|
+
const timeSeconds = number(event.timeSeconds, `${place}.timeSeconds`, 0), value = number(event.value, `${place}.value`);
|
|
2219
|
+
if (timeSeconds < previous) throw new TypeError("Automation points must be ordered by time.");
|
|
2220
|
+
if (type === "exponential" && value <= 0) throw new TypeError("Exponential automation requires positive values.");
|
|
2221
|
+
previous = timeSeconds;
|
|
2222
|
+
return { type, value, timeSeconds };
|
|
2223
|
+
});
|
|
2224
|
+
const loop = item.loop === void 0 ? void 0 : enumeration(item.loop, ["repeat", "once"], `${path}.loop`);
|
|
2225
|
+
return { id: text2(item.id, `${path}.id`), target: parameter(item.target, `${path}.target`), points, ...loop ? { loop } : {}, ...item.enabled !== void 0 ? { enabled: item.enabled } : {}, ...item.initialValue !== void 0 ? { initialValue: number(item.initialValue, `${path}.initialValue`) } : {} };
|
|
2226
|
+
});
|
|
2227
|
+
const project = { schema: "webmusic.module-project", version: 1, id: text2(data.id, "project.id"), contexts, modules, assets, connections, modulations, macros, automation, session: session(data.session), layout: layout(data.layout) };
|
|
2228
|
+
const mapped = mappings(data.mappings);
|
|
2229
|
+
if (mapped) project.mappings = mapped;
|
|
2230
|
+
validateReferences(project);
|
|
2231
|
+
return copyProjectJson(project);
|
|
2232
|
+
}
|
|
2233
|
+
function validateReferences(project) {
|
|
2234
|
+
const contexts = unique(project.contexts, "contexts"), modules = unique(project.modules, "modules"), assets = unique(project.assets, "assets");
|
|
2235
|
+
for (const [name, entries] of [["connections", project.connections], ["modulations", project.modulations], ["macros", project.macros], ["automation", project.automation]]) unique(entries, name);
|
|
2236
|
+
if (project.contexts.filter((context) => !context.parentId).length !== 1) throw new TypeError("A project requires exactly one root context.");
|
|
2237
|
+
for (const context of project.contexts) {
|
|
2238
|
+
const visited = /* @__PURE__ */ new Set();
|
|
2239
|
+
let current = context;
|
|
2240
|
+
while (current) {
|
|
2241
|
+
if (visited.has(current.id)) throw new TypeError("Project context topology contains a cycle.");
|
|
2242
|
+
visited.add(current.id);
|
|
2243
|
+
if (visited.size > 128) throw new RangeError("Project context nesting exceeds 128 scopes.");
|
|
2244
|
+
if (current.parentId && !contexts.has(current.parentId)) throw new TypeError(`Missing parent context ${current.parentId}.`);
|
|
2245
|
+
current = current.parentId ? contexts.get(current.parentId) : void 0;
|
|
2246
|
+
}
|
|
2247
|
+
if (context.ownerModuleId) {
|
|
2248
|
+
const owner = modules.get(context.ownerModuleId);
|
|
2249
|
+
if (!context.parentId || !owner || owner.contextId !== context.parentId) throw new TypeError("A context owner must belong to its direct parent context.");
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2252
|
+
const requireModule = (id) => {
|
|
2253
|
+
if (!modules.has(id)) throw new TypeError(`Project references missing module ${id}.`);
|
|
2254
|
+
};
|
|
2255
|
+
for (const module of project.modules) {
|
|
2256
|
+
if (!contexts.has(module.contextId)) throw new TypeError(`Module ${module.id} references missing context ${module.contextId}.`);
|
|
2257
|
+
for (const id of Object.values(_nullishCoalesce(module.assets, () => ( {})))) if (!assets.has(id)) throw new TypeError(`Module ${module.id} references missing asset ${id}.`);
|
|
2258
|
+
}
|
|
2259
|
+
const routes = /* @__PURE__ */ new Map();
|
|
2260
|
+
const replacements = /* @__PURE__ */ new Set();
|
|
2261
|
+
for (const connection of project.connections) {
|
|
2262
|
+
requireModule(connection.from.moduleId);
|
|
2263
|
+
requireModule(connection.to.moduleId);
|
|
2264
|
+
if (connection.kind === "audio") {
|
|
2265
|
+
const next = _nullishCoalesce(routes.get(connection.from.moduleId), () => ( /* @__PURE__ */ new Set()));
|
|
2266
|
+
next.add(connection.to.moduleId);
|
|
2267
|
+
routes.set(connection.from.moduleId, next);
|
|
2268
|
+
if ((_nullishCoalesce(connection.mode, () => ( "replace"))) === "replace") {
|
|
2269
|
+
const key = JSON.stringify(connection.from);
|
|
2270
|
+
if (replacements.has(key)) throw new TypeError("An audio output can have only one replacement connection.");
|
|
2271
|
+
replacements.add(key);
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
}
|
|
2275
|
+
const degrees = /* @__PURE__ */ new Map();
|
|
2276
|
+
for (const [source, targets] of routes) {
|
|
2277
|
+
if (!degrees.has(source)) degrees.set(source, 0);
|
|
2278
|
+
for (const target of targets) degrees.set(target, (_nullishCoalesce(degrees.get(target), () => ( 0))) + 1);
|
|
2279
|
+
}
|
|
2280
|
+
const ready = [...degrees.keys()].filter((id) => degrees.get(id) === 0);
|
|
2281
|
+
let consumed = 0;
|
|
2282
|
+
for (let index = 0; index < ready.length; index++) {
|
|
2283
|
+
const id = ready[index];
|
|
2284
|
+
consumed++;
|
|
2285
|
+
for (const target of _nullishCoalesce(routes.get(id), () => ( []))) {
|
|
2286
|
+
const remaining = degrees.get(target) - 1;
|
|
2287
|
+
degrees.set(target, remaining);
|
|
2288
|
+
if (remaining === 0) ready.push(target);
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
if (consumed !== degrees.size) throw new TypeError("Project audio connections contain a feedback cycle.");
|
|
2292
|
+
for (const modulation of project.modulations) {
|
|
2293
|
+
requireModule(modulation.source.moduleId);
|
|
2294
|
+
requireModule(modulation.target.moduleId);
|
|
2295
|
+
}
|
|
2296
|
+
for (const macro of project.macros) {
|
|
2297
|
+
const targets = /* @__PURE__ */ new Set();
|
|
2298
|
+
for (const target of macro.targets) {
|
|
2299
|
+
requireModule(target.moduleId);
|
|
2300
|
+
const key = JSON.stringify([target.moduleId, target.param]);
|
|
2301
|
+
if (targets.has(key)) throw new TypeError("A macro cannot map one target twice.");
|
|
2302
|
+
targets.add(key);
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
const automated = /* @__PURE__ */ new Set();
|
|
2306
|
+
for (const automation of project.automation) {
|
|
2307
|
+
requireModule(automation.target.moduleId);
|
|
2308
|
+
const key = JSON.stringify(automation.target);
|
|
2309
|
+
if (automated.has(key)) throw new TypeError("A parameter can have only one project automation track.");
|
|
2310
|
+
automated.add(key);
|
|
2311
|
+
}
|
|
2312
|
+
for (const position of project.layout.modules) requireModule(position.moduleId);
|
|
2313
|
+
for (const position of _nullishCoalesce(project.layout.presentation, () => ( []))) requireModule(position.moduleId);
|
|
2314
|
+
for (const comment of _nullishCoalesce(project.layout.comments, () => ( []))) if (!contexts.has(comment.contextId)) throw new TypeError(`Comment ${comment.id} references missing context ${comment.contextId}.`);
|
|
2315
|
+
for (const group of _nullishCoalesce(project.layout.groups, () => ( []))) for (const moduleId of group.moduleIds) requireModule(moduleId);
|
|
2316
|
+
for (const mapping of _nullishCoalesce(project.mappings, () => ( []))) requireModule(mapping.target.moduleId);
|
|
2317
|
+
}
|
|
2318
|
+
function serializeModuleProject(project, space) {
|
|
2319
|
+
const text3 = JSON.stringify(parseModuleProject(project), null, space);
|
|
2320
|
+
if (text3.length > MAX_BYTES) throw new RangeError("Project JSON text exceeds size limit.");
|
|
2321
|
+
return text3;
|
|
2322
|
+
}
|
|
2323
|
+
|
|
2324
|
+
// src/module/project-registry.ts
|
|
2325
|
+
var _entries;
|
|
2326
|
+
var ProjectPluginRegistry = class {
|
|
2327
|
+
constructor() {
|
|
2328
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _entries, /* @__PURE__ */ new Map());
|
|
2329
|
+
}
|
|
2330
|
+
get(id, version) {
|
|
2331
|
+
return _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _entries), 'access', _129 => _129.get, 'call', _130 => _130(id), 'optionalAccess', _131 => _131.get, 'call', _132 => _132(version)]);
|
|
2332
|
+
}
|
|
2333
|
+
register(factory) {
|
|
2334
|
+
const id = factory.id, version = factory.version;
|
|
2335
|
+
for (const value of [id, version]) if (typeof value !== "string" || !value || value !== value.trim()) throw new TypeError("Plugin ID and version must be nonempty trimmed strings.");
|
|
2336
|
+
if (typeof factory.create !== "function") throw new TypeError("Plugin factory requires create().");
|
|
2337
|
+
const versions = _nullishCoalesce(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _entries).get(id), () => ( /* @__PURE__ */ new Map()));
|
|
2338
|
+
if (versions.has(version)) throw new Error(`Plugin already registered: ${id}@${version}.`);
|
|
2339
|
+
const entry = Object.freeze({ id, version, create: factory.create.bind(factory) });
|
|
2340
|
+
versions.set(version, entry);
|
|
2341
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _entries).set(id, versions);
|
|
2342
|
+
return _chunkEXDCK2VLcjs.createConnectionLease.call(void 0, () => {
|
|
2343
|
+
if (versions.get(version) !== entry) return;
|
|
2344
|
+
versions.delete(version);
|
|
2345
|
+
if (versions.size === 0) _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _entries).delete(id);
|
|
2346
|
+
});
|
|
2347
|
+
}
|
|
2348
|
+
};
|
|
2349
|
+
_entries = new WeakMap();
|
|
2350
|
+
|
|
2351
|
+
// src/module/project-runtime.ts
|
|
2352
|
+
function tapped(untap, connect) {
|
|
2353
|
+
let lease;
|
|
2354
|
+
try {
|
|
2355
|
+
lease = connect();
|
|
2356
|
+
} catch (error) {
|
|
2357
|
+
untap();
|
|
2358
|
+
throw error;
|
|
2359
|
+
}
|
|
2360
|
+
return _chunkEXDCK2VLcjs.createConnectionLease.call(void 0, () => {
|
|
2361
|
+
try {
|
|
2362
|
+
lease.release();
|
|
2363
|
+
} finally {
|
|
2364
|
+
untap();
|
|
2365
|
+
}
|
|
2366
|
+
});
|
|
2367
|
+
}
|
|
2368
|
+
function aborted() {
|
|
2369
|
+
const error = new Error("Project restoration was cancelled.");
|
|
2370
|
+
error.name = "AbortError";
|
|
2371
|
+
return error;
|
|
2372
|
+
}
|
|
2373
|
+
function assertSignal(signal) {
|
|
2374
|
+
if (signal.aborted) throw aborted();
|
|
2375
|
+
}
|
|
2376
|
+
async function abortable(value, signal, retireLate) {
|
|
2377
|
+
if (signal.aborted) {
|
|
2378
|
+
void Promise.resolve(value).then((result) => _optionalChain([retireLate, 'optionalCall', _133 => _133(result)]), () => {
|
|
2379
|
+
});
|
|
2380
|
+
throw aborted();
|
|
2381
|
+
}
|
|
2382
|
+
let finished = false;
|
|
2383
|
+
let acquired;
|
|
2384
|
+
let retired = false;
|
|
2385
|
+
const retire = (result) => {
|
|
2386
|
+
if (!retired) {
|
|
2387
|
+
retired = true;
|
|
2388
|
+
_optionalChain([retireLate, 'optionalCall', _134 => _134(result)]);
|
|
2389
|
+
}
|
|
2390
|
+
};
|
|
2391
|
+
let rejectAbort;
|
|
2392
|
+
const cancellation = new Promise((_resolve, reject) => {
|
|
2393
|
+
rejectAbort = reject;
|
|
2394
|
+
});
|
|
2395
|
+
const onAbort = () => rejectAbort(aborted());
|
|
2396
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
2397
|
+
const task = Promise.resolve(value);
|
|
2398
|
+
void task.then((result) => {
|
|
2399
|
+
acquired = { value: result };
|
|
2400
|
+
if (signal.aborted && !finished) retire(result);
|
|
2401
|
+
}, () => {
|
|
2402
|
+
});
|
|
2403
|
+
try {
|
|
2404
|
+
const result = await Promise.race([task, cancellation]);
|
|
2405
|
+
assertSignal(signal);
|
|
2406
|
+
finished = true;
|
|
2407
|
+
return result;
|
|
2408
|
+
} catch (error) {
|
|
2409
|
+
if (!finished && acquired) retire(acquired.value);
|
|
2410
|
+
throw error;
|
|
2411
|
+
} finally {
|
|
2412
|
+
signal.removeEventListener("abort", onAbort);
|
|
2413
|
+
}
|
|
2414
|
+
}
|
|
2415
|
+
var _options2, _listeners4, _ownedInstances, _graph, _pending, _generation, _revision, _disposed3, _editing, _editObserved, _preparedEdit, _committing, _observers, _sequence, _signalProbes, _stopPreload, _ModuleProjectRuntime_instances, wireProbe_fn, tap_fn, captureSnapshot_fn, exportGraph_fn, graphTempo_fn, prepareEdit_fn, assertEdit_fn, commitEdit_fn, finishEdit_fn, build_fn, createModule_fn, discardModule_fn, connect_fn, connectModulation_fn, validateAudioTopology_fn, parameter_fn, command_fn, activate_fn, disposeGraph_fn, disposeInstance_fn, retire_fn, cleanup_fn, report_fn, assertActive_fn, requireGraph_fn, requireEditable_fn, assertPending_fn, uncapturedParameterState_fn, observe_fn, changed_fn, notify_fn2, call_fn;
|
|
2416
|
+
var ModuleProjectRuntime = class {
|
|
2417
|
+
constructor(options) {
|
|
2418
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _ModuleProjectRuntime_instances);
|
|
2419
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _options2);
|
|
2420
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _listeners4, /* @__PURE__ */ new Set());
|
|
2421
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _ownedInstances, /* @__PURE__ */ new WeakSet());
|
|
2422
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _graph);
|
|
2423
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _pending);
|
|
2424
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _generation, 0);
|
|
2425
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _revision, 0);
|
|
2426
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _disposed3, false);
|
|
2427
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _editing, false);
|
|
2428
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _editObserved, false);
|
|
2429
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _preparedEdit);
|
|
2430
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _committing, false);
|
|
2431
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _observers, /* @__PURE__ */ new Set());
|
|
2432
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _sequence, 0);
|
|
2433
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _signalProbes, /* @__PURE__ */ new Set());
|
|
2434
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _stopPreload);
|
|
2435
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _options2, options);
|
|
2436
|
+
const preload = options.preload;
|
|
2437
|
+
if (preload) {
|
|
2438
|
+
const given = typeof preload === "object" ? preload : {};
|
|
2439
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _stopPreload, keepProjectSessionPreloaded(this, { ...given, onError: _nullishCoalesce(given.onError, () => ( options.onCleanupError)) }));
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
/**
|
|
2443
|
+
* Observe every message and note as it is about to cross a cord of the
|
|
2444
|
+
* active graph (DEC-078). Delivery is unchanged: listeners run first, in
|
|
2445
|
+
* delivery order, and cannot stop or alter it; a throwing listener is
|
|
2446
|
+
* reported, not propagated. Returns an unsubscribe function.
|
|
2447
|
+
*/
|
|
2448
|
+
observe(listener) {
|
|
2449
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, assertActive_fn).call(this);
|
|
2450
|
+
if (typeof listener !== "function") throw new TypeError("An observer must be a function.");
|
|
2451
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _observers).add(listener);
|
|
2452
|
+
return () => {
|
|
2453
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _observers).delete(listener);
|
|
2454
|
+
};
|
|
2455
|
+
}
|
|
2456
|
+
/**
|
|
2457
|
+
* Listen to an audio or control output with an analyser that follows the
|
|
2458
|
+
* endpoint across rebuilds; it never changes the output's routes. The probe
|
|
2459
|
+
* owns the analyser; release it to disconnect.
|
|
2460
|
+
*/
|
|
2461
|
+
probeSignal(endpoint2, options = {}) {
|
|
2462
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, assertActive_fn).call(this);
|
|
2463
|
+
const analyser = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options2).audio.prepare().createAnalyser();
|
|
2464
|
+
analyser.fftSize = _nullishCoalesce(options.fftSize, () => ( 2048));
|
|
2465
|
+
const entry = { endpoint: { ...endpoint2 }, analyser };
|
|
2466
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _signalProbes).add(entry);
|
|
2467
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, wireProbe_fn).call(this, entry);
|
|
2468
|
+
let released = false;
|
|
2469
|
+
return Object.freeze({
|
|
2470
|
+
analyser,
|
|
2471
|
+
get connected() {
|
|
2472
|
+
return !released && entry.lease !== void 0;
|
|
2473
|
+
},
|
|
2474
|
+
release: () => {
|
|
2475
|
+
if (released) return;
|
|
2476
|
+
released = true;
|
|
2477
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _signalProbes).delete(entry);
|
|
2478
|
+
if (entry.lease) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, retire_fn).call(this, entry.lease);
|
|
2479
|
+
entry.lease = void 0;
|
|
2480
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, cleanup_fn).call(this, () => analyser.disconnect());
|
|
2481
|
+
}
|
|
2482
|
+
});
|
|
2483
|
+
}
|
|
2484
|
+
get context() {
|
|
2485
|
+
return _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _graph), 'optionalAccess', _135 => _135.context]);
|
|
2486
|
+
}
|
|
2487
|
+
get session() {
|
|
2488
|
+
return _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _graph), 'optionalAccess', _136 => _136.session]);
|
|
2489
|
+
}
|
|
2490
|
+
get resources() {
|
|
2491
|
+
const graph = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _graph);
|
|
2492
|
+
return graph && Object.freeze({ context: graph.context, session: graph.session, module: (id) => graph.handles.get(id) });
|
|
2493
|
+
}
|
|
2494
|
+
getModule(id) {
|
|
2495
|
+
return _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _graph), 'optionalAccess', _137 => _137.handles, 'access', _138 => _138.get, 'call', _139 => _139(id)]);
|
|
2496
|
+
}
|
|
2497
|
+
getMacro(id) {
|
|
2498
|
+
return _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _graph), 'optionalAccess', _140 => _140.macros, 'access', _141 => _141.get, 'call', _142 => _142(id)]);
|
|
2499
|
+
}
|
|
2500
|
+
snapshot() {
|
|
2501
|
+
const graph = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _graph);
|
|
2502
|
+
return _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, captureSnapshot_fn).call(this, graph, graph ? _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, exportGraph_fn).call(this, graph) : void 0);
|
|
2503
|
+
}
|
|
2504
|
+
exportProject() {
|
|
2505
|
+
return _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, exportGraph_fn).call(this, _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, requireGraph_fn).call(this));
|
|
2506
|
+
}
|
|
2507
|
+
/** Build/prepare a private candidate. A failed factory, asset, parameter or route leaves the active graph intact. */
|
|
2508
|
+
async restore(input, options = {}) {
|
|
2509
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, assertActive_fn).call(this);
|
|
2510
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _committing)) throw new Error("Project restoration cannot re-enter activation.");
|
|
2511
|
+
const project = parseModuleProject(input);
|
|
2512
|
+
if (_optionalChain([options, 'access', _143 => _143.signal, 'optionalAccess', _144 => _144.aborted])) return { status: "cancelled", snapshot: this.snapshot() };
|
|
2513
|
+
const previousPending = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pending);
|
|
2514
|
+
const pending = { controller: new AbortController(), generation: ++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _generation)._ };
|
|
2515
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _pending, pending);
|
|
2516
|
+
_optionalChain([previousPending, 'optionalAccess', _145 => _145.controller, 'access', _146 => _146.abort, 'call', _147 => _147()]);
|
|
2517
|
+
const cancel = () => {
|
|
2518
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pending) === pending) this.cancelRestore();
|
|
2519
|
+
};
|
|
2520
|
+
_optionalChain([options, 'access', _148 => _148.signal, 'optionalAccess', _149 => _149.addEventListener, 'call', _150 => _150("abort", cancel, { once: true })]);
|
|
2521
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, changed_fn).call(this);
|
|
2522
|
+
let candidate;
|
|
2523
|
+
try {
|
|
2524
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, assertPending_fn).call(this, pending);
|
|
2525
|
+
candidate = await _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, build_fn).call(this, project, pending.controller);
|
|
2526
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, assertPending_fn).call(this, pending);
|
|
2527
|
+
if (options.play) await _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, command_fn).call(this, candidate.session.play(), pending.controller.signal);
|
|
2528
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, assertPending_fn).call(this, pending);
|
|
2529
|
+
const prepared = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, captureSnapshot_fn).call(this, candidate, _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, exportGraph_fn).call(this, candidate));
|
|
2530
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, assertPending_fn).call(this, pending);
|
|
2531
|
+
const snapshot = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, activate_fn).call(this, candidate, pending, prepared);
|
|
2532
|
+
candidate = void 0;
|
|
2533
|
+
return { status: "committed", snapshot };
|
|
2534
|
+
} catch (error) {
|
|
2535
|
+
if (candidate) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, disposeGraph_fn).call(this, candidate);
|
|
2536
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pending) !== pending || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed3)) return { status: "cancelled", snapshot: this.snapshot() };
|
|
2537
|
+
throw error;
|
|
2538
|
+
} finally {
|
|
2539
|
+
_optionalChain([options, 'access', _151 => _151.signal, 'optionalAccess', _152 => _152.removeEventListener, 'call', _153 => _153("abort", cancel)]);
|
|
2540
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pending) === pending) {
|
|
2541
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _pending, void 0);
|
|
2542
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, changed_fn).call(this);
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
retryMissing(options = {}) {
|
|
2547
|
+
return this.restore(this.exportProject(), options);
|
|
2548
|
+
}
|
|
2549
|
+
cancelRestore() {
|
|
2550
|
+
const pending = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pending);
|
|
2551
|
+
if (!pending) return;
|
|
2552
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _pending, void 0);
|
|
2553
|
+
++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _generation)._;
|
|
2554
|
+
pending.controller.abort();
|
|
2555
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, changed_fn).call(this);
|
|
2556
|
+
}
|
|
2557
|
+
/** Presentation-only mutations preserve all instances, routes, voices and Session state. */
|
|
2558
|
+
updateLayout(layout2) {
|
|
2559
|
+
const graph = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, requireEditable_fn).call(this);
|
|
2560
|
+
graph.project = parseModuleProject({ ...graph.project, layout: layout2 });
|
|
2561
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, changed_fn).call(this);
|
|
2562
|
+
}
|
|
2563
|
+
/** Change the Session's tempo and meter (DEC-077) without rebuilding; timers that follow musical time adjust. */
|
|
2564
|
+
updateTempo(tempo) {
|
|
2565
|
+
const graph = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, requireEditable_fn).call(this);
|
|
2566
|
+
const next = _chunkTA3TNJZUcjs.createMusicalTempo.call(void 0, { ..._chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, graphTempo_fn).call(this, graph), ...tempo });
|
|
2567
|
+
graph.project = parseModuleProject({ ...graph.project, session: { ...graph.project.session, tempo: { ...next } } });
|
|
2568
|
+
_optionalChain([graph, 'access', _154 => _154.musicalListeners, 'optionalAccess', _155 => _155.forEach, 'call', _156 => _156((listener) => {
|
|
2569
|
+
try {
|
|
2570
|
+
listener();
|
|
2571
|
+
} catch (error) {
|
|
2572
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, report_fn).call(this, error);
|
|
2573
|
+
}
|
|
2574
|
+
})]);
|
|
2575
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, changed_fn).call(this);
|
|
2576
|
+
}
|
|
2577
|
+
/** Replace the control mappings (DEC-076); mappings are data and rebuild nothing. */
|
|
2578
|
+
updateMappings(mappings2) {
|
|
2579
|
+
const graph = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, requireEditable_fn).call(this);
|
|
2580
|
+
graph.project = parseModuleProject({ ...graph.project, mappings: mappings2 });
|
|
2581
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, changed_fn).call(this);
|
|
2582
|
+
}
|
|
2583
|
+
updatePresentation(options) {
|
|
2584
|
+
const graph = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, requireEditable_fn).call(this);
|
|
2585
|
+
const records = new Map(graph.project.modules.map((record) => [record.id, record]));
|
|
2586
|
+
const modules = _optionalChain([options, 'access', _157 => _157.modules, 'optionalAccess', _158 => _158.map, 'call', _159 => _159((item) => {
|
|
2587
|
+
const record = records.get(item.id);
|
|
2588
|
+
if (!record) throw new Error(`Unknown presentation module ${item.id}.`);
|
|
2589
|
+
records.delete(item.id);
|
|
2590
|
+
const { label: _previousLabel, ...rest } = record;
|
|
2591
|
+
return { ...rest, ...item.label !== void 0 ? { label: item.label } : {} };
|
|
2592
|
+
})]);
|
|
2593
|
+
if (modules && records.size) throw new Error("Presentation updates must retain every module ID.");
|
|
2594
|
+
graph.project = parseModuleProject({ ...graph.project, ...modules ? { modules } : {}, ...options.layout ? { layout: options.layout } : {} });
|
|
2595
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, changed_fn).call(this);
|
|
2596
|
+
}
|
|
2597
|
+
/** Add one explicit edge without recreating playing modules. The backend still validates context/routing. */
|
|
2598
|
+
async connect(connection) {
|
|
2599
|
+
const graph = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, requireEditable_fn).call(this);
|
|
2600
|
+
const generation = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation);
|
|
2601
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _editing, true);
|
|
2602
|
+
let lease;
|
|
2603
|
+
let committed;
|
|
2604
|
+
try {
|
|
2605
|
+
const next = parseModuleProject({ ...graph.project, connections: [...graph.project.connections, connection] });
|
|
2606
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, validateAudioTopology_fn).call(this, graph, next);
|
|
2607
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, assertEdit_fn).call(this, graph, generation);
|
|
2608
|
+
const record = next.connections[next.connections.length - 1];
|
|
2609
|
+
const diagnostics = [...graph.diagnostics];
|
|
2610
|
+
lease = await _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, connect_fn).call(this, graph, record, diagnostics);
|
|
2611
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, assertEdit_fn).call(this, graph, generation);
|
|
2612
|
+
const prepared = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, prepareEdit_fn).call(this, graph, next, diagnostics);
|
|
2613
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, assertEdit_fn).call(this, graph, generation);
|
|
2614
|
+
if (lease) graph.connectionLeases.set(record.id, lease);
|
|
2615
|
+
committed = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, commitEdit_fn).call(this, graph, next, diagnostics, prepared);
|
|
2616
|
+
return committed;
|
|
2617
|
+
} catch (error) {
|
|
2618
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, retire_fn).call(this, lease);
|
|
2619
|
+
throw error;
|
|
2620
|
+
} finally {
|
|
2621
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, finishEdit_fn).call(this, committed);
|
|
2622
|
+
}
|
|
2623
|
+
}
|
|
2624
|
+
disconnect(id) {
|
|
2625
|
+
const graph = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, requireEditable_fn).call(this);
|
|
2626
|
+
const generation = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation);
|
|
2627
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _editing, true);
|
|
2628
|
+
let committed;
|
|
2629
|
+
try {
|
|
2630
|
+
if (!graph.project.connections.some((connection) => connection.id === id)) throw new Error(`Unknown project connection ${id}.`);
|
|
2631
|
+
const next = parseModuleProject({ ...graph.project, connections: graph.project.connections.filter((connection) => connection.id !== id) });
|
|
2632
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, validateAudioTopology_fn).call(this, graph, next);
|
|
2633
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, assertEdit_fn).call(this, graph, generation);
|
|
2634
|
+
const diagnostics = graph.diagnostics.filter((item) => !(item.kind === "connection" && item.id === id));
|
|
2635
|
+
const prepared = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, prepareEdit_fn).call(this, graph, next, diagnostics);
|
|
2636
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, assertEdit_fn).call(this, graph, generation);
|
|
2637
|
+
const lease = graph.connectionLeases.get(id);
|
|
2638
|
+
graph.connectionLeases.delete(id);
|
|
2639
|
+
committed = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, commitEdit_fn).call(this, graph, next, diagnostics, prepared);
|
|
2640
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, retire_fn).call(this, lease);
|
|
2641
|
+
return committed;
|
|
2642
|
+
} finally {
|
|
2643
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, finishEdit_fn).call(this, committed);
|
|
2644
|
+
}
|
|
2645
|
+
}
|
|
2646
|
+
async connectModulation(record) {
|
|
2647
|
+
const graph = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, requireEditable_fn).call(this);
|
|
2648
|
+
const generation = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation);
|
|
2649
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _editing, true);
|
|
2650
|
+
let lease;
|
|
2651
|
+
let committed;
|
|
2652
|
+
try {
|
|
2653
|
+
const next = parseModuleProject({ ...graph.project, modulations: [...graph.project.modulations, record] });
|
|
2654
|
+
const modulation = next.modulations[next.modulations.length - 1];
|
|
2655
|
+
const diagnostics = [...graph.diagnostics];
|
|
2656
|
+
lease = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, connectModulation_fn).call(this, graph, modulation, diagnostics);
|
|
2657
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, assertEdit_fn).call(this, graph, generation);
|
|
2658
|
+
const mappings2 = new Map(graph.modulationLeases);
|
|
2659
|
+
if (lease) mappings2.set(modulation.id, lease);
|
|
2660
|
+
const prepared = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, prepareEdit_fn).call(this, graph, next, diagnostics, mappings2);
|
|
2661
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, assertEdit_fn).call(this, graph, generation);
|
|
2662
|
+
if (lease) graph.modulationLeases.set(modulation.id, lease);
|
|
2663
|
+
committed = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, commitEdit_fn).call(this, graph, next, diagnostics, prepared);
|
|
2664
|
+
return committed;
|
|
2665
|
+
} catch (error) {
|
|
2666
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, retire_fn).call(this, lease);
|
|
2667
|
+
throw error;
|
|
2668
|
+
} finally {
|
|
2669
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, finishEdit_fn).call(this, committed);
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
disconnectModulation(id) {
|
|
2673
|
+
const graph = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, requireEditable_fn).call(this);
|
|
2674
|
+
const generation = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation);
|
|
2675
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _editing, true);
|
|
2676
|
+
let committed;
|
|
2677
|
+
try {
|
|
2678
|
+
if (!graph.project.modulations.some((record) => record.id === id)) throw new Error(`Unknown project modulation ${id}.`);
|
|
2679
|
+
const next = parseModuleProject({ ...graph.project, modulations: graph.project.modulations.filter((record) => record.id !== id) });
|
|
2680
|
+
const diagnostics = graph.diagnostics.filter((item) => !(item.kind === "modulation" && item.id === id));
|
|
2681
|
+
const prepared = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, prepareEdit_fn).call(this, graph, next, diagnostics);
|
|
2682
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, assertEdit_fn).call(this, graph, generation);
|
|
2683
|
+
const lease = graph.modulationLeases.get(id);
|
|
2684
|
+
graph.modulationLeases.delete(id);
|
|
2685
|
+
committed = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, commitEdit_fn).call(this, graph, next, diagnostics, prepared);
|
|
2686
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, retire_fn).call(this, lease);
|
|
2687
|
+
return committed;
|
|
2688
|
+
} finally {
|
|
2689
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, finishEdit_fn).call(this, committed);
|
|
2690
|
+
}
|
|
2691
|
+
}
|
|
2692
|
+
/**
|
|
2693
|
+
* Add one module without rebuilding (DEC-094): every other instance, route
|
|
2694
|
+
* and voice, and the Session's state, stay as they are. The record joins a
|
|
2695
|
+
* context the project already has; `assets` adds the references it names,
|
|
2696
|
+
* and `layout` replaces the layout in the same edit, so the new box has its
|
|
2697
|
+
* place. A missing plugin leaves the record unresolved, as a restore does.
|
|
2698
|
+
* A failure leaves the graph as it was.
|
|
2699
|
+
*/
|
|
2700
|
+
async addModule(record, options = {}) {
|
|
2701
|
+
const graph = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, requireEditable_fn).call(this);
|
|
2702
|
+
const generation = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation);
|
|
2703
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _editing, true);
|
|
2704
|
+
let committed;
|
|
2705
|
+
let added;
|
|
2706
|
+
try {
|
|
2707
|
+
const next = parseModuleProject({
|
|
2708
|
+
...graph.project,
|
|
2709
|
+
modules: [...graph.project.modules, record],
|
|
2710
|
+
...options.assets ? { assets: [...graph.project.assets, ...options.assets] } : {},
|
|
2711
|
+
...options.layout ? { layout: options.layout } : {}
|
|
2712
|
+
});
|
|
2713
|
+
const parsed = next.modules[next.modules.length - 1];
|
|
2714
|
+
const diagnostics = [...graph.diagnostics];
|
|
2715
|
+
added = parsed.id;
|
|
2716
|
+
await _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, createModule_fn).call(this, graph, parsed, graph.contexts.get(parsed.contextId), graph.controller.signal, new Map(next.assets.map((asset) => [asset.id, asset])), diagnostics);
|
|
2717
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, assertEdit_fn).call(this, graph, generation);
|
|
2718
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, validateAudioTopology_fn).call(this, graph, next);
|
|
2719
|
+
const prepared = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, prepareEdit_fn).call(this, graph, next, diagnostics);
|
|
2720
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, assertEdit_fn).call(this, graph, generation);
|
|
2721
|
+
committed = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, commitEdit_fn).call(this, graph, next, diagnostics, prepared);
|
|
2722
|
+
added = void 0;
|
|
2723
|
+
for (const probe of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _signalProbes)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, wireProbe_fn).call(this, probe);
|
|
2724
|
+
const instance = graph.instances.get(parsed.id);
|
|
2725
|
+
if (_optionalChain([instance, 'optionalAccess', _160 => _160.activate])) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, cleanup_fn).call(this, () => instance.activate());
|
|
2726
|
+
return committed;
|
|
2727
|
+
} catch (error) {
|
|
2728
|
+
if (added !== void 0 && !graph.disposed) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, discardModule_fn).call(this, graph, added);
|
|
2729
|
+
throw error;
|
|
2730
|
+
} finally {
|
|
2731
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, finishEdit_fn).call(this, committed);
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2734
|
+
/**
|
|
2735
|
+
* Remove one module without rebuilding (DEC-094), with the cords,
|
|
2736
|
+
* modulations, automation and mappings that touch it and its place in the
|
|
2737
|
+
* layout (a group left with one member is dissolved); `layout` replaces the layout instead. Everything else keeps
|
|
2738
|
+
* playing. A module that owns a context, or that a macro targets, is not
|
|
2739
|
+
* removed this way: restore the edited project.
|
|
2740
|
+
*/
|
|
2741
|
+
removeModule(id, options = {}) {
|
|
2742
|
+
const graph = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, requireEditable_fn).call(this);
|
|
2743
|
+
const generation = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation);
|
|
2744
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _editing, true);
|
|
2745
|
+
let committed;
|
|
2746
|
+
try {
|
|
2747
|
+
const current = graph.project;
|
|
2748
|
+
if (!current.modules.some((record) => record.id === id)) throw new Error(`Unknown project module ${id}.`);
|
|
2749
|
+
if (current.contexts.some((context) => context.ownerModuleId === id)) throw new Error(`Module ${id} owns a context: restore the edited project to remove it.`);
|
|
2750
|
+
if (current.macros.some((macro) => macro.targets.some((target) => target.moduleId === id))) throw new Error(`A macro targets module ${id}: restore the edited project to remove it.`);
|
|
2751
|
+
const connections = new Set(current.connections.filter((item) => item.from.moduleId === id || item.to.moduleId === id).map((item) => item.id));
|
|
2752
|
+
const modulations = new Set(current.modulations.filter((item) => item.source.moduleId === id || item.target.moduleId === id).map((item) => item.id));
|
|
2753
|
+
const automation = new Set(current.automation.filter((item) => item.target.moduleId === id).map((item) => item.id));
|
|
2754
|
+
const layout2 = _nullishCoalesce(options.layout, () => ( {
|
|
2755
|
+
...current.layout,
|
|
2756
|
+
modules: current.layout.modules.filter((item) => item.moduleId !== id),
|
|
2757
|
+
...current.layout.presentation ? { presentation: current.layout.presentation.filter((item) => item.moduleId !== id) } : {},
|
|
2758
|
+
// A group is at least two modules: one that would hold fewer is dissolved.
|
|
2759
|
+
...current.layout.groups ? { groups: current.layout.groups.map((group) => ({ ...group, moduleIds: group.moduleIds.filter((member) => member !== id) })).filter((group) => group.moduleIds.length > 1) } : {}
|
|
2760
|
+
}));
|
|
2761
|
+
const next = parseModuleProject({
|
|
2762
|
+
...current,
|
|
2763
|
+
layout: layout2,
|
|
2764
|
+
modules: current.modules.filter((record) => record.id !== id),
|
|
2765
|
+
connections: current.connections.filter((item) => !connections.has(item.id)),
|
|
2766
|
+
modulations: current.modulations.filter((item) => !modulations.has(item.id)),
|
|
2767
|
+
automation: current.automation.filter((item) => !automation.has(item.id)),
|
|
2768
|
+
...current.mappings ? { mappings: current.mappings.filter((item) => item.target.moduleId !== id) } : {}
|
|
2769
|
+
});
|
|
2770
|
+
const remaining = new Map(graph.instances);
|
|
2771
|
+
remaining.delete(id);
|
|
2772
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, validateAudioTopology_fn).call(this, { ...graph, instances: remaining }, next);
|
|
2773
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, assertEdit_fn).call(this, graph, generation);
|
|
2774
|
+
const diagnostics = graph.diagnostics.filter((item) => !(item.kind === "module" && item.id === id) && !(item.kind === "connection" && connections.has(item.id)) && !(item.kind === "modulation" && modulations.has(item.id)) && !(item.kind === "automation" && automation.has(item.id)));
|
|
2775
|
+
const mappings2 = new Map([...graph.modulationLeases].filter(([key]) => !modulations.has(key)));
|
|
2776
|
+
const prepared = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, prepareEdit_fn).call(this, graph, next, diagnostics, mappings2);
|
|
2777
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, assertEdit_fn).call(this, graph, generation);
|
|
2778
|
+
const retired = [];
|
|
2779
|
+
for (const key of connections) {
|
|
2780
|
+
retired.push(graph.connectionLeases.get(key));
|
|
2781
|
+
graph.connectionLeases.delete(key);
|
|
2782
|
+
}
|
|
2783
|
+
for (const key of modulations) {
|
|
2784
|
+
retired.push(graph.modulationLeases.get(key));
|
|
2785
|
+
graph.modulationLeases.delete(key);
|
|
2786
|
+
}
|
|
2787
|
+
for (const key of automation) {
|
|
2788
|
+
retired.push(graph.automationLeases.get(key));
|
|
2789
|
+
graph.automationLeases.delete(key);
|
|
2790
|
+
}
|
|
2791
|
+
committed = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, commitEdit_fn).call(this, graph, next, diagnostics, prepared);
|
|
2792
|
+
for (const lease of retired.reverse()) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, retire_fn).call(this, lease);
|
|
2793
|
+
for (const probe of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _signalProbes)) {
|
|
2794
|
+
if (probe.endpoint.moduleId !== id || !probe.lease) continue;
|
|
2795
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, retire_fn).call(this, probe.lease);
|
|
2796
|
+
probe.lease = void 0;
|
|
2797
|
+
}
|
|
2798
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, discardModule_fn).call(this, graph, id);
|
|
2799
|
+
return committed;
|
|
2800
|
+
} finally {
|
|
2801
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, finishEdit_fn).call(this, committed);
|
|
2802
|
+
}
|
|
2803
|
+
}
|
|
2804
|
+
subscribe(listener) {
|
|
2805
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, assertActive_fn).call(this);
|
|
2806
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners4).add(listener);
|
|
2807
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, call_fn).call(this, listener);
|
|
2808
|
+
return () => {
|
|
2809
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners4).delete(listener);
|
|
2810
|
+
};
|
|
2811
|
+
}
|
|
2812
|
+
dispose() {
|
|
2813
|
+
var _a;
|
|
2814
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed3)) return;
|
|
2815
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _disposed3, true);
|
|
2816
|
+
(_a = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _stopPreload)) == null ? void 0 : _a.call(this);
|
|
2817
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _stopPreload, void 0);
|
|
2818
|
+
const pending = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pending), graph = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _graph);
|
|
2819
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _pending, void 0);
|
|
2820
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _graph, void 0);
|
|
2821
|
+
++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _generation)._;
|
|
2822
|
+
_optionalChain([pending, 'optionalAccess', _161 => _161.controller, 'access', _162 => _162.abort, 'call', _163 => _163()]);
|
|
2823
|
+
if (graph) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, disposeGraph_fn).call(this, graph);
|
|
2824
|
+
for (const probe of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _signalProbes)) {
|
|
2825
|
+
if (probe.lease) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, retire_fn).call(this, probe.lease);
|
|
2826
|
+
probe.lease = void 0;
|
|
2827
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, cleanup_fn).call(this, () => probe.analyser.disconnect());
|
|
2828
|
+
}
|
|
2829
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _signalProbes).clear();
|
|
2830
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _observers).clear();
|
|
2831
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, changed_fn).call(this);
|
|
2832
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners4).clear();
|
|
2833
|
+
}
|
|
2834
|
+
};
|
|
2835
|
+
_options2 = new WeakMap();
|
|
2836
|
+
_listeners4 = new WeakMap();
|
|
2837
|
+
_ownedInstances = new WeakMap();
|
|
2838
|
+
_graph = new WeakMap();
|
|
2839
|
+
_pending = new WeakMap();
|
|
2840
|
+
_generation = new WeakMap();
|
|
2841
|
+
_revision = new WeakMap();
|
|
2842
|
+
_disposed3 = new WeakMap();
|
|
2843
|
+
_editing = new WeakMap();
|
|
2844
|
+
_editObserved = new WeakMap();
|
|
2845
|
+
_preparedEdit = new WeakMap();
|
|
2846
|
+
_committing = new WeakMap();
|
|
2847
|
+
_observers = new WeakMap();
|
|
2848
|
+
_sequence = new WeakMap();
|
|
2849
|
+
_signalProbes = new WeakMap();
|
|
2850
|
+
_stopPreload = new WeakMap();
|
|
2851
|
+
_ModuleProjectRuntime_instances = new WeakSet();
|
|
2852
|
+
wireProbe_fn = function(entry) {
|
|
2853
|
+
const graph = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _graph);
|
|
2854
|
+
if (entry.lease && entry.graph === graph) return;
|
|
2855
|
+
if (entry.lease) {
|
|
2856
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, retire_fn).call(this, entry.lease);
|
|
2857
|
+
entry.lease = void 0;
|
|
2858
|
+
}
|
|
2859
|
+
entry.graph = graph;
|
|
2860
|
+
const instance = _optionalChain([graph, 'optionalAccess', _164 => _164.instances, 'access', _165 => _165.get, 'call', _166 => _166(entry.endpoint.moduleId)]);
|
|
2861
|
+
if (!instance) return;
|
|
2862
|
+
const port = _optionalChain([instance, 'access', _167 => _167.module, 'access', _168 => _168.getPort, 'optionalCall', _169 => _169(entry.endpoint.port)]);
|
|
2863
|
+
if (port && typeof port.send === "function") {
|
|
2864
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, cleanup_fn).call(this, () => {
|
|
2865
|
+
entry.lease = port.send(entry.analyser);
|
|
2866
|
+
});
|
|
2867
|
+
return;
|
|
2868
|
+
}
|
|
2869
|
+
const control = _optionalChain([instance, 'access', _170 => _170.getControl, 'optionalCall', _171 => _171(entry.endpoint.port)]);
|
|
2870
|
+
if (control) {
|
|
2871
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, cleanup_fn).call(this, () => {
|
|
2872
|
+
control.output.connect(entry.analyser);
|
|
2873
|
+
entry.lease = _chunkEXDCK2VLcjs.createConnectionLease.call(void 0, () => {
|
|
2874
|
+
try {
|
|
2875
|
+
control.output.disconnect(entry.analyser);
|
|
2876
|
+
} catch (e18) {
|
|
2877
|
+
}
|
|
2878
|
+
});
|
|
2879
|
+
});
|
|
2880
|
+
}
|
|
2881
|
+
};
|
|
2882
|
+
/** A tap that reports a delivery along `connection` before it happens. */
|
|
2883
|
+
tap_fn = function(connection, kind) {
|
|
2884
|
+
return (value) => {
|
|
2885
|
+
if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _observers).size) return;
|
|
2886
|
+
const base = { connectionId: connection.id, from: connection.from, to: connection.to, sequence: ++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _sequence)._ };
|
|
2887
|
+
const event = kind === "message" ? Object.freeze({ ...base, kind, message: value, depth: _chunkCR6OUWBJcjs.currentMessageDepth.call(void 0, ) }) : Object.freeze({ ...base, kind, event: value });
|
|
2888
|
+
for (const observer of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _observers)]) {
|
|
2889
|
+
try {
|
|
2890
|
+
observer(event);
|
|
2891
|
+
} catch (error) {
|
|
2892
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, report_fn).call(this, error);
|
|
2893
|
+
}
|
|
2894
|
+
}
|
|
2895
|
+
};
|
|
2896
|
+
};
|
|
2897
|
+
captureSnapshot_fn = function(graph, project) {
|
|
2898
|
+
return Object.freeze({
|
|
2899
|
+
project,
|
|
2900
|
+
revision: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision),
|
|
2901
|
+
restoring: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pending) !== void 0,
|
|
2902
|
+
disposed: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed3),
|
|
2903
|
+
modules: Object.freeze((_nullishCoalesce(_optionalChain([graph, 'optionalAccess', _172 => _172.project, 'access', _173 => _173.modules]), () => ( []))).map((record) => {
|
|
2904
|
+
const instance = _optionalChain([graph, 'optionalAccess', _174 => _174.instances, 'access', _175 => _175.get, 'call', _176 => _176(record.id)]);
|
|
2905
|
+
const diagnostic = _optionalChain([graph, 'optionalAccess', _177 => _177.diagnostics, 'access', _178 => _178.find, 'call', _179 => _179((item) => item.kind === "module" && item.id === record.id), 'optionalAccess', _180 => _180.reason]);
|
|
2906
|
+
const defaultOwnerModuleId = _optionalChain([graph, 'optionalAccess', _181 => _181.defaultOwners, 'access', _182 => _182.get, 'call', _183 => _183(record.contextId)]);
|
|
2907
|
+
return Object.freeze({
|
|
2908
|
+
record,
|
|
2909
|
+
status: instance ? "ready" : "unresolved",
|
|
2910
|
+
ports: Object.freeze((_nullishCoalesce(_optionalChain([instance, 'optionalAccess', _184 => _184.ports]), () => ( []))).map((port) => Object.freeze({ ...port }))),
|
|
2911
|
+
...defaultOwnerModuleId ? { defaultOwnerModuleId } : {},
|
|
2912
|
+
...diagnostic ? { diagnostic } : {}
|
|
2913
|
+
});
|
|
2914
|
+
})),
|
|
2915
|
+
unresolved: Object.freeze([..._nullishCoalesce(_optionalChain([graph, 'optionalAccess', _185 => _185.diagnostics]), () => ( []))])
|
|
2916
|
+
});
|
|
2917
|
+
};
|
|
2918
|
+
exportGraph_fn = function(graph) {
|
|
2919
|
+
const transport = graph.session.snapshot;
|
|
2920
|
+
return parseModuleProject({
|
|
2921
|
+
...graph.project,
|
|
2922
|
+
modules: graph.project.modules.map((record) => {
|
|
2923
|
+
const instance = graph.instances.get(record.id);
|
|
2924
|
+
if (!instance) return record;
|
|
2925
|
+
const params = { ...record.params };
|
|
2926
|
+
for (const handle of _nullishCoalesce(instance.module.params, () => ( []))) params[handle.descriptor.id] = handle.snapshot.baseValue;
|
|
2927
|
+
return { ...record, config: _nullishCoalesce(_optionalChain([instance, 'access', _186 => _186.exportConfig, 'optionalCall', _187 => _187()]), () => ( record.config)), params };
|
|
2928
|
+
}),
|
|
2929
|
+
macros: graph.project.macros.map((record) => ({ ...record, value: _nullishCoalesce(_optionalChain([graph, 'access', _188 => _188.macros, 'access', _189 => _189.get, 'call', _190 => _190(record.id), 'optionalAccess', _191 => _191.value]), () => ( record.value)) })),
|
|
2930
|
+
modulations: graph.project.modulations.map((record) => ({ ...record, depth: _nullishCoalesce(_optionalChain([graph, 'access', _192 => _192.modulationLeases, 'access', _193 => _193.get, 'call', _194 => _194(record.id), 'optionalAccess', _195 => _195.depth]), () => ( record.depth)) })),
|
|
2931
|
+
automation: graph.project.automation.map((record) => ({ ...record, ...graph.automationLeases.has(record.id) ? { enabled: graph.automationLeases.get(record.id).active, initialValue: graph.automationLeases.get(record.id).initialValue } : {} })),
|
|
2932
|
+
session: {
|
|
2933
|
+
positionSeconds: graph.session.clock.positionAt(transport.referenceTime),
|
|
2934
|
+
rate: transport.rate,
|
|
2935
|
+
loop: transport.loop,
|
|
2936
|
+
...graph.project.session.tempo ? { tempo: graph.project.session.tempo } : {}
|
|
2937
|
+
}
|
|
2938
|
+
});
|
|
2939
|
+
};
|
|
2940
|
+
graphTempo_fn = function(graph) {
|
|
2941
|
+
return _chunkTA3TNJZUcjs.createMusicalTempo.call(void 0, _nullishCoalesce(graph.project.session.tempo, () => ( {})));
|
|
2942
|
+
};
|
|
2943
|
+
prepareEdit_fn = function(graph, project, diagnostics, modulationLeases = graph.modulationLeases) {
|
|
2944
|
+
const candidate = { ...graph, project, diagnostics, modulationLeases };
|
|
2945
|
+
const observed = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _editObserved);
|
|
2946
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _editObserved, false);
|
|
2947
|
+
try {
|
|
2948
|
+
const project2 = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, exportGraph_fn).call(this, candidate);
|
|
2949
|
+
const snapshot = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, captureSnapshot_fn).call(this, candidate, project2);
|
|
2950
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _preparedEdit, { graph, project: project2 });
|
|
2951
|
+
return snapshot;
|
|
2952
|
+
} catch (error) {
|
|
2953
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _editObserved) || _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _editObserved, observed);
|
|
2954
|
+
throw error;
|
|
2955
|
+
}
|
|
2956
|
+
};
|
|
2957
|
+
assertEdit_fn = function(graph, generation) {
|
|
2958
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _graph) !== graph || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation) !== generation || graph.disposed) throw aborted();
|
|
2959
|
+
};
|
|
2960
|
+
commitEdit_fn = function(graph, project, diagnostics, prepared) {
|
|
2961
|
+
graph.project = project;
|
|
2962
|
+
graph.diagnostics.splice(0, graph.diagnostics.length, ...diagnostics);
|
|
2963
|
+
return Object.freeze({ ...prepared, revision: ++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _revision)._ });
|
|
2964
|
+
};
|
|
2965
|
+
finishEdit_fn = function(committed) {
|
|
2966
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _editing, false);
|
|
2967
|
+
const observed = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _editObserved);
|
|
2968
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _editObserved, false);
|
|
2969
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _preparedEdit, void 0);
|
|
2970
|
+
if (committed) {
|
|
2971
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, notify_fn2).call(this, committed.revision, committed);
|
|
2972
|
+
if (observed && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _graph)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, observe_fn).call(this, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _graph));
|
|
2973
|
+
} else if (observed) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, changed_fn).call(this);
|
|
2974
|
+
};
|
|
2975
|
+
build_fn = async function(project, controller) {
|
|
2976
|
+
const signal = controller.signal;
|
|
2977
|
+
assertSignal(signal);
|
|
2978
|
+
const audio = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options2).audio.prepare();
|
|
2979
|
+
assertSignal(signal);
|
|
2980
|
+
const gate = audio.createGain();
|
|
2981
|
+
gate.gain.value = 0;
|
|
2982
|
+
const root = project.contexts.find((context2) => !context2.parentId);
|
|
2983
|
+
const session2 = new (0, _chunkJFCBJMA7cjs.SessionTransport)(() => audio.currentTime);
|
|
2984
|
+
const musical = _chunkCR6OUWBJcjs.createMusicalTimeSource.call(void 0, session2, () => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, graphTempo_fn).call(this, graph));
|
|
2985
|
+
const context = new (0, _chunkOCKAHITLcjs.ModuleContext)({
|
|
2986
|
+
id: root.id,
|
|
2987
|
+
audio: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options2).audio,
|
|
2988
|
+
session: session2,
|
|
2989
|
+
destination: () => gate,
|
|
2990
|
+
capabilities: new (0, _chunkI4YMA5VMcjs.ModuleCapabilities)().with(_chunkCR6OUWBJcjs.MUSICAL_TIME, musical)
|
|
2991
|
+
});
|
|
2992
|
+
const graph = {
|
|
2993
|
+
project,
|
|
2994
|
+
controller,
|
|
2995
|
+
gate,
|
|
2996
|
+
session: session2,
|
|
2997
|
+
context,
|
|
2998
|
+
contexts: /* @__PURE__ */ new Map([[root.id, context]]),
|
|
2999
|
+
defaultOwners: /* @__PURE__ */ new Map([[root.id, void 0]]),
|
|
3000
|
+
instances: /* @__PURE__ */ new Map(),
|
|
3001
|
+
handles: /* @__PURE__ */ new Map(),
|
|
3002
|
+
macros: /* @__PURE__ */ new Map(),
|
|
3003
|
+
leases: [],
|
|
3004
|
+
moduleLeases: /* @__PURE__ */ new Map(),
|
|
3005
|
+
connectionLeases: /* @__PURE__ */ new Map(),
|
|
3006
|
+
modulationLeases: /* @__PURE__ */ new Map(),
|
|
3007
|
+
automationLeases: /* @__PURE__ */ new Map(),
|
|
3008
|
+
diagnostics: [],
|
|
3009
|
+
disposed: false
|
|
3010
|
+
};
|
|
3011
|
+
graph.musicalListeners = /* @__PURE__ */ new Set([() => musical.notify()]);
|
|
3012
|
+
try {
|
|
3013
|
+
const destination = _nullishCoalesce(_optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options2), 'access', _196 => _196.destination, 'optionalCall', _197 => _197()]), () => ( audio.destination));
|
|
3014
|
+
if (destination.context !== audio || destination === gate) throw new Error("Project output destination must belong to its AudioContext.");
|
|
3015
|
+
gate.connect(destination);
|
|
3016
|
+
const assets = new Map(project.assets.map((asset) => [asset.id, asset]));
|
|
3017
|
+
const prepareContext = async (record) => {
|
|
3018
|
+
assertSignal(signal);
|
|
3019
|
+
const parent = record.parentId ? graph.contexts.get(record.parentId) : context;
|
|
3020
|
+
let scope = record.parentId ? void 0 : context;
|
|
3021
|
+
if (record.parentId && parent) {
|
|
3022
|
+
const fresh = parent.derive({ id: record.id, registry: new (0, _chunkBADJJ6DVcjs.ModuleRegistry)() });
|
|
3023
|
+
try {
|
|
3024
|
+
let defaultOwner = graph.defaultOwners.get(record.parentId);
|
|
3025
|
+
if (!record.ownerModuleId) scope = fresh;
|
|
3026
|
+
else {
|
|
3027
|
+
const owner = graph.instances.get(record.ownerModuleId);
|
|
3028
|
+
if (_optionalChain([owner, 'optionalAccess', _198 => _198.childContext])) {
|
|
3029
|
+
scope = owner.childContext(fresh);
|
|
3030
|
+
if (scope && (scope.admit !== fresh.admit || scope.destination !== fresh.destination)) {
|
|
3031
|
+
defaultOwner = _optionalChain([owner, 'access', _199 => _199.ports, 'optionalAccess', _200 => _200.some, 'call', _201 => _201((port) => port.kind === "audio" && port.direction === "input")]) ? record.ownerModuleId : void 0;
|
|
3032
|
+
}
|
|
3033
|
+
}
|
|
3034
|
+
}
|
|
3035
|
+
if (scope && (scope.id !== fresh.id || scope.registry !== fresh.registry || scope.audio !== fresh.audio || scope.session !== fresh.session)) throw new Error("A project child context must preserve its ID, registry, audio and Session ownership.");
|
|
3036
|
+
if (scope) {
|
|
3037
|
+
graph.contexts.set(record.id, scope);
|
|
3038
|
+
graph.defaultOwners.set(record.id, defaultOwner);
|
|
3039
|
+
} else _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, cleanup_fn).call(this, () => fresh.registry.dispose());
|
|
3040
|
+
} catch (error) {
|
|
3041
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, cleanup_fn).call(this, () => fresh.registry.dispose());
|
|
3042
|
+
throw error;
|
|
3043
|
+
}
|
|
3044
|
+
}
|
|
3045
|
+
if (!scope) graph.diagnostics.push({ kind: "context", id: record.id, reason: "Parent context or owner plugin is unresolved." });
|
|
3046
|
+
for (const moduleRecord of project.modules.filter((module) => module.contextId === record.id)) {
|
|
3047
|
+
await _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, createModule_fn).call(this, graph, moduleRecord, scope, signal, assets, graph.diagnostics);
|
|
3048
|
+
}
|
|
3049
|
+
for (const child of project.contexts.filter((child2) => child2.parentId === record.id)) await prepareContext(child);
|
|
3050
|
+
};
|
|
3051
|
+
await prepareContext(root);
|
|
3052
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, validateAudioTopology_fn).call(this, graph, project);
|
|
3053
|
+
const normalRoutes = /* @__PURE__ */ new Map();
|
|
3054
|
+
for (const connection of project.connections) {
|
|
3055
|
+
if (connection.kind !== "audio" || (_nullishCoalesce(connection.mode, () => ( "replace"))) !== "replace") continue;
|
|
3056
|
+
const source = _optionalChain([graph, 'access', _202 => _202.instances, 'access', _203 => _203.get, 'call', _204 => _204(connection.from.moduleId), 'optionalAccess', _205 => _205.module, 'access', _206 => _206.getPort, 'optionalCall', _207 => _207(connection.from.port)]);
|
|
3057
|
+
if (!source) continue;
|
|
3058
|
+
if (normalRoutes.has(source)) throw new Error("Aliased audio output ports cannot have multiple replacement claims.");
|
|
3059
|
+
normalRoutes.set(source, source.defaultDestination);
|
|
3060
|
+
source.setDefault(void 0);
|
|
3061
|
+
}
|
|
3062
|
+
for (const connection of project.connections) {
|
|
3063
|
+
const lease = await _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, connect_fn).call(this, graph, connection, graph.diagnostics);
|
|
3064
|
+
if (lease) graph.connectionLeases.set(connection.id, lease);
|
|
3065
|
+
assertSignal(signal);
|
|
3066
|
+
}
|
|
3067
|
+
for (const [source, normal] of normalRoutes) source.setDefault(normal);
|
|
3068
|
+
for (const record of project.modulations) {
|
|
3069
|
+
const lease = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, connectModulation_fn).call(this, graph, record, graph.diagnostics);
|
|
3070
|
+
if (lease) graph.modulationLeases.set(record.id, lease);
|
|
3071
|
+
assertSignal(signal);
|
|
3072
|
+
}
|
|
3073
|
+
for (const record of project.macros) {
|
|
3074
|
+
const targets = record.targets.map((target) => ({ target: _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, parameter_fn).call(this, graph, target), min: target.min, max: target.max }));
|
|
3075
|
+
if (targets.some((target) => !target.target)) {
|
|
3076
|
+
graph.diagnostics.push({ kind: "macro", id: record.id, reason: "Macro parameter is unresolved." });
|
|
3077
|
+
continue;
|
|
3078
|
+
}
|
|
3079
|
+
const macro = new ParamMacro(targets, { value: record.value });
|
|
3080
|
+
graph.macros.set(record.id, macro);
|
|
3081
|
+
graph.leases.push(_chunkEXDCK2VLcjs.createConnectionLease.call(void 0, macro.subscribe(() => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, observe_fn).call(this, graph))));
|
|
3082
|
+
}
|
|
3083
|
+
await _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, command_fn).call(this, session2.setRate(project.session.rate), signal);
|
|
3084
|
+
if (project.session.loop) await _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, command_fn).call(this, session2.setLoop(project.session.loop), signal);
|
|
3085
|
+
await _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, command_fn).call(this, session2.seek(project.session.positionSeconds), signal);
|
|
3086
|
+
for (const record of project.automation) {
|
|
3087
|
+
if (record.enabled === false) continue;
|
|
3088
|
+
const target = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, parameter_fn).call(this, graph, record.target);
|
|
3089
|
+
if (!target) {
|
|
3090
|
+
graph.diagnostics.push({ kind: "automation", id: record.id, reason: "Automation parameter is unresolved." });
|
|
3091
|
+
continue;
|
|
3092
|
+
}
|
|
3093
|
+
const lease = _chunkJFCBJMA7cjs.attachSessionAutomation.call(void 0, session2.scheduling, audio, target, record.points, {
|
|
3094
|
+
loop: record.loop,
|
|
3095
|
+
initialValue: record.initialValue,
|
|
3096
|
+
onRelease: () => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, observe_fn).call(this, graph),
|
|
3097
|
+
onError: (error) => {
|
|
3098
|
+
graph.diagnostics.push({ kind: "automation", id: record.id, reason: `Automation stopped: ${String(error)}` });
|
|
3099
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, observe_fn).call(this, graph);
|
|
3100
|
+
}
|
|
3101
|
+
});
|
|
3102
|
+
graph.automationLeases.set(record.id, lease);
|
|
3103
|
+
assertSignal(signal);
|
|
3104
|
+
}
|
|
3105
|
+
graph.leases.push(_chunkEXDCK2VLcjs.createConnectionLease.call(void 0, session2.subscribe(() => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, observe_fn).call(this, graph))));
|
|
3106
|
+
return graph;
|
|
3107
|
+
} catch (error) {
|
|
3108
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, disposeGraph_fn).call(this, graph);
|
|
3109
|
+
throw error;
|
|
3110
|
+
}
|
|
3111
|
+
};
|
|
3112
|
+
createModule_fn = async function(graph, moduleRecord, scope, signal, assets, diagnostics) {
|
|
3113
|
+
assertSignal(signal);
|
|
3114
|
+
const factory = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options2).plugins.get(moduleRecord.plugin.id, moduleRecord.plugin.version);
|
|
3115
|
+
if (!scope || !factory) {
|
|
3116
|
+
diagnostics.push({ kind: "module", id: moduleRecord.id, reason: !scope ? "Module context is unresolved." : `Missing plugin ${moduleRecord.plugin.id}@${moduleRecord.plugin.version}.` });
|
|
3117
|
+
return;
|
|
3118
|
+
}
|
|
3119
|
+
const asset = (role) => {
|
|
3120
|
+
const id = _optionalChain([moduleRecord, 'access', _208 => _208.assets, 'optionalAccess', _209 => _209[role]]);
|
|
3121
|
+
return id === void 0 ? void 0 : assets.get(id);
|
|
3122
|
+
};
|
|
3123
|
+
let instance;
|
|
3124
|
+
try {
|
|
3125
|
+
instance = await abortable(factory.create({
|
|
3126
|
+
record: moduleRecord,
|
|
3127
|
+
context: scope,
|
|
3128
|
+
signal,
|
|
3129
|
+
asset,
|
|
3130
|
+
resolveAsset: async (role) => {
|
|
3131
|
+
assertSignal(signal);
|
|
3132
|
+
const reference = asset(role);
|
|
3133
|
+
if (!reference) throw new Error(`Missing asset role ${role} for ${moduleRecord.id}.`);
|
|
3134
|
+
if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options2).resolveAsset) throw new Error("No project asset resolver was supplied.");
|
|
3135
|
+
return abortable(Promise.resolve(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options2).resolveAsset(reference, signal)), signal);
|
|
3136
|
+
}
|
|
3137
|
+
}), signal, (value) => {
|
|
3138
|
+
if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _ownedInstances).has(value)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, disposeInstance_fn).call(this, value);
|
|
3139
|
+
});
|
|
3140
|
+
} catch (error) {
|
|
3141
|
+
if (signal.aborted || !_chunkI4YMA5VMcjs.isProjectModuleUnavailable.call(void 0, error)) throw error;
|
|
3142
|
+
diagnostics.push({ kind: "module", id: moduleRecord.id, reason: error.message });
|
|
3143
|
+
return;
|
|
3144
|
+
}
|
|
3145
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _ownedInstances).has(instance)) throw new Error("Project factories must return fresh owned instances.");
|
|
3146
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _ownedInstances).add(instance);
|
|
3147
|
+
graph.instances.set(moduleRecord.id, instance);
|
|
3148
|
+
const own = [];
|
|
3149
|
+
graph.moduleLeases.set(moduleRecord.id, own);
|
|
3150
|
+
const keep = (lease) => {
|
|
3151
|
+
own.push(lease);
|
|
3152
|
+
graph.leases.push(lease);
|
|
3153
|
+
};
|
|
3154
|
+
if (instance.module.id !== moduleRecord.id || typeof instance.dispose !== "function") throw new Error("Plugin instance must preserve its stable module ID and provide disposal.");
|
|
3155
|
+
graph.handles.set(moduleRecord.id, _chunkBADJJ6DVcjs.createModuleHandle.call(void 0, instance.module));
|
|
3156
|
+
const registered = scope.registry.get(moduleRecord.id);
|
|
3157
|
+
if (registered && registered !== instance.module) throw new Error(`Different module is already registered: ${moduleRecord.id}.`);
|
|
3158
|
+
if (!registered) keep(scope.registry.register(instance.module));
|
|
3159
|
+
await abortable(_optionalChain([instance, 'access', _210 => _210.module, 'access', _211 => _211.prepare, 'optionalCall', _212 => _212()]), signal);
|
|
3160
|
+
for (const [id, value] of Object.entries(_nullishCoalesce(moduleRecord.params, () => ( {})))) {
|
|
3161
|
+
const parameter2 = _optionalChain([instance, 'access', _213 => _213.module, 'access', _214 => _214.params, 'optionalAccess', _215 => _215.get, 'call', _216 => _216(id)]);
|
|
3162
|
+
if (!parameter2) throw new Error(`Unknown saved parameter ${moduleRecord.id}.${id}.`);
|
|
3163
|
+
parameter2.setBaseValue(value);
|
|
3164
|
+
assertSignal(signal);
|
|
3165
|
+
}
|
|
3166
|
+
for (const parameter2 of _nullishCoalesce(instance.module.params, () => ( []))) {
|
|
3167
|
+
let baseRevision = parameter2.snapshot.baseRevision;
|
|
3168
|
+
keep(_chunkEXDCK2VLcjs.createConnectionLease.call(void 0, parameter2.subscribe((snapshot) => {
|
|
3169
|
+
const baseChanged = snapshot.baseRevision !== baseRevision;
|
|
3170
|
+
baseRevision = snapshot.baseRevision;
|
|
3171
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, observe_fn).call(this, graph, baseChanged || snapshot.disposed || _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, uncapturedParameterState_fn).call(this, graph, moduleRecord.id, parameter2.descriptor.id, snapshot.baseValue));
|
|
3172
|
+
})));
|
|
3173
|
+
}
|
|
3174
|
+
if (instance.module.subscribe) keep(_chunkEXDCK2VLcjs.createConnectionLease.call(void 0, instance.module.subscribe(() => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, observe_fn).call(this, graph))));
|
|
3175
|
+
};
|
|
3176
|
+
/** Take one module out of a graph: the leases its creation took, then the instance. */
|
|
3177
|
+
discardModule_fn = function(graph, id) {
|
|
3178
|
+
const own = _nullishCoalesce(graph.moduleLeases.get(id), () => ( []));
|
|
3179
|
+
graph.moduleLeases.delete(id);
|
|
3180
|
+
for (const lease of [...own].reverse()) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, retire_fn).call(this, lease);
|
|
3181
|
+
if (own.length) {
|
|
3182
|
+
const gone = new Set(own);
|
|
3183
|
+
graph.leases.splice(0, graph.leases.length, ...graph.leases.filter((lease) => !gone.has(lease)));
|
|
3184
|
+
}
|
|
3185
|
+
const instance = graph.instances.get(id);
|
|
3186
|
+
graph.instances.delete(id);
|
|
3187
|
+
graph.handles.delete(id);
|
|
3188
|
+
if (instance) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, disposeInstance_fn).call(this, instance);
|
|
3189
|
+
};
|
|
3190
|
+
connect_fn = async function(graph, connection, diagnostics) {
|
|
3191
|
+
assertSignal(graph.controller.signal);
|
|
3192
|
+
const from = graph.instances.get(connection.from.moduleId), to = graph.instances.get(connection.to.moduleId);
|
|
3193
|
+
if (connection.kind === "audio") {
|
|
3194
|
+
const source2 = _optionalChain([from, 'optionalAccess', _217 => _217.module, 'access', _218 => _218.getPort, 'optionalCall', _219 => _219(connection.from.port)]), target = _optionalChain([to, 'optionalAccess', _220 => _220.getInput, 'optionalCall', _221 => _221(connection.to.port)]);
|
|
3195
|
+
if (source2 && target) return source2[_nullishCoalesce(connection.mode, () => ( "replace"))](target);
|
|
3196
|
+
diagnostics.push({ kind: "connection", id: connection.id, reason: "Audio source or destination is unresolved." });
|
|
3197
|
+
if (source2 && (_nullishCoalesce(connection.mode, () => ( "replace"))) === "replace") {
|
|
3198
|
+
const silence = source2.context.createGain();
|
|
3199
|
+
let replacement;
|
|
3200
|
+
try {
|
|
3201
|
+
replacement = source2.replace(silence);
|
|
3202
|
+
} catch (error) {
|
|
3203
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, cleanup_fn).call(this, () => silence.disconnect());
|
|
3204
|
+
throw error;
|
|
3205
|
+
}
|
|
3206
|
+
return _chunkEXDCK2VLcjs.createConnectionLease.call(void 0, () => {
|
|
3207
|
+
try {
|
|
3208
|
+
replacement.release();
|
|
3209
|
+
} finally {
|
|
3210
|
+
silence.disconnect();
|
|
3211
|
+
}
|
|
3212
|
+
});
|
|
3213
|
+
}
|
|
3214
|
+
return void 0;
|
|
3215
|
+
}
|
|
3216
|
+
if (connection.kind === "note" && from && to) {
|
|
3217
|
+
const source2 = _chunkBADJJ6DVcjs.getModulePort.call(void 0, from.module, connection.from.port, "note", "output");
|
|
3218
|
+
const target = _chunkBADJJ6DVcjs.getModulePort.call(void 0, to.module, connection.to.port, "note", "input");
|
|
3219
|
+
if (source2 && target) return tapped(source2.subscribe(_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, tap_fn).call(this, connection, "note")), () => target.connect(source2));
|
|
3220
|
+
}
|
|
3221
|
+
if (connection.kind === "message" && from && to) {
|
|
3222
|
+
const source2 = _chunkBADJJ6DVcjs.getModulePort.call(void 0, from.module, connection.from.port, "message", "output");
|
|
3223
|
+
if (source2 && connection.to.port.startsWith("param:")) {
|
|
3224
|
+
const handle = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, parameter_fn).call(this, graph, { moduleId: connection.to.moduleId, param: connection.to.port.slice("param:".length) });
|
|
3225
|
+
if (handle) return _chunkCR6OUWBJcjs.connectMessageToParameter.call(void 0, source2, handle, graph.gate.context);
|
|
3226
|
+
}
|
|
3227
|
+
const target = _chunkBADJJ6DVcjs.getModulePort.call(void 0, to.module, connection.to.port, "message", "input");
|
|
3228
|
+
if (source2 && target) return tapped(source2.subscribe(_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, tap_fn).call(this, connection, "message")), () => target.connect(source2));
|
|
3229
|
+
}
|
|
3230
|
+
let source = from;
|
|
3231
|
+
if (connection.kind === "source" && from && to) {
|
|
3232
|
+
const carried = _nullishCoalesce(_optionalChain([from, 'access', _222 => _222.sourceOutput, 'optionalCall', _223 => _223(connection.from.port)]), () => ( from.module));
|
|
3233
|
+
if (carried !== from.module) source = { ...from, module: carried };
|
|
3234
|
+
const accepted = _optionalChain([to, 'access', _224 => _224.connectSource, 'optionalCall', _225 => _225(connection.to.port, carried)]);
|
|
3235
|
+
if (accepted) return accepted;
|
|
3236
|
+
}
|
|
3237
|
+
if (source && to && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options2).connect) {
|
|
3238
|
+
const lease = await abortable(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options2).connect({ connection, from: source, to, context: graph.context, signal: graph.controller.signal }), graph.controller.signal, (value) => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, retire_fn).call(this, value));
|
|
3239
|
+
if (lease !== void 0) {
|
|
3240
|
+
if (!lease || lease.active !== true || typeof lease.release !== "function") {
|
|
3241
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, retire_fn).call(this, lease);
|
|
3242
|
+
throw new Error("A project connector must return an active connection lease.");
|
|
3243
|
+
}
|
|
3244
|
+
return lease;
|
|
3245
|
+
}
|
|
3246
|
+
}
|
|
3247
|
+
diagnostics.push({ kind: "connection", id: connection.id, reason: "Signal endpoints or a matching connector are unavailable." });
|
|
3248
|
+
return void 0;
|
|
3249
|
+
};
|
|
3250
|
+
connectModulation_fn = function(graph, record, diagnostics) {
|
|
3251
|
+
const source = _optionalChain([graph, 'access', _226 => _226.instances, 'access', _227 => _227.get, 'call', _228 => _228(record.source.moduleId), 'optionalAccess', _229 => _229.getControl, 'optionalCall', _230 => _230(record.source.port)]);
|
|
3252
|
+
const target = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, parameter_fn).call(this, graph, record.target);
|
|
3253
|
+
if (!source || !target) {
|
|
3254
|
+
diagnostics.push({ kind: "modulation", id: record.id, reason: "Control source or parameter is unresolved." });
|
|
3255
|
+
return void 0;
|
|
3256
|
+
}
|
|
3257
|
+
return target.connectModulation(source, { depth: record.depth, polarity: record.polarity });
|
|
3258
|
+
};
|
|
3259
|
+
validateAudioTopology_fn = function(graph, project) {
|
|
3260
|
+
const routes = /* @__PURE__ */ new Map();
|
|
3261
|
+
const replaced = new Set(project.connections.filter((connection) => connection.kind === "audio" && (_nullishCoalesce(connection.mode, () => ( "replace"))) === "replace").map((connection) => JSON.stringify(connection.from)));
|
|
3262
|
+
const add = (from, to) => {
|
|
3263
|
+
const targets = _nullishCoalesce(routes.get(from), () => ( /* @__PURE__ */ new Set()));
|
|
3264
|
+
targets.add(to);
|
|
3265
|
+
routes.set(from, targets);
|
|
3266
|
+
};
|
|
3267
|
+
for (const record of project.modules) {
|
|
3268
|
+
const owner = graph.defaultOwners.get(record.contextId), instance = graph.instances.get(record.id);
|
|
3269
|
+
if (!owner || !instance) continue;
|
|
3270
|
+
for (const descriptor of _nullishCoalesce(instance.ports, () => ( []))) {
|
|
3271
|
+
if (descriptor.kind !== "audio" || descriptor.direction !== "output") continue;
|
|
3272
|
+
if (replaced.has(JSON.stringify({ moduleId: record.id, port: descriptor.id }))) continue;
|
|
3273
|
+
if (_optionalChain([instance, 'access', _231 => _231.module, 'access', _232 => _232.getPort, 'optionalCall', _233 => _233(descriptor.id), 'optionalAccess', _234 => _234.defaultDestination])) add(record.id, owner);
|
|
3274
|
+
}
|
|
3275
|
+
}
|
|
3276
|
+
for (const connection of project.connections) {
|
|
3277
|
+
if (connection.kind !== "audio") continue;
|
|
3278
|
+
if (_optionalChain([graph, 'access', _235 => _235.instances, 'access', _236 => _236.get, 'call', _237 => _237(connection.from.moduleId), 'optionalAccess', _238 => _238.module, 'access', _239 => _239.getPort, 'optionalCall', _240 => _240(connection.from.port)]) && _optionalChain([graph, 'access', _241 => _241.instances, 'access', _242 => _242.get, 'call', _243 => _243(connection.to.moduleId), 'optionalAccess', _244 => _244.getInput, 'optionalCall', _245 => _245(connection.to.port)])) add(connection.from.moduleId, connection.to.moduleId);
|
|
3279
|
+
}
|
|
3280
|
+
const degrees = /* @__PURE__ */ new Map();
|
|
3281
|
+
for (const [source, targets] of routes) {
|
|
3282
|
+
if (!degrees.has(source)) degrees.set(source, 0);
|
|
3283
|
+
for (const target of targets) degrees.set(target, (_nullishCoalesce(degrees.get(target), () => ( 0))) + 1);
|
|
3284
|
+
}
|
|
3285
|
+
const ready = [...degrees.keys()].filter((id) => degrees.get(id) === 0);
|
|
3286
|
+
for (let index = 0; index < ready.length; index++) for (const target of _nullishCoalesce(routes.get(ready[index]), () => ( []))) {
|
|
3287
|
+
const remaining = degrees.get(target) - 1;
|
|
3288
|
+
degrees.set(target, remaining);
|
|
3289
|
+
if (remaining === 0) ready.push(target);
|
|
3290
|
+
}
|
|
3291
|
+
if (ready.length !== degrees.size) throw new Error("Project routes would create feedback through a nested default bus.");
|
|
3292
|
+
};
|
|
3293
|
+
parameter_fn = function(graph, target) {
|
|
3294
|
+
return _optionalChain([graph, 'access', _246 => _246.instances, 'access', _247 => _247.get, 'call', _248 => _248(target.moduleId), 'optionalAccess', _249 => _249.module, 'access', _250 => _250.params, 'optionalAccess', _251 => _251.get, 'call', _252 => _252(target.param)]);
|
|
3295
|
+
};
|
|
3296
|
+
command_fn = async function(command, signal) {
|
|
3297
|
+
const result = await abortable(command, signal);
|
|
3298
|
+
if (result.status !== "committed") throw new Error("Project Session preparation was superseded.");
|
|
3299
|
+
};
|
|
3300
|
+
activate_fn = function(candidate, pending, prepared) {
|
|
3301
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, assertPending_fn).call(this, pending);
|
|
3302
|
+
const previous = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _graph);
|
|
3303
|
+
const time = candidate.gate.context.currentTime;
|
|
3304
|
+
let committed;
|
|
3305
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _committing, true);
|
|
3306
|
+
try {
|
|
3307
|
+
candidate.gate.gain.setValueAtTime(1, time);
|
|
3308
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, assertPending_fn).call(this, pending);
|
|
3309
|
+
_optionalChain([previous, 'optionalAccess', _253 => _253.gate, 'access', _254 => _254.gain, 'access', _255 => _255.setValueAtTime, 'call', _256 => _256(0, time)]);
|
|
3310
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, assertPending_fn).call(this, pending);
|
|
3311
|
+
committed = Object.freeze({ ...prepared, revision: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision) + 1, restoring: false, disposed: false });
|
|
3312
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _graph, candidate);
|
|
3313
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _pending, void 0);
|
|
3314
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _revision, committed.revision);
|
|
3315
|
+
} catch (error) {
|
|
3316
|
+
try {
|
|
3317
|
+
candidate.gate.gain.setValueAtTime(0, time);
|
|
3318
|
+
} catch (cleanup) {
|
|
3319
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, report_fn).call(this, cleanup);
|
|
3320
|
+
}
|
|
3321
|
+
try {
|
|
3322
|
+
_optionalChain([previous, 'optionalAccess', _257 => _257.gate, 'access', _258 => _258.gain, 'access', _259 => _259.setValueAtTime, 'call', _260 => _260(1, time)]);
|
|
3323
|
+
} catch (cleanup) {
|
|
3324
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, report_fn).call(this, cleanup);
|
|
3325
|
+
}
|
|
3326
|
+
throw error;
|
|
3327
|
+
} finally {
|
|
3328
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _committing, false);
|
|
3329
|
+
}
|
|
3330
|
+
if (previous) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, disposeGraph_fn).call(this, previous);
|
|
3331
|
+
for (const probe of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _signalProbes)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, wireProbe_fn).call(this, probe);
|
|
3332
|
+
for (const instance of candidate.instances.values()) {
|
|
3333
|
+
if (instance.activate) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, cleanup_fn).call(this, () => instance.activate());
|
|
3334
|
+
}
|
|
3335
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, notify_fn2).call(this, committed.revision, committed);
|
|
3336
|
+
return committed;
|
|
3337
|
+
};
|
|
3338
|
+
disposeGraph_fn = function(graph) {
|
|
3339
|
+
if (graph.disposed) return;
|
|
3340
|
+
graph.disposed = true;
|
|
3341
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, cleanup_fn).call(this, () => {
|
|
3342
|
+
graph.gate.gain.value = 0;
|
|
3343
|
+
});
|
|
3344
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, cleanup_fn).call(this, () => graph.controller.abort());
|
|
3345
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, cleanup_fn).call(this, () => graph.session.dispose());
|
|
3346
|
+
for (const lease of [...graph.connectionLeases.values()].reverse()) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, retire_fn).call(this, lease);
|
|
3347
|
+
for (const lease of graph.modulationLeases.values()) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, retire_fn).call(this, lease);
|
|
3348
|
+
for (const lease of graph.automationLeases.values()) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, retire_fn).call(this, lease);
|
|
3349
|
+
for (const lease of graph.leases.reverse()) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, retire_fn).call(this, lease);
|
|
3350
|
+
for (const macro of graph.macros.values()) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, cleanup_fn).call(this, () => macro.dispose());
|
|
3351
|
+
for (const instance of [...graph.instances.values()].reverse()) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, disposeInstance_fn).call(this, instance);
|
|
3352
|
+
for (const context of [...graph.contexts.values()].reverse()) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, cleanup_fn).call(this, () => context.registry.dispose());
|
|
3353
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, cleanup_fn).call(this, () => graph.gate.disconnect());
|
|
3354
|
+
};
|
|
3355
|
+
disposeInstance_fn = function(instance) {
|
|
3356
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, cleanup_fn).call(this, () => _optionalChain([instance, 'optionalAccess', _261 => _261.dispose, 'optionalCall', _262 => _262()]));
|
|
3357
|
+
};
|
|
3358
|
+
retire_fn = function(lease) {
|
|
3359
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, cleanup_fn).call(this, () => _optionalChain([lease, 'optionalAccess', _263 => _263.release, 'call', _264 => _264()]));
|
|
3360
|
+
};
|
|
3361
|
+
cleanup_fn = function(callback) {
|
|
3362
|
+
try {
|
|
3363
|
+
callback();
|
|
3364
|
+
} catch (error) {
|
|
3365
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, report_fn).call(this, error);
|
|
3366
|
+
}
|
|
3367
|
+
};
|
|
3368
|
+
report_fn = function(error) {
|
|
3369
|
+
try {
|
|
3370
|
+
const result = _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options2), 'access', _265 => _265.onCleanupError, 'optionalCall', _266 => _266(error)]);
|
|
3371
|
+
if (result && typeof result.then === "function") void Promise.resolve(result).catch(() => {
|
|
3372
|
+
});
|
|
3373
|
+
} catch (e19) {
|
|
3374
|
+
}
|
|
3375
|
+
};
|
|
3376
|
+
assertActive_fn = function() {
|
|
3377
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed3)) throw new Error("ModuleProjectRuntime is disposed.");
|
|
3378
|
+
};
|
|
3379
|
+
requireGraph_fn = function() {
|
|
3380
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, assertActive_fn).call(this);
|
|
3381
|
+
if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _graph)) throw new Error("No module project is active.");
|
|
3382
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _graph);
|
|
3383
|
+
};
|
|
3384
|
+
requireEditable_fn = function() {
|
|
3385
|
+
const graph = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, requireGraph_fn).call(this);
|
|
3386
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pending) || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _editing) || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _committing)) throw new Error("Project edits cannot overlap restore or another edit.");
|
|
3387
|
+
return graph;
|
|
3388
|
+
};
|
|
3389
|
+
assertPending_fn = function(pending) {
|
|
3390
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed3) || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pending) !== pending || pending.generation !== _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation)) throw aborted();
|
|
3391
|
+
assertSignal(pending.controller.signal);
|
|
3392
|
+
};
|
|
3393
|
+
uncapturedParameterState_fn = function(graph, moduleId, parameterId, baseValue) {
|
|
3394
|
+
const captured = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _preparedEdit);
|
|
3395
|
+
if (!captured || captured.graph !== graph) return true;
|
|
3396
|
+
return _optionalChain([captured, 'access', _267 => _267.project, 'access', _268 => _268.modules, 'access', _269 => _269.find, 'call', _270 => _270((record) => record.id === moduleId), 'optionalAccess', _271 => _271.params, 'optionalAccess', _272 => _272[parameterId]]) !== baseValue || captured.project.modulations.some((record) => {
|
|
3397
|
+
const mapping = graph.modulationLeases.get(record.id);
|
|
3398
|
+
return mapping !== void 0 && mapping.depth !== record.depth;
|
|
3399
|
+
}) || captured.project.automation.some((record) => {
|
|
3400
|
+
const automation = graph.automationLeases.get(record.id);
|
|
3401
|
+
return automation !== void 0 && automation.active !== (record.enabled !== false);
|
|
3402
|
+
});
|
|
3403
|
+
};
|
|
3404
|
+
observe_fn = function(graph, affectsSavedState = true) {
|
|
3405
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _graph) !== graph || graph.disposed) return;
|
|
3406
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _editing)) {
|
|
3407
|
+
if (affectsSavedState) _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _editObserved, true);
|
|
3408
|
+
} else _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, changed_fn).call(this);
|
|
3409
|
+
};
|
|
3410
|
+
changed_fn = function() {
|
|
3411
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, notify_fn2).call(this, ++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _revision)._);
|
|
3412
|
+
};
|
|
3413
|
+
notify_fn2 = function(revision, snapshot) {
|
|
3414
|
+
for (const listener of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners4)]) {
|
|
3415
|
+
if (revision !== _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision)) break;
|
|
3416
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners4).has(listener)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, call_fn).call(this, listener, snapshot);
|
|
3417
|
+
}
|
|
3418
|
+
};
|
|
3419
|
+
call_fn = function(listener, snapshot) {
|
|
3420
|
+
try {
|
|
3421
|
+
const result = listener(_nullishCoalesce(snapshot, () => ( this.snapshot())));
|
|
3422
|
+
if (result && typeof result.then === "function") void Promise.resolve(result).catch((error) => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, report_fn).call(this, error));
|
|
3423
|
+
} catch (error) {
|
|
3424
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _ModuleProjectRuntime_instances, report_fn).call(this, error);
|
|
3425
|
+
}
|
|
3426
|
+
};
|
|
3427
|
+
function keepProjectSessionPreloaded(runtime, options = {}) {
|
|
3428
|
+
const onError = _nullishCoalesce(options.onError, () => ( (() => {
|
|
3429
|
+
})));
|
|
3430
|
+
let released = false, scheduled = false;
|
|
3431
|
+
let session2 = runtime.session;
|
|
3432
|
+
let unwatch;
|
|
3433
|
+
let waits = 0;
|
|
3434
|
+
let waiting;
|
|
3435
|
+
const failed = (error, current) => {
|
|
3436
|
+
if (released || runtime.session !== current) return;
|
|
3437
|
+
if (!_optionalChain([options, 'access', _273 => _273.transient, 'optionalCall', _274 => _274(error)]) || waits >= 20) {
|
|
3438
|
+
onError(error);
|
|
3439
|
+
return;
|
|
3440
|
+
}
|
|
3441
|
+
waits += 1;
|
|
3442
|
+
waiting = setTimeout(() => {
|
|
3443
|
+
waiting = void 0;
|
|
3444
|
+
schedule();
|
|
3445
|
+
}, 100);
|
|
3446
|
+
};
|
|
3447
|
+
const run = () => {
|
|
3448
|
+
scheduled = false;
|
|
3449
|
+
const current = runtime.session;
|
|
3450
|
+
if (released || !current) return;
|
|
3451
|
+
let pending;
|
|
3452
|
+
try {
|
|
3453
|
+
pending = current.preload();
|
|
3454
|
+
} catch (error) {
|
|
3455
|
+
failed(error, current);
|
|
3456
|
+
return;
|
|
3457
|
+
}
|
|
3458
|
+
void pending.then(() => {
|
|
3459
|
+
waits = 0;
|
|
3460
|
+
}, (error) => failed(error, current));
|
|
3461
|
+
};
|
|
3462
|
+
const schedule = () => {
|
|
3463
|
+
if (!scheduled && !released) {
|
|
3464
|
+
scheduled = true;
|
|
3465
|
+
queueMicrotask(run);
|
|
3466
|
+
}
|
|
3467
|
+
};
|
|
3468
|
+
const watch = () => {
|
|
3469
|
+
_optionalChain([unwatch, 'optionalCall', _275 => _275()]);
|
|
3470
|
+
session2 = runtime.session;
|
|
3471
|
+
unwatch = _optionalChain([session2, 'optionalAccess', _276 => _276.subscribe, 'call', _277 => _277((event) => {
|
|
3472
|
+
if (event.type === "participants") schedule();
|
|
3473
|
+
})]);
|
|
3474
|
+
if (session2) schedule();
|
|
3475
|
+
};
|
|
3476
|
+
watch();
|
|
3477
|
+
const stop = runtime.subscribe(() => {
|
|
3478
|
+
if (runtime.session !== session2) watch();
|
|
3479
|
+
});
|
|
3480
|
+
return () => {
|
|
3481
|
+
released = true;
|
|
3482
|
+
if (waiting !== void 0) clearTimeout(waiting);
|
|
3483
|
+
stop();
|
|
3484
|
+
_optionalChain([unwatch, 'optionalCall', _278 => _278()]);
|
|
3485
|
+
unwatch = void 0;
|
|
3486
|
+
};
|
|
3487
|
+
}
|
|
3488
|
+
|
|
3489
|
+
// src/module/project-editor.ts
|
|
3490
|
+
function createProjectEditorBinding(runtime, options = {}) {
|
|
3491
|
+
const depth = _nullishCoalesce(options.modulationDepth, () => ( 1));
|
|
3492
|
+
if (!Number.isFinite(depth)) throw new RangeError("Editor modulation depth must be finite.");
|
|
3493
|
+
let sequence = 0;
|
|
3494
|
+
const snapshot = () => {
|
|
3495
|
+
const state = runtime.snapshot();
|
|
3496
|
+
const project = state.project;
|
|
3497
|
+
const parameterPorts = /* @__PURE__ */ new Map();
|
|
3498
|
+
const modules = state.modules.map((entry) => {
|
|
3499
|
+
const ports = [...entry.ports];
|
|
3500
|
+
if (entry.status === "unresolved") {
|
|
3501
|
+
const infer = (endpoint2, direction, kind) => {
|
|
3502
|
+
if (endpoint2.moduleId === entry.record.id && !ports.some((port) => port.id === endpoint2.port)) ports.push({ id: endpoint2.port, direction, kind });
|
|
3503
|
+
};
|
|
3504
|
+
for (const connection of _nullishCoalesce(_optionalChain([project, 'optionalAccess', _279 => _279.connections]), () => ( []))) {
|
|
3505
|
+
infer(connection.from, "output", connection.kind);
|
|
3506
|
+
infer(connection.to, "input", connection.kind);
|
|
3507
|
+
}
|
|
3508
|
+
for (const mapping of _nullishCoalesce(_optionalChain([project, 'optionalAccess', _280 => _280.modulations]), () => ( []))) {
|
|
3509
|
+
infer(mapping.source, "output", "control");
|
|
3510
|
+
}
|
|
3511
|
+
}
|
|
3512
|
+
const parameters = /* @__PURE__ */ new Map();
|
|
3513
|
+
for (const handle of _nullishCoalesce(_optionalChain([runtime, 'access', _281 => _281.getModule, 'call', _282 => _282(entry.record.id), 'optionalAccess', _283 => _283.params]), () => ( []))) {
|
|
3514
|
+
if (handle.descriptor.modulation === "audio-rate" || handle.descriptor.modulation === "control-rate") {
|
|
3515
|
+
parameters.set(handle.descriptor.id, _nullishCoalesce(handle.descriptor.label, () => ( handle.descriptor.id)));
|
|
3516
|
+
}
|
|
3517
|
+
}
|
|
3518
|
+
const available = new Set(parameters.keys());
|
|
3519
|
+
for (const mapping of _nullishCoalesce(_optionalChain([project, 'optionalAccess', _284 => _284.modulations]), () => ( []))) {
|
|
3520
|
+
if (mapping.target.moduleId === entry.record.id && !parameters.has(mapping.target.param)) parameters.set(mapping.target.param, mapping.target.param);
|
|
3521
|
+
}
|
|
3522
|
+
const occupied = new Set(ports.map((port) => port.id));
|
|
3523
|
+
const reserved = new Set([...parameters.keys()].map(parameterPort));
|
|
3524
|
+
const allocated = /* @__PURE__ */ new Map();
|
|
3525
|
+
parameterPorts.set(entry.record.id, allocated);
|
|
3526
|
+
for (const [parameterId, label] of [...parameters].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) {
|
|
3527
|
+
const base = parameterPort(parameterId);
|
|
3528
|
+
let id = base, suffix = 0;
|
|
3529
|
+
while (occupied.has(id)) {
|
|
3530
|
+
do {
|
|
3531
|
+
id = `${base}#${++suffix}`;
|
|
3532
|
+
} while (reserved.has(id));
|
|
3533
|
+
}
|
|
3534
|
+
occupied.add(id);
|
|
3535
|
+
allocated.set(parameterId, id);
|
|
3536
|
+
if (available.has(parameterId) || entry.status === "unresolved") ports.push({ id, parameterId, label, direction: "input", kind: "control" });
|
|
3537
|
+
}
|
|
3538
|
+
const position = _optionalChain([project, 'optionalAccess', _285 => _285.layout, 'access', _286 => _286.modules, 'access', _287 => _287.find, 'call', _288 => _288((layout2) => layout2.moduleId === entry.record.id)]);
|
|
3539
|
+
const size = _optionalChain([position, 'optionalAccess', _289 => _289.width]) !== void 0 && position.height !== void 0 ? { width: position.width, height: position.height } : void 0;
|
|
3540
|
+
return { id: entry.record.id, contextId: entry.record.contextId, label: _nullishCoalesce(entry.record.label, () => ( entry.record.id)), ports, position, ...size ? { size } : {}, status: entry.status, diagnostic: entry.diagnostic };
|
|
3541
|
+
});
|
|
3542
|
+
const diagnostic = (kind, id) => _optionalChain([state, 'access', _290 => _290.unresolved, 'access', _291 => _291.find, 'call', _292 => _292((item) => item.kind === kind && item.id === id), 'optionalAccess', _293 => _293.reason]);
|
|
3543
|
+
const connections = (_nullishCoalesce(_optionalChain([project, 'optionalAccess', _294 => _294.connections]), () => ( []))).map((record) => ({
|
|
3544
|
+
id: connectionId(record.id),
|
|
3545
|
+
recordId: record.id,
|
|
3546
|
+
from: record.from,
|
|
3547
|
+
to: record.to,
|
|
3548
|
+
mode: _nullishCoalesce(record.mode, () => ( (record.kind === "audio" ? "replace" : "connect"))),
|
|
3549
|
+
status: diagnostic("connection", record.id) ? "unresolved" : "connected",
|
|
3550
|
+
diagnostic: diagnostic("connection", record.id)
|
|
3551
|
+
}));
|
|
3552
|
+
for (const record of _nullishCoalesce(_optionalChain([project, 'optionalAccess', _295 => _295.modulations]), () => ( []))) connections.push({
|
|
3553
|
+
id: modulationId(record.id),
|
|
3554
|
+
from: record.source,
|
|
3555
|
+
to: {
|
|
3556
|
+
moduleId: record.target.moduleId,
|
|
3557
|
+
port: _nullishCoalesce(_optionalChain([parameterPorts, 'access', _296 => _296.get, 'call', _297 => _297(record.target.moduleId), 'optionalAccess', _298 => _298.get, 'call', _299 => _299(record.target.param)]), () => ( parameterPort(record.target.param)))
|
|
3558
|
+
},
|
|
3559
|
+
mode: "connect",
|
|
3560
|
+
status: diagnostic("modulation", record.id) ? "unresolved" : "connected",
|
|
3561
|
+
diagnostic: diagnostic("modulation", record.id)
|
|
3562
|
+
});
|
|
3563
|
+
for (const entry of state.modules) {
|
|
3564
|
+
const owner = state.modules.find((module) => module.record.id === entry.defaultOwnerModuleId);
|
|
3565
|
+
if (!owner || owner.status !== "ready") continue;
|
|
3566
|
+
const inputs = owner.ports.filter((port) => port.kind === "audio" && port.direction === "input");
|
|
3567
|
+
if (inputs.length !== 1) continue;
|
|
3568
|
+
const record = entry.record;
|
|
3569
|
+
for (const port of entry.ports) {
|
|
3570
|
+
if (port.kind !== "audio" || port.direction !== "output") continue;
|
|
3571
|
+
const live = _optionalChain([runtime, 'access', _300 => _300.getModule, 'call', _301 => _301(record.id), 'optionalAccess', _302 => _302.getPort, 'optionalCall', _303 => _303(port.id)]);
|
|
3572
|
+
if (!_optionalChain([live, 'optionalAccess', _304 => _304.defaultDestination]) || live.replaced) continue;
|
|
3573
|
+
connections.push({
|
|
3574
|
+
id: `default:${JSON.stringify([record.id, port.id])}`,
|
|
3575
|
+
from: { moduleId: record.id, port: port.id },
|
|
3576
|
+
to: { moduleId: owner.record.id, port: inputs[0].id },
|
|
3577
|
+
mode: "default",
|
|
3578
|
+
status: "connected",
|
|
3579
|
+
editable: false
|
|
3580
|
+
});
|
|
3581
|
+
}
|
|
3582
|
+
}
|
|
3583
|
+
return { modules, connections, disabled: state.disposed || state.restoring || !project };
|
|
3584
|
+
};
|
|
3585
|
+
return Object.freeze({
|
|
3586
|
+
snapshot,
|
|
3587
|
+
async connect(request) {
|
|
3588
|
+
const state = snapshot();
|
|
3589
|
+
if (state.disabled) throw new Error("The project is not editable.");
|
|
3590
|
+
const fromModule = state.modules.find((module) => module.id === request.from.moduleId);
|
|
3591
|
+
const toModule = state.modules.find((module) => module.id === request.to.moduleId);
|
|
3592
|
+
if (_optionalChain([fromModule, 'optionalAccess', _305 => _305.status]) !== "ready" || _optionalChain([toModule, 'optionalAccess', _306 => _306.status]) !== "ready") throw new Error("The selected module is unavailable.");
|
|
3593
|
+
const source = fromModule.ports.find((port) => port.id === request.from.port);
|
|
3594
|
+
const target = toModule.ports.find((port) => port.id === request.to.port);
|
|
3595
|
+
if (!source || !target || source.direction !== "output" || target.direction !== "input" || source.kind !== target.kind) throw new Error("Choose compatible output and input ports.");
|
|
3596
|
+
const project = runtime.exportProject();
|
|
3597
|
+
let id;
|
|
3598
|
+
do {
|
|
3599
|
+
id = `patch-${++sequence}`;
|
|
3600
|
+
} while ([...project.connections, ...project.modulations].some((record) => record.id === id));
|
|
3601
|
+
if (source.kind !== "audio" && request.mode !== "connect") throw new Error("This signal requires connect mode.");
|
|
3602
|
+
if (source.kind === "control" && target.parameterId !== void 0) {
|
|
3603
|
+
if (request.mode !== "connect") throw new Error("A parameter mapping uses connect mode.");
|
|
3604
|
+
await runtime.connectModulation({ id, source: request.from, target: { moduleId: request.to.moduleId, param: target.parameterId }, depth });
|
|
3605
|
+
} else {
|
|
3606
|
+
if (source.kind === "audio" && request.mode === "connect") throw new Error("Audio patches require replace, send or tap mode.");
|
|
3607
|
+
await runtime.connect({ id, kind: source.kind, from: request.from, to: request.to, ...request.mode !== "connect" && { mode: request.mode } });
|
|
3608
|
+
}
|
|
3609
|
+
},
|
|
3610
|
+
disconnect(id) {
|
|
3611
|
+
if (id.startsWith("connection:")) runtime.disconnect(id.slice(11));
|
|
3612
|
+
else if (id.startsWith("modulation:")) runtime.disconnectModulation(id.slice(11));
|
|
3613
|
+
else throw new Error("Default routes cannot be removed by the editor.");
|
|
3614
|
+
},
|
|
3615
|
+
moveModule(id, position) {
|
|
3616
|
+
const project = runtime.exportProject();
|
|
3617
|
+
if (!project.modules.some((module) => module.id === id)) throw new Error(`Unknown module ${id}.`);
|
|
3618
|
+
const previous = project.layout.modules.find((layout2) => layout2.moduleId === id);
|
|
3619
|
+
runtime.updateLayout({ modules: [...project.layout.modules.filter((layout2) => layout2.moduleId !== id), { ...previous, moduleId: id, ...position }] });
|
|
3620
|
+
},
|
|
3621
|
+
subscribe: (notify) => runtime.subscribe(notify)
|
|
3622
|
+
});
|
|
3623
|
+
}
|
|
3624
|
+
var parameterPort = (id) => `param:${id}`;
|
|
3625
|
+
var connectionId = (id) => `connection:${id}`;
|
|
3626
|
+
var modulationId = (id) => `modulation:${id}`;
|
|
3627
|
+
|
|
3628
|
+
// src/module/rack.ts
|
|
3629
|
+
var nextRackId = 0;
|
|
3630
|
+
var unit = (value) => Math.max(0, Math.min(1, Number.isFinite(value) ? value : 0));
|
|
3631
|
+
var balance = (value) => Math.max(-1, Math.min(1, Number.isFinite(value) ? value : 0));
|
|
3632
|
+
var _upstream, _registry, _registration, _channels, _admitting, _listeners5, _onError, _masterLevel, _params, _control, _master, _chain, _port3, _route, _recipe, _ports2, _disposed4, _preparing, _RackModule_instances, edit_fn, applyMix_fn, refreshPorts_fn, notify_fn3, assertActive_fn2;
|
|
3633
|
+
var RackModule = class {
|
|
3634
|
+
constructor(upstream, options = {}) {
|
|
3635
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _RackModule_instances);
|
|
3636
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _upstream);
|
|
3637
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _registry, new (0, _chunkBADJJ6DVcjs.ModuleRegistry)());
|
|
3638
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _registration);
|
|
3639
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _channels, /* @__PURE__ */ new Map());
|
|
3640
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _admitting, /* @__PURE__ */ new Set());
|
|
3641
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _listeners5, /* @__PURE__ */ new Set());
|
|
3642
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _onError);
|
|
3643
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _masterLevel);
|
|
3644
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _params);
|
|
3645
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _control);
|
|
3646
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _master);
|
|
3647
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _chain);
|
|
3648
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _port3);
|
|
3649
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _route);
|
|
3650
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _recipe);
|
|
3651
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _ports2, Object.freeze([]));
|
|
3652
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _disposed4, false);
|
|
3653
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _preparing, false);
|
|
3654
|
+
this.id = _nullishCoalesce(options.id, () => ( `rack-${++nextRackId}`));
|
|
3655
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _upstream, upstream);
|
|
3656
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _recipe, options.effect);
|
|
3657
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _onError, options.onError);
|
|
3658
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _masterLevel, new (0, _chunk5AHVQXTFcjs.ParamHandle)(
|
|
3659
|
+
{ id: "master-volume", label: "Master volume", unit: "gain", range: { min: 0, max: 1 }, defaultValue: 1 },
|
|
3660
|
+
{ apply: (value) => {
|
|
3661
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master)) _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master).gain.value = value;
|
|
3662
|
+
} }
|
|
3663
|
+
));
|
|
3664
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _params, new (0, _chunk5AHVQXTFcjs.ParamSurface)([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _masterLevel)]));
|
|
3665
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _control, _chunkOCKAHITLcjs.createControlPort.call(void 0, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _params)));
|
|
3666
|
+
this.context = upstream.derive({
|
|
3667
|
+
id: `${this.id}:scope`,
|
|
3668
|
+
registry: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _registry),
|
|
3669
|
+
target: this,
|
|
3670
|
+
admit: (module, port) => this.admit(module, port)
|
|
3671
|
+
});
|
|
3672
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _RackModule_instances, refreshPorts_fn).call(this);
|
|
3673
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _registration, upstream.registry.register(this));
|
|
3674
|
+
}
|
|
3675
|
+
get disposed() {
|
|
3676
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed4);
|
|
3677
|
+
}
|
|
3678
|
+
get params() {
|
|
3679
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _params);
|
|
3680
|
+
}
|
|
3681
|
+
get inserts() {
|
|
3682
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _chain);
|
|
3683
|
+
}
|
|
3684
|
+
/** Prepared master input for explicit audio patching; ownership stays with the Rack. */
|
|
3685
|
+
get input() {
|
|
3686
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master);
|
|
3687
|
+
}
|
|
3688
|
+
get effect() {
|
|
3689
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _recipe);
|
|
3690
|
+
}
|
|
3691
|
+
get masterVolume() {
|
|
3692
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _masterLevel).snapshot.baseValue;
|
|
3693
|
+
}
|
|
3694
|
+
setEffect(effect) {
|
|
3695
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _RackModule_instances, assertActive_fn2).call(this);
|
|
3696
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _preparing)) throw new Error("Effects cannot change during Rack construction.");
|
|
3697
|
+
_optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _chain), 'optionalAccess', _307 => _307.setCompatibility, 'call', _308 => _308(effect)]);
|
|
3698
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _recipe, effect);
|
|
3699
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _RackModule_instances, notify_fn3).call(this);
|
|
3700
|
+
}
|
|
3701
|
+
setMasterVolume(value) {
|
|
3702
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _masterLevel).setBaseValue(unit(value));
|
|
3703
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _RackModule_instances, notify_fn3).call(this);
|
|
3704
|
+
}
|
|
3705
|
+
list() {
|
|
3706
|
+
return Object.freeze([..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _channels).values()].map(({ id, module, volume, pan, muted, solo }) => Object.freeze({ id, module, volume, pan, muted, solo })));
|
|
3707
|
+
}
|
|
3708
|
+
channel(id) {
|
|
3709
|
+
return this.list().find((channel) => channel.id === id);
|
|
3710
|
+
}
|
|
3711
|
+
/** Stable post-fader inserts owned by this Rack channel. */
|
|
3712
|
+
channelInserts(id) {
|
|
3713
|
+
return _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _channels), 'access', _309 => _309.get, 'call', _310 => _310(id), 'optionalAccess', _311 => _311.inserts]);
|
|
3714
|
+
}
|
|
3715
|
+
setVolume(id, value) {
|
|
3716
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _RackModule_instances, edit_fn).call(this, id, (channel) => {
|
|
3717
|
+
channel.volume = unit(value);
|
|
3718
|
+
});
|
|
3719
|
+
}
|
|
3720
|
+
setPan(id, value) {
|
|
3721
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _RackModule_instances, edit_fn).call(this, id, (channel) => {
|
|
3722
|
+
channel.pan = balance(value);
|
|
3723
|
+
if (channel.panner) channel.panner.pan.value = channel.pan;
|
|
3724
|
+
});
|
|
3725
|
+
}
|
|
3726
|
+
mute(id, muted) {
|
|
3727
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _RackModule_instances, edit_fn).call(this, id, (channel) => {
|
|
3728
|
+
channel.muted = muted;
|
|
3729
|
+
});
|
|
3730
|
+
}
|
|
3731
|
+
solo(id, solo) {
|
|
3732
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _RackModule_instances, edit_fn).call(this, id, (channel) => {
|
|
3733
|
+
channel.solo = solo;
|
|
3734
|
+
});
|
|
3735
|
+
}
|
|
3736
|
+
/** `master` (aliases `output`, `main`) or `channel:<module id>` for a post-insert channel tap. */
|
|
3737
|
+
getPort(name) {
|
|
3738
|
+
if (name === "master" || name === "output" || name === "main") return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _port3);
|
|
3739
|
+
return name.startsWith("channel:") ? _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _channels), 'access', _312 => _312.get, 'call', _313 => _313(name.slice("channel:".length)), 'optionalAccess', _314 => _314.output]) : void 0;
|
|
3740
|
+
}
|
|
3741
|
+
ports() {
|
|
3742
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _ports2);
|
|
3743
|
+
}
|
|
3744
|
+
prepare() {
|
|
3745
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _RackModule_instances, assertActive_fn2).call(this);
|
|
3746
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _chain)) return;
|
|
3747
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _preparing)) throw new Error("Rack preparation cannot reenter audio graph construction.");
|
|
3748
|
+
const audio = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _upstream).audio.prepare();
|
|
3749
|
+
const master = audio.createGain();
|
|
3750
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _preparing, true);
|
|
3751
|
+
let chain;
|
|
3752
|
+
let port;
|
|
3753
|
+
let route;
|
|
3754
|
+
try {
|
|
3755
|
+
master.gain.value = this.masterVolume;
|
|
3756
|
+
chain = new (0, _chunkC3LMS36Lcjs.InsertChain)(audio);
|
|
3757
|
+
chain.setCompatibility(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _recipe));
|
|
3758
|
+
master.connect(chain.input);
|
|
3759
|
+
port = new (0, _chunkOCKAHITLcjs.AudioOutputPort)(chain.output, { id: "master" });
|
|
3760
|
+
route = _chunkOCKAHITLcjs.routeModuleOutput.call(void 0, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _upstream), this, port);
|
|
3761
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _RackModule_instances, assertActive_fn2).call(this);
|
|
3762
|
+
if (!route.active) throw new Error("Rack admission was cancelled.");
|
|
3763
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _master, master);
|
|
3764
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _chain, chain);
|
|
3765
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _port3, port);
|
|
3766
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _route, route);
|
|
3767
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _RackModule_instances, refreshPorts_fn).call(this);
|
|
3768
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _RackModule_instances, notify_fn3).call(this);
|
|
3769
|
+
} catch (error) {
|
|
3770
|
+
try {
|
|
3771
|
+
_optionalChain([route, 'optionalAccess', _315 => _315.release, 'call', _316 => _316()]);
|
|
3772
|
+
} catch (e20) {
|
|
3773
|
+
}
|
|
3774
|
+
try {
|
|
3775
|
+
_optionalChain([port, 'optionalAccess', _317 => _317.dispose, 'call', _318 => _318()]);
|
|
3776
|
+
} catch (e21) {
|
|
3777
|
+
}
|
|
3778
|
+
try {
|
|
3779
|
+
_optionalChain([chain, 'optionalAccess', _319 => _319.dispose, 'call', _320 => _320()]);
|
|
3780
|
+
} catch (e22) {
|
|
3781
|
+
}
|
|
3782
|
+
try {
|
|
3783
|
+
master.disconnect();
|
|
3784
|
+
} catch (e23) {
|
|
3785
|
+
}
|
|
3786
|
+
throw error;
|
|
3787
|
+
} finally {
|
|
3788
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _preparing, false);
|
|
3789
|
+
}
|
|
3790
|
+
}
|
|
3791
|
+
/**
|
|
3792
|
+
* Follow a republished upstream scope in place (DEC-065): a destination-only
|
|
3793
|
+
* change re-routes the prepared master and keeps every channel, level and
|
|
3794
|
+
* member. Returns false when the change needs a rebind.
|
|
3795
|
+
*/
|
|
3796
|
+
retarget(next) {
|
|
3797
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _RackModule_instances, assertActive_fn2).call(this);
|
|
3798
|
+
const change = _chunkOCKAHITLcjs.moduleScopeChange.call(void 0, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _upstream), next);
|
|
3799
|
+
if (change === "scope") return false;
|
|
3800
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _upstream, next);
|
|
3801
|
+
if (change === "destination" && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _route) && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _port3)) {
|
|
3802
|
+
const previous = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _route);
|
|
3803
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _route, void 0);
|
|
3804
|
+
previous.release();
|
|
3805
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _route, _chunkOCKAHITLcjs.routeModuleOutput.call(void 0, next, this, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _port3)));
|
|
3806
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _RackModule_instances, notify_fn3).call(this);
|
|
3807
|
+
}
|
|
3808
|
+
return true;
|
|
3809
|
+
}
|
|
3810
|
+
/** Give a module's output its own channel. The lease removes only that channel. */
|
|
3811
|
+
admit(module, port) {
|
|
3812
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _RackModule_instances, assertActive_fn2).call(this);
|
|
3813
|
+
if (module === this) throw new Error("A Rack cannot admit its own output.");
|
|
3814
|
+
const assertAvailable = () => {
|
|
3815
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _channels).has(module.id) || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _admitting).has(module.id)) throw new Error(`Module ${module.id} already has a Rack channel.`);
|
|
3816
|
+
};
|
|
3817
|
+
assertAvailable();
|
|
3818
|
+
this.prepare();
|
|
3819
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _RackModule_instances, assertActive_fn2).call(this);
|
|
3820
|
+
assertAvailable();
|
|
3821
|
+
const master = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master);
|
|
3822
|
+
if (port.context !== master.context) throw new Error("Rack admission requires the same AudioContext.");
|
|
3823
|
+
const previousDestination = port.defaultDestination;
|
|
3824
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _admitting).add(module.id);
|
|
3825
|
+
let fader;
|
|
3826
|
+
let panner;
|
|
3827
|
+
let inserts;
|
|
3828
|
+
let output;
|
|
3829
|
+
let channel;
|
|
3830
|
+
try {
|
|
3831
|
+
const context = master.context;
|
|
3832
|
+
fader = context.createGain();
|
|
3833
|
+
panner = typeof context.createStereoPanner === "function" ? context.createStereoPanner() : void 0;
|
|
3834
|
+
inserts = new (0, _chunkC3LMS36Lcjs.InsertChain)(context, { onCleanupError: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _onError) });
|
|
3835
|
+
if (panner) {
|
|
3836
|
+
fader.connect(panner);
|
|
3837
|
+
panner.connect(inserts.input);
|
|
3838
|
+
} else fader.connect(inserts.input);
|
|
3839
|
+
output = new (0, _chunkOCKAHITLcjs.AudioOutputPort)(inserts.output, { id: `channel:${module.id}`, defaultDestination: master, onCleanupError: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _onError) });
|
|
3840
|
+
port.setDefault(fader);
|
|
3841
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _RackModule_instances, assertActive_fn2).call(this);
|
|
3842
|
+
const channelFader = fader;
|
|
3843
|
+
const channelPanner = panner;
|
|
3844
|
+
const channelInserts = inserts;
|
|
3845
|
+
const channelOutput = output;
|
|
3846
|
+
channel = {
|
|
3847
|
+
id: module.id,
|
|
3848
|
+
module,
|
|
3849
|
+
fader,
|
|
3850
|
+
panner,
|
|
3851
|
+
inserts,
|
|
3852
|
+
output,
|
|
3853
|
+
volume: 1,
|
|
3854
|
+
pan: 0,
|
|
3855
|
+
muted: false,
|
|
3856
|
+
solo: false,
|
|
3857
|
+
lease: _chunkEXDCK2VLcjs.createConnectionLease.call(void 0, () => {
|
|
3858
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _channels).get(module.id) === channel) _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _channels).delete(module.id);
|
|
3859
|
+
let failure;
|
|
3860
|
+
const clean = (callback) => {
|
|
3861
|
+
try {
|
|
3862
|
+
callback();
|
|
3863
|
+
} catch (error) {
|
|
3864
|
+
_nullishCoalesce(failure, () => ( (failure = error)));
|
|
3865
|
+
}
|
|
3866
|
+
};
|
|
3867
|
+
clean(() => {
|
|
3868
|
+
if (!port.disposed && port.defaultDestination === channelFader) port.setDefault(void 0);
|
|
3869
|
+
});
|
|
3870
|
+
clean(() => channelOutput.dispose());
|
|
3871
|
+
clean(() => channelFader.disconnect(_nullishCoalesce(channelPanner, () => ( channelInserts.input))));
|
|
3872
|
+
clean(() => _optionalChain([channelPanner, 'optionalAccess', _321 => _321.disconnect, 'call', _322 => _322(channelInserts.input)]));
|
|
3873
|
+
clean(() => channelInserts.dispose());
|
|
3874
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _RackModule_instances, refreshPorts_fn).call(this);
|
|
3875
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _RackModule_instances, applyMix_fn).call(this);
|
|
3876
|
+
if (failure !== void 0) throw failure;
|
|
3877
|
+
})
|
|
3878
|
+
};
|
|
3879
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _channels).set(module.id, channel);
|
|
3880
|
+
} catch (error) {
|
|
3881
|
+
try {
|
|
3882
|
+
if (fader && !port.disposed && port.defaultDestination === fader) {
|
|
3883
|
+
port.setDefault(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed4) ? void 0 : previousDestination);
|
|
3884
|
+
}
|
|
3885
|
+
} catch (e24) {
|
|
3886
|
+
}
|
|
3887
|
+
try {
|
|
3888
|
+
_optionalChain([output, 'optionalAccess', _323 => _323.dispose, 'call', _324 => _324()]);
|
|
3889
|
+
} catch (e25) {
|
|
3890
|
+
}
|
|
3891
|
+
try {
|
|
3892
|
+
_optionalChain([inserts, 'optionalAccess', _325 => _325.dispose, 'call', _326 => _326()]);
|
|
3893
|
+
} catch (e26) {
|
|
3894
|
+
}
|
|
3895
|
+
try {
|
|
3896
|
+
if (panner && inserts) panner.disconnect(inserts.input);
|
|
3897
|
+
} catch (e27) {
|
|
3898
|
+
}
|
|
3899
|
+
try {
|
|
3900
|
+
if (fader && inserts) fader.disconnect(_nullishCoalesce(panner, () => ( inserts.input)));
|
|
3901
|
+
} catch (e28) {
|
|
3902
|
+
}
|
|
3903
|
+
throw error;
|
|
3904
|
+
} finally {
|
|
3905
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _admitting).delete(module.id);
|
|
3906
|
+
}
|
|
3907
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _RackModule_instances, refreshPorts_fn).call(this);
|
|
3908
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _RackModule_instances, applyMix_fn).call(this);
|
|
3909
|
+
return channel.lease;
|
|
3910
|
+
}
|
|
3911
|
+
subscribe(listener) {
|
|
3912
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners5).add(listener);
|
|
3913
|
+
return () => {
|
|
3914
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners5).delete(listener);
|
|
3915
|
+
};
|
|
3916
|
+
}
|
|
3917
|
+
dispose() {
|
|
3918
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed4)) return;
|
|
3919
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _disposed4, true);
|
|
3920
|
+
let failure;
|
|
3921
|
+
const clean = (callback) => {
|
|
3922
|
+
try {
|
|
3923
|
+
callback();
|
|
3924
|
+
} catch (error) {
|
|
3925
|
+
_nullishCoalesce(failure, () => ( (failure = error)));
|
|
3926
|
+
}
|
|
3927
|
+
};
|
|
3928
|
+
for (const channel of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _channels).values()]) clean(() => channel.lease.release());
|
|
3929
|
+
clean(() => _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _route), 'optionalAccess', _327 => _327.release, 'call', _328 => _328()]));
|
|
3930
|
+
clean(() => _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _port3), 'optionalAccess', _329 => _329.dispose, 'call', _330 => _330()]));
|
|
3931
|
+
clean(() => _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _chain), 'optionalAccess', _331 => _331.dispose, 'call', _332 => _332()]));
|
|
3932
|
+
clean(() => _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master), 'optionalAccess', _333 => _333.disconnect, 'call', _334 => _334()]));
|
|
3933
|
+
clean(() => _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _masterLevel).dispose());
|
|
3934
|
+
clean(() => _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _registration).release());
|
|
3935
|
+
clean(() => _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _registry).dispose());
|
|
3936
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners5).clear();
|
|
3937
|
+
if (failure !== void 0) throw failure;
|
|
3938
|
+
}
|
|
3939
|
+
};
|
|
3940
|
+
_upstream = new WeakMap();
|
|
3941
|
+
_registry = new WeakMap();
|
|
3942
|
+
_registration = new WeakMap();
|
|
3943
|
+
_channels = new WeakMap();
|
|
3944
|
+
_admitting = new WeakMap();
|
|
3945
|
+
_listeners5 = new WeakMap();
|
|
3946
|
+
_onError = new WeakMap();
|
|
3947
|
+
_masterLevel = new WeakMap();
|
|
3948
|
+
_params = new WeakMap();
|
|
3949
|
+
_control = new WeakMap();
|
|
3950
|
+
_master = new WeakMap();
|
|
3951
|
+
_chain = new WeakMap();
|
|
3952
|
+
_port3 = new WeakMap();
|
|
3953
|
+
_route = new WeakMap();
|
|
3954
|
+
_recipe = new WeakMap();
|
|
3955
|
+
_ports2 = new WeakMap();
|
|
3956
|
+
_disposed4 = new WeakMap();
|
|
3957
|
+
_preparing = new WeakMap();
|
|
3958
|
+
_RackModule_instances = new WeakSet();
|
|
3959
|
+
edit_fn = function(id, change) {
|
|
3960
|
+
const channel = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _channels).get(id);
|
|
3961
|
+
if (!channel) return;
|
|
3962
|
+
change(channel);
|
|
3963
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _RackModule_instances, applyMix_fn).call(this);
|
|
3964
|
+
};
|
|
3965
|
+
applyMix_fn = function() {
|
|
3966
|
+
const solo = [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _channels).values()].some((channel) => channel.solo);
|
|
3967
|
+
for (const channel of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _channels).values()) {
|
|
3968
|
+
channel.fader.gain.value = channel.muted || solo && !channel.solo ? 0 : channel.volume;
|
|
3969
|
+
}
|
|
3970
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _RackModule_instances, notify_fn3).call(this);
|
|
3971
|
+
};
|
|
3972
|
+
refreshPorts_fn = function() {
|
|
3973
|
+
const ports = [_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _control)];
|
|
3974
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _port3)) ports.push(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _port3));
|
|
3975
|
+
for (const channel of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _channels).values()) ports.push(channel.output);
|
|
3976
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _ports2, Object.freeze(ports));
|
|
3977
|
+
};
|
|
3978
|
+
notify_fn3 = function() {
|
|
3979
|
+
var _a;
|
|
3980
|
+
for (const listener of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners5)]) {
|
|
3981
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed4)) break;
|
|
3982
|
+
try {
|
|
3983
|
+
listener();
|
|
3984
|
+
} catch (error) {
|
|
3985
|
+
try {
|
|
3986
|
+
(_a = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _onError)) == null ? void 0 : _a.call(this, error);
|
|
3987
|
+
} catch (e29) {
|
|
3988
|
+
}
|
|
3989
|
+
}
|
|
3990
|
+
}
|
|
3991
|
+
};
|
|
3992
|
+
assertActive_fn2 = function() {
|
|
3993
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed4)) throw new Error("Rack module has been disposed.");
|
|
3994
|
+
};
|
|
3995
|
+
|
|
3996
|
+
// src/module/provider-scope.ts
|
|
3997
|
+
function createProviderScope(options) {
|
|
3998
|
+
const { parent } = options;
|
|
3999
|
+
const ownedAudio = parent ? void 0 : new (0, _chunkOCKAHITLcjs.ModuleAudioEnvironment)(options.audio);
|
|
4000
|
+
const audio = _nullishCoalesce(_optionalChain([parent, 'optionalAccess', _335 => _335.audio]), () => ( ownedAudio));
|
|
4001
|
+
const inherited = options.local ? void 0 : _optionalChain([parent, 'optionalAccess', _336 => _336.session]);
|
|
4002
|
+
const ownedSession = inherited ? void 0 : new (0, _chunkJFCBJMA7cjs.SessionTransport)(_nullishCoalesce(_optionalChain([options, 'access', _337 => _337.session, 'optionalAccess', _338 => _338.now]), () => ( (() => _nullishCoalesce(_optionalChain([audio, 'access', _339 => _339.peek, 'call', _340 => _340(), 'optionalAccess', _341 => _341.currentTime]), () => ( 0))))), options.session);
|
|
4003
|
+
const session2 = _nullishCoalesce(inherited, () => ( ownedSession));
|
|
4004
|
+
let context;
|
|
4005
|
+
try {
|
|
4006
|
+
const relation = {
|
|
4007
|
+
id: options.id,
|
|
4008
|
+
session: session2,
|
|
4009
|
+
registry: options.registry,
|
|
4010
|
+
...options.admit !== void 0 ? { admit: options.admit } : {},
|
|
4011
|
+
...options.target !== void 0 ? { target: options.target } : {}
|
|
4012
|
+
};
|
|
4013
|
+
context = parent ? parent.derive(relation) : new (0, _chunkOCKAHITLcjs.ModuleContext)({
|
|
4014
|
+
...relation,
|
|
4015
|
+
audio,
|
|
4016
|
+
destination: options.destination,
|
|
4017
|
+
admit: _nullishCoalesce(options.admit, () => ( void 0)),
|
|
4018
|
+
target: _nullishCoalesce(options.target, () => ( void 0))
|
|
4019
|
+
});
|
|
4020
|
+
} catch (error) {
|
|
4021
|
+
_optionalChain([ownedSession, 'optionalAccess', _342 => _342.dispose, 'call', _343 => _343()]);
|
|
4022
|
+
_optionalChain([ownedAudio, 'optionalAccess', _344 => _344.dispose, 'call', _345 => _345()]);
|
|
4023
|
+
throw error;
|
|
4024
|
+
}
|
|
4025
|
+
let disposed = false;
|
|
4026
|
+
return Object.freeze({
|
|
4027
|
+
context,
|
|
4028
|
+
session: session2,
|
|
4029
|
+
ownedSession,
|
|
4030
|
+
ownedAudio,
|
|
4031
|
+
dispose() {
|
|
4032
|
+
if (disposed) return;
|
|
4033
|
+
disposed = true;
|
|
4034
|
+
let failure;
|
|
4035
|
+
try {
|
|
4036
|
+
_optionalChain([ownedSession, 'optionalAccess', _346 => _346.dispose, 'call', _347 => _347()]);
|
|
4037
|
+
} catch (error) {
|
|
4038
|
+
failure = error;
|
|
4039
|
+
}
|
|
4040
|
+
try {
|
|
4041
|
+
_optionalChain([ownedAudio, 'optionalAccess', _348 => _348.dispose, 'call', _349 => _349()]);
|
|
4042
|
+
} catch (error) {
|
|
4043
|
+
_nullishCoalesce(failure, () => ( (failure = error)));
|
|
4044
|
+
}
|
|
4045
|
+
if (failure !== void 0) throw failure;
|
|
4046
|
+
}
|
|
4047
|
+
});
|
|
4048
|
+
}
|
|
4049
|
+
|
|
4050
|
+
// src/module/sinks.ts
|
|
4051
|
+
var _input, _ports3, _listeners6, _disposed5;
|
|
4052
|
+
var AudioSink = class {
|
|
4053
|
+
constructor(environment, id) {
|
|
4054
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _input);
|
|
4055
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _ports3, Object.freeze([]));
|
|
4056
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _listeners6, /* @__PURE__ */ new Set());
|
|
4057
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _disposed5, false);
|
|
4058
|
+
_chunkBADJJ6DVcjs.assertModuleId.call(void 0, id);
|
|
4059
|
+
this.id = id;
|
|
4060
|
+
this.environment = environment;
|
|
4061
|
+
}
|
|
4062
|
+
get disposed() {
|
|
4063
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed5);
|
|
4064
|
+
}
|
|
4065
|
+
/** Present after {@link prepare}; producers connect to it. */
|
|
4066
|
+
get input() {
|
|
4067
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _input);
|
|
4068
|
+
}
|
|
4069
|
+
ports() {
|
|
4070
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _ports3);
|
|
4071
|
+
}
|
|
4072
|
+
prepare() {
|
|
4073
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed5)) throw new Error(`${this.constructor.name} is disposed`);
|
|
4074
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _input)) return;
|
|
4075
|
+
const context = this.environment.prepare();
|
|
4076
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _input, new (0, _chunkOCKAHITLcjs.AudioInputPort)(this.createInput(context), { id: "input" }));
|
|
4077
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _ports3, Object.freeze([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _input)]));
|
|
4078
|
+
this.notify();
|
|
4079
|
+
}
|
|
4080
|
+
subscribe(listener) {
|
|
4081
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners6).add(listener);
|
|
4082
|
+
return () => {
|
|
4083
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners6).delete(listener);
|
|
4084
|
+
};
|
|
4085
|
+
}
|
|
4086
|
+
dispose() {
|
|
4087
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed5)) return;
|
|
4088
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _disposed5, true);
|
|
4089
|
+
let failure;
|
|
4090
|
+
try {
|
|
4091
|
+
_optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _input), 'optionalAccess', _350 => _350.dispose, 'call', _351 => _351()]);
|
|
4092
|
+
} catch (error) {
|
|
4093
|
+
failure = error;
|
|
4094
|
+
}
|
|
4095
|
+
try {
|
|
4096
|
+
this.release();
|
|
4097
|
+
} catch (error) {
|
|
4098
|
+
_nullishCoalesce(failure, () => ( (failure = error)));
|
|
4099
|
+
}
|
|
4100
|
+
this.notify();
|
|
4101
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners6).clear();
|
|
4102
|
+
if (failure !== void 0) throw failure;
|
|
4103
|
+
}
|
|
4104
|
+
release() {
|
|
4105
|
+
}
|
|
4106
|
+
notify() {
|
|
4107
|
+
for (const listener of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners6)]) {
|
|
4108
|
+
try {
|
|
4109
|
+
listener();
|
|
4110
|
+
} catch (e30) {
|
|
4111
|
+
}
|
|
4112
|
+
}
|
|
4113
|
+
}
|
|
4114
|
+
};
|
|
4115
|
+
_input = new WeakMap();
|
|
4116
|
+
_ports3 = new WeakMap();
|
|
4117
|
+
_listeners6 = new WeakMap();
|
|
4118
|
+
_disposed5 = new WeakMap();
|
|
4119
|
+
var DeviceSink = class extends AudioSink {
|
|
4120
|
+
constructor(environment, options = {}) {
|
|
4121
|
+
super(environment, _nullishCoalesce(options.id, () => ( "device")));
|
|
4122
|
+
}
|
|
4123
|
+
get supportsDeviceSelection() {
|
|
4124
|
+
const context = this.environment.peek();
|
|
4125
|
+
return typeof _optionalChain([context, 'optionalAccess', _352 => _352.setSinkId]) === "function";
|
|
4126
|
+
}
|
|
4127
|
+
/** Route the whole environment to another output device; rejects where unsupported. */
|
|
4128
|
+
async selectDevice(deviceId) {
|
|
4129
|
+
this.prepare();
|
|
4130
|
+
const context = this.environment.peek();
|
|
4131
|
+
if (typeof context.setSinkId !== "function") throw new Error("Output device selection is unavailable in this environment");
|
|
4132
|
+
await context.setSinkId(deviceId);
|
|
4133
|
+
this.notify();
|
|
4134
|
+
}
|
|
4135
|
+
createInput(context) {
|
|
4136
|
+
return context.destination;
|
|
4137
|
+
}
|
|
4138
|
+
};
|
|
4139
|
+
var _options3, _node2, _recorder, _take;
|
|
4140
|
+
var CaptureSink = class extends AudioSink {
|
|
4141
|
+
constructor(environment, options = {}) {
|
|
4142
|
+
super(environment, _nullishCoalesce(options.id, () => ( "capture")));
|
|
4143
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _options3);
|
|
4144
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _node2);
|
|
4145
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _recorder);
|
|
4146
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _take);
|
|
4147
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _options3, options);
|
|
4148
|
+
}
|
|
4149
|
+
get recording() {
|
|
4150
|
+
return _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _recorder), 'optionalAccess', _353 => _353.state]) === "recording";
|
|
4151
|
+
}
|
|
4152
|
+
start() {
|
|
4153
|
+
this.prepare();
|
|
4154
|
+
if (this.recording) throw new Error("CaptureSink is already recording");
|
|
4155
|
+
const Recorder = _nullishCoalesce(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options3).recorder, () => ( globalThis.MediaRecorder));
|
|
4156
|
+
if (!Recorder) throw new Error("MediaRecorder is unavailable in this environment");
|
|
4157
|
+
const recorder = new Recorder(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _node2).stream, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options3).mimeType ? { mimeType: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options3).mimeType } : void 0);
|
|
4158
|
+
const chunks = [];
|
|
4159
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _take, new Promise((resolve, reject) => {
|
|
4160
|
+
recorder.addEventListener("dataavailable", (event) => {
|
|
4161
|
+
if (event.data.size > 0) chunks.push(event.data);
|
|
4162
|
+
});
|
|
4163
|
+
recorder.addEventListener("stop", () => resolve(new Blob(chunks, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options3).mimeType ? { type: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options3).mimeType } : void 0)));
|
|
4164
|
+
recorder.addEventListener("error", (event) => reject(_nullishCoalesce(event.error, () => ( new Error("Capture failed")))));
|
|
4165
|
+
}));
|
|
4166
|
+
void _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _take).catch(() => {
|
|
4167
|
+
});
|
|
4168
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _recorder, recorder);
|
|
4169
|
+
recorder.start();
|
|
4170
|
+
this.notify();
|
|
4171
|
+
}
|
|
4172
|
+
/** Finish the current take. */
|
|
4173
|
+
stop() {
|
|
4174
|
+
const recorder = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _recorder);
|
|
4175
|
+
const take = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _take);
|
|
4176
|
+
if (!recorder || !take) return Promise.reject(new Error("CaptureSink is not recording"));
|
|
4177
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _recorder, void 0);
|
|
4178
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _take, void 0);
|
|
4179
|
+
if (recorder.state !== "inactive") recorder.stop();
|
|
4180
|
+
this.notify();
|
|
4181
|
+
return take;
|
|
4182
|
+
}
|
|
4183
|
+
createInput(context) {
|
|
4184
|
+
const create = context.createMediaStreamDestination;
|
|
4185
|
+
if (typeof create !== "function") throw new Error("Audio capture requires a live AudioContext");
|
|
4186
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _node2, create.call(context));
|
|
4187
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _node2);
|
|
4188
|
+
}
|
|
4189
|
+
release() {
|
|
4190
|
+
const recorder = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _recorder);
|
|
4191
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _recorder, void 0);
|
|
4192
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _take, void 0);
|
|
4193
|
+
if (recorder && recorder.state !== "inactive") recorder.stop();
|
|
4194
|
+
}
|
|
4195
|
+
};
|
|
4196
|
+
_options3 = new WeakMap();
|
|
4197
|
+
_node2 = new WeakMap();
|
|
4198
|
+
_recorder = new WeakMap();
|
|
4199
|
+
_take = new WeakMap();
|
|
4200
|
+
var offlineContexts = /* @__PURE__ */ new WeakSet();
|
|
4201
|
+
function isOfflineModuleContext(context) {
|
|
4202
|
+
return !!context && offlineContexts.has(context);
|
|
4203
|
+
}
|
|
4204
|
+
var _running;
|
|
4205
|
+
var OfflineTicks = class {
|
|
4206
|
+
constructor() {
|
|
4207
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _running, /* @__PURE__ */ new Set());
|
|
4208
|
+
}
|
|
4209
|
+
create() {
|
|
4210
|
+
let callback;
|
|
4211
|
+
let disposed = false;
|
|
4212
|
+
const running = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _running);
|
|
4213
|
+
const deliver = () => _optionalChain([callback, 'optionalCall', _354 => _354()]);
|
|
4214
|
+
return {
|
|
4215
|
+
start(onTick) {
|
|
4216
|
+
if (disposed) throw new Error("Tick source is disposed");
|
|
4217
|
+
callback = onTick;
|
|
4218
|
+
running.add(deliver);
|
|
4219
|
+
},
|
|
4220
|
+
stop() {
|
|
4221
|
+
running.delete(deliver);
|
|
4222
|
+
},
|
|
4223
|
+
get running() {
|
|
4224
|
+
return running.has(deliver);
|
|
4225
|
+
},
|
|
4226
|
+
workerBacked: false,
|
|
4227
|
+
dispose() {
|
|
4228
|
+
disposed = true;
|
|
4229
|
+
running.delete(deliver);
|
|
4230
|
+
callback = void 0;
|
|
4231
|
+
}
|
|
4232
|
+
};
|
|
4233
|
+
}
|
|
4234
|
+
get active() {
|
|
4235
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _running).size > 0;
|
|
4236
|
+
}
|
|
4237
|
+
tick() {
|
|
4238
|
+
for (const deliver of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _running)]) {
|
|
4239
|
+
try {
|
|
4240
|
+
deliver();
|
|
4241
|
+
} catch (e31) {
|
|
4242
|
+
}
|
|
4243
|
+
}
|
|
4244
|
+
}
|
|
4245
|
+
};
|
|
4246
|
+
_running = new WeakMap();
|
|
4247
|
+
function createOfflineModuleEnvironment(options) {
|
|
4248
|
+
const channels = _nullishCoalesce(options.channels, () => ( 2));
|
|
4249
|
+
if (!Number.isInteger(channels) || channels < 1) throw new RangeError("channels must be a positive integer");
|
|
4250
|
+
if (!Number.isFinite(options.sampleRate) || options.sampleRate <= 0) throw new RangeError("sampleRate must be positive");
|
|
4251
|
+
let length = options.length;
|
|
4252
|
+
if (length === void 0) {
|
|
4253
|
+
const seconds = options.durationSeconds;
|
|
4254
|
+
if (seconds === void 0 || !Number.isFinite(seconds) || seconds <= 0) throw new RangeError("durationSeconds must be positive");
|
|
4255
|
+
length = Math.ceil(seconds * options.sampleRate);
|
|
4256
|
+
}
|
|
4257
|
+
if (!Number.isInteger(length) || length < 1) throw new RangeError("length must be a positive integer number of frames");
|
|
4258
|
+
const step = _nullishCoalesce(options.tickSeconds, () => ( 0.025));
|
|
4259
|
+
if (!Number.isFinite(step) || step <= 0) throw new RangeError("tickSeconds must be positive");
|
|
4260
|
+
const create = _nullishCoalesce(options.create, () => ( ((count, frames2, rate) => {
|
|
4261
|
+
const Offline = globalThis.OfflineAudioContext;
|
|
4262
|
+
if (!Offline) throw new Error("OfflineAudioContext is unavailable in this environment");
|
|
4263
|
+
return new Offline(count, frames2, rate);
|
|
4264
|
+
})));
|
|
4265
|
+
const context = create(channels, length, options.sampleRate);
|
|
4266
|
+
offlineContexts.add(context);
|
|
4267
|
+
const ticks = new OfflineTicks();
|
|
4268
|
+
const nativeResume = typeof context.resume === "function" ? context.resume.bind(context) : void 0;
|
|
4269
|
+
const nativeState = _optionalChain([Object, 'access', _355 => _355.getOwnPropertyDescriptor, 'call', _356 => _356(_nullishCoalesce(Object.getPrototypeOf(context), () => ( {})), "state"), 'optionalAccess', _357 => _357.get]);
|
|
4270
|
+
let rendering = false;
|
|
4271
|
+
try {
|
|
4272
|
+
Object.defineProperty(context, "state", {
|
|
4273
|
+
configurable: true,
|
|
4274
|
+
get: () => rendering && nativeState ? nativeState.call(context) : "running"
|
|
4275
|
+
});
|
|
4276
|
+
Object.defineProperty(context, "resume", { configurable: true, value: () => rendering && nativeResume ? nativeResume() : Promise.resolve() });
|
|
4277
|
+
} catch (e32) {
|
|
4278
|
+
}
|
|
4279
|
+
const environment = new (0, _chunkOCKAHITLcjs.ModuleAudioEnvironment)({ context, createTickSource: () => ticks.create() });
|
|
4280
|
+
const frames = length;
|
|
4281
|
+
let rendered;
|
|
4282
|
+
return Object.freeze({
|
|
4283
|
+
environment,
|
|
4284
|
+
context,
|
|
4285
|
+
render: () => _nullishCoalesce(rendered, () => ( (rendered = (() => {
|
|
4286
|
+
rendering = true;
|
|
4287
|
+
const end = frames / options.sampleRate;
|
|
4288
|
+
if (typeof context.suspend === "function" && nativeResume) {
|
|
4289
|
+
const quantum = 128 / options.sampleRate;
|
|
4290
|
+
let previous = -1;
|
|
4291
|
+
for (let time = step; time < end; time += step) {
|
|
4292
|
+
const at = Math.floor(time / quantum) * quantum;
|
|
4293
|
+
if (at <= previous) continue;
|
|
4294
|
+
previous = at;
|
|
4295
|
+
void context.suspend(at).then(() => {
|
|
4296
|
+
ticks.tick();
|
|
4297
|
+
return nativeResume();
|
|
4298
|
+
}).catch(() => {
|
|
4299
|
+
});
|
|
4300
|
+
}
|
|
4301
|
+
}
|
|
4302
|
+
ticks.tick();
|
|
4303
|
+
return context.startRendering();
|
|
4304
|
+
})())))
|
|
4305
|
+
});
|
|
4306
|
+
}
|
|
4307
|
+
|
|
4308
|
+
// src/module/offline-render.ts
|
|
4309
|
+
async function renderModuleGraph(options) {
|
|
4310
|
+
const offline = createOfflineModuleEnvironment(options);
|
|
4311
|
+
const session2 = new (0, _chunkJFCBJMA7cjs.SessionTransport)(() => offline.context.currentTime, { driftCheckIntervalMs: 0 });
|
|
4312
|
+
const scope = new (0, _chunkOCKAHITLcjs.ModuleContext)({ id: _nullishCoalesce(options.id, () => ( "offline")), audio: offline.environment, session: session2 });
|
|
4313
|
+
let cleanup = void 0;
|
|
4314
|
+
try {
|
|
4315
|
+
cleanup = await options.build(scope);
|
|
4316
|
+
if (options.startSeconds) await session2.seek(options.startSeconds);
|
|
4317
|
+
await session2.play();
|
|
4318
|
+
return await offline.render();
|
|
4319
|
+
} finally {
|
|
4320
|
+
try {
|
|
4321
|
+
await session2.stop();
|
|
4322
|
+
} catch (e33) {
|
|
4323
|
+
}
|
|
4324
|
+
try {
|
|
4325
|
+
if (typeof cleanup === "function") cleanup();
|
|
4326
|
+
} finally {
|
|
4327
|
+
session2.dispose();
|
|
4328
|
+
}
|
|
4329
|
+
}
|
|
4330
|
+
}
|
|
4331
|
+
|
|
4332
|
+
|
|
4333
|
+
|
|
4334
|
+
|
|
4335
|
+
|
|
4336
|
+
|
|
4337
|
+
|
|
4338
|
+
|
|
4339
|
+
|
|
4340
|
+
|
|
4341
|
+
|
|
4342
|
+
|
|
4343
|
+
|
|
4344
|
+
|
|
4345
|
+
|
|
4346
|
+
|
|
4347
|
+
|
|
4348
|
+
|
|
4349
|
+
|
|
4350
|
+
|
|
4351
|
+
|
|
4352
|
+
|
|
4353
|
+
|
|
4354
|
+
|
|
4355
|
+
|
|
4356
|
+
|
|
4357
|
+
|
|
4358
|
+
|
|
4359
|
+
|
|
4360
|
+
|
|
4361
|
+
|
|
4362
|
+
|
|
4363
|
+
|
|
4364
|
+
|
|
4365
|
+
|
|
4366
|
+
|
|
4367
|
+
|
|
4368
|
+
|
|
4369
|
+
|
|
4370
|
+
|
|
4371
|
+
|
|
4372
|
+
|
|
4373
|
+
|
|
4374
|
+
|
|
4375
|
+
|
|
4376
|
+
|
|
4377
|
+
|
|
4378
|
+
|
|
4379
|
+
|
|
4380
|
+
|
|
4381
|
+
|
|
4382
|
+
exports.PresetBank = PresetBank; exports.captureParameters = captureParameters; exports.applyParameters = applyParameters; exports.controlFraction = controlFraction; exports.controlSource = controlSource; exports.sourceMatches = sourceMatches; exports.describeSource = describeSource; exports.ControlMappings = ControlMappings; exports.VoiceAllocator = VoiceAllocator; exports.MessageDebugger = MessageDebugger; exports.WAM_MODULE = WAM_MODULE; exports.wamPlugin = wamPlugin; exports.MAX_MC_CHANNELS = MAX_MC_CHANNELS; exports.multichannelPlugin = multichannelPlugin; exports.ChannelPack = ChannelPack; exports.ChannelUnpack = ChannelUnpack; exports.NoteMaker = NoteMaker; exports.COMPONENT_BOUNDARY = COMPONENT_BOUNDARY; exports.POLY_VOICE = POLY_VOICE; exports.NestedComponent = NestedComponent; exports.PolyComponent = PolyComponent; exports.InletModule = InletModule; exports.OutletModule = OutletModule; exports.VoiceNotes = VoiceNotes; exports.PresetModule = PresetModule; exports.nodeWeights = nodeWeights; exports.NodesModule = NodesModule; exports.createStructurePlugins = createStructurePlugins; exports.SOURCE_SCHEMAS = SOURCE_SCHEMAS; exports.SourcePublisher = SourcePublisher; exports.checkModuleConformance = checkModuleConformance; exports.ControlLFO = ControlLFO; exports.ControlEnvelope = ControlEnvelope; exports.EnvelopeFollower = EnvelopeFollower; exports.ParamMacro = ParamMacro; exports.copyProjectJson = copyProjectJson; exports.parseModuleProject = parseModuleProject; exports.serializeModuleProject = serializeModuleProject; exports.ProjectPluginRegistry = ProjectPluginRegistry; exports.ModuleProjectRuntime = ModuleProjectRuntime; exports.keepProjectSessionPreloaded = keepProjectSessionPreloaded; exports.createProjectEditorBinding = createProjectEditorBinding; exports.RackModule = RackModule; exports.createProviderScope = createProviderScope; exports.DeviceSink = DeviceSink; exports.CaptureSink = CaptureSink; exports.isOfflineModuleContext = isOfflineModuleContext; exports.createOfflineModuleEnvironment = createOfflineModuleEnvironment; exports.renderModuleGraph = renderModuleGraph;
|
|
4383
|
+
//# sourceMappingURL=chunk-IVWHMDCB.cjs.map
|